Use LED pattern helper to test LED patterns
authorPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 24 Feb 2010 17:19:35 +0000 (18:19 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 24 Feb 2010 18:10:24 +0000 (19:10 +0100)
src/led-program-dialog.vala

index bb7c4ff..2fec429 100644 (file)
@@ -36,10 +36,10 @@ class LedProgramDialog : Gtk.Dialog {
                var pannable = new Hildon.PannableArea ();
                var vbox = new Gtk.VBox (false, 0);
 
-               foreach (LedCommandRX51 command in lpv.pattern.engine1) {
-                       var label = new Gtk.Label ("0x%04x".printf (command.code));
+               foreach (LedCommand command in lpv.pattern.engine1) {
+                       var command_widget = new LedCommandWidget (command);
 
-                       vbox.pack_start (label, false, false, 0);
+                       vbox.pack_start (command_widget, false, false, 0);
                }
 
                pannable.add_with_viewport (vbox);
@@ -55,7 +55,8 @@ class LedProgramDialog : Gtk.Dialog {
 
        void on_response (int response) {
                if (response == 1) {
-                       // Test pattern
+                       Timeout.add (200, delayed_spawn);
+                       return;
                }
                if (response == Gtk.ResponseType.ACCEPT) {
                        if (pattern.dump () != lpv.pattern.dump ()) {
@@ -63,4 +64,22 @@ class LedProgramDialog : Gtk.Dialog {
                        }
                }
        }
+
+       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;
+       }
 }