[gnome-maps] Handle the 'geo' URI scheme



commit 548128b8bcf0ceaf5c15540b1eff34ae1c5d2a91
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Mon Nov 2 18:27:29 2015 +0800

    Handle the 'geo' URI scheme
    
    This will let Maps open the geo: URI scheme as
    specified by RFC 5870.
    
    In its simplest form it looks like:
        geo:latitude,longitude
    
    An Android extension to set a description is also supported:
        geo:0,0?q=latitude,longitude(description)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756512

 data/org.gnome.Maps.desktop.in |    2 +-
 src/application.js             |   12 +++++++++++-
 src/mapView.js                 |   19 +++++++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.Maps.desktop.in b/data/org.gnome.Maps.desktop.in
index 44bf21e..ad41ea0 100644
--- a/data/org.gnome.Maps.desktop.in
+++ b/data/org.gnome.Maps.desktop.in
@@ -10,4 +10,4 @@ StartupNotify=true
 Categories=GNOME;GTK;Utility;
 _Keywords=Maps;
 DBusActivatable=true
-MimeType=application/vnd.geo+json
+MimeType=application/vnd.geo+json;x-scheme-handler/geo
diff --git a/src/application.js b/src/application.js
index 348a777..92b2448 100644
--- a/src/application.js
+++ b/src/application.js
@@ -254,10 +254,20 @@ const Application = new Lang.Class({
     },
 
     _openInternal: function(file) {
-        let content_type = Gio.content_type_guess(file.get_uri(), null)[0];
+        let uri = file.get_uri();
+
+        if (GLib.uri_parse_scheme(uri) === 'geo') {
+            /* we get an uri that looks like geo:///lat,lon, remove slashes */
+            let geoURI = uri.replace(/\//g, '');
+            this._mainWindow.mapView.goToGeoURI(geoURI);
+            return;
+        }
+
+        let content_type = Gio.content_type_guess(uri, null)[0];
         if (content_type === 'application/vnd.geo+json' ||
             content_type === 'application/json') {
             this._mainWindow.mapView.openGeoJSON(file);
+            return;
         }
     },
 
diff --git a/src/mapView.js b/src/mapView.js
index bf93654..03a1022 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -208,6 +208,25 @@ const MapView = new Lang.Class({
         }
     },
 
+    goToGeoURI: function(uri) {
+        try {
+            let location = new Location.Location({ heading: -1 });
+            location.set_from_uri(uri);
+
+            let place = new Place.Place({ location: location,
+                                          name: location.description,
+                                          store: false });
+            let marker = new PlaceMarker.PlaceMarker({ place: place,
+                                                       mapView: this });
+            this._placeLayer.add_marker(marker);
+            marker.goToAndSelect(true);
+        } catch(e) {
+            let msg = _("Failed to open GeoURI");
+            Application.notificationManager.showMessage(msg);
+            Utils.debug("failed to open GeoURI: %s".format(e.message));
+        }
+    },
+
     gotoUserLocation: function(animate) {
         if (!this._userLocation)
             return;


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