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
10 changes: 5 additions & 5 deletions data/maps.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<enum id="map-sources">
<value value="0" nick="mapnik"/>
<value value="1" nick="transport"/>
<enum id="map-settings">
<value value="0" nick="explore"/>
<value value="1" nick="transit"/>
</enum>

<schema path="/io/elementary/maps/" id="io.elementary.maps">
Expand Down Expand Up @@ -36,8 +36,8 @@
<summary>Zoom level</summary>
<description>Zoom level of the map last used</description>
</key>
<key enum="map-sources" name="map-source">
<default>'mapnik'</default>
<key enum="map-settings" name="map-source">
<default>'explore'</default>
<summary>Active map source</summary>
<description>The type of the map last used</description>
</key>
Expand Down
6 changes: 3 additions & 3 deletions src/Define.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace Define {
public const string FORCE_DARK = "force-dark";
}

namespace MapSource {
public const string MAPNIK = "mapnik";
public const string TRANSPORT = "transport";
namespace MapSetting {
public const string EXPLORE = "explore";
public const string TRANSIT = "transit";
}
}
24 changes: 10 additions & 14 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow {

var explore_source_button = new Gtk.ToggleButton () {
action_name = "win.map-source",
action_target = Define.MapSource.MAPNIK,
action_target = Define.MapSetting.EXPLORE,
child = new Gtk.Image.from_icon_name ("map-tile-explore") {
pixel_size = 48
}
Expand All @@ -112,8 +112,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow {

var transit_source_button = new Gtk.ToggleButton () {
action_name = "win.map-source",
action_target = Define.MapSource.TRANSPORT,
group = explore_source_button,
action_target = Define.MapSetting.TRANSIT,
child = new Gtk.Image.from_icon_name ("map-tile-transit") {
pixel_size = 48
}
Expand Down Expand Up @@ -289,18 +288,15 @@ public class Maps.MainWindow : Adw.ApplicationWindow {
}

private void setup_map_source_action () {
var map_source_action = new SimpleAction.stateful (
"map-source", VariantType.STRING, new Variant.string (Define.MapSource.MAPNIK)
);
map_source_action.bind_property ("state", map_widget, "map-source",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE,
Util.map_source_action_transform_to_cb,
Util.map_source_action_transform_from_cb);
Application.settings.bind_with_mapping ("map-source", map_widget, "map-source", SettingsBindFlags.DEFAULT,
(SettingsBindGetMappingShared) Util.map_source_get_mapping_cb,
(SettingsBindSetMappingShared) Util.map_source_set_mapping_cb,
null, null);
var map_source_action = Application.settings.create_action ("map-source");
add_action (map_source_action);

Application.settings.bind_with_mapping (
"map-source", map_widget, "map-source", GET,
(SettingsBindGetMappingShared) Util.map_source_get_mapping_cb,
(SettingsBindSetMappingShared) null,
null, null
);
}

private async void search_location (string term, ListStore res) {
Expand Down
72 changes: 3 additions & 69 deletions src/Util.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,59 +33,14 @@ namespace Util {
}
}

public static bool map_source_action_transform_to_cb (Binding binding, Value from_value, ref Value to_value) {
Variant? variant = from_value.dup_variant ();
if (variant == null) {
warning ("Failed to Variant.dup_variant");
return false;
}

string map_source;
var val = variant.get_string ();
switch (val) {
case Define.MapSource.MAPNIK:
map_source = Shumate.MAP_SOURCE_OSM_MAPNIK;
break;
case Define.MapSource.TRANSPORT:
map_source = Shumate.MAP_SOURCE_OSM_TRANSPORT_MAP;
break;
default:
warning ("map_source_action_transform_to_cb: Invalid map_source: %s", val);
return false;
}

var registry = new Shumate.MapSourceRegistry.with_defaults ();
to_value.set_object (registry.get_by_id (map_source));

return true;
}

public static bool map_source_action_transform_from_cb (Binding binding, Value from_value, ref Value to_value) {
unowned var val = (Shumate.MapSource) from_value.get_object ();
string id = val.id;
switch (id) {
case Shumate.MAP_SOURCE_OSM_MAPNIK:
to_value.set_variant (new Variant.string (Define.MapSource.MAPNIK));
break;
case Shumate.MAP_SOURCE_OSM_TRANSPORT_MAP:
to_value.set_variant (new Variant.string (Define.MapSource.TRANSPORT));
break;
default:
warning ("map_source_action_transform_from_cb: Invalid map_source: %s", id);
return false;
}

return true;
}

public static static bool map_source_get_mapping_cb (Value value, Variant variant, void* user_data) {
public static bool map_source_get_mapping_cb (Value value, Variant variant, void* user_data) {
string map_source;
var val = (string) variant;
switch (val) {
case Define.MapSource.MAPNIK:
case Define.MapSetting.EXPLORE:
map_source = Shumate.MAP_SOURCE_OSM_MAPNIK;
break;
case Define.MapSource.TRANSPORT:
case Define.MapSetting.TRANSIT:
map_source = Shumate.MAP_SOURCE_OSM_TRANSPORT_MAP;
break;
default:
Expand All @@ -98,25 +53,4 @@ namespace Util {

return true;
}

public static static Variant map_source_set_mapping_cb (Value value, VariantType expected_type, void* user_data) {
string map_source;
var val = (Shumate.MapSource) value;
unowned var id = val.id;
switch (id) {
case Shumate.MAP_SOURCE_OSM_MAPNIK:
map_source = Define.MapSource.MAPNIK;
break;
case Shumate.MAP_SOURCE_OSM_TRANSPORT_MAP:
map_source = Define.MapSource.TRANSPORT;
break;
default:
warning ("map_source_set_mapping_cb: Invalid map_source: %s", id);
// fallback to mapnik
map_source = Define.MapSource.MAPNIK;
break;
}

return new Variant.string (map_source);
}
}