[Xfce4-commits] <midori:master> Implement support for geo URI RFC 5870

Christian Dywan noreply at xfce.org
Thu May 5 22:54:01 CEST 2011


Updating branch refs/heads/master
         to 414997b236ada8e363f132e6e276a5f41e4609c5 (commit)
       from c7fbe841815d8c8140e537d4e5572fc656b4f011 (commit)

commit 414997b236ada8e363f132e6e276a5f41e4609c5
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu May 5 21:49:51 2011 +0200

    Implement support for geo URI RFC 5870

 data/midori.desktop.in |    2 +-
 midori/midori-view.c   |    9 ++++++++-
 midori/sokoke.c        |   28 ++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/data/midori.desktop.in b/data/midori.desktop.in
index 403ac3c..f5e2852 100644
--- a/data/midori.desktop.in
+++ b/data/midori.desktop.in
@@ -5,7 +5,7 @@ _Name=Midori
 _GenericName=Web Browser
 _Comment=Lightweight web browser
 Categories=GTK;Network;WebBrowser;
-MimeType=text/html;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;
+MimeType=text/html;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/geo;
 Exec=midori %u
 Icon=midori
 Terminal=false
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 96cd4e2..5777a0a 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -983,7 +983,14 @@ midori_view_web_view_navigation_decision_cb (WebKitWebView*             web_view
     JSContextRef js_context;
     gchar* result;
     const gchar* uri = webkit_network_request_get_uri (request);
-    if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri))
+    if (g_str_has_prefix (uri, "geo:"))
+    {
+        gchar* new_uri = sokoke_magic_uri (uri);
+        midori_view_set_uri (view, new_uri);
+        g_free (new_uri);
+        return TRUE;
+    }
+    else if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri))
     {
         if (sokoke_show_uri (gtk_widget_get_screen (GTK_WIDGET (web_view)),
                              uri, GDK_CURRENT_TIME, NULL))
diff --git a/midori/sokoke.c b/midori/sokoke.c
index 39b0a4d..4df529a 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -812,6 +812,7 @@ sokoke_external_uri (const gchar* uri)
 
     if (!uri || !strncmp (uri, "http", 4)
              || !strncmp (uri, "file", 4)
+             || !strncmp (uri, "geo", 3)
              || !strncmp (uri, "about:", 6))
         return FALSE;
 
@@ -850,6 +851,33 @@ sokoke_magic_uri (const gchar* uri)
     /* Add file:// if we have a local path */
     if (g_path_is_absolute (uri))
         return g_strconcat ("file://", uri, NULL);
+    /* Parse geo URI geo:48.202778,16.368472;crs=wgs84;u=40 as a location */
+    if (!strncmp (uri, "geo:", 4))
+    {
+        gchar* comma;
+        gchar* semicolon;
+        gchar* latitude;
+        gchar* longitude;
+        gchar* geo;
+
+        comma = strchr (&uri[4], ',');
+        /* geo:latitude,longitude[,altitude][;u=u][;crs=crs] */
+        if (!(comma && *comma))
+            return g_strdup (uri);
+        semicolon = strchr (comma + 1, ';');
+        if (!semicolon)
+            semicolon = strchr (comma + 1, ',');
+        latitude = g_strndup (&uri[4], comma - &uri[4]);
+        if (semicolon)
+            longitude = g_strndup (comma + 1, semicolon - comma - 1);
+        else
+            longitude = g_strdup (comma + 1);
+        geo = g_strdup_printf ("http://www.openstreetmap.org/?mlat=%s&mlon=%s",
+            latitude, longitude);
+        g_free (latitude);
+        g_free (longitude);
+        return geo;
+    }
     /* Do we have a protocol? */
     if (g_strstr_len (uri, 8, "://"))
         return sokoke_idn_to_punycode (g_strdup (uri));



More information about the Xfce4-commits mailing list