* small cosmetic cleanups, leak fix for modest_account_mgr_set_first_account_as_default
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 12 Jun 2007 10:36:32 +0000 (10:36 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 12 Jun 2007 10:36:32 +0000 (10:36 +0000)
pmo-trunk-r2176

src/modest-account-mgr-helpers.c
src/modest-tny-account-store.c
src/modest-tny-account-store.h

index 42eaa1d..5872397 100644 (file)
@@ -240,7 +240,7 @@ 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 */);
+                                           TRUE /* server account */);
 }
 
 void
@@ -248,15 +248,15 @@ modest_server_account_set_username_has_succeeded (ModestAccountMgr *self, const
        gboolean succeeded)
 {
        modest_account_mgr_set_bool (self, account_name, MODEST_ACCOUNT_USERNAME_HAS_SUCCEEDED, 
-               succeeded, TRUE /* server account */);
+                                    succeeded, TRUE /* server account */);
 }
 
 void
 modest_server_account_set_password (ModestAccountMgr *self, const gchar* account_name, 
-       const gchar* password)
+                                   const gchar* password)
 {
        modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_PASSWORD, 
-               password, TRUE /* server account */);
+                                      password, TRUE /* server account */);
 }
        
 gchar*
@@ -527,13 +527,6 @@ modest_account_mgr_get_default_account  (ModestAccountMgr *self)
                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 (account && !modest_account_mgr_account_exists (self, account, FALSE)) {
                g_printerr ("modest: default account does not exist\n");
@@ -556,7 +549,7 @@ modest_account_mgr_set_default_account  (ModestAccountMgr *self, const gchar* ac
                              FALSE);
        
        conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf;
-               
+
        return modest_conf_set_string (conf, MODEST_CONF_DEFAULT_ACCOUNT,
                                       account, NULL);
 
@@ -580,23 +573,29 @@ gint on_accounts_list_sort_by_title(gconstpointer a, gconstpointer b)
        return g_utf8_collate((const gchar*)a, (const gchar*)b);
 }
 
+
+static void
+free_element (gpointer data, gpointer user_data)
+{
+       g_free (data);
+}
+
 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 */);
-       
+               
        /* Get the first one, alphabetically, by title: */
        GSList* list_sorted = g_slist_sort (account_names, 
                on_accounts_list_sort_by_title);
-       if(list_sorted)
-       {
+       if(list_sorted) {
                const gchar* account_name = (const gchar*)list_sorted->data;
                if (account_name) 
                        result = modest_account_mgr_set_default_account (self, account_name);
        }
        
-       /* TODO: Free the strings too? */
+       g_slist_foreach (account_names, free_element, NULL);
        g_slist_free (account_names);
        
        return result;
index 6af53da..fbfaa36 100644 (file)
@@ -325,6 +325,8 @@ on_account_removed (ModestAccountMgr *acc_mgr,
        ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
        TnyAccount *store_account;
 
+       g_warning ("removing account %s", account);
+       
        /* Clear the account cache */
        store_account =
                modest_tny_account_store_get_server_account (self,
@@ -333,8 +335,9 @@ on_account_removed (ModestAccountMgr *acc_mgr,
        if (store_account) {
                tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account));
                g_object_unref (store_account);
-       }
-
+       } else
+               g_printerr ("modest: cannot find server account for %s", account);
+       
        /* FIXME: make this more finegrained; changes do not
         * really affect _all_ accounts, and some do not
         * affect tny accounts at all (such as 'last_update')
@@ -351,6 +354,8 @@ on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account,
 
 {
        ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+
+       g_warning ("updating account %s (%d change(s))", account, g_slist_length((GSList*)keys));
        
        /* Ignore the change if it's a change in the last_updated value */
        if (g_slist_length ((GSList *)keys) == 1 &&
@@ -1173,10 +1178,10 @@ modest_tny_account_store_get_server_account (ModestTnyAccountStore *self,
                }
        } else {
                ModestAccountData *account_data;
-
                account_data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
                if (!account_data) {
-                       g_printerr ("modest: %s: cannot get account data for account '%s'\n", __FUNCTION__, account_name);
+                       g_printerr ("modest: %s: cannot get account data for account '%s'\n", __FUNCTION__,
+                                   account_name);
                        return NULL;
                }
 
@@ -1277,14 +1282,16 @@ modest_tny_account_store_get_transport_account_for_open_connection (ModestTnyAcc
        return account;
 }
 
-gboolean modest_tny_account_is_virtual_local_folders (TnyAccount *self)
+gboolean
+modest_tny_account_is_virtual_local_folders (TnyAccount *self)
 {
        /* We should make this more sophisticated if we ever use ModestTnyLocalFoldersAccount 
         * for anything else. */
        return MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (self);
 }
 
-TnyAccount* modest_tny_account_store_get_local_folders_account (TnyAccountStore *self)
+TnyAccount*
+modest_tny_account_store_get_local_folders_account (TnyAccountStore *self)
 {
        TnyAccount *account = NULL;
        ModestTnyAccountStorePrivate *priv;     
index bb685bc..463c2da 100644 (file)
@@ -121,9 +121,9 @@ TnyAccount* modest_tny_account_store_get_tny_account_by_id  (ModestTnyAccountSto
  * g_object_unref when it's no longer needed
  */
 TnyAccount* modest_tny_account_store_get_server_account (ModestTnyAccountStore *self,
-                                                                const gchar *account_name,
-                                                                TnyAccountType type);
-                                                    
+                                                        const gchar *account_name,
+                                                        TnyAccountType type);
+
 /**
  * modest_tny_account_store_get_transport_account_for_open_connection
  * @self: a ModestTnyAccountStore instance
@@ -137,7 +137,7 @@ TnyAccount* modest_tny_account_store_get_server_account (ModestTnyAccountStore *
  * g_object_unref when it's no longer needed
  */                                             
 TnyAccount* modest_tny_account_store_get_transport_account_for_open_connection (ModestTnyAccountStore *self,
-                                                                const gchar *account_name);
+                                                                               const gchar *account_name);
 
 /**
  * tny_account_store_get_session