* update for the modest-protocol-info changes
[modest] / src / modest-account-mgr.c
index ba553d8..b0b7910 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) ||
@@ -309,22 +307,17 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
                                       const gchar * name, const gchar *hostname,
                                       const gchar * username, const gchar * password,
                                       ModestProtocol proto,
-                                      ModestProtocol security,
-                                      ModestProtocol auth)
+                                      ModestConnectionProtocol security,
+                                      ModestAuthProtocol auth)
 {
        ModestAccountMgrPrivate *priv;
        gchar *key;
-       ModestProtocolType proto_type;
        gboolean ok = TRUE;
        GError *err = NULL;
        
        g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
        g_return_val_if_fail (name, FALSE);
        g_return_val_if_fail (strchr(name, '/') == NULL, FALSE);
-
-       proto_type = modest_protocol_info_get_protocol_type (proto);
-       g_return_val_if_fail (proto_type == MODEST_PROTOCOL_TYPE_TRANSPORT ||
-                             proto_type == MODEST_PROTOCOL_TYPE_STORE, FALSE);
                              
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        
@@ -376,7 +369,9 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        /* proto */
        key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_PROTO, TRUE);
        ok = modest_conf_set_string (priv->modest_conf, key,
-                                    modest_protocol_info_get_protocol_name(proto), &err);
+                                    modest_protocol_info_get_protocol_name(proto,
+                                                                           MODEST_TRANSPORT_STORE_PROTOCOL),
+                                    &err);
        if (err) {
                g_printerr ("modest: failed to set %s: %s\n", key, err->message);
                g_error_free (err);
@@ -389,7 +384,9 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        /* auth mechanism */
        key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_AUTH_MECH, TRUE);
        ok = modest_conf_set_string (priv->modest_conf, key,
-                                    modest_protocol_info_get_protocol_name (auth), &err);
+                                    modest_protocol_info_get_protocol_name (auth,
+                                                                            MODEST_AUTH_PROTOCOL),
+                                    &err);
        if (err) {
                g_printerr ("modest: failed to set %s: %s\n", key, err->message);
                g_error_free (err);
@@ -398,53 +395,12 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        g_free (key);
        if (!ok)
                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);
-               
-               
+       
+       if (modest_protocol_info_protocol_is_store(proto)) {
                /* Add the security settings: */
                modest_server_account_set_security (self, name, security);
        }
-
+       
 cleanup:
        if (!ok) {
                g_printerr ("modest: failed to add server account\n");
@@ -454,7 +410,9 @@ cleanup:
        return TRUE;
 }
 
-
+/** modest_account_mgr_add_server_account_uri:
+ * Only used for mbox and maildir accounts.
+ */
 gboolean
 modest_account_mgr_add_server_account_uri (ModestAccountMgr * self,
                                           const gchar *name, ModestProtocol proto,
@@ -475,7 +433,8 @@ modest_account_mgr_add_server_account_uri (ModestAccountMgr * self,
        /* proto */
        key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_PROTO, TRUE);
        ok = modest_conf_set_string (priv->modest_conf, key,
-                                    modest_protocol_info_get_protocol_name(proto), NULL);
+                                    modest_protocol_info_get_protocol_name(proto, MODEST_TRANSPORT_STORE_PROTOCOL),
+                                    NULL);
        g_free (key);
 
        if (!ok) {
@@ -592,13 +551,6 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
        GError *err = NULL;
        
        g_return_val_if_fail (self, NULL);
-
-       if (proto != MODEST_PROTOCOL_UNKNOWN) {
-               ModestProtocolType proto_type;
-               proto_type = modest_protocol_info_get_protocol_type (proto);
-               g_return_val_if_fail (proto_type == MODEST_PROTOCOL_TYPE_TRANSPORT ||
-                                     proto_type == MODEST_PROTOCOL_TYPE_STORE, NULL);
-       }
        
        key      = _modest_account_mgr_get_account_keyname (account_name, NULL, TRUE);
        priv     = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
@@ -619,11 +571,9 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
        while (cursor) { 
                gchar *account   = _modest_account_mgr_account_from_key ((gchar*)cursor->data, NULL, NULL);
                gchar *acc_proto = modest_account_mgr_get_string (self, account, MODEST_ACCOUNT_PROTO,TRUE);
-               ModestProtocol     this_proto = modest_protocol_info_get_protocol (acc_proto);
-               ModestProtocolType this_type  = modest_protocol_info_get_protocol_type (this_proto);
-
-               if ((this_type  != MODEST_PROTOCOL_TYPE_UNKNOWN && this_type  != type) ||
-                   (this_proto != MODEST_PROTOCOL_UNKNOWN      && this_proto != proto)) {
+               ModestProtocol     this_proto = modest_protocol_info_get_protocol (acc_proto,
+                                                                                  MODEST_TRANSPORT_STORE_PROTOCOL);
+               if (this_proto != MODEST_PROTOCOL_UNKNOWN && this_proto != proto) {
                        GSList *nxt = cursor->next;
                        accounts = g_slist_delete_link (accounts, cursor);
                        cursor = nxt;