From 4e0cd4cd2c87db28d9bacf8b21cd509af36c0d84 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Wed, 25 Jul 2007 12:34:45 +0000 Subject: [PATCH] 2007-07-25 Murray Cumming * src/maemo/modest-maemo-utils.h: * src/maemo/modest-maemo-utils.c: Added modest_maemo_show_information_note_in_main_context_and_forget(). * src/modest-tny-account-store.c: (modest_tny_account_store_alert): Use the new function to show simple error dialogs in the main context, though question dialogs are still in the current context, which is unfortunately usually not the main context. This should fix some hangs. pmo-trunk-r2792 --- ChangeLog2 | 11 ++++++++ src/maemo/modest-maemo-utils.c | 31 ++++++++++++++++++++ src/maemo/modest-maemo-utils.h | 10 +++++++ src/modest-tny-account-store.c | 61 +++++++++++++++------------------------- 4 files changed, 74 insertions(+), 39 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index b29410f..61c95b6 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,16 @@ 2007-07-25 Murray Cumming + * src/maemo/modest-maemo-utils.h: + * src/maemo/modest-maemo-utils.c: Added + modest_maemo_show_information_note_in_main_context_and_forget(). + * src/modest-tny-account-store.c: (modest_tny_account_store_alert): + Use the new function to show simple error dialogs in the main + context, though question dialogs are still in the current context, + which is unfortunately usually not the main context. This should + fix some hangs. + +2007-07-25 Murray Cumming + * src/modest-tny-account-store.c: (get_password): Never save the entered username and password in gconf, because the UI spec says we should not. This helps diff --git a/src/maemo/modest-maemo-utils.c b/src/maemo/modest-maemo-utils.c index b48c804..522392b 100644 --- a/src/maemo/modest-maemo-utils.c +++ b/src/maemo/modest-maemo-utils.c @@ -546,6 +546,35 @@ on_hide (GtkDialog *dialog, gpointer user_data) } #endif +/* user_data for the idle callback: */ +typedef struct +{ + GtkWindow *parent_window; + gchar *message; +} ModestIdleNoteInfo; + +static gboolean +on_idle_show_information(gpointer user_data) +{ + ModestIdleNoteInfo *info = (ModestIdleNoteInfo*)user_data; + + modest_maemo_show_information_note_and_forget (info->parent_window, info->message); + + g_free (info->message); + g_slice_free (ModestIdleNoteInfo, info); + + return FALSE; /* Don't call this again. */ +} + +void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window, const gchar* message) +{ + ModestIdleNoteInfo *info = g_slice_new (ModestIdleNoteInfo); + info->parent_window = parent_window; + info->message = g_strdup (message); + + g_idle_add (on_idle_show_information, info); +} + void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog) { gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window); @@ -555,6 +584,8 @@ void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *d gtk_widget_show (GTK_WIDGET (dialog)); } + + void modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, gboolean thumbable) { diff --git a/src/maemo/modest-maemo-utils.h b/src/maemo/modest-maemo-utils.h index 3fa9ef3..3bae920 100644 --- a/src/maemo/modest-maemo-utils.h +++ b/src/maemo/modest-maemo-utils.h @@ -132,6 +132,16 @@ void modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser); */ void modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message); +/** modest_maemo_show_information_note_in_main_context_and_forget: + * @parent_window: The window for which the note should be transient. + * @message: The text to show. + * + * This calls modest_maemo_show_information_note_and_forget() in an idle handler. + * This should be used when you are not sure that you are in the main context, + * because you should try to use GTK+ UI code only in the main context. + */ +void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window, const gchar* message); + /** modest_maemo_show_dialog_and_forget: * @parent_window: The window for which the note should be transient. * @message: The dialog to show. diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 2291b62..bf01e38 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -1336,48 +1336,31 @@ modest_tny_account_store_alert (TnyAccountStore *self, TnyAccount *account, TnyA if (!prompt) return FALSE; -#ifdef MODEST_PLATFORM_MAEMO - /* The Tinymail documentation says that we should show Yes and No buttons, - * when it is a question. - * Obviously, we need tinymail to use more specific error codes instead, - * so we know what buttons to show. */ - GtkWidget *dialog = NULL; - if (question) { - dialog = GTK_WIDGET (hildon_note_new_confirmation (NULL, + ModestWindow *main_window = + modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); + gboolean retval = TRUE; + if (question) { + /* The Tinymail documentation says that we should show Yes and No buttons, + * 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)); + const int response = gtk_dialog_run (GTK_DIALOG (dialog)); + if (question) { + retval = (response == GTK_RESPONSE_YES) || + (response == GTK_RESPONSE_OK); + } + + gtk_widget_destroy (dialog); + } else { - dialog = GTK_WIDGET (hildon_note_new_information (NULL, - prompt)); + /* Just show the error text and use the default response: */ + modest_maemo_show_information_note_in_main_context_and_forget (GTK_WINDOW (main_window), + prompt); } -#else - - GtkMessageType gtktype = GTK_MESSAGE_ERROR; - switch (type) - { - case TNY_ALERT_TYPE_INFO: - gtktype = GTK_MESSAGE_INFO; - break; - case TNY_ALERT_TYPE_WARNING: - gtktype = GTK_MESSAGE_WARNING; - break; - case TNY_ALERT_TYPE_ERROR: - default: - gtktype = GTK_MESSAGE_ERROR; - break; - } - - GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, - gtktype, GTK_BUTTONS_YES_NO, prompt); -#endif /* #ifdef MODEST_PLATFORM_MAEMO */ - - gboolean retval = TRUE; - const int response = gtk_dialog_run (GTK_DIALOG (dialog)); - if (question) { - retval = (response == GTK_RESPONSE_YES) || - (response == GTK_RESPONSE_OK); - } - - gtk_widget_destroy (dialog); /* TODO: Don't free this when we no longer strdup the message for testers. */ g_free (prompt); -- 1.7.9.5