+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):
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)) {
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);
}
#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)
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;
}
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;
}
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;
}