[gnome-games/wip/exalm/views: 7/19] application-window: Migrate to views



commit 310184e5d93ac2fdbdd1cb7bbfd694a7a6a4a074
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Oct 4 17:50:06 2018 +0500

    application-window: Migrate to views
    
    Use a CollectionView and DisplayView objects instead of separate box and
    header bar objects.

 data/ui/application-window.ui  |  35 ----------
 src/ui/application-window.vala | 144 ++++++++++++++++++++++-------------------
 2 files changed, 77 insertions(+), 102 deletions(-)
---
diff --git a/data/ui/application-window.ui b/data/ui/application-window.ui
index b134363a..98a05970 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -14,24 +14,6 @@
     <child>
       <object class="GtkStack" id="content_box">
         <property name="visible">True</property>
-        <child>
-          <object class="GamesCollectionBox" id="collection_box">
-            <property name="visible">True</property>
-            <signal name="game-activated" handler="on_game_activated"/>
-          </object>
-          <packing>
-            <property name="name">collection</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GamesDisplayBox" id="display_box">
-            <property name="visible">True</property>
-            <signal name="back" handler="on_display_back"/>
-          </object>
-          <packing>
-            <property name="name">display</property>
-          </packing>
-        </child>
       </object>
     </child>
     <child type="titlebar">
@@ -40,23 +22,6 @@
         <child>
           <object class="GtkStack" id="header_bar">
             <property name="visible">True</property>
-            <child>
-              <object class="GamesCollectionHeaderBar" id="collection_header_bar">
-                <property name="visible">True</property>
-              </object>
-              <packing>
-                <property name="name">collection</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GamesDisplayHeaderBar" id="display_header_bar">
-                <property name="visible">True</property>
-                <signal name="back" handler="on_display_back"/>
-              </object>
-              <packing>
-                <property name="name">display</property>
-              </packing>
-            </child>
           </object>
         </child>
       </object>
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 14a566a8..45c50e4d 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -7,6 +7,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        private const string CONTRIBUTE_URI = "https://wiki.gnome.org/Apps/Games/Contribute";;
 
