[evolution] Bug 771404 - Use OpenStreetMap or Google Maps to open maps



commit f977bd747fbd45c59bfe3a5b0e526beec74e7ade
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 12 19:31:51 2017 +0200

    Bug 771404 - Use OpenStreetMap or Google Maps to open maps

 .../org.gnome.evolution.addressbook.gschema.xml.in |    5 +
 src/addressbook/gui/widgets/eab-contact-display.c  |  106 ++++++++++++++++----
 .../gui/widgets/eab-contact-formatter.c            |    2 +-
 src/modules/addressbook/autocompletion-config.c    |   34 ++++++-
 4 files changed, 123 insertions(+), 24 deletions(-)
---
diff --git a/data/org.gnome.evolution.addressbook.gschema.xml.in 
b/data/org.gnome.evolution.addressbook.gschema.xml.in
index ba5fcbe..b300c89 100644
--- a/data/org.gnome.evolution.addressbook.gschema.xml.in
+++ b/data/org.gnome.evolution.addressbook.gschema.xml.in
@@ -115,5 +115,10 @@
       <summary>Show Certificates tab</summary>
       <_description>Whether to show Certificates tab in the editor</_description>
     </key>
+    <key type="s" name="open-map-target">
+      <default>'openstreetmap'</default>
+      <_summary>Where to open contact locations</_summary>
+      <_description>Currently supported values are “openstreetmap” and “google”; if unknown set, uses 
“openstreetmap”</_description>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/addressbook/gui/widgets/eab-contact-display.c 
b/src/addressbook/gui/widgets/eab-contact-display.c
index de972ff..ca34ad1 100644
--- a/src/addressbook/gui/widgets/eab-contact-display.c
+++ b/src/addressbook/gui/widgets/eab-contact-display.c
@@ -41,6 +41,9 @@
 #define TEXT_IS_RIGHT_TO_LEFT \
        (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
 
+#define GOOGLE_MAP_PREFIX "https://maps.google.com?q=";
+#define OPENSTREETMAP_PREFIX "https://www.openstreetmap.org/search?query=";
+
 struct _EABContactDisplayPrivate {
        EContact *contact;
 
@@ -80,6 +83,39 @@ G_DEFINE_TYPE (
        E_TYPE_WEB_VIEW)
 
 static void
+contact_display_open_map (EABContactDisplay *display,
+                         const gchar *query)
+{
+       GSettings *settings;
+       gchar *open_map_target;
+       gpointer parent;
+       gchar *uri;
+       const gchar *prefix;
+
+       g_return_if_fail (EAB_IS_CONTACT_DISPLAY (display));
+       g_return_if_fail (query != NULL);
+
+       parent = gtk_widget_get_toplevel (GTK_WIDGET (display));
+       parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
+
+       settings = e_util_ref_settings ("org.gnome.evolution.addressbook");
+       open_map_target = g_settings_get_string (settings, "open-map-target");
+       g_object_unref (settings);
+
+       if (open_map_target && g_ascii_strcasecmp (open_map_target, "google") == 0) {
+               prefix = GOOGLE_MAP_PREFIX;
+       } else {
+               prefix = OPENSTREETMAP_PREFIX;
+       }
+
+       g_free (open_map_target);
+
+       uri = g_strconcat (prefix, query, NULL);
+       e_show_uri (parent, uri);
+       g_free (uri);
+}
+
+static void
 contact_display_emit_send_message (EABContactDisplay *display,
                                    gint email_num)
 {
@@ -267,36 +303,50 @@ contact_display_hovering_over_link (EWebView *web_view,
                                     const gchar *title,
                                     const gchar *uri)
 {
-       EWebViewClass *web_view_class;
        EABContactDisplay *display;
        EContact *contact;
        const gchar *name;
        gchar *message;
+       gboolean handled = FALSE;
 
-       if (uri == NULL || *uri == '\0')
-               goto chainup;
+       if (uri && g_str_has_prefix (uri, "internal-mailto:";)) {
+               display = EAB_CONTACT_DISPLAY (web_view);
+               contact = eab_contact_display_get_contact (display);
 
-       if (!g_str_has_prefix (uri, "internal-mailto:";))
-               goto chainup;
+               name = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+               if (name == NULL)
+                       e_contact_get_const (contact, E_CONTACT_FULL_NAME);
+               g_return_if_fail (name != NULL);
 
-       display = EAB_CONTACT_DISPLAY (web_view);
-       contact = eab_contact_display_get_contact (display);
+               message = g_strdup_printf (_("Click to mail %s"), name);
+               e_web_view_status_message (web_view, message);
+               g_free (message);
+
+               handled = TRUE;
+       } else if (uri && g_str_has_prefix (uri, "open-map:")) {
+               SoupURI *suri;
+
+               suri = soup_uri_new (uri);
+               if (suri) {
+                       gchar *decoded;
 
-       name = e_contact_get_const (contact, E_CONTACT_FILE_AS);
-       if (name == NULL)
-               e_contact_get_const (contact, E_CONTACT_FULL_NAME);
-       g_return_if_fail (name != NULL);
+                       decoded = soup_uri_decode (soup_uri_get_path (suri));
 
-       message = g_strdup_printf (_("Click to mail %s"), name);
-       e_web_view_status_message (web_view, message);
-       g_free (message);
+                       message = g_strdup_printf (_("Click to open map for %s"), decoded);
+                       e_web_view_status_message (web_view, message);
+                       g_free (message);
 
-       return;
+                       handled = TRUE;
 
-chainup:
-       /* Chain up to parent's hovering_over_link() method. */
-       web_view_class = E_WEB_VIEW_CLASS (eab_contact_display_parent_class);
-       web_view_class->hovering_over_link (web_view, title, uri);
+                       soup_uri_free (suri);
+                       g_free (decoded);
+               }
+       }
+
+       if (!handled) {
+               /* Chain up to parent's method. */
+               E_WEB_VIEW_CLASS (eab_contact_display_parent_class)->hovering_over_link (web_view, title, 
uri);
+       }
 }
 
 static void
@@ -317,9 +367,21 @@ contact_display_link_clicked (EWebView *web_view,
                return;
        }
 
-       /* Chain up to parent's link_clicked() method. */
-       E_WEB_VIEW_CLASS (eab_contact_display_parent_class)->
-               link_clicked (web_view, uri);
+       length = strlen ("open-map:");
+       if (g_str_has_prefix (uri, "open-map:")) {
+               SoupURI *suri;
+
+               suri = soup_uri_new (uri);
+               if (suri) {
+                       contact_display_open_map (display, soup_uri_get_path (suri));
+                       soup_uri_free (suri);
+               }
+
+               return;
+       }
+
+       /* Chain up to parent's method. */
+       E_WEB_VIEW_CLASS (eab_contact_display_parent_class)->link_clicked (web_view, uri);
 }
 
 static void
diff --git a/src/addressbook/gui/widgets/eab-contact-formatter.c 
b/src/addressbook/gui/widgets/eab-contact-formatter.c
index e7ae78c..84eb485 100644
--- a/src/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/src/addressbook/gui/widgets/eab-contact-formatter.c
@@ -138,7 +138,7 @@ render_address_link (GString *buffer,
                g_string_assign (link, escaped);
                g_free (escaped);
 
-               g_string_prepend (link, "<a href=\"http://maps.google.com?q=";);
+               g_string_prepend (link, "<a href=\"open-map:");
                g_string_append_printf (link, "\">%s</a>", _("Open map"));
        }
 
diff --git a/src/modules/addressbook/autocompletion-config.c b/src/modules/addressbook/autocompletion-config.c
index de9baa7..3e00c03 100644
--- a/src/modules/addressbook/autocompletion-config.c
+++ b/src/modules/addressbook/autocompletion-config.c
@@ -95,6 +95,7 @@ get_general_page (EConfig *config,
        ESourceRegistry *registry;
        GtkWidget *container;
        GtkWidget *itembox;
+       GtkWidget *label;
        GtkWidget *widget;
        GtkWidget *vbox;
        EShell *shell;
@@ -123,7 +124,7 @@ get_general_page (EConfig *config,
                DTFormatKindDateTime, _("_Table column:"));
        gtk_widget_show (widget);
 
-       itembox = add_section (vbox, _("Address formatting"), FALSE);
+       itembox = add_section (vbox, _("Miscellaneous"), FALSE);
 
        widget = gtk_check_button_new_with_mnemonic (
                _("_Format address according to standard of its destination country"));
@@ -134,6 +135,37 @@ get_general_page (EConfig *config,
        gtk_box_pack_start (GTK_BOX (itembox), widget, FALSE, FALSE, 0);
        gtk_widget_show (widget);
 
+       container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+       gtk_box_pack_start (GTK_BOX (itembox), container, FALSE, FALSE, 0);
+       gtk_widget_show (container);
+
+       /* Translators: This is part of a sentence "Open maps with OpenStreetMap" and "Open maps with Google" 
*/
+       label = gtk_label_new_with_mnemonic (C_("OpenMap", "Open _maps with"));
+       gtk_box_pack_start (GTK_BOX (container), label, FALSE, FALSE, 0);
+       gtk_widget_show (label);
+
+       widget = gtk_combo_box_text_new ();
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "openstreetmap",
+               /* Translators: This is part of "Open maps with OpenStreetMap" */
+               C_("OpenMap", "OpenStreetMap"));
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "google",
+               /* Translators: This is part of "Open maps with Google" */
+               C_("OpenMap", "Google"));
+
+       gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
+
+       gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
+       gtk_widget_show (widget);
+
+       g_settings_bind (
+               settings, "open-map-target",
+               widget, "active-id",
+               G_SETTINGS_BIND_DEFAULT);
+
+       /* In case user has some garbage/unknown value set there */
+       if (!gtk_combo_box_get_active_id (GTK_COMBO_BOX (widget)))
+               gtk_combo_box_set_active_id (GTK_COMBO_BOX (widget), "openstreetmap");
+
        itembox = add_section (vbox, _("Autocompletion"), TRUE);
 
        widget = gtk_check_button_new_with_mnemonic (


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