libgimp: reimplement gimp_procedure_run_config() for public usage.

Previous gimp_procedure_run_config() was in fact only good for private usage
inside the various run() methods for the different GimpProcedure subtypes. The
problem with this implementation is that the returned config object is not
complete. For instance, for a GimpLoadProcedure, the "run-mode" and "file"
properties are not part of the config object so you cannot call a
GimpLoadProcedure with any of the gimp_procedure_run*() functions.

Note: we had some working usage, e.g. in file-openraster, but only because it
was running the load procedure as a GimpPDBProcedure whose returned config
object was indeed always complete!

As a consequence, I rename gimp_procedure_run_config() as an internal-only
function _gimp_procedure_create_run_config() and I create a new
gimp_procedure_run_config() which always return a full config with all
arguments.
This commit is contained in:
Jehan 2024-05-01 21:47:55 +02:00
parent 5bcc6bfe52
commit a4bb3a48a2
9 changed files with 62 additions and 18 deletions

View File

@ -161,7 +161,7 @@ gimp_batch_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value); gimp_value_array_append (remaining, value);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
_gimp_procedure_config_begin_run (config, NULL, run_mode, remaining); _gimp_procedure_config_begin_run (config, NULL, run_mode, remaining);
gimp_value_array_unref (remaining); gimp_value_array_unref (remaining);

View File

@ -366,7 +366,7 @@ gimp_export_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value); gimp_value_array_append (remaining, value);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
if (export_proc->priv->export_metadata) if (export_proc->priv->export_metadata)
{ {
mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure)); mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure));

View File

@ -174,7 +174,7 @@ gimp_image_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value); gimp_value_array_append (remaining, value);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
_gimp_procedure_config_begin_run (config, image, run_mode, remaining); _gimp_procedure_config_begin_run (config, image, run_mode, remaining);
return_values = image_proc->priv->run_func (procedure, return_values = image_proc->priv->run_func (procedure,

View File

@ -206,7 +206,7 @@ gimp_load_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value); gimp_value_array_append (remaining, value);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure)); mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure));
if (mimetype != NULL) if (mimetype != NULL)

View File

