[gnome-photos/wip/uajain/de_dup: 5/5] temp3
- From: Umang Jain <uajain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/uajain/de_dup: 5/5] temp3
- Date: Fri, 26 Aug 2016 00:20:57 +0000 (UTC)
commit b27246d1e0b3c88569682fcae00c866956b69bae
Author: Umang Jain <mailumangjain gmail com>
Date: Fri Aug 26 05:11:51 2016 +0530
temp3
src/photos-base-item.c | 51 ++++++++++++--
src/photos-base-item.h | 11 +++-
src/photos-share-point-google.c | 139 ++++++++++++---------------------------
3 files changed, 95 insertions(+), 106 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 660f889..7cf22cd 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -3439,15 +3439,33 @@ photos_base_item_trash (PhotosBaseItem *self)
gboolean
-photos_base_item_add_metadata_to_local (PhotosBaseItem *item, const gchar *tag, gchar *id)
+photos_base_item_add_metadata_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_add_metadata_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
+}
+
+
+static void
+photos_base_item_add_metadata_in_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
GExiv2Metadata *meta;
GFile *file;
+ const gchar *tag;
const gchar *uri;
const gchar *mime_type;
gchar *path;
+ gchar *id;
GError *error = NULL;
- gboolean ret_val = FALSE;
mime_type = photos_base_item_get_mime_type (item);
if ((g_strcmp0 (mime_type, "image/png") == 0) ||
@@ -3465,25 +3483,42 @@ photos_base_item_add_metadata_to_local (PhotosBaseItem *item, const gchar *tag,
goto out;
else
{
+ tag = (const gchar *) g_object_get_data (G_OBJECT (item), "tag");
+ id = (gchar *) task_data;
+
if (gexiv2_metadata_has_tag (meta, tag))
gexiv2_metadata_clear_tag (meta, tag);
- gexiv2_metadata_set_tag_string (meta, tag, id);
+ gexiv2_metadata_set_tag_string (meta, tag, id);
gexiv2_metadata_save_file (meta, path, &error);
if (error)
- goto out;
+ goto out;
}
-
- ret_val = TRUE;
g_print("Metadata embedded successfully\n");
}
out:
gexiv2_metadata_free (meta);
g_free (path);
+ g_free (id);
g_object_unref (file);
- g_object_unref (item);
+}
- return ret_val;
+
+void
+photos_base_item_add_metadata_async (PhotosBaseItem *self,
+ gchar *id,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_base_item_add_metadata_async);
+ g_task_set_task_data (task, id, g_free);
+
+ g_task_run_in_thread (task, photos_base_item_add_metadata_in_thread_func);
+ g_object_unref (task);
}
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 8d99414..9046eff 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -101,8 +101,15 @@ 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, gchar *id);
-
+void photos_base_item_add_metadata_async (PhotosBaseItem *self,
+ gchar *id,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean photos_base_item_add_metadata_finish (PhotosBaseItem *self,
+ GAsyncResult *res,
+ GError **error);
gboolean photos_base_item_can_edit (PhotosBaseItem *self);
diff --git a/src/photos-share-point-google.c b/src/photos-share-point-google.c
index 1a1a5f2..b7cb606 100644
--- a/src/photos-share-point-google.c
+++ b/src/photos-share-point-google.c
@@ -207,136 +207,67 @@ photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncR
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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ photos_tracker_queue_update (self->queue, query->sparql, cancellable, NULL, NULL, NULL);
- /*Not sure how to do this with Equipment*/
+ /* Not sure how to do this with Equipment
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);
+ 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);
+ 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);
+ 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);
+ photos_tracker_queue_update (self->queue, query->sparql, cancellable, NULL, NULL, NULL);
g_free (height);
/* borrowed from query_builder_mtime_update_query */
@@ -345,12 +276,7 @@ photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncR
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);
+ photos_tracker_queue_update (self->queue, query->sparql, cancellable, NULL, NULL, NULL);
g_free (time);
photos_query_free (query);
@@ -360,6 +286,22 @@ photos_google_share_point_tracker_entry_created (GObject *source_object, GAsyncR
static void
+photos_share_point_google_metadata_added (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+ GError *error = NULL;
+
+ if (!photos_base_item_add_metadata_finish (item, res, &error))
+ {
+ g_warning ("Could not remote link as metadata: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (item);
+}
+
+
+static void
photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
GTask *task,
GError **error)
@@ -369,7 +311,7 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
PhotosQuery *query;
GApplication *app;
GCancellable *cancellable;
- const gchar *id;
+ const gchar *id, *tag;
gchar *identifier;
app = g_application_get_default ();
@@ -389,9 +331,14 @@ photos_share_point_google_create_tracker_entry (PhotosSharePointGoogle *self,
photos_query_free (query);
data->item = PHOTOS_BASE_ITEM (g_object_ref (data->item));
- identifier = g_strconcat ("google:picasaweb:", id, NULL);
- photos_base_item_add_metadata_to_local (data->item, "Xmp.xmp.gnome-photos.google.identifier", identifier);
- g_free (identifier);
+ identifier = g_strdup_printf ("google:picasaweb:%s", id);
+ tag = "Xmp.xmp.gnome-photos.google.identifier";
+ g_object_set_data (G_OBJECT (data->item), "tag", (gpointer *) tag);
+ photos_base_item_add_metadata_async (data->item,
+ identifier,
+ cancellable,
+ photos_share_point_google_metadata_added,
+ NULL);
}
@@ -427,7 +374,7 @@ photos_share_point_google_share_save_to_stream (GObject *source_object, GAsyncRe
data->file_entry = GDATA_PICASAWEB_FILE (g_object_ref (file_entry));
error = NULL;
- photos_share_point_google_create_tracker_entry (self, task, &error);
+ photos_share_point_google_create_tracker_entry (self, g_object_ref(task), &error);
if (error != NULL)
{
g_task_return_error (task, error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]