[gimp/goat-invasion: 264/401] app: factor out the creation of GeglOperation config proxy objects
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 264/401] app: factor out the creation of GeglOperation config proxy objects
- Date: Mon, 2 Apr 2012 12:10:19 +0000 (UTC)
commit b7848cbacef4cae042b40a2f51ab7b953b49f689
Author: Michael Natterer <mitch gimp org>
Date: Mon Mar 26 19:11:29 2012 +0200
app: factor out the creation of GeglOperation config proxy objects
app/Makefile.am | 3 +-
app/gegl/Makefile.am | 2 +
app/gegl/gimp-gegl-config-proxy.c | 199 +++++++++++++++++++++++++++++++++++++
app/gegl/gimp-gegl-config-proxy.h | 25 +++++
app/tools/gimpgegltool.c | 171 +-------------------------------
5 files changed, 231 insertions(+), 169 deletions(-)
---
diff --git a/app/Makefile.am b/app/Makefile.am
index 7cdad79..ee6e66d 100644
--- a/app/Makefile.am
+++ b/app/Makefile.am
@@ -147,7 +147,8 @@ AM_LDFLAGS = \
$(workaround_that_core_depends_on_xcf) \
$(workaround_that_core_depends_on_pdb) \
$(workaround_that_plug_in_depends_on_pdb) \
- $(workaround_that_file_depends_on_plug_in)
+ $(workaround_that_file_depends_on_plug_in) \
+ -u $(SYMPREFIX)gimp_param_spec_duplicate
gimpconsoleldadd = \
xcf/libappxcf.a \
diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am
index 59ee0b8..a47acaf 100644
--- a/app/gegl/Makefile.am
+++ b/app/gegl/Makefile.am
@@ -20,6 +20,8 @@ libappgegl_a_sources = \
gimp-gegl-types.h \
gimp-gegl.c \
gimp-gegl.h \
+ gimp-gegl-config-proxy.c \
+ gimp-gegl-config-proxy.h \
gimp-gegl-nodes.c \
gimp-gegl-nodes.h \
gimp-gegl-utils.c \
diff --git a/app/gegl/gimp-gegl-config-proxy.c b/app/gegl/gimp-gegl-config-proxy.c
new file mode 100644
index 0000000..4075597
--- /dev/null
+++ b/app/gegl/gimp-gegl-config-proxy.c
@@ -0,0 +1,199 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gegl.h>
+
+#include "libgimpconfig/gimpconfig.h"
+
+#include "gimp-gegl-types.h"
+
+#include "core/gimpobject.h"
+#include "core/gimpparamspecs-duplicate.h"
+
+#include "gimp-gegl-config-proxy.h"
+
+
+static GValue *
+gimp_gegl_config_value_new (GParamSpec *pspec)
+{
+ GValue *value = g_slice_new0 (GValue);
+
+ g_value_init (value, pspec->value_type);
+
+ return value;
+}
+
+static void
+gimp_gegl_config_value_free (GValue *value)
+{
+ g_value_unset (value);
+ g_slice_free (GValue, value);
+}
+
+static GHashTable *
+gimp_gegl_config_get_properties (GObject *object)
+{
+ GHashTable *properties = g_object_get_data (object, "properties");
+
+ if (! properties)
+ {
+ properties = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) gimp_gegl_config_value_free);
+
+ g_object_set_data_full (object, "properties", properties,
+ (GDestroyNotify) g_hash_table_unref);
+ }
+
+ return properties;
+}
+
+static GValue *
+gimp_gegl_config_value_get (GObject *object,
+ GParamSpec *pspec)
+{
+ GHashTable *properties = gimp_gegl_config_get_properties (object);
+ GValue *value;
+
+ value = g_hash_table_lookup (properties, pspec->name);
+
+ if (! value)
+ {
+ value = gimp_gegl_config_value_new (pspec);
+ g_hash_table_insert (properties, g_strdup (pspec->name), value);
+ }
+
+ return value;
+}
+
+static void
+gimp_gegl_config_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GValue *val = gimp_gegl_config_value_get (object, pspec);
+
+ g_value_copy (value, val);
+}
+
+static void
+gimp_gegl_config_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GValue *val = gimp_gegl_config_value_get (object, pspec);
+
+ g_value_copy (val, value);
+}
+
+static void
+gimp_gegl_config_class_init (GObjectClass *klass,
+ const gchar *operation)
+{
+ GParamSpec **pspecs;
+ guint n_pspecs;
+ gint i;
+
+ klass->set_property = gimp_gegl_config_set_property;
+ klass->get_property = gimp_gegl_config_get_property;
+
+ pspecs = gegl_list_properties (operation, &n_pspecs);
+
+ for (i = 0; i < n_pspecs; i++)
+ {
+ GParamSpec *pspec = pspecs[i];
+
+ if ((pspec->flags & G_PARAM_READABLE) &&
+ (pspec->flags & G_PARAM_WRITABLE) &&
+ strcmp (pspec->name, "input") &&
+ strcmp (pspec->name, "output"))
+ {
+ GParamSpec *copy = gimp_param_spec_duplicate (pspec);
+
+ if (copy)
+ {
+ g_object_class_install_property (klass, i + 1, copy);
+ }
+ }
+ }
+
+ g_free (pspecs);
+}
+
+GimpObject *
+gimp_gegl_get_config_proxy (const gchar *operation)
+{
+ static GHashTable *config_types = NULL;
+ GType config_type;
+
+ if (! config_types)
+ config_types = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+
+ config_type = (GType) g_hash_table_lookup (config_types, operation);
+
+ if (! config_type)
+ {
+ GTypeInfo info =
+ {
+ sizeof (GimpObjectClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gimp_gegl_config_class_init,
+ NULL, /* class_finalize */
+ operation,
+ sizeof (GimpObject),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) NULL,
+ };
+
+ const GInterfaceInfo config_info =
+ {
+ NULL, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ gchar *type_name = g_strdup_printf ("GimpGegl-%s-config",
+ operation);
+
+ g_strcanon (type_name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
+
+ config_type = g_type_register_static (GIMP_TYPE_OBJECT, type_name,
+ &info, 0);
+
+ g_free (type_name);
+
+ g_type_add_interface_static (config_type, GIMP_TYPE_CONFIG,
+ &config_info);
+
+ g_hash_table_insert (config_types,
+ g_strdup (operation),
+ (gpointer) config_type);
+ }
+
+ return g_object_new (config_type, NULL);
+}
diff --git a/app/gegl/gimp-gegl-config-proxy.h b/app/gegl/gimp-gegl-config-proxy.h
new file mode 100644
index 0000000..55298aa
--- /dev/null
+++ b/app/gegl/gimp-gegl-config-proxy.h
@@ -0,0 +1,25 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_GEGL_CONFIG_PROXY_H__
+#define __GIMP_GEGL_CONFIG_PROXY_H__
+
+
+GimpObject * gimp_gegl_get_config_proxy (const gchar *operation);
+
+
+#endif /* __GIMP_GEGL_CONFIG_PROXY_H__ */
diff --git a/app/tools/gimpgegltool.c b/app/tools/gimpgegltool.c
index e579eab..f29b85b 100644
--- a/app/tools/gimpgegltool.c
+++ b/app/tools/gimpgegltool.c
@@ -29,6 +29,8 @@
#include "tools-types.h"
+#include "gegl/gimp-gegl-config-proxy.h"
+
#include "core/gimpdrawable.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
@@ -458,173 +460,6 @@ gimp_gegl_tool_config_notify (GObject *object,
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
-static GValue *
-gimp_gegl_tool_config_value_new (GParamSpec *pspec)
-{
- GValue *value = g_slice_new0 (GValue);
-
- g_value_init (value, pspec->value_type);
-
- return value;
-}
-
-static void
-gimp_gegl_tool_config_value_free (GValue *value)
-{
- g_value_unset (value);
- g_slice_free (GValue, value);
-}
-
-static GHashTable *
-gimp_gegl_tool_config_get_properties (GObject *object)
-{
- GHashTable *properties = g_object_get_data (object, "properties");
-
- if (! properties)
- {
- properties = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) gimp_gegl_tool_config_value_free);
-
- g_object_set_data_full (object, "properties", properties,
- (GDestroyNotify) g_hash_table_unref);
- }
-
- return properties;
-}
-
-static GValue *
-gimp_gegl_tool_config_value_get (GObject *object,
- GParamSpec *pspec)
-{
- GHashTable *properties = gimp_gegl_tool_config_get_properties (object);
- GValue *value;
-
- value = g_hash_table_lookup (properties, pspec->name);
-
- if (! value)
- {
- value = gimp_gegl_tool_config_value_new (pspec);
- g_hash_table_insert (properties, g_strdup (pspec->name), value);
- }
-
- return value;
-}
-
-static void
-gimp_gegl_tool_config_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GValue *val = gimp_gegl_tool_config_value_get (object, pspec);
-
- g_value_copy (value, val);
-}
-
-static void
-gimp_gegl_tool_config_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GValue *val = gimp_gegl_tool_config_value_get (object, pspec);
-
- g_value_copy (val, value);
-}
-
-static void
-gimp_gegl_tool_config_class_init (GObjectClass *klass,
- const gchar *operation)
-{
- GParamSpec **pspecs;
- guint n_pspecs;
- gint i;
-
- klass->set_property = gimp_gegl_tool_config_set_property;
- klass->get_property = gimp_gegl_tool_config_get_property;
-
- pspecs = gegl_operation_list_properties (operation, &n_pspecs);
-
- for (i = 0; i < n_pspecs; i++)
- {
- GParamSpec *pspec = pspecs[i];
-
- if ((pspec->flags & G_PARAM_READABLE) &&
- (pspec->flags & G_PARAM_WRITABLE) &&
- strcmp (pspec->name, "input") &&
- strcmp (pspec->name, "output"))
- {
- GParamSpec *copy = gimp_param_spec_duplicate (pspec);
-
- if (copy)
- {
- g_object_class_install_property (klass, i + 1, copy);
- }
- }
- }
-
- g_free (pspecs);
-}
-
-static GimpObject *
-gimp_gegl_tool_get_config (GimpGeglTool *tool)
-{
- static GHashTable *config_types = NULL;
- GType config_type;
-
- if (! config_types)
- config_types = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
-
- config_type = (GType) g_hash_table_lookup (config_types, tool->operation);
-
- if (! config_type)
- {
- GTypeInfo info =
- {
- sizeof (GimpObjectClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gimp_gegl_tool_config_class_init,
- NULL, /* class_finalize */
- tool->operation,
- sizeof (GimpObject),
- 0, /* n_preallocs */
- (GInstanceInitFunc) NULL,
- };
-
- const GInterfaceInfo config_info =
- {
- NULL, /* interface_init */
- NULL, /* interface_finalize */
- NULL /* interface_data */
- };
-
- gchar *type_name = g_strdup_printf ("GimpGeglTool-%s-config",
- tool->operation);
-
- g_strcanon (type_name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
-
- config_type = g_type_register_static (GIMP_TYPE_OBJECT, type_name,
- &info, 0);
-
- g_free (type_name);
-
- g_type_add_interface_static (config_type, GIMP_TYPE_CONFIG,
- &config_info);
-
- g_hash_table_insert (config_types,
- g_strdup (tool->operation),
- (gpointer) config_type);
- }
-
- return g_object_new (config_type, NULL);
-}
-
static void
gimp_gegl_tool_operation_changed (GtkWidget *widget,
GimpGeglTool *tool)
@@ -669,7 +504,7 @@ gimp_gegl_tool_operation_changed (GtkWidget *widget,
gimp_image_map_tool_create_map (GIMP_IMAGE_MAP_TOOL (tool));
- tool->config = gimp_gegl_tool_get_config (tool);
+ tool->config = gimp_gegl_get_config_proxy (tool->operation);
if (tool->options_table)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]