From: Dirk-Jan C. Binnema Date: Fri, 21 Sep 2007 11:42:11 +0000 (+0000) Subject: * make sure there only one modal window at any time, and X-Git-Tag: git_migration_finished~2315 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=d3211dc47121ebbf4a387e5950e411931365397d * make sure there only one modal window at any time, and also that it is the toplevel one; this prevents a number of hangs and seemingly-hangs pmo-trunk-r3388 --- diff --git a/src/maemo/modest-account-view-window.c b/src/maemo/modest-account-view-window.c index 3384d05..f343aaa 100644 --- a/src/maemo/modest-account-view-window.c +++ b/src/maemo/modest-account-view-window.c @@ -297,7 +297,7 @@ on_wizard_response (GtkDialog *dialog, gint response, gpointer user_data) /* Destroy the dialog: */ if (dialog) { gtk_widget_destroy (GTK_WIDGET (dialog)); - modest_window_mgr_set_easysetup_dialog ( + modest_window_mgr_set_modal_dialog ( modest_runtime_get_window_mgr(), NULL); } } @@ -305,21 +305,25 @@ on_wizard_response (GtkDialog *dialog, gint response, gpointer user_data) static void on_new_button_clicked (GtkWidget *button, ModestAccountViewWindow *self) { - GtkDialog *wizard; + GtkDialog *wizard, *dialog; /* Show the easy-setup wizard: */ - wizard = modest_window_mgr_get_easysetup_dialog (modest_runtime_get_window_mgr()); - if (wizard) { + dialog = modest_window_mgr_get_modal_dialog (modest_runtime_get_window_mgr()); + if (dialog && MODEST_IS_EASYSETUP_WIZARD_DIALOG(dialog)) { /* old wizard is active already; */ - gtk_window_present (GTK_WINDOW(wizard)); + gtk_window_present (GTK_WINDOW(dialog)); return; - } else { - /* there is no such wizard yet */ - wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ()); - modest_window_mgr_set_easysetup_dialog (modest_runtime_get_window_mgr(), - GTK_DIALOG(wizard)); - } + } + + /* there is no such wizard yet */ + wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ()); + modest_window_mgr_set_modal_dialog (modest_runtime_get_window_mgr(), + GTK_DIALOG(wizard)); + + /* if there is already another modal dialog, make it non-modal */ + if (dialog) + gtk_window_set_modal (GTK_WINDOW(dialog), FALSE); gtk_window_set_modal (GTK_WINDOW (wizard), TRUE); gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (self)); diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index f41dd95..3b5c774 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -696,6 +696,7 @@ on_response (GtkDialog *dialog, } + static gint modest_platform_run_folder_name_dialog (GtkWindow *parent_window, TnyFolderStore *parent, @@ -761,11 +762,8 @@ modest_platform_run_folder_name_dialog (GtkWindow *parent_window, hbox, FALSE, FALSE, 0); gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox)); - gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window); - - - + result = gtk_dialog_run (GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) *folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); @@ -848,42 +846,76 @@ modest_platform_run_rename_folder_dialog (GtkWindow *parent_window, folder_name); } + + +static void +on_destroy_dialog (GtkDialog *dialog) +{ + if (dialog == modest_window_mgr_get_modal_dialog (modest_runtime_get_window_mgr())) + modest_window_mgr_set_modal_dialog (modest_runtime_get_window_mgr(), + NULL); + gtk_widget_destroy (GTK_WIDGET(dialog)); +} + + +/* is there already a modal dialog? if so, return TRUE, if not set this + * dialog to be the registered one */ +static void +check_modal_and_set_maybe (GtkDialog *dialog) +{ + GtkDialog *old_modal; + + old_modal = + modest_window_mgr_get_modal_dialog (modest_runtime_get_window_mgr()); + + if (!old_modal) { + gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); + modest_window_mgr_set_modal_dialog (modest_runtime_get_window_mgr(), + dialog); + } else { + /* un-modalize the old one; the one on top should be the + * modal one */ + gtk_window_set_modal (GTK_WINDOW(old_modal), FALSE); + gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); + } + +} + gint modest_platform_run_confirmation_dialog (GtkWindow *parent_window, const gchar *message) { GtkWidget *dialog; gint response; - + dialog = hildon_note_new_confirmation (parent_window, message); - gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); + check_modal_and_set_maybe (GTK_DIALOG(dialog)); response = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (GTK_WIDGET (dialog)); - + on_destroy_dialog (GTK_DIALOG(dialog)); + while (gtk_events_pending ()) gtk_main_iteration (); return response; } - + gint modest_platform_run_yes_no_dialog (GtkWindow *parent_window, const gchar *message) { GtkWidget *dialog; gint response; - + dialog = hildon_note_new_confirmation_add_buttons (parent_window, message, _("mcen_bd_yes"), GTK_RESPONSE_YES, _("mcen_bd_no"), GTK_RESPONSE_NO, NULL); - gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); - + check_modal_and_set_maybe (GTK_DIALOG(dialog)); response = gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_widget_destroy (GTK_WIDGET (dialog)); + + on_destroy_dialog (GTK_DIALOG(dialog)); while (gtk_events_pending ()) gtk_main_iteration (); @@ -891,20 +923,23 @@ modest_platform_run_yes_no_dialog (GtkWindow *parent_window, return response; } + + void modest_platform_run_information_dialog (GtkWindow *parent_window, const gchar *message) { - GtkWidget *dialog; - - dialog = hildon_note_new_information (parent_window, message); - - g_signal_connect_swapped (dialog, + GtkWidget *note; + + note = hildon_note_new_information (parent_window, message); + check_modal_and_set_maybe (GTK_DIALOG(note)); + + g_signal_connect_swapped (note, "response", - G_CALLBACK (gtk_widget_destroy), - dialog); + G_CALLBACK (on_destroy_dialog), + note); - gtk_widget_show_all (dialog); + gtk_widget_show_all (note); } @@ -1130,7 +1165,7 @@ modest_platform_run_sort_dialog (GtkWindow *parent_window, /* Build dialog */ dialog = hildon_sort_dialog_new (parent_window); - gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); + check_modal_and_set_maybe (GTK_DIALOG(dialog)); /* Fill sort keys */ switch (type) { @@ -1141,7 +1176,7 @@ modest_platform_run_sort_dialog (GtkWindow *parent_window, } /* Free */ - gtk_widget_destroy (GTK_WIDGET (dialog)); + on_destroy_dialog (GTK_DIALOG(dialog)); } @@ -1554,9 +1589,11 @@ modest_platform_run_certificate_conformation_dialog (const gchar* server_name, g_signal_connect (G_OBJECT(note), "response", G_CALLBACK(on_cert_dialog_response), (gpointer) certificate); + + check_modal_and_set_maybe (GTK_DIALOG(note)); response = gtk_dialog_run(GTK_DIALOG(note)); - gtk_widget_destroy(GTK_WIDGET(note)); + on_destroy_dialog (GTK_DIALOG(note)); g_free (question); return response; @@ -1579,11 +1616,12 @@ modest_platform_run_alert_dialog (const gchar* prompt, * so we know what buttons to show. */ GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_window), prompt)); + check_modal_and_set_maybe (GTK_DIALOG(dialog)); + const int response = gtk_dialog_run (GTK_DIALOG (dialog)); retval = (response == GTK_RESPONSE_YES) || (response == GTK_RESPONSE_OK); - gtk_widget_destroy (dialog); - + on_destroy_dialog (GTK_DIALOG(dialog)); } else { /* Just show the error text and use the default response: */ modest_platform_run_information_dialog (GTK_WINDOW (main_window), diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 77c1a42..a0f44e6 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -197,6 +197,8 @@ msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_fo return (src_is_pop && !uncached_msgs); } + +/* FIXME: this should be merged with the similar code in modest-account-view-window */ /* Show the account creation wizard dialog. * returns: TRUE if an account was created. FALSE if the user cancelled. */ @@ -204,25 +206,39 @@ gboolean modest_run_account_setup_wizard (ModestWindow *win) { gboolean result = FALSE; - GtkDialog *wizard; - - wizard = modest_window_mgr_get_easysetup_dialog - (modest_runtime_get_window_mgr()); - if (wizard) { - /* old wizard is active already; present it and - * act as if the user cancelled the non-existing - * new one + GtkDialog *wizard, *dialog; + + /* Show the easy-setup wizard: */ + dialog = modest_window_mgr_get_modal_dialog (modest_runtime_get_window_mgr()); + if (dialog && MODEST_IS_EASYSETUP_WIZARD_DIALOG(dialog)) { + /* old wizard is active already; */ - printf ("wizard already active\n"); + gtk_window_present (GTK_WINDOW(dialog)); return FALSE; - } else { - /* there is no such wizard yet */ - wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ()); - modest_window_mgr_set_easysetup_dialog - (modest_runtime_get_window_mgr(), GTK_DIALOG(wizard)); - } + } + + /* there is no such wizard yet */ + + wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ()); + if (!wizard) { + g_printerr ("modest: failed to create easysetup wizard\n"); + return FALSE; + } + modest_window_mgr_set_modal_dialog + (modest_runtime_get_window_mgr(), GTK_DIALOG(wizard)); + + + /* there is no such wizard yet */ + wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ()); + modest_window_mgr_set_modal_dialog (modest_runtime_get_window_mgr(), + GTK_DIALOG(wizard)); + + /* make it non-modal; if though we register it as a modal dialog above + * apparently, making it modal *at all* gives hangs -- FIXME: check this*/ + gtk_window_set_modal (GTK_WINDOW(dialog), FALSE); + /* always present a main window in the background * we do it here, so we cannot end up with to wizards (as this * function might be called in modest_window_mgr_get_main_window as well */ @@ -251,7 +267,7 @@ modest_run_account_setup_wizard (ModestWindow *win) gtk_widget_destroy (GTK_WIDGET (wizard)); /* clear it from the window mgr */ - modest_window_mgr_set_easysetup_dialog + modest_window_mgr_set_modal_dialog (modest_runtime_get_window_mgr(), NULL); return result; diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index fa32586..32dc0f3 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -62,7 +62,7 @@ struct _ModestWindowMgrPrivate { GList *window_list; ModestWindow *main_window; - GtkDialog *easysetup_dialog; + GtkDialog *modal_dialog; gboolean fullscreen_mode; @@ -127,7 +127,7 @@ modest_window_mgr_init (ModestWindowMgr *obj) priv->window_list = NULL; priv->main_window = NULL; priv->fullscreen_mode = FALSE; - priv->easysetup_dialog = NULL; + priv->modal_dialog = NULL; priv->preregistered_uids = NULL; @@ -171,11 +171,11 @@ modest_window_mgr_finalize (GObject *obj) priv->viewer_handlers = NULL; } - if (priv->easysetup_dialog) { - g_warning ("%s: forgot to destroy an easysetup dialog somewhere", + if (priv->modal_dialog) { + g_warning ("%s: forgot to destroy a modal dialog somewhere", __FUNCTION__); - gtk_widget_destroy (GTK_WIDGET(priv->easysetup_dialog)); - priv->easysetup_dialog = NULL; + gtk_widget_destroy (GTK_WIDGET(priv->modal_dialog)); + priv->modal_dialog = NULL; } /* Do not unref priv->main_window because it does not hold a @@ -547,10 +547,11 @@ disconnect_msg_changed (gpointer key, gpointer value, gpointer user_data) { - gulong *handler_id; - - handler_id = (gulong *) value; - g_signal_handler_disconnect (G_OBJECT (key), *handler_id); + guint handler_id; + handler_id = GPOINTER_TO_UINT(value); + + if (key && G_IS_OBJECT(key)) + g_signal_handler_disconnect (G_OBJECT (key), handler_id); } @@ -792,26 +793,26 @@ modest_window_mgr_get_main_window (ModestWindowMgr *self) GtkDialog* -modest_window_mgr_get_easysetup_dialog (ModestWindowMgr *self) +modest_window_mgr_get_modal_dialog (ModestWindowMgr *self) { ModestWindowMgrPrivate *priv; g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), NULL); priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - return priv->easysetup_dialog; + return priv->modal_dialog; } GtkDialog* -modest_window_mgr_set_easysetup_dialog (ModestWindowMgr *self, GtkDialog *dialog) +modest_window_mgr_set_modal_dialog (ModestWindowMgr *self, GtkDialog *dialog) { ModestWindowMgrPrivate *priv; g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), NULL); priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - return priv->easysetup_dialog = dialog; + return priv->modal_dialog = dialog; } diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index 91d61b2..2ee6e83 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -138,26 +138,26 @@ ModestWindow* modest_window_mgr_get_main_window (ModestWindowMgr *self); /** - * modest_window_mgr_get_easysetup_dialog: + * modest_window_mgr_get_modal_dialog: * @self: a #ModestWindowMgr * - * get the easysetup dialog; if it's NULL, there's no active dialog + * get the modal dialog; if it's NULL, there's no active dialog * - * Returns: the easy setup dialog or NULL + * Returns: the modal dialog or NULL **/ -GtkDialog* modest_window_mgr_get_easysetup_dialog (ModestWindowMgr *self); +GtkDialog* modest_window_mgr_get_modal_dialog (ModestWindowMgr *self); /** * modest_window_mgr_get_easysetup_dialog: * @self: a #ModestWindowMgr * - * set the easysetup dialog; set it to NULL after destroying the dialog + * set the modal dialog; set it to NULL after destroying the dialog * - * Returns: the easy setup dialog just set + * Returns: the modal dialog just set **/ -GtkDialog* modest_window_mgr_set_easysetup_dialog (ModestWindowMgr *self, - GtkDialog *dialog); +GtkDialog* modest_window_mgr_set_modal_dialog (ModestWindowMgr *self, + GtkDialog *dialog); /**