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 LedProgramDialog : Gtk.Dialog {
21 LedPatternRX51 pattern;
23 public LedProgramDialog (LedPatternRX51 _pattern) {
25 set_title ("LED pattern editor - " +
26 (pattern.name.has_prefix ("Pattern") ?
27 pattern.name.offset (7) : pattern.name) + " pattern");
29 var content = (Gtk.VBox) get_content_area ();
30 content.set_size_request (-1, 5*70);
32 lpv = new LedPatternView (pattern.copy ());
33 lpv.set_size_request (-1, 70);
34 content.pack_start (lpv, false, false, 0);
36 var pannable = new Hildon.PannableArea ();
37 var vbox = new Gtk.VBox (false, 0);
39 foreach (LedCommand command in lpv.pattern.engine1) {
40 var command_widget = new LedCommandWidget (command);
42 vbox.pack_start (command_widget, false, false, 0);
45 pannable.add_with_viewport (vbox);
46 content.pack_start (pannable, true, true, 0);
50 var led_color = new LedColorButton.with_map (lpv.pattern.led_map);
51 led_color.clicked.connect (on_color_clicked);
52 add_action_widget (led_color, 2);
53 action_area.set_child_secondary (led_color, true);
55 action_area.show_all ();
57 add_button ("Test", 1);
58 add_button ("Done", Gtk.ResponseType.ACCEPT);
60 response.connect (on_response);
63 void on_response (int response) {
65 Timeout.add (200, delayed_spawn);
68 if (response == Gtk.ResponseType.ACCEPT) {
69 if (pattern.dump () != lpv.pattern.dump ()) {
70 pattern.replace_with (lpv.pattern);
75 bool delayed_spawn () {
79 var command = "sudo /usr/bin/led-pattern-helper test \"" +
80 lpv.pattern.dump () + "\"";
81 Process.spawn_command_line_sync (command, null, out error, out exit_status);
82 if (exit_status != 0) {
83 var information = "Exit status: %d\n%s".printf (exit_status, error);
84 Hildon.Banner.show_information (null, null, information);
86 } catch (SpawnError e) {
87 Hildon.Banner.show_information (null, null, e.message);
93 void on_color_clicked (Gtk.Button button) {
94 var dialog = new LedColorDialog ();
95 int response = dialog.run ();
97 ((LedColorButton) button).set_color ((LedColor) response);
98 switch ((LedColor) response) {
100 lpv.pattern.led_map = "r";
103 lpv.pattern.led_map = "g";
106 lpv.pattern.led_map = "b";
109 lpv.pattern.led_map = "rg";
112 lpv.pattern.led_map = "rb";
115 lpv.pattern.led_map = "gb";
118 lpv.pattern.led_map = "rgb";
121 lpv.pattern.changed ();