[gnome-photos/wip/rishi/misc-fixes: 11/20] base-item, pipeline: Pass the URI during construction



commit 4c438bcc797e84fd148e11c2dbaa43c945e29c72
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 18 20:13:28 2015 +0100

    base-item, pipeline: Pass the URI during construction
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759363

 src/photos-base-item.c |   27 +++++++++++++++------------
 src/photos-pipeline.c  |   20 ++++++++++++++++++--
 src/photos-pipeline.h  |    2 +-
 3 files changed, 34 insertions(+), 15 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 46feb54..ca5c089 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1826,12 +1826,27 @@ photos_base_item_load_async (PhotosBaseItem *self,
     }
   else
     {
+      PhotosBaseItemClass *class;
+      gchar *uri = NULL;
+
+      class = PHOTOS_BASE_ITEM_GET_CLASS (self);
+      if (class->create_pipeline_path != NULL)
+        {
+          gchar *path;
+
+          path = class->create_pipeline_path (self);
+          uri = photos_utils_convert_path_to_uri (path);
+          g_free (path);
+        }
+
       priv->edit_graph = gegl_node_new ();
       priv->buffer_source = gegl_node_new_child (priv->edit_graph, "operation", "gegl:buffer-source", NULL);
       photos_pipeline_new_async (priv->edit_graph,
+                                 uri,
                                  cancellable,
                                  photos_base_item_load_pipeline,
                                  g_object_ref (task));
+      g_free (uri);
     }
 
   g_object_unref (task);
@@ -1898,16 +1913,10 @@ photos_base_item_pipeline_save_async (PhotosBaseItem *self,
 {
   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);
@@ -1915,17 +1924,11 @@ photos_base_item_pipeline_save_async (PhotosBaseItem *self,
   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);
 }
 
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
index c938cbb..2f2f667 100644
--- a/src/photos-pipeline.c
+++ b/src/photos-pipeline.c
@@ -38,6 +38,7 @@ struct _PhotosPipeline
   GHashTable *hash;
   GQueue *history;
   GeglNode *graph;
+  gchar *uri;
 };
 
 struct _PhotosPipelineClass
@@ -49,6 +50,7 @@ enum
 {
   PROP_0,
   PROP_PARENT,
+  PROP_URI
 };
 
 static void photos_pipeline_async_initable_iface_init (GAsyncInitableIface *iface);
@@ -147,6 +149,7 @@ photos_pipeline_finalize (GObject *object)
   PhotosPipeline *self = PHOTOS_PIPELINE (object);
 
   g_queue_free (self->history);
+  g_free (self->uri);
 
   G_OBJECT_CLASS (photos_pipeline_parent_class)->finalize (object);
 
@@ -165,6 +168,10 @@ photos_pipeline_set_property (GObject *object, guint prop_id, const GValue *valu
       self->parent = GEGL_NODE (g_value_dup_object (value));
       break;
 
+    case PROP_URI:
+      self->uri = g_value_dup_string (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -199,6 +206,14 @@ photos_pipeline_class_init (PhotosPipelineClass *class)
                                                         "A GeglNode representing the parent graph",
                                                         GEGL_TYPE_NODE,
                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_URI,
+                                   g_param_spec_string ("uri",
+                                                        "An URI",
+                                                        "The location to save this pipeline",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 }
 
 
@@ -244,6 +259,7 @@ photos_pipeline_async_initable_iface_init (GAsyncInitableIface *iface)
 
 void
 photos_pipeline_new_async (GeglNode *parent,
+                           const gchar *uri,
                            GCancellable *cancellable,
                            GAsyncReadyCallback callback,
                            gpointer user_data)
@@ -254,6 +270,7 @@ photos_pipeline_new_async (GeglNode *parent,
                               callback,
                               user_data,
                               "parent", parent,
+                              "uri", uri,
                               NULL);
 }
 
@@ -380,7 +397,6 @@ photos_pipeline_reset (PhotosPipeline *self)
 
 void
 photos_pipeline_save_async (PhotosPipeline *self,
-                            const gchar *uri,
                             GCancellable *cancellable,
                             GAsyncReadyCallback callback,
                             gpointer user_data)
@@ -396,7 +412,7 @@ photos_pipeline_save_async (PhotosPipeline *self,
   xml = photos_pipeline_to_xml (self);
   g_task_set_task_data (task, xml, g_free);
 
-  file = g_file_new_for_uri (uri);
+  file = g_file_new_for_uri (self->uri);
   len = strlen (xml);
   g_file_replace_contents_async (file,
                                  xml,
diff --git a/src/photos-pipeline.h b/src/photos-pipeline.h
index d0a6577..226402a 100644
--- a/src/photos-pipeline.h
+++ b/src/photos-pipeline.h
@@ -56,6 +56,7 @@ typedef struct _PhotosPipelineClass PhotosPipelineClass;
 GType                  photos_pipeline_get_type          (void) G_GNUC_CONST;
 
 void                   photos_pipeline_new_async         (GeglNode *parent,
+                                                          const gchar *uri,
                                                           GCancellable *cancellable,
                                                           GAsyncReadyCallback callback,
                                                           gpointer user_data);
@@ -82,7 +83,6 @@ GeglProcessor         *photos_pipeline_new_processor     (PhotosPipeline *self);
 void                   photos_pipeline_reset             (PhotosPipeline *self);
 
 void                   photos_pipeline_save_async        (PhotosPipeline *self,
-                                                          const gchar *uri,
                                                           GCancellable *cancellable,
                                                           GAsyncReadyCallback callback,
                                                           gpointer user_data);


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