From 2898ebc01fda4931d8c45e159dd86bd7b18f7315 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Fri, 11 May 2007 10:25:36 +0000 Subject: [PATCH] * Full implementation of the Global settings dialogs UI with all the notifications and error cases pmo-trunk-r1837 --- src/gnome/modest-platform.c | 9 +- src/maemo/modest-maemo-global-settings-dialog.c | 31 ++++- src/maemo/modest-platform.c | 12 +- src/modest-platform.h | 10 +- src/modest-ui-actions.c | 4 +- src/widgets/modest-global-settings-dialog-priv.h | 18 ++- src/widgets/modest-global-settings-dialog.c | 149 +++++++++++++++------- 7 files changed, 154 insertions(+), 79 deletions(-) diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index 4dc60c0..c0a9a21 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -178,15 +178,8 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window, void modest_platform_run_information_dialog (GtkWindow *parent_window, - ModestInformationDialogType type) + const gchar *message) { - switch (type) { - case MODEST_INFORMATION_CREATE_FOLDER: - break; - case MODEST_INFORMATION_DELETE_FOLDER: - break; - }; - /* TODO: implement a information dialog */ } diff --git a/src/maemo/modest-maemo-global-settings-dialog.c b/src/maemo/modest-maemo-global-settings-dialog.c index 5c5e5d8..dabf556 100644 --- a/src/maemo/modest-maemo-global-settings-dialog.c +++ b/src/maemo/modest-maemo-global-settings-dialog.c @@ -69,12 +69,15 @@ enum { LAST_SIGNAL }; -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); +static gboolean on_range_error (HildonNumberEditor *editor, + HildonNumberEditorErrorType type, + gpointer user_data); + +static void on_auto_update_toggled (GtkToggleButton *togglebutton, + gpointer user_data); typedef struct _ModestMaemoGlobalSettingsDialogPrivate ModestMaemoGlobalSettingsDialogPrivate; struct _ModestMaemoGlobalSettingsDialogPrivate { @@ -128,7 +131,6 @@ static void modest_maemo_global_settings_dialog_init (ModestMaemoGlobalSettingsDialog *self) { ModestGlobalSettingsDialogPrivate *ppriv; -/* GdkGeometry *geometry; */ ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self); @@ -189,6 +191,7 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self) NULL, HILDON_CAPTION_MANDATORY); gtk_box_pack_start (GTK_BOX (vbox_update), caption, FALSE, FALSE, MODEST_MARGIN_HALF); + g_signal_connect (ppriv->auto_update, "toggled", G_CALLBACK (on_auto_update_toggled), self); /* Connected via */ list = _modest_global_settings_dialog_get_connected_via (); @@ -287,6 +290,22 @@ create_composing_page (ModestMaemoGlobalSettingsDialog *self) return vbox; } +static void +on_auto_update_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + ModestGlobalSettingsDialogPrivate *ppriv; + GtkWidget *caption; + + ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data); + caption = gtk_widget_get_ancestor (ppriv->connect_via, HILDON_TYPE_CAPTION); + + if (gtk_toggle_button_get_active (togglebutton)) + gtk_widget_set_sensitive (caption, TRUE); + else + gtk_widget_set_sensitive (caption, FALSE); +} + static gboolean on_range_error (HildonNumberEditor *editor, HildonNumberEditorErrorType type, diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index d16e0c0..88a5edf 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -627,19 +627,9 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window, void modest_platform_run_information_dialog (GtkWindow *parent_window, - ModestInformationDialogType type) + const gchar *message) { GtkWidget *dialog; - gchar *message = NULL; - - switch (type) { - case MODEST_INFORMATION_CREATE_FOLDER: - message = _("mail_in_ui_folder_create_error"); - break; - case MODEST_INFORMATION_DELETE_FOLDER: - message = _("mail_in_ui_folder_delete_error"); - break; - }; dialog = hildon_note_new_information (parent_window, message); diff --git a/src/modest-platform.h b/src/modest-platform.h index 46af1e2..e6f94bd 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -39,11 +39,6 @@ typedef enum _ModestConfirmationDialogType { MODEST_CONFIRMATION_DELETE_FOLDER, } ModestConfirmationDialogType; -typedef enum _ModestInformationDialogType { - MODEST_INFORMATION_CREATE_FOLDER, - MODEST_INFORMATION_DELETE_FOLDER, -} ModestInformationDialogType; - typedef enum _ModestSortDialogType { MODEST_SORT_HEADERS, } ModestSortDialogType; @@ -169,12 +164,13 @@ gint modest_platform_run_confirmation_dialog (GtkWindow *parent_window /** * modest_platform_run_information_dialog: * @parent_window: the parent #GtkWindow of the dialog - * @type: the type of information dialog + * @message: the message to show * * shows an information dialog **/ void modest_platform_run_information_dialog (GtkWindow *parent_window, - ModestInformationDialogType type); + const gchar *message); + /** * modest_platform_run_sort_dialog: * @parent_window: the parent #GtkWindow of the dialog diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 77886d7..aeef9aa 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1506,7 +1506,7 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_windo /* /\* suggested_name = X; *\/ */ /* /\* Show error to the user *\/ */ /* modest_platform_run_information_dialog (GTK_WINDOW (main_window), */ -/* MODEST_INFORMATION_CREATE_FOLDER); */ +/* _("mail_in_ui_folder_create_error")); */ /* } */ g_object_unref (mail_op); } @@ -1591,7 +1591,7 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash) /* Show error if happened */ if (modest_mail_operation_get_error (mail_op)) modest_platform_run_information_dialog (GTK_WINDOW (main_window), - MODEST_INFORMATION_DELETE_FOLDER); + _("mail_in_ui_folder_delete_error")); g_object_unref (G_OBJECT (mail_op)); } diff --git a/src/widgets/modest-global-settings-dialog-priv.h b/src/widgets/modest-global-settings-dialog-priv.h index 9ab18c9..ca1f6f5 100644 --- a/src/widgets/modest-global-settings-dialog-priv.h +++ b/src/widgets/modest-global-settings-dialog-priv.h @@ -35,6 +35,16 @@ G_BEGIN_DECLS +typedef struct _ModestGlobalSettingsState { + gboolean auto_update; + gint connect_via; + gint update_interval; + gint size_limit; + gboolean play_sound; + gint msg_format; + gboolean include_reply; +} ModestGlobalSettingsState; + typedef struct _ModestGlobalSettingsDialogPrivate ModestGlobalSettingsDialogPrivate; struct _ModestGlobalSettingsDialogPrivate { GtkWidget *notebook; @@ -48,7 +58,11 @@ struct _ModestGlobalSettingsDialogPrivate { GtkWidget *play_sound; GtkWidget *msg_format; GtkWidget *include_reply; + + gboolean changed; + ModestGlobalSettingsState initial_state; }; + #define MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_GLOBAL_SETTINGS_DIALOG, \ ModestGlobalSettingsDialogPrivate)) @@ -57,8 +71,8 @@ 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); -void _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv); -void _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv); +void _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv); +gboolean _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv); G_END_DECLS diff --git a/src/widgets/modest-global-settings-dialog.c b/src/widgets/modest-global-settings-dialog.c index 8085b48..47ff698 100644 --- a/src/widgets/modest-global-settings-dialog.c +++ b/src/widgets/modest-global-settings-dialog.c @@ -39,6 +39,7 @@ #include "modest-runtime.h" #include "modest-ui-constants.h" #include "modest-tny-msg.h" +#include "modest-platform.h" #include "widgets/modest-combo-box.h" #ifdef MODEST_PLATFORM_MAEMO #ifdef MODEST_HILDON_VERSION_0 @@ -49,6 +50,8 @@ #endif /* include other impl specific header files */ +#define RETURN_FALSE_ON_ERROR(error) if (error) { g_clear_error (&error); return FALSE; } + /* 'private'/'protected' functions */ static void modest_global_settings_dialog_class_init (ModestGlobalSettingsDialogClass *klass); static void modest_global_settings_dialog_init (ModestGlobalSettingsDialog *obj); @@ -57,6 +60,8 @@ static void modest_global_settings_dialog_finalize (GObject *obj); static void on_response (GtkDialog *dialog, gint arg1, gpointer user_data); +static void get_current_settings (ModestGlobalSettingsDialogPrivate *priv, + ModestGlobalSettingsState *state); /* list my signals */ enum { @@ -116,14 +121,14 @@ modest_global_settings_dialog_init (ModestGlobalSettingsDialog *self) priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self); priv->notebook = gtk_notebook_new (); - + priv->changed = FALSE; + /* Add the buttons: */ 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: */ - g_signal_connect (G_OBJECT (self), "response", - G_CALLBACK (on_response), self); + g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self); /* Set title */ gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_options")); @@ -249,6 +254,7 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri checked = FALSE; } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->auto_update), checked); + priv->initial_state.auto_update = checked; /* Connected by */ combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, &error); @@ -259,6 +265,10 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri } modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->connect_via), (gpointer) &combo_id); + priv->initial_state.connect_via = combo_id; + + /* Emit toggled to update the visibility of connect_by caption */ + gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (priv->auto_update)); /* Update interval */ combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_INTERVAL, &error); @@ -269,6 +279,7 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri } modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->update_interval), (gpointer) &combo_id); + priv->initial_state.update_interval = combo_id; /* Size limit */ value = modest_conf_get_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, &error); @@ -282,10 +293,9 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri #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); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit, value)); #endif - - /* TODO Fix with the value */ + priv->initial_state.size_limit = value; /* Play sound */ checked = modest_conf_get_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, &error); @@ -295,6 +305,7 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri checked = FALSE; } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->play_sound), checked); + priv->initial_state.play_sound = checked; /* Msg format */ combo_id = modest_conf_get_int (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, &error); @@ -305,6 +316,7 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri } modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->msg_format), (gpointer) &combo_id); + priv->initial_state.msg_format = combo_id; /* Include reply */ value = modest_conf_get_int (conf, MODEST_CONF_REPLY_TYPE, &error); @@ -318,52 +330,78 @@ _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *pri else checked = FALSE; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->include_reply), checked); + priv->initial_state.include_reply = checked; } -void -_modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv) +static void +get_current_settings (ModestGlobalSettingsDialogPrivate *priv, + ModestGlobalSettingsState *state) { - 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); + gint *id; - /* 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 */ + /* Get values from UI */ + state->auto_update = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auto_update)); + id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->connect_via)); + state->connect_via = *id; #ifdef MODEST_PLATFORM_MAEMO - value = hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (priv->size_limit)); + state->size_limit = hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (priv->size_limit)); #else - value = gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit); + state->size_limit = gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit)); #endif - modest_conf_set_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, value, NULL); + id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->update_interval)); + state->update_interval = *id; + state->play_sound = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->play_sound)); + id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->msg_format)); + state->msg_format = *id; + state->include_reply = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->include_reply)); +} - /* 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); +gboolean +_modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv) +{ + ModestConf *conf; + ModestGlobalSettingsState current_state; + GError *error = 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); + conf = modest_runtime_get_conf (); - /* 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 : + get_current_settings (priv, ¤t_state); + + /* Save configuration */ + modest_conf_set_bool (conf, MODEST_CONF_AUTO_UPDATE, current_state.auto_update, &error); + RETURN_FALSE_ON_ERROR(error); + modest_conf_set_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, current_state.connect_via, NULL); + RETURN_FALSE_ON_ERROR(error); + modest_conf_set_int (conf, MODEST_CONF_UPDATE_INTERVAL, current_state.update_interval, NULL); + RETURN_FALSE_ON_ERROR(error); + modest_conf_set_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, current_state.size_limit, NULL); + RETURN_FALSE_ON_ERROR(error); + modest_conf_set_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, current_state.play_sound, NULL); + RETURN_FALSE_ON_ERROR(error); + modest_conf_set_int (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, current_state.msg_format, NULL); + RETURN_FALSE_ON_ERROR(error); + modest_conf_set_int (conf, MODEST_CONF_REPLY_TYPE, + (current_state.include_reply) ? MODEST_TNY_MSG_REPLY_TYPE_QUOTE : MODEST_TNY_MSG_REPLY_TYPE_CITE, NULL); + RETURN_FALSE_ON_ERROR(error); + + return TRUE; +} + +static gboolean +settings_changed (ModestGlobalSettingsState initial_state, + ModestGlobalSettingsState current_state) +{ + if (initial_state.auto_update != current_state.auto_update || + initial_state.connect_via != current_state.connect_via || + initial_state.update_interval != current_state.update_interval || + initial_state.size_limit != current_state.size_limit || + initial_state.play_sound != current_state.play_sound || + initial_state.msg_format != current_state.msg_format || + initial_state.include_reply != current_state.include_reply) + return TRUE; + else + return FALSE; } static void @@ -372,9 +410,34 @@ on_response (GtkDialog *dialog, gpointer user_data) { ModestGlobalSettingsDialogPrivate *priv; + ModestGlobalSettingsState current_state; + gboolean changed; priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data); - if (arg1 == GTK_RESPONSE_OK) - _modest_global_settings_dialog_save_conf (priv); + get_current_settings (priv, ¤t_state); + changed = settings_changed (priv->initial_state, current_state); + + if (arg1 == GTK_RESPONSE_OK) { + if (changed) { + gboolean saved; + + saved = _modest_global_settings_dialog_save_conf (priv); + if (saved) + modest_platform_run_information_dialog (GTK_WINDOW (user_data), + _("mcen_ib_advsetup_settings_saved")); + else + modest_platform_run_information_dialog (GTK_WINDOW (user_data), + _("mail_ib_setting_failed")); + } + } else { + if (changed) { + gint response; + response = modest_platform_run_confirmation_dialog (GTK_WINDOW (user_data), + _("imum_nc_wizard_confirm_lose_changes")); + /* Do not close if the user Cancels */ + if (response == GTK_RESPONSE_CANCEL) + g_signal_stop_emission_by_name (dialog, "response"); + } + } } -- 1.7.9.5