[gnome-games] ui: Bind and connect in xml where possible



commit f5f56ec947c8a413a32f0543b45f7d27e2603081
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Aug 22 01:36:37 2019 +0500

    ui: Bind and connect in xml where possible

 data/ui/checkmark-item.ui                          |  7 ++--
 data/ui/collection-box.ui                          |  2 +
 data/ui/collection-header-bar.ui                   |  4 ++
 data/ui/display-box.ui                             |  2 +
 data/ui/fullscreen-box.ui                          |  2 +-
 data/ui/platforms-view.ui                          |  1 +
 data/ui/preferences-page-platforms-generic-row.ui  |  1 +
 data/ui/savestates-list.ui                         |  2 +
 .../data/ui/nintendo-ds-layout-switcher.ui         |  1 +
 .../src/nintendo-ds-layout-switcher.vala           |  3 +-
 src/ui/checkmark-item.vala                         | 18 +--------
 src/ui/collection-box.vala                         | 45 ++++++----------------
 src/ui/collection-header-bar.vala                  | 15 --------
 src/ui/display-box.vala                            |  7 +---
 src/ui/fullscreen-box.vala                         |  3 --
 src/ui/platforms-view.vala                         | 11 +++---
 src/ui/preferences-page-platforms-generic-row.vala | 12 +-----
 src/ui/savestates-list.vala                        |  4 +-
 18 files changed, 41 insertions(+), 99 deletions(-)
---
diff --git a/data/ui/checkmark-item.ui b/data/ui/checkmark-item.ui
index faabdae2..dcd2c2bb 100644
--- a/data/ui/checkmark-item.ui
+++ b/data/ui/checkmark-item.ui
@@ -9,15 +9,16 @@
         <property name="spacing">12</property>
         <property name="visible">true</property>
         <child>
-          <object class="GtkLabel" id="title_label">
+          <object class="GtkLabel">
             <property name="visible">true</property>
             <property name="vexpand">true</property>
             <property name="wrap">true</property>
+            <property name="label" bind-source="GamesCheckmarkItem" bind-property="label" 
bind-flags="default"/>
           </object>
         </child>
         <child>
-          <object class="GtkImage" id="checkmark_image">
-            <property name="visible">False</property>
+          <object class="GtkImage">
+            <property name="visible" bind-source="GamesCheckmarkItem" bind-property="checkmark-visible" 
bind-flags="default">False</property>
             <property name="icon-name">object-select-symbolic</property>
             <property name="valign">center</property>
           </object>
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index 438f6a76..65560069 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -10,6 +10,7 @@
     <child>
       <object class="GamesSearchBar" id="search_bar">
         <property name="visible">True</property>
+        <property name="search-mode-enabled" bind-source="GamesCollectionBox" bind-property="search-mode" 
bind-flags="bidirectional"/>
         <signal name="notify::text" handler="on_search_text_notify"/>
       </object>
     </child>
@@ -66,6 +67,7 @@
             <property name="visible">True</property>
             <property name="halign">center</property>
             <property name="valign">start</property>
+            <property name="reveal-child" bind-source="GamesCollectionBox" 
bind-property="loading-notification" bind-flags="bidirectional"/>
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
diff --git a/data/ui/collection-header-bar.ui b/data/ui/collection-header-bar.ui
index 2b27a0e6..f8577d76 100644
--- a/data/ui/collection-header-bar.ui
+++ b/data/ui/collection-header-bar.ui
@@ -85,6 +85,8 @@
               <object class="GtkToggleButton" id="search">
                 <property name="visible">True</property>
                 <property name="valign">center</property>
+                <property name="active" bind-source="GamesCollectionHeaderBar" bind-property="search-mode" 
bind-flags="bidirectional"/>
+                <property name="sensitive" bind-source="GamesCollectionHeaderBar" 
bind-property="is-collection-empty" bind-flags="bidirectional|invert-boolean"/>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -137,6 +139,8 @@
               <object class="GtkToggleButton" id="search_subview">
                 <property name="visible">True</property>
                 <property name="valign">center</property>
+                <property name="active" bind-source="GamesCollectionHeaderBar" bind-property="search-mode" 
bind-flags="bidirectional"/>
+                <property name="sensitive" bind-source="GamesCollectionHeaderBar" 
bind-property="is-collection-empty" bind-flags="bidirectional|invert-boolean"/>
                 <style>
                   <class name="image-button"/>
                 </style>
diff --git a/data/ui/display-box.ui b/data/ui/display-box.ui
index 6435ba2d..b288071d 100644
--- a/data/ui/display-box.ui
+++ b/data/ui/display-box.ui
@@ -6,11 +6,13 @@
     <child>
       <object class="GamesFullscreenBox" id="fullscreen_box">
         <property name="visible">True</property>
