diff --git a/data/maps.desktop.in b/data/maps.desktop.in index 0bc68e3..22d5849 100644 --- a/data/maps.desktop.in +++ b/data/maps.desktop.in @@ -8,7 +8,9 @@ Categories=GTK;Utility;Science;Maps Keywords=trip;explore; Icon=io.elementary.maps -Exec=io.elementary.maps +Exec=io.elementary.maps %u SingleMainWindow=true StartupNotify=true Terminal=false + +MimeType=x-scheme-handler/geo; diff --git a/data/maps.metainfo.xml.in b/data/maps.metainfo.xml.in index f5f4213..3fc98e3 100644 --- a/data/maps.metainfo.xml.in +++ b/data/maps.metainfo.xml.in @@ -65,6 +65,7 @@ + Handle geo:// uri scheme Can't navigate from Search to results with the keyboard Can't type space character in Search diff --git a/src/Application.vala b/src/Application.vala index 1740421..4e4bebf 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -16,7 +16,7 @@ public class Maps.Application : Adw.Application { public Application () { Object ( application_id: "io.elementary.maps", - flags: ApplicationFlags.DEFAULT_FLAGS + flags: ApplicationFlags.HANDLES_OPEN ); } @@ -65,6 +65,22 @@ public class Maps.Application : Adw.Application { add_action (style_action); } + protected override void open (File[] files, string hint) { + activate (); + + if (files.length == 0) { + return; + } + + var file = files[0]; + if (!file.has_uri_scheme ("geo")) { + critical ("no geo uri scheme"); + return; + } + + ((MainWindow) active_window).go_to_uri (file.get_uri ()); + } + protected override void startup () { /* * Granite.init() calls Gdk.DisplayManager.get() internally without diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 8e5a8c8..c450261 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -239,7 +239,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow { search_listview.activate.connect ((pos) => { var place = (Geocode.Place) selection_model.get_item (pos); - map_widget.go_to_place (place); + map_widget.go_to_location (place.location); search_res_popover.popdown (); }); @@ -255,6 +255,25 @@ public class Maps.MainWindow : Adw.ApplicationWindow { destroy (); } + public void go_to_uri (string uri) { + try { + map_widget.go_to_uri (uri); + } catch (Error e) { + var error_dialog = new Granite.MessageDialog ( + _("Couldn't open location"), + _("Maps wasn't able to parse ā€œ%sā€. Please report this using the Feedback app.").printf (uri), + new ThemedIcon ("find-location") + ) { + badge_icon = new ThemedIcon ("dialog-error"), + modal = true, + transient_for = this + }; + error_dialog.show_error_details (e.message); + error_dialog.response.connect (error_dialog.destroy); + error_dialog.present (); + } + } + private void on_search_activate () { search_entry.grab_focus (); } diff --git a/src/MapWidget.vala b/src/MapWidget.vala index 15a6782..412472b 100644 --- a/src/MapWidget.vala +++ b/src/MapWidget.vala @@ -54,6 +54,10 @@ public class Maps.MapWidget : Gtk.Box { // Set the initial location of the map widget. private void set_init_place () { + if (base_map.viewport.latitude != 0 || base_map.viewport.longitude != 0) { + return; + } + Shumate.MapSource map_source = map_widget.map_source; double latitude = Maps.Application.settings.get_double ("latitude"); @@ -136,12 +140,19 @@ public class Maps.MapWidget : Gtk.Box { base_map.go_to_full (location.latitude, location.longitude, DEFAULT_ZOOM_LEVEL); } - public void go_to_place (Geocode.Place place) { - Geocode.Location loc = place.location; + public void go_to_uri (string uri) throws Error { + var location = new Geocode.Location (base_map.viewport.latitude, base_map.viewport.longitude); - clear_pin (); - mark_pin_at (loc.latitude, loc.longitude); - base_map.go_to (loc.latitude, loc.longitude); + // we get an uri that looks like geo:///lat,lon, remove slashes + location.set_from_uri (uri.replace ("///", "")); + + go_to_location (location); + } + + public void go_to_location (Geocode.Location location) { + pin_layer.remove_all (); + mark_pin_at (location.latitude, location.longitude); + base_map.go_to_full (location.latitude, location.longitude, DEFAULT_ZOOM_LEVEL); } // Saves the latest state of the map. @@ -155,10 +166,6 @@ public class Maps.MapWidget : Gtk.Box { location_layer.remove_all (); } - private void clear_pin () { - pin_layer.remove_all (); - } - private void mark_location_at (double latitude, double longitude) { var marker = new Shumate.Point () { latitude = latitude,