* src/modest-ui-actions.c:
[modest] / src / modest-account-mgr.c
index 82dd892..99d40ef 100644 (file)
@@ -53,15 +53,10 @@ static guint signals[LAST_SIGNAL] = {0};
 static void
 on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data)
 {
-       ModestAccountMgr *self;
-       ModestAccountMgrPrivate *priv;
-
-       gchar *account;
-       gboolean is_account_key, is_server_account;
-       gboolean enabled;
-
-       self = MODEST_ACCOUNT_MGR (user_data);
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       /* printf("DEBUG: %s: key=%s\n", __FUNCTION__, key); */
+       
+       ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data);
+       /* ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); */
 
        /* there is only one not-really-account key which will still emit
         * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT */
@@ -74,7 +69,9 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
                return;
        }
        
-       account = _modest_account_mgr_account_from_key (key, &is_account_key, &is_server_account);
+       gboolean is_account_key = FALSE;
+       gboolean is_server_account = FALSE;
+       gchar* account = _modest_account_mgr_account_from_key (key, &is_account_key, &is_server_account);
        
        /* if this is not an account-related key change, ignore */
        if (!account)
@@ -89,13 +86,14 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
        }
 
        /* is this account enabled? */
+       gboolean enabled = FALSE;
        if (is_server_account)
                enabled = TRUE;
        else 
                enabled = modest_account_mgr_get_enabled (self, account);
 
-       /* server account was changed, default account was changed
-        * and always notify when enabled/disabled changes
+       /* Notify is server account was changed, default account was changed
+        * or when enabled/disabled changes:
         */
        if (enabled ||
            g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) ||
@@ -222,7 +220,8 @@ gboolean
 modest_account_mgr_add_account (ModestAccountMgr *self,
                                const gchar *name,
                                const gchar *store_account,
-                               const gchar *transport_account)
+                               const gchar *transport_account,
+                               gboolean enabled)
 {
        ModestAccountMgrPrivate *priv;
        gchar *key;
@@ -289,7 +288,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
                        return FALSE;
                }
        }
-       modest_account_mgr_set_enabled (self, name, TRUE);
+       modest_account_mgr_set_enabled (self, name, enabled);
 
        /* if no default account has been defined yet, do so now */
        default_account = modest_account_mgr_get_default_account (self);
@@ -410,6 +409,10 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
                option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_USE_LSUB);
                option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_CHECK_ALL);
 
+               /* TODO: Remove this hack. These are hard-coded camel options to make the connection work.
+                * The regular connection options (set later here) should be interpreted instead 
+                * because in future these camel options will not be in gconf. murrayc.
+                */
                /* Security options */
                switch (security) {
                case MODEST_PROTOCOL_SECURITY_NONE:
@@ -434,6 +437,10 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
                }
                g_slist_free (option_list);
                g_free (key);
+               
+               
+               /* Add the security settings: */
+               modest_server_account_set_security (self, name, security);
        }
 
 cleanup:
@@ -540,6 +547,14 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                g_printerr ("modest: error removing key: %s\n", err->message);
                g_error_free (err);
        }
+
+       /* If this was the default, then remove that setting: */
+       if (!server_account) {
+               gchar *default_account_name = modest_account_mgr_get_default_account (self);
+               if (default_account_name && (strcmp (default_account_name, name) == 0))
+                       modest_account_mgr_unset_default_account (self);
+               g_free (default_account_name);
+       }
        
        return retval;
 }
@@ -624,7 +639,7 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
 
 
 GSList*
-modest_account_mgr_account_names (ModestAccountMgr * self)
+modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled)
 {
        GSList *accounts;
        ModestAccountMgrPrivate *priv;
@@ -646,7 +661,32 @@ modest_account_mgr_account_names (ModestAccountMgr * self)
        }
        
        strip_prefix_from_elements (accounts, prefix_len);
-       return accounts;
+               
+       GSList *result = NULL;
+       
+       /* Filter-out the disabled accounts if requested: */
+       if (only_enabled) {
+               GSList *iter = accounts;
+               while (iter) {
+                       if (!(iter->data))
+                               continue;
+                               
+                       const gchar* account_name = (const gchar*)iter->data;
+                       if (account_name && modest_account_mgr_get_enabled (self, account_name))
+                               result = g_slist_append (result, g_strdup (account_name));
+                               
+                       iter = g_slist_next (iter);     
+               }
+               
+               /* TODO: Free the strings too? */
+               g_slist_free (accounts);
+               accounts = NULL;
+       }
+       else
+               result = accounts;
+       
+
+       return result;
 }
 
 
@@ -942,7 +982,8 @@ gboolean    modest_account_mgr_account_with_display_name_exists       (ModestAccountMgr
        GSList *account_names = NULL;
        GSList *cursor = NULL;
        
-       cursor = account_names = modest_account_mgr_account_names (self);
+       cursor = account_names = modest_account_mgr_account_names (self, 
+               TRUE /* enabled accounts, because disabled accounts are not user visible. */);
 
        gboolean found = FALSE;