[gimp] app: add gimp_gegl_get_op_enum_type() to get the GType of a gegl enum



commit 5b86b55e2adef918d763343d5b20b74c3ae21b44
Author: Michael Natterer <mitch gimp org>
Date:   Mon Sep 24 19:04:01 2012 +0200

    app: add gimp_gegl_get_op_enum_type() to get the GType of a gegl enum
    
    and use it in convert-precision-dialog.c

 app/dialogs/convert-precision-dialog.c |   10 ++++------
 app/gegl/gimp-gegl-utils.c             |   28 ++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-utils.h             |    3 +++
 3 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/app/dialogs/convert-precision-dialog.c b/app/dialogs/convert-precision-dialog.c
index bf06eaf..ade1817 100644
--- a/app/dialogs/convert-precision-dialog.c
+++ b/app/dialogs/convert-precision-dialog.c
@@ -25,6 +25,8 @@
 
 #include "dialogs-types.h"
 
+#include "gegl/gimp-gegl-utils.h"
+
 #include "core/gimp.h"
 #include "core/gimpcontext.h"
 #include "core/gimpimage.h"
@@ -88,8 +90,6 @@ convert_precision_dialog_new (GimpImage     *image,
   GtkSizeGroup  *size_group;
   const gchar   *enum_desc;
   gchar         *blurb;
-  GType          operation_type;
-  GParamSpec    *dither_pspec;
   GType          dither_type;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
@@ -155,10 +155,8 @@ convert_precision_dialog_new (GimpImage     *image,
 
   /*  dithering  */
 
-  operation_type = gegl_operation_gtype_from_name ("gegl:color-reduction");
-  dither_pspec = g_object_class_find_property (g_type_class_peek (operation_type),
-                                               "dither-strategy");
-  dither_type = G_TYPE_FROM_CLASS (G_PARAM_SPEC_ENUM (dither_pspec)->enum_class);
+  dither_type = gimp_gegl_get_op_enum_type ("gegl:color-reduction",
+                                            "dither-strategy");
 
   frame = gimp_frame_new (_("Dithering"));
   gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 7df86c0..3fdfecf 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -45,6 +45,34 @@ gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
   return "nearest";
 }
 
+GType
+gimp_gegl_get_op_enum_type (const gchar *operation,
+                            const gchar *property)
+{
+  GeglNode   *node;
+  GObject    *op;
+  GParamSpec *pspec;
+
+  g_return_val_if_fail (operation != NULL, G_TYPE_NONE);
+  g_return_val_if_fail (property != NULL, G_TYPE_NONE);
+
+  node = g_object_new (GEGL_TYPE_NODE,
+                       "operation", operation,
+                       NULL);
+  g_object_get (node, "gegl-operation", &op, NULL);
+  g_object_unref (node);
+
+  g_return_val_if_fail (op != NULL, G_TYPE_NONE);
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (op), property);
+
+  g_return_val_if_fail (G_IS_PARAM_SPEC_ENUM (pspec), G_TYPE_NONE);
+
+  g_object_unref (op);
+
+  return G_TYPE_FROM_CLASS (G_PARAM_SPEC_ENUM (pspec)->enum_class);
+}
+
 GeglColor *
 gimp_gegl_color_new (const GimpRGB *rgb)
 {
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index c680c7b..80fb74f 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -24,6 +24,9 @@
 
 const gchar * gimp_interpolation_to_gegl_filter (GimpInterpolationType  interpolation) G_GNUC_CONST;
 
+GType         gimp_gegl_get_op_enum_type        (const gchar           *operation,
+                                                 const gchar           *property);
+
 GeglColor   * gimp_gegl_color_new               (const GimpRGB         *rgb);
 
 void          gimp_gegl_progress_connect        (GeglNode              *node,



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