Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion data/maps.desktop.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions data/maps.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</ul>
</description>
<issues>
<issue url="https://github.com/elementary/maps/issues/108">Handle geo:// uri scheme</issue>
<issue url="https://github.com/elementary/maps/issues/125">Can't navigate from Search to results with the keyboard</issue>
<issue url="https://github.com/elementary/maps/issues/150">Can't type space character in Search</issue>
</issues>
Expand Down
18 changes: 17 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
});

Expand All @@ -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 ();
}
Expand Down
25 changes: 16 additions & 9 deletions src/MapWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down