Add sections' names.
[tweakr] / maemo-tweaks.c
index 8ad6505..aa0568b 100644 (file)
@@ -4,56 +4,35 @@
 
 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
 #include <gtk/gtk.h>
-#include <hildon/hildon-picker-button.h>
+#include <hildon/hildon-note.h>
 
-GtkWidget * create_desktop_snap_to_grid (void)
-{
-    const gchar *options[] = {"Default", "Small grid", "Large grid", NULL};
-    gint i = 0;
-    GtkWidget *button, *selector;
-
-    selector = hildon_touch_selector_new_text ();
-    while (options[i] && options[i] != '\0')
-    {
-        hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
-                                           options [i++]);
-    }
+#include "maemo-tweaks-types.h"
+#include "libmaemo-tweaks-section/maemo-tweaks-section.h"
+#include "maemo-tweaks-module-manager.h"
 
-    button = hildon_picker_button_new (HILDON_SIZE_AUTO,
-                                       HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-
-    hildon_button_set_title (HILDON_BUTTON (button),
-                             "Snap desktop icons to grid");
-
-    hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
-                                       HILDON_TOUCH_SELECTOR (selector));
-
-    gtk_widget_show (button);
-    return button;
-}
+static gboolean save_ret;
 
 GtkWidget *create_dialog (GtkWindow *parent)
 {
     GtkWidget *dialog;
-    GtkWidget *box;
 
     dialog = gtk_dialog_new_with_buttons
         ("Maemo 5 Tweaks",
          parent,
          GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
-         GTK_STOCK_OK,
+         GTK_STOCK_SAVE,
          GTK_RESPONSE_OK,
          GTK_STOCK_CANCEL,
          GTK_RESPONSE_CANCEL,
          NULL);
 
-    box = GTK_DIALOG (dialog)->vbox;
-    gtk_box_pack_start (GTK_BOX (box), create_desktop_snap_to_grid (),
-                        TRUE, TRUE, 0);
-
     return dialog;
 }
 
+void _save (MaemoTweaksSection *section, gboolean *requires_restart)
+{
+    save_ret &= maemo_tweaks_section_save (section, requires_restart);
+}
 
 osso_return_t execute (osso_context_t *osso, gpointer data,
                        gboolean user_activated)
@@ -61,13 +40,74 @@ osso_return_t execute (osso_context_t *osso, gpointer data,
     GtkWidget *dialog;
     gint response;
 
+    MaemoTweaksModuleManager *manager;
+    GType *section_types;
+    guint n_sections;
+    GList *sections = NULL;
+    gint i;
+    gboolean requires_restart = FALSE;
+
+    manager = g_object_new (MAEMO_TWEAKS_TYPE_MODULE_MANAGER,
+                            "module-path", MODULES_DIR,
+                            NULL);
+
+    section_types = g_type_children (MAEMO_TWEAKS_TYPE_SECTION, &n_sections);
+
     dialog = create_dialog (GTK_WINDOW (data));
-    response = gtk_dialog_run (GTK_DIALOG (dialog));
-    if (response == GTK_RESPONSE_OK)
+
+    for (i = 0; i < n_sections; i++)
     {
+        MaemoTweaksSection *section;
+        MaemoTweaksSectionClass *klass;
+
+        klass = g_type_class_ref (section_types[i]);
+        section = maemo_tweaks_section_new (section_types[i]);
+
+        sections = g_list_prepend (sections, section);
+        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+                            gtk_label_new (section->name),
+                            TRUE, TRUE, 0);
+        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+                            maemo_tweaks_section_get_widget (section),
+                            TRUE, TRUE, 0);
+
+        g_type_class_unref (klass);
+    }
+
+    gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+
+    for (;;)
+    {
+        save_ret = TRUE;
+        response = gtk_dialog_run (GTK_DIALOG (dialog));
+        if (response == GTK_RESPONSE_OK)
+        {
+            /* Save all settings */
+            g_list_foreach (sections, (GFunc) _save, &requires_restart);
+        }
+        if (save_ret)
+            break;
     }
 
     gtk_widget_destroy (GTK_WIDGET (dialog));
+    g_object_unref (manager);
+    if (sections)
+    {
+        g_list_foreach (sections, (GFunc) g_object_unref, NULL);
+        g_list_free (sections);
+    }
+
+    if (requires_restart)
+    {
+        GtkWidget *note;
+
+        note = hildon_note_new_information
+            (GTK_WINDOW (data), "Some of the settings you have changed"
+             " will take effect only after you restart your device.");
+        gtk_dialog_run (GTK_DIALOG (note));
+        gtk_widget_destroy (note);
+    }
+
     return OSSO_OK;
 }