[gnome-photos/wip/rishi/de-dup: 3/5] base-item: Add photos_base_item_metadata_add_shared_async



commit 95f2e4f2f3bbe937063d3ca33cd1756d10be7ad8
Author: Umang Jain <mailumangjain gmail com>
Date:   Sat Aug 27 04:12:12 2016 +0530

    base-item: Add photos_base_item_metadata_add_shared_async
    
    Some changes by Debarshi Ray.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770267

 src/photos-base-item.c |  108 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |   12 +++++
 2 files changed, 120 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 18d9823..ca804ee 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -131,10 +131,18 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PhotosBaseItem, photos_base_item, G_TYPE_OBJEC
 EGG_DEFINE_COUNTER (instances, "PhotosBaseItem", "Instances", "Number of PhotosBaseItem instances")
 
 
+typedef struct _PhotosBaseItemMetadataAddSharedData PhotosBaseItemMetadataAddSharedData;
 typedef struct _PhotosBaseItemSaveData PhotosBaseItemSaveData;
 typedef struct _PhotosBaseItemSaveBufferData PhotosBaseItemSaveBufferData;
 typedef struct _PhotosBaseItemSaveToStreamData PhotosBaseItemSaveToStreamData;
 
+struct _PhotosBaseItemMetadataAddSharedData
+{
+  gchar *account_identity;
+  gchar *provider_type;
+  gchar *shared_id;
+};
+
 struct _PhotosBaseItemSaveData
 {
   GFile *dir;
@@ -167,6 +175,32 @@ static const gint PIXEL_SIZES[] = {2048, 1024};
 static void photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor);
 
 
+static PhotosBaseItemMetadataAddSharedData *
+photos_base_item_metadata_add_shared_data_new (const gchar *provider_type,
+                                               const gchar *account_identity,
+                                               const gchar *shared_id)
+{
+  PhotosBaseItemMetadataAddSharedData *data;
+
+  data = g_slice_new0 (PhotosBaseItemMetadataAddSharedData);
+  data->account_identity = g_strdup (account_identity);
+  data->provider_type = g_strdup (provider_type);
+  data->shared_id = g_strdup (shared_id);
+
+  return data;
+}
+
+
+static void
+photos_base_item_metadata_add_shared_data_free (PhotosBaseItemMetadataAddSharedData *data)
+{
+  g_free (data->account_identity);
+  g_free (data->provider_type);
+  g_free (data->shared_id);
+  g_slice_free (PhotosBaseItemMetadataAddSharedData, data);
+}
+
+
 static PhotosBaseItemSaveData *
 photos_base_item_save_data_new (GFile *dir, GeglBuffer *buffer, const gchar *type, gdouble zoom)
 {
@@ -1340,6 +1374,34 @@ photos_base_item_load_pipeline (GObject *source_object, GAsyncResult *res, gpoin
 
 
 static void
+photos_base_item_metadata_add_shared_in_thread_func (GTask *task,
+                                                     gpointer source_object,
+                                                     gpointer task_data,
+                                                     GCancellable *cancellable)
+{
+  PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
+  GError *error;
+  PhotosBaseItemMetadataAddSharedData *data = (PhotosBaseItemMetadataAddSharedData *) task_data;
+  gboolean result;
+
+  error = NULL;
+  result = PHOTOS_BASE_ITEM_GET_CLASS (self)->metadata_add_shared (self,
+                                                                   data->provider_type,
+                                                                   data->account_identity,
+                                                                   data->shared_id,
+                                                                   cancellable,
+                                                                   &error);
+  if (error != NULL)
+    {
+      g_task_return_error (task, error);
+      return;
+    }
+
+  g_task_return_boolean (task, result);
+}
+
+
+static void
 photos_base_item_pipeline_save_save (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
   GTask *task = G_TASK (user_data);
@@ -3082,6 +3144,52 @@ photos_base_item_load_finish (PhotosBaseItem *self, GAsyncResult *res, GError **
 
 
 void
+photos_base_item_metadata_add_shared_async (PhotosBaseItem *self,
+                                            const gchar *provider_type,
+                                            const gchar *account_identity,
+                                            const gchar *shared_id,
+                                            GCancellable *cancellable,
+                                            GAsyncReadyCallback callback,
+                                            gpointer user_data)
+{
+  PhotosBaseItemPrivate *priv;
+  GTask *task;
+  PhotosBaseItemMetadataAddSharedData *data;
+
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+  priv = photos_base_item_get_instance_private (self);
+
+  g_return_if_fail (!priv->collection);
+  g_return_if_fail (provider_type != NULL && provider_type[0] != '\0');
+  g_return_if_fail (account_identity != NULL && account_identity[0] != '\0');
+  g_return_if_fail (shared_id != NULL && shared_id[0] != '\0');
+
+  data = photos_base_item_metadata_add_shared_data_new (provider_type, account_identity, shared_id);
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, photos_base_item_metadata_add_shared_async);
+  g_task_set_task_data (task, data, (GDestroyNotify) photos_base_item_metadata_add_shared_data_free);
+
+  g_task_run_in_thread (task, photos_base_item_metadata_add_shared_in_thread_func);
+  g_object_unref (task);
+}
+
+
+gboolean
+photos_base_item_metadata_add_shared_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
+{
+  GTask *task = G_TASK (res);
+
+  g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+  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_metadata_add_shared_async, FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  return g_task_propagate_boolean (task, error);
+}
+
+
+void
 photos_base_item_open (PhotosBaseItem *self, GdkScreen *screen, guint32 timestamp)
 {
   g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 5366360..f793786 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -180,6 +180,18 @@ GeglNode           *photos_base_item_load_finish             (PhotosBaseItem *se
                                                               GAsyncResult *res,
                                                               GError **error);
 
+void                photos_base_item_metadata_add_shared_async  (PhotosBaseItem *self,
+                                                                 const gchar *provider_type,
+                                                                 const gchar *account_identity,
+                                                                 const gchar *shared_id,
+                                                                 GCancellable *cancellable,
+                                                                 GAsyncReadyCallback callback,
+                                                                 gpointer user_data);
+
+gboolean            photos_base_item_metadata_add_shared_finish (PhotosBaseItem *self,
+                                                                 GAsyncResult *res,
+                                                                 GError **error);
+
 void                photos_base_item_open                    (PhotosBaseItem *self,
                                                               GdkScreen *screen,
                                                               guint32 timestamp);


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