[gimp/metadata-browser] metadata: file parsing of XMP data replaced by libgexiv2



commit a8c1babd736ae0037c7790444b7ae0e5226f49d3
Author: Roman Joost <roman bromeco de>
Date:   Wed Feb 27 12:57:36 2013 +1000

    metadata: file parsing of XMP data replaced by libgexiv2

 .../metadata/tests/test-xmp-model-functional.c     |   32 +++++----------
 plug-ins/metadata/tests/test-xmp-model.c           |    4 +-
 plug-ins/metadata/xmp-model.c                      |   41 ++++++++++++++-----
 3 files changed, 43 insertions(+), 34 deletions(-)
---
diff --git a/plug-ins/metadata/tests/test-xmp-model-functional.c 
b/plug-ins/metadata/tests/test-xmp-model-functional.c
index 9b8ddb4..df02352 100644
--- a/plug-ins/metadata/tests/test-xmp-model-functional.c
+++ b/plug-ins/metadata/tests/test-xmp-model-functional.c
@@ -99,10 +99,10 @@ static void
 test_xmp_model_import_export_structures (GimpTestFixture *fixture,
                                          gconstpointer    data)
 {
-  int             i, j;
+  int             i;
   gboolean        result;
-  const gchar   **before_value;
-  const gchar   **after_value;
+  const gchar    *before_value;
+  const gchar    *after_value;
   GString        *buffer;
   TestDataEntry  *testdata;
   const gchar    *scalarvalue = "test";
@@ -122,9 +122,9 @@ test_xmp_model_import_export_structures (GimpTestFixture *fixture,
     testdata = &(import_exportdata[i]);
 
     /* backup the original raw value */
-    before_value = xmp_model_get_raw_property_value (fixture->xmp_model,
-                                                     testdata->schema_name,
-                                                     testdata->name);
+    before_value = xmp_model_get_scalar_property (fixture->xmp_model,
+                                                  testdata->schema_name,
+                                                  testdata->name);
     g_assert (before_value != NULL);
 
     /* set a new scalar value */
@@ -144,23 +144,13 @@ test_xmp_model_import_export_structures (GimpTestFixture *fixture,
                             buffer->len,
                             TRUE,
                             error);
-    after_value = xmp_model_get_raw_property_value (fixture->xmp_model,
-                                                    testdata->schema_name,
-                                                    testdata->name);
+    after_value = xmp_model_get_scalar_property (fixture->xmp_model,
+                                                 testdata->schema_name,
+                                                 testdata->name);
     /* check that the scalar value is correctly exported */
     g_assert (after_value != NULL);
-    g_assert_cmpstr (after_value[testdata->pos], ==, scalarvalue);
-
-    /* check that the original data is not changed */
-    for (j = 0; after_value[j] != NULL; ++j)
-     {
-       if (j == testdata->pos)
-         continue;
+    g_assert_cmpstr (after_value, ==, scalarvalue);
 
-       g_assert (before_value[j] != NULL);
-       g_assert (after_value[j]  != NULL);
-       g_assert_cmpstr (before_value[j], ==, after_value[j]);
-     }
    }
 }
 
diff --git a/plug-ins/metadata/tests/test-xmp-model.c b/plug-ins/metadata/tests/test-xmp-model.c
index 2d8681c..754cae3 100644
--- a/plug-ins/metadata/tests/test-xmp-model.c
+++ b/plug-ins/metadata/tests/test-xmp-model.c
@@ -261,7 +261,7 @@ test_xmp_model_parse_file (GimpTestFixture *fixture,
 
   // title
   value = xmp_model_get_scalar_property (fixture->xmp_model, "dc", "title");
-  g_assert_cmpstr (value, == , "image title");
+  g_assert_cmpstr (value, == , "lang=\"x-default\" image title");
 
   // creator
   value = xmp_model_get_scalar_property (fixture->xmp_model, "dc", "creator");
@@ -269,7 +269,7 @@ test_xmp_model_parse_file (GimpTestFixture *fixture,
 
   // description
   value = xmp_model_get_scalar_property (fixture->xmp_model, "dc", "description");
-  g_assert_cmpstr (value, == , "bla");
+  g_assert_cmpstr (value, == , "lang=\"x-default\" bla, lang=\"de_de\" Deutsche Beschreibung");
 
   g_free (uri);
 }
diff --git a/plug-ins/metadata/xmp-model.c b/plug-ins/metadata/xmp-model.c
index bf7b6f3..1154c4c 100644
--- a/plug-ins/metadata/xmp-model.c
+++ b/plug-ins/metadata/xmp-model.c
@@ -25,6 +25,8 @@
 
 #include <libgimp/gimp.h>
 
+#include <gexiv2/gexiv2.h>
+
 #include "libgimp/stdplugins-intl.h"
 
 #include "xmp-schemas.h"
@@ -772,19 +774,36 @@ xmp_model_parse_file (XMPModel     *xmp_model,
                       const gchar  *filename,
                       GError      **error)
 {
-  gchar *buffer;
-  gsize  buffer_length;
-
-  g_return_val_if_fail (filename != NULL, FALSE);
-
-  if (! g_file_get_contents (filename, &buffer, &buffer_length, error))
+  GExiv2Metadata *metadata  = NULL;
+  gchar         **tags      = NULL;
+  gchar          *tag       = NULL;
+  gchar          *value     = NULL;
+  gchar         **temp      = NULL;
+  int             i         = 0;
+
+  metadata = gexiv2_metadata_new ();
+  if (! gexiv2_metadata_open_path (metadata, filename, error))
     return FALSE;
 
-  if (! xmp_model_parse_buffer (xmp_model, buffer, buffer_length, TRUE, error))
-    return FALSE;
+  tags = gexiv2_metadata_get_xmp_tags (metadata);
 
-  g_free (buffer);
+  for (i = 0; tags[i] != NULL; i++)
+   {
+    tag = tags[i];
+    value = gexiv2_metadata_get_xmp_tag_string (metadata, tag);
+
+    /* the value is of the form: Xmp.<schema>.<property_name>. Split and
+     * use the last items of the array to set the value.
+     */
+    temp = g_strsplit (tag, ".", 0);
+    if (! xmp_model_set_scalar_property (xmp_model, temp[1], temp[2], value))
+      g_printerr ("\n Unable to set XMP tag: %s:%s - %s\n", temp[1], temp[2], value);
+   }
 
+  gexiv2_metadata_free (metadata);
+  g_free (tags);
+  g_free (temp);
+  g_free (value);
   return TRUE;
 }
 


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