[gnome-photos/wip/uajain/de_dup] google-share-point: Stop duplication



commit 40a1adb0a298bc7bdf5f49af720ca5129d5522d9
Author: Umang Jain <mailumangjain gmail com>
Date:   Tue Jul 26 22:41:46 2016 +0530

    google-share-point: Stop duplication
    
    When an image is uploaded, the remote image does not show up,
    in the overview mode.
    However, if you close and re-run the app, the remote image shows
    up in the overview.
    
    Somehow we should let the item manager know that to handle the case
    different if a base-item has 'relatedTo' property set and accordingly
    update the overview mode.
    
    Constraints here are: handling cases while searching only for
    'google-items' etc.

 src/photos-google-share-point.c |  113 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-google-share-point.c b/src/photos-google-share-point.c
index bf89f90..4c3b58d 100644
--- a/src/photos-google-share-point.c
+++ b/src/photos-google-share-point.c
@@ -24,12 +24,13 @@
 #include <gio/gio.h>
 #include <gdata/gdata.h>
 #include <gdata/gdata-goa-authorizer.h>
-
+#include <tracker-sparql.h>
 #include "photos-base-item.h"
 #include "photos-filterable.h"
 #include "photos-google-share-point.h"
 #include "photos-share-point.h"
 #include "photos-utils.h"
+#include "photos-filterable.h"
 
 struct _PhotosGoogleSharePoint
 {
@@ -93,6 +94,109 @@ photos_google_share_point_finalize (GObject *object)
 
 
 static void
+photos_google_share_point_create_tracker_entry (GDataPicasaWebFile *uploaded_file_entry,
+                                                PhotosBaseItem *item,
+                                                GCancellable *cancellable,
+                                                GError **error)
+{
+  gchar *sparql;
+  const gchar *title, *base_item_urn;
+  GVariant *variant, *child;
+  TrackerSparqlConnection *connection;
+  GError *local_error = NULL;
+  const gchar *urn;
+  gchar *identifier;
+
+  identifier = g_strconcat ("google:picasaweb:", gdata_entry_get_id (GDATA_ENTRY (uploaded_file_entry)), 
NULL);
+  title = gdata_entry_get_title (GDATA_ENTRY (uploaded_file_entry));
+
+  printf("IDENTIFIER: %s\n", identifier);
+  sparql = g_strdup_printf ("INSERT { _:res a nfo:RemoteDataObject; a nmm:Photo ; "
+                            "nie:title '%s' ; "
+                            "nao:identifier '%s' }",
+                            title,
+                            identifier);
+
+  // Copy-paste from https://developer.gnome.org/libtracker-sparql/stable/tracker-examples-writeonly.html
+  connection = tracker_sparql_connection_get (NULL, &local_error);
+  if (!connection)
+    {
+      g_printerr ("Couldn't obtain a connection to the Tracker store: %s",
+                  local_error ? local_error->message : "unknown error");
+      g_clear_error (&local_error);
+
+      return;
+    }
+
+  variant = tracker_sparql_connection_update_blank (connection,
+                                              sparql,
+                                              G_PRIORITY_DEFAULT,
+                                              NULL,
+                                              &local_error);
+
+  if (local_error)
+  {
+    g_printerr ("Couldn't update the Tracker store: %s",
+                local_error ? local_error->message : "unknown error");
+
+    g_clear_error (&local_error);
+    g_object_unref (connection);
+    return;
+  }
+
+  if (!variant)
+    {
+      g_print ("No results were returned\n");
+      g_object_unref (connection);
+      return;
+    }
+  else
+    {
+      child = g_variant_get_child_value (variant, 0); /* variant is now aa{ss} */
+      g_variant_unref (variant);
+      variant = child;
+
+      child = g_variant_get_child_value (variant, 0); /* variant is now s{ss} */
+      g_variant_unref (variant);
+      variant = child;
+
+      child = g_variant_get_child_value (variant, 0); /* variant is now {ss} */
+      g_variant_unref (variant);
+      variant = child;
+
+      child = g_variant_get_child_value (variant, 1);
+      urn = g_variant_dup_string (child, NULL);       /*urn of inserted object*/
+      g_variant_unref (child);
+      printf("Inserted URN: %s\n", urn);
+    }
+
+  local_error = NULL;
+  base_item_urn = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+  printf("I have got base-item urn: %s\n", base_item_urn);
+
+  sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:relatedTo '%s' }", base_item_urn, urn);
+  printf("Query: %s\n", sparql);
+
+  if (connection)
+    {
+      printf("ABOUT TO EXECUTE ^ QUERY\n");
+      tracker_sparql_connection_update (connection,
+                                        sparql,
+                                        G_PRIORITY_DEFAULT,
+                                        NULL,
+                                        &local_error);
+    }
+
+  if(local_error)
+    printf("error in relatedTo:\n");
+
+  g_object_unref (connection);
+  g_free (sparql);
+  g_free (identifier);
+}
+
+
+static void
 photos_google_share_point_share_image (PhotosGoogleSharePoint *self, GCancellable *cancellable, 
PhotosBaseItem *item, GError **error)
 {
   GDataPicasaWebFile *uploaded_file_entry;
@@ -147,7 +251,6 @@ photos_google_share_point_share_image (PhotosGoogleSharePoint *self, GCancellabl
                           G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
                           cancellable,
                           &local_error);
-
   if (local_error != NULL)
     {
       g_propagate_error (error, local_error);
@@ -164,6 +267,12 @@ photos_google_share_point_share_image (PhotosGoogleSharePoint *self, GCancellabl
       goto out;
     }
 
+  /*De-Dup logic*/
+  photos_google_share_point_create_tracker_entry (uploaded_file_entry,
+                                                  item,
+                                                  cancellable,
+                                                  &local_error);
+
 out:
   g_clear_object (&file_data);
   g_clear_object (&file_info);


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