[gimp/wip/Jehan/classy-GIMP: 25/64] libgimp: allow object GimpImage as procedure parameter.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/classy-GIMP: 25/64] libgimp: allow object GimpImage as procedure parameter.
- Date: Sun, 18 Aug 2019 19:58:24 +0000 (UTC)
commit e116a43b402aa7a9d96b33e5872936d44d99949c
Author: Jehan <jehan girinstud io>
Date: Tue Aug 13 12:34:09 2019 +0200
libgimp: allow object GimpImage as procedure parameter.
Though it is still possible to use an image ID as procedure parameter,
it is now possible to pass a GimpImage GParamSpecObject.
Over the wire, this will transform back and forth into a GimpImageID,
totally transparently for the plug-in which will only always get a
GimpImage.
libgimp/gimpgpparams-body.c | 17 +++++++++++++++++
libgimp/gimpprocedure.c | 35 +++++++++++++++++++++++++----------
libgimp/gimpprocedure.h | 2 +-
3 files changed, 43 insertions(+), 11 deletions(-)
---
diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c
index 9edbdac9e2..457b1ecca2 100644
--- a/libgimp/gimpgpparams-body.c
+++ b/libgimp/gimpgpparams-body.c
@@ -172,6 +172,23 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
param_def->meta.m_param_def.type_name =
(gchar *) g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec));
}
+ else if (pspec_type == G_TYPE_PARAM_OBJECT)
+ {
+ /* We can't pass objects over the wire, but we can support
+ * specific objects which are actually handled in the core through
+ * IDs by converting these types to their respective IDs.
+ */
+
+ /* Don't compare with libgimp types directly as this file is also
+ * included from app/ which won't know of the types.
+ */
+ if (g_strcmp0 (g_type_name (pspec->value_type), "GimpImage") == 0)
+ {
+ param_def->type_name = "GimpParamImageID";
+ param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
+ param_def->meta.m_id.none_ok = TRUE;
+ }
+ }
}
void
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index 4443881463..cd7318fd56 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -105,7 +105,7 @@ static GimpValueArray *
static gboolean gimp_procedure_validate_args (GimpProcedure *procedure,
GParamSpec **param_specs,
gint n_param_specs,
- const GimpValueArray *args,
+ GimpValueArray *args,
gboolean return_vals,
GError **error);
@@ -1293,8 +1293,8 @@ gimp_procedure_new_return_values (GimpProcedure *procedure,
* Since: 3.0
**/
GimpValueArray *
-gimp_procedure_run (GimpProcedure *procedure,
- const GimpValueArray *args)
+gimp_procedure_run (GimpProcedure *procedure,
+ GimpValueArray *args)
{
GimpValueArray *return_vals;
GError *error = NULL;
@@ -1409,12 +1409,12 @@ gimp_procedure_extension_ready (GimpProcedure *procedure)
/* private functions */
static gboolean
-gimp_procedure_validate_args (GimpProcedure *procedure,
- GParamSpec **param_specs,
- gint n_param_specs,
- const GimpValueArray *args,
- gboolean return_vals,
- GError **error)
+gimp_procedure_validate_args (GimpProcedure *procedure,
+ GParamSpec **param_specs,
+ gint n_param_specs,
+ GimpValueArray *args,
+ gboolean return_vals,
+ GError **error)
{
gint i;
@@ -1425,7 +1425,22 @@ gimp_procedure_validate_args (GimpProcedure *procedure,
GType arg_type = G_VALUE_TYPE (arg);
GType spec_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
- if (arg_type != spec_type)
+ /* As a special case, validation can transform IDs into their
+ * respective object.
+ */
+ if (arg_type == GIMP_TYPE_IMAGE_ID &&
+ spec_type == GIMP_TYPE_IMAGE)
+ {
+ GValue value = G_VALUE_INIT;
+ GimpImage *image = gimp_image_new_by_id (g_value_get_int (arg));
+
+ g_value_init (&value, GIMP_TYPE_IMAGE);
+ g_value_take_object (&value, image);
+ gimp_value_array_remove (args, i);
+ gimp_value_array_insert (args, i, &value);
+ g_value_unset (&value);
+ }
+ else if (arg_type != spec_type)
{
if (return_vals)
{
diff --git a/libgimp/gimpprocedure.h b/libgimp/gimpprocedure.h
index a83115fea0..0f4351e345 100644
--- a/libgimp/gimpprocedure.h
+++ b/libgimp/gimpprocedure.h
@@ -166,7 +166,7 @@ GimpValueArray * gimp_procedure_new_return_values (GimpProcedure *proced
GError *error);
GimpValueArray * gimp_procedure_run (GimpProcedure *procedure,
- const GimpValueArray *args);
+ GimpValueArray *args);
void gimp_procedure_extension_ready (GimpProcedure *procedure);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]