From f25e0448b27e50d007bb3e14f48e7e0f081bf041 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 15 Oct 2023 19:22:32 +0200 Subject: [PATCH] libgimp, plug-ins: gimp_procedure_config_[gs]et_values() not public anymore. This goes with our planned change of not making GimpProcedure arguments order relevant anymore regarding the PDB API. In particular, it means we don't want to use GimpValueArray for various procedure arguments API, but directly GimpProcedureConfig objects. This change will allow to add or reorder arguments in the future, so that we won't have to create new PDB procedures when adding new arguments, while still keeping PDB API stability. --- libgimp/gimp.def | 2 - libgimp/gimppdb.c | 3 +- libgimp/gimpprocedureconfig-private.h | 3 + libgimp/gimpprocedureconfig.c | 188 +++++++++--------- libgimp/gimpprocedureconfig.h | 4 - .../script-fu/libscriptfu/script-fu-command.c | 13 +- .../script-fu/libscriptfu/script-fu-dialog.c | 71 ++----- .../script-fu/libscriptfu/script-fu-script.c | 28 ++- .../script-fu/libscriptfu/script-fu-script.h | 2 +- 9 files changed, 141 insertions(+), 173 deletions(-) diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 8c4935fe86..2c98335e27 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -733,9 +733,7 @@ EXPORTS gimp_procedure_config_get_choice_id gimp_procedure_config_get_procedure gimp_procedure_config_get_type - gimp_procedure_config_get_values gimp_procedure_config_save_metadata - gimp_procedure_config_set_values gimp_procedure_create_config gimp_procedure_extension_ready gimp_procedure_find_argument diff --git a/libgimp/gimppdb.c b/libgimp/gimppdb.c index e240f7733b..fab20a87d9 100644 --- a/libgimp/gimppdb.c +++ b/libgimp/gimppdb.c @@ -31,6 +31,7 @@ #include "gimppdb_pdb.h" #include "gimppdbprocedure.h" #include "gimpplugin-private.h" +#include "gimpprocedureconfig-private.h" #include "libgimp-intl.h" @@ -394,7 +395,7 @@ gimp_pdb_run_procedure_config (GimpPDB *pdb, args = gimp_procedure_new_arguments (procedure); - gimp_procedure_config_get_values (config, args); + _gimp_procedure_config_get_values (config, args); return_values = gimp_pdb_run_procedure_array (pdb, procedure_name, args); gimp_value_array_unref (args); diff --git a/libgimp/gimpprocedureconfig-private.h b/libgimp/gimpprocedureconfig-private.h index dc34e28291..6b434d3850 100644 --- a/libgimp/gimpprocedureconfig-private.h +++ b/libgimp/gimpprocedureconfig-private.h @@ -22,6 +22,9 @@ #ifndef __GIMP_PROCEDURE_CONFIG_PRIVATE_H__ #define __GIMP_PROCEDURE_CONFIG_PRIVATE_H__ +void _gimp_procedure_config_get_values (GimpProcedureConfig *config, + GimpValueArray *values); + void _gimp_procedure_config_begin_run (GimpProcedureConfig *config, GimpImage *image, GimpRunMode run_mode, diff --git a/libgimp/gimpprocedureconfig.c b/libgimp/gimpprocedureconfig.c index 70974e1edd..d5f50d93c8 100644 --- a/libgimp/gimpprocedureconfig.c +++ b/libgimp/gimpprocedureconfig.c @@ -79,6 +79,10 @@ static void gimp_procedure_config_get_property (GObject *obje GValue *value, GParamSpec *pspec); + +static void gimp_procedure_config_set_values (GimpProcedureConfig *config, + const GimpValueArray *values); + static gboolean gimp_procedure_config_load_last (GimpProcedureConfig *config, GError **error); static gboolean gimp_procedure_config_save_last (GimpProcedureConfig *config, @@ -233,98 +237,6 @@ gimp_procedure_config_get_procedure (GimpProcedureConfig *config) return config->priv->procedure; } -/** - * gimp_procedure_config_set_values: - * @config: a #GimpProcedureConfig - * @values: a #GimpValueArray - * - * Sets the values from @values on @config's properties. - * - * The number, order and types of values in @values must match the - * number, order and types of @config's properties. - * - * This function is meant to be used on @values which are passed as - * arguments to the run() function of the [class@Procedure] which created - * this @config. See [method@Procedure.create_config]. - * - * Since: 3.0 - **/ -void -gimp_procedure_config_set_values (GimpProcedureConfig *config, - const GimpValueArray *values) -{ - GParamSpec **pspecs; - guint n_pspecs; - gint n_aux_args; - gint n_values; - gint i; - - g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config)); - g_return_if_fail (values != NULL); - - pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), - &n_pspecs); - gimp_procedure_get_aux_arguments (config->priv->procedure, &n_aux_args); - n_values = gimp_value_array_length (values); - - /* The first property is the procedure, all others are arguments. */ - g_return_if_fail (n_pspecs == n_values + n_aux_args + 1); - - for (i = 0; i < n_values; i++) - { - GParamSpec *pspec = pspecs[i + 1]; - GValue *value = gimp_value_array_index (values, i); - - g_object_set_property (G_OBJECT (config), pspec->name, value); - } - - g_free (pspecs); -} - -/** - * gimp_procedure_config_get_values: - * @config: a #GimpProcedureConfig - * @values: a #GimpValueArray - * - * Gets the values from @config's properties and stores them in - * @values. - * - * See [method@ProcedureConfig.set_values]. - * - * Since: 3.0 - **/ -void -gimp_procedure_config_get_values (GimpProcedureConfig *config, - GimpValueArray *values) -{ - GParamSpec **pspecs; - guint n_pspecs; - gint n_aux_args; - gint n_values; - gint i; - - g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config)); - g_return_if_fail (values != NULL); - - pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), - &n_pspecs); - gimp_procedure_get_aux_arguments (config->priv->procedure, &n_aux_args); - n_values = gimp_value_array_length (values); - - /* The config will have 1 additional property: "procedure". */ - g_return_if_fail (n_pspecs == n_values + n_aux_args + 1); - - for (i = 1; i < n_pspecs; i++) - { - GParamSpec *pspec = pspecs[i]; - GValue *value = gimp_value_array_index (values, i - 1); - - g_object_get_property (G_OBJECT (config), pspec->name, value); - } - - g_free (pspecs); -} - static void gimp_procedure_config_get_parasite (GimpProcedureConfig *config, GParamSpec *pspec) @@ -590,6 +502,50 @@ gimp_procedure_config_get_choice_id (GimpProcedureConfig *config, /* Functions only used by GimpProcedure classes */ +/** + * _gimp_procedure_config_get_values: + * @config: a #GimpProcedureConfig + * @values: a #GimpValueArray + * + * Gets the values from @config's properties and stores them in + * @values. + * + * See [method@ProcedureConfig.set_values]. + * + * Since: 3.0 + **/ +void +_gimp_procedure_config_get_values (GimpProcedureConfig *config, + GimpValueArray *values) +{ + GParamSpec **pspecs; + guint n_pspecs; + gint n_aux_args; + gint n_values; + gint i; + + g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config)); + g_return_if_fail (values != NULL); + + pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), + &n_pspecs); + gimp_procedure_get_aux_arguments (config->priv->procedure, &n_aux_args); + n_values = gimp_value_array_length (values); + + /* The config will have 1 additional property: "procedure". */ + g_return_if_fail (n_pspecs == n_values + n_aux_args + 1); + + for (i = 1; i < n_pspecs; i++) + { + GParamSpec *pspec = pspecs[i]; + GValue *value = gimp_value_array_index (values, i - 1); + + g_object_get_property (G_OBJECT (config), pspec->name, value); + } + + g_free (pspecs); +} + /** * _gimp_procedure_config_begin_run: * @config: a #GimpProcedureConfig @@ -1038,6 +994,54 @@ _gimp_procedure_config_save_default (GimpProcedureConfig *config, /* private functions */ +/** + * gimp_procedure_config_set_values: + * @config: a #GimpProcedureConfig + * @values: a #GimpValueArray + * + * Sets the values from @values on @config's properties. + * + * The number, order and types of values in @values must match the + * number, order and types of @config's properties. + * + * This function is meant to be used on @values which are passed as + * arguments to the run() function of the [class@Procedure] which created + * this @config. See [method@Procedure.create_config]. + * + * Since: 3.0 + **/ +static void +gimp_procedure_config_set_values (GimpProcedureConfig *config, + const GimpValueArray *values) +{ + GParamSpec **pspecs; + guint n_pspecs; + gint n_aux_args; + gint n_values; + gint i; + + g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config)); + g_return_if_fail (values != NULL); + + pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), + &n_pspecs); + gimp_procedure_get_aux_arguments (config->priv->procedure, &n_aux_args); + n_values = gimp_value_array_length (values); + + /* The first property is the procedure, all others are arguments. */ + g_return_if_fail (n_pspecs == n_values + n_aux_args + 1); + + for (i = 0; i < n_values; i++) + { + GParamSpec *pspec = pspecs[i + 1]; + GValue *value = gimp_value_array_index (values, i); + + g_object_set_property (G_OBJECT (config), pspec->name, value); + } + + g_free (pspecs); +} + static gboolean gimp_procedure_config_load_last (GimpProcedureConfig *config, GError **error) diff --git a/libgimp/gimpprocedureconfig.h b/libgimp/gimpprocedureconfig.h index 26610c6ad7..dbcdf4c5c3 100644 --- a/libgimp/gimpprocedureconfig.h +++ b/libgimp/gimpprocedureconfig.h @@ -70,10 +70,6 @@ GType gimp_procedure_config_get_type (void) G_GNUC_CONST; GimpProcedure * gimp_procedure_config_get_procedure (GimpProcedureConfig *config); -void gimp_procedure_config_set_values (GimpProcedureConfig *config, - const GimpValueArray *values); -void gimp_procedure_config_get_values (GimpProcedureConfig *config, - GimpValueArray *values); void gimp_procedure_config_save_metadata (GimpProcedureConfig *config, GimpImage *exported_image, diff --git a/plug-ins/script-fu/libscriptfu/script-fu-command.c b/plug-ins/script-fu/libscriptfu/script-fu-command.c index 4e9fd340ee..4af58d60ac 100644 --- a/plug-ins/script-fu/libscriptfu/script-fu-command.c +++ b/plug-ins/script-fu/libscriptfu/script-fu-command.c @@ -105,17 +105,8 @@ script_fu_interpret_image_proc (GimpProcedure *procedure, GimpValueArray *result = NULL; gboolean interpretation_result; GError *error = NULL; - GimpValueArray *args = gimp_procedure_new_arguments (procedure); - guint n_specs; - g_free (g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_specs)); - while (gimp_value_array_length (args) > n_specs - 1) - gimp_value_array_remove (args, 0); - - /* Store config's values into args. */ - gimp_procedure_config_get_values (config, args); - - command = script_fu_script_get_command_for_image_proc (script, image, n_drawables, drawables, args); + command = script_fu_script_get_command_for_image_proc (script, image, n_drawables, drawables, config); /* Take responsibility for handling errors from the scripts further calls to PDB. * ScriptFu does not show an error dialog, but forwards errors back to GIMP. @@ -154,7 +145,5 @@ script_fu_interpret_image_proc (GimpProcedure *procedure, gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (), GIMP_PDB_ERROR_HANDLER_INTERNAL); - gimp_value_array_unref (args); - return result; } diff --git a/plug-ins/script-fu/libscriptfu/script-fu-dialog.c b/plug-ins/script-fu/libscriptfu/script-fu-dialog.c index 7f9c336826..db038b7489 100644 --- a/plug-ins/script-fu/libscriptfu/script-fu-dialog.c +++ b/plug-ins/script-fu/libscriptfu/script-fu-dialog.c @@ -60,72 +60,37 @@ dump_properties (GimpProcedureConfig *config) g_free (pspecs); } -static gint -get_length (GimpProcedureConfig *config) -{ - GParamSpec **pspecs; - guint n_pspecs; - - pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), - &n_pspecs); - g_free (pspecs); - g_debug ("length config: %d", n_pspecs); - - return n_pspecs; -} - -/* Fill a new (length zero) gva with new gvalues (empty but holding the correct type) - from the config. - */ static void -fill_gva_from (GimpProcedureConfig *config, - GimpValueArray *gva) -{ - GParamSpec **pspecs; - guint n_pspecs; - - pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), - &n_pspecs); - /* !!! Start at property 1 */ - for (guint i = 1; i < n_pspecs; i++) - { - g_debug ("%s %s\n", pspecs[i]->name, G_PARAM_SPEC_TYPE_NAME (pspecs[i])); - /* append empty gvalue */ - gimp_value_array_append (gva, NULL); - } - - g_free (pspecs); -} - -static void -dump_objects (GimpProcedureConfig *config) +dump_objects (GimpProcedureConfig *config) { /* Check it will return non-null objects. */ - GimpValueArray *args; - gint length; + GParamSpec **pspecs; + guint n_pspecs; - /* Need one less gvalue !!! */ - args = gimp_value_array_new (get_length (config) - 1); - /* The array still has length zero. */ - g_debug ("GVA length: %d", gimp_value_array_length (args)); + pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_pspecs); - fill_gva_from (config, args); - - gimp_procedure_config_get_values (config, args); - if (args == NULL) + /* config will have at least 1 property: "procedure". */ + if (n_pspecs == 1) { g_debug ("config holds no values"); return; } - length = gimp_value_array_length (args); - for (guint i = 1; i < length; i++) + for (gint i = 1; i < n_pspecs; i++) { - GValue *gvalue = gimp_value_array_index (args, i); - if (G_VALUE_HOLDS_OBJECT (gvalue)) - if (g_value_get_object (gvalue) == NULL) + GParamSpec *pspec = pspecs[i]; + GValue value = G_VALUE_INIT; + + g_value_init (&value, pspec->value_type); + g_object_get_property (G_OBJECT (config), pspec->name, &value); + + if (G_VALUE_HOLDS_OBJECT (&value)) + if (g_value_get_object (&value) == NULL) g_debug ("gvalue %d holds NULL object", i); + + g_value_unset (&value); } + g_free (pspecs); } #endif diff --git a/plug-ins/script-fu/libscriptfu/script-fu-script.c b/plug-ins/script-fu/libscriptfu/script-fu-script.c index 2ef4853a95..10d67b06cb 100644 --- a/plug-ins/script-fu/libscriptfu/script-fu-script.c +++ b/plug-ins/script-fu/libscriptfu/script-fu-script.c @@ -405,11 +405,15 @@ script_fu_script_get_command_for_image_proc (SFScript *script, GimpImage *image, guint n_drawables, GimpDrawable **drawables, - const GimpValueArray *args) + GimpProcedureConfig *config) { - GString *s; + GParamSpec **pspecs; + guint n_pspecs; + GString *s; + gint i; g_return_val_if_fail (script != NULL, NULL); + g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL); s = g_string_new ("("); g_string_append (s, script->name); @@ -430,20 +434,28 @@ script_fu_script_get_command_for_image_proc (SFScript *script, */ script_fu_command_append_drawables (s, n_drawables, drawables); - /* args contains the "other" args + /* config contains the "other" args * Iterate over the GimpValueArray. * But script->args should be the same length, and types should match. */ - for (guint i = 0; i < gimp_value_array_length (args); i++) + pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_pspecs); + + /* config will have 1 additional property: "procedure". */ + for (i = 1; i < n_pspecs; i++) { - GValue *value = gimp_value_array_index (args, i); + GParamSpec *pspec = pspecs[i]; + GValue value = G_VALUE_INIT; + g_string_append_c (s, ' '); - script_fu_arg_append_repr_from_gvalue (&script->args[i], - s, - value); + + g_value_init (&value, pspec->value_type); + g_object_get_property (G_OBJECT (config), pspec->name, &value); + script_fu_arg_append_repr_from_gvalue (&script->args[i - 1], s, &value); + g_value_unset (&value); } g_string_append_c (s, ')'); + g_free (pspecs); return g_string_free (s, FALSE); } diff --git a/plug-ins/script-fu/libscriptfu/script-fu-script.h b/plug-ins/script-fu/libscriptfu/script-fu-script.h index be1f51fbe5..f11914fa0b 100644 --- a/plug-ins/script-fu/libscriptfu/script-fu-script.h +++ b/plug-ins/script-fu/libscriptfu/script-fu-script.h @@ -53,7 +53,7 @@ gchar * script_fu_script_get_command_for_image_proc ( GimpImage *image, guint n_drawables, GimpDrawable **drawables, - const GimpValueArray *args); + GimpProcedureConfig *config); GimpProcedure * script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in, SFScript *script,