[gnome-games] ui: Remove AdaptiveState



commit e586c5db9f141f8c561987a185839652abd3d013
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Jan 27 00:50:45 2020 +0500

    ui: Remove AdaptiveState
    
    Replace it with separate properties.

 data/ui/collection-box.ui         |  6 +++++
 data/ui/collection-header-bar.ui  |  6 ++++-
 data/ui/platforms-view.ui         |  2 ++
 src/meson.build                   |  1 -
 src/ui/adaptive-state.vala        | 15 ------------
 src/ui/collection-box.vala        | 20 +++++++---------
 src/ui/collection-header-bar.vala | 31 +++++++------------------
 src/ui/collection-view.vala       | 36 ++++++++++++++++++++++------
 src/ui/platforms-view.vala        | 49 +++++++++++----------------------------
 9 files changed, 73 insertions(+), 93 deletions(-)
---
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index b5f5a054..7684f45f 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -7,6 +7,9 @@
     <property name="hexpand">True</property>
     <property name="vexpand">True</property>
     <property name="width-request">360</property>
+    <signal name="notify::is-folded" handler="update_bottom_bar"/>
+    <signal name="notify::is-showing-bottom-bar" handler="update_bottom_bar"/>
+    <signal name="notify::is-subview-open" handler="update_bottom_bar"/>
     <child>
       <object class="GamesSearchBar" id="search_bar">
         <property name="visible">True</property>
@@ -51,6 +54,9 @@
             <child>
               <object class="GamesPlatformsView" id="platform_view">
                 <property name="visible">True</property>
+                <property name="is-folded" bind-source="GamesCollectionBox" bind-property="is-folded" 
bind-flags="bidirectional"/>
+                <property name="is-subview-open" bind-source="GamesCollectionBox" 
bind-property="is-subview-open" bind-flags="bidirectional"/>
+                <property name="subview-title" bind-source="GamesCollectionBox" 
bind-property="subview-title" bind-flags="bidirectional"/>
                 <signal name="game-activated" handler="on_game_activated"/>
               </object>
               <packing>
diff --git a/data/ui/collection-header-bar.ui b/data/ui/collection-header-bar.ui
index 524a4096..a0293583 100644
--- a/data/ui/collection-header-bar.ui
+++ b/data/ui/collection-header-bar.ui
@@ -3,6 +3,9 @@
   <requires lib="gtk+" version="3.24"/>
   <template class="GamesCollectionHeaderBar" parent="GtkBin">
     <property name="visible">True</property>
+    <signal name="notify::is-collection-empty" handler="update_adaptive_state"/>
+    <signal name="notify::is-folded" handler="update_subview"/>
+    <signal name="notify::is-subview-open" handler="update_subview"/>
     <child>
       <object class="GtkStack" id="stack">
         <property name="visible">True</property>
@@ -63,7 +66,7 @@
               <object class="HdySqueezer" id="title_squeezer">
                 <property name="visible">True</property>
                 <property name="transition-type">crossfade</property>
-                <signal name="notify::visible-child" handler="on_squeezer_visible_child_changed"/>
+                <signal name="notify::visible-child" handler="update_adaptive_state"/>
                 <child>
                   <object class="HdyViewSwitcher" id="view_switcher">
                     <property name="visible">True</property>
@@ -113,6 +116,7 @@
           <object class="GtkHeaderBar" id="subview_header_bar">
             <property name="visible">True</property>
             <property name="show_close_button">True</property>
+            <property name="title" bind-source="GamesCollectionHeaderBar" bind-property="subview-title" 
bind-flags="bidirectional"/>
             <child>
               <object class="GtkButton">
                 <property name="visible">True</property>
diff --git a/data/ui/platforms-view.ui b/data/ui/platforms-view.ui
index 31ffd498..15c78e8c 100644
--- a/data/ui/platforms-view.ui
+++ b/data/ui/platforms-view.ui
@@ -6,6 +6,8 @@
     <property name="expand">True</property>
     <signal name="map" after="yes" handler="on_map"/>
     <signal name="unmap" after="no" handler="on_unmap"/>
