From bb1d9974f850535acaa54862cf0e9a66cc019f31 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Mon, 7 May 2007 11:58:33 +0000 Subject: [PATCH] 2007-05-07 Murray Cumming * src/widgets/modest-window-mgr.c: * src/widgets/modest-window-mgr.h: Added modest_window_mgr_prevent_hibernation_while_window_is_shown() and modest_window_mgr_get_hibernation_is_prevented(). * src/maemo/modest-main-window.c: (on_hildon_program_is_topmost_notify): Prevent hibernation (possible when the application goes to the background in the WM), if modest_window_mgr_get_hibernation_is_prevented() is TRUE. * src/maemo/easysetup/modest-easysetup-wizard.c: (modest_easysetup_wizard_dialog_init): * src/maemo/modest-account-settings-dialog.c: (modest_account_settings_dialog_init): * src/maemo/modest-connection-specific-smtp-edit-window.c: (modest_connection_specific_smtp_edit_window_init): * src/maemo/modest-connection-specific-smtp-window.c: (modest_connection_specific_smtp_window_init): * src/maemo/modest-signature-editor-dialog.c: (modest_signature_editor_dialog_init): Call modest_window_mgr_prevent_hibernation_while_window_is_shown() to prevent hibernation while any of these account settings dialogs are open. pmo-trunk-r1768 --- ChangeLog2 | 25 +++++++++ src/maemo/easysetup/modest-easysetup-wizard.c | 7 ++- src/maemo/modest-account-settings-dialog.c | 7 ++- .../modest-connection-specific-smtp-edit-window.c | 8 +++ src/maemo/modest-connection-specific-smtp-window.c | 5 ++ src/maemo/modest-main-window.c | 9 ++-- src/maemo/modest-signature-editor-dialog.c | 6 +++ src/widgets/modest-window-mgr.c | 56 ++++++++++++++++++++ src/widgets/modest-window-mgr.h | 29 ++++++++++ 9 files changed, 146 insertions(+), 6 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 2b1dd27..2d2c166 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,28 @@ +2007-05-07 Murray Cumming + + * src/widgets/modest-window-mgr.c: + * src/widgets/modest-window-mgr.h: + Added modest_window_mgr_prevent_hibernation_while_window_is_shown() and + modest_window_mgr_get_hibernation_is_prevented(). + + * src/maemo/modest-main-window.c: + (on_hildon_program_is_topmost_notify): Prevent hibernation + (possible when the application goes to the background in the WM), + if modest_window_mgr_get_hibernation_is_prevented() is TRUE. + + * src/maemo/easysetup/modest-easysetup-wizard.c: + (modest_easysetup_wizard_dialog_init): + * src/maemo/modest-account-settings-dialog.c: + (modest_account_settings_dialog_init): + * src/maemo/modest-connection-specific-smtp-edit-window.c: + (modest_connection_specific_smtp_edit_window_init): + * src/maemo/modest-connection-specific-smtp-window.c: + (modest_connection_specific_smtp_window_init): + * src/maemo/modest-signature-editor-dialog.c: + (modest_signature_editor_dialog_init): + Call modest_window_mgr_prevent_hibernation_while_window_is_shown() to + prevent hibernation while any of these account settings dialogs are open. + 2007-05-04 Murray Cumming * src/maemo/Makefile.am: diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index 0433321..0151a28 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -894,7 +894,12 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self) * then gtk_notebook_get_current_page() would return an incorrect value.) */ g_signal_connect_after (G_OBJECT (self), "response", - G_CALLBACK (on_response), self); + G_CALLBACK (on_response), self); + + /* When this window is shown, hibernation should not be possible, + * because there is no sensible way to save the state: */ + modest_window_mgr_prevent_hibernation_while_window_is_shown ( + modest_runtime_get_window_mgr (), GTK_WINDOW (self)); } ModestEasysetupWizardDialog* diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index 8561270..94588c8 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -915,7 +915,12 @@ modest_account_settings_dialog_init (ModestAccountSettingsDialog *self) g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self); - self->modified = FALSE; + self->modified = FALSE; + + /* When this window is shown, hibernation should not be possible, + * because there is no sensible way to save the state: */ + modest_window_mgr_prevent_hibernation_while_window_is_shown ( + modest_runtime_get_window_mgr (), GTK_WINDOW (self)); } ModestAccountSettingsDialog* diff --git a/src/maemo/modest-connection-specific-smtp-edit-window.c b/src/maemo/modest-connection-specific-smtp-edit-window.c index fbd89b7..5fa75b8 100644 --- a/src/maemo/modest-connection-specific-smtp-edit-window.c +++ b/src/maemo/modest-connection-specific-smtp-edit-window.c @@ -3,6 +3,8 @@ #include "modest-connection-specific-smtp-edit-window.h" #include "maemo/modest-maemo-ui-constants.h" #include "modest-hildon-includes.h" +#include "modest-runtime.h" + #include "widgets/modest-serversecurity-combo-box.h" #include "widgets/modest-secureauth-combo-box.h" #include "widgets/modest-validating-entry.h" @@ -202,6 +204,12 @@ modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEd gtk_widget_show (box); + + + /* When this window is shown, hibernation should not be possible, + * because there is no sensible way to save the state: */ + modest_window_mgr_prevent_hibernation_while_window_is_shown ( + modest_runtime_get_window_mgr (), GTK_WINDOW (self)); } ModestConnectionSpecificSmtpEditWindow* diff --git a/src/maemo/modest-connection-specific-smtp-window.c b/src/maemo/modest-connection-specific-smtp-window.c index 35a8b38..be379d2 100644 --- a/src/maemo/modest-connection-specific-smtp-window.c +++ b/src/maemo/modest-connection-specific-smtp-window.c @@ -342,6 +342,11 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow g_signal_connect (sel, "changed", G_CALLBACK(on_selection_changed), self); on_selection_changed (sel, self); + + /* When this window is shown, hibernation should not be possible, + * because there is no sensible way to save the state: */ + modest_window_mgr_prevent_hibernation_while_window_is_shown ( + modest_runtime_get_window_mgr (), GTK_WINDOW (self)); } ModestConnectionSpecificSmtpWindow* diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 68bf108..f0cae36 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -448,12 +448,13 @@ static void on_hildon_program_is_topmost_notify(GObject *self, /* Allow hibernation if the program has gone to the background: */ /* However, prevent hibernation while the settings are being changed: */ - gboolean settings_dialog_is_open = FALSE; - - if (settings_dialog_is_open) + const gboolean hibernation_prevented = + modest_window_mgr_get_hibernation_is_prevented ( + modest_runtime_get_window_mgr ()); + + if (hibernation_prevented) hildon_program_set_can_hibernate (app, FALSE); else { - /* Allow hibernation, after saving the state: */ modest_osso_save_state(); hildon_program_set_can_hibernate (app, TRUE); diff --git a/src/maemo/modest-signature-editor-dialog.c b/src/maemo/modest-signature-editor-dialog.c index 005bc8d..76281e8 100644 --- a/src/maemo/modest-signature-editor-dialog.c +++ b/src/maemo/modest-signature-editor-dialog.c @@ -6,6 +6,7 @@ #include "widgets/modest-serversecurity-combo-box.h" #include "widgets/modest-secureauth-combo-box.h" #include "widgets/modest-validating-entry.h" +#include "modest-runtime.h" #include #include #include @@ -141,6 +142,11 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) gtk_widget_show (box); + + /* When this window is shown, hibernation should not be possible, + * because there is no sensible way to save the state: */ + modest_window_mgr_prevent_hibernation_while_window_is_shown ( + modest_runtime_get_window_mgr (), GTK_WINDOW (self)); } ModestSignatureEditorDialog* diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index 528fa33..71de009 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -57,6 +57,8 @@ struct _ModestWindowMgrPrivate { gboolean fullscreen_mode; gboolean show_toolbars; gboolean show_toolbars_fullscreen; + + GSList* windows_that_prevent_hibernation; }; #define MODEST_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_WINDOW_MGR, \ @@ -419,3 +421,57 @@ modest_window_mgr_get_main_window (ModestWindowMgr *self) return priv->main_window; } + +static void +on_nonhibernating_window_hide(GtkWidget *widget, gpointer user_data) +{ + ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data); + ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + /* Forget this window, + * so hibernation will be allowed again if no windows are remembered: */ + g_slist_remove (priv->windows_that_prevent_hibernation, GTK_WINDOW(widget)); +} + +static void +on_nonhibernating_window_show(GtkWidget *widget, gpointer user_data) +{ + ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data); + ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + GtkWindow *window = GTK_WINDOW (widget); + + priv->windows_that_prevent_hibernation = + g_slist_append (priv->windows_that_prevent_hibernation, window); + + /* Allow hibernation again when the window has been hidden: */ + g_signal_connect (window, "hide", + G_CALLBACK (on_nonhibernating_window_hide), self); +} + +void modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self, GtkWindow *window) +{ + g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); + + if (GTK_WIDGET_VISIBLE(window)) { + on_nonhibernating_window_show (GTK_WIDGET (window), self); + } + else + { + /* Wait for it to be shown: */ + g_signal_connect (window, "show", + G_CALLBACK (on_nonhibernating_window_show), self); + } +} + +gboolean modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self) +{ + g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); + + ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + /* Prevent hibernation if any open windows are currently + * preventing hibernation: */ + return (g_slist_length (priv->windows_that_prevent_hibernation) > 0); +} + diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index 8fdb66a..ba400fa 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -140,6 +140,35 @@ void modest_window_mgr_show_toolbars (ModestWindowMgr *self, ModestWindow* modest_window_mgr_get_main_window (ModestWindowMgr *self); +/** + * modest_window_mgr_prevent_hibernation_while_window_is_shown: + * @self: a #ModestWindowMgr + * @window: The window that should prevent hibernation while it is shown. + * + * Call this if hibernation should not be allowed because + * windows are open whose state cannot sensible be saved, such as Account + * Settings dialogs. + * This causes modest_window_mgr_get_hibernation_is_prevented() to return TRUE + * until all such windows have been closed. That means, until the windows have + * been hidden - window destruction or other memory management is not relevant. + **/ + +void modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self, + GtkWindow *window); + +/** + * modest_window_mgr_get_hibernation_is_prevented: + * @self: a #ModestWindowMgr + * @result: Whether any windows are currently preventing hibernation. + * + * Use this to discover whether hibernation should not be allowed because + * windows are open whose state cannot sensible be saved, such as Account + * Settings dialogs. This function will return true after someone has called + * modest_window_mgr_prevent_hibernation_while_window_is_shown() and before + * that window has been closed. + **/ +gboolean modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self); + G_END_DECLS #endif /* __MODEST_WINDOW_MGR_H__ */ -- 1.7.9.5