[gnome-maps/wip/mlundblad/maps-uri: 6/6] WIP: application: Handle maps: URIs




commit 2e20c6e5bca79ad562e5aea88bdda649e04aab0d
Author: Marcus Lundblad <ml update uu se>
Date:   Fri Oct 29 23:07:09 2021 +0200

    WIP: application: Handle maps: URIs

 src/application.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/src/application.js b/src/application.js
index 5985c87c..1a99adfc 100644
--- a/src/application.js
+++ b/src/application.js
@@ -33,6 +33,7 @@ const CheckIn = imports.checkIn;
 const ContactPlace = imports.contactPlace;
 const Format = imports.format;
 const Geoclue = imports.geoclue;
+const GeocodeFactory = imports.geocode;
 const MainWindow = imports.mainWindow;
 const Maps = imports.gi.GnomeMaps;
 const OSMEdit = imports.osmEdit;
@@ -311,16 +312,71 @@ var Application = GObject.registerClass({
         let scheme = GLib.uri_parse_scheme(uri);
 
         if (scheme === 'geo') {
-            /* we get an uri that looks like geo:///lat,lon, remove slashes */
+            // we get a URI that looks like geo:///lat,lon, remove slashes
             let geoURI = uri.replace(/\//g, '');
             this._mainWindow.mapView.goToGeoURI(geoURI);
         } else if (scheme === 'http' || scheme === 'https') {
             this._mainWindow.mapView.goToHttpURL(uri);
+        } else if (scheme === 'maps') {
+            // we get a URI that looks like maps:///q=Search, remove slashes
+            let mapsURI = uri.replace(/\//g, '');
+            this._openMapsUri(mapsURI);
         } else {
             this._mainWindow.mapView.openShapeLayers(files);
         }
     }
 
+    _openMapsUri(uri) {
+        let path = uri.substring('maps:'.length);
+        let [param, value] = Utils.splitAtFirst(path, '=');
+
+        if (param === 'q')
+            this._openMapsUriQuery(value);
+        else
+            this._invalidMapsUri(uri);
+    }
+
+    _openMapsUriQuery(query) {
+        let cancellable = new Gio.Cancellable();
+
+        this.connect('shutdown', () => cancellable.cancel());
+        GeocodeFactory.getGeocoder().search(query, null, null, cancellable,
+                                            (places, error) => {
+            log('places: ' + places?.length);
+            if (error) {
+                log('error: ' + error);
+                Utils.showDialog(_("An error has occurred"),
+                                 Gtk.MessageType.ERROR, this._mainWindow);
+            } else {
+                // clear search entry
+                this._mainWindow.placeEntry.text = '';
+
+                if (places?.length === 1) {
+                    this._mainWindow.mapView.showPlace(places[0], true);
+                } else {
+                    this._mainWindow.placeEntry.updateResults(places, query,
+                                                              false);
+                    /*
+                    if (!places) {
+                        popover.showNoResults();
+                    } else {
+                        log('1');
+                        popover.updateResult(places, query);
+                        log('2');
+                        popover.showResults();
+                    }
+                    */
+                    //this._mainWindow.placeEntry.popover.showResult();
+                }
+            }
+        });
+    }
+
+    _invalidMapsUri(uri) {
+        Utils.showDialog(_("Invalid maps: URI: %s").format(uri),
+                         Gtk.MessageType.ERROR, this._mainWindow);
+    }
+
     vfunc_open(files) {
         normalStartup = false;
         this.activate();


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