[gegl] Move Meta redirect logic out of GeglNode



commit a34eb6550fc3bd004a3b225b5963f93ce6930966
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Sat Feb 1 22:29:04 2014 -0800

    Move Meta redirect logic out of GeglNode
    
    Handle the value propagation in OperationMeta instead of having
    a special case in Node.

 gegl/graph/gegl-node.c               |    8 ----
 gegl/operation/gegl-operation-meta.c |   62 +++++++++++++++++++++-------------
 gegl/operation/gegl-operation-meta.h |    2 +-
 3 files changed, 39 insertions(+), 33 deletions(-)
---
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index 193c14a..f9647ba 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -1100,14 +1100,6 @@ gegl_node_property_changed (GObject    *gobject,
 {
   GeglNode *self = GEGL_NODE (user_data);
 
-  if (self->operation &&
-      arg1 != user_data &&
-      g_type_is_a (G_OBJECT_TYPE (self->operation), GEGL_TYPE_OPERATION_META))
-    {
-      gegl_operation_meta_property_changed (
-        GEGL_OPERATION_META (self->operation), arg1, user_data);
-    }
-
   if (arg1 != user_data &&
       ((arg1 &&
         arg1->value_type != GEGL_TYPE_BUFFER) ||
diff --git a/gegl/operation/gegl-operation-meta.c b/gegl/operation/gegl-operation-meta.c
index 80610f1..f921e86 100644
--- a/gegl/operation/gegl-operation-meta.c
+++ b/gegl/operation/gegl-operation-meta.c
@@ -25,10 +25,14 @@
 #include "gegl-operation-meta.h"
 
 static void       finalize     (GObject       *self_object);
+
 static GeglNode * detect       (GeglOperation *operation,
                                 gint           x,
                                 gint           y);
 
+static GObject *   constructor (GType                  gtype,
+                                guint                  n_properties,
+                                GObjectConstructParam *properties);
 
 G_DEFINE_TYPE (GeglOperationMeta, gegl_operation_meta, GEGL_TYPE_OPERATION)
 
@@ -39,6 +43,7 @@ gegl_operation_meta_class_init (GeglOperationMetaClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize               = finalize;
+  object_class->constructor            = constructor;
   GEGL_OPERATION_CLASS (klass)->detect = detect;
 }
 
@@ -48,6 +53,18 @@ gegl_operation_meta_init (GeglOperationMeta *self)
   self->redirects = NULL;
 }
 
+static GObject *
+constructor (GType                  gtype,
+             guint                  n_properties,
+             GObjectConstructParam *properties)
+{
+  GObject *operation = G_OBJECT_CLASS (gegl_operation_meta_parent_class)->constructor (gtype, n_properties, 
properties);
+
+  g_signal_connect (operation, "notify", G_CALLBACK (gegl_operation_meta_property_changed), NULL);
+
+  return operation;
+}
+
 static GeglNode *
 detect (GeglOperation *operation,
         gint           x,
@@ -115,14 +132,11 @@ redirect_destroy (Redirect *self)
   g_slice_free (Redirect, self);
 }
 
-/* FIXME: take GeglNode's as parameters, since we need
- * extra behavior provided by GeglNode on top of GObject.
- */
 static void
-gegl_node_copy_property_property (GObject     *source,
-                                  const gchar *source_property,
-                                  GObject     *destination,
-                                  const gchar *destination_property)
+gegl_node_copy_property_property (GeglOperation *source,
+                                  const gchar   *source_property,
+                                  GeglOperation *destination,
+                                  const gchar   *destination_property)
 {
   GValue      value = { 0 };
   GParamSpec *spec  = g_object_class_find_property (G_OBJECT_GET_CLASS (source),
@@ -130,8 +144,8 @@ gegl_node_copy_property_property (GObject     *source,
 
   g_assert (spec);
   g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
-  gegl_node_get_property (GEGL_OPERATION (source)->node, source_property, &value);
-  gegl_node_set_property (GEGL_OPERATION (destination)->node, destination_property, &value);
+  gegl_node_get_property (source->node, source_property, &value);
+  gegl_node_set_property (destination->node, destination_property, &value);
   g_value_unset (&value);
 }
 
@@ -147,31 +161,31 @@ gegl_operation_meta_redirect (GeglOperation *operation,
   self->redirects = g_slist_prepend (self->redirects, redirect);
 
   /* set default value */
-  gegl_node_copy_property_property (G_OBJECT (operation),
+  gegl_node_copy_property_property (operation,
                                     redirect->name,
-                                    G_OBJECT (gegl_node_get_gegl_operation (internal)),
+                                    gegl_node_get_gegl_operation (internal),
                                     redirect->internal_name);
 }
 
 void
 gegl_operation_meta_property_changed (GeglOperationMeta *self,
-                                      GParamSpec        *arg1,
+                                      GParamSpec        *pspec,
                                       gpointer           user_data)
 {
-  g_assert (GEGL_IS_OPERATION_META (self));
-  if (arg1)
+  GSList *iter;
+
+  g_return_if_fail (GEGL_IS_OPERATION_META (self));
+  g_return_if_fail (pspec);
+
+  for (iter = self->redirects; iter; iter = iter->next)
     {
-      GSList *iter = self->redirects;
-      while (iter)
+      Redirect *redirect = iter->data;
+
+      if (!strcmp (redirect->name, pspec->name))
         {
-          Redirect *redirect = iter->data;
-          if (!strcmp (redirect->name, arg1->name))
-            {
-              gegl_node_copy_property_property (G_OBJECT (self), arg1->name,
-                                                G_OBJECT (gegl_node_get_gegl_operation (redirect->internal)),
-                                                redirect->internal_name);
-            }
-          iter = iter->next;
+          gegl_node_copy_property_property (GEGL_OPERATION (self), pspec->name,
+                                            gegl_node_get_gegl_operation (redirect->internal),
+                                            redirect->internal_name);
         }
     }
 }
diff --git a/gegl/operation/gegl-operation-meta.h b/gegl/operation/gegl-operation-meta.h
index 6eaf6c7..5841145 100644
--- a/gegl/operation/gegl-operation-meta.h
+++ b/gegl/operation/gegl-operation-meta.h
@@ -60,7 +60,7 @@ void  gegl_operation_meta_redirect         (GeglOperation     *operation,
                                             const gchar       *internal_name);
 
 void  gegl_operation_meta_property_changed (GeglOperationMeta *self,
-                                            GParamSpec        *arg1,
+                                            GParamSpec        *pspec,
                                             gpointer           user_data);
 
 G_END_DECLS


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