[gimp/gimp-2-10] plug-ins: improve formatting of gps data in metadata-viewer.



commit f3c4e7af99fdcda5f8cf28034e18a4157e643797
Author: Jacob Boerema <jgboerema gmail com>
Date:   Wed Nov 25 22:49:04 2020 -0500

    plug-ins: improve formatting of gps data in metadata-viewer.
    
    Adding metadata-tags to Makefile.am for
    the metadata-viewer since until now it was only used in
    the metadata-editor.
    
    The Exif gps metadata tags for longitude, latitude and
    altitude get special handling to show them with more
    precision and let the string parts be translated.
    
    (cherry picked from commit 34407a6b7e1cef63a0d3cbe21df06b1509c0ea13)
    
    # Conflicts:
    #       plug-ins/metadata/meson.build
    #       plug-ins/metadata/metadata-viewer.c

 plug-ins/metadata/Makefile.am       |   4 +-
 plug-ins/metadata/metadata-viewer.c | 139 ++++++++++++++++++++++++++++++++++--
 2 files changed, 135 insertions(+), 8 deletions(-)
---
diff --git a/plug-ins/metadata/Makefile.am b/plug-ins/metadata/Makefile.am
index d7be32fe91..23e00f2c8d 100644
--- a/plug-ins/metadata/Makefile.am
+++ b/plug-ins/metadata/Makefile.am
@@ -40,7 +40,9 @@ metadata_editor_SOURCES = \
        metadata-xml.h
 
 metadata_viewer_SOURCES = \
-       metadata-viewer.c
+       metadata-viewer.c       \
+       metadata-tags.c         \
+       metadata-tags.h
 
 AM_CPPFLAGS = \
        -I$(top_srcdir) \
diff --git a/plug-ins/metadata/metadata-viewer.c b/plug-ins/metadata/metadata-viewer.c
index d18f80766d..34d44cb7d1 100644
--- a/plug-ins/metadata/metadata-viewer.c
+++ b/plug-ins/metadata/metadata-viewer.c
@@ -30,6 +30,7 @@
 
 #include "libgimp/stdplugins-intl.h"
 
+#include "metadata-tags.h"
 
 #define PLUG_IN_PROC   "plug-in-metadata-viewer"
 #define PLUG_IN_BINARY "metadata-viewer"
@@ -89,6 +90,18 @@ static void       metadata_dialog_append_tags      (GExiv2Metadata  *metadata,
                                                     gint             tag_column,
                                                     gint             value_column,
                                                     gboolean         load_iptc);
+static void metadata_dialog_add_tag                (GtkListStore    *store,
+                                                    GtkTreeIter      iter,
+                                                    gint             tag_column,
+                                                    gint             value_column,
+                                                    const gchar     *tag,
+                                                    const gchar     *value);
+static void metadata_dialog_add_translated_tag     (GExiv2Metadata  *metadata,
+                                                    GtkListStore    *store,
+                                                    GtkTreeIter      iter,
+                                                    gint             tag_column,
+                                                    gint             value_column,
+                                                    const gchar     *tag);
 static gchar    * metadata_dialog_format_tag_value (GExiv2Metadata  *metadata,
                                                     const gchar     *tag,
                                                     gboolean         truncate);
@@ -107,6 +120,7 @@ const GimpPlugInInfo PLUG_IN_INFO =
 /*  functions  */
 
 MAIN ()
+static void metadata_dialog_add_tag               (GtkListStore    *store,
 
 static void
 query (void)
@@ -330,6 +344,40 @@ metadata_tag_is_string (const gchar *tag)
           g_strcmp0 (tag_type, NULL)        != 0);
 }
 
