2007-05-07 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Mon, 7 May 2007 11:58:33 +0000 (11:58 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Mon, 7 May 2007 11:58:33 +0000 (11:58 +0000)
* 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
src/maemo/easysetup/modest-easysetup-wizard.c
src/maemo/modest-account-settings-dialog.c
src/maemo/modest-connection-specific-smtp-edit-window.c
src/maemo/modest-connection-specific-smtp-window.c
src/maemo/modest-main-window.c
src/maemo/modest-signature-editor-dialog.c
src/widgets/modest-window-mgr.c
src/widgets/modest-window-mgr.h

index 2b1dd27..2d2c166 100644 (file)
@@ -1,3 +1,28 @@
+2007-05-07  Murray Cumming  <murrayc@murrayc.com>
+
+       * 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  <murrayc@murrayc.com>
 
        * src/maemo/Makefile.am:
index 0433321..0151a28 100644 (file)
@@ -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*
index 8561270..94588c8 100644 (file)
@@ -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*
index fbd89b7..5fa75b8 100644 (file)
@@ -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*
index 35a8b38..be379d2 100644 (file)
@@ -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*
index 68bf108..f0cae36 100644 (file)
@@ -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);
index 005bc8d..76281e8 100644 (file)
@@ -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 <modest-account-mgr-helpers.h>
 #include <gtk/gtkcheckbutton.h>
 #include <gtk/gtkhbox.h>
@@ -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*
index 528fa33..71de009 100644 (file)
@@ -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);
+}
+
index 8fdb66a..ba400fa 100644 (file)
@@ -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__ */