* Added global settings persistence
authorSergio Villar Senin <svillar@igalia.com>
Fri, 11 May 2007 08:27:43 +0000 (08:27 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 11 May 2007 08:27:43 +0000 (08:27 +0000)
* Added some UI notifications when errors
* Fixed a bug in the Modest Combo box

pmo-trunk-r1833

src/maemo/modest-maemo-global-settings-dialog.c
src/widgets/modest-combo-box.c
src/widgets/modest-global-settings-dialog-priv.h
src/widgets/modest-global-settings-dialog.c

index c019a81..5c5e5d8 100644 (file)
 #ifdef MODEST_HILDON_VERSION_0
 #include <hildon-widgets/hildon-caption.h>
 #include <hildon-widgets/hildon-number-editor.h>
 #ifdef MODEST_HILDON_VERSION_0
 #include <hildon-widgets/hildon-caption.h>
 #include <hildon-widgets/hildon-number-editor.h>
+#include <hildon-widgets/hildon-banner.h>
 #else
 #include <hildon/hildon-caption.h>
 #include <hildon/hildon-number-editor.h>
 #else
 #include <hildon/hildon-caption.h>
 #include <hildon/hildon-number-editor.h>
+#include <hildon/hildon-banner.h>
 #endif /*MODEST_HILDON_VERSION_0*/
 
 #include <glib/gi18n.h>
 #endif /*MODEST_HILDON_VERSION_0*/
 
 #include <glib/gi18n.h>
@@ -51,8 +53,9 @@
 #include "maemo/modest-maemo-global-settings-dialog.h"
 #include "widgets/modest-ui-constants.h"
 
 #include "maemo/modest-maemo-global-settings-dialog.h"
 #include "widgets/modest-ui-constants.h"
 
-
-/* include other impl specific header files */
+#define MSG_SIZE_MAX_VAL 5000
+#define MSG_SIZE_DEF_VAL 1000
+#define MSG_SIZE_MIN_VAL 1
 
 /* 'private'/'protected' functions */
 static void modest_maemo_global_settings_dialog_class_init (ModestMaemoGlobalSettingsDialogClass *klass);
 
 /* 'private'/'protected' functions */
 static void modest_maemo_global_settings_dialog_class_init (ModestMaemoGlobalSettingsDialogClass *klass);
@@ -69,6 +72,10 @@ enum {
 static GtkWidget* create_updating_page  (ModestMaemoGlobalSettingsDialog *self);
 static GtkWidget* create_composing_page (ModestMaemoGlobalSettingsDialog *self);
 
 static GtkWidget* create_updating_page  (ModestMaemoGlobalSettingsDialog *self);
 static GtkWidget* create_composing_page (ModestMaemoGlobalSettingsDialog *self);
 
+static gboolean   on_range_error        (HildonNumberEditor *editor, 
+                                        HildonNumberEditorErrorType type,
+                                        gpointer user_data);
+
 typedef struct _ModestMaemoGlobalSettingsDialogPrivate ModestMaemoGlobalSettingsDialogPrivate;
 struct _ModestMaemoGlobalSettingsDialogPrivate {
 };
 typedef struct _ModestMaemoGlobalSettingsDialogPrivate ModestMaemoGlobalSettingsDialogPrivate;
 struct _ModestMaemoGlobalSettingsDialogPrivate {
 };
@@ -136,6 +143,9 @@ modest_maemo_global_settings_dialog_init (ModestMaemoGlobalSettingsDialog *self)
                
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), ppriv->notebook);
        gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF);
                
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), ppriv->notebook);
        gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF);
+
+       /* Load current config */
+       _modest_global_settings_dialog_load_conf (ppriv);
        gtk_widget_show_all (ppriv->notebook);
 }
 
        gtk_widget_show_all (ppriv->notebook);
 }
 
@@ -213,8 +223,9 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self)
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
        /* Size limit */
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
        /* Size limit */
