[gnome-games/wip/exalm/unified-window: 44/60] collection-box: Merge into CollectionView



commit 62a92b7c90590257c19f4fc86fc042b534d47b82
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Apr 10 03:02:00 2020 +0500

    collection-box: Merge into CollectionView

 data/org.gnome.Games.gresource.xml                |   2 +-
 data/ui/{collection-box.ui => collection-view.ui} |  12 +-
 src/meson.build                                   |   1 -
 src/ui/collection-box.vala                        | 209 ----------------------
 src/ui/collection-view.vala                       | 207 +++++++++++++++++----
 5 files changed, 183 insertions(+), 248 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index f83b61ae..68e1260b 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -12,9 +12,9 @@
     <file preprocess="xml-stripblanks">gesture/stick-symbolic.svg</file>
     <file preprocess="xml-stripblanks">ui/application-window.ui</file>
     <file preprocess="xml-stripblanks">ui/checkmark-item.ui</file>
-    <file preprocess="xml-stripblanks">ui/collection-box.ui</file>
     <file preprocess="xml-stripblanks">ui/collection-header-bar.ui</file>
     <file preprocess="xml-stripblanks">ui/collection-icon-view.ui</file>
+    <file preprocess="xml-stripblanks">ui/collection-view.ui</file>
     <file preprocess="xml-stripblanks">ui/display-box.ui</file>
     <file preprocess="xml-stripblanks">ui/display-header-bar.ui</file>
     <file preprocess="xml-stripblanks">ui/empty-collection.ui</file>
diff --git a/data/ui/collection-box.ui b/data/ui/collection-view.ui
similarity index 93%
rename from data/ui/collection-box.ui
rename to data/ui/collection-view.ui
index cf690892..97f3905f 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-view.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.24"/>
-  <template class="GamesCollectionBox" parent="GtkBox">
+  <template class="GamesCollectionView" parent="GtkBox">
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <property name="hexpand">True</property>
@@ -19,7 +19,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"/>
+        <property name="search-mode-enabled" bind-source="GamesCollectionView" bind-property="search-mode" 
bind-flags="bidirectional"/>
         <signal name="notify::text" handler="on_search_text_notify"/>
       </object>
     </child>
@@ -70,9 +70,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"/>
+                    <property name="is-folded" bind-source="GamesCollectionView" bind-property="is-folded" 
bind-flags="bidirectional"/>
+                    <property name="is-subview-open" bind-source="GamesCollectionView" 
bind-property="is-subview-open" bind-flags="bidirectional"/>
+                    <property name="subview-title" bind-source="GamesCollectionView" 
bind-property="subview-title" bind-flags="bidirectional"/>
                     <signal name="game-activated" handler="on_game_activated"/>
                   </object>
                   <packing>
