[gnome-photos/wip/uajain/de_dup: 57/58] share-point-google:Insert remote object manually to tracker database
- From: Umang Jain <uajain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/uajain/de_dup: 57/58] share-point-google:Insert remote object manually to tracker database
- Date: Sat, 20 Aug 2016 10:37:00 +0000 (UTC)
commit fec15bc9933e783ffa792e98a3a379b03d66b0a0
Author: Umang Jain <mailumangjain gmail com>
Date: Sun Aug 7 06:08:40 2016 +0530
share-point-google:Insert remote object manually to tracker database
src/photos-query-builder.c | 29 +++++++++
src/photos-query-builder.h | 4 +
src/photos-share-point-google.c | 131 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 163 insertions(+), 1 deletions(-)
---
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index a16bc8e..80f82e2 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -348,6 +348,35 @@ photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const
}
+PhotosQuery *
+photos_query_builder_relate_remote_object (PhotosSearchContextState *state, const gchar *remote_urn, const
gchar *item_urn)
+{
+ gchar *sparql;
+
+ sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:relatedTo '%s' }", remote_urn, item_urn);
+
+ return photos_query_new (state, sparql);
+}
+
+
+PhotosQuery *
+photos_query_builder_insert_remote_object (PhotosSearchContextState *state, const gchar *title, const gchar
*id)
+{
+ gchar *identifier;
+ gchar *sparql;
+
+ identifier = g_strconcat ("google:picasaweb:", id, NULL);
+ sparql = g_strdup_printf ("INSERT { _:res a nfo:RemoteDataObject; a nmm:Photo ; "
+ "nie:title '%s' ; "
+ "nao:identifier '%s' }",
+ title,
+ identifier);
+ g_free (identifier);
+
+ return photos_query_new (state, sparql);
+}
+
+
gchar *
photos_query_builder_filter_local (void)
{
diff --git a/src/photos-query-builder.h b/src/photos-query-builder.h
index 30c9693..c03c368 100644
--- a/src/photos-query-builder.h
+++ b/src/photos-query-builder.h
@@ -62,6 +62,10 @@ PhotosQuery *photos_query_builder_update_mtime_query (PhotosSearchContextState
gchar *photos_query_builder_filter_local (void);
+PhotosQuery *photos_query_builder_insert_remote_object (PhotosSearchContextState *state, const gchar
*title, const gchar *id);
+
+PhotosQuery *photos_query_builder_relate_remote_object (PhotosSearchContextState *state, const gchar
*remote_urn, const gchar *item_urn);
+
G_END_DECLS
#endif /* PHOTOS_QUERY_BUILDER */
diff --git a/src/photos-share-point-google.c b/src/photos-share-point-google.c
index eb6edcf..2c4c661 100644
--- a/src/photos-share-point-google.c
+++ b/src/photos-share-point-google.c
@@ -25,16 +25,23 @@
#include <gdata/gdata.h>
#include "photos-base-item.h"
+#include "photos-filterable.h"
+#include "photos-query.h"
+#include "photos-query-builder.h"
+#include "photos-search-context.h"
#include "photos-share-point-google.h"
#include "photos-source.h"
-#include "photos-utils.h"
+#include "photos-tracker-queue.h"
+ #include "photos-utils.h"
struct _PhotosSharePointGoogle
{
PhotosSharePointOnline parent_instance;
+ PhotosTrackerQueue *queue;
GDataGoaAuthorizer *authorizer;
GDataPicasaWebService *service;
+ GError *queue_error;
};
@@ -77,6 +84,106 @@ photos_share_point_google_share_data_free (PhotosSharePointGoogleShareData *data
static void
+photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncResult *res, gpointer
user_data)
+{
+ PhotosSharePointGoogle *self;
+ PhotosSharePointGoogleShareData *data;
+ TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
+ PhotosSearchContextState *state;
+ PhotosQuery *query;
+ GApplication *app;
+ GCancellable *cancellable;
+ GError *error;
+ GTask *task = G_TASK (user_data);
+ GVariant *variant;
+ GVariant *child;
+ const gchar *item_urn;
+ const gchar *remote_urn;
+
+ app = g_application_get_default ();
+ state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+ self = PHOTOS_SHARE_POINT_GOOGLE (g_task_get_source_object (task));
+ cancellable = g_task_get_cancellable (task);
+ data = (PhotosSharePointGoogleShareData *) g_task_get_task_data (task);
+
+ error = NULL;
+ variant = tracker_sparql_connection_update_blank_finish (connection, res, &error);
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ return;
+ }
+
+ 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);
+ remote_urn = g_variant_dup_string (child, NULL); /*urn of inserted object*/
+ 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.
+ */
+ query = photos_query_builder_relate_remote_object (state, remote_urn, item_urn);
+ printf("Related query %s \n", query->sparql);
+ photos_tracker_queue_update (self->queue,
+ query->sparql,
+ cancellable,
+ NULL,
+ NULL,
+ NULL);
+ photos_query_free (query);
+}
+
+
+static void
+photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
+ GTask *task,
+ GDataPicasaWebFile *file_entry,
+ GError **error)
+{
+ PhotosSearchContextState *state;
+ PhotosQuery *query;
+ 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));
+
+ cancellable = g_task_get_cancellable (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);
+ photos_tracker_queue_update_blank (self->queue,
+ query->sparql,
+ cancellable,
+ photos_google_share_point_tracker_entry_created,
+ g_object_ref (task),
+ g_object_unref);
+ photos_query_free (query);
+}
+
+
+static void
photos_share_point_google_share_save_to_stream (GObject *source_object, GAsyncResult *res, gpointer
user_data)
{
PhotosSharePointGoogle *self;
@@ -106,6 +213,15 @@ 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)
+ {
+ g_task_return_error (task, error);
+ goto out;
+ }
+
g_task_return_boolean (task, TRUE);
out:
@@ -244,6 +360,7 @@ photos_share_point_google_dispose (GObject *object)
PhotosSharePointGoogle *self = PHOTOS_SHARE_POINT_GOOGLE (object);
g_clear_object (&self->authorizer);
+ g_clear_object (&self->queue);
g_clear_object (&self->service);
G_OBJECT_CLASS (photos_share_point_google_parent_class)->dispose (object);
@@ -251,8 +368,19 @@ photos_share_point_google_dispose (GObject *object)
static void
+photos_share_point_google_finalize (GObject *object)
+{
+ PhotosSharePointGoogle *self = PHOTOS_SHARE_POINT_GOOGLE (object);
+
+ g_clear_error (&self->queue_error);
+
+ G_OBJECT_CLASS (photos_share_point_google_parent_class)->dispose (object);
+}
+
+static void
photos_share_point_google_init (PhotosSharePointGoogle *self)
{
+ self->queue = photos_tracker_queue_dup_singleton (NULL, &self->queue_error);
}
@@ -264,6 +392,7 @@ photos_share_point_google_class_init (PhotosSharePointGoogleClass *class)
object_class->constructed = photos_share_point_google_constructed;
object_class->dispose = photos_share_point_google_dispose;
+ object_class->finalize = photos_share_point_google_finalize;
share_point_class->share_async = photos_share_point_google_share_async;
share_point_class->share_finish = photos_share_point_google_share_finish;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]