Fix for NB#88031:
authorJose Dapena Paz <jdapena@igalia.com>
Wed, 17 Sep 2008 15:10:58 +0000 (15:10 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 17 Sep 2008 15:10:58 +0000 (15:10 +0000)
* 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

src/maemo/easysetup/modest-easysetup-wizard-dialog.c
src/modest-account-mgr.c
src/modest-account-mgr.h

index eee0903..d550624 100644 (file)
@@ -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);
        }
        
index 6c5f320..65536cb 100644 (file)
@@ -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;
+}
+
 
 
 
index e2e4a6d..5edea62 100644 (file)
@@ -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