X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-account-store.c;h=dfd859daa2287edab8b80aa9a52bbd3bf97c705d;hp=d5b06a1571f7c4cd9fd6dccde940dbcb09f0aae5;hb=96d0d173e287c0453ba53589fe7f407136590b9d;hpb=5b20214853dcf7416c0e9b2590fed93af2c635e0 diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index d5b06a1..dfd859d 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -53,6 +53,7 @@ #include #include #include +#include #include "modest-tny-account-store.h" #include "modest-tny-platform-factory.h" @@ -300,19 +301,35 @@ modest_tny_account_store_instance_init (ModestTnyAccountStore *obj) /* disconnect the list of TnyAccounts */ static void -foreach_account_disconnect (gpointer data, - gpointer user_data) +account_disconnect (TnyAccount *account) { - tny_camel_account_set_online (TNY_CAMEL_ACCOUNT(data), FALSE, NULL, NULL); + g_return_if_fail (account && TNY_IS_ACCOUNT(account)); + tny_camel_account_set_online (TNY_CAMEL_ACCOUNT(account), FALSE, NULL, NULL); } +/* disconnect the list of TnyAccounts */ +static void +account_verify_last_ref (TnyAccount *account, const gchar *str) +{ + gchar *txt; + + g_return_if_fail (account && TNY_IS_ACCOUNT(account)); + + txt = g_strdup_printf ("%s: %s", str ? str : "?", tny_account_get_name(account)); + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(G_OBJECT(account),txt); + g_free (txt); +} + + + + static void foreach_account_append_to_list (gpointer data, gpointer user_data) { TnyList *list; - + list = TNY_LIST (user_data); tny_list_append (list, G_OBJECT (data)); } @@ -405,7 +422,7 @@ on_vfs_volume_unmounted(GnomeVFSVolumeMonitor *volume_monitor, if (found) { /* Remove from the list */ tny_list_remove (priv->store_accounts, G_OBJECT (mmc_account)); - + /* Notify observers */ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL], @@ -599,12 +616,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc /* TODO: Settting cancel to FALSE does not actually cancel everything. * We still get multiple requests afterwards, so we end up showing the * same dialogs repeatedly. - */ - - printf ("DEBUG: modest: %s: prompt (not shown) = %s\n", __FUNCTION__, prompt_not_used); - - g_return_val_if_fail (account, NULL); - + */ const TnyAccountStore *account_store = NULL; ModestTnyAccountStore *self = NULL; ModestTnyAccountStorePrivate *priv; @@ -613,6 +625,12 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc gpointer pwd_ptr = NULL; gboolean already_asked = FALSE; + g_return_val_if_fail (account, NULL); + + MODEST_DEBUG_BLOCK( + g_debug ("DEBUG: modest: %s: prompt (not shown) = %s\n", __FUNCTION__, prompt_not_used); + ); + /* Initialize the output parameter: */ if (cancel) *cancel = FALSE; @@ -642,9 +660,10 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc server_account_name, NULL, (gpointer*)&pwd_ptr); - - printf ("DEBUG: modest: %s: Already asked = %d\n", __FUNCTION__, already_asked); - + MODEST_DEBUG_BLOCK( + g_debug ("DEBUG: modest: %s: Already asked = %d\n", __FUNCTION__, already_asked); + ); + /* If the password is not already there, try ModestConf */ if (!already_asked) { pwd = modest_account_mgr_get_server_account_password (priv->account_mgr, @@ -660,7 +679,10 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc */ const gboolean settings_have_password = modest_account_mgr_get_server_account_has_password (priv->account_mgr, server_account_name); - printf ("DEBUG: modest: %s: settings_have_password=%d\n", __FUNCTION__, settings_have_password); + MODEST_DEBUG_BLOCK( + printf ("DEBUG: modest: %s: settings_have_password=%d\n", + __FUNCTION__, settings_have_password); + ); if (settings_have_password) { /* The password must be wrong, so show the account settings dialog so it can be corrected: */ show_wrong_password_dialog (account); @@ -709,10 +731,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc username = NULL; } else if (cancel) - *cancel = FALSE; - - /* printf(" DEBUG: %s: returning %s\n", __FUNCTION__, pwd); */ - + *cancel = FALSE; return pwd; } @@ -820,13 +839,15 @@ modest_tny_account_store_finalize (GObject *obj) /* Destroy all accounts. Disconnect all accounts before they are destroyed */ if (priv->store_accounts) { - tny_list_foreach (priv->store_accounts, foreach_account_disconnect, NULL); + tny_list_foreach (priv->store_accounts, (GFunc)account_disconnect, NULL); + tny_list_foreach (priv->store_accounts, (GFunc)account_verify_last_ref, "store"); g_object_unref (priv->store_accounts); priv->store_accounts = NULL; } - + if (priv->transport_accounts) { - tny_list_foreach (priv->transport_accounts, foreach_account_disconnect, NULL); + tny_list_foreach (priv->transport_accounts, (GFunc)account_disconnect, NULL); + tny_list_foreach (priv->transport_accounts, (GFunc)account_verify_last_ref, "transport"); g_object_unref (priv->transport_accounts); priv->transport_accounts = NULL; } @@ -1027,8 +1048,8 @@ modest_tny_account_store_get_device (TnyAccountStore *self) g_return_val_if_fail (self, NULL); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); - - if (priv->device) + + if (priv->device) return g_object_ref (G_OBJECT(priv->device)); else return NULL; @@ -1261,6 +1282,7 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self, return account; } + TnyAccount* modest_tny_account_store_get_server_account (ModestTnyAccountStore *self, const gchar *account_name, @@ -1301,7 +1323,7 @@ modest_tny_account_store_get_server_account (ModestTnyAccountStore *self, modest_acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (tmp_account); - if (!strcmp (account_name, modest_acc_name)) { + if (account_name && modest_acc_name && !strcmp (account_name, modest_acc_name)) { found = TRUE; retval = g_object_ref (tmp_account); } @@ -1582,7 +1604,7 @@ insert_account (ModestTnyAccountStore *self, /* Add accounts to the lists */ tny_list_append (priv->store_accounts, G_OBJECT (store_account)); tny_list_append (priv->transport_accounts, G_OBJECT (transport_account)); - + /* Create a new pseudo-account with an outbox for this transport account and add it to the global outbox in the local account */ @@ -1618,8 +1640,7 @@ on_account_inserted (ModestAccountMgr *acc_mgr, } static void -on_account_removed (ModestAccountMgr *acc_mgr, - const gchar *account, +on_account_removed (ModestAccountMgr *acc_mgr, const gchar *account, gpointer user_data) { TnyAccount *store_account = NULL, *transport_account = NULL; @@ -1630,7 +1651,7 @@ on_account_removed (ModestAccountMgr *acc_mgr, modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_STORE); transport_account = modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_TRANSPORT); - + /* If there was any problem creating the account, for example, with the configuration system this could not exist */ if (store_account) { @@ -1639,6 +1660,7 @@ on_account_removed (ModestAccountMgr *acc_mgr, /* Notify the observers */ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL], 0, store_account); + account_disconnect (store_account); /* disconnect the account */ g_object_unref (store_account); } else { g_warning ("There is no store account for account %s\n", account); @@ -1670,6 +1692,7 @@ on_account_removed (ModestAccountMgr *acc_mgr, /* Notify the observers */ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL], 0, transport_account); + account_disconnect (transport_account); /* disconnect the account */ g_object_unref (transport_account); } else { g_warning ("There is no transport account for account %s\n", account);