-       ppriv->size_limit = hildon_number_editor_new (1, 5000);;
-       hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (ppriv->size_limit), 1000);;
+       ppriv->size_limit = hildon_number_editor_new (MSG_SIZE_MIN_VAL, MSG_SIZE_MAX_VAL);;
+       hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (ppriv->size_limit), MSG_SIZE_DEF_VAL);;
+       g_signal_connect (ppriv->size_limit, "range_error", G_CALLBACK (on_range_error), self);
        caption = hildon_caption_new (size_group, 
                                      _("mcen_fi_advsetup_sizelimit"), 
                                      ppriv->size_limit, 
        caption = hildon_caption_new (size_group, 
                                      _("mcen_fi_advsetup_sizelimit"), 
                                      ppriv->size_limit, 
@@ -267,7 +278,7 @@ create_composing_page (ModestMaemoGlobalSettingsDialog *self)
        /* Reply */
        ppriv->include_reply = gtk_check_button_new ();
        caption = hildon_caption_new (size_group, 
        /* Reply */
        ppriv->include_reply = gtk_check_button_new ();
        caption = hildon_caption_new (size_group, 
-                                     _("mcen_fi_options_playsound"), 
+                                     _("mcen_va_options_include_original_inreply"), 
                                      ppriv->include_reply, 
                                      NULL, 
                                      HILDON_CAPTION_MANDATORY);
                                      ppriv->include_reply, 
                                      NULL, 
                                      HILDON_CAPTION_MANDATORY);
@@ -275,3 +286,43 @@ create_composing_page (ModestMaemoGlobalSettingsDialog *self)
 
        return vbox;
 }
 
        return vbox;
 }
+
+static gboolean
+on_range_error (HildonNumberEditor *editor, 
+               HildonNumberEditorErrorType type,
+               gpointer user_data)
+{
+       gchar *msg;
+       gint new_val;
+
+       switch (type) {
+       case MAXIMUM_VALUE_EXCEED:
+               msg = g_strdup_printf (_("ckct_ib_maximum_value"), MSG_SIZE_MAX_VAL);
+               new_val = MSG_SIZE_MAX_VAL;
+               break;
+       case MINIMUM_VALUE_EXCEED:
+               msg = g_strdup_printf (_("ckct_ib_minimum_value"), MSG_SIZE_MIN_VAL);
+               new_val = MSG_SIZE_MIN_VAL;
+               break;
+       case ERRONEOUS_VALUE:
+               msg = g_strdup_printf (_("ckct_ib_set_a_value_within_range"), 
+                                      MSG_SIZE_MIN_VAL, 
+                                      MSG_SIZE_MAX_VAL);
+               /* FIXME: use the previous */
+               new_val = MSG_SIZE_DEF_VAL;
+               break;
+       default:
+               g_return_val_if_reached (FALSE);
+       }
+
+       /* Restore value */
+       hildon_number_editor_set_value (editor, new_val);
+
+       /* Show error */
+       hildon_banner_show_information (GTK_WIDGET (user_data), NULL, msg);
+
+       /* Free */
+       g_free (msg);
+
+       return TRUE;
+}
index 16e8973..8956df8 100644 (file)
@@ -206,15 +206,13 @@ gpointer
 modest_combo_box_get_active_id (ModestComboBox *self)
 {
        GValue val = {0,};
 modest_combo_box_get_active_id (ModestComboBox *self)
 {
        GValue val = {0,};
-       gpointer retval;
 
        g_return_val_if_fail (self, NULL);
        
        /* Do not unset the GValue */
        get_active (self, &val, COLUMN_ID);
 
        g_return_val_if_fail (self, NULL);
        
        /* Do not unset the GValue */
        get_active (self, &val, COLUMN_ID);
-       retval = g_value_peek_pointer (&val);
 
 
-       return retval;
+       return g_value_get_pointer (&val);
 }
 
 
 }
 
 
@@ -237,7 +235,7 @@ modest_combo_box_set_active_id (ModestComboBox *self, gpointer id)
        do {
                gpointer row_id;
                gtk_tree_model_get (model, &iter, COLUMN_ID, &row_id, -1);
        do {
                gpointer row_id;
                gtk_tree_model_get (model, &iter, COLUMN_ID, &row_id, -1);
-               if ((priv->id_equal_func)(id, row_id) == 0) {
+               if ((priv->id_equal_func)(id, row_id)) {
                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX(self), &iter);
                        found = TRUE;
                }
                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX(self), &iter);
                        found = TRUE;
                }
@@ -252,14 +250,14 @@ modest_combo_box_set_active_id (ModestComboBox *self, gpointer id)
 const gchar*
 modest_combo_box_get_active_display_name (ModestComboBox *self)
 {
 const gchar*
 modest_combo_box_get_active_display_name (ModestComboBox *self)
 {
-       GValue val = {0,};
-       gpointer retval;
+       const GValue val = {0,};
+       const gchar *retval;
 
        g_return_val_if_fail (self, NULL);
 
        /* Do not unset the GValue */
 
        g_return_val_if_fail (self, NULL);
 
        /* Do not unset the GValue */
-       get_active (self, &val, COLUMN_DISPLAY_NAME);
-       retval = g_value_peek_pointer (&val);
+       get_active (self, (GValue *)&val, COLUMN_DISPLAY_NAME);
+       retval = g_value_get_string (&val);
 
 
-       return (gchar*) retval;
+       return retval;
 }
 }