@@ -91,7 +91,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"/>
+            <property name="reveal-child" bind-source="GamesCollectionView" 
bind-property="loading-notification" bind-flags="bidirectional"/>
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
diff --git a/src/meson.build b/src/meson.build
index 14445037..ecd6911e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -99,7 +99,6 @@ vala_sources = [
   'ui/application.vala',
   'ui/application-window.vala',
   'ui/checkmark-item.vala',
-  'ui/collection-box.vala',
   'ui/collection-icon-view.vala',
   'ui/collection-header-bar.vala',
   'ui/collection-view.vala',
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 3eaff69d..e8a95e33 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -1,15 +1,40 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-private class Games.CollectionView : Object, UiView {
+[GtkTemplate (ui = "/org/gnome/Games/ui/collection-view.ui")]
+private class Games.CollectionView : Gtk.Box, UiView {
        private const string CONTRIBUTE_URI = "https://wiki.gnome.org/Apps/Games/Contribute";;
 
        public signal void game_activated (Game game);
 
-       private CollectionBox box;
+       [GtkChild]
+       private ErrorInfoBar error_info_bar;
+       [GtkChild]
+       private SearchBar search_bar;
+       [GtkChild]
+       private EmptyCollection empty_collection;
+       [GtkChild]
+       private EmptySearch empty_search;
+       [GtkChild]
+       private CollectionIconView collection_view;
+       [GtkChild]
+       private PlatformsView platform_view;
+       [GtkChild]
+       private Gtk.Stack empty_stack;
+       [GtkChild (name = "viewstack")]
+       private Gtk.Stack _viewstack;
+       [GtkChild]
+       private Hdy.ViewSwitcherBar view_switcher_bar;
+       [GtkChild]
        private CollectionHeaderBar header_bar;
+       [GtkChild]
+       private Hdy.SwipeGroup swipe_group;
 
        public Gtk.Widget content_box {
-               get { return box; }
+               get { return this; }
+       }
+
+       public Gtk.Stack viewstack {
+               get { return _viewstack; }
        }
 
        private bool _is_view_active;
@@ -28,12 +53,36 @@ private class Games.CollectionView : Object, UiView {
                }
        }
 
+       private bool _is_collection_empty;
+       public bool is_collection_empty {
+               get { return _is_collection_empty; }
+               set {
+                       _is_collection_empty = value;
+                       if (_is_collection_empty)
+                               empty_stack.visible_child = empty_collection;
+                       else
+                               empty_stack.visible_child = viewstack;
+               }
+       }
+
+       public string[] filtering_terms;
+       public string filtering_text {
+                set {
+                       if (value == null)
+                               filtering_terms = null;
+                       else
+                               filtering_terms = value.split (" ");
+
+                       platform_view.set_filter (filtering_terms);
+                       collection_view.set_filter (filtering_terms);
+               }
+       }
+
        public Gtk.Window window { get; construct; }
        public GameModel game_model { get; construct; }
 
        public bool loading_notification { get; set; }
        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; }
@@ -43,50 +92,37 @@ private class Games.CollectionView : Object, UiView {
        private KonamiCode konami_code;
 
        construct {
-               box = new CollectionBox (game_model);
-               header_bar = box.header_bar;
+               var icon_name = Config.APPLICATION_ID + "-symbolic";
+               viewstack.child_set (collection_view, "icon-name", icon_name);
 
-               box.game_activated.connect (game => {
-                       game_activated (game);
-               });
+               collection_view.game_model = game_model;
+               platform_view.game_model = game_model;
+
+               swipe_group.add_swipeable (platform_view.get_leaflet ());
 
                is_collection_empty = game_model.get_n_items () == 0;
                game_model.items_changed.connect (() => {
                        is_collection_empty = game_model.get_n_items () == 0;
                });
 
-               header_bar.viewstack = box.viewstack;
-
-               bind_property ("loading-notification", box,
-                              "loading-notification", BindingFlags.DEFAULT);
+               bind_property ("viewstack", header_bar,
+                              "viewstack", BindingFlags.SYNC_CREATE);
 
-               bind_property ("search-mode", box,
-                              "search-mode", BindingFlags.BIDIRECTIONAL);
                bind_property ("search-mode", header_bar,
                               "search-mode", BindingFlags.BIDIRECTIONAL);
 
-               bind_property ("is-collection-empty", box,
-                              "is-collection-empty", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
                bind_property ("is-collection-empty", header_bar,
                               "is-collection-empty", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
 
-               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);
 
@@ -99,7 +135,7 @@ private class Games.CollectionView : Object, UiView {
        }
 
        public void show_error (string error_message) {
-               box.show_error (error_message);
+               error_info_bar.show_error (error_message);
        }
 
        public bool on_button_pressed (Gdk.EventButton event) {
@@ -129,19 +165,79 @@ private class Games.CollectionView : Object, UiView {
                        return true;
                }
 
-               return box.search_bar_handle_event (event);
+               if (is_collection_empty)
+                       return false;
+
+               return search_bar.handle_event (event);
        }
 
        public bool gamepad_button_press_event (Manette.Event event) {
-               return window.is_active && box.gamepad_button_press_event (event);
+               if (!window.is_active)
+                       return false;
+
+               if (!get_mapped ())
+                       return false;
+
+               uint16 button;
+               if (!event.get_button (out button))
+                       return false;
+
+               if (is_collection_empty)
+                       return false;
+
+               switch (button) {
+               case EventCode.BTN_TL:
+                       var views = viewstack.get_children ();
+                       unowned List<weak Gtk.Widget> current_view = views.find (viewstack.visible_child);
+
+                       assert (current_view != null);
+
+                       if (current_view.prev != null)
+                               viewstack.visible_child = current_view.prev.data;
+
+                       return true;
+               case EventCode.BTN_TR:
+                       var views = viewstack.get_children ();
+                       unowned List<weak Gtk.Widget> current_view = views.find (viewstack.visible_child);
+
+                       assert (current_view != null);
+
+                       if (current_view.next != null)
+                               viewstack.visible_child = current_view.next.data;
+
+                       return true;
+               default:
+                       if (viewstack.visible_child == platform_view)
+                               return platform_view.gamepad_button_press_event (event);
+                       else
+                               return collection_view.gamepad_button_press_event (event);
+               }
        }
 
        public bool gamepad_button_release_event (Manette.Event event) {
-               return window.is_active && box.gamepad_button_release_event (event);
+               if (!window.is_active)
+                       return false;
+
+               if (!get_mapped ())
+                       return false;
+
+               if (viewstack.visible_child == platform_view)
+                       return platform_view.gamepad_button_release_event (event);
+               else
+                       return collection_view.gamepad_button_release_event (event);
        }
 
        public bool gamepad_absolute_axis_event (Manette.Event event) {
-               return window.is_active && box.gamepad_absolute_axis_event (event);
+               if (!window.is_active)
+                       return false;
+
+               if (!get_mapped ())
+                       return false;
+
+               if (viewstack.visible_child == platform_view)
+                       return platform_view.gamepad_absolute_axis_event (event);
+               else
+                       return collection_view.gamepad_absolute_axis_event (event);
        }
 
        private void on_konami_code_performed () {
@@ -158,6 +254,55 @@ private class Games.CollectionView : Object, UiView {
 
        public void run_search (string query) {
                search_mode = true;
-               box.run_search (query);
+               search_bar.run_search (query);
+       }
+
+       [GtkCallback]
+       private void on_loading_notification_closed () {
+               loading_notification = false;
+       }
+
+       [GtkCallback]
+       private void on_game_activated (Game game) {
+               game_activated (game);
+       }
+
+       [GtkCallback]
+       private void on_visible_child_changed () {
+               if (viewstack.visible_child == collection_view)
+                       collection_view.reset_scroll_position ();
+               else
+                       platform_view.reset ();
+       }
+
+       [GtkCallback]
+       private void on_search_text_notify () {
+               filtering_text = search_bar.text;
+               if (found_games ())
+                       empty_stack.visible_child = viewstack;
+               else
+                       empty_stack.visible_child = empty_search;
+
+               // Changing the filtering_text for the PlatformView might
+               // cause the currently selected sidebar row to become empty and therefore
+               // hidden. In this case the first visible row will become selected and
+               // this causes the search bar to lose focus so we have to regrab it here
+               search_bar.focus_entry ();
+       }
+
+       private bool found_games () {
+               for (int i = 0; i < game_model.get_n_items (); i++) {
+                       var game = game_model.get_item (i) as Game;
+
+                       if (game.matches_search_terms (filtering_terms))
+                               return true;
+               }
+
+               return false;
+       }
+
+       [GtkCallback]
+       private void update_bottom_bar () {
+               view_switcher_bar.reveal = is_showing_bottom_bar && (!is_folded || !is_subview_open);
        }
 }


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