Add PatternInhibit support
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sun, 20 Jun 2010 17:39:33 +0000 (19:39 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 10 Feb 2011 16:13:24 +0000 (17:13 +0100)
A high-priority inhibitor pattern should keep MCE from fiddling with the
LED controls while we do.

Makefile.am
debian/control
debian/led-pattern-editor.postinst
debian/led-pattern-editor.postrm
src/led-pattern-dialog.vala
src/led-program-dialog.vala

index 974c303..43eedda 100644 (file)
@@ -44,7 +44,8 @@ libled_pattern_editor_la_VALASOURCES = \
        src/mce-ini-parse.vala
 
 libled_pattern_editor_la_VALAFLAGS = --vapidir ./vapi \
-       --pkg config --pkg hildon-1 --pkg libosso
+       --disable-dbus-transformation \
+       --pkg config --pkg dbus-glib-1 --pkg hildon-1 --pkg libosso
 libled_pattern_editor_la_CFLAGS = ${HILDON_CFLAGS} \
        -DGETTEXT_PACKAGE=\"@GETTEXT_PACKAGE@\"
 libled_pattern_editor_la_LIBADD = ${HILDON_LIBS}
index 2149a79..3d9bf14 100644 (file)
@@ -9,7 +9,7 @@ XSBC-Bugtracker: https://bugs.maemo.org/enter_bug.cgi?product=LED%20Pattern
 
 Package: led-pattern-editor
 Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, osso-icons-default
+Depends: ${shlibs:Depends}, ${misc:Depends}, osso-icons-default, mceledpattern
 XB-Description: A control panel applet to edit notification LED blinking patterns
  Can graphically edit the blinking patterns and LED colors, preview the
  LED patterns and save the configuration and restart MCE to apply changes.
index af248e7..76cf5ca 100644 (file)
@@ -2,3 +2,7 @@
 update-sudoers
 [ -e /etc/mce/mce.ini.orig ] || cp /etc/mce/mce.ini /etc/mce/mce.ini.orig
 rm -f /home/user/.cache/launch/com.nokia.controlpanel.pvr
+grep PatternInhibit= /etc/mce/mce.ini > /dev/null || (
+       mceledpattern add PatternInhibit "0;5;0;r;9d8040007f007f0040ff7f007f000000;9d800000"
+       initctl stop mce; sleep 3; initctl start mce
+)
index aa6489f..b00dd3f 100644 (file)
@@ -1,3 +1,4 @@
 #!/bin/sh
 update-sudoers
 rm -f /home/user/.cache/launch/com.nokia.controlpanel.pvr
+mceledpattern remove PatternInhibit || true
index caf11a1..051c5f5 100644 (file)
@@ -38,6 +38,11 @@ class LedPatternDialog : Gtk.Dialog {
                var vbox = new Gtk.VBox (false, 0);
 
                foreach (LedPattern pattern in list) {
+                       // Skip PatternInhibit, which the LED Pattern Editor uses
+                       // internally to make MCE keep its hands off the LEDs.
+                       if (pattern.name == "PatternInhibit")
+                               continue;
+
                        var button = new LedPatternButton (pattern);
                        Hildon.gtk_widget_set_theme_size (button, Hildon.SizeType.FINGER_HEIGHT);
                        button.set_data ("pattern", pattern);
index 91840f3..601f43c 100644 (file)
  */
 
 class LedProgramDialog : Gtk.Dialog {
+       private const string MCE_SERVICE = "com.nokia.mce";
+       private const string MCE_REQUEST_IF = "com.nokia.mce.request";
+       private const string MCE_REQUEST_PATH = "/com/nokia/mce/request";
+
+       private enum ResponseType {
+               TEST = 1,
+               COPY = 2
+       }
+
        LedPatternView lpv;
        LedPatternRX51 pattern;
 
@@ -24,6 +33,10 @@ class LedProgramDialog : Gtk.Dialog {
        LedColorButton led_color2;
        Gtk.Widget list1;
        Gtk.Widget list2;
+       Gtk.ToggleButton test_button;
+
+       DBus.Connection bus;
+       dynamic DBus.Object mce;
 
        public LedProgramDialog (LedPatternRX51 _pattern) {
                pattern = _pattern;
@@ -73,14 +86,21 @@ class LedProgramDialog : Gtk.Dialog {
                add_action_widget (hbox, 2);
                action_area.set_child_secondary (hbox, true);
 
-               action_area.show_all ();
+               test_button = (Gtk.ToggleButton) Hildon.gtk_toggle_button_new (Hildon.SizeType.FINGER_HEIGHT);
+               test_button.set_label (_("Test"));
+               add_action_widget (test_button, ResponseType.TEST);
 
-               add_button (_("Copy"), 2);
-               add_button (_("Test"), 1);
+               add_button (_("Copy"), ResponseType.COPY);
                add_button (_("Done"), Gtk.ResponseType.ACCEPT);
 
+               action_area.show_all ();
+
+               test_button.toggled.connect (on_test_toggled);
                key_press_event.connect (on_key_pressed);
                response.connect (on_response);
+
+               bus = DBus.Bus.get (DBus.BusType.SYSTEM);
+               mce = bus.get_object (MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF);
        }
 
        private bool on_key_pressed (Gdk.EventKey event) {
@@ -123,14 +143,16 @@ class LedProgramDialog : Gtk.Dialog {
        }
 
        void on_response (int response) {
-               if (response == 1) {
-                       Timeout.add (200, delayed_spawn);
-               } else if (response == 2) {
+               if (response == ResponseType.COPY) {
                        copy ();
+                       return;
                } else if (response == Gtk.ResponseType.ACCEPT) {
                        if (pattern.dump () != lpv.pattern.dump ()) {
                                pattern.replace_with (lpv.pattern);
                        }
+                       test_button.set_active (false);
+               } else if (response == Gtk.ResponseType.CANCEL) {
+                       test_button.set_active (false);
                }
        }
 
@@ -158,6 +180,23 @@ class LedProgramDialog : Gtk.Dialog {
                }
        }
 
+       void on_test_toggled (Gtk.ToggleButton source) {
+               if (source.get_active ()) {
+                       try {
+                               mce.req_led_pattern_activate ("PatternError");
+                       } catch (DBus.Error e) {
+                               Hildon.Banner.show_information (null, null, e.message);
+                       }
+                       Timeout.add (200, delayed_spawn);
+               } else {
+                       try {
+                               mce.req_led_pattern_deactivate ("PatternError");
+                       } catch (DBus.Error e) {
+                               Hildon.Banner.show_information (null, null, e.message);
+                       }
+               }
+       }
+
        bool delayed_spawn () {
                try {
                        int exit_status;