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 add_button ("Test", 1);
51 add_button ("Done", Gtk.ResponseType.ACCEPT);
53 response.connect (on_response);
56 void on_response (int response) {
58 Timeout.add (200, delayed_spawn);
61 if (response == Gtk.ResponseType.ACCEPT) {
62 if (pattern.dump () != lpv.pattern.dump ()) {
63 pattern.replace_with (lpv.pattern);
68 bool delayed_spawn () {
72 var command = "sudo /usr/bin/led-pattern-helper test \"" +
73 lpv.pattern.dump () + "\"";
74 Process.spawn_command_line_sync (command, null, out error, out exit_status);
75 if (exit_status != 0) {
76 var information = "Exit status: %d\n%s".printf (exit_status, error);
77 Hildon.Banner.show_information (null, null, information);
79 } catch (SpawnError e) {
80 Hildon.Banner.show_information (null, null, e.message);