[gnome-games/wip/abhinavsingh/gamepad-config: 35/35] ui: Add preferences page for inputs



commit dcaac8a56a6e3e1fd5c0e6dd458bbff0a7d3dab7
Author: theawless <theawless gmail com>
Date:   Tue May 23 20:13:26 2017 +0530

    ui: Add preferences page for inputs
    
    This screen will allow the users to edit the settings related to inputs
    like gamepads and keyboard.

 data/Makefile.am                    |    1 +
 data/org.gnome.Games.gresource.xml  |    1 +
 data/ui/preferences-page-inputs.ui  |   67 ++++++++++++++++++++++++++
 data/ui/preferences-window.ui       |    9 ++++
 src/Makefile.am                     |    1 +
 src/ui/preferences-page-inputs.vala |   88 +++++++++++++++++++++++++++++++++++
 6 files changed, 167 insertions(+), 0 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 5f3d675..dd8eb44 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -41,6 +41,7 @@ EXTRA_DIST = \
        ui/game-icon-view.ui \
        ui/media-menu-button.ui \
        ui/media-selector.ui \
+       ui/preferences-page-inputs.ui \
        ui/preferences-page-plugins-item.ui \
        ui/preferences-page-plugins.ui \
        ui/preferences-page-video.ui \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 49a7af4..9e628d9 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -20,6 +20,7 @@
     <file preprocess="xml-stripblanks">ui/game-icon-view.ui</file>
     <file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
     <file preprocess="xml-stripblanks">ui/media-selector.ui</file>
+    <file preprocess="xml-stripblanks">ui/preferences-page-inputs.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-plugins.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-plugins-item.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-video.ui</file>
diff --git a/data/ui/preferences-page-inputs.ui b/data/ui/preferences-page-inputs.ui
new file mode 100644
index 0000000..6df11f0
--- /dev/null
+++ b/data/ui/preferences-page-inputs.ui
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GamesPreferencesPageInputs" parent="GtkStack">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="visible-child">main_stack_child_holder</property>
+    <property name="transition-type">GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT</property>
+    <child>
+      <object class="GtkBox" id="extra_stack_child_holder">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="name">extra_stack_child</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="main_stack_child_holder">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <child>
+          <object class="GtkViewport">
+            <property name="can_focus">False</property>
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkFrame">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="border_width">12</property>
+                <property name="valign">start</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="top_padding">12</property>
+                    <child>
+                      <object class="GtkListBox" id="gamepads_list_box">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="selection_mode">none</property>
+                        <signal name="row-activated" handler="gamepads_list_box_row_activated"/>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Gamepads</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="name">main_stack_child</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index 36026a6..2e54d0b 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -95,6 +95,15 @@
               </packing>
             </child>
             <child>
+              <object class="GamesPreferencesPageInputs" id="inputs_page">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="name">inputs</property>
+                <property name="title" translatable="yes">Inputs</property>
+              </packing>
+            </child>
+            <child>
               <object class="GamesPreferencesPagePlugins" id="plugins_page">
                 <property name="visible">True</property>
               </object>
diff --git a/src/Makefile.am b/src/Makefile.am
index d5772fa..158caad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -141,6 +141,7 @@ gnome_games_SOURCES = \
        ui/media-selector.vala \
        ui/media-menu-button.vala \
        ui/preferences-page.vala \
+       ui/preferences-page-inputs.vala \
        ui/preferences-page-plugins.vala \
        ui/preferences-page-plugins-item.vala \
        ui/preferences-page-video.vala \
diff --git a/src/ui/preferences-page-inputs.vala b/src/ui/preferences-page-inputs.vala
new file mode 100644
index 0000000..59b925a
--- /dev/null
+++ b/src/ui/preferences-page-inputs.vala
@@ -0,0 +1,88 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-inputs.ui")]
+private class Games.PreferencesPageInputs: Gtk.Stack, PreferencesPage {
+       private Gtk.Widget? _custom_title;
+       public Gtk.Widget? custom_title {
+               get { return _custom_title; }
+               protected set { _custom_title = value; }
+       }
+       
+       public string? subtitle {
+               get { return null; }
+               protected set {}
+       }
+
+       private string? _title;
+       public string? title {
+               get { return _title; }
+               protected set { _title = value; }
+       }
+
+       [GtkChild]
+       private Gtk.ListBox gamepads_list_box;
+       [GtkChild]
+       private Gtk.Box extra_stack_child_holder;
+       private GamepadMonitor gamepad_monitor;
+       private Gtk.Label default_label;
+
+       construct {
+               title = _("Inputs");
+               gamepad_monitor = GamepadMonitor.get_instance ();
+
+               gamepad_monitor.gamepad_unplugged.connect (rebuild_gamepad_list);
+               gamepad_monitor.gamepad_plugged.connect (rebuild_gamepad_list);
+               build_gamepad_list ();
+       }
+
+       public void visible_page_changed () {
+               on_mapper_back ();
+       }
+
+       private void rebuild_gamepad_list () {
+               clear_gamepad_list ();
+               build_gamepad_list ();
+       }
+
+       private void build_gamepad_list () {
+               var i = 0;
+               gamepad_monitor.foreach_gamepad ((gamepad) => {
+                       i += 1;
+                       var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+                       box.pack_start (new Gtk.Label (gamepad.name), false, false);
+                       box.margin = 6;
+                       box.show_all ();
+                       gamepads_list_box.add (box);
+               });
+       }
+
+       private void clear_gamepad_list () {
+               gamepads_list_box.foreach ((child) => child.destroy ());
+       }
+
+       [GtkCallback]
+       private void gamepads_list_box_row_activated (Gtk.ListBoxRow row_item) {
+               Gamepad? gamepad = null;
+               var i = 0;
+               var row_index = row_item.get_index ();
+               gamepad_monitor.foreach_gamepad ((gamepad_) => {
+                       if (i++ == row_index)
+                               gamepad = gamepad_;
+               });
+
+               if (gamepad == null)
+                       return;
+               var mapper = new GamepadMapper(gamepad);
+               mapper.back.connect (on_mapper_back);
+               custom_title = mapper.header_content;
+               extra_stack_child_holder.pack_start (mapper);
+               set_visible_child_name ("extra_stack_child");
+               mapper.start ();
+       }
+
+       private void on_mapper_back () {
+               custom_title = null;
+               set_visible_child_name ("main_stack_child");
+               extra_stack_child_holder.foreach ((child) => child.destroy ());
+       }
+}


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