@ -130,6 +130,12 @@ static GimpProcedureConfig * gimp_procedure_real_create_config (GimpProcedure
GParamSpec **args, GParamSpec **args,
gint n_args); gint n_args);
static GimpProcedureConfig *
gimp_procedure_create_config_with_prefix (GimpProcedure *procedure,
const gchar *prefix,
GParamSpec **args,
gint n_args);
static GimpValueArray * gimp_procedure_new_arguments (GimpProcedure *procedure); static GimpValueArray * gimp_procedure_new_arguments (GimpProcedure *procedure);
static gboolean gimp_procedure_validate_args (GimpProcedure *procedure, static gboolean gimp_procedure_validate_args (GimpProcedure *procedure,
GParamSpec **param_specs, GParamSpec **param_specs,
@ -510,7 +516,7 @@ gimp_procedure_real_run (GimpProcedure *procedure,
image = GIMP_VALUES_GET_IMAGE (args, 1); image = GIMP_VALUES_GET_IMAGE (args, 1);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
_gimp_procedure_config_begin_run (config, image, run_mode, args); _gimp_procedure_config_begin_run (config, image, run_mode, args);
retvals = procedure->priv->run_func (procedure, config, retvals = procedure->priv->run_func (procedure, config,
@ -540,11 +546,22 @@ static GimpProcedureConfig *
gimp_procedure_real_create_config (GimpProcedure *procedure, gimp_procedure_real_create_config (GimpProcedure *procedure,
GParamSpec **args, GParamSpec **args,
gint n_args) gint n_args)
{
return gimp_procedure_create_config_with_prefix (procedure,
"GimpProcedureConfigRun",
args, n_args);
}
static GimpProcedureConfig *
gimp_procedure_create_config_with_prefix (GimpProcedure *procedure,
const gchar *prefix,
GParamSpec **args,
gint n_args)
{ {
gchar *type_name; gchar *type_name;
GType type; GType type;
type_name = g_strdup_printf ("GimpProcedureConfig-%s", type_name = g_strdup_printf ("%s-%s", prefix,
gimp_procedure_get_name (procedure)); gimp_procedure_get_name (procedure));
type = g_type_from_name (type_name); type = g_type_from_name (type_name);
@ -1992,6 +2009,29 @@ gimp_procedure_run_config (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
/**
* _gimp_procedure_create_run_config:
* @procedure: A #GimpProcedure
*
* Create a #GimpConfig with properties that match @procedure's arguments, to be
* used in the run() method for @procedure.
*
* This is an internal function to be used only by libgimp code.
*
* Returns: (transfer full): The new #GimpConfig.
*
* Since: 3.0
**/
GimpProcedureConfig *
_gimp_procedure_create_run_config (GimpProcedure *procedure)
{
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL);
return GIMP_PROCEDURE_GET_CLASS (procedure)->create_config (procedure,
procedure->priv->args,
procedure->priv->n_args);
}
GimpValueArray * GimpValueArray *
_gimp_procedure_run_array (GimpProcedure *procedure, _gimp_procedure_run_array (GimpProcedure *procedure,
GimpValueArray *args) GimpValueArray *args)
@ -2022,7 +2062,7 @@ _gimp_procedure_run_array (GimpProcedure *procedure,
GimpValueArray *complete; GimpValueArray *complete;
/* if saved defaults exist, they override GParamSpec */ /* if saved defaults exist, they override GParamSpec */
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
if (gimp_procedure_config_load_default (config, NULL)) if (gimp_procedure_config_load_default (config, NULL))
config_class = G_OBJECT_GET_CLASS (config); config_class = G_OBJECT_GET_CLASS (config);
else else
@ -2125,7 +2165,8 @@ gimp_procedure_extension_ready (GimpProcedure *procedure)
* gimp_procedure_create_config: * gimp_procedure_create_config:
* @procedure: A #GimpProcedure * @procedure: A #GimpProcedure
* *
* Create a #GimpConfig with properties that match @procedure's arguments. * Create a #GimpConfig with properties that match @procedure's arguments, to be
* used in [method@Procedure.run_config] method.
* *
* Returns: (transfer full): The new #GimpConfig. * Returns: (transfer full): The new #GimpConfig.
* *
@ -2136,9 +2177,10 @@ gimp_procedure_create_config (GimpProcedure *procedure)
{ {
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL); g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL);
return GIMP_PROCEDURE_GET_CLASS (procedure)->create_config (procedure, return gimp_procedure_create_config_with_prefix (procedure,
procedure->priv->args, "GimpProcedureConfig",
procedure->priv->n_args); procedure->priv->args,
procedure->priv->n_args);
} }

View File

@ -251,8 +251,10 @@ GimpProcedureConfig *
/* Internal use */ /* Internal use */
G_GNUC_INTERNAL GimpValueArray * _gimp_procedure_run_array (GimpProcedure *procedure, G_GNUC_INTERNAL GimpProcedureConfig * _gimp_procedure_create_run_config (GimpProcedure *procedure);
GimpValueArray *args);
G_GNUC_INTERNAL GimpValueArray * _gimp_procedure_run_array (GimpProcedure *procedure,
GimpValueArray *args);
G_END_DECLS G_END_DECLS

View File

@ -535,10 +535,10 @@ _gimp_procedure_config_get_values (GimpProcedureConfig *config,
/* The config will have 1 additional property: "procedure". */ /* The config will have 1 additional property: "procedure". */
g_return_if_fail (n_pspecs == n_values + n_aux_args + 1); g_return_if_fail (n_pspecs == n_values + n_aux_args + 1);
for (i = 1; i < n_pspecs; i++) for (i = 0; i < n_values; i++)
{ {
GParamSpec *pspec = pspecs[i]; GParamSpec *pspec = pspecs[i + 1];
GValue *value = gimp_value_array_index (values, i - 1); GValue *value = gimp_value_array_index (values, i);
g_object_get_property (G_OBJECT (config), pspec->name, value); g_object_get_property (G_OBJECT (config), pspec->name, value);
} }

View File

@ -164,7 +164,7 @@ gimp_thumbnail_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value); gimp_value_array_append (remaining, value);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
_gimp_procedure_config_begin_run (config, NULL, GIMP_RUN_NONINTERACTIVE, remaining); _gimp_procedure_config_begin_run (config, NULL, GIMP_RUN_NONINTERACTIVE, remaining);
gimp_value_array_unref (remaining); gimp_value_array_unref (remaining);

View File

@ -210,7 +210,7 @@ gimp_vector_load_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value); gimp_value_array_append (remaining, value);
} }
config = gimp_procedure_create_config (procedure); config = _gimp_procedure_create_run_config (procedure);
mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure)); mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure));
if (mimetype != NULL) if (mimetype != NULL)