[gimp] app: add GimpPDBContext which holds more state available to procedures



commit 2066545b913acd5cb077987779f41e0a34e2d4e7
Author: Michael Natterer <mitch gimp org>
Date:   Sat Sep 4 22:17:01 2010 +0200

    app: add GimpPDBContext which holds more state available to procedures
    
    Initially contains antialias, feather and feather radius for the
    upcoming gimp-item-to-selection preocedure. Keeping states in the
    context reduces the number of parameters of procedures, and both the
    state API and the API using the states can be changed/deprecated
    independently. Make sure that all procedures and all plug-ins get
    GimpPDBContexts instead of plain GimpContexts passed.

 app/pdb/Makefile.am                     |    2 +
 app/pdb/gimppdbcontext.c                |  184 +++++++++++++++++++++++++++++++
 app/pdb/gimppdbcontext.h                |   61 ++++++++++
 app/pdb/gimpprocedure.c                 |   15 +++-
 app/plug-in/gimpplugin-context.c        |    6 +-
 app/plug-in/gimpplugin.c                |    7 +-
 app/plug-in/gimppluginmanager-call.c    |   11 +-
 app/plug-in/gimppluginmanager-restore.c |    7 +-
 app/plug-in/gimppluginprocframe.c       |    6 +-
 9 files changed, 283 insertions(+), 16 deletions(-)
---
diff --git a/app/pdb/Makefile.am b/app/pdb/Makefile.am
index 37c5127..f59e5b3 100644
--- a/app/pdb/Makefile.am
+++ b/app/pdb/Makefile.am
@@ -25,6 +25,8 @@ libapppdb_a_SOURCES = \
 	gimppdb-query.h			\
 	gimppdb-utils.c			\
 	gimppdb-utils.h			\
+	gimppdbcontext.c		\
+	gimppdbcontext.h		\
 	gimppdberror.c			\
 	gimppdberror.h			\
 	gimpprocedure.c			\
