[eog/wip/phako/gexiv2: 2/2] all: Replace Exempi with gexiv2



commit 929419d849c5ce7f3e2d2b54ea69f528a899192a
Author: Jens Georg <mail jensge org>
Date:   Wed Feb 7 21:12:35 2018 +0100

    all: Replace Exempi with gexiv2

 meson.build                   |   17 +------
 src/eog-application.c         |   13 +----
 src/eog-exif-util.c           |    6 ++-
 src/eog-image-private.h       |    6 +--
 src/eog-image.c               |   14 ++---
 src/eog-metadata-details.c    |   10 +---
 src/eog-metadata-details.h    |    5 +--
 src/eog-metadata-reader-jpg.c |   12 ++++-
 src/eog-metadata-reader-png.c |   12 ++++-
 src/eog-metadata-reader.c     |    2 +-
 src/eog-metadata-reader.h     |    5 +--
 src/eog-metadata-sidebar.c    |    5 --
 src/eog-properties-dialog.c   |  105 +++++++---------------------------------
 13 files changed, 59 insertions(+), 153 deletions(-)
---
diff --git a/meson.build b/meson.build
index 97f8b17..d57f1c9 100644
--- a/meson.build
+++ b/meson.build
@@ -133,6 +133,8 @@ if get_option('libexif')
     eog_deps += libexif_dep
     config_h.set10('HAVE_EXIF', true,
                    description: 'EXIF Support.')
+    config_h.set10('HAVE_EXEMPI', true,
+                   description: 'XMP Support.')
   endif
 endif
 
@@ -149,19 +151,6 @@ if get_option('cms')
   endif
 endif
 
-# Exempi (optional)
-have_exempi = false
-if get_option('xmp')
-  libexempi_dep = dependency('exempi-2.0', version: '>= 1.99.5', required: false)
-  have_exempi = libexempi_dep.found()
-
-  if have_exempi
-    eog_deps += libexempi_dep
-    config_h.set10('HAVE_EXEMPI', true,
-                   description: 'XMP Support.')
-  endif
-endif
-
 # Jpeg (semi-optional)
 jpeg_deps = []
 
@@ -287,7 +276,7 @@ output += '  Source code location .......:  ' + meson.source_root() + '\n'
 output += '  Compiler ...................:  ' + cc.get_id() + '\n'
 output += '  Extra Compiler Warnings ....:  ' + ' '.join(compiler_flags) + '\n'
 output += '  EXIF support ...............:  ' + have_exif.to_string() + '\n'
-output += '  XMP support ................:  ' + have_exempi.to_string() + '\n'
+output += '  XMP support ................:  ' + have_exif.to_string() + '\n'
 output += '  JPEG support ...............:  ' + have_jpeg.to_string() + '\n'
 output += '  Colour management support ..:  ' + have_lcms.to_string() + '\n'
 output += '  GObject Introspection.......:  ' + have_gir.to_string() + '\n'
diff --git a/src/eog-application.c b/src/eog-application.c
index 95ca9ac..a3566ae 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -45,10 +45,6 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
-#if HAVE_EXEMPI
-#include <exempi/xmp.h>
-#endif
-
 #define APPLICATION_SERVICE_NAME "org.gnome.eog.ApplicationService"
 
 static void eog_application_load_accelerators (void);
@@ -279,9 +275,8 @@ eog_application_startup (GApplication *application)
        g_application_set_resource_base_path (application, "/org/gnome/eog");
        G_APPLICATION_CLASS (eog_application_parent_class)->startup (application);
 
-#ifdef HAVE_EXEMPI
-       xmp_init();
-#endif
+    gexiv2_initialize ();
+
        eog_debug_init ();
        eog_job_scheduler_init ();
        eog_thumbnail_init ();
@@ -334,10 +329,6 @@ eog_application_startup (GApplication *application)
 static void
 eog_application_shutdown (GApplication *application)
 {
-#ifdef HAVE_EXEMPI
-       xmp_terminate();
-#endif
-
        G_APPLICATION_CLASS (eog_application_parent_class)->shutdown (application);
 }
 
