From e76422cb1dd5bc8b0b818be549a8f158e6ed61a2 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Thu, 27 May 2010 20:49:45 +0200 Subject: [PATCH] Add a help button and a button to restore original patterns Fixes bugs #10255 and #10256. --- src/led-pattern-dialog.vala | 58 ++++++++++++++++++++++++++++++++++++++++--- src/led-pattern-editor.vala | 17 ++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/led-pattern-dialog.vala b/src/led-pattern-dialog.vala index 1f05a39..e5bbdea 100644 --- a/src/led-pattern-dialog.vala +++ b/src/led-pattern-dialog.vala @@ -17,10 +17,18 @@ */ class LedPatternDialog : Gtk.Dialog { - unowned List list; + public enum Response { + HELP = 1, + RESTORE = 2 + } + + private unowned Osso.Context osso_context; + private unowned List list; + private bool close = false; - public LedPatternDialog (List _list) { + public LedPatternDialog (List _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; + } + } } diff --git a/src/led-pattern-editor.vala b/src/led-pattern-editor.vala index a528c43..09e832d 100644 --- a/src/led-pattern-editor.vala +++ b/src/led-pattern-editor.vala @@ -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; -- 1.7.9.5