+static void
+metadata_dialog_add_tag (GtkListStore    *store,
+                         GtkTreeIter      iter,
+                         gint             tag_column,
+                         gint             value_column,
+                         const gchar     *tag,
+                         const gchar     *value)
+{
+  if (value)
+    {
+      gtk_list_store_append (store, &iter);
+      gtk_list_store_set (store, &iter,
+                          tag_column,   tag,
+                          value_column, value,
+                          -1);
+    }
+}
+
+static void
+metadata_dialog_add_translated_tag (GExiv2Metadata  *metadata,
+                                    GtkListStore    *store,
+                                    GtkTreeIter      iter,
+                                    gint             tag_column,
+                                    gint             value_column,
+                                    const gchar     *tag)
+{
+  gchar *value;
+
+  value = gexiv2_metadata_get_tag_interpreted_string (metadata, tag);
+  metadata_dialog_add_tag (store, iter, tag_column, value_column,
+                           tag, gettext (value));
+  g_free (value);
+}
+
 static void
 metadata_dialog_append_tags (GExiv2Metadata  *metadata,
                              gchar          **tags,
@@ -341,6 +389,7 @@ metadata_dialog_append_tags (GExiv2Metadata  *metadata,
   GtkTreeIter  iter;
   const gchar *tag;
   const gchar *last_tag = NULL;
+  gboolean     gps_done = FALSE;
 
   while ((tag = *tags++))
     {
@@ -385,19 +434,95 @@ metadata_dialog_append_tags (GExiv2Metadata  *metadata,
 
               g_strfreev (values);
             }
+        }
+      else if (! strcmp ("Exif.GPSInfo.GPSLongitude",    tag) ||
+               ! strcmp ("Exif.GPSInfo.GPSLongitudeRef", tag) ||
+               ! strcmp ("Exif.GPSInfo.GPSLatitude",     tag) ||
+               ! strcmp ("Exif.GPSInfo.GPSLatitudeRef",  tag) ||
+               ! strcmp ("Exif.GPSInfo.GPSAltitude",     tag) ||
+               ! strcmp ("Exif.GPSInfo.GPSAltitudeRef",  tag))
+        {
+          /* We need special handling for some of the GPS tags to
+           * be able to show better values than the default. */
+          if (! gps_done)
+            {
+              gdouble  lng, lat, alt;
+              gchar   *str;
+              gchar  *value;
 
+              if (gexiv2_metadata_get_gps_longitude (GEXIV2_METADATA (metadata),
+                                                     &lng))
+                {
+                  str = metadata_format_gps_longitude_latitude (lng);
+                  metadata_dialog_add_tag (store, iter,
+                                           tag_column, value_column,
+                                           "Exif.GPSInfo.GPSLongitude",
+                                           str);
+                  g_free (str);
+                }
+              metadata_dialog_add_translated_tag (metadata, store, iter,
+                                                  tag_column, value_column,
+                                                  "Exif.GPSInfo.GPSLongitudeRef");
+
+              if (gexiv2_metadata_get_gps_latitude (GEXIV2_METADATA (metadata),
+                                                    &lat))
+                {
+                  str = metadata_format_gps_longitude_latitude (lat);
+                  metadata_dialog_add_tag (store, iter,
+                                           tag_column, value_column,
+                                           "Exif.GPSInfo.GPSLatitude",
+                                           str);
+                  g_free (str);
+                }
+              metadata_dialog_add_translated_tag (metadata, store, iter,
+                                                  tag_column, value_column,
+                                                  "Exif.GPSInfo.GPSLatitudeRef");
+
+              if (gexiv2_metadata_get_gps_altitude (GEXIV2_METADATA (metadata),
+                                                    &alt))
+                {
+                  gchar *str2, *str3;
+
+                  str  = metadata_format_gps_altitude (alt, TRUE,  _(" meter"));
+                  str2 = metadata_format_gps_altitude (alt, FALSE, _(" feet"));
+                  str3 = g_strdup_printf ("%s (%s)", str, str2);
+                  metadata_dialog_add_tag (store, iter,
+                                           tag_column, value_column,
+                                           "Exif.GPSInfo.GPSAltitude",
+                                           str3);
+                  g_free (str);
+                  g_free (str2);
+                  g_free (str3);
+                  value = gexiv2_metadata_get_tag_string (metadata,
+                                                          "Exif.GPSInfo.GPSAltitudeRef");
+
+                  if (value)
+                    {
+                      gint index;
+
+                      if (value[0] == '0')
+                        index = 1;
+                      else if (value[0] == '1')
+                        index = 2;
+                      else
+                        index = 0;
+                      metadata_dialog_add_tag (store, iter,
+                                              tag_column, value_column,
+                                              "Exif.GPSInfo.GPSAltitudeRef",
+                                              gettext (gpsaltref[index]));
+                      g_free (value);
+                    }
+                }
+              gps_done = TRUE;
+            }
         }
       else
         {
           value = metadata_dialog_format_tag_value (metadata, tag,
                                                     /* truncate = */ TRUE);
-
-          gtk_list_store_append (store, &iter);
-          gtk_list_store_set (store, &iter,
-                              tag_column,   tag,
-                              value_column, value,
-                              -1);
-
+          metadata_dialog_add_tag (store, iter,
+                                   tag_column, value_column,
+                                   tag, value);
           g_free (value);
         }
     }


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