+        <property name="is-fullscreen" bind-source="GamesDisplayBox" bind-property="is-fullscreen" 
bind-flags="bidirectional"/>
         <child type="titlebar">
           <object class="GamesDisplayHeaderBar" id="fullscreen_header_bar">
             <property name="visible">True</property>
             <property name="show-title-buttons">False</property>
             <signal name="back" handler="on_fullscreen_header_bar_back"/>
+            <signal name="size-allocate" handler="on_fullscreen_header_bar_size_allocated"/>
           </object>
         </child>
         <child>
diff --git a/data/ui/fullscreen-box.ui b/data/ui/fullscreen-box.ui
index 8c4b23df..66e3abe7 100644
--- a/data/ui/fullscreen-box.ui
+++ b/data/ui/fullscreen-box.ui
@@ -10,7 +10,7 @@
         <property name="visible">True</property>
         <child type="overlay">
           <object class="GtkRevealer" id="header_bar_revealer">
-            <property name="visible">True</property>
+            <property name="visible" bind-source="GamesFullscreenBox" bind-property="is-fullscreen" 
bind-flags="bidirectional">True</property>
             <property name="valign">start</property>
             <property name="hexpand">True</property>
             <property name="transition-type">slide-down</property>
diff --git a/data/ui/platforms-view.ui b/data/ui/platforms-view.ui
index 68dceeaf..5f978337 100644
--- a/data/ui/platforms-view.ui
+++ b/data/ui/platforms-view.ui
@@ -32,6 +32,7 @@
           <object class="GamesCollectionIconView" id="collection_view">
             <property name="visible">True</property>
             <property name="expand">True</property>
+            <signal name="game-activated" handler="on_game_activated"/>
           </object>
         </child>
       </object>
diff --git a/data/ui/preferences-page-platforms-generic-row.ui 
b/data/ui/preferences-page-platforms-generic-row.ui
index 6d5b87f1..fa50f6c0 100644
--- a/data/ui/preferences-page-platforms-generic-row.ui
+++ b/data/ui/preferences-page-platforms-generic-row.ui
@@ -10,6 +10,7 @@
         <property name="halign">start</property>
         <property name="hexpand">true</property>
         <property name="margin">6</property>
+        <property name="label" bind-source="GamesPreferencesPagePlatformsGenericRow" bind-property="title"/>
       </object>
     </child>
   </template>
diff --git a/data/ui/savestates-list.ui b/data/ui/savestates-list.ui
index d0a96aad..71f93aab 100644
--- a/data/ui/savestates-list.ui
+++ b/data/ui/savestates-list.ui
@@ -10,6 +10,7 @@
         <property name="visible">True</property>
         <property name="reveal-child">False</property>
         <property name="transition-type">slide-left</property>
+        <signal name="notify::child-revealed" handler="on_revealer_transition_end"/>
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
@@ -140,6 +141,7 @@
                 <property name="visible">true</property>
                 <property name="hexpand">true</property>
                 <property name="width-chars">1</property>
+                <signal name="notify::text" handler="on_rename_entry_text_changed"/>
                 <signal name="activate" handler="on_rename_entry_activated"/>
               </object>
             </child>
diff --git a/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui 
b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
index 95f9dfab..1e3c4880 100644
--- a/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
+++ b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
@@ -60,6 +60,7 @@
   </template>
   <object class="GtkPopover" id="layout_popover">
     <property name="visible">False</property>
+    <signal name="show" handler="update_ui"/>
     <child>
       <object class="GtkFrame">
         <property name="visible">True</property>
diff --git a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala 
b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
index e2ad0237..62eae1a0 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -31,8 +31,6 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
                        list_box.add (item);
                }
 
-               layout_popover.show.connect (update_ui);
-
                update_ui ();
 
                runner.notify["screen-layout"].connect (update_ui);
@@ -45,6 +43,7 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
                Object (runner: runner);
        }
 
