From d8ac0c31f8a4e72a97c6e8676bd6db188f631b73 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Wed, 17 Sep 2008 15:10:58 +0000 Subject: [PATCH] Fix for NB#88031: * src/modest-account-mgr.[ch]: added method to check if there's already an store account with the same login, hostname and port as the one we're trying to add to account manager. * src/maemo/easysetup/modest-easysetup-wizard-dialog.c: now we check also on trying to save the account if there's already an account with the same setup data. We prevent as we don't want two modest accounts using the same cache. pmo-trunk-r5606 --- .../easysetup/modest-easysetup-wizard-dialog.c | 7 ++ src/modest-account-mgr.c | 82 ++++++++++++++++++++ src/modest-account-mgr.h | 12 +++ 3 files changed, 101 insertions(+) diff --git a/src/maemo/easysetup/modest-easysetup-wizard-dialog.c b/src/maemo/easysetup/modest-easysetup-wizard-dialog.c index eee0903..d550624 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard-dialog.c +++ b/src/maemo/easysetup/modest-easysetup-wizard-dialog.c @@ -1621,6 +1621,13 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget * if (priv->pending_load_settings) { save_to_settings (self); } + + /* We check if there's already another account with the same configuration */ + if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) { + modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed")); + return FALSE; + } + modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings); } diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 6c5f320..65536cb 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -1141,6 +1141,88 @@ modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self, return found; } +static gboolean +server_accounts_equal (ModestServerAccountSettings *s1, + ModestServerAccountSettings *s2) +{ + const gchar *str1, *str2; + + if (modest_server_account_settings_get_protocol (s1) != + modest_server_account_settings_get_protocol (s2)) + return FALSE; + + str1 = modest_server_account_settings_get_username (s1); + str2 = modest_server_account_settings_get_username (s2); + if (str1 && str2 && (str1 != str2) && + strcmp (str1, str2) != 0) + return FALSE; + + str1 = modest_server_account_settings_get_hostname (s1); + str2 = modest_server_account_settings_get_hostname (s2); + if (str1 && str2 && (str1 != str2) && + strcmp (str1, str2) != 0) + return FALSE; + + if (modest_server_account_settings_get_port (s1) != + modest_server_account_settings_get_port (s2)) + return FALSE; + + return TRUE; +} + +gboolean +modest_account_mgr_check_already_configured_account (ModestAccountMgr *self, + ModestAccountSettings *settings) +{ + GSList *account_names = NULL; + GSList *cursor = NULL; + ModestServerAccountSettings *server_settings; + + cursor = account_names = modest_account_mgr_account_names (self, + TRUE /* enabled accounts, because disabled accounts are not user visible. */); + + gboolean found = FALSE; + + server_settings = modest_account_settings_get_store_settings (settings); + if (!server_settings) { + g_printerr ("modest: couldn't get store settings from settings"); + modest_account_mgr_free_account_names (account_names); + return FALSE; + } + + /* Look at each non-server account to check their display names; */ + while (cursor && !found) { + const gchar *account_name; + ModestAccountSettings *from_mgr_settings; + ModestServerAccountSettings *from_mgr_server_settings; + + account_name = (gchar*)cursor->data; + from_mgr_settings = modest_account_mgr_load_account_settings (self, account_name); + if (!settings) { + g_printerr ("modest: failed to get account data for %s\n", account_name); + continue; + } + + from_mgr_server_settings = modest_account_settings_get_store_settings (from_mgr_settings); + if (server_settings) { + if (server_accounts_equal (from_mgr_server_settings, server_settings)) { + found = TRUE; + } + g_object_unref (from_mgr_server_settings); + } else { + g_printerr ("modest: couldn't get store settings from account %s", account_name); + } + g_object_unref (from_mgr_settings); + cursor = cursor->next; + } + + g_object_unref (server_settings); + modest_account_mgr_free_account_names (account_names); + account_names = NULL; + + return found; +} + diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index e2e4a6d..5edea62 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -253,6 +253,18 @@ gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr * const gchar *display_name); /** + * modest_account_mgr_check_already_configured_account: + * @self: a #ModestAccountMgr + * @settings: a #ModestAccountSettings *settings + * + * Checks if there's already an active store account with the same settings + * + * Returns: %TRUE if account setup exists + */ +gboolean modest_account_mgr_check_already_configured_account (ModestAccountMgr * self, + ModestAccountSettings *settings); + +/** * modest_account_mgr_unset: * @self: a ModestAccountMgr instance * @name: the name of the account -- 1.7.9.5