[gimp] app, libgimp*: add protocol support for GValues holding a GParamSpec
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app, libgimp*: add protocol support for GValues holding a GParamSpec
- Date: Mon, 5 Aug 2019 08:50:15 +0000 (UTC)
commit aa505b43dc6b2a2ac0a9ae3405af2c58869d0e7b
Author: Michael Natterer <mitch gimp org>
Date: Mon Aug 5 00:58:44 2019 +0200
app, libgimp*: add protocol support for GValues holding a GParamSpec
so we can have PDB introspection procedures for the new plug-in API.
app/plug-in/Makefile.am | 1 -
app/plug-in/gimpgpparams.c | 4 +-
app/plug-in/gimpgpparams.h | 45 ---
app/plug-in/gimpplugin-message.c | 12 +-
app/plug-in/gimppluginmanager-call.c | 3 +-
app/plug-in/plug-in-rc.c | 3 +-
libgimp/gimp.c | 3 +-
libgimp/gimpgpparams-body.c | 573 +++++++++++++++++++----------------
libgimp/gimpgpparams.c | 169 +++++++++++
libgimp/gimpgpparams.h | 15 +-
libgimp/gimplegacy.c | 3 +-
libgimp/gimpplugin-private.c | 3 +-
libgimpbase/gimpprotocol.c | 18 ++
libgimpbase/gimpprotocol.h | 4 +-
14 files changed, 533 insertions(+), 323 deletions(-)
---
diff --git a/app/plug-in/Makefile.am b/app/plug-in/Makefile.am
index 248b96d6c3..45dfcc3654 100644
--- a/app/plug-in/Makefile.am
+++ b/app/plug-in/Makefile.am
@@ -21,7 +21,6 @@ libappplug_in_a_SOURCES = \
gimpenvirontable.c \
gimpenvirontable.h \
gimpgpparams.c \
- gimpgpparams.h \
gimpinterpreterdb.c \
gimpinterpreterdb.h \
gimpplugindebug.c \
diff --git a/app/plug-in/gimpgpparams.c b/app/plug-in/gimpgpparams.c
index f01eb9def5..35356d1392 100644
--- a/app/plug-in/gimpgpparams.c
+++ b/app/plug-in/gimpgpparams.c
@@ -33,7 +33,7 @@
#include "core/gimp.h"
#include "core/gimpparamspecs.h"
-#include "gimpgpparams.h"
+#include "libgimp/gimpgpparams.h"
/* public functions */
@@ -49,7 +49,7 @@
#include "../../libgimp/gimpgpparams-body.c"
GParamSpec *
-_gimp_gp_param_def_to_param_spec (Gimp *gimp,
+_gimp_gp_param_def_to_param_spec (gpointer gimp,
GPParamDef *param_def)
{
const gchar *name = param_def->name;
diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c
index 1d7caf143c..786706a78c 100644
--- a/app/plug-in/gimpplugin-message.c
+++ b/app/plug-in/gimpplugin-message.c
@@ -28,6 +28,8 @@
#include "libgimpbase/gimpprotocol.h"
#include "libgimpbase/gimpwire.h"
+#include "libgimp/gimpgpparams.h"
+
#include "plug-in-types.h"
#include "gegl/gimp-babl.h"
@@ -41,7 +43,6 @@
#include "pdb/gimppdb.h"
#include "pdb/gimppdberror.h"
-#include "gimpgpparams.h"
#include "gimpplugin.h"
#include "gimpplugin-cleanup.h"
#include "gimpplugin-message.h"
@@ -566,7 +567,8 @@ gimp_plug_in_handle_proc_run (GimpPlugIn *plug_in,
if (! proc_name)
proc_name = canonical;
- args = _gimp_gp_params_to_value_array (procedure ? procedure->args : NULL,
+ args = _gimp_gp_params_to_value_array (plug_in->manager->gimp,
+ procedure ? procedure->args : NULL,
procedure ? procedure->num_args : 0,
proc_run->params,
proc_run->nparams,
@@ -635,7 +637,8 @@ gimp_plug_in_handle_proc_return (GimpPlugIn *plug_in,
g_return_if_fail (proc_return != NULL);
proc_frame->return_vals =
- _gimp_gp_params_to_value_array (proc_frame->procedure->values,
+ _gimp_gp_params_to_value_array (plug_in->manager->gimp,
+ proc_frame->procedure->values,
proc_frame->procedure->num_values,
proc_return->params,
proc_return->nparams,
@@ -670,7 +673,8 @@ gimp_plug_in_handle_temp_proc_return (GimpPlugIn *plug_in,
GimpPlugInProcFrame *proc_frame = plug_in->temp_proc_frames->data;
proc_frame->return_vals =
- _gimp_gp_params_to_value_array (proc_frame->procedure->values,
+ _gimp_gp_params_to_value_array (plug_in->manager->gimp,
+ proc_frame->procedure->values,
proc_frame->procedure->num_values,
proc_return->params,
proc_return->nparams,
diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c
index 82604fdfbe..616c8a6a9f 100644
--- a/app/plug-in/gimppluginmanager-call.c
+++ b/app/plug-in/gimppluginmanager-call.c
@@ -30,6 +30,8 @@
#include "libgimpbase/gimpprotocol.h"
#include "libgimpbase/gimpwire.h"
+#include "libgimp/gimpgpparams.h"
+
#include "plug-in-types.h"
#include "config/gimpguiconfig.h"
@@ -39,7 +41,6 @@
#include "pdb/gimppdbcontext.h"
-#include "gimpgpparams.h"
#include "gimpplugin.h"
#include "gimpplugin-message.h"
#include "gimpplugindef.h"
diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c
index c470b8884e..790060dfbc 100644
--- a/app/plug-in/plug-in-rc.c
+++ b/app/plug-in/plug-in-rc.c
@@ -27,11 +27,12 @@
#include "libgimpbase/gimpprotocol.h"
#include "libgimpconfig/gimpconfig.h"
+#include "libgimp/gimpgpparams.h"
+
#include "plug-in-types.h"
#include "core/gimp.h"
-#include "gimpgpparams.h"
#include "gimpplugindef.h"
#include "gimppluginprocedure.h"
#include "plug-in-rc.h"
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index f2e8fd39d1..bfb71b9db3 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -748,7 +748,8 @@ gimp_run_procedure_with_array (const gchar *name,
proc_return = msg.data;
- return_values = _gimp_gp_params_to_value_array (NULL, 0,
+ return_values = _gimp_gp_params_to_value_array (NULL,
+ NULL, 0,
proc_return->params,
proc_return->nparams,
TRUE, FALSE);
diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c
index 30b59118f8..c0e726376f 100644
--- a/libgimp/gimpgpparams-body.c
+++ b/libgimp/gimpgpparams-body.c
@@ -158,8 +158,168 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
}
}
+void
+_gimp_gp_param_to_value (gpointer gimp,
+ GPParam *param,
+ GType type,
+ GValue *value,
+ gboolean full_copy)
+{
+ g_return_if_fail (param != NULL);
+ g_return_if_fail (value != NULL);
+
+ if (type == G_TYPE_NONE)
+ type = g_type_from_name (param->type_name);
+
+ g_value_init (value, type);
+
+ if (type == G_TYPE_INT ||
+ type == GIMP_TYPE_INT32 ||
+ type == GIMP_TYPE_INT16 ||
+ type == GIMP_TYPE_UNIT)
+ {
+ g_value_set_int (value, param->data.d_int);
+ }
+ else if (G_VALUE_HOLDS_UINT (value))
+ {
+ g_value_set_uint (value, param->data.d_int);
+ }
+ else if (G_VALUE_HOLDS_ENUM (value))
+ {
+ g_value_set_enum (value, param->data.d_int);
+ }
+ else if (G_VALUE_HOLDS_BOOLEAN (value))
+ {
+ g_value_set_boolean (value, param->data.d_int ? TRUE : FALSE);
+ }
+ else if (G_VALUE_HOLDS_DOUBLE (value))
+ {
+ g_value_set_double (value, param->data.d_float);
+ }
+ else if (G_VALUE_HOLDS_STRING (value))
+ {
+ if (full_copy)
+ g_value_set_string (value, param->data.d_string);
+ else
+ g_value_set_static_string (value, param->data.d_string);
+ }
+ else if (GIMP_VALUE_HOLDS_RGB (value))
+ {
+ gimp_value_set_rgb (value, ¶m->data.d_color);
+ }
+ else if (GIMP_VALUE_HOLDS_PARASITE (value))
+ {
+ if (full_copy)
+ g_value_set_boxed (value, ¶m->data.d_parasite);
+ else
+ g_value_set_static_boxed (value, ¶m->data.d_parasite);
+ }
+ else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value))
+ {
+ if (full_copy)
+ gimp_value_set_int32_array (value,
+ (gint32 *) param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (gint32));
+ else
+ gimp_value_set_static_int32_array (value,
+ (gint32 *) param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (gint32));
+ }
+ else if (GIMP_VALUE_HOLDS_INT16_ARRAY (value))
+ {
+ if (full_copy)
+ gimp_value_set_int16_array (value,
+ (gint16 *) param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (gint16));
+ else
+ gimp_value_set_static_int16_array (value,
+ (gint16 *) param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (gint16));
+ }
+ else if (GIMP_VALUE_HOLDS_INT8_ARRAY (value))
+ {
+ if (full_copy)
+ gimp_value_set_int8_array (value,
+ param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (guint8));
+ else
+ gimp_value_set_static_int8_array (value,
+ param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (guint8));
+ }
+ else if (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value))
+ {
+ if (full_copy)
+ gimp_value_set_float_array (value,
+ (const gdouble *)
+ param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (gdouble));
+ else
+ gimp_value_set_static_float_array (value,
+ (const gdouble *)
+ param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (gdouble));
+ }
+ else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
+ {
+ if (full_copy)
+ gimp_value_set_string_array (value,
+ (const gchar **)
+ param->data.d_string_array.data,
+ param->data.d_string_array.size);
+ else
+ gimp_value_set_static_string_array (value,
+ (const gchar **)
+ param->data.d_string_array.data,
+ param->data.d_string_array.size);
+ }
+ else if (GIMP_VALUE_HOLDS_RGB_ARRAY (value))
+ {
+ if (full_copy)
+ gimp_value_set_rgb_array (value,
+ (GimpRGB *)
+ param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (GimpRGB));
+ else
+ gimp_value_set_static_rgb_array (value,
+ (GimpRGB *)
+ param->data.d_array.data,
+ param->data.d_array.size /
+ sizeof (GimpRGB));
+ }
+ else if (GIMP_VALUE_HOLDS_DISPLAY_ID (value) ||
+ GIMP_VALUE_HOLDS_IMAGE_ID (value) ||
+ GIMP_VALUE_HOLDS_ITEM_ID (value) ||
+ GIMP_VALUE_HOLDS_DRAWABLE_ID (value) ||
+ GIMP_VALUE_HOLDS_LAYER_ID (value) ||
+ GIMP_VALUE_HOLDS_CHANNEL_ID (value) ||
+ GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) ||
+ GIMP_VALUE_HOLDS_SELECTION_ID (value) ||
+ GIMP_VALUE_HOLDS_VECTORS_ID (value))
+ {
+ g_value_set_int (value, param->data.d_int);
+ }
+ else if (G_VALUE_HOLDS_PARAM (value))
+ {
+ GParamSpec *pspec =
+ _gimp_gp_param_def_to_param_spec (gimp, ¶m->data.d_param_def);
+
+ g_value_take_param (value, pspec);
+ }
+}
+
GimpValueArray *
-_gimp_gp_params_to_value_array (GParamSpec **pspecs,
+_gimp_gp_params_to_value_array (gpointer gimp,
+ GParamSpec **pspecs,
gint n_pspecs,
GPParam *params,
gint n_params,
@@ -230,143 +390,7 @@ _gimp_gp_params_to_value_array (GParamSpec **pspecs,
}
}
- g_value_init (&value, type);
-
- if (type == G_TYPE_INT ||
- type == GIMP_TYPE_INT32 ||
- type == GIMP_TYPE_INT16 ||
- type == GIMP_TYPE_UNIT)
- {
- g_value_set_int (&value, params[i].data.d_int);
- }
- else if (G_VALUE_HOLDS_UINT (&value))
- {
- g_value_set_uint (&value, params[i].data.d_int);
- }
- else if (G_VALUE_HOLDS_ENUM (&value))
- {
- g_value_set_enum (&value, params[i].data.d_int);
- }
- else if (G_VALUE_HOLDS_BOOLEAN (&value))
- {
- g_value_set_boolean (&value, params[i].data.d_int ? TRUE : FALSE);
- }
- else if (G_VALUE_HOLDS_DOUBLE (&value))
- {
- g_value_set_double (&value, params[i].data.d_float);
- }
- else if (G_VALUE_HOLDS_STRING (&value))
- {
- if (full_copy)
- g_value_set_string (&value, params[i].data.d_string);
- else
- g_value_set_static_string (&value, params[i].data.d_string);
- }
- else if (GIMP_VALUE_HOLDS_RGB (&value))
- {
- gimp_value_set_rgb (&value, ¶ms[i].data.d_color);
- }
- else if (GIMP_VALUE_HOLDS_PARASITE (&value))
- {
- if (full_copy)
- g_value_set_boxed (&value, ¶ms[i].data.d_parasite);
- else
- g_value_set_static_boxed (&value, ¶ms[i].data.d_parasite);
- }
- else if (GIMP_VALUE_HOLDS_INT32_ARRAY (&value))
- {
- if (full_copy)
- gimp_value_set_int32_array (&value,
- (gint32 *) params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (gint32));
- else
- gimp_value_set_static_int32_array (&value,
- (gint32 *) params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (gint32));
- }
- else if (GIMP_VALUE_HOLDS_INT16_ARRAY (&value))
- {
- if (full_copy)
- gimp_value_set_int16_array (&value,
- (gint16 *) params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (gint16));
- else
- gimp_value_set_static_int16_array (&value,
- (gint16 *) params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (gint16));
- }
- else if (GIMP_VALUE_HOLDS_INT8_ARRAY (&value))
- {
- if (full_copy)
- gimp_value_set_int8_array (&value,
- params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (guint8));
- else
- gimp_value_set_static_int8_array (&value,
- params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (guint8));
- }
- else if (GIMP_VALUE_HOLDS_FLOAT_ARRAY (&value))
- {
- if (full_copy)
- gimp_value_set_float_array (&value,
- (const gdouble *)
- params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (gdouble));
- else
- gimp_value_set_static_float_array (&value,
- (const gdouble *)
- params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (gdouble));
- }
- else if (GIMP_VALUE_HOLDS_STRING_ARRAY (&value))
- {
- if (full_copy)
- gimp_value_set_string_array (&value,
- (const gchar **)
- params[i].data.d_string_array.data,
- params[i].data.d_string_array.size);
- else
- gimp_value_set_static_string_array (&value,
- (const gchar **)
- params[i].data.d_string_array.data,
- params[i].data.d_string_array.size);
- }
- else if (GIMP_VALUE_HOLDS_RGB_ARRAY (&value))
- {
- if (full_copy)
- gimp_value_set_rgb_array (&value,
- (GimpRGB *)
- params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (GimpRGB));
- else
- gimp_value_set_static_rgb_array (&value,
- (GimpRGB *)
- params[i].data.d_array.data,
- params[i].data.d_array.size /
- sizeof (GimpRGB));
- }
- else if (GIMP_VALUE_HOLDS_DISPLAY_ID (&value) ||
- GIMP_VALUE_HOLDS_IMAGE_ID (&value) ||
- GIMP_VALUE_HOLDS_ITEM_ID (&value) ||
- GIMP_VALUE_HOLDS_DRAWABLE_ID (&value) ||
- GIMP_VALUE_HOLDS_LAYER_ID (&value) ||
- GIMP_VALUE_HOLDS_CHANNEL_ID (&value) ||
- GIMP_VALUE_HOLDS_LAYER_MASK_ID (&value) ||
- GIMP_VALUE_HOLDS_SELECTION_ID (&value) ||
- GIMP_VALUE_HOLDS_VECTORS_ID (&value))
- {
- g_value_set_int (&value, params[i].data.d_int);
- }
+ _gimp_gp_param_to_value (gimp, ¶ms[i], type, &value, full_copy);
gimp_value_array_append (args, &value);
g_value_unset (&value);
@@ -375,165 +399,186 @@ _gimp_gp_params_to_value_array (GParamSpec **pspecs,
return args;
}
-GPParam *
-_gimp_value_array_to_gp_params (GimpValueArray *args,
- gboolean full_copy)
+void
+_gimp_value_to_gp_param (const GValue *value,
+ GPParam *param,
+ gboolean full_copy)
{
- GPParam *params;
- gint length;
- gint i;
+ GType type;
- g_return_val_if_fail (args != NULL, NULL);
+ g_return_if_fail (value != NULL);
+ g_return_if_fail (param != NULL);
- params = g_new0 (GPParam, gimp_value_array_length (args));
+ type = G_VALUE_TYPE (value);
- length = gimp_value_array_length (args);
+ param->param_type = -1;
- for (i = 0; i < length; i++)
+ if (full_copy)
+ param->type_name = g_strdup (g_type_name (type));
+ else
+ param->type_name = (gchar *) g_type_name (type);
+
+ if (type == G_TYPE_INT ||
+ type == GIMP_TYPE_INT32 ||
+ type == GIMP_TYPE_INT16 ||
+ type == GIMP_TYPE_UNIT)
{
- GValue *value = gimp_value_array_index (args, i);
- GType type = G_VALUE_TYPE (value);
+ param->param_type = GP_PARAM_TYPE_INT;
+
+ param->data.d_int = g_value_get_int (value);
+ }
+ else if (type == G_TYPE_UINT ||
+ type == GIMP_TYPE_INT8)
+ {
+ param->param_type = GP_PARAM_TYPE_INT;
+
+ param->data.d_int = g_value_get_uint (value);
+ }
+ else if (G_VALUE_HOLDS_ENUM (value))
+ {
+ param->param_type = GP_PARAM_TYPE_INT;
+
+ param->data.d_int = g_value_get_enum (value);
+ }
+ else if (G_VALUE_HOLDS_BOOLEAN (value))
+ {
+ param->param_type = GP_PARAM_TYPE_INT;
+
+ param->data.d_int = g_value_get_boolean (value);
+ }
+ else if (G_VALUE_HOLDS_DOUBLE (value))
+ {
+ param->param_type = GP_PARAM_TYPE_FLOAT;
- params[i].param_type = -1;
+ param->data.d_float = g_value_get_double (value);
+ }
+ else if (G_VALUE_HOLDS_STRING (value))
+ {
+ param->param_type = GP_PARAM_TYPE_STRING;
if (full_copy)
- params[i].type_name = g_strdup (g_type_name (type));
+ param->data.d_string = g_value_dup_string (value);
else
- params[i].type_name = (gchar *) g_type_name (type);
+ param->data.d_string = (gchar *) g_value_get_string (value);
+ }
+ else if (GIMP_VALUE_HOLDS_RGB (value))
+ {
+ param->param_type = GP_PARAM_TYPE_COLOR;
- if (type == G_TYPE_INT ||
- type == GIMP_TYPE_INT32 ||
- type == GIMP_TYPE_INT16 ||
- type == GIMP_TYPE_UNIT)
- {
- params[i].param_type = GP_PARAM_TYPE_INT;
+ gimp_value_get_rgb (value, ¶m->data.d_color);
+ }
+ else if (GIMP_VALUE_HOLDS_PARASITE (value))
+ {
+ GimpParasite *parasite = (full_copy ?
+ g_value_dup_boxed (value) :
+ g_value_get_boxed (value));
- params[i].data.d_int = g_value_get_int (value);
- }
- else if (type == G_TYPE_UINT ||
- type == GIMP_TYPE_INT8)
- {
- params[i].param_type = GP_PARAM_TYPE_INT;
+ param->param_type = GP_PARAM_TYPE_PARASITE;
- params[i].data.d_int = g_value_get_uint (value);
- }
- else if (G_VALUE_HOLDS_ENUM (value))
+ if (parasite)
{
- params[i].param_type = GP_PARAM_TYPE_INT;
+ param->data.d_parasite.name = parasite->name;
+ param->data.d_parasite.flags = parasite->flags;
+ param->data.d_parasite.size = parasite->size;
+ param->data.d_parasite.data = parasite->data;
- params[i].data.d_int = g_value_get_enum (value);
- }
- else if (G_VALUE_HOLDS_BOOLEAN (value))
- {
- params[i].param_type = GP_PARAM_TYPE_INT;
+ if (full_copy)
+ {
+ parasite->name = NULL;
+ parasite->flags = 0;
+ parasite->size = 0;
+ parasite->data = NULL;
- params[i].data.d_int = g_value_get_boolean (value);
+ gimp_parasite_free (parasite);
+ }
}
- else if (G_VALUE_HOLDS_DOUBLE (value))
+ else
{
- params[i].param_type = GP_PARAM_TYPE_FLOAT;
-
- params[i].data.d_float = g_value_get_double (value);
+ param->data.d_parasite.name = NULL;
+ param->data.d_parasite.flags = 0;
+ param->data.d_parasite.size = 0;
+ param->data.d_parasite.data = NULL;
}
- else if (G_VALUE_HOLDS_STRING (value))
- {
- params[i].param_type = GP_PARAM_TYPE_STRING;
+ }
+ else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
+ GIMP_VALUE_HOLDS_INT16_ARRAY (value) ||
+ GIMP_VALUE_HOLDS_INT8_ARRAY (value) ||
+ GIMP_VALUE_HOLDS_FLOAT_ARRAY (value) ||
+ GIMP_VALUE_HOLDS_RGB_ARRAY (value))
+ {
+ GimpArray *array = g_value_get_boxed (value);
- if (full_copy)
- params[i].data.d_string = g_value_dup_string (value);
- else
- params[i].data.d_string = (gchar *) g_value_get_string (value);
- }
- else if (GIMP_VALUE_HOLDS_RGB (value))
- {
- params[i].param_type = GP_PARAM_TYPE_COLOR;
+ param->param_type = GP_PARAM_TYPE_ARRAY;
- gimp_value_get_rgb (value, ¶ms[i].data.d_color);
- }
- else if (GIMP_VALUE_HOLDS_PARASITE (value))
- {
- GimpParasite *parasite = (full_copy ?
- g_value_dup_boxed (value) :
- g_value_get_boxed (value));
+ param->data.d_array.size = array->length;
- params[i].param_type = GP_PARAM_TYPE_PARASITE;
+ if (full_copy)
+ param->data.d_array.data = g_memdup (array->data,
+ array->length);
+ else
+ param->data.d_array.data = array->data;
+ }
+ else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
+ {
+ GimpArray *array = g_value_get_boxed (value);
- if (parasite)
- {
- params[i].data.d_parasite.name = parasite->name;
- params[i].data.d_parasite.flags = parasite->flags;
- params[i].data.d_parasite.size = parasite->size;
- params[i].data.d_parasite.data = parasite->data;
+ param->param_type = GP_PARAM_TYPE_STRING_ARRAY;
- if (full_copy)
- {
- parasite->name = NULL;
- parasite->flags = 0;
- parasite->size = 0;
- parasite->data = NULL;
+ param->data.d_string_array.size = array->length;
- gimp_parasite_free (parasite);
- }
- }
- else
- {
- params[i].data.d_parasite.name = NULL;
- params[i].data.d_parasite.flags = 0;
- params[i].data.d_parasite.size = 0;
- params[i].data.d_parasite.data = NULL;
- }
- }
- else if (GIMP_VALUE_HOLDS_INT32_ARRAY (value) ||
- GIMP_VALUE_HOLDS_INT16_ARRAY (value) ||
- GIMP_VALUE_HOLDS_INT8_ARRAY (value) ||
- GIMP_VALUE_HOLDS_FLOAT_ARRAY (value) ||
- GIMP_VALUE_HOLDS_RGB_ARRAY (value))
- {
- GimpArray *array = g_value_get_boxed (value);
+ if (full_copy)
+ param->data.d_string_array.data =
+ gimp_value_dup_string_array (value);
+ else
+ param->data.d_string_array.data =
+ (gchar **) gimp_value_get_string_array (value);
+ }
+ else if (GIMP_VALUE_HOLDS_DISPLAY_ID (value) ||
+ GIMP_VALUE_HOLDS_IMAGE_ID (value) ||
+ GIMP_VALUE_HOLDS_ITEM_ID (value) ||
+ GIMP_VALUE_HOLDS_DRAWABLE_ID (value) ||
+ GIMP_VALUE_HOLDS_LAYER_ID (value) ||
+ GIMP_VALUE_HOLDS_CHANNEL_ID (value) ||
+ GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) ||
+ GIMP_VALUE_HOLDS_SELECTION_ID (value) ||
+ GIMP_VALUE_HOLDS_VECTORS_ID (value))
+ {
+ param->param_type = GP_PARAM_TYPE_INT;
+
+ param->data.d_int = g_value_get_int (value);
+ }
+ else if (G_VALUE_HOLDS_PARAM (value))
+ {
+ param->param_type = GP_PARAM_TYPE_PARAM_DEF;
- params[i].param_type = GP_PARAM_TYPE_ARRAY;
+ _gimp_param_spec_to_gp_param_def (g_value_get_param (value),
+ ¶m->data.d_param_def);
+ }
- params[i].data.d_array.size = array->length;
+ if (param->param_type == -1)
+ g_printerr ("%s: GValue contains unsupported type '%s'\n",
+ G_STRFUNC, param->type_name);
+}
- if (full_copy)
- params[i].data.d_array.data = g_memdup (array->data,
- array->length);
- else
- params[i].data.d_array.data = array->data;
- }
- else if (GIMP_VALUE_HOLDS_STRING_ARRAY (value))
- {
- GimpArray *array = g_value_get_boxed (value);
+GPParam *
+_gimp_value_array_to_gp_params (GimpValueArray *args,
+ gboolean full_copy)
+{
+ GPParam *params;
+ gint length;
+ gint i;
- params[i].param_type = GP_PARAM_TYPE_STRING_ARRAY;
+ g_return_val_if_fail (args != NULL, NULL);
- params[i].data.d_string_array.size = array->length;
+ length = gimp_value_array_length (args);
- if (full_copy)
- params[i].data.d_string_array.data =
- gimp_value_dup_string_array (value);
- else
- params[i].data.d_string_array.data =
- (gchar **) gimp_value_get_string_array (value);
- }
- else if (GIMP_VALUE_HOLDS_DISPLAY_ID (value) ||
- GIMP_VALUE_HOLDS_IMAGE_ID (value) ||
- GIMP_VALUE_HOLDS_ITEM_ID (value) ||
- GIMP_VALUE_HOLDS_DRAWABLE_ID (value) ||
- GIMP_VALUE_HOLDS_LAYER_ID (value) ||
- GIMP_VALUE_HOLDS_CHANNEL_ID (value) ||
- GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) ||
- GIMP_VALUE_HOLDS_SELECTION_ID (value) ||
- GIMP_VALUE_HOLDS_VECTORS_ID (value))
- {
- params[i].param_type = GP_PARAM_TYPE_INT;
+ params = g_new0 (GPParam, length);
- params[i].data.d_int = g_value_get_int (value);
- }
+ for (i = 0; i < length; i++)
+ {
+ GValue *value = gimp_value_array_index (args, i);
- if (params[i].param_type == -1)
- g_printerr ("%s: GValue contains unsupported type '%s'\n",
- G_STRFUNC, params[i].type_name);
+ _gimp_value_to_gp_param (value, ¶ms[i], full_copy);
}
return params;
diff --git a/libgimp/gimpgpparams.c b/libgimp/gimpgpparams.c
index 6870085638..51f814e312 100644
--- a/libgimp/gimpgpparams.c
+++ b/libgimp/gimpgpparams.c
@@ -38,3 +38,172 @@
* libgimp/ but need different headers.
*/
#include "gimpgpparams-body.c"
+
+GParamSpec *
+_gimp_gp_param_def_to_param_spec (gpointer gimp,
+ GPParamDef *param_def)
+{
+ const gchar *name = param_def->name;
+ const gchar *nick = param_def->nick;
+ const gchar *blurb = param_def->blurb;
+ GParamFlags flags = G_PARAM_READWRITE;
+
+ switch (param_def->param_def_type)
+ {
+ case GP_PARAM_DEF_TYPE_DEFAULT:
+ if (! strcmp (param_def->type_name, "GimpParamInt32Array"))
+ return gimp_param_spec_int32_array (name, nick, blurb, flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamInt16Array"))
+ return gimp_param_spec_int16_array (name, nick, blurb, flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamInt8Array"))
+ return gimp_param_spec_int8_array (name, nick, blurb, flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamFloatArray"))
+ return gimp_param_spec_float_array (name, nick, blurb, flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamStringArray"))
+ return gimp_param_spec_string_array (name, nick, blurb, flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamRGBArray"))
+ return gimp_param_spec_rgb_array (name, nick, blurb, flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamParasite"))
+ return gimp_param_spec_parasite (name, nick, blurb, flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_INT:
+ if (! strcmp (param_def->type_name, "GParamInt"))
+ return g_param_spec_int (name, nick, blurb,
+ param_def->meta.m_int.min_val,
+ param_def->meta.m_int.max_val,
+ param_def->meta.m_int.default_val,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamInt32"))
+ return gimp_param_spec_int32 (name, nick, blurb,
+ param_def->meta.m_int.min_val,
+ param_def->meta.m_int.max_val,
+ param_def->meta.m_int.default_val,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamInt16"))
+ return gimp_param_spec_int16 (name, nick, blurb,
+ param_def->meta.m_int.min_val,
+ param_def->meta.m_int.max_val,
+ param_def->meta.m_int.default_val,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamInt8"))
+ return gimp_param_spec_int8 (name, nick, blurb,
+ param_def->meta.m_int.min_val,
+ param_def->meta.m_int.max_val,
+ param_def->meta.m_int.default_val,
+ flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_UNIT:
+ if (! strcmp (param_def->type_name, "GimpParamUnit"))
+ return gimp_param_spec_unit (name, nick, blurb,
+ param_def->meta.m_unit.allow_pixels,
+ param_def->meta.m_unit.allow_percent,
+ param_def->meta.m_unit.default_val,
+ flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_ENUM:
+ if (! strcmp (param_def->type_name, "GParamEnum"))
+ return g_param_spec_enum (name, nick, blurb,
+ g_type_from_name (param_def->meta.m_enum.type_name),
+ param_def->meta.m_enum.default_val,
+ flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_BOOLEAN:
+ if (! strcmp (param_def->type_name, "GParamBoolean"))
+ return g_param_spec_boolean (name, nick, blurb,
+ param_def->meta.m_boolean.default_val,
+ flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_FLOAT:
+ if (! strcmp (param_def->type_name, "GParamDouble"))
+ return g_param_spec_double (name, nick, blurb,
+ param_def->meta.m_float.min_val,
+ param_def->meta.m_float.max_val,
+ param_def->meta.m_float.default_val,
+ flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_STRING:
+ if (! strcmp (param_def->type_name, "GimpParamString") ||
+ ! strcmp (param_def->type_name, "GParamString"))
+ return gimp_param_spec_string (name, nick, blurb,
+ param_def->meta.m_string.allow_non_utf8,
+ param_def->meta.m_string.null_ok,
+ param_def->meta.m_string.non_empty,
+ param_def->meta.m_string.default_val,
+ flags);
+ break;
+
+ case GP_PARAM_DEF_TYPE_COLOR:
+ if (! strcmp (param_def->type_name, "GimpParamRGB"))
+ return gimp_param_spec_rgb (name, nick, blurb,
+ param_def->meta.m_color.has_alpha,
+ ¶m_def->meta.m_color.default_val,
+ flags);
+
+ case GP_PARAM_DEF_TYPE_ID:
+ if (! strcmp (param_def->type_name, "GimpParamDisplayID"))
+ return gimp_param_spec_display_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamImageID"))
+ return gimp_param_spec_image_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamItemID"))
+ return gimp_param_spec_item_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamDrawableID"))
+ return gimp_param_spec_drawable_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamLayerID"))
+ return gimp_param_spec_layer_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamChannelID"))
+ return gimp_param_spec_channel_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamLayerMaskID"))
+ return gimp_param_spec_layer_mask_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamSelectionID"))
+ return gimp_param_spec_selection_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+
+ if (! strcmp (param_def->type_name, "GimpParamVectorsID"))
+ return gimp_param_spec_vectors_id (name, nick, blurb,
+ param_def->meta.m_id.none_ok,
+ flags);
+ break;
+ }
+
+ g_printerr ("%s: GParamSpec type '%s' is not handled\n",
+ G_STRFUNC, param_def->type_name);
+
+ return NULL;
+}
diff --git a/libgimp/gimpgpparams.h b/libgimp/gimpgpparams.h
index 17226238b4..637edd1d39 100644
--- a/libgimp/gimpgpparams.h
+++ b/libgimp/gimpgpparams.h
@@ -25,15 +25,28 @@
G_BEGIN_DECLS
+GParamSpec * _gimp_gp_param_def_to_param_spec (gpointer gimp,
+ GPParamDef *param_def);
+
void _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
GPParamDef *param_def);
-GimpValueArray * _gimp_gp_params_to_value_array (GParamSpec **pspecs,
+void _gimp_gp_param_to_value (gpointer gimp,
+ GPParam *param,
+ GType type,
+ GValue *value,
+ gboolean full_copy);
+GimpValueArray * _gimp_gp_params_to_value_array (gpointer gimp,
+ GParamSpec **pspecs,
gint n_pspecs,
GPParam *params,
gint n_params,
gboolean return_values,
gboolean full_copy);
+
+void _gimp_value_to_gp_param (const GValue *value,
+ GPParam *param,
+ gboolean full_copy);
GPParam * _gimp_value_array_to_gp_params (GimpValueArray *args,
gboolean full_copy);
diff --git a/libgimp/gimplegacy.c b/libgimp/gimplegacy.c
index 44d75fe41b..2a3cd9e488 100644
--- a/libgimp/gimplegacy.c
+++ b/libgimp/gimplegacy.c
@@ -1165,7 +1165,8 @@ gimp_proc_run_internal (GPProcRun *proc_run,
gint n_params;
gint n_return_vals;
- arguments = _gimp_gp_params_to_value_array (NULL, 0,
+ arguments = _gimp_gp_params_to_value_array (NULL,
+ NULL, 0,
proc_run->params,
proc_run->nparams,
FALSE, FALSE);
diff --git a/libgimp/gimpplugin-private.c b/libgimp/gimpplugin-private.c
index ff7ae2ec80..08fb6d635d 100644
--- a/libgimp/gimpplugin-private.c
+++ b/libgimp/gimpplugin-private.c
@@ -347,7 +347,8 @@ gimp_plug_in_proc_run_internal (GPProcRun *proc_run,
GimpValueArray *arguments;
GimpValueArray *return_values = NULL;
- arguments = _gimp_gp_params_to_value_array (NULL, 0,
+ arguments = _gimp_gp_params_to_value_array (NULL,
+ NULL, 0,
proc_run->params,
proc_run->nparams,
FALSE, FALSE);
diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c
index 0eb2bf6ce2..6aa5937be7 100644
--- a/libgimpbase/gimpprotocol.c
+++ b/libgimpbase/gimpprotocol.c
@@ -1721,6 +1721,13 @@ _gp_params_read (GIOChannel *channel,
else
(*params)[i].data.d_parasite.data = NULL;
break;
+
+ case GP_PARAM_TYPE_PARAM_DEF:
+ if (! _gp_param_def_read (channel,
+ &(*params)[i].data.d_param_def,
+ user_data))
+ goto cleanup;
+ break;
}
}
@@ -1833,6 +1840,13 @@ _gp_params_write (GIOChannel *channel,
}
}
break;
+
+ case GP_PARAM_TYPE_PARAM_DEF:
+ if (! _gp_param_def_write (channel,
+ ¶ms[i].data.d_param_def,
+ user_data))
+ return;
+ break;
}
}
}
@@ -1883,6 +1897,10 @@ _gp_params_destroy (GPParam *params,
if (params[i].data.d_parasite.data)
g_free (params[i].data.d_parasite.data);
break;
+
+ case GP_PARAM_TYPE_PARAM_DEF:
+ _gp_param_def_destroy (¶ms[i].data.d_param_def);
+ break;
}
}
diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h
index b570ed9380..a91f334830 100644
--- a/libgimpbase/gimpprotocol.h
+++ b/libgimpbase/gimpprotocol.h
@@ -67,7 +67,8 @@ typedef enum
GP_PARAM_TYPE_COLOR,
GP_PARAM_TYPE_PARASITE,
GP_PARAM_TYPE_ARRAY,
- GP_PARAM_TYPE_STRING_ARRAY
+ GP_PARAM_TYPE_STRING_ARRAY,
+ GP_PARAM_TYPE_PARAM_DEF
} GPParamType;
@@ -236,6 +237,7 @@ struct _GPParam
GimpParasite d_parasite;
GPParamArray d_array;
GPParamStringArray d_string_array;
+ GPParamDef d_param_def;
} data;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]