setuid in the right package.
[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
8 #include "maemo-tweaks-types.h"
9 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
10 #include "maemo-tweaks-module-manager.h"
11
12 GtkWidget *create_dialog (GtkWindow *parent)
13 {
14     GtkWidget *dialog;
15
16     dialog = gtk_dialog_new_with_buttons
17         ("Maemo 5 Tweaks",
18          parent,
19          GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
20          GTK_STOCK_SAVE,
21          GTK_RESPONSE_OK,
22          GTK_STOCK_CANCEL,
23          GTK_RESPONSE_CANCEL,
24          NULL);
25
26     return dialog;
27 }
28
29 osso_return_t execute (osso_context_t *osso, gpointer data,
30                        gboolean user_activated)
31 {
32     GtkWidget *dialog;
33     gint response;
34
35     MaemoTweaksModuleManager *manager;
36     GType *section_types;
37     guint n_sections;
38     GList *sections = NULL;
39     gint i;
40
41     manager = g_object_new (MAEMO_TWEAKS_TYPE_MODULE_MANAGER,
42                             "module-path", MODULES_DIR,
43                             NULL);
44
45     section_types = g_type_children (MAEMO_TWEAKS_TYPE_SECTION, &n_sections);
46
47     dialog = create_dialog (GTK_WINDOW (data));
48
49     for (i = 0; i < n_sections; i++)
50     {
51         MaemoTweaksSection *section;
52         MaemoTweaksSectionClass *klass;
53
54         klass = g_type_class_ref (section_types[i]);
55         section = maemo_tweaks_section_new (section_types[i]);
56
57         sections = g_list_prepend (sections, section);
58         gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
59                             maemo_tweaks_section_get_widget (section),
60                             TRUE, TRUE, 0);
61
62         g_type_class_unref (klass);
63     }
64
65     gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
66     response = gtk_dialog_run (GTK_DIALOG (dialog));
67     if (response == GTK_RESPONSE_OK)
68     {
69         /* Save all settings */
70         g_list_foreach (sections, (GFunc) maemo_tweaks_section_save, NULL);
71     }
72
73
74     gtk_widget_destroy (GTK_WIDGET (dialog));
75     g_object_unref (manager);
76     if (sections)
77     {
78         g_list_foreach (sections, (GFunc) g_object_unref, NULL);
79         g_list_free (sections);
80     }
81
82     return OSSO_OK;
83 }
84