+    <signal name="notify::is-folded" handler="update_selection_mode"/>
+    <signal name="notify::is-subview-open" handler="update_subview"/>
     <child>
       <object class="HdyLeaflet" id="leaflet">
         <property name="visible">True</property>
diff --git a/src/meson.build b/src/meson.build
index e6132ef4..d7a74275 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -98,7 +98,6 @@ vala_sources = [
   'tracker/tracker-uri-query.vala',
   'tracker/tracker-uri-source.vala',
 
-  'ui/adaptive-state.vala',
   'ui/application.vala',
   'ui/application-window.vala',
   'ui/checkmark-item.vala',
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index 515bb24d..aa49817d 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -39,7 +39,10 @@ private class Games.CollectionBox : Gtk.Box {
                }
        }
 
-       public AdaptiveState adaptive_state { get; construct; }
+       public bool is_folded { get; set; }
+       public bool is_showing_bottom_bar { get; set; }
+       public bool is_subview_open { get; set; }
+       public string subview_title { get; set; }
 
        construct {
                var icon_name = Config.APPLICATION_ID + "-symbolic";
@@ -47,15 +50,10 @@ private class Games.CollectionBox : Gtk.Box {
 
                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-folded"].connect (update_bottom_bar);
        }
 
-       public CollectionBox (ListModel collection, AdaptiveState adaptive_state) {
-               Object (collection: collection, adaptive_state: adaptive_state);
+       public CollectionBox (ListModel collection) {
+               Object (collection: collection);
        }
 
        public void show_error (string error_message) {
@@ -141,7 +139,7 @@ private class Games.CollectionBox : Gtk.Box {
                        collection_view.reset_scroll_position ();
                }
 
-               adaptive_state.is_subview_open = false;
+               is_subview_open = false;
        }
 
        [GtkCallback]
@@ -165,8 +163,8 @@ private class Games.CollectionBox : Gtk.Box {
                return search_bar.handle_event (event);
        }
 
+       [GtkCallback]
        private void update_bottom_bar () {
-               view_switcher_bar.reveal = adaptive_state.is_showing_bottom_bar &&
-                       (!adaptive_state.is_folded || !adaptive_state.is_subview_open);
+               view_switcher_bar.reveal = is_showing_bottom_bar && (!is_folded || !is_subview_open);
        }
 }
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index 2e11430c..b4f487f4 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -23,11 +23,13 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
                set {
                        _is_collection_empty = value;
                        title_squeezer.set_child_enabled (view_switcher, !value);
-                       update_adaptive_state ();
                }
        }
 
-       public AdaptiveState adaptive_state { get; construct; }
+       public bool is_folded { get; set; }
+       public bool is_showing_bottom_bar { get; set; }
+       public bool is_subview_open { get; set; }
+       public string subview_title { get; set; }
 
        [GtkChild]
        private Gtk.Stack stack;
@@ -42,39 +44,22 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
 
        private ulong viewstack_child_changed_id;
 
-       construct {
-               adaptive_state.notify["is-folded"].connect (update_subview);
-               adaptive_state.notify["is-subview-open"].connect (update_subview);
-               adaptive_state.notify["subview-title"].connect (update_subview_title);
-       }
-
-       public CollectionHeaderBar (AdaptiveState adaptive_state) {
-               Object (adaptive_state: adaptive_state);
-       }
-
        [GtkCallback]
-       private void on_squeezer_visible_child_changed () {
-               update_adaptive_state ();
-       }
-
        private void update_adaptive_state () {
                bool showing_title = title_squeezer.visible_child != view_switcher;
-               adaptive_state.is_showing_bottom_bar = showing_title && !is_collection_empty;
+               is_showing_bottom_bar = showing_title && !is_collection_empty;
        }
 
+       [GtkCallback]
        private void update_subview () {
-               if (adaptive_state.is_subview_open && adaptive_state.is_folded)
+               if (is_subview_open && is_folded)
                        stack.visible_child = subview_header_bar;
                else
                        stack.visible_child = header_bar;
        }
 
