2007-06-05 Murray Cumming <murrayc@murrayc.com>modest/trunk] > more ChangeLog2
[modest] / src / modest-account-mgr.c
index b0b7910..7fef539 100644 (file)
@@ -251,7 +251,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
        if (!ok) {
                g_printerr ("modest: cannot set display name\n");
                if (err) {
        if (!ok) {
                g_printerr ("modest: cannot set display name\n");
                if (err) {
-                       g_printerr ("modest: %s\n", err->message);
+                       g_printerr ("modest: Error adding account conf: %s\n", err->message);
                        g_error_free (err);
                }
                return FALSE;
                        g_error_free (err);
                }
                return FALSE;
@@ -265,7 +265,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
                        g_printerr ("modest: failed to set store account '%s'\n",
                                store_account);
                        if (err) {
                        g_printerr ("modest: failed to set store account '%s'\n",
                                store_account);
                        if (err) {
-                               g_printerr ("modest: %s\n", err->message);
+                               g_printerr ("modest: Error adding store account conf: %s\n", err->message);
                                g_error_free (err);
                        }
                        
                                g_error_free (err);
                        }
                        
@@ -282,12 +282,20 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
                        g_printerr ("modest: failed to set transport account '%s'\n",
                                    transport_account);
                        if (err) {
                        g_printerr ("modest: failed to set transport account '%s'\n",
                                    transport_account);
                        if (err) {
-                               g_printerr ("modest: %s\n", err->message);
+                               g_printerr ("modest: Error adding transport account conf: %s\n", err->message);
                                g_error_free (err);
                        }       
                        return FALSE;
                }
        }
                                g_error_free (err);
                        }       
                        return FALSE;
                }
        }
+
+       /* Make sure that leave-messages-on-server is enabled by default, 
+        * as per the UI spec, though it is only meaningful for accounts using POP.
+        * (possibly this gconf key should be under the server account): */
+       modest_account_mgr_set_bool (self, name,
+               MODEST_ACCOUNT_LEAVE_ON_SERVER, TRUE, FALSE /* not server account */);
+
+
        modest_account_mgr_set_enabled (self, name, enabled);
 
        /* if no default account has been defined yet, do so now */
        modest_account_mgr_set_enabled (self, name, enabled);
 
        /* if no default account has been defined yet, do so now */
