[gnome-games/wip/abhinavsingh/gamepad-config] gamepad: Allow GamepadMapper to save/reset mappings



commit 757f144480b426689d041594dce3174afd7928c7
Author: theawless <theawless gmail com>
Date:   Wed Jun 21 05:51:13 2017 +0530

    gamepad: Allow GamepadMapper to save/reset mappings
    
    Add reset button to the GamepadMapper, and allow it to access
    GamepadMappingsManager to reset and save user mappings.

 data/ui/gamepad-mapper.ui  |   10 ++++++++++
 src/ui/gamepad-mapper.vala |   31 +++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/gamepad-mapper.ui b/data/ui/gamepad-mapper.ui
index 1628876..1332c3d 100644
--- a/data/ui/gamepad-mapper.ui
+++ b/data/ui/gamepad-mapper.ui
@@ -58,6 +58,16 @@
         <property name="pack-type">start</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkButton" id="reset_button">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Reset</property>
+        <signal name="clicked" handler="on_reset_clicked"/>
+      </object>
+      <packing>
+        <property name="pack-type">start</property>
+      </packing>
+    </child>
     <child type="center">
       <object class="GtkLabel" id="title">
         <property name="visible">True</property>
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index 6e8adb8..224c3fd 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -122,7 +122,7 @@ private class Games.GamepadMapper : Gtk.Box {
 
        [GtkCallback]
        private void on_apply_clicked () {
-               save_sdl_string ();
+               save_mapping ();
                back ();
        }
 
@@ -132,6 +132,12 @@ private class Games.GamepadMapper : Gtk.Box {
        }
 
        [GtkCallback]
+       private void on_reset_clicked () {
+               reset_mapping ();
+               back ();
+       }
+
+       [GtkCallback]
        private void on_back_clicked () {
                back ();
        }
@@ -227,9 +233,26 @@ private class Games.GamepadMapper : Gtk.Box {
                state = State.CONFIGURE;
        }
 
-       private void save_sdl_string () {
+       private void save_mapping () {
                var sdl_string = mapping_builder.build_sdl_string ();
-               message (sdl_string);
-               // TODO: Save using GamepadManager
+               save_sdl_string (sdl_string);
+       }
+
+       private void reset_mapping () {
+               var mappings_manager = GamepadMappingsManager.get_instance ();
+               var sdl_string =  mappings_manager.get_default_mapping (gamepad.guid);
+               save_sdl_string (sdl_string);
+       }
+
+       private void save_sdl_string (string sdl_string) {
+               var mappings_manager = GamepadMappingsManager.get_instance ();
+               try {
+                       var mapping = new GamepadMapping.from_sdl_string (sdl_string);
+                       mappings_manager.save_mapping (gamepad.guid, gamepad.name, sdl_string);
+                       gamepad.set_mapping (mapping);
+               }
+               catch (Error e) {
+                       debug (e.message);
+               }
        }
 }


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