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



commit c1a645df872c92ce3676f4bb916a6b31029e02f8
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 |   36 ++++++++++++++++++++++++++++--------
 src/photos-pipeline.h |    2 ++
 2 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
index 2376920..38462ea 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;
@@ -212,12 +211,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 */
 }
 
 
@@ -236,7 +232,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);
 }
@@ -264,8 +259,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);
@@ -304,7 +304,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,
@@ -713,6 +713,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 99c287d..a13249c 100644
--- a/src/photos-pipeline.h
+++ b/src/photos-pipeline.h
@@ -76,6 +76,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]