[gnome-games] ui: Add CollectionBox



commit 1ccf2a074e78f7f36d65c09b3bbe7658bd41613e
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Jul 24 12:22:35 2016 +0200

    ui: Add CollectionBox
    
    This will be used in a subsequent commit to replace ContentBox.
    
    This is needed to better distribute the concerns of the different parts
    of the UI.

 data/org.gnome.Games.gresource.xml |    1 +
 data/ui/collection-box.ui          |   53 +++++++++++++++++++++++++++++++
 src/Makefile.am                    |    1 +
 src/ui/collection-box.vala         |   61 ++++++++++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index aebe861..d48423e 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -5,6 +5,7 @@
     <file>gamepads/gamecontrollerdb.txt</file>
     <file preprocess="xml-stripblanks">gtk/menus.ui</file>
     <file preprocess="xml-stripblanks">ui/application-window.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/content-box.ui</file>
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
new file mode 100644
index 0000000..653f415
--- /dev/null
+++ b/data/ui/collection-box.ui
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GamesCollectionBox" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">0</property>
+    <property name="halign">fill</property>
+    <property name="valign">fill</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="can-focus">False</property>
+    <child>
+      <object class="GamesSearchBar" id="search_bar">
+        <property name="visible">True</property>
+        <signal name="notify::text" handler="on_search_text_notify"/>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkOverlay" id="overlay">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <child type="overlay">
+          <object class="GtkBox" id="info_box">
+            <property name="visible">True</property>
+            <property name="halign">center</property>
+            <property name="valign">start</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">False</property>
+            <property name="orientation">vertical</property>
+          </object>
+        </child>
+        <child>
+          <object class="GamesCollectionIconView" id="icon_view">
+            <property name="visible">True</property>
+            <signal name="game-activated" handler="on_game_activated"/>
+          </object>
+          <packing>
+            <property name="name">icon-view</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index f3fa6d1..8c614eb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -84,6 +84,7 @@ gnome_games_SOURCES = \
        \
        ui/application.vala \
        ui/application-window.vala \
+       ui/collection-box.vala \
        ui/collection-icon-view.vala \
        ui/collection-header-bar.vala \
        ui/content-box.vala \
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
new file mode 100644
index 0000000..c41d0d6
--- /dev/null
+++ b/src/ui/collection-box.vala
@@ -0,0 +1,61 @@
+// This file is part of GNOME Games. License: GPLv3
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/collection-box.ui")]
+private class Games.CollectionBox : Gtk.Box {
+       public signal void game_activated (Game game);
+
+       public ListModel collection { construct set; get; }
+       public bool search_mode { set; get; }
+
+       [GtkChild]
+       private SearchBar search_bar;
+       [GtkChild]
+       private Gtk.Box info_box;
+       [GtkChild]
+       private CollectionIconView icon_view;
+
+       private Binding collection_binding;
+       private Binding search_binding;
+
+       public CollectionBox (ListStore collection) {
+               Object (collection: collection);
+       }
+
+       construct {
+               collection_binding = bind_property ("collection", icon_view, "model",
+                                                   BindingFlags.BIDIRECTIONAL);
+               search_binding = bind_property ("search-mode", search_bar, "search-mode-enabled",
+                                               BindingFlags.BIDIRECTIONAL);
+       }
+
+       public void display_error (string message) {
+               var error = new ErrorInfoBar ();
+               error.message = message;
+               info_box.pack_start (error, false, false);
+
+               error.response.connect (on_info_bar_response);
+               error.close.connect (on_info_bar_close);
+       }
+
+       private void on_info_bar_response (Gtk.InfoBar info_bar, int response_id) {
+               info_box.remove (info_bar);
+       }
+
+       private void on_info_bar_close (Gtk.InfoBar info_bar) {
+               info_box.remove (info_bar);
+       }
+
+       [GtkCallback]
+       private void on_game_activated (Game game) {
+               game_activated (game);
+       }
+
+       [GtkCallback]
+       private void on_search_text_notify () {
+               icon_view.filtering_text = search_bar.text;
+       }
+
+       public bool search_bar_handle_event (Gdk.Event event) {
+               return search_bar.handle_event (event);
+       }
+}


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