X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-tny-account-store.c;h=f98b87dd41fe02f4d5a6feebc3208e123cd5867e;hb=4cc71b71b7e5df064bd3589b62717b1e9db4bac6;hp=f216937887c4cef12ec339224dcac2dbb4553858;hpb=f10121c8130b6ee6d3838558d416b7140124a240;p=modest diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index f216937..f98b87d 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -65,7 +65,6 @@ #ifdef MODEST_PLATFORM_MAEMO #include -#include #endif #include @@ -489,10 +488,12 @@ on_account_changed (ModestAccountMgr *acc_mgr, g_object_unref (iter); } -static void -show_wrong_password_dialog (TnyAccount *account, +static void +show_wrong_password_dialog (TnyAccount *account, gboolean show_banner) -{ +{ + g_debug ("%s: %s", __FUNCTION__, tny_account_get_id (account)); + if (g_object_get_data (G_OBJECT (account), "connection_specific") != NULL) { modest_ui_actions_on_smtp_servers (NULL, NULL); } else { @@ -510,9 +511,16 @@ show_wrong_password_dialog (TnyAccount *account, /* Create and show the dialog */ if (proto && MODEST_IS_ACCOUNT_PROTOCOL (proto)) { + GtkWindow *parent; + ModestWindowMgr *mgr = modest_runtime_get_window_mgr (); ModestAccountSettingsDialog *dialog = modest_account_protocol_get_account_settings_dialog (proto, modest_account_name); - modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), NULL); + + parent = modest_window_mgr_get_modal (mgr); + if (!parent) + parent = (GtkWindow *) modest_window_mgr_get_current_top (mgr); + + modest_window_mgr_set_modal (mgr, GTK_WINDOW (dialog), parent); gtk_widget_show (GTK_WIDGET (dialog)); } } @@ -541,9 +549,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc g_return_val_if_fail (account, NULL); - MODEST_DEBUG_BLOCK( - g_debug ("%s: prompt (not shown) = %s\n", __FUNCTION__, prompt_not_used); - ); + g_debug ("%s: %s", __FUNCTION__, prompt_not_used); /* Get a reference to myself */ self = MODEST_TNY_ACCOUNT_STORE (g_object_get_data (G_OBJECT(account), "account_store")); @@ -587,7 +593,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc already_asked = priv->password_hash && g_hash_table_lookup_extended (priv->password_hash, server_account_name, NULL, - &attempt_ptr); + attempt_ptr); /* If the password is not already there, try ModestConf */ if (!already_asked) { @@ -1077,7 +1083,8 @@ modest_tny_account_store_alert (TnyAccountStore *self, gboolean retval = TRUE; /* NOTE: account may be NULL in some cases */ - g_return_val_if_fail (error, FALSE); + if (!error) + return FALSE; /* Get the server name: */ if (account) { @@ -1149,27 +1156,34 @@ modest_tny_account_store_alert (TnyAccountStore *self, else if (error->code == TNY_SERVICE_ERROR_AUTHENTICATE || error->code == TNY_SERVICE_ERROR_CONNECT) { TnyDevice *device = modest_runtime_get_device (); - - if (error->code == TNY_SERVICE_ERROR_CONNECT) { - gboolean success; - success = modest_account_mgr_get_server_account_username_has_succeeded (modest_runtime_get_account_mgr (), - tny_account_get_id (account)); - if (success) - goto end; + gboolean success; + + /* If we get the connection error after establishing a + proper connection then do not show the dialog as we + are probably behind a firewall, or in a network + with connection issues. We just keep this code to + detect situations were the user does not enter the + server info properly */ + success = modest_account_mgr_get_server_account_username_has_succeeded (modest_runtime_get_account_mgr (), + tny_account_get_id (account)); + + if (!success) { + g_debug ("%s: %s alert received (%s)", __FUNCTION__, + (error->code == TNY_SERVICE_ERROR_CONNECT) ? "connect" : "aunthenticate", + error->message); + + modest_platform_run_information_dialog (NULL, prompt, TRUE); + + /* Show the account dialog. Checking the online status + allows us to minimize the number of times that we + incorrectly show the dialog */ + if (tny_device_is_online (device)) + show_wrong_password_dialog (account, + (error->code == TNY_SERVICE_ERROR_CONNECT) ? FALSE : TRUE); + retval = TRUE; } - - modest_platform_run_information_dialog (NULL, prompt, TRUE); - - /* Show the account dialog. Checking the online status - allows us to minimize the number of times that we - incorrectly show the dialog */ - if (tny_device_is_online (device)) - show_wrong_password_dialog (account, - (error->code == TNY_SERVICE_ERROR_CONNECT) ? FALSE : TRUE); - - retval = TRUE; } - end: + g_debug ("%s: error code %d (%s", __FUNCTION__, error->code, error->message); if (prompt) @@ -2150,8 +2164,6 @@ account_shutdown_callback (TnyCamelAccount *account, gboolean canceled, GError * op_data->callback (op_data->account_store, op_data->userdata); g_object_unref (op_data->account_store); g_free (op_data); - } else { - g_object_unref (op_data->account_store); } } @@ -2161,19 +2173,15 @@ account_shutdown (TnyAccount *account, ShutdownOpData *op_data) g_return_if_fail (account && TNY_IS_ACCOUNT(account)); if (TNY_IS_STORE_ACCOUNT (account) && - !modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account))) - goto frees; - - /* Disconnect account */ - if (tny_account_get_connection_status (account) == TNY_CONNECTION_STATUS_CONNECTED) { - tny_camel_account_set_online (TNY_CAMEL_ACCOUNT(account), FALSE, - account_shutdown_callback, op_data); + !modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account))) { + op_data->pending--; return; } - frees: - op_data->pending--; - g_object_unref (op_data->account_store); + /* Disconnect account */ + tny_camel_account_set_online (TNY_CAMEL_ACCOUNT(account), FALSE, + account_shutdown_callback, op_data); + } @@ -2182,7 +2190,7 @@ modest_tny_account_store_shutdown (ModestTnyAccountStore *self, ModestTnyAccountStoreShutdownCallback callback, gpointer userdata) { - gint i, num_accounts; + gint num_accounts; ShutdownOpData *op_data; ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self); @@ -2193,15 +2201,16 @@ modest_tny_account_store_shutdown (ModestTnyAccountStore *self, if (priv->transport_accounts) num_accounts += tny_list_get_length (priv->transport_accounts); - for (i = 0 ; i < num_accounts ; i++) - g_object_ref (self); - /* Create the helper object */ op_data = g_new0 (ShutdownOpData, 1); op_data->callback = callback; op_data->userdata = userdata; op_data->pending = num_accounts; - op_data->account_store = self; + op_data->account_store = g_object_ref (self); + + /* Force the TnyDevice to be offline. This way new + undesired connections won't be initiated */ + tny_device_force_offline (priv->device); /* Destroy all accounts. Disconnect all accounts before they are destroyed */ if (priv->store_accounts) { @@ -2215,6 +2224,7 @@ modest_tny_account_store_shutdown (ModestTnyAccountStore *self, if (op_data->pending == 0) { if (op_data->callback) op_data->callback (op_data->account_store, op_data->userdata); + g_object_unref (op_data->account_store); g_free (op_data); } }