[gnome-games/wip/abhinavsingh/gamepad-config: 16/21] ui: Make gamepad list real time for gamepad prefs



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

    ui: Make gamepad list real time for gamepad prefs
    
    Update on 'gamepad-plugged' and 'gamepad-unplugged' signals from the
    GamepadMonitor.

 src/ui/preferences-page-gamepads.vala |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/src/ui/preferences-page-gamepads.vala b/src/ui/preferences-page-gamepads.vala
index fe5da53..582e9b1 100644
--- a/src/ui/preferences-page-gamepads.vala
+++ b/src/ui/preferences-page-gamepads.vala
@@ -8,9 +8,22 @@ private class Games.PreferencesPageGamepads: 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.PreferencesPageGamepads: 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]