From 15d142be3bac6de6dd2709cb4a8899ee381d32a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 10:26:06 -0700 Subject: [PATCH 1/9] Support GEO uri --- data/maps.desktop.in | 2 ++ src/Application.vala | 14 +++++++++++++- src/MainWindow.vala | 12 +++++++++++- src/MapWidget.vala | 25 ++++++++++++++++--------- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/data/maps.desktop.in b/data/maps.desktop.in index 0bc68e3..65a9b96 100644 --- a/data/maps.desktop.in +++ b/data/maps.desktop.in @@ -12,3 +12,5 @@ Exec=io.elementary.maps SingleMainWindow=true StartupNotify=true Terminal=false + +MimeType=x-scheme-handler/geo; diff --git a/src/Application.vala b/src/Application.vala index 1740421..61ee201 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,18 @@ public class Maps.Application : Adw.Application { add_action (style_action); } + public override void open (File[] files, string hint) { + activate (); + + var file = files[0]; + if (file == null || !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 597bc7b..99573cf 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,16 @@ public class Maps.MainWindow : Adw.ApplicationWindow { destroy (); } + public void go_to_uri (string uri) { + try { + map_widget.go_to_uri (uri); + } catch (Error e) { + // TODO: throw error to the UI + critical (e.message); + return; + } + } + 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, From 4702b7b4555a74081193524ce4a784f12ae6d1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 11:34:12 -0700 Subject: [PATCH 2/9] Throw error dialog --- src/MainWindow.vala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 99573cf..7a49c7a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -259,9 +259,17 @@ public class Maps.MainWindow : Adw.ApplicationWindow { try { map_widget.go_to_uri (uri); } catch (Error e) { - // TODO: throw error to the UI - critical (e.message); - return; + var messagedialog = 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 = (Gtk.Window) get_root () + }; + messagedialog.present (); + messagedialog.response.connect (messagedialog.destroy); } } From 85db57e55e9203ec11b9c8c4ec624228af4d698d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 11:50:16 -0700 Subject: [PATCH 3/9] Fix XDG open --- data/maps.desktop.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/maps.desktop.in b/data/maps.desktop.in index 65a9b96..22d5849 100644 --- a/data/maps.desktop.in +++ b/data/maps.desktop.in @@ -8,7 +8,7 @@ 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 From 82bd32a2825ba17c2ab5d810d2d47d65e58c6d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 11:53:39 -0700 Subject: [PATCH 4/9] Update maps.metainfo.xml.in --- data/maps.metainfo.xml.in | 1 + 1 file changed, 1 insertion(+) diff --git a/data/maps.metainfo.xml.in b/data/maps.metainfo.xml.in index 79c3e2c..32b7b7e 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 From d6b1b7b120f1421ba0dbe56ba3bfc92e10a2f7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 15:13:55 -0700 Subject: [PATCH 5/9] Update Application.vala Co-authored-by: Ryo Nakano --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 61ee201..7f6bdff 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -65,7 +65,7 @@ public class Maps.Application : Adw.Application { add_action (style_action); } - public override void open (File[] files, string hint) { + protected override void open (File[] files, string hint) { activate (); var file = files[0]; From d1ae998f6f39e844fa2734bc2d9ec847943abf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 15:16:46 -0700 Subject: [PATCH 6/9] Update MainWindow.vala Co-authored-by: Ryo Nakano --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 7a49c7a..fbc1de6 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -268,8 +268,8 @@ public class Maps.MainWindow : Adw.ApplicationWindow { modal = true, transient_for = (Gtk.Window) get_root () }; - messagedialog.present (); messagedialog.response.connect (messagedialog.destroy); + messagedialog.present (); } } From 751a7f302017049d65a3a557f7e8140127bdc002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 15:33:49 -0700 Subject: [PATCH 7/9] Address review comments --- src/Application.vala | 6 +++++- src/MainWindow.vala | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 7f6bdff..4e4bebf 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -68,8 +68,12 @@ public class Maps.Application : Adw.Application { protected override void open (File[] files, string hint) { activate (); + if (files.length == 0) { + return; + } + var file = files[0]; - if (file == null || !file.has_uri_scheme ("geo")) { + if (!file.has_uri_scheme ("geo")) { critical ("no geo uri scheme"); return; } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index fbc1de6..bb53ab7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -259,7 +259,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow { try { map_widget.go_to_uri (uri); } catch (Error e) { - var messagedialog = new Granite.MessageDialog ( + var message_dialog = new Granite.message_dialog ( _("Couldn't open location"), _("Maps wasn't able to parse “%s”. Please report this using the Feedback app.").printf (uri), new ThemedIcon ("find-location") @@ -268,8 +268,9 @@ public class Maps.MainWindow : Adw.ApplicationWindow { modal = true, transient_for = (Gtk.Window) get_root () }; - messagedialog.response.connect (messagedialog.destroy); - messagedialog.present (); + message_dialog.show_error_details (e.message); + message_dialog.response.connect (message_dialog.destroy); + message_dialog.present (); } } From e0625e0b3713f411a281fac5817f1f0619285443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 11 Sep 2025 15:35:30 -0700 Subject: [PATCH 8/9] Rename error_dialog --- src/MainWindow.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index bb53ab7..380c170 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -259,7 +259,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow { try { map_widget.go_to_uri (uri); } catch (Error e) { - var message_dialog = new Granite.message_dialog ( + 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") @@ -268,9 +268,9 @@ public class Maps.MainWindow : Adw.ApplicationWindow { modal = true, transient_for = (Gtk.Window) get_root () }; - message_dialog.show_error_details (e.message); - message_dialog.response.connect (message_dialog.destroy); - message_dialog.present (); + error_dialog.show_error_details (e.message); + error_dialog.response.connect (error_dialog.destroy); + error_dialog.present (); } } From f6ea3b870170f8494a663843f80dc85cb564e2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 12 Sep 2025 11:24:03 -0700 Subject: [PATCH 9/9] Update MainWindow.vala --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 380c170..c16241c 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -266,7 +266,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow { ) { badge_icon = new ThemedIcon ("dialog-error"), modal = true, - transient_for = (Gtk.Window) get_root () + transient_for = this }; error_dialog.show_error_details (e.message); error_dialog.response.connect (error_dialog.destroy);