[gimp] libgimp: add gimp_procedure_config_save_metadata()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: add gimp_procedure_config_save_metadata()
- Date: Mon, 8 Jun 2020 12:29:28 +0000 (UTC)
commit afe98c5c703180e6e50a7d3274b192933fa18005
Author: Michael Natterer <mitch gimp org>
Date: Fri Jun 5 18:40:18 2020 +0200
libgimp: add gimp_procedure_config_save_metadata()
so the export's GimpMetadata can be written at any time during the
export process, which is for example needed for TIFF export.
libgimp/gimp.def | 1 +
libgimp/gimpprocedureconfig.c | 117 ++++++++++++++++++++++++++++--------------
libgimp/gimpprocedureconfig.h | 5 ++
3 files changed, 85 insertions(+), 38 deletions(-)
---
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 3d556c5cfa..26a8bcc983 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -700,6 +700,7 @@ EXPORTS
gimp_procedure_config_load_parasite
gimp_procedure_config_save_default
gimp_procedure_config_save_last
+ gimp_procedure_config_save_metadata
gimp_procedure_config_save_parasite
gimp_procedure_config_set_values
gimp_procedure_create_config
diff --git a/libgimp/gimpprocedureconfig.c b/libgimp/gimpprocedureconfig.c
index 3def738191..369665c26f 100644
--- a/libgimp/gimpprocedureconfig.c
+++ b/libgimp/gimpprocedureconfig.c
@@ -67,6 +67,7 @@ struct _GimpProcedureConfigPrivate
GimpMetadata *metadata;
gchar *mime_type;
GimpMetadataSaveFlags metadata_flags;
+ gboolean metadata_saved;
};
@@ -622,9 +623,10 @@ gimp_procedure_config_begin_export (GimpProcedureConfig *config,
* provides additional features to automate file export:
*
* If @status is %GIMP_PDB_SUCCESS, and
- * gimp_procedure_config_begin_export() returned a #GimpMetadata,
- * @config's export properties are synced back to the metadata's
- * #GimpMetadataSaveFlags and the metadata is written to @file using
+ * gimp_procedure_config_begin_export() returned a #GimpMetadata, this
+ * function calls gimp_procedure_config_save_metadata(), which syncs
+ * back @config's export properties to the metadata's
+ * #GimpMetadataSaveFlags and writes metadata to @file using
* gimp_image_metadata_save_finish().
*
* If the procedure has a "comment" argument, and it was modified
@@ -634,10 +636,10 @@ gimp_procedure_config_begin_export (GimpProcedureConfig *config,
* Since: 3.0
**/
void
-gimp_procedure_config_end_export (GimpProcedureConfig *config,
- GimpImage *exported_image,
- GFile *file,
- GimpPDBStatusType status)
+gimp_procedure_config_end_export (GimpProcedureConfig *config,
+ GimpImage *exported_image,
+ GFile *file,
+ GimpPDBStatusType status)
{
g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config));
g_return_if_fail (GIMP_IS_IMAGE (exported_image));
@@ -721,46 +723,85 @@ gimp_procedure_config_end_export (GimpProcedureConfig *config,
g_free (comment);
}
- if (config->priv->metadata)
- {
- gint i;
-
- for (i = 0; i < G_N_ELEMENTS (metadata_properties); i++)
- {
- const gchar *prop_name = metadata_properties[i].name;
- GimpMetadataSaveFlags prop_flag = metadata_properties[i].flag;
- GParamSpec *pspec;
- gboolean value;
-
- pspec = g_object_class_find_property (object_class, prop_name);
- if (pspec)
- {
- g_object_get (config,
- prop_name, &value,
- NULL);
-
- if (value)
- config->priv->metadata_flags |= prop_flag;
- else
- config->priv->metadata_flags &= ~prop_flag;
- }
-
- gimp_image_metadata_save_finish (exported_image,
- config->priv->mime_type,
- config->priv->metadata,
- config->priv->metadata_flags,
- file, NULL);
- }
- }
+ gimp_procedure_config_save_metadata (config, exported_image, file);
}
g_clear_object (&config->priv->metadata);
g_clear_pointer (&config->priv->mime_type, g_free);
config->priv->metadata_flags = 0;
+ config->priv->metadata_saved = FALSE;
gimp_procedure_config_end_run (config, status);
}
+/**
+ * gimp_procedure_config_save_metadata:
+ * @config: a #GimpProcedureConfig
+ * @exported_image: the #GimpImage that was actually exported
+ * @file: the #GFile @exported_image was written to
+ *
+ * Note: There is normally no need to call this function because it's
+ * already called from gimp_procedure_config_end_export().
+ *
+ * Only use this function if the #GimpMetadata returned by
+ * gimp_procedure_config_begin_run() needs to be written at a specific
+ * point of the export, other than its end.
+ *
+ * This function syncs back @config's export properties to the
+ * metadata's #GimpMetadataSaveFlags and writes the metadata to @file
+ * using gimp_image_metadata_save_finish().
+ *
+ * The metadata is only ever written once. If this function has been
+ * called explicitly, it will do nothing when called a second time
+ * from gimp_procedure_config_end_export().
+ *
+ * Since: 3.0
+ **/
+void
+gimp_procedure_config_save_metadata (GimpProcedureConfig *config,
+ GimpImage *exported_image,
+ GFile *file)
+{
+ g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config));
+ g_return_if_fail (GIMP_IS_IMAGE (exported_image));
+ g_return_if_fail (G_IS_FILE (file));
+
+ if (config->priv->metadata && ! config->priv->metadata_saved)
+ {
+ GObjectClass *object_class = G_OBJECT_GET_CLASS (config);
+ gint i;
+
+ for (i = 0; i < G_N_ELEMENTS (metadata_properties); i++)
+ {
+ const gchar *prop_name = metadata_properties[i].name;
+ GimpMetadataSaveFlags prop_flag = metadata_properties[i].flag;
+ GParamSpec *pspec;
+ gboolean value;
+
+ pspec = g_object_class_find_property (object_class, prop_name);
+ if (pspec)
+ {
+ g_object_get (config,
+ prop_name, &value,
+ NULL);
+
+ if (value)
+ config->priv->metadata_flags |= prop_flag;
+ else
+ config->priv->metadata_flags &= ~prop_flag;
+ }
+
+ gimp_image_metadata_save_finish (exported_image,
+ config->priv->mime_type,
+ config->priv->metadata,
+ config->priv->metadata_flags,
+ file, NULL);
+ }
+
+ config->priv->metadata_saved = TRUE;
+ }
+}
+
/* private functions */
diff --git a/libgimp/gimpprocedureconfig.h b/libgimp/gimpprocedureconfig.h
index a79f29c5a5..8114debb43 100644
--- a/libgimp/gimpprocedureconfig.h
+++ b/libgimp/gimpprocedureconfig.h
@@ -93,6 +93,11 @@ void gimp_procedure_config_end_export (GimpProcedureConfig *config,
GFile *file,
GimpPDBStatusType status);
+void gimp_procedure_config_save_metadata (GimpProcedureConfig *config,
+ GimpImage *exported_image,
+ GFile *file);
+
+
G_END_DECLS
#endif /* __GIMP_PROCEDURE_CONFIG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]