[gnome-photos/wip/uajain/de_dup: 11/11] google-share-point: Insert new object in tracker database and map its urn to base item which is shar



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

    google-share-point: Insert new object in tracker database
    and map its urn to base item which is shared

 src/photos-google-share-point.c |  117 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 115 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-google-share-point.c b/src/photos-google-share-point.c
index bf89f90..e38a653 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,108 @@ 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 *identifier, *title, *base_item_urn;
+  GVariant *variant, *child;
+  TrackerSparqlConnection *connection;
+  GError *local_error = NULL;
+  const gchar *urn;
+
+  identifier = photos_base_item_get_identifier (item);
+  title = gdata_entry_get_title (GDATA_ENTRY (uploaded_file_entry));
+  
+  sparql = g_strdup_printf ("INSERT { _:res a nfo:DataContainer ; a nie:DataObject ; "
+                            "nie:title '%s' ; "
+                            "nao:identifier '%s' }",
+                            title,
+                            identifier); // not sure of correct identifier - THIS SHOULD BE CORRECT TO STOP 
DUPLICATION
+
+  // 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;
+    }
+
+  /* Run a synchronous blank node update query */
+  variant = tracker_sparql_connection_update_blank (connection,
+                                              sparql,
+                                              G_PRIORITY_DEFAULT,
+                                              NULL,
+                                              &local_error);
+
+  if (local_error)
+  {
+    /* Some error happened performing the query, not good */
+    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);
+}
+
+
+static void
 photos_google_share_point_share_image (PhotosGoogleSharePoint *self, GCancellable *cancellable, 
PhotosBaseItem *item, GError **error)
 {
   GDataPicasaWebFile *uploaded_file_entry;
@@ -147,7 +250,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 +266,17 @@ photos_google_share_point_share_image (PhotosGoogleSharePoint *self, GCancellabl
       goto out;
     }
 
+    /*DEBUG POINT : print here the title of the uploaded_file_entry*/
+    printf("Title of uploaded_file_entry : %s\n", gdata_entry_get_title (GDATA_ENTRY (uploaded_file_entry)));
+
+  /* De duplication logic starts here.
+   * Create a :_res object in the tracker database
+   */
+  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]