From 5fe84384c617285abe0e5f2f08e4be08ae4d339b Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Thu, 12 Jul 2007 14:00:57 +0000 Subject: [PATCH] 2007-07-12 Murray Cumming * src/gnome/modest-platform.c: (modest_platform_connect_and_wait): * src/maemo/modest-platform.c: (modest_platform_connect_and_wait): Take a TnyAccount* parameter and try to set it to online (a TnyCamel-only API), because tinymail sets accounts to offline when the user cancels a password dialog, and doesn't ask again until it has been set to online. However, this is commented out because it causes a hang now. (modest_platform_connect_and_wait_if_network_account): * src/modest-mail-operation.c: (modest_mail_operation_update_account): * src/modest-platform.h: * src/modest-ui-actions.c: (_modest_ui_actions_open), (download_uncached_messages), (modest_ui_actions_on_send): Adapted. pmo-trunk-r2727 --- ChangeLog2 | 18 ++++++++++++++++++ src/gnome/modest-platform.c | 2 +- src/maemo/modest-platform.c | 40 ++++++++++++++++++++++++++++++++++++---- src/modest-mail-operation.c | 30 +++++++++++++++--------------- src/modest-platform.h | 4 +++- src/modest-ui-actions.c | 6 +++--- 6 files changed, 76 insertions(+), 24 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 1801ce7..447015d 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,21 @@ +2007-07-12 Murray Cumming + + * src/gnome/modest-platform.c: (modest_platform_connect_and_wait): + * src/maemo/modest-platform.c: + (modest_platform_connect_and_wait): + Take a TnyAccount* parameter and try to set it to online + (a TnyCamel-only API), because tinymail sets accounts to offline + when the user cancels a password dialog, and doesn't ask again until + it has been set to online. + However, this is commented out because it causes a hang now. + + (modest_platform_connect_and_wait_if_network_account): + * src/modest-mail-operation.c: + (modest_mail_operation_update_account): + * src/modest-platform.h: + * src/modest-ui-actions.c: (_modest_ui_actions_open), + (download_uncached_messages), (modest_ui_actions_on_send): Adapted. + 2007-07-12 Armin Burgmeier * src/modest-error.h: Added MODEST_MAIL_OPERATION_FOLDER_EXISTS error. diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index acd06b7..afe8f66 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -183,7 +183,7 @@ modest_platform_run_information_dialog (GtkWindow *parent_window, /* TODO: implement a information dialog */ } -gboolean modest_platform_connect_and_wait (GtkWindow *parent_window) +gboolean modest_platform_connect_and_wait (GtkWindow *parent_window, TnyAccount *account) { /* TODO: Do something with network-manager? Otherwise, maybe it is safe to assume that we would already be online if we could be. */ diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index b53ee1b..3cc28de 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -1025,8 +1025,34 @@ on_idle_wait_for_previous_connect_to_finish(gpointer user_data) return result; } +static void +set_account_to_online (TnyAccount *account) +{ + /* TODO: This is necessary to prevent a cancel of the password dialog + * from making a restart necessary to be asked the password again, + * but it causes a hang: + */ + #if 0 + if (account && TNY_IS_CAMEL_STORE_ACCOUNT (account)) { + /* Make sure that store accounts are online too, + * because tinymail sets accounts to offline if + * a password dialog is ever cancelled. + * We don't do this for transport accounts because + * a) They fundamentally need network access, so they can't really be offline. + * b) That might cause a transport connection to happen too early. + */ + GError *error = NULL; + tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), TRUE, &error); + if (error) { + g_warning ("%s: tny_camel_account_set_online() returned a GError:\n %s\n", + __FUNCTION__, error->message); + g_error_free (error); + } + } + #endif +} -gboolean modest_platform_connect_and_wait (GtkWindow *parent_window) +gboolean modest_platform_connect_and_wait (GtkWindow *parent_window, TnyAccount *account) { if (connect_request_in_progress) return FALSE; @@ -1036,6 +1062,7 @@ gboolean modest_platform_connect_and_wait (GtkWindow *parent_window) if (tny_device_is_online (device)) { printf ("DEBUG: %s: Already online.\n", __FUNCTION__); + set_account_to_online (account); return TRUE; } else { @@ -1073,8 +1100,13 @@ gboolean modest_platform_connect_and_wait (GtkWindow *parent_window) /* g_main_context_unref (context); */ g_slice_free (UtilIdleData, data); - - return tny_device_is_online (device); + + gboolean result = tny_device_is_online (device); + + if (result) + set_account_to_online (account); + + return result; } gboolean modest_platform_connect_and_wait_if_network_account (GtkWindow *parent_window, TnyAccount *account) @@ -1087,7 +1119,7 @@ gboolean modest_platform_connect_and_wait_if_network_account (GtkWindow *parent_ } } - return modest_platform_connect_and_wait (parent_window); + return modest_platform_connect_and_wait (parent_window, account); } gboolean modest_platform_connect_and_wait_if_network_folderstore (GtkWindow *parent_window, TnyFolderStore *folder_store) diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index df94621..aa51380 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -1365,12 +1365,12 @@ modest_mail_operation_update_account (ModestMailOperation *self, UpdateAccountCallback callback, gpointer user_data) { - GThread *thread; - UpdateAccountInfo *info; - ModestMailOperationPrivate *priv; - ModestAccountMgr *mgr; - TnyStoreAccount *modest_account; - TnyTransportAccount *transport_account; + GThread *thread = NULL; + UpdateAccountInfo *info = NULL; + ModestMailOperationPrivate *priv = NULL; + ModestAccountMgr *mgr = NULL; + TnyStoreAccount *store_account = NULL; + TnyTransportAccount *transport_account = NULL; g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE); g_return_val_if_fail (account_name, FALSE); @@ -1383,20 +1383,20 @@ modest_mail_operation_update_account (ModestMailOperation *self, priv->done = 0; priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS; + /* Get the Modest account */ + store_account = (TnyStoreAccount *) + modest_tny_account_store_get_server_account (modest_runtime_get_account_store (), + account_name, + TNY_ACCOUNT_TYPE_STORE); + /* Make sure that we have a connection, and request one * if necessary: * TODO: Is there some way to trigger this for every attempt to * use the network? */ - if (!modest_platform_connect_and_wait (NULL)) + if (!modest_platform_connect_and_wait (NULL, TNY_ACCOUNT (store_account))) goto error; - /* Get the Modest account */ - modest_account = (TnyStoreAccount *) - modest_tny_account_store_get_server_account (modest_runtime_get_account_store (), - account_name, - TNY_ACCOUNT_TYPE_STORE); - - if (!modest_account) { + if (!store_account) { g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR, MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND, "cannot get tny store account for %s\n", account_name); @@ -1419,7 +1419,7 @@ modest_mail_operation_update_account (ModestMailOperation *self, /* Create the helper object */ info = g_slice_new (UpdateAccountInfo); info->mail_op = self; - info->account = modest_account; + info->account = store_account; info->transport_account = transport_account; info->callback = callback; info->user_data = user_data; diff --git a/src/modest-platform.h b/src/modest-platform.h index 3b321b3..c1bdd14 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -215,13 +215,15 @@ void modest_platform_run_sort_dialog (GtkWindow *parent_window, /* * modest_platform_connect_and_wait: * @parent_window: the parent #GtkWindow for any interactive or progress feedback UI. + * @account: The account to be used. * @return value: Whether a connection was made. * * Attempts to make a connection, possibly showing interactive UI to achieve this. * This will return TRUE immediately if a connection is already open. * Otherwise, this function blocks until the connection attempt has either succeded or failed. + * This also sets the account to online, if it is a store account, in case it has been set to offline mode. */ -gboolean modest_platform_connect_and_wait (GtkWindow *parent_window); +gboolean modest_platform_connect_and_wait (GtkWindow *parent_window, TnyAccount *account); /* diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 61b68e3..554ee4c 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -889,7 +889,7 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win) * than later in a thread: */ if (tny_list_get_length (not_opened_cached_headers) > 0) { - gboolean connected = modest_platform_connect_and_wait (GTK_WINDOW (win)); + gboolean connected = modest_platform_connect_and_wait (GTK_WINDOW (win), NULL); /* Don't go further if a connection would be necessary but none is available: */ if (!connected) { @@ -1158,7 +1158,7 @@ download_uncached_messages (TnyList *header_list, GtkWindow *win, retval = FALSE; else { /* If a download will be necessary, make sure that we have a connection: */ - retval = modest_platform_connect_and_wait(win); + retval = modest_platform_connect_and_wait(win, NULL); } } return retval; @@ -1926,7 +1926,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) return; /* Offer the connection dialog, if necessary: */ - if (!modest_platform_connect_and_wait (GTK_WINDOW (edit_window))) + if (!modest_platform_connect_and_wait (GTK_WINDOW (edit_window), NULL)) return; /* FIXME: Code added just for testing. The final version will -- 1.7.9.5