index 1df131a..9ab18c9 100644 (file)
@@ -32,7 +32,6 @@
 
 #include <gtk/gtkwidget.h>
 #include "modest-pair.h"
 
 #include <gtk/gtkwidget.h>
 #include "modest-pair.h"
-/* other include files */
 
 G_BEGIN_DECLS
 
 
 G_BEGIN_DECLS
 
@@ -58,6 +57,9 @@ ModestPairList*   _modest_global_settings_dialog_get_connected_via   (void);
 ModestPairList*   _modest_global_settings_dialog_get_update_interval (void);
 ModestPairList*   _modest_global_settings_dialog_get_msg_formats     (void);
 
 ModestPairList*   _modest_global_settings_dialog_get_update_interval (void);
 ModestPairList*   _modest_global_settings_dialog_get_msg_formats     (void);
 
+void _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv);
+void _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv);
+
 G_END_DECLS
 
 #endif /* __MODEST_GLOBAL_SETTINGS_DIALOG_PRIV_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_GLOBAL_SETTINGS_DIALOG_PRIV_H__ */
index c78ad96..8085b48 100644 (file)
 #include <gtk/gtknotebook.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtknotebook.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtklabel.h>
-#include "modest-global-settings-dialog.h"
+#include <gtk/gtktogglebutton.h>
+#include "widgets/modest-global-settings-dialog.h"
+#include "widgets/modest-global-settings-dialog-priv.h"
 #include "modest-defs.h"
 #include "modest-defs.h"
+#include "modest-conf.h"
+#include "modest-runtime.h"
 #include "modest-ui-constants.h"
 #include "modest-ui-constants.h"
+#include "modest-tny-msg.h"
 #include "widgets/modest-combo-box.h"
 #include "widgets/modest-combo-box.h"
+#ifdef MODEST_PLATFORM_MAEMO
+#ifdef MODEST_HILDON_VERSION_0
+#include <hildon-widgets/hildon-number-editor.h>
+#else
+#include <hildon/hildon-number-editor.h>
+#endif /*MODEST_HILDON_VERSION_0*/
+#endif
 /* include other impl specific header files */
 
 /* 'private'/'protected' functions */
 /* include other impl specific header files */
 
 /* 'private'/'protected' functions */
