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))
30 SHORT_POWER_KEY_DISABLED,
36 typedef struct _picker_t
43 static picker_t spk [] = {
44 {SHORT_POWER_KEY_DISABLED, "disabled", "Disabled"},
45 {SHORT_POWER_KEY_MENU, "menu", "Show menu"},
46 {SHORT_POWER_KEY_OFF, "poweroff", "Power off"}
49 typedef struct _MaemoTweaksMceSection MaemoTweaksMceSection;
50 typedef struct _MaemoTweaksMceSectionClass
51 MaemoTweaksMceSectionClass;
53 struct _MaemoTweaksMceSection
55 MaemoTweaksSection parent_instance;
58 GtkWidget *short_power_key;
61 struct _MaemoTweaksMceSectionClass
63 MaemoTweaksSectionClass parent_class;
67 static GType maemo_tweaks_mce_section_get_type (GTypeModule *module);
68 static void maemo_tweaks_mce_section_class_init
69 (MaemoTweaksMceSectionClass *class);
70 static void maemo_tweaks_mce_section_init
71 (MaemoTweaksMceSection *section);
72 static void maemo_tweaks_mce_section_dispose (GObject *obj);
74 static void _save (MaemoTweaksSection *section);
76 static GType maemo_tweaks_mce_section_type = 0;
77 static MaemoTweaksSectionClass *
78 maemo_tweaks_mce_section_parent_class = NULL;
82 maemo_tweaks_module_load (MaemoTweaksModule *module)
84 maemo_tweaks_mce_section_get_type (G_TYPE_MODULE (module));
88 maemo_tweaks_module_unload (MaemoTweaksModule *module)
93 maemo_tweaks_mce_section_get_type (GTypeModule *module)
95 if (!maemo_tweaks_mce_section_type)
97 static const GTypeInfo section_info =
99 sizeof (MaemoTweaksMceSectionClass),
100 (GBaseInitFunc) NULL,
101 (GBaseFinalizeFunc) NULL,
102 (GClassInitFunc) maemo_tweaks_mce_section_class_init,
103 NULL, /* class_finalize */
104 NULL, /* class_data */
105 sizeof (MaemoTweaksMceSection),
107 (GInstanceInitFunc) maemo_tweaks_mce_section_init
110 maemo_tweaks_mce_section_type =
111 g_type_module_register_type (module, MAEMO_TWEAKS_TYPE_SECTION,
112 "MaemoTweaksMceSection",
116 return maemo_tweaks_mce_section_type;
120 maemo_tweaks_mce_section_class_init
121 (MaemoTweaksMceSectionClass *klass)
123 GObjectClass *object_class = G_OBJECT_CLASS (klass);
124 MaemoTweaksSectionClass *section_class =
125 MAEMO_TWEAKS_SECTION_CLASS (klass);
127 maemo_tweaks_mce_section_parent_class =
128 g_type_class_peek_parent (klass);
130 section_class->name = "_Mce";
131 section_class->save = _save;
133 object_class->dispose = maemo_tweaks_mce_section_dispose;
136 GtkWidget * _build_short_power_key (void)
139 GtkWidget *button, *selector;
141 selector = hildon_touch_selector_new_text ();
142 for (i = 0; i < SHORT_POWER_KEY_N; i++)
144 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
148 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
149 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
151 hildon_button_set_title (HILDON_BUTTON (button),
152 "Power button short press");
153 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
154 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
155 HILDON_TOUCH_SELECTOR (selector));
157 gtk_widget_show (button);
162 maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section)
164 MaemoTweaksSection *iface;
165 gchar *short_power_key_value;
168 section->short_power_key = _build_short_power_key ();
170 section->ini = g_key_file_new ();
172 if (!g_key_file_load_from_file (section->ini, MCE,
173 G_KEY_FILE_NONE, NULL))
175 g_warning ("%s: failed to load %s", G_STRFUNC, MCE);
179 short_power_key_value = g_key_file_get_string (section->ini, "PowerKey",
180 "PowerKeyShortAction",
183 for (i = 0; i < SHORT_POWER_KEY_N; i++)
185 if (g_strcmp0 (short_power_key_value, spk[i].value) == 0)
187 hildon_picker_button_set_active
188 (HILDON_PICKER_BUTTON (section->short_power_key), i);
193 iface = MAEMO_TWEAKS_SECTION (section);
194 iface->widget = gtk_vbox_new (FALSE, 0);
195 gtk_box_pack_start (GTK_BOX (iface->widget), section->short_power_key,
200 maemo_tweaks_mce_section_dispose (GObject *obj)
202 MaemoTweaksMceSection *section = MAEMO_TWEAKS_MCE_SECTION (obj);
205 g_key_file_free (section->ini);
209 G_OBJECT_CLASS (maemo_tweaks_mce_section_parent_class)->dispose
214 static void _save (MaemoTweaksSection *section)
219 active = hildon_picker_button_get_active
220 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
221 (section)->short_power_key));
223 argv[0] = g_strdup ("/usr/bin/maemo-tweaks-mce-save");
224 argv[1] = g_strdup_printf ("%s", spk[active].value);
227 g_spawn_sync ("/home/user", argv, NULL,
228 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
229 NULL, NULL, NULL, NULL, NULL, NULL);