Make _save a gboolean and mce has a confirmation note if all disabled.
authorSalvatore Iovene <salvatore@iovene.com>
Wed, 9 Dec 2009 18:48:01 +0000 (20:48 +0200)
committerSalvatore Iovene <salvatore@iovene.com>
Wed, 9 Dec 2009 18:48:01 +0000 (20:48 +0200)
libmaemo-tweaks-section/maemo-tweaks-section.c
libmaemo-tweaks-section/maemo-tweaks-section.h
maemo-tweaks.c
modules/maemo-tweaks-desktop.c
modules/maemo-tweaks-mce.c

index 336b16b..ef730b1 100644 (file)
@@ -38,18 +38,20 @@ maemo_tweaks_section_get_widget (MaemoTweaksSection *section)
     return section->widget;
 }
 
-void
+gboolean
 maemo_tweaks_section_save (MaemoTweaksSection *section,
                            gboolean *requires_restart)
 {
-    g_return_if_fail (MAEMO_TWEAKS_IS_SECTION (section));
+    g_return_val_if_fail (MAEMO_TWEAKS_IS_SECTION (section), TRUE);
 
     if (MAEMO_TWEAKS_SECTION_GET_CLASS (section)->save)
-        MAEMO_TWEAKS_SECTION_GET_CLASS (section)->save (section,
-                                                        requires_restart);
+        return MAEMO_TWEAKS_SECTION_GET_CLASS (section)->save
+            (section, requires_restart);
     else
         g_warning ("%s: section class %s doesn't implement "
                    "MaemoTweaksSection::filter ()\n",
                    G_STRFUNC, g_type_name (G_TYPE_FROM_INSTANCE (section)));
+
+    return TRUE;
 }
 
index 0e14daf..d1c05b3 100644 (file)
@@ -44,7 +44,8 @@ struct _MaemoTweaksSectionClass
 
     const gchar *name;
 
-    void (*save) (MaemoTweaksSection *section, gboolean *requires_restart);
+    gboolean (*save) (MaemoTweaksSection *section,
+                      gboolean *requires_restart);
 };
 
 
@@ -53,8 +54,8 @@ GType maemo_tweaks_section_get_type (void) G_GNUC_CONST;
 MaemoTweaksSection * maemo_tweaks_section_new (GType type);
 
 GtkWidget * maemo_tweaks_section_get_widget (MaemoTweaksSection *section);
-void maemo_tweaks_section_save (MaemoTweaksSection *section,
-                                gboolean *requires_restart);
+gboolean maemo_tweaks_section_save (MaemoTweaksSection *section,
+                                    gboolean *requires_restart);
 
 G_END_DECLS
 
index 9679937..5cd5b40 100644 (file)
@@ -10,6 +10,8 @@
 #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;
@@ -27,6 +29,11 @@ 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)
 {
@@ -65,12 +72,18 @@ osso_return_t execute (osso_context_t *osso, gpointer data,
     }
 
     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,
-                        &requires_restart);
+        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));
index 5dbb4d5..f934b7e 100644 (file)
@@ -72,7 +72,8 @@ static void maemo_tweaks_desktop_section_init
     (MaemoTweaksDesktopSection *section);
 static void maemo_tweaks_desktop_section_dispose (GObject *obj);
 
-static void _save (MaemoTweaksSection *section, gboolean *requires_restart);
+static gboolean _save (MaemoTweaksSection *section,
+                       gboolean *requires_restart);
 
 static GType maemo_tweaks_desktop_section_type = 0;
 static MaemoTweaksSectionClass *
@@ -219,7 +220,8 @@ maemo_tweaks_desktop_section_dispose (GObject *obj)
 }
 
 
-static void _save (MaemoTweaksSection *section, gboolean *requires_restart)
+static gboolean  _save (MaemoTweaksSection *section,
+                        gboolean *requires_restart)
 {
     gchar *argv[3];
     gint active;
@@ -238,5 +240,7 @@ static void _save (MaemoTweaksSection *section, gboolean *requires_restart)
 
     g_free (argv[0]);
     g_free (argv[1]);
+
+    return TRUE;
 }
 
index 2b244c3..47b70b1 100644 (file)
@@ -7,6 +7,7 @@
 #include <gtk/gtk.h>
 #include <hildon/hildon-picker-button.h>
 #include <hildon/hildon-touch-selector.h>
+#include <hildon/hildon-note.h>
 
 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
 #include "libmaemo-tweaks-section/maemo-tweaks-module.h"
@@ -110,7 +111,8 @@ static void maemo_tweaks_mce_section_init
     (MaemoTweaksMceSection *section);
 static void maemo_tweaks_mce_section_dispose (GObject *obj);
 
-static void _save (MaemoTweaksSection *section, gboolean *requires_restart);
+static gboolean _save (MaemoTweaksSection *section,
+                       gboolean *requires_restart);
 
 static GType maemo_tweaks_mce_section_type = 0;
 static MaemoTweaksSectionClass *
@@ -349,16 +351,15 @@ maemo_tweaks_mce_section_dispose (GObject *obj)
         (obj);
 }
 
-static void _save (MaemoTweaksSection *section, gboolean *requires_restart)
+static gboolean _save (MaemoTweaksSection *section,
+                       gboolean *requires_restart)
 {
     gchar *argv[5];
     gint short_active, long_active, double_active;
     gint i;
 
     if (!MAEMO_TWEAKS_MCE_SECTION (section)->value_changed)
-        return;
-
-    *requires_restart = TRUE;
+        return TRUE;
 
     short_active = hildon_picker_button_get_active
         (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
@@ -372,6 +373,26 @@ static void _save (MaemoTweaksSection *section, gboolean *requires_restart)
         (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_MCE_SECTION
                                (section)->double_power_key));
 
+    if (short_active  == SHORT_POWER_KEY_DISABLED &&
+        long_active   == LONG_POWER_KEY_DISABLED  &&
+        double_active == DOUBLE_POWER_KEY_DISABLED)
+    {
+        GtkWidget *note;
+        gint retcode;
+
+        note = hildon_note_new_confirmation
+            (NULL, "Setting all Power Key options to \"Disabled\" means "
+             "that the only way to turn the device off is the removal of "
+             "the battery. Do you want to continue?");
+        retcode = gtk_dialog_run (GTK_DIALOG (note));
+        gtk_widget_destroy (note);
+
+        if (retcode == GTK_RESPONSE_CANCEL)
+            return FALSE;
+    }
+
+    *requires_restart = TRUE;
+
     argv[0] = g_strdup ("/usr/bin/maemo-tweaks-mce-save");
     argv[1] = g_strdup_printf ("%s", spk[short_active].value);
     argv[2] = g_strdup_printf ("%s", lpk[long_active].value);
@@ -384,5 +405,7 @@ static void _save (MaemoTweaksSection *section, gboolean *requires_restart)
 
     for (i = 0; i < (sizeof (argv) / sizeof (gchar *)) - 1; i++)
         g_free (argv[i]);
+
+    return TRUE;
 }