2007-05-24 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Thu, 24 May 2007 10:40:39 +0000 (10:40 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Thu, 24 May 2007 10:40:39 +0000 (10:40 +0000)
* src/modest-account-mgr-helpers.c:
        (modest_account_mgr_get_default_account): Make sure that at least
        one account is always the default, if there are any enabled accounts.
        This is just a sanity check that shouldn't be necessary.

        * src/modest-account-mgr-priv.c:
        (_modest_account_mgr_account_from_key): Unescape the conf key to
        get the real account name. For instance, this is an issue if a space
        was in the account name, which can happen because the account name
        is generated from the display name.
        (_modest_account_mgr_get_account_keyname): Always escape the
        account name.
        * src/modest-account-mgr.c: (modest_account_mgr_account_names):
        Unescape the conf keys to get the real account names.

        For instance, previously the is-default radio button in the accounts
        list was not checked for any accounts at first. This fixes that,
        and might fix several similar bugs.

pmo-trunk-r1968

ChangeLog2
src/modest-account-mgr-helpers.c
src/modest-account-mgr-priv.c
src/modest-account-mgr.c

index 0186523..54946f1 100644 (file)
@@ -1,3 +1,24 @@
+2007-05-24  Murray Cumming  <murrayc@murrayc.com>
+
+       * src/modest-account-mgr-helpers.c:
+       (modest_account_mgr_get_default_account): Make sure that at least 
+       one account is always the default, if there are any enabled accounts. 
+       This is just a sanity check that shouldn't be necessary.
+       
+       * src/modest-account-mgr-priv.c:
+       (_modest_account_mgr_account_from_key): Unescape the conf key to 
+       get the real account name. For instance, this is an issue if a space 
+       was in the account name, which can happen because the account name 
+       is generated from the display name.
+       (_modest_account_mgr_get_account_keyname): Always escape the 
+       account name.
+       * src/modest-account-mgr.c: (modest_account_mgr_account_names): 
+       Unescape the conf keys to get the real account names.
+       
+       For instance, previously the is-default radio button in the accounts 
+       list was not checked for any accounts at first. This fixes that,
+       and might fix several similar bugs.
+
 2007-05-23  Murray Cumming  <murrayc@murrayc.com>
 
        * src/modest-ui-actions.c: (set_active_account_from_tny_account):
index c994b55..47a343c 100644 (file)
@@ -491,9 +491,12 @@ modest_account_mgr_get_default_account  (ModestAccountMgr *self)
                return  NULL;
        }
        
-       /* it's not really an error if there is no default account */
-       if (!account) 
-               return NULL;
+       /* Make sure that at least one account is always the default, if possible:
+        * (It would be meaningless to have enabled accounts but no default account. */
+       if (!account) {
+               modest_account_mgr_set_first_account_as_default (self);
+               account = modest_conf_get_string (conf, MODEST_CONF_DEFAULT_ACCOUNT, &err);
+       }
 
        /* sanity check */
        if (!modest_account_mgr_account_exists (self, account, FALSE)) {
@@ -553,7 +556,7 @@ modest_account_mgr_set_first_account_as_default  (ModestAccountMgr *self)
        if(list_sorted)
        {
                const gchar* account_name = (const gchar*)list_sorted->data;
-               if (account_name)
+               if (account_name) 
                        result = modest_account_mgr_set_default_account (self, account_name);
        }
        
index a3607e7..d0c80f6 100644 (file)
@@ -32,6 +32,7 @@
 #include <modest-defs.h>
 #include <string.h>
 #include <modest-conf.h>
+#include <stdio.h>
 
 gchar*
 _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account)
@@ -78,7 +79,13 @@ _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key
        if (cursor)
                *cursor = '\0';
 
-       return account;
+       if (account) {
+               /* The key is an escaped string, so unescape it to get the actual account name: */
+               gchar *unescaped_name = modest_conf_key_unescape (account);
+               g_free (account);
+               return unescaped_name;
+       } else
+               return NULL;
 }
 
 
@@ -87,32 +94,31 @@ _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key
 gchar *
 _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account)
 {
-       gchar *namespace;
-       gchar *retval;
+       gchar *retval = NULL;
        
-       namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
+       gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
        
        if (!account_name)
                return g_strdup (namespace);
        
-       if (name)
-               retval = g_strconcat (namespace, "/", account_name, "/", name, NULL);
-       else
-               retval = g_strconcat (namespace, "/", account_name, NULL);
+       /* Always escape the conf keys, so that it is acceptable to gconf: */
+       gchar *escaped_account_name = account_name ? modest_conf_key_escape (account_name) : NULL;
+       gchar *escaped_name =  name ? modest_conf_key_escape (name) : NULL;
 
-       /* special case: the key has some weird characters */
-       if (!modest_conf_key_is_valid (retval)) {
+       if (escaped_account_name && escaped_name)
+               retval = g_strconcat (namespace, "/", escaped_account_name, "/", escaped_name, NULL);
+       else if (escaped_account_name)
+               retval = g_strconcat (namespace, "/", escaped_account_name, NULL);
 
-               gchar *account_name_esc, *name_esc;
+       /* Sanity check: */
+       if (!modest_conf_key_is_valid (retval)) {
+               g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__, retval);
                g_free (retval);
-               
-               account_name_esc = account_name ? modest_conf_key_escape (account_name) : NULL;
-               name_esc         = name ? modest_conf_key_escape (name) : NULL;
-               
-               retval =  _modest_account_mgr_get_account_keyname (account_name_esc, name_esc, server_account);
-
-               g_free (account_name_esc);
-               g_free (name_esc);
+               retval = NULL;
        }
+
+       g_free (escaped_name);
+       g_free (escaped_account_name);
+
        return retval;
 }
index d1a4e7e..a6e4509 100644 (file)
@@ -627,27 +627,40 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled
                
        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;
 }