* src/modest-ui-actions.c:
[modest] / src / modest-account-mgr-helpers.c
index 6f5038d..927105e 100644 (file)
@@ -262,8 +262,35 @@ void
 modest_server_account_set_username (ModestAccountMgr *self, const gchar* account_name, 
        const gchar* username)
 {
+       /* Note that this won't work properly as long as the gconf cache is broken 
+        * in Maemo Bora: */
+       gchar *existing_username = modest_server_account_get_username(self, 
+               account_name);
+       
        modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_USERNAME, 
                username, TRUE /* server account */);
+               
+       /* We don't know anything about new usernames: */
+       if (strcmp (existing_username, username) != 0)
+               modest_server_account_set_username_has_succeeded (self, 
+               account_name, FALSE);
+               
+       g_free (existing_username);
+}
+
+gboolean
+modest_server_account_get_username_has_succeeded (ModestAccountMgr *self, const gchar* account_name)
+{
+       return modest_account_mgr_get_bool (self, account_name, MODEST_ACCOUNT_USERNAME_HAS_SUCCEEDED, 
+               TRUE /* server account */);
+}
+
+void
+modest_server_account_set_username_has_succeeded (ModestAccountMgr *self, const gchar* account_name, 
+       gboolean succeeded)
+{
+       modest_account_mgr_set_bool (self, account_name, MODEST_ACCOUNT_USERNAME_HAS_SUCCEEDED, 
+               succeeded, TRUE /* server account */);
 }
 
 void
@@ -617,14 +644,23 @@ modest_account_mgr_unset_default_account  (ModestAccountMgr *self)
 
 }
 
+gint on_accounts_list_sort_by_title(gconstpointer a, gconstpointer b)
+{
+       return g_utf8_collate((const gchar*)a, (const gchar*)b);
+}
+
 gboolean
 modest_account_mgr_set_first_account_as_default  (ModestAccountMgr *self)
 {
        gboolean result = FALSE;
        GSList *account_names = modest_account_mgr_account_names (self, TRUE /* only enabled */);
-       if(account_names)
+       
+       /* Get the first one, alphabetically, by title: */
+       GSList* list_sorted = g_slist_sort (account_names, 
+               on_accounts_list_sort_by_title);
+       if(list_sorted)
        {
-               const gchar* account_name = (const gchar*)account_names->data;
+               const gchar* account_name = (const gchar*)list_sorted->data;
                if (account_name)
                        result = modest_account_mgr_set_default_account (self, account_name);
        }