From 53f99018655dddd9acaea39dafa4e4df84a82b0e Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Wed, 9 Dec 2009 08:26:18 +0200 Subject: [PATCH] Add the double power key press. --- modules/maemo-tweaks-mce-save.c | 8 +++- modules/maemo-tweaks-mce.c | 98 +++++++++++++++++++++++++++++++++------ 2 files changed, 90 insertions(+), 16 deletions(-) diff --git a/modules/maemo-tweaks-mce-save.c b/modules/maemo-tweaks-mce-save.c index dc28b49..608c2d8 100644 --- a/modules/maemo-tweaks-mce-save.c +++ b/modules/maemo-tweaks-mce-save.c @@ -17,13 +17,13 @@ typedef struct _value_t int main (int argc, char *argv[]) { GKeyFile *kf; - value_t v[2]; + value_t v[3]; gint i; GError *error = NULL; gchar *data; gsize size; - if (argc < 3) + if (argc < (sizeof (v) / sizeof (value_t)) + 1) { exit (EXIT_FAILURE); } @@ -36,6 +36,10 @@ int main (int argc, char *argv[]) v[1].name = "PowerKeyLongAction"; v[1].value = argv[2]; + v[2].group = "PowerKey"; + v[2].name = "PowerKeyDoubleAction"; + v[2].value = argv[3]; + kf = g_key_file_new (); if (!g_key_file_load_from_file (kf, FILENAME, G_KEY_FILE_KEEP_COMMENTS | diff --git a/modules/maemo-tweaks-mce.c b/modules/maemo-tweaks-mce.c index e7013b9..96c1e22 100644 --- a/modules/maemo-tweaks-mce.c +++ b/modules/maemo-tweaks-mce.c @@ -26,6 +26,11 @@ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ MAEMO_TWEAKS_TYPE_MCE_SECTION)) +#define DISABLE_LABEL "Disable" +#define SHOW_MENU_LABEL "Show menu" +#define POWER_OFF_LABEL "Power off" +#define LOCK_LABEL "Lock" + enum { SHORT_POWER_KEY_DISABLED, SHORT_POWER_KEY_MENU, @@ -40,6 +45,14 @@ enum { LONG_POWER_KEY_N }; +enum { + DOUBLE_POWER_KEY_DISABLED, + DOUBLE_POWER_KEY_MENU, + DOUBLE_POWER_KEY_OFF, + DOUBLE_POWER_KEY_LOCK, + DOUBLE_POWER_KEY_N +}; + typedef struct _picker_t { @@ -49,16 +62,23 @@ typedef struct _picker_t } picker_t; static picker_t spk [] = { - {SHORT_POWER_KEY_DISABLED, "disabled", "Disabled"}, - {SHORT_POWER_KEY_MENU, "menu", "Show menu"}, - {SHORT_POWER_KEY_OFF, "poweroff", "Power off"} + {SHORT_POWER_KEY_DISABLED, "disabled", DISABLE_LABEL}, + {SHORT_POWER_KEY_MENU, "menu", SHOW_MENU_LABEL}, + {SHORT_POWER_KEY_OFF, "poweroff", POWER_OFF_LABEL} }; static picker_t lpk [] = { - {SHORT_POWER_KEY_DISABLED, "disabled", "Disabled"}, - {SHORT_POWER_KEY_MENU, "menu", "Show menu"}, - {SHORT_POWER_KEY_OFF, "poweroff", "Power off"} -}; + {LONG_POWER_KEY_DISABLED, "disabled", DISABLE_LABEL}, + {LONG_POWER_KEY_MENU, "menu", SHOW_MENU_LABEL}, + {LONG_POWER_KEY_OFF, "poweroff", POWER_OFF_LABEL} +}; + +static picker_t dpk [] = { + {DOUBLE_POWER_KEY_DISABLED, "disabled", DISABLE_LABEL}, + {DOUBLE_POWER_KEY_MENU, "menu", SHOW_MENU_LABEL}, + {DOUBLE_POWER_KEY_OFF, "poweroff", POWER_OFF_LABEL}, + {DOUBLE_POWER_KEY_LOCK, "tklock", LOCK_LABEL} +}; typedef struct _MaemoTweaksMceSection MaemoTweaksMceSection; @@ -72,6 +92,7 @@ struct _MaemoTweaksMceSection GKeyFile *ini; GtkWidget *short_power_key; GtkWidget *long_power_key; + GtkWidget *double_power_key; guint value_changed : 1; }; @@ -214,16 +235,47 @@ GtkWidget * _build_long_power_key (MaemoTweaksMceSection *section) return button; } +GtkWidget * _build_double_power_key (MaemoTweaksMceSection *section) +{ + gint i; + GtkWidget *button, *selector; + + selector = hildon_touch_selector_new_text (); + for (i = 0; i < DOUBLE_POWER_KEY_N; i++) + { + hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), + dpk[i].label); + } + + button = hildon_picker_button_new (HILDON_SIZE_AUTO, + HILDON_BUTTON_ARRANGEMENT_VERTICAL); + + hildon_button_set_title (HILDON_BUTTON (button), + "Power key: double press"); + gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f); + hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button), + HILDON_TOUCH_SELECTOR (selector)); + + g_signal_connect (G_OBJECT (button), "value-changed", + G_CALLBACK (_value_changed), section); + + gtk_widget_show (button); + return button; +} + + static void maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section) { MaemoTweaksSection *iface; gchar *short_power_key_value; gchar *long_power_key_value; + gchar *double_power_key_value; gint i; 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->ini = g_key_file_new (); @@ -240,6 +292,9 @@ maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section) long_power_key_value = g_key_file_get_string (section->ini, "PowerKey", "PowerKeyLongAction", NULL); + double_power_key_value = g_key_file_get_string (section->ini, "PowerKey", + "PowerKeyDoubleAction", + NULL); for (i = 0; i < SHORT_POWER_KEY_N; i++) { @@ -259,6 +314,15 @@ maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section) } } + for (i = 0; i < DOUBLE_POWER_KEY_N; i++) + { + if (g_strcmp0 (double_power_key_value, dpk[i].value) == 0) + { + hildon_picker_button_set_active + (HILDON_PICKER_BUTTON (section->double_power_key), i); + } + } + section->value_changed = FALSE; iface = MAEMO_TWEAKS_SECTION (section); @@ -267,7 +331,8 @@ maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section) TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (iface->widget), section->long_power_key, TRUE, TRUE, 0); - + gtk_box_pack_start (GTK_BOX (iface->widget), section->double_power_key, + TRUE, TRUE, 0); } static void @@ -286,8 +351,9 @@ maemo_tweaks_mce_section_dispose (GObject *obj) static void _save (MaemoTweaksSection *section, gboolean *requires_restart) { - gchar *argv[4]; - gint short_active, long_active; + gchar *argv[5]; + gint short_active, long_active, double_active; + gint i; if (!MAEMO_TWEAKS_MCE_SECTION (section)->value_changed) return; @@ -302,17 +368,21 @@ static void _save (MaemoTweaksSection *section, gboolean *requires_restart) (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION (section)->long_power_key)); + double_active = hildon_picker_button_get_active + (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION + (section)->double_power_key)); + argv[0] = g_strdup ("/usr/bin/maemo-tweaks-mce-save"); argv[1] = g_strdup_printf ("%s", spk[short_active].value); argv[2] = g_strdup_printf ("%s", lpk[long_active].value); - argv[3] = NULL; + argv[3] = g_strdup_printf ("%s", dpk[double_active].value); + argv[4] = NULL; g_spawn_sync ("/home/user", argv, NULL, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, NULL, NULL); - g_free (argv[0]); - g_free (argv[1]); - g_free (argv[2]); + for (i = 0; i < (sizeof (argv) / sizeof (gchar *)) - 1; i++) + g_free (argv[i]); } -- 1.7.9.5