[gimp/gimp-attributes-wip: 147/148] libgimpbase/plug-ins: implement GPS show in Google Maps



commit bf9c4ceca0d6924bba964eb5b235072cb38029ca
Author: Hartmut Kuhse <hk_priv gmx de>
Date:   Sat Feb 7 14:19:18 2015 +0100

    libgimpbase/plug-ins: implement GPS show in Google Maps

 libgimpbase/gimpattribute.c  |   54 ++++++++++++++++++++++
 libgimpbase/gimpattribute.h  |    1 +
 libgimpbase/gimpbase.def     |    1 +
 plug-ins/common/attributes.c |  102 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 158 insertions(+), 0 deletions(-)
---
diff --git a/libgimpbase/gimpattribute.c b/libgimpbase/gimpattribute.c
index 16d3bb0..6825025 100644
--- a/libgimpbase/gimpattribute.c
+++ b/libgimpbase/gimpattribute.c
@@ -829,6 +829,60 @@ gimp_attribute_print (GimpAttribute *attribute)
 }
 
 /**
+ * gimp_attribute_get_gps_degree:
+ *
+ * @attribute:    a @GimpAttribute
+ *
+ * returns the degree representation of the #GimpAttributes GPS value,
+ * -999.9 otherwise.
+ *
+ * Return value:  #gdouble degree representation of the #GimpAttributes GPS value
+ *
+ * Since: 2.10
+ */
+gdouble
+gimp_attribute_get_gps_degree (GimpAttribute *attribute)
+{
+  gdouble               return_val;
+  GimpAttributePrivate *private;
+
+  g_return_val_if_fail (attribute != NULL, TAG_INVALID);
+
+  private = GIMP_ATTRIBUTE_GET_PRIVATE (attribute);
+
+  if (private->value_type == TYPE_RATIONAL)
+    {
+      gint i;
+      gdouble        r_val    = 0.0;
+      Rational      *rational;
+
+      string_to_rational (private->tag_value, &rational);
+
+      for (i = 0; i < rational->length; i++)
+        {
+          RationalValue or;
+
+          or = g_array_index (rational->rational_array, RationalValue, i);
+
+          r_val = (gfloat)or.nom / (gfloat)or.denom;
+
+          if (i == 0)
+            return_val = r_val;
+          else if (i == 1)
+            return_val = return_val + (r_val / 60);
+          else if (i == 2)
+            return_val = return_val + (r_val / 3600);
+          else return -999.9;
+        }
+
+      return return_val;
+    }
+  else
+    return -999.9;
+
+}
+
+/**
  * gimp_attribute_get_xml:
  *
  * @attribute:    a @GimpAttribute
diff --git a/libgimpbase/gimpattribute.h b/libgimpbase/gimpattribute.h
index adf0951..c4b3a15 100644
--- a/libgimpbase/gimpattribute.h
+++ b/libgimpbase/gimpattribute.h
@@ -88,6 +88,7 @@ GSList*                     gimp_attribute_get_attribute_structure        (GimpA
 void                        gimp_attribute_set_structure_type             (GimpAttribute              
*attribute,
                                                                            GimpAttributeStructureType  
value);
 GimpAttributeStructureType  gimp_attribute_get_structure_type             (GimpAttribute              
*attribute);
+gdouble                     gimp_attribute_get_gps_degree                 (GimpAttribute              
*attribute);
 gchar*                      gimp_attribute_get_xml                        (GimpAttribute              
*attribute);
 void                        gimp_attribute_print                          (GimpAttribute              
*attribute);
 
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index ac6574e..888bc2e 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -15,6 +15,7 @@ EXPORTS
        gimp_attribute_get_value
        gimp_attribute_get_value_type
        gimp_attribute_get_value_type_from_string
+       gimp_attribute_get_gps_degree
        gimp_attribute_get_xml
        gimp_attribute_has_structure
        gimp_attribute_is_valid
diff --git a/plug-ins/common/attributes.c b/plug-ins/common/attributes.c
index 4d60a26..9a79ce4 100644
--- a/plug-ins/common/attributes.c
+++ b/plug-ins/common/attributes.c
@@ -40,6 +40,7 @@
 #endif
 
 #include <glib/gstdio.h>
+#include <gio/gio.h>
 
 #ifdef G_OS_WIN32
 #include <io.h>
@@ -50,6 +51,7 @@
 
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
+#include <libgimpbase/gimpbase.h>
 
 #include "libgimp/stdplugins-intl.h"
 
@@ -62,6 +64,8 @@
 
 #define THUMB_SIZE       48
 #define RESPONSE_EXPORT   1
+#define RESPONSE_IMPORT   2
+#define RESPONSE_GPS      3
 
 typedef enum
 {
@@ -108,6 +112,8 @@ static void            attributes_file_export_dialog      (GtkWidget        *par
 static void            attributes_export_dialog_response  (GtkWidget        *dlg,
                                                            gint              response_id,
                                                            gpointer          data);
+static void            attributes_show_gps                (GtkWidget        *parent,
+                                                           GimpAttributes   *attributes);
 
 static void            attributes_message_dialog          (GtkMessageType    type,
                                                            GtkWindow        *parent,
@@ -129,6 +135,12 @@ static GHashTable *tab_table = NULL;
 
 static gchar      *item_name = NULL;
 
+static GtkWidget   *gps_button;
+static gdouble      gps_latitude       = 0.0;
+static gdouble      gps_longitude      = 0.0;
+static gchar       *gps_latitude_ref   = "N";
+static gchar       *gps_longitude_ref  = "W";
+
 /*  functions  */
 
 MAIN ()
