[gnome-photos/wip/uajain/de_dup: 3/3] base-item: Add metadata to local resource
- From: Umang Jain <uajain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/uajain/de_dup: 3/3] base-item: Add metadata to local resource
- Date: Fri, 26 Aug 2016 08:45:31 +0000 (UTC)
commit 6ebb89baef4f13a11d8d678d84602bc9fb78f937
Author: Umang Jain <mailumangjain gmail com>
Date: Fri Aug 26 05:49:32 2016 +0530
base-item: Add metadata to local resource
https://bugzilla.gnome.org/show_bug.cgi?id=770267
src/photos-base-item.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++
src/photos-base-item.h | 10 +++++
2 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 1e9a678..26a8016 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -2148,6 +2148,61 @@ photos_base_item_print_load (GObject *source_object, GAsyncResult *res, gpointer
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;
+
+ mime_type = photos_base_item_get_mime_type (item);
+ if ((g_strcmp0 (mime_type, "image/png") == 0) ||
+ (g_strcmp0 (mime_type, "image/jpeg") == 0)||
+ (g_strcmp0 (mime_type, "image/jpg") == 0))
+ {
+ meta = gexiv2_metadata_new ();
+
+ /*Can we do something better to get path ?*/
+ uri = photos_base_item_get_uri (item);
+ file = g_file_new_for_uri (uri);
+ path = g_file_get_path (file);
+ gexiv2_metadata_open_path (meta, path, &error);
+ if (error != NULL)
+ 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_save_file (meta, path, &error);
+
+ if (error)
+ goto out;
+ }
+ g_print("Metadata embedded successfully\n");
+ }
+
+out:
+ gexiv2_metadata_free (meta);
+ g_free (path);
+ g_free (id);
+ g_object_unref (file);
+}
+
+
+static void
photos_base_item_constructed (GObject *object)
{
PhotosBaseItem *self = PHOTOS_BASE_ITEM (object);
@@ -3596,3 +3651,34 @@ photos_base_item_trash (PhotosBaseItem *self)
photos_delete_item_job_run (job, NULL, NULL, NULL);
g_object_unref (job);
}
+
+
+gboolean
+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);
+}
+
+
+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 55b7f19..5021535 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -100,6 +100,16 @@ struct _PhotosBaseItemClass
GType photos_base_item_get_type (void) G_GNUC_CONST;
+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);
gboolean photos_base_item_can_trash (PhotosBaseItem *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]