[gimp] plug-ins: fix incorrect saving of Iptc.Application2.Caption in metadata-editor.



commit 5d14c59d2e20a104b3d2929abe9851715b9015c1
Author: Jacob Boerema <jgboerema gmail com>
Date:   Wed Mar 24 12:51:24 2021 -0400

    plug-ins: fix incorrect saving of Iptc.Application2.Caption in metadata-editor.
    
    The saved value for Iptc.Application2.Caption is copied from Xmp.dc.description.
    However the last one is multiline but the former should be single line. This
    caused only the first line to be saved instead of all lines.
    
    To fix this we set Iptc.Application2.Caption to single and use a different
    conversion based on whether the tags from Xmp and Iptc are both
    multiline or whether Iptc is single line.

 plug-ins/metadata/metadata-editor.c | 35 ++++++++++++++++++++++++++++-------
 plug-ins/metadata/metadata-tags.c   |  2 +-
 2 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index d34d9ca7fb..527dd55d40 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -4260,15 +4260,36 @@ metadata_editor_write_callback (GtkWidget  *dialog,
 
                 gexiv2_metadata_clear_tag (GEXIV2_METADATA (g_metadata),
                                            equivalent_metadata_tags[index].tag);
-                multi = g_strsplit (text, "\n", 0);
-                if (! gexiv2_metadata_set_tag_multiple (GEXIV2_METADATA (g_metadata),
-                                                        equivalent_metadata_tags[index].tag,
-                                                        (const gchar **) multi))
+                if (! strcmp ("multi", equivalent_metadata_tags[index].mode))
                   {
-                    set_tag_failed (equivalent_metadata_tags[index].tag);
-                  }
+                    multi = g_strsplit (text, "\n", 0);
+                    if (! gexiv2_metadata_set_tag_multiple (GEXIV2_METADATA (g_metadata),
+                                                            equivalent_metadata_tags[index].tag,
+                                                            (const gchar **) multi))
+                      {
+                        set_tag_failed (equivalent_metadata_tags[index].tag);
+                      }
 
-                g_strfreev (multi);
+                    g_strfreev (multi);
+                  }
+                else if (! strcmp ("single", equivalent_metadata_tags[index].mode))
+                  {
+                    /* Convert from multiline to single line: keep the \n and just add the whole text. */
+                    if (*text &&
+                        ! gexiv2_metadata_set_tag_string (GEXIV2_METADATA (g_metadata),
+                                                          equivalent_metadata_tags[index].tag,
+                                                          text))
+                      {
+                        set_tag_failed (equivalent_metadata_tags[index].tag);
+                      }
+                  }
+                else
+                  {
+                    g_warning ("Copying from multiline tag %s to %s tag %s not implemented!",
+                               default_metadata_tags[i].tag,
+                               equivalent_metadata_tags[index].mode,
+                               equivalent_metadata_tags[index].tag);
+                  }
               }
 
           if (text)
diff --git a/plug-ins/metadata/metadata-tags.c b/plug-ins/metadata/metadata-tags.c
index 8b542e2604..29c1e0f4b8 100644
--- a/plug-ins/metadata/metadata-tags.c
+++ b/plug-ins/metadata/metadata-tags.c
@@ -150,7 +150,7 @@ const metadata_tag equivalent_metadata_tags[] =
   { "Iptc.Application2.Urgency",                 "combo",  26,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 11
   { "Iptc.Application2.SubLocation",             "single", 28,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 12
   { "Iptc.Application2.Byline",                  "single",  1,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 13
-  { "Iptc.Application2.Caption",                 "multi",   2,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 14
+  { "Iptc.Application2.Caption",                 "single",  2,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 14
   { "Iptc.Application2.Keywords",                "multi",   3,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 15
   { "Iptc.Application2.ObjectName",              "single",  0,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 16
   { "Iptc.Application2.Copyright",               "single",  4,  TAG_TYPE_IPTC, GIMP_XMP_NONE }, // 17


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]