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.
This commit is contained in:
Jehan 2023-10-15 19:22:32 +02:00
parent 8881079d9d
commit f25e0448b2
9 changed files with 141 additions and 173 deletions

View file

@ -733,9 +733,7 @@ EXPORTS
gimp_procedure_config_get_choice_id gimp_procedure_config_get_choice_id
gimp_procedure_config_get_procedure gimp_procedure_config_get_procedure
gimp_procedure_config_get_type gimp_procedure_config_get_type
gimp_procedure_config_get_values
gimp_procedure_config_save_metadata gimp_procedure_config_save_metadata
gimp_procedure_config_set_values
gimp_procedure_create_config gimp_procedure_create_config
gimp_procedure_extension_ready gimp_procedure_extension_ready
gimp_procedure_find_argument gimp_procedure_find_argument

View file

@ -31,6 +31,7 @@
#include "gimppdb_pdb.h" #include "gimppdb_pdb.h"
#include "gimppdbprocedure.h" #include "gimppdbprocedure.h"
#include "gimpplugin-private.h" #include "gimpplugin-private.h"
#include "gimpprocedureconfig-private.h"
#include "libgimp-intl.h" #include "libgimp-intl.h"
@ -394,7 +395,7 @@ gimp_pdb_run_procedure_config (GimpPDB *pdb,
args = gimp_procedure_new_arguments (procedure); 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); return_values = gimp_pdb_run_procedure_array (pdb, procedure_name, args);
gimp_value_array_unref (args); gimp_value_array_unref (args);

View file

@ -22,6 +22,9 @@
#ifndef __GIMP_PROCEDURE_CONFIG_PRIVATE_H__ #ifndef __GIMP_PROCEDURE_CONFIG_PRIVATE_H__
#define __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, void _gimp_procedure_config_begin_run (GimpProcedureConfig *config,
GimpImage *image, GimpImage *image,
GimpRunMode run_mode, GimpRunMode run_mode,

View file

@ -79,6 +79,10 @@ static void gimp_procedure_config_get_property (GObject *obje
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_procedure_config_set_values (GimpProcedureConfig *config,
const GimpValueArray *values);
static gboolean gimp_procedure_config_load_last (GimpProcedureConfig *config, static gboolean gimp_procedure_config_load_last (GimpProcedureConfig *config,
GError **error); GError **error);
static gboolean gimp_procedure_config_save_last (GimpProcedureConfig *config, static gboolean gimp_procedure_config_save_last (GimpProcedureConfig *config,
@ -233,98 +237,6 @@ gimp_procedure_config_get_procedure (GimpProcedureConfig *config)
return config->priv->procedure; 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 static void
gimp_procedure_config_get_parasite (GimpProcedureConfig *config, gimp_procedure_config_get_parasite (GimpProcedureConfig *config,
GParamSpec *pspec) GParamSpec *pspec)
@ -590,6 +502,50 @@ gimp_procedure_config_get_choice_id (GimpProcedureConfig *config,
/* Functions only used by GimpProcedure classes */ /* 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: * _gimp_procedure_config_begin_run:
* @config: a #GimpProcedureConfig * @config: a #GimpProcedureConfig
@ -1038,6 +994,54 @@ _gimp_procedure_config_save_default (GimpProcedureConfig *config,
/* private functions */ /* 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 static gboolean
gimp_procedure_config_load_last (GimpProcedureConfig *config, gimp_procedure_config_load_last (GimpProcedureConfig *config,
GError **error) GError **error)

View file

@ -70,10 +70,6 @@ GType gimp_procedure_config_get_type (void) G_GNUC_CONST;
GimpProcedure * GimpProcedure *
gimp_procedure_config_get_procedure (GimpProcedureConfig *config); 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, void gimp_procedure_config_save_metadata (GimpProcedureConfig *config,
GimpImage *exported_image, GimpImage *exported_image,

View file

@ -105,17 +105,8 @@ script_fu_interpret_image_proc (GimpProcedure *procedure,
GimpValueArray *result = NULL; GimpValueArray *result = NULL;
gboolean interpretation_result; gboolean interpretation_result;
GError *error = NULL; 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)); command = script_fu_script_get_command_for_image_proc (script, image, n_drawables, drawables, config);
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);
/* Take responsibility for handling errors from the scripts further calls to PDB. /* 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. * 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_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
GIMP_PDB_ERROR_HANDLER_INTERNAL); GIMP_PDB_ERROR_HANDLER_INTERNAL);
gimp_value_array_unref (args);
return result; return result;
} }

View file

@ -60,72 +60,37 @@ dump_properties (GimpProcedureConfig *config)
g_free (pspecs); 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 static void
fill_gva_from (GimpProcedureConfig *config, dump_objects (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)
{ {
/* Check it will return non-null objects. */ /* Check it will return non-null objects. */
GimpValueArray *args; GParamSpec **pspecs;
gint length; guint n_pspecs;
/* Need one less gvalue !!! */ pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_pspecs);
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));
fill_gva_from (config, args); /* config will have at least 1 property: "procedure". */
if (n_pspecs == 1)
gimp_procedure_config_get_values (config, args);
if (args == NULL)
{ {
g_debug ("config holds no values"); g_debug ("config holds no values");
return; 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); GParamSpec *pspec = pspecs[i];
if (G_VALUE_HOLDS_OBJECT (gvalue)) GValue value = G_VALUE_INIT;
if (g_value_get_object (gvalue) == NULL)
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_debug ("gvalue %d holds NULL object", i);
g_value_unset (&value);
} }
g_free (pspecs);
} }
#endif #endif

View file

@ -405,11 +405,15 @@ script_fu_script_get_command_for_image_proc (SFScript *script,
GimpImage *image, GimpImage *image,
guint n_drawables, guint n_drawables,
GimpDrawable **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 (script != NULL, NULL);
g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL);
s = g_string_new ("("); s = g_string_new ("(");
g_string_append (s, script->name); 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); script_fu_command_append_drawables (s, n_drawables, drawables);
/* args contains the "other" args /* config contains the "other" args
* Iterate over the GimpValueArray. * Iterate over the GimpValueArray.
* But script->args should be the same length, and types should match. * 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, ' '); g_string_append_c (s, ' ');
script_fu_arg_append_repr_from_gvalue (&script->args[i],
s, g_value_init (&value, pspec->value_type);
value); 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_string_append_c (s, ')');
g_free (pspecs);
return g_string_free (s, FALSE); return g_string_free (s, FALSE);
} }

View file

@ -53,7 +53,7 @@ gchar * script_fu_script_get_command_for_image_proc (
GimpImage *image, GimpImage *image,
guint n_drawables, guint n_drawables,
GimpDrawable **drawables, GimpDrawable **drawables,
const GimpValueArray *args); GimpProcedureConfig *config);
GimpProcedure * script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in, GimpProcedure * script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in,
SFScript *script, SFScript *script,