[gnome-photos/wip/rishi/de-dup: 4/5] local-item: Embed XMP metadata identifying shared copies
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/de-dup: 4/5] local-item: Embed XMP metadata identifying shared copies
- Date: Wed, 7 Sep 2016 07:20:04 +0000 (UTC)
commit 2ca30d7cf23a9fa174012bd7edccabaf85407ed3
Author: Umang Jain <mailumangjain gmail com>
Date: Tue Sep 6 20:46:05 2016 +0200
local-item: Embed XMP metadata identifying shared copies
It is rumoured (ask in #darktable on Freenode) that modifying the
metadata of RAW files is risky and has caused such files to get
corrupted. Therefore, we play it safe and only touch PNGs, JPEGs and
JPEG-2000s.
Some changes by Debarshi Ray.
https://bugzilla.gnome.org/show_bug.cgi?id=770267
src/photos-local-item.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 5cba1da..036445a 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,105 @@ 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;
+ const gchar *mime_type;
+ 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;
+
+ mime_type = photos_base_item_get_mime_type (item);
+ if (g_strcmp0 (mime_type, "image/png") != 0
+ && g_strcmp0 (mime_type, "image/jp2") != 0
+ && g_strcmp0 (mime_type, "image/jpeg") != 0)
+ {
+ ret_val = TRUE;
+ goto out;
+ }
+
+ 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 +371,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]