[gnome-photos/wip/rishi/misc-fixes: 10/15] base-item: Add photos_base_item_pipeline_save_async



commit 5ab83f6ec6e27b7386fbb029dbe2166e375fdf18
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 18 13:41:51 2015 +0100

    base-item: Add photos_base_item_pipeline_save_async

 src/photos-base-item.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |    9 ++++++
 2 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 2cab807..55c2de8 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -899,6 +899,29 @@ photos_base_item_load_load_buffer (GObject *source_object, GAsyncResult *res, gp
 }
 
 
+static void
+photos_base_item_pipeline_save_save (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  GTask *task = G_TASK (user_data);
+  PhotosBaseItem *self;
+  GError *error;
+
+  self = PHOTOS_BASE_ITEM (g_task_get_source_object (task));
+
+  error = NULL;
+  if (!photos_pipeline_save_finish (self->priv->pipeline, res, &error))
+    {
+      g_task_return_error (task, error);
+      goto out;
+    }
+
+  g_task_return_boolean (task, TRUE);
+
+ out:
+  g_object_unref (task);
+}
+
+
 static gboolean
 photos_base_item_process_idle (gpointer user_data)
 {
@@ -1842,6 +1865,59 @@ photos_base_item_operation_undo (PhotosBaseItem *self)
 
 
 void
+photos_base_item_pipeline_save_async (PhotosBaseItem *self,
+                                      GCancellable *cancellable,
+                                      GAsyncReadyCallback callback,
+                                      gpointer user_data)
+{
+  PhotosBaseItemPrivate *priv;
+  GTask *task;
+  gchar *path;
+  gchar *uri;
+  PhotosBaseItemClass *class;
+
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+  priv = self->priv;
+
+  class = PHOTOS_BASE_ITEM_GET_CLASS (self);
+  g_return_if_fail (class->create_pipeline_path != NULL);
+
+  g_return_if_fail (priv->edit_graph != NULL);
+  g_return_if_fail (priv->load_graph != NULL);
+  g_return_if_fail (priv->pipeline != NULL);
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, photos_base_item_pipeline_save_async);
+
+  path = class->create_pipeline_path (self);
+  uri = photos_utils_convert_path_to_uri (path);
+
+  photos_pipeline_save_async (priv->pipeline,
+                              uri,
+                              cancellable,
+                              photos_base_item_pipeline_save_save,
+                              g_object_ref (task));
+
+  g_free (path);
+  g_free (uri);
+  g_object_unref (task);
+}
+
+
+gboolean
+photos_base_item_pipeline_save_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_pipeline_save_async, FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  return g_task_propagate_boolean (task, error);
+}
+
+
+void
 photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel)
 {
   photos_base_item_load_async (self, NULL, photos_base_item_print_load, g_object_ref (toplevel));
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index f9c197d..ee2702d 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -195,6 +195,15 @@ gboolean            photos_base_item_operation_get           (PhotosBaseItem *se
 
 gboolean            photos_base_item_operation_undo          (PhotosBaseItem *self);
 
+void                photos_base_item_pipeline_save_async     (PhotosBaseItem *self,
+                                                              GCancellable *cancellable,
+                                                              GAsyncReadyCallback callback,
+                                                              gpointer user_data);
+
+gboolean            photos_base_item_pipeline_save_finish    (PhotosBaseItem *self,
+                                                              GAsyncResult *res,
+                                                              GError **error);
+
 void                photos_base_item_print                   (PhotosBaseItem *self, GtkWidget *toplevel);
 
 void                photos_base_item_process_async           (PhotosBaseItem *self,


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