+       public ListModel collection { get; construct set; }
+
        private UiState _ui_state;
        public UiState ui_state {
                get { return _ui_state; }
@@ -18,20 +20,26 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                        switch (ui_state) {
                        case UiState.COLLECTION:
-                               content_box.visible_child = collection_box;
-                               header_bar.visible_child = collection_header_bar;
+                               content_box.visible_child = collection_view.content_box;
+                               header_bar.visible_child = collection_view.title_bar;
+
+                               display_view.is_view_active = false;
+                               collection_view.is_view_active = true;
 
                                is_fullscreen = false;
 
-                               if (display_box.runner != null) {
-                                       display_box.runner.stop ();
-                                       display_box.runner = null;
+                               if (display_view.box.runner != null) {
+                                       display_view.box.runner.stop ();
+                                       display_view.box.runner = null;
                                }
 
                                break;
                        case UiState.DISPLAY:
-                               content_box.visible_child = display_box;
-                               header_bar.visible_child = display_header_bar;
+                               content_box.visible_child = display_view.content_box;
+                               header_bar.visible_child = display_view.title_bar;
+
+                               collection_view.is_view_active = false;
+                               display_view.is_view_active = true;
 
                                search_mode = false;
 
@@ -70,17 +78,11 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        [GtkChild]
        private Gtk.Stack content_box;
-       [GtkChild]
-       private CollectionBox collection_box;
-       [GtkChild]
-       private DisplayBox display_box;
-
        [GtkChild]
        private Gtk.Stack header_bar;
-       [GtkChild]
-       private CollectionHeaderBar collection_header_bar;
-       [GtkChild]
-       private DisplayHeaderBar display_header_bar;
+
+       private CollectionView collection_view;
+       private DisplayView display_view;
 
        private Settings settings;
 
@@ -108,16 +110,28 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private KonamiCode konami_code;
 
        public ApplicationWindow (Application application, ListModel collection) {
-               Object(application: application);
+               Object(application: application, collection: collection);
+       }
 
-               collection_box.collection = collection;
+       construct {
                collection.items_changed.connect (() => {
                        is_collection_empty = collection.get_n_items () == 0;
                });
                is_collection_empty = collection.get_n_items () == 0;
-       }
 
-       construct {
+               collection_view = new CollectionView (this, collection);
+               display_view = new DisplayView (this);
+
+               content_box.add (collection_view.content_box);
+               content_box.add (display_view.content_box);
+               header_bar.add (collection_view.title_bar);
+               header_bar.add (display_view.title_bar);
+
+               collection_view.game_activated.connect (on_game_activated);
+               display_view.back.connect (on_display_back);
+
+               ui_state = UiState.COLLECTION;
+
                settings = new Settings ("org.gnome.Games");
 
                int width, height;
@@ -132,28 +146,26 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                if (settings.get_boolean ("window-maximized"))
                        maximize ();
 
-               box_search_binding = bind_property ("search-mode", collection_box, "search-mode",
+               box_search_binding = bind_property ("search-mode", collection_view.box, "search-mode",
                                                    BindingFlags.BIDIRECTIONAL);
-               loading_notification_binding = bind_property ("loading-notification", collection_box, 
"loading-notification",
+               loading_notification_binding = bind_property ("loading-notification", collection_view.box, 
"loading-notification",
                                                              BindingFlags.DEFAULT);
-               header_bar_search_binding = bind_property ("search-mode", collection_header_bar, 
"search-mode",
+               header_bar_search_binding = bind_property ("search-mode", collection_view.header_bar, 
"search-mode",
                                                           BindingFlags.BIDIRECTIONAL);
 
-               box_fullscreen_binding = bind_property ("is-fullscreen", display_box, "is-fullscreen",
+               box_fullscreen_binding = bind_property ("is-fullscreen", display_view.box, "is-fullscreen",
                                                        BindingFlags.BIDIRECTIONAL);
-               header_bar_fullscreen_binding = bind_property ("is-fullscreen", display_header_bar, 
"is-fullscreen",
+               header_bar_fullscreen_binding = bind_property ("is-fullscreen", display_view.header_bar, 
"is-fullscreen",
                                                               BindingFlags.BIDIRECTIONAL);
 
-               box_empty_collection_binding = bind_property ("is-collection-empty", collection_box, 
"is-collection-empty",
+               box_empty_collection_binding = bind_property ("is-collection-empty", collection_view.box, 
"is-collection-empty",
                                                              BindingFlags.BIDIRECTIONAL);
-               header_bar_empty_collection_binding = bind_property ("is-collection-empty", 
collection_header_bar, "is-collection-empty",
+               header_bar_empty_collection_binding = bind_property ("is-collection-empty", 
collection_view.header_bar, "is-collection-empty",
                                                                     BindingFlags.BIDIRECTIONAL);
 
                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;
@@ -169,7 +181,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        public void run_game (Game game) {
                // If there is a game already running we have to quit it first
-               if (display_box.runner != null && !quit_game())
+               if (display_view.box.runner != null && !quit_game ())
                        return;
 
                if (run_game_cancellable != null)
@@ -280,7 +292,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool gamepad_button_press_event (Manette.Event event) {
                switch (ui_state) {
                case UiState.COLLECTION:
-                       return is_active && collection_box.gamepad_button_press_event (event);
+                       return is_active && collection_view.box.gamepad_button_press_event (event);
                case UiState.DISPLAY:
                        if (resume_dialog != null)
                                return resume_dialog.is_active && resume_dialog.gamepad_button_press_event 
(event);
@@ -314,7 +326,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool gamepad_button_release_event (Manette.Event event) {
                switch (ui_state) {
                case UiState.COLLECTION:
-                       return is_active && collection_box.gamepad_button_release_event (event);
+                       return is_active && collection_view.box.gamepad_button_release_event (event);
                default:
                        return false;
                }
@@ -323,18 +335,16 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool gamepad_absolute_axis_event (Manette.Event event) {
                switch (ui_state) {
                case UiState.COLLECTION:
-                       return is_active && collection_box.gamepad_absolute_axis_event (event);
+                       return is_active && collection_view.box.gamepad_absolute_axis_event (event);
                default:
                        return false;
                }
        }
 
-       [GtkCallback]
        private void on_game_activated (Game game) {
                run_game (game);
        }
 
-       [GtkCallback]
        private void on_display_back () {
                if (quit_game ())
                        ui_state = UiState.COLLECTION;
@@ -343,8 +353,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private void run_game_with_cancellable (Game game, Cancellable cancellable) {
-               display_header_bar.game_title = game.name;
-               display_box.header_bar.game_title = game.name;
+               display_view.header_bar.game_title = game.name;
+               display_view.box.header_bar.game_title = game.name;
                ui_state = UiState.DISPLAY;
 
                // Reset the UI parts depending on the runner to avoid an
@@ -355,12 +365,12 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                if (runner == null)
                        return;
 
-               display_header_bar.can_fullscreen = runner.can_fullscreen;
-               display_box.header_bar.can_fullscreen = runner.can_fullscreen;
-               display_header_bar.runner = runner;
-               display_box.runner = runner;
-               display_header_bar.media_set = runner.media_set;
-               display_box.header_bar.media_set = runner.media_set;
+               display_view.header_bar.can_fullscreen = runner.can_fullscreen;
+               display_view.box.header_bar.can_fullscreen = runner.can_fullscreen;
+               display_view.header_bar.runner = runner;
+               display_view.box.runner = runner;
+               display_view.header_bar.media_set = runner.media_set;
+               display_view.box.header_bar.media_set = runner.media_set;
 
                is_fullscreen = settings.get_boolean ("fullscreen") && runner.can_fullscreen;
 
@@ -389,14 +399,14 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                                return runner;
 
                        reset_display_page ();
-                       display_box.display_running_game_failed (game, error_message);
+                       display_view.box.display_running_game_failed (game, error_message);
 
                        return null;
                }
                catch (Error e) {
                        warning (e.message);
                        reset_display_page ();
-                       display_box.display_running_game_failed (game, _("An unexpected error occurred."));
+                       display_view.box.display_running_game_failed (game, _("An unexpected error 
occurred."));
 
                        return null;
                }
@@ -429,7 +439,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private bool try_run_with_cancellable (Runner runner, bool resume, Cancellable cancellable) {
                try {
                        if (resume)
-                               display_box.runner.resume ();
+                               display_view.box.runner.resume ();
                        else
                                runner.start ();
 
@@ -462,7 +472,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        response = Gtk.ResponseType.CANCEL;
 
                if (response == Gtk.ResponseType.CANCEL) {
-                       display_box.runner = null;
+                       display_view.box.runner = null;
                        ui_state = UiState.COLLECTION;
 
                        return;
@@ -477,13 +487,13 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        public bool quit_game_with_cancellable (Cancellable cancellable) {
-               if (display_box.runner == null)
+               if (display_view.box.runner == null)
                        return true;
 
-               display_box.runner.pause ();
+               display_view.box.runner.pause ();
 
-               if (display_box.runner.can_quit_safely) {
-                       display_box.runner.stop();
+               if (display_view.box.runner.can_quit_safely) {
+                       display_view.box.runner.stop ();
 
                        return true;
                }
@@ -518,9 +528,9 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private bool cancel_quitting_game () {
-               if (display_box.runner != null)
+               if (display_view.box.runner != null)
                        try {
-                               display_box.runner.resume ();
+                               display_view.box.runner.resume ();
                        }
                        catch (Error e) {
                                warning (e.message);
@@ -582,7 +592,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                if (is_active)
                        try {
-                               display_box.runner.resume ();
+                               display_view.box.runner.resume ();
                        }
                        catch (Error e) {
                                warning (e.message);
@@ -590,7 +600,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                else if (with_delay)
                        focus_out_timeout_id = Timeout.add (FOCUS_OUT_DELAY_MILLISECONDS, 
on_focus_out_delay_elapsed);
                else
-                       display_box.runner.pause ();
+                       display_view.box.runner.pause ();
        }
 
        private bool on_focus_out_delay_elapsed () {
@@ -600,7 +610,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        return false;
 
                if (!is_active)
-                       display_box.runner.pause ();
+                       display_view.box.runner.pause ();
 
                return false;
        }
@@ -609,7 +619,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                if (ui_state != UiState.DISPLAY)
                        return false;
 
-               if (display_box.runner == null)
+               if (display_view.box.runner == null)
                        return false;
 
                if (run_game_cancellable != null)
@@ -635,7 +645,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        return true;
                }
 
-               return collection_box.search_bar_handle_event (event);
+               return collection_view.box.search_bar_handle_event (event);
        }
 
        private bool handle_display_key_event (Gdk.EventKey event) {
@@ -646,21 +656,21 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                if ((event.keyval == Gdk.Key.f || event.keyval == Gdk.Key.F) &&
                    (event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK &&
-                   display_header_bar.can_fullscreen) {
+                   display_view.header_bar.can_fullscreen) {
                        is_fullscreen = !is_fullscreen;
                        settings.set_boolean ("fullscreen", is_fullscreen);
 
                        return true;
                }
 
-               if (event.keyval == Gdk.Key.F11 && display_header_bar.can_fullscreen) {
+               if (event.keyval == Gdk.Key.F11 && display_view.header_bar.can_fullscreen) {
                        is_fullscreen = !is_fullscreen;
                        settings.set_boolean ("fullscreen", is_fullscreen);
 
                        return true;
                }
 
-               if (event.keyval == Gdk.Key.Escape && display_header_bar.can_fullscreen) {
+               if (event.keyval == Gdk.Key.Escape && display_view.header_bar.can_fullscreen) {
                        is_fullscreen = false;
                        settings.set_boolean ("fullscreen", false);
 
@@ -710,12 +720,12 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private void reset_display_page () {
-               display_header_bar.can_fullscreen = false;
-               display_box.header_bar.can_fullscreen = false;
-               display_header_bar.runner = null;
-               display_box.runner = null;
-               display_header_bar.media_set = null;
-               display_box.header_bar.media_set = null;
+               display_view.header_bar.can_fullscreen = false;
+               display_view.box.header_bar.can_fullscreen = false;
+               display_view.header_bar.runner = null;
+               display_view.box.runner = null;
+               display_view.header_bar.media_set = null;
+               display_view.box.header_bar.media_set = null;
        }
 
        private void on_konami_code_performed () {


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