Add some margin between sections.
[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 #include <hildon/hildon-pannable-area.h>
9 #include <hildon/hildon-defines.h>
10
11 #include "maemo-tweaks-types.h"
12 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
13 #include "maemo-tweaks-module-manager.h"
14
15 static gboolean save_ret;
16
17 GtkWidget *create_dialog (GtkWindow *parent)
18 {
19     GtkWidget *dialog;
20
21     dialog = gtk_dialog_new_with_buttons
22         ("Maemo Tweaks",
23          parent,
24          GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
25          GTK_STOCK_SAVE,
26          GTK_RESPONSE_OK,
27          GTK_STOCK_CANCEL,
28          GTK_RESPONSE_CANCEL,
29          NULL);
30
31     return dialog;
32 }
33
34 void _save (MaemoTweaksSection *section, gboolean *requires_restart)
35 {
36     save_ret &= maemo_tweaks_section_save (section, requires_restart);
37 }
38
39 osso_return_t execute (osso_context_t *osso, gpointer data,
40                        gboolean user_activated)
41 {
42     GtkWidget *dialog;
43     GtkWidget *panarea;
44     GtkWidget *box;
45     gint response;
46
47     MaemoTweaksModuleManager *manager;
48     GType *section_types;
49     guint n_sections;
50     GList *sections = NULL;
51     gint i;
52     gboolean requires_restart = FALSE;
53
54     manager = g_object_new (MAEMO_TWEAKS_TYPE_MODULE_MANAGER,
55                             "module-path", MODULES_DIR,
56                             NULL);
57
58     section_types = g_type_children (MAEMO_TWEAKS_TYPE_SECTION, &n_sections);
59
60     dialog = create_dialog (GTK_WINDOW (data));
61     panarea = hildon_pannable_area_new ();
62     box = gtk_vbox_new (FALSE, HILDON_MARGIN_DOUBLE);
63
64     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (panarea),
65                                             box);
66     g_object_set (G_OBJECT (panarea), "height-request", 350, NULL);
67
68     for (i = 0; i < n_sections; i++)
69     {
70         MaemoTweaksSection *section;
71         MaemoTweaksSectionClass *klass;
72
73         klass = g_type_class_ref (section_types[i]);
74         section = maemo_tweaks_section_new (section_types[i]);
75
76         sections = g_list_prepend (sections, section);
77         gtk_box_pack_start (GTK_BOX (box),
78                             gtk_label_new (section->name),
79                             FALSE, FALSE, 0);
80         gtk_box_pack_start (GTK_BOX (box),
81                             maemo_tweaks_section_get_widget (section),
82                             FALSE, FALSE, 0);
83
84         g_type_class_unref (klass);
85     }
86
87     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), panarea,
88                         FALSE, FALSE, 0);
89     gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
90
91     for (;;)
92     {
93         save_ret = TRUE;
94         response = gtk_dialog_run (GTK_DIALOG (dialog));
95         if (response == GTK_RESPONSE_OK)
96         {
97             /* Save all settings */
98             g_list_foreach (sections, (GFunc) _save, &requires_restart);
99         }
100         if (save_ret)
101             break;
102     }
103
104     gtk_widget_destroy (GTK_WIDGET (dialog));
105     g_object_unref (manager);
106     if (sections)
107     {
108         g_list_foreach (sections, (GFunc) g_object_unref, NULL);
109         g_list_free (sections);
110     }
111
112     if (requires_restart)
113     {
114         GtkWidget *note;
115
116         note = hildon_note_new_information
117             (GTK_WINDOW (data), "Some of the settings you have changed"
118              " will take effect only after you restart your device.");
119         gtk_dialog_run (GTK_DIALOG (note));
120         gtk_widget_destroy (note);
121     }
122
123     return OSSO_OK;
124 }
125