From 6456539f60c6a180af774427f6e9f8f273dece1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 16 Jul 2025 12:16:50 -0700 Subject: [PATCH 1/3] MainWindow: use settings.create_action --- data/maps.gschema.xml | 6 ++-- src/Define.vala | 6 ++-- src/MainWindow.vala | 24 ++++++--------- src/Util.vala | 72 ++----------------------------------------- 4 files changed, 19 insertions(+), 89 deletions(-) diff --git a/data/maps.gschema.xml b/data/maps.gschema.xml index 7eefd5e..662d7a0 100644 --- a/data/maps.gschema.xml +++ b/data/maps.gschema.xml @@ -1,8 +1,8 @@ - - + + @@ -37,7 +37,7 @@ Zoom level of the map last used - 'mapnik' + 'explore' Active map source The type of the map last used diff --git a/src/Define.vala b/src/Define.vala index e82b647..18c6fa0 100644 --- a/src/Define.vala +++ b/src/Define.vala @@ -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"; } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ba4fb02..6d58075 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -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 } @@ -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 } @@ -284,18 +283,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, + () => { return false; }, + null, null + ); } private async void search_location (string term, ListStore res) { diff --git a/src/Util.vala b/src/Util.vala index 7dab87b..04860ad 100644 --- a/src/Util.vala +++ b/src/Util.vala @@ -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: @@ -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); - } } From 1191deeffd5a39c5a62e2e0925a8ad502b6e6adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 17 Jul 2025 10:06:37 -0700 Subject: [PATCH 2/3] Update src/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 3ec863f..597bc7b 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -294,7 +294,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow { Application.settings.bind_with_mapping ( "map-source", map_widget, "map-source", GET, (SettingsBindGetMappingShared) Util.map_source_get_mapping_cb, - () => { return false; }, + (SettingsBindSetMappingShared) null, null, null ); } From 67f63f81217aa86251b241b7570f4626d8d81f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 17 Jul 2025 10:09:03 -0700 Subject: [PATCH 3/3] Rename enum --- data/maps.gschema.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/maps.gschema.xml b/data/maps.gschema.xml index 662d7a0..f20d1f8 100644 --- a/data/maps.gschema.xml +++ b/data/maps.gschema.xml @@ -1,6 +1,6 @@ - + @@ -36,7 +36,7 @@ Zoom level Zoom level of the map last used - + 'explore' Active map source The type of the map last used