[gnome-photos/wip/rishi/de-dup: 6/6] local-item: implement vfunc
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/de-dup: 6/6] local-item: implement vfunc
- Date: Tue, 6 Sep 2016 22:50:29 +0000 (UTC)
commit e0566e3d3d29e444d0f496c570ae9e16f07c8a84
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Sep 6 20:46:05 2016 +0200
local-item: implement vfunc
src/photos-local-item.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 5cba1da..77ccae0 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -26,6 +26,7 @@
#include "config.h"
+#include <gexiv2/gexiv2.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -170,6 +171,95 @@ photos_local_item_get_source_widget (PhotosBaseItem *item)
}
+static gboolean
+photos_local_item_metadata_add_shared (PhotosBaseItem *item,
+ const gchar *provider_type,
+ const gchar *account_identity,
+ const gchar *shared_id,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GExiv2Metadata *metadata = NULL;
+ gboolean ret_val = FALSE;
+ gchar *path = NULL;
+ gchar **account_identities = NULL;
+ gchar **provider_types = NULL;
+ gchar **shared_ids = NULL;
+ guint n_account_identities;
+ guint n_provider_types;
+ guint n_shared_ids;
+
+ path = photos_base_item_download (item, cancellable, error);
+ if (path == NULL)
+ goto out;
+
+ metadata = gexiv2_metadata_new ();
+
+ if (!gexiv2_metadata_open_path (metadata, path, error))
+ goto out;
+
+ account_identities = gexiv2_metadata_get_tag_multiple (metadata, "Xmp.gnome.photos-account-identity");
+ n_account_identities = g_strv_length (account_identities);
+
+ provider_types = gexiv2_metadata_get_tag_multiple (metadata, "Xmp.gnome.photos-provider-type");
+ n_provider_types = g_strv_length (provider_types);
+
+ shared_ids = gexiv2_metadata_get_tag_multiple (metadata, "Xmp.gnome.photos-shared-id");
+ n_shared_ids = g_strv_length (shared_ids);
+
+ if (n_account_identities != n_provider_types || n_provider_types != n_shared_ids)
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, "Invalid Xmp.gnome metadata");
+ goto out;
+ }
+
+ account_identities = (gchar **) g_realloc_n (account_identities, n_account_identities + 2, sizeof (gchar
*));
+ account_identities[n_account_identities] = g_strdup (account_identity);
+ account_identities[n_account_identities + 1] = NULL;
+
+ provider_types = (gchar **) g_realloc_n (provider_types, n_provider_types + 2, sizeof (gchar *));
+ provider_types[n_provider_types] = g_strdup (provider_type);
+ provider_types[n_provider_types + 1] = NULL;
+
+ shared_ids = (gchar **) g_realloc_n (shared_ids, n_shared_ids + 2, sizeof (gchar *));
+ shared_ids[n_shared_ids] = g_strdup (shared_id);
+ shared_ids[n_shared_ids + 1] = NULL;
+
+ if (!gexiv2_metadata_set_tag_multiple (metadata,
+ "Xmp.gnome.photos-account-identity",
+ (const gchar **) account_identities))
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, "Failed to write Xmp.gnome.photos-account-identity");
+ goto out;
+ }
+
+ if (!gexiv2_metadata_set_tag_multiple (metadata, "Xmp.gnome.photos-provider-type", (const gchar **)
provider_types))
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, "Failed to write Xmp.gnome.photos-provider-type");
+ goto out;
+ }
+
+ if (!gexiv2_metadata_set_tag_multiple (metadata, "Xmp.gnome.photos-shared-id", (const gchar **)
shared_ids))
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, "Failed to write Xmp.gnome.photos-shared-id");
+ goto out;
+ }
+
+ if (!gexiv2_metadata_save_file (metadata, path, error))
+ goto out;
+
+ ret_val = TRUE;
+
+ out:
+ g_clear_object (&metadata);
+ g_free (path);
+ g_strfreev (account_identities);
+ g_strfreev (provider_types);
+ g_strfreev (shared_ids);
+ return ret_val;
+}
+
+
static void
photos_local_item_trash_finish (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
@@ -271,5 +361,6 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
base_item_class->create_thumbnail = photos_local_item_create_thumbnail;
base_item_class->download = photos_local_item_download;
base_item_class->get_source_widget = photos_local_item_get_source_widget;
+ base_item_class->metadata_add_shared = photos_local_item_metadata_add_shared;
base_item_class->trash = photos_local_item_trash;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]