Add long power key button.
[tweakr] / maemo-tweaks.c
1 /*
2  * vim:ts=4:sw=4:et:cindent:cino=(0
3  */ 
4
5 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
6 #include <gtk/gtk.h>
7 #include <hildon/hildon-note.h>
8
9 #include "maemo-tweaks-types.h"
10 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
11 #include "maemo-tweaks-module-manager.h"
12
13 GtkWidget *create_dialog (GtkWindow *parent)
14 {
15     GtkWidget *dialog;
16
17     dialog = gtk_dialog_new_with_buttons
18         ("Maemo 5 Tweaks",
19          parent,
20          GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
21          GTK_STOCK_SAVE,
22          GTK_RESPONSE_OK,
23          GTK_STOCK_CANCEL,
24          GTK_RESPONSE_CANCEL,
25          NULL);
26
27     return dialog;
28 }
29
30 osso_return_t execute (osso_context_t *osso, gpointer data,
31                        gboolean user_activated)
32 {
33     GtkWidget *dialog;
34     gint response;
35
36     MaemoTweaksModuleManager *manager;
37     GType *section_types;
38     guint n_sections;
39     GList *sections = NULL;
40     gint i;
41     gboolean requires_restart = FALSE;
42
43     manager = g_object_new (MAEMO_TWEAKS_TYPE_MODULE_MANAGER,
44                             "module-path", MODULES_DIR,
45                             NULL);
46
47     section_types = g_type_children (MAEMO_TWEAKS_TYPE_SECTION, &n_sections);
48
49     dialog = create_dialog (GTK_WINDOW (data));
50
51     for (i = 0; i < n_sections; i++)
52     {
53         MaemoTweaksSection *section;
54         MaemoTweaksSectionClass *klass;
55
56         klass = g_type_class_ref (section_types[i]);
57         section = maemo_tweaks_section_new (section_types[i]);
58
59         sections = g_list_prepend (sections, section);
60         gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
61                             maemo_tweaks_section_get_widget (section),
62                             TRUE, TRUE, 0);
63
64         g_type_class_unref (klass);
65     }
66
67     gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
68     response = gtk_dialog_run (GTK_DIALOG (dialog));
69     if (response == GTK_RESPONSE_OK)
70     {
71         /* Save all settings */
72         g_list_foreach (sections, (GFunc) maemo_tweaks_section_save,
73                         &requires_restart);
74     }
75
76     gtk_widget_destroy (GTK_WIDGET (dialog));
77     g_object_unref (manager);
78     if (sections)
79     {
80         g_list_foreach (sections, (GFunc) g_object_unref, NULL);
81         g_list_free (sections);
82     }
83
84     if (requires_restart)
85     {
86         GtkWidget *note;
87
88         note = hildon_note_new_information
89             (GTK_WINDOW (data), "Some of the settings you have changed"
90              " will take effect only after you restart your device.");
91         gtk_dialog_run (GTK_DIALOG (note));
92         gtk_widget_destroy (note);
93     }
94
95     return OSSO_OK;
96 }
97