[gnome-games/wip/exalm/cleanups: 5/10] ui: Use GObject-style construction
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cleanups: 5/10] ui: Use GObject-style construction
- Date: Mon, 25 Feb 2019 11:02:09 +0000 (UTC)
commit 22597ec1e211e31a5159da9680f3033cff281926
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Mon Feb 25 15:26:11 2019 +0500
ui: Use GObject-style construction
All of these classes are often instantiated via GtkBuilder, and use a mix
of GObject-style and Vala-style construction. Move everything to GObject
construction to reduce confusion.
src/ui/application-window.vala | 16 +++++++++++-----
src/ui/checkmark-item.vala | 10 ++++++++--
src/ui/game-icon-view.vala | 9 ++-------
src/ui/gamepad-mapper.vala | 25 +++++++++++++++++--------
src/ui/gamepad-tester.vala | 26 +++++++++++++++++---------
src/ui/keyboard-mapper.vala | 21 +++++++++++++++------
src/ui/keyboard-tester.vala | 21 +++++++++++++++------
src/ui/konami-code.vala | 8 +++++++-
src/ui/platform-list-item.vala | 4 ++--
src/ui/preferences-page-plugins-item.vala | 10 ++++++++--
src/ui/preferences-sidebar-item.vala | 2 +-
src/ui/preferences-subpage-gamepad.vala | 21 +++++++++++++++------
src/ui/preferences-subpage-keyboard.vala | 2 +-
src/ui/preferences-window.vala | 2 +-
14 files changed, 120 insertions(+), 57 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index c606c33c..0d93e22e 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -107,12 +107,18 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
private KonamiCode konami_code;
+ public ListModel collection {
+ construct {
+ collection_box.collection = value;
+ value.items_changed.connect (() => {
+ is_collection_empty = value.get_n_items () == 0;
+ });
+ is_collection_empty = value.get_n_items () == 0;
+ }
+ }
+
public ApplicationWindow (ListModel collection) {
- collection_box.collection = collection;
- collection.items_changed.connect (() => {
- is_collection_empty = collection.get_n_items () == 0;
- });
- is_collection_empty = collection.get_n_items () == 0;
+ Object (collection: collection);
}
construct {
diff --git a/src/ui/checkmark-item.vala b/src/ui/checkmark-item.vala
index 8405845c..3011bcd6 100644
--- a/src/ui/checkmark-item.vala
+++ b/src/ui/checkmark-item.vala
@@ -10,8 +10,14 @@ private class Games.CheckmarkItem: Gtk.ListBoxRow {
public bool checkmark_visible { get; set; }
private Binding checkmark_visible_binding;
- public CheckmarkItem (string name) {
- title_label.label = name;
+ public string label {
+ construct {
+ title_label.label = value;
+ }
+ }
+
+ public CheckmarkItem (string label) {
+ Object (label: label);
}
construct {
diff --git a/src/ui/game-icon-view.vala b/src/ui/game-icon-view.vala
index cb52731e..a8e7f273 100644
--- a/src/ui/game-icon-view.vala
+++ b/src/ui/game-icon-view.vala
@@ -5,18 +5,13 @@ private class Games.GameIconView : Gtk.Box {
private Game _game;
public Game game {
get { return _game; }
- set {
- if (value == game)
- return;
-
+ construct {
_game = value;
thumbnail.uid = game.get_uid ();
thumbnail.icon = game.get_icon ();
thumbnail.cover = game.get_cover ();
title.label = game.name;
-
- queue_draw ();
}
}
@@ -26,6 +21,6 @@ private class Games.GameIconView : Gtk.Box {
private Gtk.Label title;
public GameIconView (Game game) {
- this.game = game;
+ Object (game: game);
}
}
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index 280bb7a3..5182a2ce 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -7,7 +7,6 @@ private class Games.GamepadMapper : Gtk.Bin {
[GtkChild]
private GamepadView gamepad_view;
- private Manette.Device device;
private GamepadMappingBuilder mapping_builder;
private GamepadInput[] mapping_inputs;
private GamepadInput input;
@@ -17,15 +16,25 @@ private class Games.GamepadMapper : Gtk.Bin {
private ulong gamepad_event_handler_id;
+ public Manette.Device device { get; construct; }
+
+ private GamepadViewConfiguration _configuration;
+ public GamepadViewConfiguration configuration {
+ get { return _configuration; }
+ construct {
+ _configuration = value;
+ try {
+ gamepad_view.set_configuration (value);
+ }
+ catch (Error e) {
+ critical ("Could not set up gamepad view: %s", e.message);
+ }
+ }
+ }
+
public GamepadMapper (Manette.Device device, GamepadViewConfiguration configuration, GamepadInput[]
mapping_inputs) {
- this.device = device;
+ Object (device: device, configuration: configuration);
this.mapping_inputs = mapping_inputs;
- try {
- gamepad_view.set_configuration (configuration);
- }
- catch (Error e) {
- critical ("Could not set up gamepad view: %s", e.message);
- }
}
public void start () {
diff --git a/src/ui/gamepad-tester.vala b/src/ui/gamepad-tester.vala
index 774104f2..ff624235 100644
--- a/src/ui/gamepad-tester.vala
+++ b/src/ui/gamepad-tester.vala
@@ -5,22 +5,30 @@ private class Games.GamepadTester : Gtk.Bin {
[GtkChild]
private GamepadView gamepad_view;
- private Manette.Device device;
-
private ulong gamepad_button_press_event_handler_id;
private ulong gamepad_button_release_event_handler_id;
private ulong gamepad_axis_event_handler_id;
- public GamepadTester (Manette.Device device, GamepadViewConfiguration configuration) {
- this.device = device;
- try {
- gamepad_view.set_configuration (configuration);
- }
- catch (Error e) {
- critical ("Could not set up gamepad view: %s", e.message);
+ public Manette.Device device { get; construct; }
+
+ private GamepadViewConfiguration _configuration;
+ public GamepadViewConfiguration configuration {
+ get { return _configuration; }
+ construct {
+ _configuration = value;
+ try {
+ gamepad_view.set_configuration (value);
+ }
+ catch (Error e) {
+ critical ("Could not set up gamepad view: %s", e.message);
+ }
}
}
+ public GamepadTester (Manette.Device device, GamepadViewConfiguration configuration) {
+ Object (device: device, configuration: configuration);
+ }
+
public void start () {
gamepad_view.reset ();
connect_to_gamepad ();
diff --git a/src/ui/keyboard-mapper.vala b/src/ui/keyboard-mapper.vala
index 505ed1f8..d447e067 100644
--- a/src/ui/keyboard-mapper.vala
+++ b/src/ui/keyboard-mapper.vala
@@ -14,18 +14,27 @@ private class Games.KeyboardMapper : Gtk.Bin {
public string info_message { get; private set; }
+ private GamepadViewConfiguration _configuration;
+ public GamepadViewConfiguration configuration {
+ get { return _configuration; }
+ construct {
+ _configuration = value;
+ try {
+ gamepad_view.set_configuration (value);
+ }
+ catch (Error e) {
+ critical ("Could not set up gamepad view: %s", e.message);
+ }
+ }
+ }
+
construct {
info_message = _("Press suitable key on your keyboard");
}
public KeyboardMapper (GamepadViewConfiguration configuration, GamepadInput[] mapping_inputs) {
+ Object (configuration: configuration);
this.mapping_inputs = mapping_inputs;
- try {
- gamepad_view.set_configuration (configuration);
- }
- catch (Error e) {
- critical ("Could not set up gamepad view: %s", e.message);
- }
}
public void start () {
diff --git a/src/ui/keyboard-tester.vala b/src/ui/keyboard-tester.vala
index 1aba4703..84519b0a 100644
--- a/src/ui/keyboard-tester.vala
+++ b/src/ui/keyboard-tester.vala
@@ -7,15 +7,24 @@ private class Games.KeyboardTester : Gtk.Bin {
public Retro.KeyJoypadMapping mapping { get; set; }
- public KeyboardTester (GamepadViewConfiguration configuration) {
- try {
- gamepad_view.set_configuration (configuration);
- }
- catch (Error e) {
- critical ("Could not set up gamepad view: %s", e.message);
+ private GamepadViewConfiguration _configuration;
+ public GamepadViewConfiguration configuration {
+ get { return _configuration; }
+ construct {
+ _configuration = value;
+ try {
+ gamepad_view.set_configuration (value);
+ }
+ catch (Error e) {
+ critical ("Could not set up gamepad view: %s", e.message);
+ }
}
}
+ public KeyboardTester (GamepadViewConfiguration configuration) {
+ Object (configuration: configuration);
+ }
+
public void start () {
gamepad_view.reset ();
connect_to_keyboard ();
diff --git a/src/ui/konami-code.vala b/src/ui/konami-code.vala
index 0f76471b..56b4d427 100644
--- a/src/ui/konami-code.vala
+++ b/src/ui/konami-code.vala
@@ -41,8 +41,14 @@ private class Games.KonamiCode : Object {
private uint current_index;
+ public Gtk.Widget widget {
+ construct {
+ value.key_press_event.connect (on_key_pressed);
+ }
+ }
+
public KonamiCode (Gtk.Widget widget) {
- widget.key_press_event.connect (on_key_pressed);
+ Object (widget: widget);
}
public void reset () {
diff --git a/src/ui/platform-list-item.vala b/src/ui/platform-list-item.vala
index 4aeb8753..4a2dcccb 100644
--- a/src/ui/platform-list-item.vala
+++ b/src/ui/platform-list-item.vala
@@ -2,14 +2,14 @@ private class Games.PlatformListItem: Games.SidebarListItem {
private Platform _platform;
public Platform platform {
get { return _platform; }
- set {
+ construct {
_platform = value;
label.label = value.get_name ();
}
}
public PlatformListItem (Platform platform) {
- Object (platform : platform);
+ Object (platform: platform);
}
public override bool has_game (Game game) {
diff --git a/src/ui/preferences-page-plugins-item.vala b/src/ui/preferences-page-plugins-item.vala
index 11c08e55..e613fa25 100644
--- a/src/ui/preferences-page-plugins-item.vala
+++ b/src/ui/preferences-page-plugins-item.vala
@@ -7,8 +7,14 @@ private class Games.PreferencesPagePluginsItem: Gtk.Box {
[GtkChild]
private Gtk.Label plugin_description;
+ public PluginRegistrar plugin_registrar {
+ construct {
+ plugin_name.label = value.name;
+ plugin_description.label = value.description;
+ }
+ }
+
public PreferencesPagePluginsItem (PluginRegistrar plugin_registrar) {
- plugin_name.label = plugin_registrar.name;
- plugin_description.label = plugin_registrar.description;
+ Object (plugin_registrar: plugin_registrar);
}
}
diff --git a/src/ui/preferences-sidebar-item.vala b/src/ui/preferences-sidebar-item.vala
index 6a551d4b..9fd38e83 100644
--- a/src/ui/preferences-sidebar-item.vala
+++ b/src/ui/preferences-sidebar-item.vala
@@ -6,7 +6,7 @@ private class Games.PreferencesSidebarItem: Gtk.ListBoxRow {
private PreferencesPage _preferences_page;
public PreferencesPage preferences_page {
get { return _preferences_page; }
- set {
+ construct {
_preferences_page = value;
label.label = value.title;
}
diff --git a/src/ui/preferences-subpage-gamepad.vala b/src/ui/preferences-subpage-gamepad.vala
index 5d75cb5d..3e07ccd1 100644
--- a/src/ui/preferences-subpage-gamepad.vala
+++ b/src/ui/preferences-subpage-gamepad.vala
@@ -125,19 +125,28 @@ private class Games.PreferencesSubpageGamepad: Gtk.Box, PreferencesSubpage {
[GtkChild]
private Gtk.Label info_message;
- private Manette.Device device;
private GamepadMapper mapper;
private GamepadTester tester;
private Binding info_message_binding;
+ private Manette.Device _device;
+ public Manette.Device device {
+ get { return _device; }
+ construct {
+ _device = value;
+ mapper = new GamepadMapper (value, STANDARD_GAMEPAD_VIEW_CONFIGURATION,
STANDARD_GAMEPAD_INPUTS);
+ gamepad_view_stack.add (mapper);
+ tester = new GamepadTester (value, STANDARD_GAMEPAD_VIEW_CONFIGURATION);
+ gamepad_view_stack.add (tester);
+ }
+ }
+
public PreferencesSubpageGamepad (Manette.Device device) {
- this.device = device;
- mapper = new GamepadMapper (device, STANDARD_GAMEPAD_VIEW_CONFIGURATION,
STANDARD_GAMEPAD_INPUTS);
- gamepad_view_stack.add (mapper);
- tester = new GamepadTester (device, STANDARD_GAMEPAD_VIEW_CONFIGURATION);
- gamepad_view_stack.add (tester);
+ Object (device: device);
+ }
+ construct {
info_message_binding = mapper.bind_property ("info-message", info_message, "label",
BindingFlags.SYNC_CREATE);
state = State.TEST;
diff --git a/src/ui/preferences-subpage-keyboard.vala b/src/ui/preferences-subpage-keyboard.vala
index 71b5f0f1..69ec80ce 100644
--- a/src/ui/preferences-subpage-keyboard.vala
+++ b/src/ui/preferences-subpage-keyboard.vala
@@ -119,7 +119,7 @@ private class Games.PreferencesSubpageKeyboard: Gtk.Box, PreferencesSubpage {
private Binding info_message_binding;
- public PreferencesSubpageKeyboard () {
+ construct {
mapper = new KeyboardMapper (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION, KEYBOARD_GAMEPAD_INPUTS);
gamepad_view_stack.add (mapper);
tester = new KeyboardTester (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION);
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index 453ff9bf..bbf5755a 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -67,7 +67,7 @@ private class Games.PreferencesWindow : Gtk.Window {
private Binding subpage_binding;
private Binding selection_mode_binding;
- public PreferencesWindow () {
+ construct {
update_ui ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]