[gnome-games/wip/exalm/ds: 11/15] nintendo-ds: Reduce GSettings usage
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/ds: 11/15] nintendo-ds: Reduce GSettings usage
- Date: Wed, 14 Aug 2019 11:06:22 +0000 (UTC)
commit f4d6cc45c13d1d2f5211baff2339356cc4d3f922
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed Aug 14 02:12:04 2019 +0500
nintendo-ds: Reduce GSettings usage
This will make it easier to replace GSettings usage completely and replace
it with a savestate in a later commit.
.../src/nintendo-ds-layout-switcher.vala | 34 ++++++------
plugins/nintendo-ds/src/nintendo-ds-runner.vala | 61 ++++++++++++++--------
2 files changed, 58 insertions(+), 37 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
index 6f88b4be..e2ad0237 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -13,15 +13,16 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
[GtkChild]
private Gtk.ListBox list_box;
- private Settings settings;
private HashTable<NintendoDsLayout, NintendoDsLayoutItem> items;
+ public NintendoDsRunner runner { get; construct; }
+
static construct {
var icon_theme = Gtk.IconTheme.get_default ();
icon_theme.add_resource_path ("/org/gnome/Games/plugins/nintendo-ds/icons");
}
- construct {
+ public override void constructed () {
items = new HashTable<NintendoDsLayout, NintendoDsLayoutItem> (direct_hash, direct_equal);
foreach (var layout in NintendoDsLayout.get_layouts ()) {
var item = new NintendoDsLayoutItem (layout);
@@ -30,42 +31,45 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
list_box.add (item);
}
- settings = new Settings ("org.gnome.Games.plugins.nintendo-ds");
- settings.changed.connect (update_ui);
-
layout_popover.show.connect (update_ui);
update_ui ();
+
+ runner.notify["screen-layout"].connect (update_ui);
+ runner.notify["view-bottom-screen"].connect (update_ui);
+
+ base.constructed ();
+ }
+
+ public NintendoDsLayoutSwitcher (NintendoDsRunner runner) {
+ Object (runner: runner);
}
private void update_ui () {
- var layout_value = settings.get_string ("screen-layout");
- var view_bottom = settings.get_boolean ("view-bottom-screen");
+ var layout = runner.screen_layout;
+ var view_bottom = runner.view_bottom_screen;
- var layout = NintendoDsLayout.from_value (layout_value);
layout_image.icon_name = layout.get_icon ();
var item = items[layout];
list_box.select_row (item);
change_screen_revealer.reveal_child = (layout == NintendoDsLayout.QUICK_SWITCH);
- change_screen_image.icon_name = view_bottom ? "view-top-screen-symbolic" :
"view-bottom-screen-symbolic-symbolic";
+ change_screen_image.icon_name = view_bottom ?
+ "view-top-screen-symbolic" :
+ "view-bottom-screen-symbolic";
}
[GtkCallback]
private void on_screen_changed (Gtk.Button button) {
- var view_bottom = settings.get_boolean ("view-bottom-screen");
-
- settings.set_boolean ("view-bottom-screen", !view_bottom);
+ runner.view_bottom_screen = !runner.view_bottom_screen;
}
[GtkCallback]
private void on_row_activated (Gtk.ListBoxRow row) {
var layout_item = row as NintendoDsLayoutItem;
- var layout = layout_item.layout;
-
- settings.set_string ("screen-layout", layout.get_value ());
+ runner.screen_layout = layout_item.layout;
layout_popover.popdown ();
}
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 8157fe3e..ebb89c3b 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -9,6 +9,24 @@ private class Games.NintendoDsRunner : RetroRunner {
private const string SCREENS_LAYOUT_OPTION = "desmume_screens_layout";
+ private NintendoDsLayout _screen_layout;
+ public NintendoDsLayout screen_layout {
+ get { return _screen_layout; }
+ set {
+ _screen_layout = value;
+ settings.set_string ("screen-layout", value.get_value ());
+ }
+ }
+
+ private bool _view_bottom_screen;
+ public bool view_bottom_screen {
+ get { return _view_bottom_screen; }
+ set {
+ _view_bottom_screen = value;
+ settings.set_boolean ("view-bottom-screen", value);
+ }
+ }
+
static construct {
layouts = new HashTable<uint, NintendoDsLayout?> (direct_hash, direct_equal);
@@ -33,6 +51,9 @@ private class Games.NintendoDsRunner : RetroRunner {
settings = new Settings ("org.gnome.Games.plugins.nintendo-ds");
settings_changed_id = settings.changed.connect (on_changed);
+ _screen_layout = NintendoDsLayout.from_value (settings.get_string ("screen-layout"));
+ _view_bottom_screen = settings.get_boolean ("view-bottom-screen");
+
var core = get_core ();
core.options_set.connect (update_screen_layout);
@@ -48,8 +69,15 @@ private class Games.NintendoDsRunner : RetroRunner {
}
private void on_changed (string key) {
- if (key == "screen-layout" || key == "view-bottom-screen")
- update_screen_layout ();
+ if (key == "screen-layout")
+ _screen_layout = NintendoDsLayout.from_value (settings.get_string (key));
+ else
+ if (key == "view-bottom-screen")
+ _view_bottom_screen = settings.get_boolean (key);
+ else
+ return;
+
+ update_screen_layout ();
}
private void update_screen_layout () {
@@ -60,14 +88,9 @@ private class Games.NintendoDsRunner : RetroRunner {
var option = core.get_option (SCREENS_LAYOUT_OPTION);
- var setting_value = settings.get_string ("screen-layout");
-
- var option_value = setting_value;
- if (setting_value == "quick switch") {
- var bottom = settings.get_boolean ("view-bottom-screen");
-
- option_value = bottom ? "bottom only" : "top only";
- }
+ var option_value = screen_layout.get_value ();
+ if (screen_layout == NintendoDsLayout.QUICK_SWITCH)
+ option_value = view_bottom_screen ? "bottom only" : "top only";
try {
option.set_value (option_value);
@@ -81,7 +104,7 @@ private class Games.NintendoDsRunner : RetroRunner {
if (!core_supports_layouts ())
return null;
- return new NintendoDsLayoutSwitcher ();
+ return new NintendoDsLayoutSwitcher (this);
}
public override bool key_press_event (Gdk.EventKey event) {
@@ -93,19 +116,16 @@ private class Games.NintendoDsRunner : RetroRunner {
var shortcut_layout = layouts[event.keyval];
if (shortcut_layout != null) {
- settings.set_string ("screen-layout", shortcut_layout.get_value ());
+ screen_layout = shortcut_layout;
return true;
}
}
- var layout = settings.get_string ("screen-layout");
-
- if (layout != "quick switch")
+ if (screen_layout != NintendoDsLayout.QUICK_SWITCH)
return false;
- var view_bottom = settings.get_boolean ("view-bottom-screen");
- var switch_keyval = view_bottom ? Gdk.Key.Page_Up : Gdk.Key.Page_Down;
+ var switch_keyval = view_bottom_screen ? Gdk.Key.Page_Up : Gdk.Key.Page_Down;
if (event.keyval == switch_keyval)
return swap_screens ();
@@ -120,13 +140,10 @@ private class Games.NintendoDsRunner : RetroRunner {
}
private bool swap_screens () {
- var layout = settings.get_string ("screen-layout");
-
- if (layout != "quick switch")
+ if (screen_layout != NintendoDsLayout.QUICK_SWITCH)
return false;
- var view_bottom = settings.get_boolean ("view-bottom-screen");
- settings.set_boolean ("view-bottom-screen", !view_bottom);
+ view_bottom_screen = !view_bottom_screen;
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]