2 * vim:ts=4:sw=4:et:cindent:cino=(0
8 #include <hildon/hildon-picker-button.h>
9 #include <hildon/hildon-touch-selector.h>
11 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
12 #include "libmaemo-tweaks-section/maemo-tweaks-module.h"
15 #define MAEMO_TWEAKS_TYPE_MCE_SECTION \
16 (maemo_tweaks_mce_section_type)
17 #define MAEMO_TWEAKS_MCE_SECTION(obj) \
18 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
19 MAEMO_TWEAKS_TYPE_MCE_SECTION, \
20 MaemoTweaksMceSection))
21 #define MAEMO_TWEAKS_MCE_SECTION_CLASS(k) \
22 (G_TYPE_CHECK_CLASS_CAST((k), \
23 MAEMO_TWEAKS_TYPE_MCE_SECTION, \
24 MaemoTweaksMceSectionClass))
25 #define MAEMO_TWEAKS_IS_MCE_SECTION(obj) \
26 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
27 MAEMO_TWEAKS_TYPE_MCE_SECTION))
29 #define DISABLE_LABEL "Disable"
30 #define SHOW_MENU_LABEL "Show menu"
31 #define POWER_OFF_LABEL "Power off"
32 #define LOCK_LABEL "Lock"
35 SHORT_POWER_KEY_DISABLED,
42 LONG_POWER_KEY_DISABLED,
49 DOUBLE_POWER_KEY_DISABLED,
50 DOUBLE_POWER_KEY_MENU,
52 DOUBLE_POWER_KEY_LOCK,
57 typedef struct _picker_t
64 static picker_t spk [] = {
65 {SHORT_POWER_KEY_DISABLED, "disabled", DISABLE_LABEL},
66 {SHORT_POWER_KEY_MENU, "menu", SHOW_MENU_LABEL},
67 {SHORT_POWER_KEY_OFF, "poweroff", POWER_OFF_LABEL}
70 static picker_t lpk [] = {
71 {LONG_POWER_KEY_DISABLED, "disabled", DISABLE_LABEL},
72 {LONG_POWER_KEY_MENU, "menu", SHOW_MENU_LABEL},
73 {LONG_POWER_KEY_OFF, "poweroff", POWER_OFF_LABEL}
76 static picker_t dpk [] = {
77 {DOUBLE_POWER_KEY_DISABLED, "disabled", DISABLE_LABEL},
78 {DOUBLE_POWER_KEY_MENU, "menu", SHOW_MENU_LABEL},
79 {DOUBLE_POWER_KEY_OFF, "poweroff", POWER_OFF_LABEL},
80 {DOUBLE_POWER_KEY_LOCK, "tklock", LOCK_LABEL}
84 typedef struct _MaemoTweaksMceSection MaemoTweaksMceSection;
85 typedef struct _MaemoTweaksMceSectionClass
86 MaemoTweaksMceSectionClass;
88 struct _MaemoTweaksMceSection
90 MaemoTweaksSection parent_instance;
93 GtkWidget *short_power_key;
94 GtkWidget *long_power_key;
95 GtkWidget *double_power_key;
97 guint value_changed : 1;
100 struct _MaemoTweaksMceSectionClass
102 MaemoTweaksSectionClass parent_class;
106 static GType maemo_tweaks_mce_section_get_type (GTypeModule *module);
107 static void maemo_tweaks_mce_section_class_init
108 (MaemoTweaksMceSectionClass *class);
109 static void maemo_tweaks_mce_section_init
110 (MaemoTweaksMceSection *section);
111 static void maemo_tweaks_mce_section_dispose (GObject *obj);
113 static void _save (MaemoTweaksSection *section, gboolean *requires_restart);
115 static GType maemo_tweaks_mce_section_type = 0;
116 static MaemoTweaksSectionClass *
117 maemo_tweaks_mce_section_parent_class = NULL;
121 maemo_tweaks_module_load (MaemoTweaksModule *module)
123 maemo_tweaks_mce_section_get_type (G_TYPE_MODULE (module));
127 maemo_tweaks_module_unload (MaemoTweaksModule *module)
132 maemo_tweaks_mce_section_get_type (GTypeModule *module)
134 if (!maemo_tweaks_mce_section_type)
136 static const GTypeInfo section_info =
138 sizeof (MaemoTweaksMceSectionClass),
139 (GBaseInitFunc) NULL,
140 (GBaseFinalizeFunc) NULL,
141 (GClassInitFunc) maemo_tweaks_mce_section_class_init,
142 NULL, /* class_finalize */
143 NULL, /* class_data */
144 sizeof (MaemoTweaksMceSection),
146 (GInstanceInitFunc) maemo_tweaks_mce_section_init
149 maemo_tweaks_mce_section_type =
150 g_type_module_register_type (module, MAEMO_TWEAKS_TYPE_SECTION,
151 "MaemoTweaksMceSection",
155 return maemo_tweaks_mce_section_type;
159 maemo_tweaks_mce_section_class_init
160 (MaemoTweaksMceSectionClass *klass)
162 GObjectClass *object_class = G_OBJECT_CLASS (klass);
163 MaemoTweaksSectionClass *section_class =
164 MAEMO_TWEAKS_SECTION_CLASS (klass);
166 maemo_tweaks_mce_section_parent_class =
167 g_type_class_peek_parent (klass);
169 section_class->name = "_Mce";
170 section_class->save = _save;
172 object_class->dispose = maemo_tweaks_mce_section_dispose;
175 static void _value_changed (HildonPickerButton *b, gpointer user_data)
177 MaemoTweaksMceSection *section = MAEMO_TWEAKS_MCE_SECTION (user_data);
179 section->value_changed = TRUE;
182 GtkWidget * _build_short_power_key (MaemoTweaksMceSection *section)
185 GtkWidget *button, *selector;
187 selector = hildon_touch_selector_new_text ();
188 for (i = 0; i < SHORT_POWER_KEY_N; i++)
190 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
194 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
195 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
197 hildon_button_set_title (HILDON_BUTTON (button),
198 "Power key: short press");
199 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
200 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
201 HILDON_TOUCH_SELECTOR (selector));
203 g_signal_connect (G_OBJECT (button), "value-changed",
204 G_CALLBACK (_value_changed), section);
206 gtk_widget_show (button);
210 GtkWidget * _build_long_power_key (MaemoTweaksMceSection *section)
213 GtkWidget *button, *selector;
215 selector = hildon_touch_selector_new_text ();
216 for (i = 0; i < LONG_POWER_KEY_N; i++)
218 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
222 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
223 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
225 hildon_button_set_title (HILDON_BUTTON (button),
226 "Power key: long press");
227 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
228 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
229 HILDON_TOUCH_SELECTOR (selector));
231 g_signal_connect (G_OBJECT (button), "value-changed",
232 G_CALLBACK (_value_changed), section);
234 gtk_widget_show (button);
238 GtkWidget * _build_double_power_key (MaemoTweaksMceSection *section)
241 GtkWidget *button, *selector;
243 selector = hildon_touch_selector_new_text ();
244 for (i = 0; i < DOUBLE_POWER_KEY_N; i++)
246 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
250 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
251 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
253 hildon_button_set_title (HILDON_BUTTON (button),
254 "Power key: double press");
255 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
256 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
257 HILDON_TOUCH_SELECTOR (selector));
259 g_signal_connect (G_OBJECT (button), "value-changed",
260 G_CALLBACK (_value_changed), section);
262 gtk_widget_show (button);
268 maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section)
270 MaemoTweaksSection *iface;
271 gchar *short_power_key_value;
272 gchar *long_power_key_value;
273 gchar *double_power_key_value;
276 section->short_power_key = _build_short_power_key (section);
277 section->long_power_key = _build_long_power_key (section);
278 section->double_power_key = _build_double_power_key (section);
280 section->ini = g_key_file_new ();
282 if (!g_key_file_load_from_file (section->ini, MCE,
283 G_KEY_FILE_NONE, NULL))
285 g_warning ("%s: failed to load %s", G_STRFUNC, MCE);
289 short_power_key_value = g_key_file_get_string (section->ini, "PowerKey",
290 "PowerKeyShortAction",
292 long_power_key_value = g_key_file_get_string (section->ini, "PowerKey",
293 "PowerKeyLongAction",
295 double_power_key_value = g_key_file_get_string (section->ini, "PowerKey",
296 "PowerKeyDoubleAction",
299 for (i = 0; i < SHORT_POWER_KEY_N; i++)
301 if (g_strcmp0 (short_power_key_value, spk[i].value) == 0)
303 hildon_picker_button_set_active
304 (HILDON_PICKER_BUTTON (section->short_power_key), i);
308 for (i = 0; i < LONG_POWER_KEY_N; i++)
310 if (g_strcmp0 (long_power_key_value, lpk[i].value) == 0)
312 hildon_picker_button_set_active
313 (HILDON_PICKER_BUTTON (section->long_power_key), i);
317 for (i = 0; i < DOUBLE_POWER_KEY_N; i++)
319 if (g_strcmp0 (double_power_key_value, dpk[i].value) == 0)
321 hildon_picker_button_set_active
322 (HILDON_PICKER_BUTTON (section->double_power_key), i);
326 section->value_changed = FALSE;
328 iface = MAEMO_TWEAKS_SECTION (section);
329 iface->widget = gtk_vbox_new (FALSE, 0);
330 gtk_box_pack_start (GTK_BOX (iface->widget), section->short_power_key,
332 gtk_box_pack_start (GTK_BOX (iface->widget), section->long_power_key,
334 gtk_box_pack_start (GTK_BOX (iface->widget), section->double_power_key,
339 maemo_tweaks_mce_section_dispose (GObject *obj)
341 MaemoTweaksMceSection *section = MAEMO_TWEAKS_MCE_SECTION (obj);
344 g_key_file_free (section->ini);
348 G_OBJECT_CLASS (maemo_tweaks_mce_section_parent_class)->dispose
352 static void _save (MaemoTweaksSection *section, gboolean *requires_restart)
355 gint short_active, long_active, double_active;
358 if (!MAEMO_TWEAKS_MCE_SECTION (section)->value_changed)
361 *requires_restart = TRUE;
363 short_active = hildon_picker_button_get_active
364 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
365 (section)->short_power_key));
367 long_active = hildon_picker_button_get_active
368 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
369 (section)->long_power_key));
371 double_active = hildon_picker_button_get_active
372 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
373 (section)->double_power_key));
375 argv[0] = g_strdup ("/usr/bin/maemo-tweaks-mce-save");
376 argv[1] = g_strdup_printf ("%s", spk[short_active].value);
377 argv[2] = g_strdup_printf ("%s", lpk[long_active].value);
378 argv[3] = g_strdup_printf ("%s", dpk[double_active].value);
381 g_spawn_sync ("/home/user", argv, NULL,
382 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
383 NULL, NULL, NULL, NULL, NULL, NULL);
385 for (i = 0; i < (sizeof (argv) / sizeof (gchar *)) - 1; i++)