/* This file is part of LED Pattern Editor. * * Copyright (C) 2010 Philipp Zabel * * LED Pattern Editor is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LED Pattern Editor is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LED Pattern Editor. If not, see . */ class LedProgramDialog : Gtk.Dialog { LedPatternView lpv; LedPatternRX51 pattern; public LedProgramDialog (LedPatternRX51 _pattern) { pattern = _pattern; set_title ("LED pattern editor - " + (pattern.name.has_prefix ("Pattern") ? pattern.name.offset (7) : pattern.name) + " pattern"); var content = (Gtk.VBox) get_content_area (); content.set_size_request (-1, 5*70); lpv = new LedPatternView (pattern.copy ()); lpv.set_size_request (-1, 70); content.pack_start (lpv, false, false, 0); var pannable = new Hildon.PannableArea (); var vbox = new Gtk.VBox (false, 0); foreach (LedCommand command in lpv.pattern.engine1) { var command_widget = new LedCommandWidget (command); vbox.pack_start (command_widget, false, false, 0); } pannable.add_with_viewport (vbox); content.pack_start (pannable, true, true, 0); content.show_all (); var led_color = new LedColorButton.with_map (lpv.pattern.led_map); led_color.clicked.connect (on_color_clicked); add_action_widget (led_color, 2); action_area.set_child_secondary (led_color, true); action_area.show_all (); add_button ("Test", 1); add_button ("Done", Gtk.ResponseType.ACCEPT); response.connect (on_response); } void on_response (int response) { if (response == 1) { Timeout.add (200, delayed_spawn); return; } if (response == Gtk.ResponseType.ACCEPT) { if (pattern.dump () != lpv.pattern.dump ()) { pattern.replace_with (lpv.pattern); } } } bool delayed_spawn () { try { int exit_status; string error; var command = "sudo /usr/bin/led-pattern-helper test \"" + lpv.pattern.dump () + "\""; 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); Hildon.Banner.show_information (null, null, information); } } catch (SpawnError e) { Hildon.Banner.show_information (null, null, e.message); } return false; } void on_color_clicked (Gtk.Button button) { var dialog = new LedColorDialog (); int response = dialog.run (); if (response > 0) { ((LedColorButton) button).set_color ((LedColor) response); switch ((LedColor) response) { case LedColor.R: lpv.pattern.led_map = "r"; break; case LedColor.G: lpv.pattern.led_map = "g"; break; case LedColor.B: lpv.pattern.led_map = "b"; break; case LedColor.RG: lpv.pattern.led_map = "rg"; break; case LedColor.RB: lpv.pattern.led_map = "rb"; break; case LedColor.GB: lpv.pattern.led_map = "gb"; break; case LedColor.RGB: lpv.pattern.led_map = "rgb"; break; } lpv.pattern.changed (); } dialog.destroy (); } }