Add a help button and a button to restore original patterns
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 27 May 2010 18:49:45 +0000 (20:49 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 27 May 2010 18:55:31 +0000 (20:55 +0200)
Fixes bugs #10255 and #10256.

src/led-pattern-dialog.vala
src/led-pattern-editor.vala

index 1f05a39..e5bbdea 100644 (file)
  */
 
 class LedPatternDialog : Gtk.Dialog {
-       unowned List<LedPattern> list;
+       public enum Response {
+               HELP = 1,
+               RESTORE = 2
+       }
+
+       private unowned Osso.Context osso_context;
+       private unowned List<LedPattern> list;
+       private bool close = false;
 
-       public LedPatternDialog (List<LedPattern> _list) {
+       public LedPatternDialog (List<LedPattern> _list, Osso.Context osso) {
                list = _list;
+               osso_context = osso;
                set_title ("LED Patterns");
 
                var content = (Gtk.VBox) get_content_area ();
@@ -41,10 +49,39 @@ class LedPatternDialog : Gtk.Dialog {
                content.pack_start (pannable, true, true, 0);
                content.show_all ();
 
+               var button_help = new Gtk.Button.with_label ("Help");
+               Hildon.gtk_widget_set_theme_size (button_help, Hildon.SizeType.FINGER_HEIGHT);
+
+               var label = new Gtk.Label ("Restore original\npatterns");
+               label.justify = Gtk.Justification.CENTER;
+               var button_restore = new Gtk.Button ();
+               button_restore.add (label);
+               Hildon.helper_set_logical_font (button_restore, "SmallSystemFont");
+               Hildon.gtk_widget_set_theme_size (button_restore, Hildon.SizeType.FINGER_HEIGHT);
+
+               add_action_widget (button_help, Response.HELP);
+               add_action_widget (button_restore, Response.RESTORE);
+
+               var action_area = (Gtk.ButtonBox) get_action_area ();
+               action_area.set_child_secondary (button_help, true);
+               action_area.show_all ();
+
                add_button ("Save", Gtk.ResponseType.OK);
+
+               response.connect (on_response);
        }
 
-       void on_pattern_clicked (Gtk.Button button) {
+       public int run () {
+               int response = 0;
+               while (response >= 0) {
+                       response = base.run ();
+                       if (close)
+                               return response;
+               }
+               return response;
+       }
+
+       private void on_pattern_clicked (Gtk.Button button) {
                LedPattern pattern = button.get_data ("pattern");
                if (pattern is LedPatternRX51) {
                        var dialog = new LedProgramDialog ((LedPatternRX51) pattern);
@@ -56,4 +93,19 @@ class LedPatternDialog : Gtk.Dialog {
                        dialog.destroy ();
                }
        }
+
+       private void on_response (int response_id) {
+               if (response_id == Response.HELP) {
+                       var url = "http://wiki.maemo.org/LED_Pattern_Editor";
+                       var status = osso_context.rpc_run_with_defaults ("osso_browser", "open_new_window", null, 's', url, 'b', false);
+                       if (status != Osso.Status.OK)
+                               Hildon.Banner.show_information (this, null, "Failed to open browser.");
+               } else if (response_id == Response.RESTORE) {
+                       var note = new Hildon.Note.confirmation (this, "Restore original patterns? All user-created patterns will be lost.");
+                       response_id = note.run ();
+                       note.destroy ();
+                       if (response_id == Gtk.ResponseType.OK)
+                               close = true;
+               }
+       }
 }
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;