+ priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+ conf = modest_runtime_get_conf ();
+
+ 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_bool (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, current_state.prefer_formatted_text, NULL);
+ RETURN_FALSE_ON_ERROR(error);
+ if (current_state.default_account &&
+ (!priv->initial_state.default_account ||
+ strcmp (current_state.default_account, priv->initial_state.default_account)!= 0)) {
+ modest_account_mgr_set_default_account (modest_runtime_get_account_mgr (),
+ current_state.default_account);
+ }
+
+ /* Apply changes */
+ if (priv->initial_state.auto_update != current_state.auto_update ||
+ priv->initial_state.connect_via != current_state.connect_via ||
+ priv->initial_state.update_interval != current_state.update_interval) {
+
+ TnyAccountStore *account_store;
+ TnyDevice *device;
+
+ if (!current_state.auto_update) {
+ modest_platform_set_update_interval (0);
+ /* To avoid a new indentation level */
+ goto exit;
+ }
+
+ account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
+ device = tny_account_store_get_device (account_store);
+
+ if (tny_device_is_online (device)) {
+ /* If connected via any then set update interval */
+ if (current_state.connect_via == MODEST_CONNECTED_VIA_ANY) {
+ modest_platform_set_update_interval (current_state.update_interval);
+ } else {
+ /* Set update interval only if we
+ selected the same connect_via
+ method than the one already used by
+ the device */
+ ModestConnectedVia connect_via =
+ MODEST_GLOBAL_SETTINGS_DIALOG_GET_CLASS(self)->current_connection_func ();
+
+ if (current_state.connect_via == connect_via)
+ modest_platform_set_update_interval (current_state.update_interval);
+ else
+ modest_platform_set_update_interval (0);
+ }
+ } else {
+ /* Disable autoupdate in offline mode */
+ modest_platform_set_update_interval (0);
+ }
+ g_object_unref (device);
+ }
+
+exit:
+ 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.prefer_formatted_text != current_state.prefer_formatted_text ||
+ (current_state.default_account &&
+ (!initial_state.default_account ||
+ strcmp (current_state.default_account, initial_state.default_account)!= 0)))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static gboolean
+on_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ ModestGlobalSettingsDialogPrivate *priv;
+ ModestGlobalSettingsState current_state;
+
+ priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data);
+
+ /* If settings changed, them the response method already asked
+ the user, because it's always executed before (see
+ GtkDialog code). If it's not then simply close */
+ get_current_settings (priv, ¤t_state);
+ return settings_changed (priv->initial_state, current_state);
+}
+
+static void
+on_response (GtkDialog *dialog,
+ gint arg1,
+ gpointer user_data)
+{
+ ModestGlobalSettingsDialogPrivate *priv;
+ ModestGlobalSettingsState current_state = {0,};
+ gboolean changed = FALSE;
+
+ priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data);
+
+ 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_settings (MODEST_GLOBAL_SETTINGS_DIALOG (dialog));
+ if (saved) {
+ modest_platform_information_banner (NULL, NULL,
+ _("mcen_ib_advsetup_settings_saved"));
+ } else {
+ modest_platform_information_banner (NULL, NULL,
+ _("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_OK)
+ g_signal_stop_emission_by_name (user_data, "response");
+ }
+ }
+}
+
+static ModestConnectedVia
+current_connection_default (void)
+{
+ g_warning ("You must implement %s", __FUNCTION__);
+ g_return_val_if_reached (MODEST_CONNECTED_VIA_ANY);
+}
+
+gboolean
+modest_global_settings_dialog_save_settings (ModestGlobalSettingsDialog *self)
+{
+ g_return_val_if_fail (MODEST_IS_GLOBAL_SETTINGS_DIALOG (self), FALSE);