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 var button = new LedPatternButton (pattern);
42 Hildon.gtk_widget_set_theme_size (button, Hildon.SizeType.FINGER_HEIGHT);
43 button.set_data ("pattern", pattern);
44 button.clicked.connect (on_pattern_clicked);
45 vbox.pack_start (button, true, true, 0);
48 pannable.add_with_viewport (vbox);
49 content.pack_start (pannable, true, true, 0);
52 var button_help = new Gtk.Button.with_label ("Help");
53 Hildon.gtk_widget_set_theme_size (button_help, Hildon.SizeType.FINGER_HEIGHT);
55 var label = new Gtk.Label (_("Restore original\npatterns"));
56 label.justify = Gtk.Justification.CENTER;
57 var button_restore = new Gtk.Button ();
58 button_restore.add (label);
59 Hildon.helper_set_logical_font (button_restore, "SmallSystemFont");
60 Hildon.gtk_widget_set_theme_size (button_restore, Hildon.SizeType.FINGER_HEIGHT);
62 add_action_widget (button_help, Response.HELP);
63 add_action_widget (button_restore, Response.RESTORE);
65 var action_area = (Gtk.ButtonBox) get_action_area ();
66 action_area.set_child_secondary (button_help, true);
67 action_area.show_all ();
69 add_button (_("Save"), Gtk.ResponseType.OK);
71 response.connect (on_response);
76 while (response >= 0) {
77 response = base.run ();
84 private void on_pattern_clicked (Gtk.Button button) {
85 LedPattern pattern = button.get_data ("pattern");
86 if (pattern is LedPatternRX51) {
87 var dialog = new LedProgramDialog ((LedPatternRX51) pattern);
88 dialog.set_transient_for (this);
92 response = dialog.run ();
97 private void on_response (int response_id) {
98 if (response_id == Response.HELP) {
99 var url = "http://wiki.maemo.org/LED_Pattern_Editor";
100 var status = osso_context.rpc_run_with_defaults ("osso_browser", "open_new_window", null, 's', url, 'b', false);
101 if (status != Osso.Status.OK)
102 Hildon.Banner.show_information (this, null, _("Failed to open browser."));
103 } else if (response_id == Response.RESTORE) {
104 var note = new Hildon.Note.confirmation (this, _("Restore original patterns? All user-created patterns will be lost."));
105 response_id = note.run ();
107 if (response_id == Gtk.ResponseType.OK)