diff --git a/libgimp/gimpimagemetadata-save.c b/libgimp/gimpimagemetadata-save.c index 8f191053c0..b1a7a71e9b 100644 --- a/libgimp/gimpimagemetadata-save.c +++ b/libgimp/gimpimagemetadata-save.c @@ -106,8 +106,6 @@ gimp_image_metadata_save_prepare (GimpImage *image, if (metadata) { GDateTime *datetime; - GimpParasite *comment_parasite; - gchar *comment = NULL; gint image_width; gint image_height; gdouble xres; @@ -121,46 +119,12 @@ gimp_image_metadata_save_prepare (GimpImage *image, datetime = g_date_time_new_now_local (); - comment_parasite = gimp_image_get_parasite (image, "gimp-comment"); - if (comment_parasite) - { - guint32 parasite_size; - - comment = (gchar *) gimp_parasite_get_data (comment_parasite, ¶site_size); - comment = g_strndup (comment, parasite_size); - - gimp_parasite_free (comment_parasite); - } - /* Exif */ if (! gimp_export_exif () || ! gexiv2_metadata_has_exif (g2metadata)) *suggested_flags &= ~GIMP_METADATA_SAVE_EXIF; - if (comment) - { - gexiv2_metadata_try_set_tag_string (g2metadata, - "Exif.Photo.UserComment", - comment, &error); - if (error) - { - g_warning ("%s: failed to set metadata '%s': %s\n", - G_STRFUNC, "Exif.Photo.UserComment", error->message); - g_clear_error (&error); - } - - gexiv2_metadata_try_set_tag_string (g2metadata, - "Exif.Image.ImageDescription", - comment, &error); - if (error) - { - g_warning ("%s: failed to set metadata '%s': %s\n", - G_STRFUNC, "Exif.Image.ImageDescription", error->message); - g_clear_error (&error); - } - } - g_snprintf (buffer, sizeof (buffer), "%d:%02d:%02d %02d:%02d:%02d", g_date_time_get_year (datetime), @@ -279,7 +243,6 @@ gimp_image_metadata_save_prepare (GimpImage *image, g_free (datetime_buf); g_date_time_unref (datetime); - g_clear_pointer (&comment, g_free); /* EXIF Thumbnail */ @@ -722,7 +685,51 @@ gimp_image_metadata_save_filter (GimpImage *image, if ((flags & GIMP_METADATA_SAVE_EXIF) && support_exif) { - gchar **exif_data = gexiv2_metadata_get_exif_tags (GEXIV2_METADATA (metadata)); + gchar **exif_data = NULL; + + if ((flags & GIMP_METADATA_SAVE_COMMENT)) + { + GimpParasite *comment_parasite; + + comment_parasite = gimp_image_get_parasite (image, "gimp-comment"); + if (comment_parasite) + { + guint32 parasite_size; + gchar *comment = NULL; + + comment = (gchar *) gimp_parasite_get_data (comment_parasite, ¶site_size); + comment = g_strndup (comment, parasite_size); + + gimp_parasite_free (comment_parasite); + + if (comment) + { + gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata), + "Exif.Photo.UserComment", + comment, &code_error); + if (code_error) + { + g_warning ("%s: failed to set metadata '%s': %s\n", + G_STRFUNC, "Exif.Photo.UserComment", code_error->message); + g_clear_error (&code_error); + } + + gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata), + "Exif.Image.ImageDescription", + comment, &code_error); + if (code_error) + { + g_warning ("%s: failed to set metadata '%s': %s\n", + G_STRFUNC, "Exif.Image.ImageDescription", code_error->message); + g_clear_error (&code_error); + } + + g_free (comment); + } + } + } + + exif_data = gexiv2_metadata_get_exif_tags (GEXIV2_METADATA (metadata)); for (i = 0; exif_data[i] != NULL; i++) { diff --git a/libgimp/gimpprocedureconfig.c b/libgimp/gimpprocedureconfig.c index 0769fe874f..887c667bb3 100644 --- a/libgimp/gimpprocedureconfig.c +++ b/libgimp/gimpprocedureconfig.c @@ -426,6 +426,33 @@ gimp_procedure_config_save_metadata (GimpProcedureConfig *config, } } + if ((priv->metadata_flags & GIMP_METADATA_SAVE_COMMENT)) + { + gchar *comment_value = NULL; + gint len; + + /* To be able to synchronize the comment with metadata in + * _gimp_image_metadata_save_finish, we need the comment value + * that was possibly updated in the export dialog. + */ + + g_object_get (config, + "gimp-comment", &comment_value, + NULL); + if (comment_value && (len = strlen (comment_value)) > 0) + { + GimpParasite *parasite; + + parasite = gimp_parasite_new ("gimp-comment", + GIMP_PARASITE_PERSISTENT, + len + 1, comment_value); + + gimp_image_attach_parasite (exported_image, parasite); + gimp_parasite_free (parasite); + } + g_free (comment_value); + } + if (! _gimp_image_metadata_save_finish (exported_image, priv->mime_type, priv->metadata,