Add a help button and a button to restore original patterns
[led-pattern-ed] / src / led-pattern-editor.vala
index a528c43..09e832d 100644 (file)
@@ -21,7 +21,7 @@ public static Osso.Status execute (Osso.Context osso, void* data, bool user_acti
 
        var list = mce_ini_parse ();
 
-       var dialog = new LedPatternDialog (list);
+       var dialog = new LedPatternDialog (list, osso);
        dialog.set_transient_for (window);
 
        int response = dialog.run ();
@@ -50,6 +50,21 @@ public static Osso.Status execute (Osso.Context osso, void* data, bool user_acti
                        note = new Hildon.Note.information (window, "The modified LED patterns are stored in /tmp/mce.ini. You have to manually copy this file to /etc/mce/mce.ini and restart MCE for the changes to take effect:\n\nmv /tmp/mce.ini /etc/mce/mce.ini\ninitctl stop mce; sleep 2; initctl start mce");
                        note.run ();
                }
+       } else if (response == LedPatternDialog.Response.RESTORE) {
+               Hildon.Banner.show_information (window, null, "Applying changes and restarting MCE ...");
+               try {
+                       int exit_status;
+                       string error;
+                       var command = "sudo /usr/bin/led-pattern-helper save /etc/mce/mce.ini.orig";
+                       Process.spawn_command_line_sync (command, null, out error, out exit_status);
+                       if (exit_status != 0) {
+                               var information = "Exit status: %d\n%s".printf (exit_status, error);
+                               var note = new Hildon.Note.information (window, information);
+                               note.run ();
+                       }
+               } catch (SpawnError e) {
+                       Hildon.Banner.show_information (null, null, e.message);
+               }
        }
 
        return Osso.Status.OK;