[gnome-games] ui: Integrate Developers view & Platforms view into Games



commit 5063040204d08f74a817f921067dfa3c44500621
Author: 1PunMan <saurabhsingh412 gmail com>
Date:   Wed Aug 1 23:38:36 2018 +0530

    ui: Integrate Developers view & Platforms view into Games
    
    This commit introduces the following changes-
    * Add StackSwitcher Widget that will allow easy navigation between developers
    view & platforms view.
    * Add Developers view & Platforms view to CollectionBox.
    * Add developer & platform filtering methods to CollectionView.

 data/ui/collection-box.ui         | 37 ++++++++++++++++++++++++++++--
 data/ui/collection-header-bar.ui  |  6 ++++-
 src/ui/application-window.vala    |  2 ++
 src/ui/collection-box.vala        | 47 ++++++++++++++++++++++++++++++++++-----
 src/ui/collection-header-bar.vala | 10 +++++++++
 src/ui/collection-icon-view.vala  | 35 ++++++++++++++++++++++++-----
 6 files changed, 123 insertions(+), 14 deletions(-)
---
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index fb1e6c36..d3f14105 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -25,9 +25,42 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <child>
-          <object class="GamesCollectionIconView" id="icon_view">
+          <object class="GtkStack" id="viewstack">
             <property name="visible">True</property>
-            <signal name="game-activated" handler="on_game_activated"/>
+            <property name="can_focus">False</property>
+            <property name="visible-child">collection_view</property>
+            <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
+            <signal name="notify::visible-child" handler="on_visible_child_changed"/>
+            <child>
+              <object class="GamesCollectionIconView" id="collection_view">
+                <property name="visible">True</property>
+                <signal name="game-activated" handler="on_game_activated"/>
+              </object>
+              <packing>
+                <property name="name">games</property>
+                <property name="title" translatable="yes">Games</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GamesDevelopersView" id="developer_view">
+                <property name="visible">True</property>
+                <signal name="game-activated" handler="on_game_activated"/>
+              </object>
+              <packing>
+                <property name="name">developer</property>
+                <property name="title" translatable="yes">Developers</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GamesPlatformsView" id="platform_view">
+                <property name="visible">True</property>
+                <signal name="game-activated" handler="on_game_activated"/>
+              </object>
+              <packing>
+                <property name="name">platform</property>
+                <property name="title" translatable="yes">Platforms</property>
+              </packing>
+            </child>
           </object>
         </child>
         <child type="overlay">
diff --git a/data/ui/collection-header-bar.ui b/data/ui/collection-header-bar.ui
index 45ef2d79..93e53da8 100644
--- a/data/ui/collection-header-bar.ui
+++ b/data/ui/collection-header-bar.ui
@@ -4,7 +4,6 @@
   <template class="GamesCollectionHeaderBar" parent="GtkHeaderBar">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="title" translatable="yes">Games</property>
     <child>
       <object class="GtkButton" id="add_game">
         <property name="visible">True</property>
@@ -54,6 +53,11 @@
         <property name="pack-type">end</property>
       </packing>
     </child>
+    <child type="title">
+      <object class="GtkStackSwitcher" id="view_switcher">
+        <property name="visible">True</property>
+      </object>
+    </child>
     <child>
       <object class="GtkToggleButton" id="search">
         <property name="visible">True</property>
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 66205939..255b104a 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -134,6 +134,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                konami_code = new KonamiCode (this);
                konami_code.code_performed.connect (on_konami_code_performed);
 
