+static void on_hildon_program_is_topmost_notify(GObject *self,
+ GParamSpec *propert_param, gpointer user_data)
+{
+ HildonProgram *app = HILDON_PROGRAM (self);
+
+ /*
+ ModestWindow* self = MODEST_WINDOW(user_data);
+ */
+
+ /* Note that use of hildon_program_set_can_hibernate()
+ * is generally referred to as "setting the killable flag",
+ * though hibernation does not seem equal to death.
+ * murrayc */
+
+ if (hildon_program_get_is_topmost (app)) {
+ /* Prevent hibernation when the progam comes to the foreground,
+ * because hibernation should only happen when the application
+ * is in the background: */
+ hildon_program_set_can_hibernate (app, FALSE);
+ } else {
+ /* Allow hibernation if the program has gone to the background: */
+
+ /* However, prevent hibernation while the settings are being changed: */
+ 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);
+ }
+ }
+
+}
+
+