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