Commit 9cb62f5f authored by Michael Natterer's avatar Michael Natterer 😴

libgimp: move "image" and "run_mode" from gimp_procedure_config_end_run()

and remember them internally between begin_run() and end_run().
Simplifies plug-in code even more.

Move the begin_run() before gimp_export_image() block in all export
plug-ins.
parent 1f7c823a
......@@ -56,6 +56,9 @@ enum
struct _GimpProcedureConfigPrivate
{
GimpProcedure *procedure;
GimpImage *image;
GimpRunMode run_mode;
};
......@@ -122,6 +125,8 @@ static void
gimp_procedure_config_init (GimpProcedureConfig *config)
{
config->priv = gimp_procedure_config_get_instance_private (config);
config->priv->run_mode = -1;
}
static void
......@@ -344,6 +349,9 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
g_return_if_fail (args != NULL);
config->priv->image = image;
config->priv->run_mode = run_mode;
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE :
......@@ -377,22 +385,21 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
/**
* gimp_procedure_config_end_run:
* @config: a #GimpProcedureConfig
* @image: a #GimpImage or %NULL
* @run_mode: the #GimpRunMode passed to a #GimpProcedure's run()
* @status: the return status of the #GimpProcedure's run()
* @config: a #GimpProcedureConfig
* @status: the return status of the #GimpProcedure's run()
*
* This function is the counterpart of
* gimp_procedure_conig_begin_run() and must always be called in pairs
* in a procedure's run(), before returning return values.
*
* If @run_mode is %GIMP_RUN_INTERACTIVE, @config is saved as last
* used values to be used when the procedure runs again. Additionally,
* if @image is not %NULL, @config is attached to @image as last used
* values for this image using a #GimpParasite and
* gimp_image_attach_parasite().
* If the @run_mode passed to gimp_procedure_config_end_run() was
* %GIMP_RUN_INTERACTIVE, @config is saved as last used values to be
* used when the procedure runs again. Additionally, the @image passed
* gimp_procedure_config_begin_run() was not %NULL, @config is
* attached to @image as last used values for this image using a
* #GimpParasite and gimp_image_attach_parasite().
*
* If @run_mode is not %GIMP_RUN_NONINTERACTIVE, this function also
* If @run_mode was not %GIMP_RUN_NONINTERACTIVE, this function also
* conveniently calls gimp_display_flush(), which is what most
* procedures want and doesn't do any harm if called redundantly.
*
......@@ -401,24 +408,21 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
* Since: 3.0
**/
void
gimp_procedure_config_end_run (GimpProcedureConfig *config,
GimpImage *image,
GimpRunMode run_mode,
GimpPDBStatusType status)
gimp_procedure_config_end_run (GimpProcedureConfig *config,
GimpPDBStatusType status)
{
g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config));
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
if (run_mode != GIMP_RUN_NONINTERACTIVE)
if (config->priv->run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
if (status == GIMP_PDB_SUCCESS &&
run_mode == GIMP_RUN_INTERACTIVE)
if (status == GIMP_PDB_SUCCESS &&
config->priv->run_mode == GIMP_RUN_INTERACTIVE)
{
GError *error = NULL;
if (image)
gimp_procedure_config_save_parasite (config, image);
if (config->priv->image)
gimp_procedure_config_save_parasite (config, config->priv->image);
if (! gimp_procedure_config_save_last (config, &error))
{
......@@ -427,6 +431,9 @@ gimp_procedure_config_end_run (GimpProcedureConfig *config,
g_clear_error (&error);
}
}
config->priv->image = NULL;
config->priv->run_mode = -1;
}
......
......@@ -80,8 +80,6 @@ void gimp_procedure_config_begin_run (GimpProcedureConfig *config,
GimpRunMode run_mode,
const GimpValueArray *args);
void gimp_procedure_config_end_run (GimpProcedureConfig *config,
GimpImage *image,
GimpRunMode run_mode,
GimpPDBStatusType status);
......
......@@ -252,7 +252,7 @@ despeckle_run (GimpProcedure *procedure,
despeckle (drawable, G_OBJECT (config));
gimp_procedure_config_end_run (config, NULL, run_mode, GIMP_PDB_SUCCESS);
gimp_procedure_config_end_run (config, GIMP_PDB_SUCCESS);
g_object_unref (config);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
......
......@@ -169,38 +169,13 @@ gbr_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpImage *orig_image;
gchar *description;
GError *error = NULL;
INIT_I18N ();
orig_image = image;
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY);
export = gimp_export_image (&image, &drawable, "GBR",
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_INDEXED |
GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CANCEL,
NULL);
break;
default:
break;
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
gimp_procedure_config_begin_run (config, image, run_mode, args);
g_object_get (config,
"description", &description,
......@@ -223,6 +198,28 @@ gbr_save (GimpProcedure *procedure,
g_free (description);
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY);
export = gimp_export_image (&image, &drawable, "GBR",
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_INDEXED |
GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CANCEL,
NULL);
break;
default:
break;
}
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
......@@ -265,7 +262,7 @@ gbr_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
......
......@@ -259,6 +259,9 @@ heif_save (GimpProcedure *procedure,
INIT_I18N ();
gegl_init (NULL, NULL);
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
orig_image = image;
switch (run_mode)
......@@ -281,9 +284,6 @@ heif_save (GimpProcedure *procedure,
break;
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
......@@ -317,7 +317,7 @@ heif_save (GimpProcedure *procedure,
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
......
......@@ -148,37 +148,13 @@ pat_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpImage *orig_image;
gchar *description;
GError *error = NULL;
INIT_I18N ();
orig_image = image;
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY);
export = gimp_export_image (&image, &drawable, "PAT",
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_INDEXED |
GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL)
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
NULL);
break;
default:
break;
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
gimp_procedure_config_begin_run (config, image, run_mode, args);
g_object_get (config,
"description", &description,
......@@ -201,6 +177,27 @@ pat_save (GimpProcedure *procedure,
g_free (description);
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY);
export = gimp_export_image (&image, &drawable, "PAT",
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_INDEXED |
GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL)
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
NULL);
break;
default:
break;
}
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
......@@ -238,7 +235,7 @@ pat_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
......
......@@ -423,6 +423,21 @@ png_save (GimpProcedure *procedure,
INIT_I18N ();
gegl_init (NULL, NULL);
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
#if 0
/* Override the defaults with preferences. */
metadata = gimp_image_metadata_save_prepare (image,
"image/png",
&metadata_flags);
pngvals.save_exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
pngvals.save_xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
pngvals.save_iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
pngvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
pngvals.save_profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
#endif
orig_image = image;
switch (run_mode)
......@@ -446,21 +461,6 @@ png_save (GimpProcedure *procedure,
break;
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
#if 0
/* Override the defaults with preferences. */
metadata = gimp_image_metadata_save_prepare (orig_image,
"image/png",
&metadata_flags);
pngvals.save_exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
pngvals.save_xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
pngvals.save_iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
pngvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
pngvals.save_profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
#endif
alpha = gimp_drawable_has_alpha (drawable);
/* If the image has no transparency, then there is usually no need
......@@ -536,7 +536,7 @@ png_save (GimpProcedure *procedure,
else
metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
gimp_image_metadata_save_finish (orig_image,
gimp_image_metadata_save_finish (image,
"image/png",
metadata, metadata_flags,
file, NULL);
......@@ -550,7 +550,7 @@ png_save (GimpProcedure *procedure,
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
......
......@@ -364,13 +364,13 @@ sunras_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpImage *orig_image;
GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
orig_image = image;
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
switch (run_mode)
{
......@@ -393,9 +393,6 @@ sunras_save (GimpProcedure *procedure,
break;
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
......@@ -411,7 +408,7 @@ sunras_save (GimpProcedure *procedure,
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
......
......@@ -233,13 +233,13 @@ sgi_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpImage *orig_image;
GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
orig_image = image;
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
switch (run_mode)
{
......@@ -263,9 +263,6 @@ sgi_save (GimpProcedure *procedure,
break;
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
......@@ -281,7 +278,7 @@ sgi_save (GimpProcedure *procedure,
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment