1 /* This file is part of LED Pattern Editor.
3 * Copyright (C) 2010 Philipp Zabel
5 * LED Pattern Editor is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * LED Pattern Editor is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with LED Pattern Editor. If not, see <http://www.gnu.org/licenses/>.
19 class LedPatternDialog : Gtk.Dialog {
20 public enum Response {
25 private unowned Osso.Context osso_context;
26 private unowned List<LedPattern> list;
27 private bool close = false;
29 public LedPatternDialog (List<LedPattern> _list, Osso.Context osso) {
32 set_title (_("LED Patterns"));
34 var content = (Gtk.VBox) get_content_area ();
35 content.set_size_request (-1, 5*70);
37 var pannable = new Hildon.PannableArea ();
38 var vbox = new Gtk.VBox (false, 0);
40 foreach (LedPattern pattern in list) {
41 // Skip PatternInhibit, which the LED Pattern Editor uses
42 // internally to make MCE keep its hands off the LEDs.
43 if (pattern.name == "PatternInhibit")
46 var button = new LedPatternButton (pattern);
47 Hildon.gtk_widget_set_theme_size (button, Hildon.SizeType.FINGER_HEIGHT);
48 button.set_data ("pattern", pattern);
49 button.clicked.connect (on_pattern_clicked);
50 vbox.pack_start (button, true, true, 0);
53 pannable.add_with_viewport (vbox);
54 content.pack_start (pannable, true, true, 0);
57 var button_help = new Gtk.Button.with_label (_("Help"));
58 Hildon.gtk_widget_set_theme_size (button_help, Hildon.SizeType.FINGER_HEIGHT);
60 var label = new Gtk.Label (_("Restore original\npatterns"));
61 label.justify = Gtk.Justification.CENTER;
62 var button_restore = new Gtk.Button ();
63 button_restore.add (label);
64 Hildon.helper_set_logical_font (button_restore, "SmallSystemFont");
65 Hildon.gtk_widget_set_theme_size (button_restore, Hildon.SizeType.FINGER_HEIGHT);
67 add_action_widget (button_help, Response.HELP);
68 add_action_widget (button_restore, Response.RESTORE);
70 var action_area = (Gtk.ButtonBox) get_action_area ();
71 action_area.set_child_secondary (button_help, true);
72 action_area.show_all ();
74 add_button (_("Save"), Gtk.ResponseType.OK);
76 response.connect (on_response);
81 while (response >= 0) {
82 response = base.run ();
89 private void on_pattern_clicked (Gtk.Button button) {
90 LedPattern pattern = button.get_data ("pattern");
91 if (pattern is LedPatternRX51) {
92 var dialog = new LedProgramDialog ((LedPatternRX51) pattern);
93 dialog.set_transient_for (this);
97 response = dialog.run ();
102 private void on_response (int response_id) {
103 if (response_id == Response.HELP) {
104 var url = "http://wiki.maemo.org/LED_Pattern_Editor";
105 var status = osso_context.rpc_run_with_defaults ("osso_browser", "open_new_window", null, 's', url, 'b', false);
106 if (status != Osso.Status.OK)
107 Hildon.Banner.show_information (this, null, _("Failed to open browser."));
108 } else if (response_id == Response.RESTORE) {
109 var note = new Hildon.Note.confirmation (this, _("Restore original patterns? All user-created patterns will be lost."));
110 response_id = note.run ();
112 if (response_id == Gtk.ResponseType.OK)