Add lens cover unlocks device option to mce.
[tweakr] / modules / tweakr-mce.c
index 34ce1a6..2450009 100644 (file)
@@ -8,6 +8,7 @@
 #include <hildon/hildon-picker-button.h>
 #include <hildon/hildon-touch-selector.h>
 #include <hildon/hildon-note.h>
+#include <hildon/hildon-check-button.h>
 
 #include "libtweakr-section/tweakr-section.h"
 #include "libtweakr-section/tweakr-module.h"
@@ -94,6 +95,7 @@ struct _TweakrMceSection
     GtkWidget *short_power_key;
     GtkWidget *long_power_key;
     GtkWidget *double_power_key;
+    GtkWidget *lens_cover;
 
     guint value_changed : 1;
 };
@@ -181,6 +183,13 @@ static void _value_changed (HildonPickerButton *b, gpointer user_data)
     section->value_changed = TRUE;
 }
 
+static void _lens_cover_changed (HildonCheckButton *b, gpointer user_data)
+{
+    TweakrMceSection *section = TWEAKR_MCE_SECTION (user_data);
+
+    section->value_changed = TRUE;
+}
+
 GtkWidget * _build_short_power_key (TweakrMceSection *section)
 {
     gint i;
@@ -268,6 +277,21 @@ GtkWidget * _build_double_power_key (TweakrMceSection *section)
     return button;
 }
 
+GtkWidget *_build_lens_cover (TweakrMceSection *section)
+{
+    GtkWidget *button;
+
+    button = hildon_check_button_new (HILDON_SIZE_AUTO);
+    hildon_gtk_widget_set_theme_size (button, HILDON_SIZE_FINGER_HEIGHT);
+    gtk_button_set_label (GTK_BUTTON (button),
+                          "Opening lens cover unlocks device");
+
+    g_signal_connect (G_OBJECT (button), "toggled",
+                      G_CALLBACK (_lens_cover_changed), section);
+
+    gtk_widget_show (button);
+    return button;
+}
 
 static void
 tweakr_mce_section_init (TweakrMceSection *section)
@@ -277,10 +301,12 @@ tweakr_mce_section_init (TweakrMceSection *section)
     gchar *long_power_key_value;
     gchar *double_power_key_value;
     gint i;
+    gboolean lens_cover_value;
 
     section->short_power_key = _build_short_power_key (section);
     section->long_power_key = _build_long_power_key (section);
     section->double_power_key = _build_double_power_key (section);
+    section->lens_cover = _build_lens_cover (section);
 
     section->ini = g_key_file_new ();
 
@@ -300,6 +326,8 @@ tweakr_mce_section_init (TweakrMceSection *section)
     double_power_key_value = g_key_file_get_string (section->ini, "PowerKey",
                                                     "PowerKeyDoubleAction",
                                                     NULL);
+    lens_cover_value = g_key_file_get_boolean (section->ini, "TKLock",
+                                                "LensCoverUnlock", NULL);
 
     for (i = 0; i < SHORT_POWER_KEY_N; i++)
     {
@@ -328,6 +356,9 @@ tweakr_mce_section_init (TweakrMceSection *section)
         }
     }
 
+    hildon_check_button_set_active
+        (HILDON_CHECK_BUTTON (section->lens_cover), lens_cover_value);
+
     section->value_changed = FALSE;
 
     iface = TWEAKR_SECTION (section);
@@ -339,6 +370,8 @@ tweakr_mce_section_init (TweakrMceSection *section)
                         FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX (iface->widget), section->double_power_key,
                         FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX (iface->widget), section->lens_cover,
+                        FALSE, FALSE, 0);
 }
 
 static void
@@ -358,9 +391,10 @@ tweakr_mce_section_dispose (GObject *obj)
 static gboolean _save (TweakrSection *section,
                        gboolean *requires_restart)
 {
-    gchar *argv[5];
+    gchar *argv[6];
     gint short_active, long_active, double_active;
     gint i;
+    gboolean lens_cover_value;
 
     if (!TWEAKR_MCE_SECTION (section)->value_changed)
         return TRUE;
@@ -377,6 +411,9 @@ static gboolean _save (TweakrSection *section,
         (HILDON_PICKER_BUTTON (TWEAKR_MCE_SECTION
                                (section)->double_power_key));
 
+    lens_cover_value = hildon_check_button_get_active
+        (HILDON_CHECK_BUTTON (TWEAKR_MCE_SECTION (section)->lens_cover));
+
     if (short_active  == SHORT_POWER_KEY_DISABLED &&
         long_active   == LONG_POWER_KEY_DISABLED  &&
         double_active == DOUBLE_POWER_KEY_DISABLED)
@@ -401,7 +438,8 @@ static gboolean _save (TweakrSection *section,
     argv[1] = g_strdup_printf ("%s", spk[short_active].value);
     argv[2] = g_strdup_printf ("%s", lpk[long_active].value);
     argv[3] = g_strdup_printf ("%s", dpk[double_active].value);
-    argv[4] = NULL;
+    argv[4] = g_strdup_printf ("%s", lens_cover_value);
+    argv[5] = NULL;
 
     g_spawn_sync ("/home/user", argv, NULL,
                   G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,