@@ -42,6 +54,10 @@ static void modest_global_settings_dialog_class_init (ModestGlobalSettingsDialog
 static void modest_global_settings_dialog_init       (ModestGlobalSettingsDialog *obj);
 static void modest_global_settings_dialog_finalize   (GObject *obj);
 
 static void modest_global_settings_dialog_init       (ModestGlobalSettingsDialog *obj);
 static void modest_global_settings_dialog_finalize   (GObject *obj);
 
+static void on_response (GtkDialog *dialog,
+                        gint arg1,
+                        gpointer user_data);
+
 /* list my signals  */
 enum {
        /* MY_SIGNAL_1, */
 /* list my signals  */
 enum {
        /* MY_SIGNAL_1, */
@@ -105,13 +121,9 @@ modest_global_settings_dialog_init (ModestGlobalSettingsDialog *self)
        gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
        gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
     
        gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
        gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
     
-/*     /\* Connect to the dialog's response signal: *\/ */
-/*     /\* We use connect-before  */
-/*      * so we can stop the signal emission,  */
-/*      * to stop the default signal handler from closing the dialog. */
-/*      *\/ */
-/*     g_signal_connect (G_OBJECT (self), "response", */
-/*                       G_CALLBACK (on_response), self);  */
+       /* Connect to the dialog's response signal: */
+       g_signal_connect (G_OBJECT (self), "response",
+                         G_CALLBACK (on_response), self);
 
        /* Set title */
        gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_options"));
 
        /* Set title */
        gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_options"));
@@ -144,12 +156,12 @@ modest_global_settings_dialog_finalize (GObject *obj)
 static void
 add_to_modest_pair_list (const gint num, const gchar *str, GSList **list)
 {
 static void
 add_to_modest_pair_list (const gint num, const gchar *str, GSList **list)
 {
-       guint *number;
+       gint *number;
        ModestPair *pair;
 
        ModestPair *pair;
 
-       number = g_malloc0 (sizeof (guint));
+       number = g_malloc0 (sizeof (gint));
        *number = num;
        *number = num;
-       pair = modest_pair_new (number, g_strdup (str), TRUE);
+       pair = modest_pair_new (number, g_strdup (str), FALSE);
        *list = g_slist_prepend (*list, pair);
 }
 
        *list = g_slist_prepend (*list, pair);
 }
 
@@ -218,3 +230,151 @@ _modest_global_settings_dialog_get_msg_formats (void)
 
        return (ModestPairList *) g_slist_reverse (list);
 }
 
        return (ModestPairList *) g_slist_reverse (list);
 }
+
+void   
+_modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv)
+{
+       ModestConf *conf;
+       gboolean checked;
+       gint combo_id, value;
+       GError *error = NULL;
+
+       conf = modest_runtime_get_conf ();
+
+       /* Autoupdate */
+       checked = modest_conf_get_bool (conf, MODEST_CONF_AUTO_UPDATE, &error);
+       if (error) {
+               g_clear_error (&error);
+               error = NULL;
+               checked = FALSE;
+       }
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->auto_update), checked);
+
+       /* Connected by */
+       combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, &error);
+       if (error) {
+               g_error_free (error);
+               error = NULL;
+               combo_id = MODEST_CONNECTED_VIA_WLAN;
+       }
+       modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->connect_via), 
+                                       (gpointer) &combo_id);
+
+       /* Update interval */
+       combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_INTERVAL, &error);
+       if (error) {
+               g_error_free (error);
+               error = NULL;
+               combo_id = MODEST_UPDATE_INTERVAL_15_MIN;
+       }
+       modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->update_interval), 
+                                       (gpointer) &combo_id);
+
+       /* Size limit */
+       value  = modest_conf_get_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, &error);
+       if (error) {
+               g_error_free (error);
+               error = NULL;
+               value = 1000;
+       }
+       /* It's better to do this in the subclasses, but it's just one
+          line, so we'll leave it here for the moment */
+#ifdef MODEST_PLATFORM_MAEMO
+       hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (priv->size_limit), value);
+#else
+       gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit, value);
+#endif
+
+       /* TODO Fix with the value */
+
+       /* Play sound */
+       checked = modest_conf_get_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, &error);
+       if (error) {
+               g_error_free (error);
+               error = NULL;
+               checked = FALSE;
+       }
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->play_sound), checked);
+
+       /* Msg format */
+       combo_id = modest_conf_get_int (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, &error);
+       if (error) {
+               g_error_free (error);
+               error = NULL;
+               combo_id = MODEST_FILE_FORMAT_FORMATTED_TEXT;
+       }
+       modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->msg_format), 
+                                       (gpointer) &combo_id);
+
+       /* Include reply */
+       value = modest_conf_get_int (conf, MODEST_CONF_REPLY_TYPE, &error);
+       if (error) {
+               g_error_free (error);
+               error = NULL;
+               value = MODEST_TNY_MSG_REPLY_TYPE_QUOTE;
+       }
+       if (value == MODEST_TNY_MSG_REPLY_TYPE_QUOTE)
+               checked = TRUE;
+       else
+               checked = FALSE;
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->include_reply), checked);
+}
+
+void
+_modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv)
+{
+       ModestConf *conf;
+       gboolean checked;
+       gint *combo_id, value;
+
+       conf = modest_runtime_get_conf ();
+
+       /* Autoupdate */
+       checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auto_update));
+       modest_conf_set_bool (conf, MODEST_CONF_AUTO_UPDATE, checked, NULL);
+
+       /* Connected by */
+       combo_id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->connect_via));
+       modest_conf_set_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, *combo_id, NULL);
+
+       /* Update interval */
+       combo_id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->update_interval));
+       modest_conf_set_int (conf, MODEST_CONF_UPDATE_INTERVAL, *combo_id, NULL);
+
+       /* Size limit */        
+       /* It's better to do this in the subclasses, but it's just one
+          line, so we'll leave it here for the moment */
+#ifdef MODEST_PLATFORM_MAEMO
+       value = hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (priv->size_limit));
+#else
+       value = gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit);
+#endif
+       modest_conf_set_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, value, NULL);
+
+       /* Play sound */
+       checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->play_sound));
+       modest_conf_set_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, checked, NULL);
+
+       /* Msg format */
+       combo_id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->msg_format));
+       modest_conf_set_int (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, *combo_id, NULL);
+
+       /* Include reply */
+       checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->include_reply));
+       modest_conf_set_int (conf, MODEST_CONF_REPLY_TYPE, 
+                            (checked) ? MODEST_TNY_MSG_REPLY_TYPE_QUOTE : 
+                            MODEST_TNY_MSG_REPLY_TYPE_CITE, NULL);
+}
+
+static void
+on_response (GtkDialog *dialog,
+            gint arg1,
+            gpointer user_data)
+{
+       ModestGlobalSettingsDialogPrivate *priv;
+
+       priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data);
+
+       if (arg1 == GTK_RESPONSE_OK)
+               _modest_global_settings_dialog_save_conf (priv);
+}