* Added global settings persistence
[modest] / src / modest-account-mgr.c
index 735ab8e..b051201 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);
@@ -399,47 +398,6 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
                goto cleanup;
 
        if (proto_type == MODEST_PROTOCOL_TYPE_STORE) {
-
-               GSList *option_list = NULL;
-
-               /* Connection options. Some options are only valid for IMAP
-                  accounts but it's OK for just now since POP is still not
-                  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, 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:
-                       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, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS);
-                       break;
-               case MODEST_PROTOCOL_SECURITY_TLS_OP:
-                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE);
-                       break;
-               default:
-                       g_warning ("Invalid security option");
-               }
-               ok = modest_conf_set_list (priv->modest_conf, key, 
-                                          option_list, MODEST_CONF_VALUE_STRING, &err);
-               if (err) {
-                       g_printerr ("modest: failed to set %s: %s\n", key, err->message);
-                       g_error_free (err);
-                       ok = FALSE;
-               }
-               g_slist_free (option_list);
-               g_free (key);
-               
-               
                /* Add the security settings: */
                modest_server_account_set_security (self, name, security);
        }
@@ -640,7 +598,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;
@@ -662,7 +620,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;
 }
 
 
@@ -958,7 +941,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;