--- /dev/null
+/*
+ * vim:ts=4:sw=4:et:cindent:cino=(0
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <hildon/hildon-picker-button.h>
+#include <hildon/hildon-touch-selector.h>
+
+#include "libmaemo-tweaks-section/maemo-tweaks-section.h"
+#include "libmaemo-tweaks-section/maemo-tweaks-module.h"
+
+
+#define MAEMO_TWEAKS_TYPE_MCE_SECTION \
+ (maemo_tweaks_mce_section_type)
+#define MAEMO_TWEAKS_MCE_SECTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ MAEMO_TWEAKS_TYPE_MCE_SECTION, \
+ MaemoTweaksMceSection))
+#define MAEMO_TWEAKS_MCE_SECTION_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_CAST((k), \
+ MAEMO_TWEAKS_TYPE_MCE_SECTION, \
+ MaemoTweaksMceSectionClass))
+#define MAEMO_TWEAKS_IS_MCE_SECTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ MAEMO_TWEAKS_TYPE_MCE_SECTION))
+
+enum {
+ SHORT_POWER_KEY_DISABLED,
+ SHORT_POWER_KEY_MENU,
+ SHORT_POWER_KEY_OFF,
+ SHORT_POWER_KEY_N
+};
+
+typedef struct _picker_t
+{
+ guint index;
+ const gchar *value;
+ const gchar *label;
+} 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"}
+};
+
+typedef struct _MaemoTweaksMceSection MaemoTweaksMceSection;
+typedef struct _MaemoTweaksMceSectionClass
+ MaemoTweaksMceSectionClass;
+
+struct _MaemoTweaksMceSection
+{
+ MaemoTweaksSection parent_instance;
+
+ GKeyFile *ini;
+ GtkWidget *short_power_key;
+};
+
+struct _MaemoTweaksMceSectionClass
+{
+ MaemoTweaksSectionClass parent_class;
+};
+
+
+static GType maemo_tweaks_mce_section_get_type (GTypeModule *module);
+static void maemo_tweaks_mce_section_class_init
+ (MaemoTweaksMceSectionClass *class);
+static void maemo_tweaks_mce_section_init
+ (MaemoTweaksMceSection *section);
+static void maemo_tweaks_mce_section_dispose (GObject *obj);
+
+static void _save (MaemoTweaksSection *section);
+
+static GType maemo_tweaks_mce_section_type = 0;
+static MaemoTweaksSectionClass *
+ maemo_tweaks_mce_section_parent_class = NULL;
+
+
+G_MODULE_EXPORT void
+maemo_tweaks_module_load (MaemoTweaksModule *module)
+{
+ maemo_tweaks_mce_section_get_type (G_TYPE_MODULE (module));
+}
+
+G_MODULE_EXPORT void
+maemo_tweaks_module_unload (MaemoTweaksModule *module)
+{
+}
+
+static GType
+maemo_tweaks_mce_section_get_type (GTypeModule *module)
+{
+ if (!maemo_tweaks_mce_section_type)
+ {
+ static const GTypeInfo section_info =
+ {
+ sizeof (MaemoTweaksMceSectionClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) maemo_tweaks_mce_section_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (MaemoTweaksMceSection),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) maemo_tweaks_mce_section_init
+ };
+
+ maemo_tweaks_mce_section_type =
+ g_type_module_register_type (module, MAEMO_TWEAKS_TYPE_SECTION,
+ "MaemoTweaksMceSection",
+ §ion_info, 0);
+ }
+
+ return maemo_tweaks_mce_section_type;
+}
+
+static void
+maemo_tweaks_mce_section_class_init
+ (MaemoTweaksMceSectionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MaemoTweaksSectionClass *section_class =
+ MAEMO_TWEAKS_SECTION_CLASS (klass);
+
+ maemo_tweaks_mce_section_parent_class =
+ g_type_class_peek_parent (klass);
+
+ section_class->name = "_Mce";
+ section_class->save = _save;
+
+ object_class->dispose = maemo_tweaks_mce_section_dispose;
+}
+
+GtkWidget * _build_short_power_key (void)
+{
+ gint i;
+ GtkWidget *button, *selector;
+
+ selector = hildon_touch_selector_new_text ();
+ for (i = 0; i < SHORT_POWER_KEY_N; i++)
+ {
+ hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
+ spk[i].label);
+ }
+
+ button = hildon_picker_button_new (HILDON_SIZE_AUTO,
+ HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+
+ hildon_button_set_title (HILDON_BUTTON (button),
+ "Power button short 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));
+
+ gtk_widget_show (button);
+ return button;
+}
+
+static void
+maemo_tweaks_mce_section_init (MaemoTweaksMceSection *section)
+{
+ MaemoTweaksSection *iface;
+ gchar *short_power_key_value;
+ gint i;
+
+ section->short_power_key = _build_short_power_key ();
+
+ section->ini = g_key_file_new ();
+
+ if (!g_key_file_load_from_file (section->ini, MCE,
+ G_KEY_FILE_NONE, NULL))
+ {
+ g_warning ("%s: failed to load %s", G_STRFUNC, MCE);
+ return;
+ }
+
+ short_power_key_value = g_key_file_get_string (section->ini, "PowerKey",
+ "PowerKeyShortAction",
+ NULL);
+
+ for (i = 0; i < SHORT_POWER_KEY_N; i++)
+ {
+ if (g_strcmp0 (short_power_key_value, spk[i].value) == 0)
+ {
+ hildon_picker_button_set_active
+ (HILDON_PICKER_BUTTON (section->short_power_key), i);
+ }
+ }
+
+
+ iface = MAEMO_TWEAKS_SECTION (section);
+ iface->widget = gtk_vbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (iface->widget), section->short_power_key,
+ TRUE, TRUE, 0);
+}
+
+static void
+maemo_tweaks_mce_section_dispose (GObject *obj)
+{
+ MaemoTweaksMceSection *section = MAEMO_TWEAKS_MCE_SECTION (obj);
+ if (section->ini)
+ {
+ g_key_file_free (section->ini);
+ section->ini = NULL;
+ }
+
+ G_OBJECT_CLASS (maemo_tweaks_mce_section_parent_class)->dispose
+ (obj);
+}
+
+
+static void _save (MaemoTweaksSection *section)
+{
+ gchar *argv[3];
+ gint active;
+
+ active = hildon_picker_button_get_active
+ (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
+ (section)->short_power_key));
+
+ argv[0] = g_strdup ("/usr/bin/maemo-tweaks-mce-save");
+ argv[1] = g_strdup_printf ("%s", spk[active].value);
+ argv[2] = 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]);
+}
+