@@ -293,6 +305,14 @@ attributes_dialog_response (GtkWidget *widget,
     case RESPONSE_EXPORT:
       attributes_file_export_dialog (widget, attributes);
       break;
+    case RESPONSE_IMPORT:
+      attributes_message_dialog (GTK_MESSAGE_ERROR, GTK_WINDOW (widget),
+                               _("Failed"),
+                               _("Not yet implemented"));
+      break;
+    case RESPONSE_GPS:
+      attributes_show_gps (widget, attributes);
+      break;
 
     default:
       gtk_widget_destroy (widget);
@@ -378,9 +398,14 @@ attributes_dialog (gint32           item_id,
                             NULL, 0,
                             gimp_standard_help_func, PLUG_IN_HELP,
                             _("_Export XMP..."), RESPONSE_EXPORT,
+                            _("_Import XMP..."), RESPONSE_IMPORT,
+//                            _("_Show GPS..."), RESPONSE_GPS,
                             GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
                             NULL);
 
+  gps_button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Show GPS..."), RESPONSE_GPS);
+  gtk_widget_set_sensitive (GTK_WIDGET (gps_button), FALSE);
+
   g_signal_connect (dialog, "response",
                     G_CALLBACK (attributes_dialog_response),
                     attributes);
@@ -397,7 +422,9 @@ attributes_dialog (gint32           item_id,
                                550);
 
   gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+                                           RESPONSE_GPS,
                                            RESPONSE_EXPORT,
+                                           RESPONSE_IMPORT,
                                            GTK_RESPONSE_CLOSE,
                                            -1);
 
@@ -462,6 +489,8 @@ attributes_dialog_set_attributes (GimpAttributes *attributes,
   GtkWidget      *attributes_notebook;
   GList          *iter_list   = NULL;
   GimpAttribute  *attribute   = NULL;
+  gboolean        gps_lat     = FALSE;
+  gboolean        gps_lon     = FALSE;
 
   exif_store = GTK_TREE_STORE (gtk_builder_get_object (builder,
                                                        "exif-treestore"));
@@ -508,6 +537,43 @@ attributes_dialog_set_attributes (GimpAttributes *attributes,
 
       parent = attributes_get_parent (type, ifd);
 
+      if (! g_strcmp0 (name, "Exif.GPSInfo.GPSLatitude"))
+        {
+          gps_lat = TRUE;
+          gps_latitude = gimp_attribute_get_gps_degree (attribute);
+          if (gps_latitude < 0.0 && !gps_latitude_ref)
+            {
+              gps_latitude = gps_latitude * -1.0;
+              gps_latitude_ref = "S";
+            }
+
+        }
+      if (! g_strcmp0 (name, "Exif.GPSInfo.GPSLatitudeRef"))
+        {
+          gps_latitude_ref = gimp_attribute_get_string (attribute);
+        }
+      if (! g_strcmp0 (name, "Exif.GPSInfo.GPSLongitude"))
+        {
+          gps_lon = TRUE;
+          gps_longitude = gimp_attribute_get_gps_degree (attribute);
+          if (gps_longitude < 0.0 && !gps_longitude_ref)
+            {
+              gps_longitude = gps_longitude * -1.0;
+              gps_longitude_ref = "W";
+            }
+        }
+      if (! g_strcmp0 (name, "Exif.GPSInfo.GPSLongitudeRef"))
+        {
+          gps_longitude_ref = gimp_attribute_get_string (attribute);
+        }
+
+      if (gps_lat && gps_lon)
+        {
+          gtk_widget_set_sensitive (gps_button, TRUE);
+          gps_lat = FALSE;
+          gps_lon = FALSE;
+        }
+
       switch (gimp_attribute_get_tag_type (attribute))
       {
         case TAG_EXIF:
@@ -804,6 +870,41 @@ attributes_file_export_dialog (GtkWidget      *parent,
 //  gtk_dialog_run (GTK_DIALOG (dlg));
 }
 
+/* call default browser for google maps */
+static void
+attributes_show_gps (GtkWidget      *parent,
+                     GimpAttributes *attributes)
+{
+  GError  *error = NULL;
+  gchar   *uri   = NULL;
+  gchar    lat_buf[G_ASCII_DTOSTR_BUF_SIZE];
+  gchar    lon_buf[G_ASCII_DTOSTR_BUF_SIZE];
+
+  if (!g_strcmp0 (gps_latitude_ref, "S"))
+    gps_latitude = gps_latitude * -1.0;
+  if (!g_strcmp0 (gps_longitude_ref, "W"))
+    gps_longitude = gps_longitude * -1.0;
+
+  g_ascii_formatd (lat_buf, G_ASCII_DTOSTR_BUF_SIZE, "%.6f",
+                   gps_latitude);
+  g_ascii_formatd (lon_buf, G_ASCII_DTOSTR_BUF_SIZE, "%.6f",
+                   gps_longitude);
+
+  uri = g_strdup_printf ("http://maps.google.com?q=%s,%s&z=15";,
+                         lat_buf,
+                         lon_buf);
+
+  g_app_info_launch_default_for_uri (uri, NULL, &error);
+  if (error)
+    {
+      attributes_message_dialog (GTK_MESSAGE_ERROR, GTK_WINDOW (parent),
+                               _("GPS failure"),
+                               error->message);
+    }
+
+
+}
+
 /* save XMP metadata to a file (only XMP, nothing else) */
 static void
 attributes_export_dialog_response (GtkWidget *dlg,
@@ -890,3 +991,4 @@ attributes_message_dialog (GtkMessageType  type,
   gtk_dialog_run (GTK_DIALOG (dlg));
   gtk_widget_destroy (dlg);
 }
+


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