[gimp/metadata-browser: 24/44] Merge changes back into raw values during serialisation



commit c50040b985a0703e4e336908b3a50b067acf5415
Author: Roman Joost <roman bromeco de>
Date:   Mon Sep 26 21:01:51 2011 +1000

    Merge changes back into raw values during serialisation
    
    In case widgets changed the string representation of the raw values,
    merge them back when serializing.

 plug-ins/metadata/xmp-encode.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/plug-ins/metadata/xmp-encode.c b/plug-ins/metadata/xmp-encode.c
index fde07ed..4000c10 100644
--- a/plug-ins/metadata/xmp-encode.c
+++ b/plug-ins/metadata/xmp-encode.c
@@ -105,6 +105,7 @@ static void
 gen_property (GString            *buffer,
               const XMPSchema    *schema,
               const XMPProperty  *property,
+              const gchar        *value,
               const gchar       **value_array)
 {
   gint         i;
@@ -159,18 +160,31 @@ gen_property (GString            *buffer,
     case XMP_TYPE_LANG_ALT:
       g_string_append_printf (buffer, "  <%s:%s>\n   <rdf:Alt>\n",
                               schema->prefix, property->name);
-      for (i = 0; value_array[i] != NULL; i += 2)
-        {
-         if (value_array[i+1] == NULL)
-          {
+      if (value_array == NULL && value != NULL)
+       {
+         gen_element (buffer, 4,
+                      "rdf", "li", value,
+                      "xml:lang", "x-default",
+                      NULL);
+       }
+      else
+       {
+        for (i = 0; value_array[i] != NULL; i += 2)
+         {
+          if (value_array[i+1] == NULL)
+           {
             g_printerr("Bailing out:%s:%s", schema->prefix, property->name);
             break;
-          }
+           }
+          if (i == 0 && value_array[i+1] != value)
+            value_array[i+1] = g_strdup (value);
+
           gen_element (buffer, 4,
                        "rdf", "li", value_array[i + 1],
                        "xml:lang", value_array[i],
                        NULL);
-        }
+         }
+       }
       g_string_append_printf (buffer, "   </rdf:Alt>\n  </%s:%s>\n",
                               schema->prefix, property->name);
       break;
@@ -280,9 +294,11 @@ xmp_generate_packet (XMPModel *xmp_model,
                 {
                   const XMPProperty  *property;
                   const gchar       **value_array;
+                  const gchar        *value;
 
                   gtk_tree_model_get (model, &child,
                                       COL_XMP_TYPE_XREF, &property,
+                                      COL_XMP_VALUE,     &value,
                                       COL_XMP_VALUE_RAW, &value_array,
                                       -1);
                   /* do not process structured types multiple times */
@@ -290,7 +306,7 @@ xmp_generate_packet (XMPModel *xmp_model,
                     {
                       saved_ref = value_array;
                       g_return_if_fail (property->name != NULL);
-                      gen_property (buffer, schema, property, value_array);
+                      gen_property (buffer, schema, property, value, value_array);
                     }
                 }
               while (gtk_tree_model_iter_next (model, &child));



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