diff --git a/src/eog-exif-util.c b/src/eog-exif-util.c
index a39108d..4240e6d 100644
--- a/src/eog-exif-util.c
+++ b/src/eog-exif-util.c
@@ -310,8 +310,10 @@ const gchar *
 eog_exif_data_get_value (EogExifData *exif_data, const char *tag_id, gchar *buffer, guint buf_size)
 {
        char *data = gexiv2_metadata_get_tag_string (exif_data, tag_id);
-       strncpy (buffer, data, buf_size - 1);
-       g_free (data);
+       if (data != NULL) {
+               strncpy (buffer, data, buf_size - 1);
+               g_free (data);
+       }
 
        return buffer;
 }
diff --git a/src/eog-image-private.h b/src/eog-image-private.h
index e393dbf..7181943 100644
--- a/src/eog-image-private.h
+++ b/src/eog-image-private.h
@@ -28,10 +28,6 @@
 #include <librsvg/rsvg.h>
 #endif
 
-#ifdef HAVE_EXEMPI
-#include <exempi/xmp.h>
-#endif
-
 G_BEGIN_DECLS
 
 struct _EogImagePrivate {
@@ -75,7 +71,7 @@ struct _EogImagePrivate {
        GExiv2Metadata   *exif;
 #endif
 #ifdef HAVE_EXEMPI
-       XmpPtr   xmp;
+       GExiv2Metadata   *xmp;
 #endif
 
 #ifdef HAVE_LCMS
diff --git a/src/eog-image.c b/src/eog-image.c
index a0d67ad..23ef852 100644
--- a/src/eog-image.c
+++ b/src/eog-image.c
@@ -56,10 +56,6 @@
 #include <gexiv2/gexiv2.h>
 #endif
 
-#ifdef HAVE_EXEMPI
-#include <exempi/xmp.h>
-#endif
-
 #ifdef HAVE_LCMS
 #include <lcms2.h>
 #ifndef EXIF_TAG_GAMMA
@@ -136,7 +132,7 @@ eog_image_free_mem_private (EogImage *image)
 
 #ifdef HAVE_EXEMPI
                if (priv->xmp != NULL) {
-                       xmp_free (priv->xmp);
+                       g_object_unref (priv->xmp);
                        priv->xmp = NULL;
                }
 #endif
@@ -794,7 +790,7 @@ eog_image_set_xmp_data (EogImage *img, EogMetadataReader *md_reader)
        priv = img->priv;
 
        if (priv->xmp) {
-               xmp_free (priv->xmp);
+               g_object_unref (priv->xmp);
        }
        priv->xmp = eog_metadata_reader_get_xmp_data (md_reader);
 }
@@ -2048,7 +2044,9 @@ eog_image_get_exif_info (EogImage *img)
 
        g_mutex_lock (&priv->status_mutex);
 
-       g_object_ref (priv->exif);
+       if (priv->exif != NULL) {
+               g_object_ref (priv->exif);
+       }
        data = priv->exif;
 
        g_mutex_unlock (&priv->status_mutex);
@@ -2078,7 +2076,7 @@ eog_image_get_xmp_info (EogImage *img)
        priv = img->priv;
 
        g_mutex_lock (&priv->status_mutex);
-       data = (gpointer) xmp_copy (priv->xmp);
+       data = (gpointer) g_object_ref (priv->xmp);
        g_mutex_unlock (&priv->status_mutex);
 #endif
 
diff --git a/src/eog-metadata-details.c b/src/eog-metadata-details.c
index fdb8969..d9864df 100644
--- a/src/eog-metadata-details.c
+++ b/src/eog-metadata-details.c
@@ -29,10 +29,6 @@
 #if HAVE_EXIF
 #include <gexiv2/gexiv2.h>
 #endif
-#if HAVE_EXEMPI
-#include <exempi/xmp.h>
-#include <exempi/xmpconsts.h>
-#endif
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
@@ -591,7 +587,7 @@ eog_metadata_details_update (EogMetadataDetails *details, ExifData *data)
 }
 #endif /* HAVE_EXIF */
 