+               collection_header_bar.viewstack = collection_box.viewstack;
+
                window_size_update_timeout = -1;
                focus_out_timeout_id = -1;
                inhibit_cookie = 0;
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index 285b5b0e..78f6acfc 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -13,9 +13,20 @@ private class Games.CollectionBox : Gtk.Box {
        [GtkChild]
        private Gtk.Revealer loading_notification_revealer;
        [GtkChild]
-       private CollectionIconView icon_view;
+       private CollectionIconView collection_view;
+       [GtkChild]
+       private DevelopersView developer_view;
+       [GtkChild]
+       private PlatformsView platform_view;
+       [GtkChild (name = "viewstack")]
+       private Gtk.Stack _viewstack;
+       public Gtk.Stack viewstack {
+               get { return _viewstack; }
+       }
 
        private Binding collection_binding;
+       private Binding developer_collection_binding;
+       private Binding platform_collection_binding;
        private Binding search_binding;
        private Binding loading_notification_binding;
 
@@ -24,8 +35,15 @@ private class Games.CollectionBox : Gtk.Box {
        }
 
        construct {
-               collection_binding = bind_property ("collection", icon_view, "model",
+               collection_binding = bind_property ("collection", collection_view, "model",
                                                    BindingFlags.BIDIRECTIONAL);
+
+               developer_collection_binding = bind_property ("collection", developer_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",
@@ -33,15 +51,15 @@ private class Games.CollectionBox : Gtk.Box {
        }
 
        public bool gamepad_button_press_event (Manette.Event event) {
-               return icon_view.gamepad_button_press_event (event);
+               return collection_view.gamepad_button_press_event (event);
        }
 
        public bool gamepad_button_release_event (Manette.Event event) {
-               return icon_view.gamepad_button_release_event (event);
+               return collection_view.gamepad_button_release_event (event);
        }
 
        public bool gamepad_absolute_axis_event (Manette.Event event) {
-               return icon_view.gamepad_absolute_axis_event (event);
+               return collection_view.gamepad_absolute_axis_event (event);
        }
 
        [GtkCallback]
@@ -54,9 +72,26 @@ private class Games.CollectionBox : Gtk.Box {
                game_activated (game);
        }
 
+       [GtkCallback]
+       private void on_visible_child_changed () {
+               if (viewstack.visible_child == platform_view) {
+                       platform_view.select_default_row ();
+               }
+               else if (viewstack.visible_child == developer_view) {
+                       developer_view.select_default_row ();
+               }
+       }
+
        [GtkCallback]
        private void on_search_text_notify () {
-               icon_view.filtering_text = search_bar.text;
+               if (viewstack.visible_child == platform_view) {
+                       platform_view.filtering_text = search_bar.text;
+               }
+               else if (viewstack.visible_child == developer_view) {
+                       developer_view.filtering_text = search_bar.text;
+               }
+               else
+                       collection_view.filtering_text = search_bar.text;
        }
 
        public bool search_bar_handle_event (Gdk.Event event) {
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index 87b833cd..a7c3eea3 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -3,7 +3,17 @@
 [GtkTemplate (ui = "/org/gnome/Games/ui/collection-header-bar.ui")]
 private class Games.CollectionHeaderBar : Gtk.HeaderBar {
        public bool search_mode { set; get; }
+       private Gtk.Stack _viewstack;
+       public Gtk.Stack viewstack {
+               set {
+                       _viewstack = value;
+                       view_switcher.set_stack (_viewstack);
+               }
+               get { return _viewstack; }
+       }
 
+       [GtkChild]
+       private Gtk.StackSwitcher view_switcher;
        [GtkChild]
        private Gtk.ToggleButton search;
        private Binding search_binding;
diff --git a/src/ui/collection-icon-view.vala b/src/ui/collection-icon-view.vala
index c4b284bd..53ba49d8 100644
--- a/src/ui/collection-icon-view.vala
+++ b/src/ui/collection-icon-view.vala
@@ -11,6 +11,7 @@ private class Games.CollectionIconView : Gtk.Stack {
        private const double DEAD_ZONE = 0.3;
 
        public signal void game_activated (Game game);
+       public signal void game_changed (Game game);
 
        private string[] filtering_terms;
        public string filtering_text {
@@ -20,6 +21,24 @@ private class Games.CollectionIconView : Gtk.Stack {
                }
        }
 
+       private Developer? _filtering_developer;
+       public Developer? filtering_developer {
+               set {
+                       _filtering_developer = value;
+                       flow_box.invalidate_filter ();
+               }
+               get { return _filtering_developer; }
+       }
+
+       private Platform? _filtering_platform;
+       public Platform? filtering_platform {
+               set {
+                       _filtering_platform = value;
+                       flow_box.invalidate_filter ();
+               }
+               get { return _filtering_platform; }
+       }
+
        private ulong model_changed_id;
        private ListModel _model;
        public ListModel model {
@@ -315,12 +334,18 @@ private class Games.CollectionIconView : Gtk.Stack {
        }
 
        private bool filter_game (Game game) {
-               if (filtering_terms.length == 0)
-                       return true;
+               if (filtering_developer != null &&
+                   filtering_developer.get_developer() != game.get_developer().get_developer())
+                       return false;
 
-               foreach (var term in filtering_terms)
-                       if (!(term.casefold () in game.name.casefold ()))
-                               return false;
+               if (filtering_platform != null &&
+                   filtering_platform.get_name() != game.get_platform().get_name())
+                       return false;
+
+               if (filtering_terms.length != 0)
+                       foreach (var term in filtering_terms)
+                               if (!(term.casefold () in game.name.casefold ()))
+                                       return false;
 
                return true;
        }


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