2007-04-17 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-account-mgr.c
index e6859df..82dd892 100644 (file)
@@ -407,19 +407,20 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
                   supported */
                key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_OPTIONS, TRUE);
                /* Enable subscriptions and check the mails in all folders */
-               option_list = g_slist_append (option_list, "use_lsub");
-               option_list = g_slist_append (option_list, "check_all");
+               option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_USE_LSUB);
+               option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_CHECK_ALL);
+
                /* Security options */
                switch (security) {
                case MODEST_PROTOCOL_SECURITY_NONE:
-                       option_list = g_slist_append (option_list, "use_ssl=never");
+                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER);
                        break;
                case MODEST_PROTOCOL_SECURITY_SSL:
                case MODEST_PROTOCOL_SECURITY_TLS:
-                       option_list = g_slist_append (option_list, "use_ssl=always");
+                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS);
                        break;
                case MODEST_PROTOCOL_SECURITY_TLS_OP:
-                       option_list = g_slist_append (option_list, "use_ssl=when-possible");
+                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE);
                        break;
                default:
                        g_warning ("Invalid security option");
@@ -504,6 +505,31 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                return FALSE;
        }
 
+       /* in case we're not deleting an account, also delete the dependent store and transport account */
+       if (!server_account) {
+               gchar *server_account_name;
+               
+               server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_STORE_ACCOUNT,
+                                                                   FALSE);
+               if (server_account_name) {
+                       if (!modest_account_mgr_remove_account (self, server_account_name, TRUE))
+                               g_printerr ("modest: failed to remove store account '%s' (%s)\n",
+                                           server_account_name, name);
+                       g_free (server_account_name);
+               } else
+                       g_printerr ("modest: could not find the store account for %s\n", name);
+               
+               server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_TRANSPORT_ACCOUNT,
+                                                                   FALSE);
+               if (server_account_name) {
+                       if (!modest_account_mgr_remove_account (self, server_account_name, TRUE))
+                               g_printerr ("modest: failed to remove transport account '%s' (%s)\n",
+                                           server_account_name, name);
+                       g_free (server_account_name);
+               } else
+                       g_printerr ("modest: could not find the transport account for %s\n", name);
+       }                       
+                       
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        key = _modest_account_mgr_get_account_keyname (name, NULL, server_account);
        
@@ -910,6 +936,40 @@ modest_account_mgr_account_exists (ModestAccountMgr * self, const gchar * name,
        return retval;
 }
 
+gboolean       modest_account_mgr_account_with_display_name_exists       (ModestAccountMgr *self,
+                                                          const gchar *display_name)
+{
+       GSList *account_names = NULL;
+       GSList *cursor = NULL;
+       
+       cursor = account_names = modest_account_mgr_account_names (self);
+
+       gboolean found = FALSE;
+       
+       /* Look at each non-server account to check their display names; */
+       while (cursor) {
+               const gchar * account_name = (gchar*)cursor->data;
+               
+               ModestAccountData *account_data = modest_account_mgr_get_account_data (self, account_name);
+               if (!account_data) {
+                       g_printerr ("modest: failed to get account data for %s\n", account_name);
+                       continue;
+               }
+
+               if(account_data->display_name && (strcmp (account_data->display_name, display_name) == 0)) {
+                       found = TRUE;
+                       break;
+               }
+
+               modest_account_mgr_free_account_data (self, account_data);
+               cursor = cursor->next;
+       }
+       g_slist_free (account_names);
+       
+       return found;
+}
+
+
 
 
 gboolean