+static gboolean
+on_idle_close_all_but_first (gpointer data)
+{
+ gint num_windows, i;
+ gboolean retval;
+ HildonWindowStack *stack;
+
+ stack = hildon_window_stack_get_default ();
+ g_return_val_if_fail (stack, FALSE);
+
+ num_windows = hildon_window_stack_size (stack);
+
+ for (i = 0; i < (num_windows - 1); i++) {
+ GtkWidget *current_top;
+
+ /* Close window */
+ current_top = hildon_window_stack_peek (stack);
+ g_signal_emit_by_name (G_OBJECT (current_top), "delete-event", NULL, &retval);
+ }
+ return FALSE;
+}
+
+static void
+on_account_removed (TnyAccountStore *acc_store,
+ TnyAccount *account,
+ gpointer user_data)
+{
+ HildonWindowStack *stack;
+ ModestWindow *current_top;
+
+ /* Ignore transport account removals */
+ if (TNY_IS_TRANSPORT_ACCOUNT (account))
+ return;
+
+ stack = hildon_window_stack_get_default ();
+ current_top = (ModestWindow *) hildon_window_stack_peek (stack);
+
+ /* if we're showing the header view of the currently deleted
+ account, or the outbox and we deleted the last account,
+ then close the window */
+ if (current_top &&
+ (MODEST_IS_HEADER_WINDOW (current_top) ||
+ MODEST_IS_FOLDER_WINDOW (current_top))) {
+ const gchar *acc_name;
+
+ acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+
+ /* We emit it in an idle, because sometimes this
+ function could called when the account settings
+ dialog is about to close but still there. That
+ modal dialog would otherwise, prevent the
+ windows from being closed */
+ if (!strcmp (acc_name, modest_window_get_active_account (current_top)))
+ g_idle_add (on_idle_close_all_but_first, NULL);
+ }
+}
+
+static ModestWindow *
+modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self)
+{
+ ModestWindow *initial_window = NULL;
+ ModestHildon2WindowMgrPrivate *priv;
+
+ priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* Connect to the account store "account-removed" signal". We
+ do this here because in the init the singletons are still
+ not initialized properly */
+ if (!g_signal_handler_is_connected (modest_runtime_get_account_store (),
+ priv->accounts_handler)) {
+ priv->accounts_handler = g_signal_connect (modest_runtime_get_account_store (),
+ "account-removed",
+ G_CALLBACK (on_account_removed),
+ self);
+ }
+
+ /* Return accounts window */
+ initial_window = MODEST_WINDOW (modest_accounts_window_new ());
+ modest_window_mgr_register_window (self, initial_window, NULL);
+
+ return initial_window;
+}
+
+
+static ModestWindow *
+modest_hildon2_window_mgr_get_current_top (ModestWindowMgr *self)
+{
+ HildonWindowStack *stack;
+ stack = hildon_window_stack_get_default ();
+ return (ModestWindow *) hildon_window_stack_peek (stack);
+}
+
+static gint
+find_folder_window (gconstpointer a,
+ gconstpointer b)
+{
+ return (MODEST_IS_FOLDER_WINDOW (a)) ? 0 : 1;
+}
+
+ModestWindow *
+modest_hildon2_window_mgr_get_folder_window (ModestHildon2WindowMgr *self)
+{
+ ModestHildon2WindowMgrPrivate *priv;
+ GList *window;
+
+ g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
+
+ priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
+
+ window = g_list_find_custom (priv->window_list,
+ NULL,
+ find_folder_window);
+
+ return (window != NULL) ? MODEST_WINDOW (window->data) : NULL;
+}
+
+static gboolean
+modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self)
+{
+ ModestHildon2WindowMgrPrivate *priv = NULL;
+
+ g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
+
+ priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
+
+ return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;
+}
+
+static void
+modest_hildon2_window_mgr_create_caches (ModestWindowMgr *self)
+{
+ g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
+
+ modest_accounts_window_pre_create ();
+
+ MODEST_WINDOW_MGR_CLASS(parent_class)->create_caches (self);
+
+}
+
+static void
+osso_display_event_cb (osso_display_state_t state,
+ gpointer data)
+{
+ ModestHildon2WindowMgrPrivate *priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (data);
+
+ priv->display_state = state;
+
+ /* Stop blinking if the screen becomes on */
+ if (priv->display_state == OSSO_DISPLAY_ON)
+ modest_platform_remove_new_mail_notifications (TRUE);
+}