[gnome-photos/wip/uajain/de_dup: 1/5] Embed XMP tag string in local image



commit c0efe09ab9bc0f8ec836aa82f5d63a8789f14a0b
Author: Umang Jain <mailumangjain gmail com>
Date:   Sun Aug 21 13:11:06 2016 +0530

    Embed XMP tag string in local image

 src/photos-base-item.c          |   47 +++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h          |    5 ++++
 src/photos-share-point-google.c |   23 +++++++-----------
 3 files changed, 61 insertions(+), 14 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 5a0ff1c..473fdc1 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -3436,3 +3436,50 @@ photos_base_item_trash (PhotosBaseItem *self)
   photos_delete_item_job_run (job, NULL, NULL, NULL);
   g_object_unref (job);
 }
+
+
+gboolean
+photos_base_item_add_metadata_to_local (PhotosBaseItem *item, const gchar *tag, const gchar *id)
+{
+  GExiv2Metadata *meta;
+  GFile *file;
+  const gchar *uri;
+  gchar *identifier;
+  gchar *path;
+  GError *error = NULL;
+  gboolean ret_val = FALSE;
+
+  meta = gexiv2_metadata_new ();
+
+  /*Can we do something better to get path ?*/
+  uri = photos_base_item_get_uri (item);
+  file = g_file_new_for_uri (uri);
+  path = g_file_get_path (file);
+  gexiv2_metadata_open_path (meta, path, &error);
+  if (error != NULL)
+    goto out;
+  else
+    {
+      if (gexiv2_metadata_has_tag (meta, tag))
+       gexiv2_metadata_clear_tag (meta, tag);
+
+      identifier = g_strconcat ("google:picasaweb:", id, NULL);
+      gexiv2_metadata_set_tag_string (meta, tag, identifier);
+      gexiv2_metadata_save_file (meta, path, &error);
+
+      if (error)
+       goto out;
+      }
+
+  ret_val = TRUE;
+  g_print("Metadata embedded successfully\n");
+
+out:
+  gexiv2_metadata_free (meta);
+  g_free (identifier);
+  g_free (path);
+  g_object_unref (file);
+  g_object_unref (item);
+
+  return ret_val;
+}
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index c16e033..2e00cc1 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -101,6 +101,11 @@ struct _PhotosBaseItemClass
 
 GType               photos_base_item_get_type                (void) G_GNUC_CONST;
 
+gboolean           photos_base_item_add_metadata_to_local   (PhotosBaseItem *item,
+                                                             const gchar    *tag,
+                                                             const gchar    *id);
+
+
 gboolean            photos_base_item_can_edit                (PhotosBaseItem *self);
 
 gboolean            photos_base_item_can_share               (PhotosBaseItem *self);
diff --git a/src/photos-share-point-google.c b/src/photos-share-point-google.c
index 596a4e5..f772fd5 100644
--- a/src/photos-share-point-google.c
+++ b/src/photos-share-point-google.c
@@ -99,7 +99,7 @@ photos_share_point_google_parse_error (PhotosSharePoint *self, GError *error)
 
 
 static void
-photos_share_point_google_relate_objects (PhotosSharePointGoogle *self, GCancellable *cancellable, const 
gchar *obj1, const gchar *obj2)
+photos_share_point_google_relate_objects (PhotosSharePointGoogle *self, GCancellable *cancellable, const 
gchar *domain_urn, const gchar *range_urn)
 {
   PhotosSearchContextState *state;
   PhotosQuery *query;
@@ -108,8 +108,7 @@ photos_share_point_google_relate_objects (PhotosSharePointGoogle *self, GCancell
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  query = photos_query_builder_relate_objects (state, obj1, obj2);
-  printf("Related query 1 :%s \n", query->sparql);
+  query = photos_query_builder_relate_objects (state, domain_urn, range_urn);
   photos_tracker_queue_update (self->queue,
                                query->sparql,
                                cancellable,
@@ -117,8 +116,7 @@ photos_share_point_google_relate_objects (PhotosSharePointGoogle *self, GCancell
                                NULL,
                                NULL);
 
-  query = photos_query_builder_relate_objects (state, obj2, obj1);
-  printf("Related query 2 :%s \n", query->sparql);
+  query = photos_query_builder_relate_objects (state, range_urn, domain_urn);
   photos_tracker_queue_update (self->queue,
                                query->sparql,
                                cancellable,
@@ -168,17 +166,10 @@ photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncR
   variant = child;
 
   child = g_variant_get_child_value (variant, 1);
-  remote_urn = g_variant_dup_string (child, NULL);/*urn of inserted object*/
+  remote_urn = g_variant_dup_string (child, NULL);
   g_variant_unref (child);
-  printf("remote image urn: %s\n", remote_urn);
 
   item_urn = photos_filterable_get_id (PHOTOS_FILTERABLE (data->item));
-  printf("local image urn: %s\n", item_urn);
-
-  /* We do, remote urn relatedTo base urn mapping here.
-   * In the model, we see if any urn has set its related to property then,
-   * it is definitely a remote urn and it does not show up in overview.
-   */
 
   photos_share_point_google_relate_objects (self, cancellable, remote_urn, item_urn);
 }
@@ -191,6 +182,7 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
                                                 GError **error)
 {
   PhotosSearchContextState *state;
+  PhotosSharePointGoogleShareData *data;
   PhotosQuery *query;
   GApplication *app;
   GCancellable *cancellable;
@@ -201,6 +193,7 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
   cancellable = g_task_get_cancellable (task);
+  data = (PhotosSharePointGoogleShareData *) g_task_get_task_data (task);
 
   id = gdata_entry_get_id (GDATA_ENTRY (file_entry));
   title = gdata_entry_get_title (GDATA_ENTRY (file_entry));
@@ -213,6 +206,9 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
                                      g_object_ref (task),
                                      g_object_unref);
   photos_query_free (query);
+
+  data->item = PHOTOS_BASE_ITEM (g_object_ref (data->item));
+  photos_base_item_add_metadata_to_local (data->item, "Xmp.xmp.gnome-photos.google.identifier", id);
 }
 
 
@@ -246,7 +242,6 @@ photos_share_point_google_share_save_to_stream (GObject *source_object, GAsyncRe
       goto out;
     }
 
-    /* adding remote object logic flows from here*/
   error = NULL;
   photos_share_point_google_create_tracker_entry (self, task, file_entry, &error);
   if (error != NULL)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]