Add some margin between sections.
[tweakr] / maemo-tweaks.c
index 7f0b0c6..d79bb6f 100644 (file)
@@ -4,17 +4,22 @@
 
 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
 #include <gtk/gtk.h>
+#include <hildon/hildon-note.h>
+#include <hildon/hildon-pannable-area.h>
+#include <hildon/hildon-defines.h>
 
 #include "maemo-tweaks-types.h"
 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
 #include "maemo-tweaks-module-manager.h"
 
+static gboolean save_ret;
+
 GtkWidget *create_dialog (GtkWindow *parent)
 {
     GtkWidget *dialog;
 
     dialog = gtk_dialog_new_with_buttons
-        ("Maemo 5 Tweaks",
+        ("Maemo Tweaks",
          parent,
          GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
          GTK_STOCK_SAVE,
@@ -26,10 +31,17 @@ GtkWidget *create_dialog (GtkWindow *parent)
     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)
 {
     GtkWidget *dialog;
+    GtkWidget *panarea;
+    GtkWidget *box;
     gint response;
 
     MaemoTweaksModuleManager *manager;
@@ -37,6 +49,7 @@ osso_return_t execute (osso_context_t *osso, gpointer data,
     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,
@@ -45,6 +58,12 @@ osso_return_t execute (osso_context_t *osso, gpointer data,
     section_types = g_type_children (MAEMO_TWEAKS_TYPE_SECTION, &n_sections);
 
     dialog = create_dialog (GTK_WINDOW (data));
+    panarea = hildon_pannable_area_new ();
+    box = gtk_vbox_new (FALSE, HILDON_MARGIN_DOUBLE);
+
+    hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (panarea),
+                                            box);
+    g_object_set (G_OBJECT (panarea), "height-request", 350, NULL);
 
     for (i = 0; i < n_sections; i++)
     {
@@ -55,22 +74,33 @@ osso_return_t execute (osso_context_t *osso, gpointer data,
         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_box_pack_start (GTK_BOX (box),
+                            gtk_label_new (section->name),
+                            FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (box),
                             maemo_tweaks_section_get_widget (section),
-                            TRUE, TRUE, 0);
+                            FALSE, FALSE, 0);
 
         g_type_class_unref (klass);
     }
 
+    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), panarea,
+                        FALSE, FALSE, 0);
     gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
-    response = gtk_dialog_run (GTK_DIALOG (dialog));
-    if (response == GTK_RESPONSE_OK)
+
+    for (;;)
     {
-        /* Save all settings */
-        g_list_foreach (sections, (GFunc) maemo_tweaks_section_save, NULL);
+        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)
@@ -79,6 +109,17 @@ osso_return_t execute (osso_context_t *osso, gpointer data,
         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;
 }