[gnome-games/wip/abhinavsingh/gamepad-config: 6/25] ui: Allow real time gamepad list for gamepad pref



commit ab21886240d55edcd2bb97d7998da8a6e2b88ef7
Author: theawless <theawless gmail com>
Date:   Wed May 24 09:34:52 2017 +0530

    ui: Allow real time gamepad list for gamepad pref
    
    Update the list on 'gamepad-plugged' and 'gamepad-unplugged' signals from the
    GamepadMonitor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780754

 src/ui/preferences-page-input.vala |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/src/ui/preferences-page-input.vala b/src/ui/preferences-page-input.vala
index a64be1b..9f345ad 100644
--- a/src/ui/preferences-page-input.vala
+++ b/src/ui/preferences-page-input.vala
@@ -8,9 +8,22 @@ private class Games.PreferencesPageInput: Gtk.Bin, PreferencesPage {
 
        [GtkChild]
        private Gtk.ListBox gamepads_list_box;
+       private GamepadMonitor gamepad_monitor;
 
        construct {
-               var gamepad_monitor = GamepadMonitor.get_instance ();
+               gamepad_monitor = GamepadMonitor.get_instance ();
+
+               gamepad_monitor.gamepad_unplugged.connect (rebuild_gamepad_list);
+               gamepad_monitor.gamepad_plugged.connect (rebuild_gamepad_list);
+               build_gamepad_list ();
+       }
+
+       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;
@@ -23,6 +36,10 @@ private class Games.PreferencesPageInput: Gtk.Bin, PreferencesPage {
                });
        }
 
+       private void clear_gamepad_list () {
+               gamepads_list_box.foreach ((child) => child.destroy ());
+       }
+
        [GtkCallback]
        private void gamepads_list_box_row_activated (Gtk.ListBoxRow row_item) {
                // open the gamepad configurer here


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