Bump version to 0.0.9.
[tweakr] / tweakr.c
1 /*
2  * vim:ts=4:sw=4:et:cindent:cino=(0
3  */ 
4
5 #include <config.h>
6 #include <glib/gi18n-lib.h>
7
8 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
9 #include <gtk/gtk.h>
10 #include <hildon/hildon-note.h>
11 #include <hildon/hildon-pannable-area.h>
12 #include <hildon/hildon-defines.h>
13
14 #include "tweakr-types.h"
15 #include "libtweakr-section/tweakr-section.h"
16 #include "tweakr-module-manager.h"
17
18 static gboolean save_ret;
19
20 GtkWidget *create_dialog (GtkWindow *parent)
21 {
22     GtkWidget *dialog;
23
24     dialog = gtk_dialog_new_with_buttons
25         ("Tweakr",
26          parent,
27          GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
28          GTK_STOCK_SAVE,
29          GTK_RESPONSE_OK,
30          GTK_STOCK_CANCEL,
31          GTK_RESPONSE_CANCEL,
32          NULL);
33
34     return dialog;
35 }
36
37 void _save (TweakrSection *section, gboolean *requires_restart)
38 {
39     save_ret &= tweakr_section_save (section, requires_restart);
40 }
41
42 osso_return_t execute (osso_context_t *osso, gpointer data,
43                        gboolean user_activated)
44 {
45     GtkWidget *dialog;
46     GtkWidget *panarea;
47     GtkWidget *box;
48     gint response;
49
50     TweakrModuleManager *manager;
51     GType *section_types;
52     guint n_sections;
53     GList *sections = NULL;
54     gint i;
55     gboolean requires_restart = FALSE;
56
57     manager = g_object_new (TWEAKR_TYPE_MODULE_MANAGER,
58                             "module-path", MODULES_DIR,
59                             NULL);
60
61     section_types = g_type_children (TWEAKR_TYPE_SECTION, &n_sections);
62
63     dialog = create_dialog (GTK_WINDOW (data));
64     panarea = hildon_pannable_area_new ();
65     box = gtk_vbox_new (FALSE, HILDON_MARGIN_DOUBLE);
66
67     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (panarea),
68                                             box);
69     g_object_set (G_OBJECT (panarea), "height-request", 350, NULL);
70
71     for (i = 0; i < n_sections; i++)
72     {
73         TweakrSection *section;
74         TweakrSectionClass *klass;
75         GtkWidget *frame;
76
77         klass = g_type_class_ref (section_types[i]);
78         section = tweakr_section_new (section_types[i]);
79
80         sections = g_list_prepend (sections, section);
81         frame = gtk_frame_new (section->name);
82
83         gtk_box_pack_start (GTK_BOX (box),
84                             frame,
85                             FALSE, FALSE, 0);
86         gtk_container_add (GTK_CONTAINER (frame),
87                            tweakr_section_get_widget (section));
88
89         g_type_class_unref (klass);
90     }
91
92     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), panarea,
93                         TRUE, TRUE, 0);
94     gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
95
96     for (;;)
97     {
98         save_ret = TRUE;
99         response = gtk_dialog_run (GTK_DIALOG (dialog));
100         if (response == GTK_RESPONSE_OK)
101         {
102             /* Save all settings */
103             g_list_foreach (sections, (GFunc) _save, &requires_restart);
104         }
105         if (save_ret)
106             break;
107     }
108
109     gtk_widget_destroy (GTK_WIDGET (dialog));
110     g_object_unref (manager);
111     if (sections)
112     {
113         g_list_foreach (sections, (GFunc) g_object_unref, NULL);
114         g_list_free (sections);
115     }
116
117     if (requires_restart)
118     {
119         GtkWidget *note;
120
121         note = hildon_note_new_information
122             (GTK_WINDOW (data),
123              _("Some of the settings you have changed "
124                "will take effect only after you restart your device."));
125         gtk_dialog_run (GTK_DIALOG (note));
126         gtk_widget_destroy (note);
127     }
128
129     return OSSO_OK;
130 }
131