From: Dirk-Jan C. Binnema Date: Wed, 1 Aug 2007 08:44:29 +0000 (+0000) Subject: * step 2 of the account fixes; for now, account changes X-Git-Tag: git_migration_finished~2674 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=04fa8f60ad3ce55f41e650558c56f210e0d87143 * step 2 of the account fixes; for now, account changes are turned-off, as we get hangs when we get alert-popups pmo-trunk-r2883 --- diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index fcb7bba..7c90a39 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -429,9 +429,52 @@ modest_tny_account_store_forget_password_in_memory (ModestTnyAccountStore *self, } } + +static gboolean +update_tny_account_for_account (ModestTnyAccountStore *self, ModestAccountMgr *acc_mgr, + const gchar *account_name, TnyAccountType type) +{ + ModestTnyAccountStorePrivate *priv; + TnyList* account_list; + gboolean found = FALSE; + TnyIterator *iter = NULL; + + g_return_val_if_fail (self, FALSE); + g_return_val_if_fail (account_name, FALSE); + g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || + type == TNY_ACCOUNT_TYPE_TRANSPORT, + FALSE); + + priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); + account_list = (type == TNY_ACCOUNT_TYPE_STORE ? priv->store_accounts : priv->transport_accounts); + + iter = tny_list_create_iterator (account_list); + while (!tny_iterator_is_done (iter) && !found) { + TnyAccount *tny_account; + tny_account = TNY_ACCOUNT (tny_iterator_get_current (iter)); + if (tny_account) { + const gchar* parent_name = + modest_tny_account_get_parent_modest_account_name_for_server_account (tny_account); + if (parent_name && strcmp (parent_name, account_name) == 0) { + found = TRUE; + modest_tny_account_update_from_account (tny_account, acc_mgr, account_name, type); + g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, tny_account); + } + g_object_unref (tny_account); + } + tny_iterator_next (iter); + } + + if (iter) + g_object_unref (iter); + + return found; +} + + static void on_account_changed (ModestAccountMgr *acc_mgr, - const gchar *account, + const gchar *account_name, const gchar *key, gboolean server_account, gpointer user_data) @@ -439,31 +482,25 @@ on_account_changed (ModestAccountMgr *acc_mgr, printf ("DEBUG: modest: %s\n", __FUNCTION__); ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); - + /* Ignore the change if it's a change in the last_updated value */ if (key && g_str_has_suffix ((const gchar *) key, MODEST_ACCOUNT_LAST_UPDATED)) return; - - /* FIXME: make this more finegrained; changes do not really affect _all_ - * accounts - */ -/* recreate_all_accounts (self); */ + if (!server_account && FALSE) { /* FIXME FALSE: turned off for now */ + if (!update_tny_account_for_account (self, acc_mgr, account_name, TNY_ACCOUNT_TYPE_STORE)) + g_warning ("%s: failed to update store account for %s", __FUNCTION__, account_name); + if (!update_tny_account_for_account (self, acc_mgr, account_name, TNY_ACCOUNT_TYPE_TRANSPORT)) + g_warning ("%s: failed to update transport account for %s", __FUNCTION__, account_name); + } + /* TODO: This doesn't actually work, because * a) The account name is not sent correctly per key: * b) We should test the end of the key, not the whole keym * c) We don't seem to be getting all keys here. - * Instead, we just forget the password for all accounts when we create them, for now. + * Instead, we just forget the password for all accounts when we create them, + * for now. */ - #if 0 - /* If a password has changed, then forget the previously cached password for this account: */ - if (server_account && key && g_slist_find_custom ((GSList *)keys, MODEST_ACCOUNT_PASSWORD, (GCompareFunc)strcmp)) { - printf ("DEBUG: %s: Forgetting cached password for account ID=%s\n", __FUNCTION__, account); - modest_tny_account_store_forget_password_in_memory (self, account); - } - #endif - - g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, account); } static void @@ -1146,7 +1183,7 @@ modest_tny_account_store_alert (TnyAccountStore *self, TnyAccount *account, TnyA * when it is a question. * Obviously, we need tinymail to use more specific error codes instead, * so we know what buttons to show. */ - + /* TODO: Do this in the main context: */ GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_window), prompt)); diff --git a/src/modest-tny-account.c b/src/modest-tny-account.c index ac15b2b..4e18eff 100644 --- a/src/modest-tny-account.c +++ b/src/modest-tny-account.c @@ -552,6 +552,55 @@ forget_pass_dummy (TnyAccount *account) /* intentionally left blank */ } + + +gboolean +modest_tny_account_update_from_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr, + const gchar *account_name, TnyAccountType type) +{ + ModestAccountData *account_data = NULL; + ModestServerAccountData *server_data = NULL; + + g_return_val_if_fail (tny_account, FALSE); + g_return_val_if_fail (account_mgr, FALSE); + g_return_val_if_fail (account_name, FALSE); + g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT, + FALSE); + + account_data = modest_account_mgr_get_account_data (account_mgr, account_name); + if (!account_data) { + g_printerr ("modest: %s: cannot get account data for account %s\n", + __FUNCTION__, account_name); + return FALSE; + } + + if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account) + server_data = account_data->store_account; + else if (type == TNY_ACCOUNT_TYPE_TRANSPORT && account_data->transport_account) + server_data = account_data->transport_account; + if (!server_data) { + g_printerr ("modest: no %s account defined for '%s'\n", + type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport", + account_data->display_name); + modest_account_mgr_free_account_data (account_mgr, account_data); + return FALSE; + } + + update_tny_account (tny_account, account_mgr, server_data); + + /* This name is what shows up in the folder view -- so for some POP/IMAP/... server + * account, we set its name to the account of which it is part. */ + + if (account_data->display_name) + tny_account_set_name (tny_account, account_data->display_name); + + modest_account_mgr_free_account_data (account_mgr, account_data); + + return TRUE; +} + + + TnyAccount* modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar *account_name, @@ -567,6 +616,8 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, g_return_val_if_fail (account_mgr, NULL); g_return_val_if_fail (account_name, NULL); g_return_val_if_fail (session, NULL); + g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT, + NULL); account_data = modest_account_mgr_get_account_data (account_mgr, account_name); if (!account_data) { @@ -607,9 +658,8 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, tny_account_set_pass_func (tny_account, get_pass_func ? get_pass_func: get_pass_dummy); - - modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, account_name); - + modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, + account_name); modest_account_mgr_free_account_data (account_mgr, account_data); return tny_account; @@ -994,10 +1044,10 @@ modest_tny_account_get_parent_modest_account_name_for_server_account (TnyAccount void modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAccount *self, - const gchar* parent_modest_acount_name) + const gchar* parent_modest_account_name) { g_object_set_data_full (G_OBJECT(self), "modest_account", - (gpointer) g_strdup (parent_modest_acount_name), g_free); + (gpointer) g_strdup (parent_modest_account_name), g_free); } gboolean diff --git a/src/modest-tny-account.h b/src/modest-tny-account.h index 1c1f12c..8cbcc72 100644 --- a/src/modest-tny-account.h +++ b/src/modest-tny-account.h @@ -42,6 +42,10 @@ G_BEGIN_DECLS + + + + /** * modest_tny_account_new_from_account: * @account_mgr: a valid account mgr instance @@ -52,7 +56,6 @@ G_BEGIN_DECLS * @forget_pass_func: the forget-password function * * get a tnyaccount corresponding to the server_accounts (store or transport) for this account. - * NOTE: this function does not set the camel session or the get/forget password functions * * Returns: a new TnyAccount or NULL in case of error. */ @@ -65,6 +68,22 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar /** + * modest_tny_account_update_from_account: + * @tny_account: a valid tny_account + * @account_mgr: a valid account mgr instance + * @account_name: the modest account name for which to create a corresponding tny account of the given type. + * @type: the type of account to create (TNY_ACCOUNT_TYPE_STORE or TNY_ACCOUNT_TYPE_TRANSPORT) + * + * update a tnyaccount corresponding to the server_accounts (store or transport) for this account. + * + * Returns: a TRUE or FALSE in case of error. + */ +gboolean +modest_tny_account_update_from_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr, + const gchar *account_name, TnyAccountType type); + + +/** * modest_tny_account_new_for_local_folders: * @account_mgr: a valid account mgr instance * @session: a tny camel session diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index a131674..2f2ba5d 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -161,17 +161,14 @@ get_last_updated_string(ModestAccountMgr* account_mgr, ModestAccountData *accoun /* FIXME: let's assume that 'last update' applies to the store account... */ gchar* last_updated_string; time_t last_updated = account_data->store_account->last_updated; - if (!modest_account_mgr_account_is_busy(account_mgr, account_data->account_name)) - { + if (!modest_account_mgr_account_is_busy(account_mgr, account_data->account_name)) { if (last_updated > 0) - last_updated_string = modest_text_utils_get_display_date(last_updated); + last_updated_string = modest_text_utils_get_display_date(last_updated); else - last_updated_string = g_strdup (_("mcen_va_never")); - } - else - { + last_updated_string = g_strdup (_("mcen_va_never")); + } else { /* FIXME: There should be a logical name in the UI specs */ - last_updated_string = g_strdup(_("Refreshing...")); + last_updated_string = g_strdup(_("...")); } return last_updated_string; } @@ -316,8 +313,8 @@ on_account_removed (TnyAccountStore *account_store, static void -on_account_changed (ModestAccountMgr *obj, const gchar* account, - const gchar* key, gboolean server_account, +on_account_changed (TnyAccountStore *account_store, + TnyAccount *account, gpointer user_data) { ModestAccountView *self; @@ -326,6 +323,8 @@ on_account_changed (ModestAccountMgr *obj, const gchar* account, self = MODEST_ACCOUNT_VIEW (user_data); priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self); + g_warning ("account changed: %s", tny_account_get_id(account)); + update_account_view (priv->account_mgr, self); } diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index 51bfcfc..0353cd8 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -77,6 +77,10 @@ static void on_account_inserted (TnyAccountStore *self, TnyAccount *account, gpointer user_data); +static void on_account_changed (TnyAccountStore *self, + TnyAccount *account, + gpointer user_data); + static gint cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2, @@ -152,6 +156,7 @@ struct _ModestFolderViewPrivate { gulong changed_signal; gulong account_inserted_signal; gulong account_removed_signal; + gulong account_changed_signal; gulong conf_key_signal; /* not unref this object, its a singlenton */ @@ -257,7 +262,8 @@ modest_folder_view_class_init (ModestFolderViewClass *klass) } /* Simplify checks for NULLs: */ -static gboolean strings_are_equal (const gchar *a, const gchar *b) +static gboolean +strings_are_equal (const gchar *a, const gchar *b) { if (!a && !b) return TRUE; @@ -269,7 +275,8 @@ static gboolean strings_are_equal (const gchar *a, const gchar *b) return FALSE; } -static gboolean on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +static gboolean +on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { GObject *instance = NULL; @@ -313,7 +320,8 @@ typedef struct gchar *previous_name; } GetMmcAccountNameData; -static void on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data) +static void +on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data) { /* printf ("DEBU1G: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account))); */ @@ -695,6 +703,8 @@ modest_folder_view_finalize (GObject *obj) priv->account_inserted_signal); g_signal_handler_disconnect (G_OBJECT(priv->account_store), priv->account_removed_signal); + g_signal_handler_disconnect (G_OBJECT(priv->account_store), + priv->account_changed_signal); g_object_unref (G_OBJECT(priv->account_store)); priv->account_store = NULL; } @@ -760,7 +770,10 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore priv->account_removed_signal)) g_signal_handler_disconnect (G_OBJECT (priv->account_store), priv->account_removed_signal); - + if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), + priv->account_changed_signal)) + g_signal_handler_disconnect (G_OBJECT (priv->account_store), + priv->account_changed_signal); g_object_unref (G_OBJECT (priv->account_store)); } @@ -774,11 +787,9 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore g_signal_connect (G_OBJECT(account_store), "account_inserted", G_CALLBACK (on_account_inserted), self); - -/* g_signal_connect (G_OBJECT(account_store), "connecting_finished", */ -/* G_CALLBACK (on_accounts_reloaded), self); */ - -/* on_accounts_reloaded (account_store, (gpointer ) self); */ + priv->account_changed_signal = + g_signal_connect (G_OBJECT(account_store), "account_changed", + G_CALLBACK (on_account_changed), self); modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store); @@ -817,6 +828,16 @@ on_account_inserted (TnyAccountStore *account_store, G_OBJECT (account)); } + +static void +on_account_changed (TnyAccountStore *account_store, TnyAccount *tny_account, + gpointer user_data) +{ + g_warning ("%s: account_id = %s", __FUNCTION__, tny_account_get_id(tny_account)); +} + + + static void on_account_removed (TnyAccountStore *account_store, TnyAccount *account,