[gnome-photos/wip/rishi/thumbnailer: 11/15] pipeline: Loosen the requirement to have a parent during construction



commit 08884e21f3c66ccf7cfd22741c76ae7306aeed49
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Feb 27 00:57:36 2017 +0100

    pipeline: Loosen the requirement to have a parent during construction

 src/photos-pipeline.c |   41 +++++++++++++++++++++++++++++++++--------
 src/photos-pipeline.h |    2 ++
 2 files changed, 35 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
index cdd4b6c..391d921 100644
--- a/src/photos-pipeline.c
+++ b/src/photos-pipeline.c
@@ -36,7 +36,6 @@
 struct _PhotosPipeline
 {
   GObject parent_instance;
-  GeglNode *parent;
   GHashTable *hash;
   GeglNode *graph;
   gchar *snapshot;
@@ -217,12 +216,9 @@ photos_pipeline_constructed (GObject *object)
 
   G_OBJECT_CLASS (photos_pipeline_parent_class)->constructed (object);
 
-  gegl_node_add_child (self->parent, self->graph);
   input = gegl_node_get_input_proxy (self->graph, "input");
   output = gegl_node_get_output_proxy (self->graph, "output");
   gegl_node_link (input, output);
-
-  g_clear_object (&self->parent); /* We will not need it any more */
 }
 
 
@@ -241,7 +237,6 @@ photos_pipeline_dispose (GObject *object)
   g_clear_pointer (&self->hash, (GDestroyNotify) g_hash_table_unref);
 
   g_clear_object (&self->graph);
-  g_clear_object (&self->parent);
 
   G_OBJECT_CLASS (photos_pipeline_parent_class)->dispose (object);
 }
@@ -269,8 +264,13 @@ photos_pipeline_set_property (GObject *object, guint prop_id, const GValue *valu
   switch (prop_id)
     {
     case PROP_PARENT:
-      self->parent = GEGL_NODE (g_value_dup_object (value));
-      break;
+      {
+        GeglNode *parent;
+
+        parent = GEGL_NODE (g_value_get_object (value));
+        photos_pipeline_set_parent (self, parent);
+        break;
+      }
 
     case PROP_URI:
       self->uri = g_value_dup_string (value);
@@ -309,7 +309,7 @@ photos_pipeline_class_init (PhotosPipelineClass *class)
                                                         "GeglNode object",
                                                         "A GeglNode representing the parent graph",
                                                         GEGL_TYPE_NODE,
-                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+                                                        G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
 
   g_object_class_install_property (object_class,
                                    PROP_URI,
@@ -426,6 +426,9 @@ photos_pipeline_new_async (GeglNode *parent,
                            GAsyncReadyCallback callback,
                            gpointer user_data)
 {
+  g_return_if_fail (parent == NULL || GEGL_IS_NODE (parent));
+  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
   g_async_initable_new_async (PHOTOS_TYPE_PIPELINE,
                               G_PRIORITY_DEFAULT,
                               cancellable,
@@ -443,6 +446,8 @@ photos_pipeline_new_finish (GAsyncResult *res, GError **error)
   GObject *ret_val;
   GObject *source_object;
 
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
   source_object = g_async_result_get_source_object (res);
   ret_val = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);
   g_object_unref (source_object);
@@ -718,6 +723,26 @@ photos_pipeline_revert_to_original (PhotosPipeline *self)
 
 
 void
+photos_pipeline_set_parent (PhotosPipeline *self, GeglNode *parent)
+{
+  GeglNode *old_parent;
+
+  g_return_if_fail (PHOTOS_IS_PIPELINE (self));
+  g_return_if_fail (parent == NULL || GEGL_IS_NODE (parent));
+
+  old_parent = gegl_node_get_parent (self->graph);
+  if (parent == old_parent)
+    return;
+
+  if (old_parent != NULL)
+    gegl_node_remove_child (old_parent, self->graph);
+
+  if (parent != NULL)
+    gegl_node_add_child (parent, self->graph);
+}
+
+
+void
 photos_pipeline_snapshot (PhotosPipeline *self)
 {
   g_free (self->snapshot);
diff --git a/src/photos-pipeline.h b/src/photos-pipeline.h
index 95dce75..b6f123d 100644
--- a/src/photos-pipeline.h
+++ b/src/photos-pipeline.h
@@ -88,6 +88,8 @@ void                   photos_pipeline_revert            (PhotosPipeline *self);
 
 void                   photos_pipeline_revert_to_original(PhotosPipeline *self);
 
+void                   photos_pipeline_set_parent        (PhotosPipeline *self, GeglNode *parent);
+
 void                   photos_pipeline_snapshot          (PhotosPipeline *self);
 
 G_END_DECLS


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