-#ifdef HAVE_EXEMPI
+#ifdef HAVE_EXEMPI_
 typedef struct {
        const char *id;
        MetadataCategory category;
@@ -610,7 +606,7 @@ static XmpNsCategory xmp_ns_category_map[] = {
 };
 
 static MetadataCategory
-get_xmp_category (XmpStringPtr schema)
+get_xmp_category (const char *schema)
 {
        MetadataCategory cat = XMP_CATEGORY_OTHER;
        const char *s = xmp_string_cstr(schema);
@@ -664,7 +660,7 @@ xmp_entry_insert (EogMetadataDetails *view, XmpStringPtr xmp_schema,
 }
 
 void
-eog_metadata_details_xmp_update (EogMetadataDetails *view, XmpPtr data)
+eog_metadata_details_xmp_update (EogMetadataDetails *view, GExiv2Metadata *data)
 {
        g_return_if_fail (EOG_IS_METADATA_DETAILS (view));
 
diff --git a/src/eog-metadata-details.h b/src/eog-metadata-details.h
index 0c66390..2eed72e 100644
--- a/src/eog-metadata-details.h
+++ b/src/eog-metadata-details.h
@@ -29,9 +29,6 @@
 #if HAVE_EXIF
 #include <gexiv2/gexiv2.h>
 #endif
-#if HAVE_EXEMPI
-#include <exempi/xmp.h>
-#endif
 
 G_BEGIN_DECLS
 
@@ -70,7 +67,7 @@ void                eog_metadata_details_update      (EogMetadataDetails *detail
 #if HAVE_EXEMPI
 G_GNUC_INTERNAL
 void                eog_metadata_details_xmp_update  (EogMetadataDetails *view,
-                                                     XmpPtr          xmp_data);
+                                                     GExiv2Metadata          *xmp_data);
 #endif
 
 G_END_DECLS
diff --git a/src/eog-metadata-reader-jpg.c b/src/eog-metadata-reader-jpg.c
index 420a193..9c12e4d 100644
--- a/src/eog-metadata-reader-jpg.c
+++ b/src/eog-metadata-reader-jpg.c
@@ -487,15 +487,21 @@ static gpointer
 eog_metadata_reader_jpg_get_xmp_data (EogMetadataReaderJpg *emr )
 {
        EogMetadataReaderJpgPrivate *priv;
-       XmpPtr xmp = NULL;
+       GExiv2Metadata *xmp = NULL;
 
        g_return_val_if_fail (EOG_IS_METADATA_READER (emr), NULL);
 
        priv = emr->priv;
 
        if (priv->xmp_chunk != NULL) {
-               xmp = xmp_new (((const char*)priv->xmp_chunk)+EOG_XMP_OFFSET,
-                              priv->xmp_len-EOG_XMP_OFFSET);
+               GError *error = NULL;
+        xmp = gexiv2_metadata_new ();
+        if (!gexiv2_metadata_open_buf (xmp, (guint8 *)priv->xmp_chunk+EOG_XMP_OFFSET,
+                              priv->xmp_len-EOG_XMP_OFFSET, &error)) {
+                       g_warning ("Failed to parse XMP data : %s", error->message);
+                       g_clear_error (&error);
+                       g_clear_object (&xmp);
+               }
        }
 
        return (gpointer)xmp;
diff --git a/src/eog-metadata-reader-png.c b/src/eog-metadata-reader-png.c
index 25f58d2..54dabd8 100644
--- a/src/eog-metadata-reader-png.c
+++ b/src/eog-metadata-reader-png.c
@@ -461,15 +461,21 @@ static gpointer
 eog_metadata_reader_png_get_xmp_data (EogMetadataReaderPng *emr )
 {
        EogMetadataReaderPngPrivate *priv;
-       XmpPtr xmp = NULL;
+       GExiv2Metadata *xmp = NULL;
 
        g_return_val_if_fail (EOG_IS_METADATA_READER_PNG (emr), NULL);
 
        priv = emr->priv;
 
        if (priv->xmp_chunk != NULL) {
-               xmp = xmp_new ((const char*)priv->xmp_chunk+EOG_XMP_OFFSET,
-                              priv->xmp_len-EOG_XMP_OFFSET);
+               GError *error = NULL;
+        xmp = gexiv2_metadata_new ();
+        if (!gexiv2_metadata_open_buf (xmp, (const char*)priv->xmp_chunk+EOG_XMP_OFFSET,
+                              priv->xmp_len-EOG_XMP_OFFSET, &error)) {
+                       g_warning ("Failed to parse XMP data : %s", error->message);
+                       g_clear_error (&error);
+                       g_clear_object (&xmp);
+        }
        }
 
        return (gpointer) xmp;
diff --git a/src/eog-metadata-reader.c b/src/eog-metadata-reader.c
index 399558d..c4a818a 100644
--- a/src/eog-metadata-reader.c
+++ b/src/eog-metadata-reader.c
@@ -85,7 +85,7 @@ eog_metadata_reader_get_exif_data (EogMetadataReader *emr)
 #endif
 
 #ifdef HAVE_EXEMPI
-XmpPtr
+GExiv2Metadata*
 eog_metadata_reader_get_xmp_data (EogMetadataReader *emr)
 {
        return EOG_METADATA_READER_GET_INTERFACE (emr)->get_xmp_ptr (emr);
diff --git a/src/eog-metadata-reader.h b/src/eog-metadata-reader.h
index 83e92ce..6a785fc 100644
--- a/src/eog-metadata-reader.h
+++ b/src/eog-metadata-reader.h
@@ -26,9 +26,6 @@
 #if HAVE_EXIF
 #include "eog-exif-util.h"
 #endif
-#if HAVE_EXEMPI
-#include <exempi/xmp.h>
-#endif
 #if HAVE_LCMS
 #include <lcms2.h>
 #endif
@@ -94,7 +91,7 @@ GExiv2Metadata*         eog_metadata_reader_get_exif_data     (EogMetadataReader *em
 
 #ifdef HAVE_EXEMPI
 G_GNUC_INTERNAL
-XmpPtr              eog_metadata_reader_get_xmp_data   (EogMetadataReader *emr);
+GExiv2Metadata*         eog_metadata_reader_get_xmp_data       (EogMetadataReader *emr);
 #endif
 
 #if 0
diff --git a/src/eog-metadata-sidebar.c b/src/eog-metadata-sidebar.c
index 5dc83cb..5498ac3 100644
--- a/src/eog-metadata-sidebar.c
+++ b/src/eog-metadata-sidebar.c
@@ -44,11 +44,6 @@
 #include "eog-exif-util.h"
 #endif
 
-#if HAVE_EXEMPI
-#include <exempi/xmp.h>
-#include <exempi/xmpconsts.h>
-#endif
-
 /* There's no exempi support in the sidebar yet */
 #if HAVE_EXIF  /*|| HAVE_EXEMPI */
 #define HAVE_METADATA 1
diff --git a/src/eog-properties-dialog.c b/src/eog-properties-dialog.c
index 334138a..9ee6187 100644
--- a/src/eog-properties-dialog.c
+++ b/src/eog-properties-dialog.c
@@ -39,10 +39,6 @@
 #include <gio/gio.h>
 #include <gtk/gtk.h>
 
-#if HAVE_EXEMPI
-#include <exempi/xmp.h>
-#include <exempi/xmpconsts.h>
-#endif
 #if HAVE_EXIF || HAVE_EXEMPI
 #define HAVE_METADATA 1
 #endif
@@ -217,61 +213,6 @@ pd_update_general_tab (EogPropertiesDialog *prop_dlg,
        g_free (bytes_str);
 }
 
-#if HAVE_EXEMPI
-static void
-eog_xmp_set_label (XmpPtr xmp,
-                  const char *ns,
-                  const char *propname,
-                  GtkWidget *w)
-{
-       uint32_t options;
-
-       XmpStringPtr value = xmp_string_new ();
-
-       if (xmp_get_property (xmp, ns, propname, value, &options)) {
-               if (XMP_IS_PROP_SIMPLE (options)) {
-                       gtk_label_set_text (GTK_LABEL (w), xmp_string_cstr (value));
-               } else if (XMP_IS_PROP_ARRAY (options)) {
-                       XmpIteratorPtr iter = xmp_iterator_new (xmp,
-                                                               ns,
-                                                               propname,
-                                                               XMP_ITER_JUSTLEAFNODES);
-
-                       GString *string = g_string_new ("");
-
-                       if (iter) {
-                               gboolean first = TRUE;
-
-                               while (xmp_iterator_next (iter, NULL, NULL, value, &options)
-                                      && !XMP_IS_PROP_QUALIFIER (options)) {
-
-                                       if (!first) {
-                                               g_string_append_printf(string, ", ");
-                                       } else {
-                                               first = FALSE;
-                                       }
-
-                                       g_string_append_printf (string,
-                                                               "%s",
-                                                               xmp_string_cstr (value));
-                               }
-
-                               xmp_iterator_free (iter);
-                       }
-
-                       gtk_label_set_text (GTK_LABEL (w), string->str);
-                       g_string_free (string, TRUE);
-               }
-       } else {
-               /* Property was not found */
-               /* Clear label so it won't show bogus data */
-               gtk_label_set_text (GTK_LABEL (w), NULL);
-       }
-
-       xmp_string_free (value);
-}
-#endif
-
 #if HAVE_METADATA
 static void
 pd_update_metadata_tab (EogPropertiesDialog *prop_dlg,
@@ -283,7 +224,7 @@ pd_update_metadata_tab (EogPropertiesDialog *prop_dlg,
        GExiv2Metadata    *exif_data;
 #endif
 #if HAVE_EXEMPI
-       XmpPtr      xmp_data;
+       GExiv2Metadata     *xmp_data;
 #endif
 
        g_return_if_fail (EOG_IS_PROPERTIES_DIALOG (prop_dlg));
@@ -361,37 +302,29 @@ pd_update_metadata_tab (EogPropertiesDialog *prop_dlg,
 #endif
 
 #if HAVE_EXEMPI
-       xmp_data = (XmpPtr) eog_image_get_xmp_info (image);
+       xmp_data = (GExiv2Metadata *) eog_image_get_xmp_info (image);
 
        if (xmp_data != NULL) {
-               eog_xmp_set_label (xmp_data,
-                                  NS_IPTC4XMP,
-                                  "Location",
-                                  priv->xmp_location_label);
-
-               eog_xmp_set_label (xmp_data,
-                                  NS_DC,
-                                  "description",
-                                  priv->xmp_description_label);
-
-               eog_xmp_set_label (xmp_data,
-                                  NS_DC,
-                                  "subject",
-                                  priv->xmp_keywords_label);
-
-               eog_xmp_set_label (xmp_data,
-                                  NS_DC,
-                                  "creator",
-                                  priv->xmp_creator_label);
-
-               eog_xmp_set_label (xmp_data,
-                                  NS_DC,
-                                  "rights",
-                                  priv->xmp_rights_label);
+               eog_exif_util_set_label_text (GTK_LABEL (priv->xmp_location_label),
+                               xmp_data, "Xmp.dc.location");
+
+               eog_exif_util_set_label_text (GTK_LABEL (priv->xmp_description_label),
+                               xmp_data, "Xmp.dc.description");
+
+               eog_exif_util_set_label_text (GTK_LABEL (priv->xmp_keywords_label),
+                               xmp_data, "Xmp.dc.subject");
 
+               eog_exif_util_set_label_text (GTK_LABEL (priv->xmp_creator_label),
+                               xmp_data, "Xmp.dc.creator");
+
+               eog_exif_util_set_label_text (GTK_LABEL (priv->xmp_rights_label),
+                               xmp_data, "Xmp.dc.rights");
+
+#if 0
                eog_metadata_details_xmp_update (EOG_METADATA_DETAILS (priv->metadata_details), xmp_data);
+#endif
 
-               xmp_free (xmp_data);
+               g_clear_object (&xmp_data);
        } else {
                /* Image has no XMP data */
 


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