[gimp] app: add "progress" property to GimpSubProgress



commit 0f532787c9289eb3508c6790293764f31d0f26d4
Author: Ell <ell_se yahoo com>
Date:   Sun Mar 25 09:56:50 2018 -0400

    app: add "progress" property to GimpSubProgress
    
    Make the parent GimpProgress object of a GimpSubProgress instance
    settable through a property during construction, so that we can use
    it as a base class.

 app/core/gimpsubprogress.c |   74 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 69 insertions(+), 5 deletions(-)
---
diff --git a/app/core/gimpsubprogress.c b/app/core/gimpsubprogress.c
index 6256d83..5da22f2 100644
--- a/app/core/gimpsubprogress.c
+++ b/app/core/gimpsubprogress.c
@@ -25,9 +25,24 @@
 #include "core/gimpprogress.h"
 
 
+enum
+{
+  PROP_0,
+  PROP_PROGRESS
+};
+
+
 static void           gimp_sub_progress_iface_init    (GimpProgressInterface *iface);
 
 static void           gimp_sub_progress_finalize      (GObject             *object);
+static void           gimp_sub_progress_set_property  (GObject             *object,
+                                                       guint                property_id,
+                                                       const GValue        *value,
+                                                       GParamSpec          *pspec);
+static void           gimp_sub_progress_get_property  (GObject             *object,
+                                                       guint                property_id,
+                                                       GValue              *value,
+                                                       GParamSpec          *pspec);
 
 static GimpProgress * gimp_sub_progress_start         (GimpProgress        *progress,
                                                        gboolean             cancellable,
@@ -60,7 +75,16 @@ gimp_sub_progress_class_init (GimpSubProgressClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->finalize = gimp_sub_progress_finalize;
+  object_class->finalize     = gimp_sub_progress_finalize;
+  object_class->set_property = gimp_sub_progress_set_property;
+  object_class->get_property = gimp_sub_progress_get_property;
+
+  g_object_class_install_property (object_class, PROP_PROGRESS,
+                                   g_param_spec_object ("progress",
+                                                        NULL, NULL,
+                                                        GIMP_TYPE_PROGRESS,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -95,6 +119,47 @@ gimp_sub_progress_iface_init (GimpProgressInterface *iface)
   iface->message       = gimp_sub_progress_message;
 }
 
+static void
+gimp_sub_progress_set_property (GObject      *object,
+                                guint         property_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  GimpSubProgress *sub = GIMP_SUB_PROGRESS (object);
+
+  switch (property_id)
+    {
+    case PROP_PROGRESS:
+      g_return_if_fail (sub->progress == NULL);
+      sub->progress = g_value_dup_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_sub_progress_get_property (GObject    *object,
+                                guint       property_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  GimpSubProgress *sub = GIMP_SUB_PROGRESS (object);
+
+  switch (property_id)
+    {
+    case PROP_PROGRESS:
+      g_value_set_object (value, sub->progress);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
 static GimpProgress *
 gimp_sub_progress_start (GimpProgress *progress,
                          gboolean      cancellable,
@@ -205,10 +270,9 @@ gimp_sub_progress_new (GimpProgress *progress)
 
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
 
-  sub = g_object_new (GIMP_TYPE_SUB_PROGRESS, NULL);
-
-  if (progress)
-    sub->progress = g_object_ref (progress);
+  sub = g_object_new (GIMP_TYPE_SUB_PROGRESS,
+                      "progress", progress,
+                      NULL);
 
   return GIMP_PROGRESS (sub);
 }


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