[gnome-photos/wip/uajain/de_dup: 3/5] Add all data about remote



commit 9607ab0e78fac8f381e1b506a60b3b5082e1726b
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Aug 26 02:25:07 2016 +0530

    Add all data about remote

 src/photos-share-point-google.c |  199 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 190 insertions(+), 9 deletions(-)
---
diff --git a/src/photos-share-point-google.c b/src/photos-share-point-google.c
index f772fd5..f9a6389 100644
--- a/src/photos-share-point-google.c
+++ b/src/photos-share-point-google.c
@@ -59,6 +59,7 @@ typedef struct _PhotosSharePointGoogleShareData PhotosSharePointGoogleShareData;
 struct _PhotosSharePointGoogleShareData
 {
   GDataUploadStream *stream;
+  GDataPicasaWebFile *file_entry;
   PhotosBaseItem *item;
 };
 
@@ -70,6 +71,7 @@ photos_share_point_google_share_data_new (PhotosBaseItem *item)
 
   data = g_slice_new0 (PhotosSharePointGoogleShareData);
   data->item = g_object_ref (item);
+  data->file_entry = NULL;
 
   return data;
 }
@@ -80,6 +82,7 @@ photos_share_point_google_share_data_free (PhotosSharePointGoogleShareData *data
 {
   g_clear_object (&data->stream);
   g_clear_object (&data->item);
+  g_clear_object (&data->file_entry);
   g_slice_free (PhotosSharePointGoogleShareData, data);
 }
 
@@ -131,15 +134,44 @@ static void
 photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncResult *res, gpointer 
user_data)
 {
   PhotosSharePointGoogle *self;
+  PhotosSearchContextState *state;
   PhotosSharePointGoogleShareData *data;
+  PhotosQuery *query;
   TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
+  GApplication *app;
   GCancellable *cancellable;
+  GDataLink *alternate;
   GError *error;
+  GList *media_contents;
   GTask *task = G_TASK (user_data);
+  GTimeVal tv;
   GVariant *variant;
   GVariant *child;
+  gint64 timestamp;
+  gboolean flash;
+  
+  const gchar *credit;
+  const gchar *make;
+  const gchar *model;
+  const gchar *title;
+  const gchar *summary;
+  const gchar *mime;
   const gchar *item_urn;
   const gchar *remote_urn;
+  const gchar *flash_off;
+  const gchar *flash_on;
+  const gchar *alternate_uri;
+
+  gchar *exposure;
+  gchar *focal_length;
+  gchar *fstop;
+  gchar *iso;
+  gchar *width;
+  gchar *height;
+  gchar *time;
+
+  flash_off = "http://www.tracker-project.org/temp/nmm#flash-off";;
+  flash_on = "http://www.tracker-project.org/temp/nmm#flash-on";;
 
   self = PHOTOS_SHARE_POINT_GOOGLE (g_task_get_source_object (task));
   cancellable = g_task_get_cancellable (task);
@@ -169,8 +201,160 @@ photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncR
   remote_urn = g_variant_dup_string (child, NULL);
   g_variant_unref (child);
 
-  item_urn = photos_filterable_get_id (PHOTOS_FILTERABLE (data->item));
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  alternate = gdata_entry_look_up_link (GDATA_ENTRY (data->file_entry), GDATA_LINK_ALTERNATE);
+  alternate_uri = gdata_link_get_uri (alternate);
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nie:url", alternate_uri);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  summary = gdata_entry_get_summary (GDATA_ENTRY (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nie:description", summary);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  media_contents = gdata_picasaweb_file_get_contents (data->file_entry);
+  mime = gdata_media_content_get_content_type (GDATA_MEDIA_CONTENT (media_contents->data));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nie:mimeType", mime);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  title = gdata_entry_get_title (GDATA_ENTRY (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nie:title", title);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  credit = gdata_picasaweb_file_get_credit (data->file_entry);
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nco:creator", credit);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  exposure = g_strdup_printf ("%f", gdata_picasaweb_file_get_exposure (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nmm:exposureTime", exposure);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (exposure);
+
+  focal_length = g_strdup_printf ("%f", gdata_picasaweb_file_get_focal_length (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nmm:focalLength", focal_length);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (focal_length);
+
+  fstop = g_strdup_printf ("%f", gdata_picasaweb_file_get_fstop (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nmm:fnumber", fstop);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (fstop);
+
+  iso = g_strdup_printf ("%d", gdata_picasaweb_file_get_iso (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nmm:isoSpeed", iso);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (iso);
+
+  flash = gdata_picasaweb_file_get_flash (data->file_entry);
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nmm:flash", flash ? flash_on : 
flash_off);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
 
+  make = gdata_picasaweb_file_get_make (data->file_entry);
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nfo:manufacturer", make);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  model = gdata_picasaweb_file_get_model (data->file_entry);
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nfo:model", model);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+
+  width = g_strdup_printf ("%u", gdata_picasaweb_file_get_width (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nfo:width", width);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (width);
+
+  height = g_strdup_printf ("%u", gdata_picasaweb_file_get_height (data->file_entry));
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nfo:height", height);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (height);
+
+  /* borrowed from query_builder_mtime_update_query */
+  timestamp = gdata_picasaweb_file_get_timestamp (data->file_entry) / G_USEC_PER_SEC;
+  tv.tv_sec = timestamp;
+  tv.tv_usec = 0;
+  time = g_time_val_to_iso8601 (&tv);
+  query = photos_query_builder_insert_or_replace (state, remote_urn, "nie:contentCreated", time);
+  photos_tracker_queue_update (self->queue,
+                               query->sparql,
+                               cancellable,
+                               NULL,
+                               NULL,
+                               NULL);
+  g_free (time);
+  photos_query_free (query);
+
+  item_urn = photos_filterable_get_id (PHOTOS_FILTERABLE (data->item));
+  printf("Remote urn %s\n", remote_urn);
   photos_share_point_google_relate_objects (self, cancellable, remote_urn, item_urn);
 }
 
@@ -178,7 +362,6 @@ photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncR
 static void
 photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
                                                 GTask *task,
-                                                GDataPicasaWebFile *file_entry,
                                                 GError **error)
 {
   PhotosSearchContextState *state;
@@ -187,7 +370,6 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
   GApplication *app;
   GCancellable *cancellable;
   const gchar *id;
-  const gchar *title;
 
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
@@ -195,10 +377,8 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
   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));
-
-  query = photos_query_builder_insert_remote_object (state, title, id);
+  id = gdata_entry_get_id (GDATA_ENTRY (data->file_entry));
+  query = photos_query_builder_insert_remote_object (state, id);
   photos_tracker_queue_update_blank (self->queue,
                                      query->sparql,
                                      cancellable,
@@ -242,8 +422,9 @@ photos_share_point_google_share_save_to_stream (GObject *source_object, GAsyncRe
       goto out;
     }
 
+  data->file_entry = GDATA_PICASAWEB_FILE (g_object_ref (file_entry));
   error = NULL;
-  photos_share_point_google_create_tracker_entry (self, task, file_entry, &error);
+  photos_share_point_google_create_tracker_entry (self, task, &error);
   if (error != NULL)
     {
       g_task_return_error (task, error);
@@ -253,7 +434,7 @@ photos_share_point_google_share_save_to_stream (GObject *source_object, GAsyncRe
   g_task_return_boolean (task, TRUE);
 
  out:
-  g_clear_object (&file_entry);
+  g_object_unref (file_entry);
   g_object_unref (task);
 }
 


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