[gimp/goat-invasion] app: add gimp_gegl_progress_connect()



commit 5e013b81025f9e9785ffdf266285cc62a4e3c6d8
Author: Michael Natterer <mitch gimp org>
Date:   Tue Mar 27 17:06:44 2012 +0200

    app: add gimp_gegl_progress_connect()
    
    which connects to notify::progress of the operation inside a node an
    updates a GimpProgress accordingly.

 app/gegl/gimp-gegl-utils.c |   57 ++++++++++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-utils.h |    4 +++
 2 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index bf3b9d8..fa8e61e 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -27,6 +27,8 @@
 #include "base/temp-buf.h"
 #include "base/tile-manager.h"
 
+#include "core/gimpprogress.h"
+
 #include "gimp-gegl-utils.h"
 #include "gimptilebackendtilemanager.h"
 
@@ -290,3 +292,58 @@ gimp_gegl_color_new (const GimpRGB *rgb)
 
   return color;
 }
+
+static void
+gimp_gegl_progress_notify (GObject          *object,
+                           const GParamSpec *pspec,
+                           GimpProgress     *progress)
+{
+  const gchar *text;
+  gdouble      value;
+
+  g_object_get (object, "progress", &value, NULL);
+
+  text = g_object_get_data (object, "gimp-progress-text");
+
+  if (text)
+    {
+      if (value == 0.0)
+        {
+          gimp_progress_start (progress, text, FALSE);
+          return;
+        }
+      else if (value == 1.0)
+        {
+          gimp_progress_end (progress);
+          return;
+        }
+    }
+
+  gimp_progress_set_value (progress, value);
+}
+
+void
+gimp_gegl_progress_connect (GeglNode     *node,
+                            GimpProgress *progress,
+                            const gchar  *text)
+{
+  GObject *operation = NULL;
+
+  g_return_if_fail (GEGL_IS_NODE (node));
+  g_return_if_fail (GIMP_IS_PROGRESS (progress));
+
+  g_object_get (node, "gegl-operation", &operation, NULL);
+
+  g_return_if_fail (operation != NULL);
+
+  g_signal_connect (operation, "notify::progress",
+                    G_CALLBACK (gimp_gegl_progress_notify),
+                    progress);
+
+  if (text)
+    g_object_set_data_full (operation,
+                            "gimp-progress-text", g_strdup (text),
+                            (GDestroyNotify) g_free);
+
+  g_object_unref (operation);
+}
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index 959db0b..fdbb89c 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -50,6 +50,10 @@ void          gimp_gegl_buffer_refetch_tiles     (GeglBuffer            *buffer)
 
 GeglColor   * gimp_gegl_color_new                (const GimpRGB         *rgb);
 
+void          gimp_gegl_progress_connect         (GeglNode              *node,
+                                                  GimpProgress          *progress,
+                                                  const gchar           *text);
+
 #define       GIMP_GEGL_RECT(x,y,w,h)            (&((GeglRectangle){(x), (y), (w), (h)}))
 
 #endif /* __GIMP_GEGL_UTILS_H__ */



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