-       private void update_subview_title () {
-               subview_header_bar.title = adaptive_state.subview_title;
-       }
-
        [GtkCallback]
        private void on_subview_back_clicked () {
-               adaptive_state.is_subview_open = false;
+               is_subview_open = false;
        }
 }
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 82ad90ca..2e89d7fe 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -39,14 +39,16 @@ private class Games.CollectionView : Object, UiView {
        public bool search_mode { get; set; }
        public bool is_collection_empty { get; set; }
 
+       public bool is_folded { get; set; }
+       public bool is_showing_bottom_bar { get; set; }
+       public bool is_subview_open { get; set; }
+       public string subview_title { get; set; }
+
        private KonamiCode konami_code;
-       private AdaptiveState adaptive_state;
 
        construct {
-               adaptive_state = new AdaptiveState ();
-
-               box = new CollectionBox (collection, adaptive_state);
-               header_bar = new CollectionHeaderBar (adaptive_state);
+               box = new CollectionBox (collection);
+               header_bar = new CollectionHeaderBar ();
                box.game_activated.connect (game => {
                        game_activated (game);
                });
@@ -72,6 +74,26 @@ private class Games.CollectionView : Object, UiView {
                bind_property ("is-collection-empty", header_bar,
                               "is-collection-empty", BindingFlags.BIDIRECTIONAL);
 
+               bind_property ("is-folded", box,
+                              "is-folded", BindingFlags.BIDIRECTIONAL);
+               bind_property ("is-folded", header_bar,
+                              "is-folded", BindingFlags.BIDIRECTIONAL);
+
+               bind_property ("is-showing-bottom-bar", box,
+                              "is-showing-bottom-bar", BindingFlags.BIDIRECTIONAL);
+               bind_property ("is-showing-bottom-bar", header_bar,
+                              "is-showing-bottom-bar", BindingFlags.BIDIRECTIONAL);
+
+               bind_property ("is-subview-open", box,
+                              "is-subview-open", BindingFlags.BIDIRECTIONAL);
+               bind_property ("is-subview-open", header_bar,
+                              "is-subview-open", BindingFlags.BIDIRECTIONAL);
+
+               bind_property ("subview-title", box,
+                              "subview-title", BindingFlags.BIDIRECTIONAL);
+               bind_property ("subview-title", header_bar,
+                              "subview-title", BindingFlags.BIDIRECTIONAL);
+
                konami_code = new KonamiCode (window);
                konami_code.code_performed.connect (on_konami_code_performed);
        }
@@ -99,8 +121,8 @@ private class Games.CollectionView : Object, UiView {
                if (((event.state & default_modifiers) == Gdk.ModifierType.MOD1_MASK) &&
                    (((window.get_direction () == Gtk.TextDirection.LTR) && keyval == Gdk.Key.Left) ||
                     ((window.get_direction () == Gtk.TextDirection.RTL) && keyval == Gdk.Key.Right)) &&
-                    adaptive_state.is_subview_open) {
-                       adaptive_state.is_subview_open = false;
+                    is_subview_open) {
+                       is_subview_open = false;
 
                        return true;
                }
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
index 6c89f4ec..409b579c 100644
--- a/src/ui/platforms-view.vala
+++ b/src/ui/platforms-view.vala
@@ -16,8 +16,6 @@ private class Games.PlatformsView : Gtk.Bin {
        private GamepadBrowse gamepad_browse;
 
        private ulong model_items_changed_id;
-       private ulong adaptive_state_folded_id;
-       private ulong adaptive_state_subview_id;
 
        private GenericSet<Platform> platforms;
        private Platform selected_platform;
@@ -67,30 +65,9 @@ private class Games.PlatformsView : Gtk.Bin {
                }
        }
 
-       private AdaptiveState _adaptive_state;
-       public AdaptiveState adaptive_state {
-               get { return _adaptive_state; }
-               set {
-                       if (adaptive_state_subview_id != 0) {
-                               adaptive_state.disconnect (adaptive_state_subview_id);
-                               adaptive_state_subview_id = 0;
-                       }
-
-                       if (adaptive_state_folded_id != 0) {
-                               adaptive_state.disconnect (adaptive_state_folded_id);
-                               adaptive_state_folded_id = 0;
-                       }
-
-                       _adaptive_state = value;
-
-                       if (adaptive_state != null) {
-                               adaptive_state_subview_id = adaptive_state.notify["is-subview-open"].connect 
(update_subview);
-                               adaptive_state_folded_id = adaptive_state.notify["is-folded"].connect 
(update_selection_mode);
-
-                               on_leaflet_folded_changed ();
-                       }
-               }
-       }
+       public bool is_folded { get; set; }
+       public bool is_subview_open { get; set; }
+       public string subview_title { get; set; }
 
        construct {
                platforms = new GenericSet<Platform> (Platform.hash, Platform.equal);
@@ -194,7 +171,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
                        return true;
                case Gtk.DirectionType.RIGHT:
-                       adaptive_state.is_subview_open = true;
+                       is_subview_open = true;
                        collection_view.select_default_game (Gtk.DirectionType.RIGHT);
 
                        return true;
@@ -205,7 +182,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
        [GtkCallback]
        private bool on_gamepad_accept () {
-               adaptive_state.is_subview_open = true;
+               is_subview_open = true;
                collection_view.select_default_game (Gtk.DirectionType.RIGHT);
 
                return true;
@@ -214,7 +191,7 @@ private class Games.PlatformsView : Gtk.Bin {
        [GtkCallback]
        private bool on_gamepad_cancel () {
                collection_view.unselect_game ();
-               adaptive_state.is_subview_open = false;
+               is_subview_open = false;
 
                return true;
        }
@@ -223,13 +200,13 @@ private class Games.PlatformsView : Gtk.Bin {
        private void on_list_box_row_activated (Gtk.ListBoxRow row_item) {
                select_platform_for_row (row_item);
 
-               adaptive_state.is_subview_open = true;
+               is_subview_open = true;
        }
 
        private void select_platform_for_row (Gtk.ListBoxRow row_item) {
                var row = row_item as PlatformListItem;
                selected_platform = row.platform;
-               adaptive_state.subview_title = selected_platform.get_name ();
+               subview_title = selected_platform.get_name ();
 
                collection_view.invalidate_flow_box_filter ();
                collection_view.reset_scroll_position ();
@@ -267,7 +244,7 @@ private class Games.PlatformsView : Gtk.Bin {
        }
 
        private void select_current_row () {
-               if (adaptive_state.is_folded && !has_used_gamepad)
+               if (is_folded && !has_used_gamepad)
                        return;
 
                foreach (var child in list_box.get_children ()) {
@@ -313,8 +290,9 @@ private class Games.PlatformsView : Gtk.Bin {
                select_first_visible_row ();
        }
 
+       [GtkCallback]
        private void update_selection_mode () {
-               if (!adaptive_state.is_folded || has_used_gamepad)
+               if (!is_folded || has_used_gamepad)
                        list_box.selection_mode = Gtk.SelectionMode.SINGLE;
                else
                        list_box.selection_mode = Gtk.SelectionMode.NONE;
@@ -323,7 +301,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
        [GtkCallback]
        private void on_leaflet_folded_changed () {
-               adaptive_state.is_folded = leaflet.folded;
+               is_folded = leaflet.folded;
                if (leaflet.folded)
                        leaflet.get_style_context ().add_class ("folded");
                else
@@ -335,8 +313,9 @@ private class Games.PlatformsView : Gtk.Bin {
                game_activated (game);
        }
 
+       [GtkCallback]
        private void update_subview () {
-               if (adaptive_state.is_subview_open)
+               if (is_subview_open)
                        leaflet.visible_child = collection_view;
                else
                        leaflet.visible_child = scrolled_window;


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