diff --git a/app/pdb/gimppdbcontext.c b/app/pdb/gimppdbcontext.c
new file mode 100644
index 0000000..2e8e0bc
--- /dev/null
+++ b/app/pdb/gimppdbcontext.c
@@ -0,0 +1,184 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
+ *
+ * gimppdbcontext.c
+ *
+ * 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 <gegl.h>
+
+#include "libgimpconfig/gimpconfig.h"
+
+#include "pdb-types.h"
+
+#include "core/gimp.h"
+
+#include "gimppdbcontext.h"
+
+#include "gimp-intl.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_ANTIALIAS,
+  PROP_FEATHER,
+  PROP_FEATHER_RADIUS_X,
+  PROP_FEATHER_RADIUS_Y
+};
+
+
+static void   gimp_pdb_context_set_property (GObject      *object,
+                                             guint         property_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec);
+static void   gimp_pdb_context_get_property (GObject      *object,
+                                             guint         property_id,
+                                             GValue       *value,
+                                             GParamSpec   *pspec);
+
+
+G_DEFINE_TYPE (GimpPDBContext, gimp_pdb_context, GIMP_TYPE_CONTEXT)
+
+#define parent_class gimp_pdb_context_parent_class
+
+
+static void
+gimp_pdb_context_class_init (GimpPDBContextClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = gimp_pdb_context_set_property;
+  object_class->get_property = gimp_pdb_context_get_property;
+
+  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_ANTIALIAS,
+                                    "antialias",
+                                    N_("Smooth edges"),
+                                    TRUE,
+                                    GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FEATHER,
+                                    "feather", NULL,
+                                    FALSE,
+                                    GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FEATHER_RADIUS_X,
+                                   "feather-radius-x", NULL,
+                                   0.0, 100.0, 10.0,
+                                   GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FEATHER_RADIUS_Y,
+                                   "feather-radius-y", NULL,
+                                   0.0, 100.0, 10.0,
+                                   GIMP_PARAM_STATIC_STRINGS);
+}
+
+static void
+gimp_pdb_context_init (GimpPDBContext *options)
+{
+}
+
+static void
+gimp_pdb_context_set_property (GObject      *object,
+                               guint         property_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  GimpPDBContext *options = GIMP_PDB_CONTEXT (object);
+
+  switch (property_id)
+    {
+    case PROP_ANTIALIAS:
+      options->antialias = g_value_get_boolean (value);
+      break;
+
+    case PROP_FEATHER:
+      options->feather = g_value_get_boolean (value);
+      break;
+
+    case PROP_FEATHER_RADIUS_X:
+      options->feather_radius_x = g_value_get_double (value);
+      break;
+
+    case PROP_FEATHER_RADIUS_Y:
+      options->feather_radius_y = g_value_get_double (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_pdb_context_get_property (GObject    *object,
+                               guint       property_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GimpPDBContext *options = GIMP_PDB_CONTEXT (object);
+
+  switch (property_id)
+    {
+    case PROP_ANTIALIAS:
+      g_value_set_boolean (value, options->antialias);
+      break;
+
+    case PROP_FEATHER:
+      g_value_set_boolean (value, options->feather);
+      break;
+
+    case PROP_FEATHER_RADIUS_X:
+      g_value_set_double (value, options->feather_radius_x);
+      break;
+
+    case PROP_FEATHER_RADIUS_Y:
+      g_value_set_double (value, options->feather_radius_y);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+GimpContext *
+gimp_pdb_context_new (Gimp        *gimp,
+                      GimpContext *parent,
+                      gboolean     set_parent)
+{
+  GimpContext *context;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+  g_return_val_if_fail (GIMP_IS_CONTEXT (parent), NULL);
+
+  context = g_object_new (GIMP_TYPE_PDB_CONTEXT,
+                          "gimp", gimp,
+                          "name", "PDB Context",
+                          NULL);
+
+  gimp_config_sync (G_OBJECT (parent), G_OBJECT (context), 0);
+
+  if (set_parent)
+    {
+      gimp_context_define_properties (context,
+                                      GIMP_CONTEXT_ALL_PROPS_MASK, FALSE);
+      gimp_context_set_parent (context, parent);
+    }
+
+  return context;
+}
diff --git a/app/pdb/gimppdbcontext.h b/app/pdb/gimppdbcontext.h
new file mode 100644
index 0000000..b8c0d3a
--- /dev/null
+++ b/app/pdb/gimppdbcontext.h
@@ -0,0 +1,61 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
+ *
+ * gimppdbcontext.h
+ *
+ * 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_PDB_CONTEXT_H__
+#define __GIMP_PDB_CONTEXT_H__
+
+
+#include "core/gimpcontext.h"
+
+
+#define GIMP_TYPE_PDB_CONTEXT            (gimp_pdb_context_get_type ())
+#define GIMP_PDB_CONTEXT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PDB_CONTEXT, GimpPDBContext))
+#define GIMP_PDB_CONTEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PDB_CONTEXT, GimpPDBContextClass))
+#define GIMP_IS_PDB_CONTEXT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PDB_CONTEXT))
+#define GIMP_IS_PDB_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PDB_CONTEXT))
+#define GIMP_PDB_CONTEXT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PDB_CONTEXT, GimpPDBContextClass))
+
+
+typedef struct _GimpPDBContext      GimpPDBContext;
+typedef struct _GimpPDBContextClass GimpPDBContextClass;
+
+struct _GimpPDBContext
+{
+  GimpContext  parent_instance;
+
+  gboolean     antialias;
+  gboolean     feather;
+  gdouble      feather_radius_x;
+  gdouble      feather_radius_y;
+};
+
+struct _GimpPDBContextClass
+{
+  GimpContextClass  parent_class;
+};
+
+
+GType         gimp_pdb_context_get_type (void) G_GNUC_CONST;
+
+GimpContext * gimp_pdb_context_new      (Gimp        *gimp,
+                                         GimpContext *parent,
+                                         gboolean     set_parent);
+
+
+#endif  /*  __GIMP_PDB_CONTEXT_H__  */
diff --git a/app/pdb/gimpprocedure.c b/app/pdb/gimpprocedure.c
index c1c61bf..370d32f 100644
--- a/app/pdb/gimpprocedure.c
+++ b/app/pdb/gimpprocedure.c
@@ -29,7 +29,6 @@
 
 #include "core/gimp.h"
 #include "core/gimp-utils.h"
-#include "core/gimpcontext.h"
 #include "core/gimpchannel.h"
 #include "core/gimplayer.h"
 #include "core/gimpparamspecs.h"
@@ -37,6 +36,7 @@
 
 #include "vectors/gimpvectors.h"
 
+#include "gimppdbcontext.h"
 #include "gimppdberror.h"
 #include "gimpprocedure.h"
 
@@ -323,6 +323,11 @@ gimp_procedure_execute (GimpProcedure  *procedure,
       return return_vals;
     }
 
+  if (GIMP_IS_PDB_CONTEXT (context))
+    context = g_object_ref (context);
+  else
+    context = gimp_pdb_context_new (gimp, context, TRUE);
+
   /*  call the procedure  */
   return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->execute (procedure,
                                                                gimp,
@@ -331,6 +336,7 @@ gimp_procedure_execute (GimpProcedure  *procedure,
                                                                args,
                                                                error);
 
+  g_object_unref (context);
 
   if (return_vals)
     {
@@ -398,9 +404,16 @@ gimp_procedure_execute_async (GimpProcedure  *procedure,
                                     procedure->args, procedure->num_args,
                                     args, FALSE, error))
     {
+      if (GIMP_IS_PDB_CONTEXT (context))
+        context = g_object_ref (context);
+      else
+        context = gimp_pdb_context_new (gimp, context, TRUE);
+
       GIMP_PROCEDURE_GET_CLASS (procedure)->execute_async (procedure, gimp,
                                                            context, progress,
                                                            args, display);
+
+      g_object_unref (context);
     }
 }
 
diff --git a/app/plug-in/gimpplugin-context.c b/app/plug-in/gimpplugin-context.c
index 6df5126..5174961 100644
--- a/app/plug-in/gimpplugin-context.c
+++ b/app/plug-in/gimpplugin-context.c
@@ -24,7 +24,8 @@
 #include "plug-in-types.h"
 
 #include "core/gimp.h"
-#include "core/gimpcontext.h"
+
+#include "pdb/gimppdbcontext.h"
 
 #include "gimpplugin.h"
 #include "gimpplugin-context.h"
@@ -47,8 +48,7 @@ gimp_plug_in_context_push (GimpPlugIn *plug_in)
   else
     parent = proc_frame->main_context;
 
-  context = gimp_context_new (plug_in->manager->gimp, "plug-in context", NULL);
-  gimp_context_copy_properties (parent, context, GIMP_CONTEXT_ALL_PROPS_MASK);
+  context = gimp_pdb_context_new (plug_in->manager->gimp, parent, FALSE);
 
   proc_frame->context_stack = g_list_prepend (proc_frame->context_stack,
                                               context);
diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c
index d371332..40f2cdc 100644
--- a/app/plug-in/gimpplugin.c
+++ b/app/plug-in/gimpplugin.c
@@ -79,9 +79,10 @@
 #include "plug-in-types.h"
 
 #include "core/gimp.h"
-#include "core/gimpcontext.h"
 #include "core/gimpprogress.h"
 
+#include "pdb/gimppdbcontext.h"
+
 #include "gimpenvirontable.h"
 #include "gimpinterpreterdb.h"
 #include "gimpplugin.h"
@@ -191,7 +192,7 @@ gimp_plug_in_new (GimpPlugInManager   *manager,
   GimpPlugIn *plug_in;
 
   g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL);
-  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
   g_return_val_if_fail (procedure == NULL ||
                         GIMP_IS_PLUG_IN_PROCEDURE (procedure), NULL);
@@ -773,7 +774,7 @@ gimp_plug_in_proc_frame_push (GimpPlugIn             *plug_in,
   GimpPlugInProcFrame *proc_frame;
 
   g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
-  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
   g_return_val_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (procedure), NULL);
 
diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c
index 00d4a54..71de9e3 100644
--- a/app/plug-in/gimppluginmanager-call.c
+++ b/app/plug-in/gimppluginmanager-call.c
@@ -34,9 +34,10 @@
 #include "composite/gimp-composite.h"
 
 #include "core/gimp.h"
-#include "core/gimpcontext.h"
 #include "core/gimpprogress.h"
 
+#include "pdb/gimppdbcontext.h"
+
 #include "gimpplugin.h"
 #include "gimpplugin-message.h"
 #include "gimpplugindef.h"
@@ -61,7 +62,7 @@ gimp_plug_in_manager_call_query (GimpPlugInManager *manager,
   GimpPlugIn *plug_in;
 
   g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
-  g_return_if_fail (GIMP_IS_CONTEXT (context));
+  g_return_if_fail (GIMP_IS_PDB_CONTEXT (context));
   g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));
 
   plug_in = gimp_plug_in_new (manager, context, NULL,
@@ -101,7 +102,7 @@ gimp_plug_in_manager_call_init (GimpPlugInManager *manager,
   GimpPlugIn *plug_in;
 
   g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
-  g_return_if_fail (GIMP_IS_CONTEXT (context));
+  g_return_if_fail (GIMP_IS_PDB_CONTEXT (context));
   g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));
 
   plug_in = gimp_plug_in_new (manager, context, NULL,
@@ -146,7 +147,7 @@ gimp_plug_in_manager_call_run (GimpPlugInManager   *manager,
   GimpPlugIn  *plug_in;
 
   g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL);
-  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
   g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (procedure), NULL);
   g_return_val_if_fail (args != NULL, NULL);
@@ -292,7 +293,7 @@ gimp_plug_in_manager_call_run_temp (GimpPlugInManager      *manager,
   GimpPlugIn  *plug_in;
 
   g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL);
-  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
   g_return_val_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (procedure), NULL);
   g_return_val_if_fail (args != NULL, NULL);
diff --git a/app/plug-in/gimppluginmanager-restore.c b/app/plug-in/gimppluginmanager-restore.c
index 551271e..d211838 100644
--- a/app/plug-in/gimppluginmanager-restore.c
+++ b/app/plug-in/gimppluginmanager-restore.c
@@ -31,9 +31,9 @@
 #include "config/gimpcoreconfig.h"
 
 #include "core/gimp.h"
-#include "core/gimpcontext.h"
 
 #include "pdb/gimppdb.h"
+#include "pdb/gimppdbcontext.h"
 
 #include "gimpinterpreterdb.h"
 #include "gimpplugindef.h"
@@ -94,6 +94,9 @@ gimp_plug_in_manager_restore (GimpPlugInManager  *manager,
 
   gimp = manager->gimp;
 
+  /* need a GimpPDBContext for calling gimp_plug_in_manager_run_foo() */
+  context = gimp_pdb_context_new (gimp, context, TRUE);
+
   /* search for binaries in the plug-in directory path */
   gimp_plug_in_manager_search (manager, status_callback);
 
@@ -189,6 +192,8 @@ gimp_plug_in_manager_restore (GimpPlugInManager  *manager,
                             gimp_plug_in_manager_file_proc_compare, manager);
 
   gimp_plug_in_manager_run_extensions (manager, context, status_callback);
+
+  g_object_unref (context);
 }
 
 
diff --git a/app/plug-in/gimppluginprocframe.c b/app/plug-in/gimppluginprocframe.c
index 94f6004..a0be2ae 100644
--- a/app/plug-in/gimppluginprocframe.c
+++ b/app/plug-in/gimppluginprocframe.c
@@ -25,9 +25,9 @@
 
 #include "plug-in-types.h"
 
-#include "core/gimpcontext.h"
 #include "core/gimpprogress.h"
 
+#include "pdb/gimppdbcontext.h"
 #include "pdb/gimppdberror.h"
 
 #include "gimpplugin.h"
@@ -47,7 +47,7 @@ gimp_plug_in_proc_frame_new (GimpContext         *context,
 {
   GimpPlugInProcFrame *proc_frame;
 
-  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
   g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (procedure), NULL);
 
@@ -67,7 +67,7 @@ gimp_plug_in_proc_frame_init (GimpPlugInProcFrame *proc_frame,
                               GimpPlugInProcedure *procedure)
 {
   g_return_if_fail (proc_frame != NULL);
-  g_return_if_fail (GIMP_IS_CONTEXT (context));
+  g_return_if_fail (GIMP_IS_PDB_CONTEXT (context));
   g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
   g_return_if_fail (procedure == NULL ||
                     GIMP_IS_PLUG_IN_PROCEDURE (procedure));



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