@@ -305,8 +313,9 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
 gboolean
 modest_account_mgr_add_server_account (ModestAccountMgr * self,
                                       const gchar * name, const gchar *hostname,
 gboolean
 modest_account_mgr_add_server_account (ModestAccountMgr * self,
                                       const gchar * name, const gchar *hostname,
+                                      guint portnumber,
                                       const gchar * username, const gchar * password,
                                       const gchar * username, const gchar * password,
-                                      ModestProtocol proto,
+                                      ModestTransportStoreProtocol proto,
                                       ModestConnectionProtocol security,
                                       ModestAuthProtocol auth)
 {
                                       ModestConnectionProtocol security,
                                       ModestAuthProtocol auth)
 {
@@ -369,8 +378,7 @@ 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,
        /* 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,
-                                                                           MODEST_TRANSPORT_STORE_PROTOCOL),
+                                    modest_protocol_info_get_transport_store_protocol_name(proto),
                                     &err);
        if (err) {
                g_printerr ("modest: failed to set %s: %s\n", key, err->message);
                                     &err);
        if (err) {
                g_printerr ("modest: failed to set %s: %s\n", key, err->message);
@@ -381,11 +389,24 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        if (!ok)
                goto cleanup;
 
        if (!ok)
                goto cleanup;
 
+
+       /* portnumber */
+       key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_PORT, TRUE);
+       ok = modest_conf_set_int (priv->modest_conf, key, portnumber, &err);
+       if (err) {
+               g_printerr ("modest: failed to set %s: %s\n", key, err->message);
+               g_error_free (err);
+               ok = FALSE;
+       }
+       g_free (key);
+       if (!ok)
+               goto cleanup;
+
+       
        /* auth mechanism */
        key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_AUTH_MECH, TRUE);
        ok = modest_conf_set_string (priv->modest_conf, key,
        /* 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,
-                                                                            MODEST_AUTH_PROTOCOL),
+                                    modest_protocol_info_get_auth_protocol_name (auth),
                                     &err);
        if (err) {
                g_printerr ("modest: failed to set %s: %s\n", key, err->message);
                                     &err);
        if (err) {
                g_printerr ("modest: failed to set %s: %s\n", key, err->message);
@@ -396,10 +417,8 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        if (!ok)
                goto cleanup;
        
        if (!ok)
                goto cleanup;
        
-       if (modest_protocol_info_protocol_is_store(proto)) {
-               /* Add the security settings: */
-               modest_server_account_set_security (self, name, security);
-       }
+       /* Add the security settings: */
+       modest_server_account_set_security (self, name, security);
        
 cleanup:
        if (!ok) {
        
 cleanup:
        if (!ok) {
@@ -415,7 +434,7 @@ cleanup:
  */
 gboolean
 modest_account_mgr_add_server_account_uri (ModestAccountMgr * self,
  */
 gboolean
 modest_account_mgr_add_server_account_uri (ModestAccountMgr * self,
-                                          const gchar *name, ModestProtocol proto,
+                                          const gchar *name, ModestTransportStoreProtocol proto,
                                           const gchar *uri)
 {
        ModestAccountMgrPrivate *priv;
                                           const gchar *uri)
 {
        ModestAccountMgrPrivate *priv;
@@ -433,7 +452,7 @@ 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,
        /* 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, MODEST_TRANSPORT_STORE_PROTOCOL),
+                                    modest_protocol_info_get_transport_store_protocol_name(proto),
                                     NULL);
        g_free (key);
 
                                     NULL);
        g_free (key);
 
@@ -469,7 +488,7 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
        g_return_val_if_fail (name, FALSE);
 
        if (!modest_account_mgr_account_exists (self, name, server_account)) {
        g_return_val_if_fail (name, FALSE);
 
        if (!modest_account_mgr_account_exists (self, name, server_account)) {
-               g_printerr ("modest: account '%s' does not exist\n", name);
+               g_printerr ("modest: %s: account '%s' does not exist\n", __FUNCTION__, name);
                return FALSE;
        }
 
                return FALSE;
        }
 
@@ -537,12 +556,12 @@ strip_prefix_from_elements (GSList * lst, guint n)
        }
 }
 
        }
 }
 
-
+#if 0
+/* Not used. */
 GSList*
 modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
                                           const gchar * account_name,
 GSList*
 modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
                                           const gchar * account_name,
-                                          ModestProtocolType type,
-                                          ModestProtocol proto)
+                                          ModestTransportStoreProtocol proto)
 {
        GSList *accounts;
        GSList *cursor;
 {
        GSList *accounts;
        GSList *cursor;
@@ -571,9 +590,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);
        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,
-                                                                                  MODEST_TRANSPORT_STORE_PROTOCOL);
-               if (this_proto != MODEST_PROTOCOL_UNKNOWN && this_proto != proto) {
+               ModestTransportStoreProtocol this_proto = 
+                       modest_protocol_info_get_transport_store_protocol (acc_proto);
+               if (this_proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN && this_proto != proto) {
                        GSList *nxt = cursor->next;
                        accounts = g_slist_delete_link (accounts, cursor);
                        cursor = nxt;
                        GSList *nxt = cursor->next;
                        accounts = g_slist_delete_link (accounts, cursor);
                        cursor = nxt;
@@ -588,7 +607,7 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
        strip_prefix_from_elements (accounts, strlen(key)+1);
        return accounts;        
 }
        strip_prefix_from_elements (accounts, strlen(key)+1);
        return accounts;        
 }
-
+#endif
 
 GSList*
 modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled)
 
 GSList*
 modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled)
@@ -616,27 +635,40 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled
                
        GSList *result = NULL;
        
                
        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);     
+       /* Unescape the keys to get the account names: */
+       GSList *iter = accounts;
+       while (iter) {
+               if (!(iter->data))
+                       continue;
+                       
+               const gchar* account_name_key = (const gchar*)iter->data;
+               /* printf ("DEBUG: %s: account_name_key=%s\n", __FUNCTION__, account_name_key); */
+               gchar* unescaped_name = account_name_key ? 
+                       modest_conf_key_unescape (account_name_key) 
+                       : NULL;
+               /* printf ("  DEBUG: %s: unescaped name=%s\n", __FUNCTION__, unescaped_name); */
+               
+               gboolean add = TRUE;
+               if (only_enabled) {
+                       if (unescaped_name && 
+                               !modest_account_mgr_get_enabled (self, unescaped_name)) {
+                               add = FALSE;
+                       }
                }
                
                }
                
-               /* TODO: Free the strings too? */
-               g_slist_free (accounts);
-               accounts = NULL;
+               if (add) {      
+                       result = g_slist_append (result, unescaped_name);
+               }
+               else {
+                       g_free (unescaped_name);
+               }
+                       
+               iter = g_slist_next (iter);     
        }
        }
-       else
-               result = accounts;
        
        
+       /* TODO: Free the strings too? */
+       g_slist_free (accounts);
+       accounts = NULL;
 
        return result;
 }
 
        return result;
 }