+       [GtkCallback]
        private void update_ui () {
                var layout = runner.screen_layout;
                var view_bottom = runner.view_bottom_screen;
diff --git a/src/ui/checkmark-item.vala b/src/ui/checkmark-item.vala
index 4599e6ca..59ef635d 100644
--- a/src/ui/checkmark-item.vala
+++ b/src/ui/checkmark-item.vala
@@ -2,26 +2,10 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/checkmark-item.ui")]
 private class Games.CheckmarkItem : Gtk.ListBoxRow {
-       [GtkChild]
-       private Gtk.Label title_label;
-       [GtkChild]
-       private Gtk.Image checkmark_image;
-
        public bool checkmark_visible { get; set; }
-       private Binding checkmark_visible_binding;
-
-       public string label {
-               construct {
-                       title_label.label = value;
-               }
-       }
+       public string label { get; construct; }
 
        public CheckmarkItem (string label) {
                Object (label: label);
        }
-
-       construct {
-               checkmark_visible_binding = bind_property ("checkmark-visible", checkmark_image, "visible",
-                                                          BindingFlags.DEFAULT);
-       }
 }
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index 77b296db..00ed2d25 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -13,8 +13,6 @@ private class Games.CollectionBox : Gtk.Box {
        [GtkChild]
        private SearchBar search_bar;
        [GtkChild]
-       private Gtk.Revealer loading_notification_revealer;
-       [GtkChild]
        private EmptyCollection empty_collection;
        [GtkChild]
        private CollectionIconView collection_view;
@@ -41,45 +39,24 @@ private class Games.CollectionBox : Gtk.Box {
                }
        }
 
-       private AdaptiveState _adaptive_state;
-       public AdaptiveState adaptive_state {
-               get { return _adaptive_state; }
-               construct {
-                       _adaptive_state = value;
+       public AdaptiveState adaptive_state { get; construct; }
+
+       construct {
+               var icon_name = Config.APPLICATION_ID + "-symbolic";
+               viewstack.child_set (collection_view, "icon-name", icon_name);
 
-                       platform_view.adaptive_state = adaptive_state;
+               collection_view.model = collection;
+               platform_view.model = collection;
+               platform_view.adaptive_state = adaptive_state;
 
-                       adaptive_state.notify["is-showing-bottom-bar"].connect (update_bottom_bar);
-                       adaptive_state.notify["is-subview-open"].connect (update_bottom_bar);
-               }
+               adaptive_state.notify["is-showing-bottom-bar"].connect (update_bottom_bar);
+               adaptive_state.notify["is-subview-open"].connect (update_bottom_bar);
        }
 
-       private Binding collection_binding;
-       private Binding platform_collection_binding;
-       private Binding search_binding;
-       private Binding loading_notification_binding;
-
        public CollectionBox (ListModel collection, AdaptiveState adaptive_state) {
                Object (collection: collection, adaptive_state: adaptive_state);
        }
 
-       construct {
-               collection_binding = bind_property ("collection", collection_view, "model",
-                                                   BindingFlags.BIDIRECTIONAL);
-
-               platform_collection_binding = bind_property ("collection", platform_view,
-                                                            "model", BindingFlags.BIDIRECTIONAL);
-
-               search_binding = bind_property ("search-mode", search_bar, "search-mode-enabled",
-                                               BindingFlags.BIDIRECTIONAL);
-               loading_notification_binding = bind_property ("loading-notification",
-                                                             loading_notification_revealer,
-                                                             "reveal-child", BindingFlags.DEFAULT);
-
-               var icon_name = Config.APPLICATION_ID + "-symbolic";
-               viewstack.child_set (collection_view, "icon-name", icon_name);
-       }
-
        public void show_error (string error_message) {
                error_info_bar.show_error (error_message);
        }
@@ -146,7 +123,7 @@ private class Games.CollectionBox : Gtk.Box {
 
        [GtkCallback]
        private void on_loading_notification_closed () {
-               loading_notification_revealer.set_reveal_child (false);
+               loading_notification = false;
        }
 
        [GtkCallback]
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index 5e8542ce..0d59fc67 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -23,7 +23,6 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
                set {
                        _is_collection_empty = value;
                        title_squeezer.set_child_enabled (view_switcher, !value);
-                       search.sensitive = !_is_collection_empty;
                        update_adaptive_state ();
                }
        }
@@ -49,23 +48,9 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
        private Hdy.Squeezer title_squeezer;
        [GtkChild]
        private Hdy.ViewSwitcher view_switcher;
-       [GtkChild]
-       private Gtk.ToggleButton search;
-       [GtkChild]
-       private Gtk.ToggleButton search_subview;
-
-       private Binding search_binding;
-       private Binding search_subview_binding;
 
        private ulong viewstack_child_changed_id;
 
-       construct {
-               search_binding = bind_property ("search-mode", search, "active",
-                                               BindingFlags.BIDIRECTIONAL);
-               search_subview_binding = bind_property ("search-mode", search_subview,
-                                                       "active", BindingFlags.BIDIRECTIONAL);
-       }
-
        public CollectionHeaderBar (AdaptiveState adaptive_state) {
                Object (adaptive_state: adaptive_state);
        }
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 702a7869..7324eebb 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -72,17 +72,11 @@ private class Games.DisplayBox : Gtk.Bin {
        [GtkChild]
        private SavestatesList savestates_list;
 
-       private Binding fullscreen_binding;
        private int fullscreen_header_bar_height;
        private long timeout_id;
 
        construct {
-               fullscreen_binding = bind_property ("is-fullscreen", fullscreen_box,
-                                                   "is-fullscreen",
-                                                   BindingFlags.BIDIRECTIONAL);
                timeout_id = -1;
-
-               fullscreen_header_bar.size_allocate.connect (on_fullscreen_header_bar_size_allocated);
        }
 
        public DisplayBox (SavestatesListState savestates_list_state) {
@@ -142,6 +136,7 @@ private class Games.DisplayBox : Gtk.Bin {
                fullscreen_box.autohide = !savestates_list.state.is_revealed;
        }
 
+       [GtkCallback]
        private void on_fullscreen_header_bar_size_allocated (Gtk.Allocation allocation) {
                fullscreen_header_bar_height = allocation.height;
        }
diff --git a/src/ui/fullscreen-box.vala b/src/ui/fullscreen-box.vala
index 9b2eaf4f..1bfce112 100644
--- a/src/ui/fullscreen-box.vala
+++ b/src/ui/fullscreen-box.vala
@@ -79,15 +79,12 @@ private class Games.FullscreenBox : Gtk.EventBox, Gtk.Buildable {
        private Gtk.Overlay overlay;
        [GtkChild]
        private Gtk.Revealer header_bar_revealer;
-       private Binding visible_binding;
        private Binding fullscreen_binding;
 
        private uint ui_timeout_id;
        private uint cursor_timeout_id;
 
        construct {
-               visible_binding = bind_property ("is-fullscreen", header_bar_revealer,
-                                                "visible", BindingFlags.BIDIRECTIONAL);
                ui_timeout_id = -1;
                cursor_timeout_id = -1;
        }
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
index cb72593f..29e5ece2 100644
--- a/src/ui/platforms-view.vala
+++ b/src/ui/platforms-view.vala
@@ -97,13 +97,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
                list_box.set_sort_func (sort_rows);
 
-               collection_view.game_activated.connect ((game) => {
-                       game_activated (game);
-               });
-
                collection_view.set_game_filter (filter_game);
-
-               has_used_gamepad = false;
        }
 
        private int sort_rows (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
@@ -332,6 +326,11 @@ private class Games.PlatformsView : Gtk.Bin {
                adaptive_state.is_folded = leaflet.folded;
        }
 
+       [GtkCallback]
+       public void on_game_activated (Game game) {
+               game_activated (game);
+       }
+
        private void update_subview () {
                if (adaptive_state.is_subview_open)
                        leaflet.visible_child = collection_view;
diff --git a/src/ui/preferences-page-platforms-generic-row.vala 
b/src/ui/preferences-page-platforms-generic-row.vala
index 73021930..b036e9b7 100644
--- a/src/ui/preferences-page-platforms-generic-row.vala
+++ b/src/ui/preferences-page-platforms-generic-row.vala
@@ -2,18 +2,10 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-platforms-generic-row.ui")]
 private class Games.PreferencesPagePlatformsGenericRow : PreferencesPagePlatformsRow, Gtk.ListBoxRow {
-       [GtkChild]
-       private Gtk.Label title_label;
-
-       public string title {
-               get { return title_label.label; }
-               construct set {
-                       title_label.label = value;
-               }
-       }
+       public string title { get; construct; }
 
        public PreferencesPagePlatformsGenericRow (string title) {
-               Object (title:title);
+               Object (title: title);
        }
 
        public void on_activated () {
diff --git a/src/ui/savestates-list.vala b/src/ui/savestates-list.vala
index 0248fc4c..192dfe19 100644
--- a/src/ui/savestates-list.vala
+++ b/src/ui/savestates-list.vala
@@ -45,8 +45,6 @@ private class Games.SavestatesList : Gtk.Box {
 
        construct {
                list_box.set_header_func (update_header);
-               revealer.notify["child-revealed"].connect (on_revealer_transition_end);
-               rename_entry.notify["text"].connect (on_rename_entry_text_changed);
        }
 
        public void set_margin (int margin) {
@@ -144,6 +142,7 @@ private class Games.SavestatesList : Gtk.Box {
                // Runner isn't resumed here but after the revealer finishes the transition
        }
 
+       [GtkCallback]
        private void on_revealer_transition_end () {
                state.on_revealer_transition_end ();
        }
@@ -216,6 +215,7 @@ private class Games.SavestatesList : Gtk.Box {
                        apply_rename ();
        }
 
+       [GtkCallback]
        private void on_rename_entry_text_changed () {
                check_rename_is_valid ();
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]