* src/modest-ui-actions.c:
[modest] / src / modest-account-mgr-helpers.c
index 6be7d5c..927105e 100644 (file)
@@ -57,6 +57,13 @@ gboolean modest_account_mgr_set_signature (ModestAccountMgr *self, const gchar*
        return result;
 }
 
+gchar* modest_account_mgr_get_display_name (ModestAccountMgr *self, 
+       const gchar* name)
+{
+       return modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_DISPLAY_NAME, FALSE);
+}
+
+
 
 gchar* modest_account_mgr_get_signature (ModestAccountMgr *self, const gchar* name, 
        gboolean* use_signature)
@@ -244,7 +251,63 @@ gchar* modest_account_mgr_get_connection_specific_smtp (ModestAccountMgr *self,
        return result;
 }
                                         
-                                        
+gchar*
+modest_server_account_get_username (ModestAccountMgr *self, const gchar* account_name)
+{
+       return modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_USERNAME, 
+               TRUE /* server account */);
+}
+
+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
+modest_server_account_set_password (ModestAccountMgr *self, const gchar* account_name, 
+       const gchar* password)
+{
+       modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_PASSWORD, 
+               password, TRUE /* server account */);
+}
+       
+gchar*
+modest_server_account_get_hostname (ModestAccountMgr *self, const gchar* account_name)
+{
+       return modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_HOSTNAME, 
+               TRUE /* server account */);
+}
 
 static ModestProtocol
 get_secure_auth_for_conf_string(const gchar* value)
@@ -581,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);
-       if(account_names)
+       GSList *account_names = modest_account_mgr_account_names (self, TRUE /* only enabled */);
+       
+       /* 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);
        }