From 93b823a0e35263f7f0134a0d334d12b8cb2c0ba2 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 27 Aug 2007 07:00:14 +0000 Subject: [PATCH] * cleaner version of the patch to make sure no double account-setup-wizards are shown * fixes a critical G-Warning in modest-window-mgr * apparently also fixes: NB#66304 pmo-trunk-r3075 --- src/maemo/easysetup/modest-easysetup-wizard.c | 16 +------ src/maemo/easysetup/modest-easysetup-wizard.h | 8 ++-- src/maemo/modest-account-view-window.c | 59 ++++++++++------------- src/modest-ui-actions.c | 42 ++++++++++++----- src/widgets/modest-window-mgr.c | 63 +++++++++++++++++++++---- src/widgets/modest-window-mgr.h | 34 ++++++++++++- 6 files changed, 147 insertions(+), 75 deletions(-) diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index 62c15e9..46a6472 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -70,10 +70,6 @@ G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODE typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate; -/* global to make sure there is only one of this - * dialog at any time - */ -static ModestEasysetupWizardDialog *_instance = NULL; typedef enum { MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01, @@ -145,8 +141,6 @@ modest_easysetup_wizard_dialog_finalize (GObject *object) g_free (self->saved_account_name); G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object); - - _instance = NULL; } static void @@ -1159,16 +1153,10 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self) } ModestEasysetupWizardDialog* -modest_easysetup_wizard_dialog_new_or_present (void) +modest_easysetup_wizard_dialog_new (void) { - if (_instance) { - g_message ("%s: already instantiated; presenting\n", - __FUNCTION__); - gtk_window_present (GTK_WINDOW(_instance)); - return NULL; - } - return _instance = g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL); + return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL); } static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self) diff --git a/src/maemo/easysetup/modest-easysetup-wizard.h b/src/maemo/easysetup/modest-easysetup-wizard.h index a417223..2eb2f79 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.h +++ b/src/maemo/easysetup/modest-easysetup-wizard.h @@ -57,9 +57,9 @@ G_BEGIN_DECLS (G_TYPE_CHECK_CLASS_CAST ((klass), \ MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogClass)) -#define ACCOUNT_IS_WIZARD_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - MODEST_TYPE_EASYSETUP_WIZARD_DIALOG)) +#define MODEST_IS_EASYSETUP_WIZARD_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MODEST_TYPE_EASYSETUP_WIZARD_DIALOG)) #define MODEST_EASYSETUP_IS_WIZARD_DIALOG_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), \ @@ -130,7 +130,7 @@ GType modest_easysetup_wizard_dialog_get_type (void); * return NULL, until the one before is destroyed; if it returns NULL * it will gtk_window_present the existing one. */ -ModestEasysetupWizardDialog* modest_easysetup_wizard_dialog_new_or_present (void); +ModestEasysetupWizardDialog* modest_easysetup_wizard_dialog_new (void); G_END_DECLS diff --git a/src/maemo/modest-account-view-window.c b/src/maemo/modest-account-view-window.c index e36899a..776f84c 100644 --- a/src/maemo/modest-account-view-window.c +++ b/src/maemo/modest-account-view-window.c @@ -61,9 +61,6 @@ struct _ModestAccountViewWindowPrivate { GtkWidget *delete_button; GtkWidget *close_button; ModestAccountView *account_view; - - /* We remember this so that we only open one at a time: */ - ModestEasysetupWizardDialog *wizard; }; #define MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_ACCOUNT_VIEW_WINDOW, \ @@ -120,13 +117,6 @@ modest_account_view_window_class_init (ModestAccountViewWindowClass *klass) static void modest_account_view_window_finalize (GObject *obj) { - ModestAccountViewWindowPrivate *priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(obj); - - if (priv->wizard) { - gtk_widget_destroy (GTK_WIDGET (priv->wizard)); - priv->wizard = NULL; - } - G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -272,43 +262,44 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self) static void on_wizard_response (GtkDialog *dialog, gint response, gpointer user_data) -{ - ModestAccountViewWindow *self = MODEST_ACCOUNT_VIEW_WINDOW (user_data); - ModestAccountViewWindowPrivate *priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self); - +{ /* The response has already been handled by the wizard dialog itself, * creating the new account. */ /* Destroy the dialog: */ - if (priv->wizard) { - gtk_widget_destroy (GTK_WIDGET (priv->wizard)); - priv->wizard = NULL; + if (dialog) { + gtk_widget_destroy (GTK_WIDGET (dialog)); + modest_window_mgr_set_easysetup_dialog ( + modest_runtime_get_window_mgr(), NULL); } } static void on_new_button_clicked (GtkWidget *button, ModestAccountViewWindow *self) { - ModestAccountViewWindowPrivate *priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self); - - /* Show the easy-setup wizard: */ + GtkDialog *wizard; - if (priv->wizard) { - /* Just show the existing window: */ - gtk_window_present (GTK_WINDOW (priv->wizard)); + /* Show the easy-setup wizard: */ + wizard = modest_window_mgr_get_easysetup_dialog + (modest_runtime_get_window_mgr()); + if (wizard) { + /* old wizard is active already; + */ + gtk_window_present (GTK_WINDOW(wizard)); + return; } else { - /* Create and show the dialog: */ - priv->wizard = modest_easysetup_wizard_dialog_new_or_present (); - if (priv->wizard) { - gtk_window_set_transient_for (GTK_WINDOW (priv->wizard), GTK_WINDOW (self)); - /* Destroy the dialog when it is closed: */ - g_signal_connect (G_OBJECT (priv->wizard), "response", G_CALLBACK (on_wizard_response), self); - gtk_widget_show (GTK_WIDGET (priv->wizard)); - } else - /* in this case, the existing one will be topped */ - g_message ("%s: easysetup dialog already exists; ignoring", __FUNCTION__); - } + /* 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)); + } + + gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (self)); + /* Destroy the dialog when it is closed: */ + g_signal_connect (G_OBJECT (wizard), "response", G_CALLBACK + (on_wizard_response), self); + gtk_widget_show (GTK_WIDGET (wizard)); } diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index bb9cd82..eae7965 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -156,22 +156,36 @@ gboolean modest_run_account_setup_wizard (ModestWindow *win) { gboolean result = FALSE; - ModestEasysetupWizardDialog *wizard; + GtkDialog *wizard; - if (!win) - win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); - - g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE); + 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 + */ + printf ("wizard already active\n"); + 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)); + } + - wizard = modest_easysetup_wizard_dialog_new_or_present (); + /* 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 */ + if (!win) + win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr()); - /* if wizard == NULL it means there is already a easy setup thingy running; - * in that case, don't do anything here; the call above will present it instead */ - if (!wizard) { - g_message ("%s: easysetup wizard already running", __FUNCTION__); - return FALSE; - } + /* make sure the mainwindow is visible */ + gtk_widget_show_all (GTK_WIDGET(win)); + gtk_window_present (GTK_WINDOW(win)); + gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win)); /* Don't make this a modal window, because secondary windows will then @@ -188,6 +202,10 @@ 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_runtime_get_window_mgr(), NULL); + return result; } diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index f87fd13..78d3077 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -57,7 +57,10 @@ enum { typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate; struct _ModestWindowMgrPrivate { GList *window_list; + ModestWindow *main_window; + GtkDialog *easysetup_dialog; + gboolean fullscreen_mode; gboolean show_toolbars; gboolean show_toolbars_fullscreen; @@ -123,7 +126,8 @@ modest_window_mgr_init (ModestWindowMgr *obj) priv->window_list = NULL; priv->main_window = NULL; priv->fullscreen_mode = FALSE; - + priv->easysetup_dialog = NULL; + priv->preregistered_uids = NULL; /* Could not initialize it from gconf, singletons are not @@ -168,9 +172,17 @@ modest_window_mgr_finalize (GObject *obj) priv->viewer_handlers = NULL; } + if (priv->easysetup_dialog) { + g_warning ("%s: forgot to destroy an easysetup dialog somewhere", + __FUNCTION__); + gtk_widget_destroy (GTK_WIDGET(priv->easysetup_dialog)); + priv->easysetup_dialog = NULL; + } + /* Do not unref priv->main_window because it does not hold a new reference */ + G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -360,7 +372,7 @@ modest_window_mgr_register_window (ModestWindowMgr *self, gint *handler_id; g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); - g_return_if_fail (MODEST_IS_WINDOW (window)); + g_return_if_fail (GTK_IS_WINDOW (window)); priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); @@ -380,6 +392,7 @@ modest_window_mgr_register_window (ModestWindowMgr *self, } } + /* remove from the list of pre-registered uids */ if (MODEST_IS_MSG_VIEW_WINDOW(window)) { const gchar *uid = modest_msg_view_window_get_message_uid @@ -601,11 +614,13 @@ modest_window_mgr_unregister_window (ModestWindowMgr *self, priv->main_window = NULL; /* Disconnect all emissions of msg-changed */ - g_hash_table_foreach (priv->viewer_handlers, - disconnect_msg_changed, - NULL); - g_hash_table_destroy (priv->viewer_handlers); - priv->viewer_handlers = NULL; + if (priv->viewer_handlers) { + g_hash_table_foreach (priv->viewer_handlers, + disconnect_msg_changed, + NULL); + g_hash_table_destroy (priv->viewer_handlers); + priv->viewer_handlers = NULL; + } } /* Remove the viewer window handler from the hash table. The @@ -755,6 +770,31 @@ modest_window_mgr_get_main_window (ModestWindowMgr *self) return priv->main_window; } + +GtkDialog* +modest_window_mgr_get_easysetup_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; +} + + +GtkDialog* +modest_window_mgr_set_easysetup_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; +} + + static void on_nonhibernating_window_hide(GtkWidget *widget, gpointer user_data) { @@ -783,7 +823,8 @@ on_nonhibernating_window_show(GtkWidget *widget, gpointer user_data) G_CALLBACK (on_nonhibernating_window_hide), self); } -void modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self, +void +modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self, GtkWindow *window) { g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); @@ -797,7 +838,8 @@ void modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMg } } -gboolean modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self) +gboolean +modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self) { g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); @@ -809,7 +851,8 @@ gboolean modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self) } -void modest_window_mgr_save_state_for_all_windows (ModestWindowMgr *self) +void +modest_window_mgr_save_state_for_all_windows (ModestWindowMgr *self) { g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index 455f17c..acf303b 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -125,9 +125,41 @@ gboolean modest_window_mgr_get_fullscreen_mode (ModestWindowMgr *self); void modest_window_mgr_show_toolbars (ModestWindowMgr *self, gboolean show_toolbars, gboolean fullscreen); - +/** + * modest_window_mgr_get_main_window: + * @self: a #ModestWindowMgr + * + * get the main window, or create if it's not there. don't destroy + * it. + * + * Returns: the main window or NULL in case of error + **/ ModestWindow* modest_window_mgr_get_main_window (ModestWindowMgr *self); + +/** + * modest_window_mgr_get_easysetup_dialog: + * @self: a #ModestWindowMgr + * + * get the easysetup dialog; if it's NULL, there's no active dialog + * + * Returns: the easy setup dialog or NULL + **/ +GtkDialog* modest_window_mgr_get_easysetup_dialog (ModestWindowMgr *self); + + +/** + * modest_window_mgr_get_easysetup_dialog: + * @self: a #ModestWindowMgr + * + * set the easysetup dialog; set it to NULL after destroying the dialog + * + * Returns: the easy setup dialog just set + **/ +GtkDialog* modest_window_mgr_set_easysetup_dialog (ModestWindowMgr *self, + GtkDialog *dialog); + + /** * modest_window_mgr_prevent_hibernation_while_window_is_shown: * @self: a #ModestWindowMgr -- 1.7.9.5