1 /* Copyright (c) 2008, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <hildon/hildon.h>
32 #include "modest-hildon2-window-mgr.h"
33 #include "modest-msg-edit-window.h"
34 #include "modest-main-window.h"
35 #include "modest-conf.h"
36 #include "modest-defs.h"
37 #include "modest-signal-mgr.h"
38 #include "modest-runtime.h"
39 #include "modest-platform.h"
40 #include "modest-ui-actions.h"
41 #include "modest-debug.h"
42 #include "modest-tny-folder.h"
43 #include "modest-folder-window.h"
44 #include "modest-accounts-window.h"
45 #include <modest-maemo-utils.h>
47 /* 'private'/'protected' functions */
48 static void modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass);
49 static void modest_hildon2_window_mgr_instance_init (ModestHildon2WindowMgr *obj);
50 static void modest_hildon2_window_mgr_finalize (GObject *obj);
52 static gboolean on_window_destroy (ModestWindow *window,
54 ModestHildon2WindowMgr *self);
56 static gboolean modest_hildon2_window_mgr_register_window (ModestWindowMgr *self,
58 ModestWindow *parent);
59 static void modest_hildon2_window_mgr_unregister_window (ModestWindowMgr *self,
60 ModestWindow *window);
61 static void modest_hildon2_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
63 static gboolean modest_hildon2_window_mgr_get_fullscreen_mode (ModestWindowMgr *self);
64 static void modest_hildon2_window_mgr_show_toolbars (ModestWindowMgr *self,
66 gboolean show_toolbars,
68 static ModestWindow* modest_hildon2_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show);
69 static GtkWindow *modest_hildon2_window_mgr_get_modal (ModestWindowMgr *self);
70 static void modest_hildon2_window_mgr_set_modal (ModestWindowMgr *self,
73 static gboolean modest_hildon2_window_mgr_find_registered_header (ModestWindowMgr *self,
76 static GList *modest_hildon2_window_mgr_get_window_list (ModestWindowMgr *self);
77 static gboolean modest_hildon2_window_mgr_close_all_windows (ModestWindowMgr *self);
78 static gboolean window_can_close (ModestWindow *window);
79 static gboolean window_has_modals (ModestWindow *window);
80 static ModestWindow *modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self);
81 static ModestWindow *modest_hildon2_window_mgr_get_current_top (ModestWindowMgr *self);
82 static gboolean modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self);
83 static void osso_display_event_cb (osso_display_state_t state,
86 typedef struct _ModestHildon2WindowMgrPrivate ModestHildon2WindowMgrPrivate;
87 struct _ModestHildon2WindowMgrPrivate {
90 GQueue *modal_windows;
92 gboolean fullscreen_mode;
94 GHashTable *destroy_handlers;
95 GHashTable *viewer_handlers;
96 GSList *window_state_uids;
100 GSList *modal_handler_uids;
101 ModestWindow *current_top;
104 osso_display_state_t display_state;
106 #define MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
107 MODEST_TYPE_HILDON2_WINDOW_MGR, \
108 ModestHildon2WindowMgrPrivate))
110 static GObjectClass *parent_class = NULL;
113 modest_hildon2_window_mgr_get_type (void)
115 static GType my_type = 0;
117 static const GTypeInfo my_info = {
118 sizeof(ModestHildon2WindowMgrClass),
119 NULL, /* base init */
120 NULL, /* base finalize */
121 (GClassInitFunc) modest_hildon2_window_mgr_class_init,
122 NULL, /* class finalize */
123 NULL, /* class data */
124 sizeof(ModestHildon2WindowMgr),
126 (GInstanceInitFunc) modest_hildon2_window_mgr_instance_init,
129 my_type = g_type_register_static (MODEST_TYPE_WINDOW_MGR,
130 "ModestHildon2WindowMgr",
137 modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass)
139 GObjectClass *gobject_class;
140 ModestWindowMgrClass *mgr_class;
142 gobject_class = (GObjectClass*) klass;
143 mgr_class = (ModestWindowMgrClass *) klass;
145 parent_class = g_type_class_peek_parent (klass);
146 gobject_class->finalize = modest_hildon2_window_mgr_finalize;
147 mgr_class->register_window = modest_hildon2_window_mgr_register_window;
148 mgr_class->unregister_window = modest_hildon2_window_mgr_unregister_window;
149 mgr_class->set_fullscreen_mode = modest_hildon2_window_mgr_set_fullscreen_mode;
150 mgr_class->get_fullscreen_mode = modest_hildon2_window_mgr_get_fullscreen_mode;
151 mgr_class->show_toolbars = modest_hildon2_window_mgr_show_toolbars;
152 mgr_class->get_main_window = modest_hildon2_window_mgr_get_main_window;
153 mgr_class->get_modal = modest_hildon2_window_mgr_get_modal;
154 mgr_class->set_modal = modest_hildon2_window_mgr_set_modal;
155 mgr_class->find_registered_header = modest_hildon2_window_mgr_find_registered_header;
156 mgr_class->get_window_list = modest_hildon2_window_mgr_get_window_list;
157 mgr_class->close_all_windows = modest_hildon2_window_mgr_close_all_windows;
158 mgr_class->show_initial_window = modest_hildon2_window_mgr_show_initial_window;
159 mgr_class->get_current_top = modest_hildon2_window_mgr_get_current_top;
160 mgr_class->screen_is_on = modest_hildon2_window_mgr_screen_is_on;
162 g_type_class_add_private (gobject_class, sizeof(ModestHildon2WindowMgrPrivate));
167 modest_hildon2_window_mgr_instance_init (ModestHildon2WindowMgr *obj)
169 ModestHildon2WindowMgrPrivate *priv;
171 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE(obj);
172 priv->window_list = NULL;
173 priv->fullscreen_mode = FALSE;
174 priv->current_top = NULL;
175 priv->window_state_uids = NULL;
177 priv->modal_windows = g_queue_new ();
178 priv->queue_lock = g_mutex_new ();
180 /* Could not initialize it from gconf, singletons are not
182 priv->destroy_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
183 priv->viewer_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
185 priv->closing_time = 0;
187 priv->modal_handler_uids = NULL;
188 priv->display_state = OSSO_DISPLAY_ON;
190 /* Listen for changes in the screen, we don't want to show a
191 led pattern when the display is on for example */
192 osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
193 osso_display_event_cb,
199 modest_hildon2_window_mgr_finalize (GObject *obj)
201 ModestHildon2WindowMgrPrivate *priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE(obj);
203 modest_signal_mgr_disconnect_all_and_destroy (priv->window_state_uids);
204 priv->window_state_uids = NULL;
206 osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
209 if (priv->window_list) {
210 GList *iter = priv->window_list;
211 /* unregister pending windows */
213 ModestWindow *window = (ModestWindow *) iter->data;
214 iter = g_list_next (iter);
215 modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (obj), window);
217 g_list_free (priv->window_list);
218 priv->window_list = NULL;
221 /* Free the hash table with the handlers */
222 if (priv->destroy_handlers) {
223 g_hash_table_destroy (priv->destroy_handlers);
224 priv->destroy_handlers = NULL;
227 if (priv->viewer_handlers) {
228 g_hash_table_destroy (priv->viewer_handlers);
229 priv->viewer_handlers = NULL;
232 modest_signal_mgr_disconnect_all_and_destroy (priv->modal_handler_uids);
233 priv->modal_handler_uids = NULL;
235 if (priv->modal_windows) {
236 g_mutex_lock (priv->queue_lock);
237 g_queue_free (priv->modal_windows);
238 priv->modal_windows = NULL;
239 g_mutex_unlock (priv->queue_lock);
241 g_mutex_free (priv->queue_lock);
243 /* Do not unref priv->main_window because it does not hold a
246 G_OBJECT_CLASS(parent_class)->finalize (obj);
250 modest_hildon2_window_mgr_new (void)
252 return MODEST_WINDOW_MGR(g_object_new(MODEST_TYPE_HILDON2_WINDOW_MGR, NULL));
256 modest_hildon2_window_mgr_close_all_windows (ModestWindowMgr *self)
258 ModestHildon2WindowMgrPrivate *priv = NULL;
259 gboolean ret_value = FALSE;
261 HildonWindowStack *stack;
262 gboolean failed = FALSE;
264 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
265 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
267 stack = hildon_window_stack_get_default ();
269 while ((window = hildon_window_stack_peek (stack)) != NULL) {
270 g_signal_emit_by_name (G_OBJECT (window), "delete-event", NULL, &ret_value);
271 if (ret_value == TRUE) {
281 compare_msguids (ModestWindow *win,
284 const gchar *msg_uid;
286 if ((!MODEST_IS_MSG_EDIT_WINDOW (win)) && (!MODEST_IS_MSG_VIEW_WINDOW (win)))
289 /* Get message uid from msg window */
290 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
291 msg_uid = modest_msg_edit_window_get_message_uid (MODEST_MSG_EDIT_WINDOW (win));
292 if (msg_uid && uid &&!strcmp (msg_uid, uid))
295 msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
298 if (msg_uid && uid &&!strcmp (msg_uid, uid))
305 modest_hildon2_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *header,
308 ModestHildon2WindowMgrPrivate *priv = NULL;
310 gboolean has_header, has_window = FALSE;
313 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
314 g_return_val_if_fail (TNY_IS_HEADER(header), FALSE);
316 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
318 has_header = MODEST_WINDOW_MGR_CLASS (parent_class)->find_registered_header (self, header, win);
320 uid = modest_tny_folder_get_header_unique_id (header);
322 item = g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids);
326 if ((!MODEST_IS_MSG_VIEW_WINDOW(item->data)) &&
327 (!MODEST_IS_MSG_EDIT_WINDOW (item->data)))
328 g_debug ("not a valid window!");
330 g_debug ("found a window");
331 *win = MODEST_WINDOW (item->data);
337 return has_header || has_window;
341 modest_hildon2_window_mgr_get_window_list (ModestWindowMgr *self)
343 ModestHildon2WindowMgrPrivate *priv;
345 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
346 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
348 return g_list_copy (priv->window_list);
352 modest_hildon2_window_mgr_register_window (ModestWindowMgr *self,
353 ModestWindow *window,
354 ModestWindow *parent)
357 ModestHildon2WindowMgrPrivate *priv;
359 HildonProgram *program;
360 HildonWindowStack *stack;
361 gboolean nested_msg = FALSE;
363 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
364 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
366 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
368 program = hildon_program_get_instance ();
369 win = g_list_find (priv->window_list, window);
371 /* this is for the case we want to register the window and it was already
372 * registered. We leave silently, telling the operation was succesful.
374 gtk_window_present (GTK_WINDOW (win));
378 stack = hildon_window_stack_get_default ();
380 if (!MODEST_WINDOW_MGR_CLASS (parent_class)->register_window (self, window, parent))
383 /* Add to list. Keep a reference to the window */
384 g_object_ref (window);
385 priv->window_list = g_list_prepend (priv->window_list, window);
387 if (priv->current_top == NULL)
388 priv->current_top = (ModestWindow *) hildon_window_stack_peek (stack);
389 nested_msg = MODEST_IS_MSG_VIEW_WINDOW (window) &&
390 MODEST_IS_MSG_VIEW_WINDOW (parent);
392 /* Close views if they're being shown. Nevertheless we must
393 allow nested messages */
395 (MODEST_IS_MSG_EDIT_WINDOW (priv->current_top) ||
396 MODEST_IS_MSG_VIEW_WINDOW (priv->current_top))) {
399 /* If the current view has modal dialogs then
400 we fail to register the new view */
401 if ((priv->current_top != NULL) &&
402 window_has_modals (MODEST_WINDOW (priv->current_top))) {
403 /* Window on top but it has opened dialogs */
407 /* Close the current view */
408 g_signal_emit_by_name (G_OBJECT (priv->current_top), "delete-event", NULL, &retval);
409 if (retval == TRUE) {
410 /* Cancelled closing top window, then we fail to register */
415 /* Listen to object destruction */
416 handler_id = g_malloc0 (sizeof (gint));
417 *handler_id = g_signal_connect (window, "delete-event", G_CALLBACK (on_window_destroy), self);
418 g_hash_table_insert (priv->destroy_handlers, window, handler_id);
420 /* Show toolbar always */
421 modest_window_show_toolbar (window, TRUE);
425 /* Add to list. Keep a reference to the window */
426 priv->window_list = g_list_remove (priv->window_list, window);
427 g_object_unref (window);
428 priv->current_top = (ModestWindow *) hildon_window_stack_peek (stack);
429 if (priv->current_top)
430 gtk_window_present (GTK_WINDOW (priv->current_top));
435 cancel_window_operations (ModestWindow *window)
437 GSList* pending_ops = NULL;
439 /* cancel open and receive operations */
440 pending_ops = modest_mail_operation_queue_get_by_source (modest_runtime_get_mail_operation_queue (),
442 while (pending_ops != NULL) {
443 ModestMailOperationTypeOperation type;
444 GSList* tmp_list = NULL;
446 type = modest_mail_operation_get_type_operation (MODEST_MAIL_OPERATION (pending_ops->data));
447 if (type == MODEST_MAIL_OPERATION_TYPE_RECEIVE || type == MODEST_MAIL_OPERATION_TYPE_OPEN) {
448 modest_mail_operation_cancel (pending_ops->data);
450 g_object_unref (G_OBJECT (pending_ops->data));
451 tmp_list = pending_ops;
452 pending_ops = g_slist_next (pending_ops);
453 g_slist_free_1 (tmp_list);
458 window_has_modals (ModestWindow *window)
462 gboolean retvalue = FALSE;
464 /* First we fetch all toplevels */
465 toplevels = gtk_window_list_toplevels ();
466 for (node = toplevels; node != NULL; node = g_list_next (node)) {
467 if (GTK_IS_WINDOW (node->data) &&
468 gtk_window_get_transient_for (GTK_WINDOW (node->data)) == GTK_WINDOW (window) &&
469 GTK_WIDGET_VISIBLE (node->data)) {
474 g_list_free (toplevels);
479 window_can_close (ModestWindow *window)
481 /* An editor can be always closed no matter the dialogs it has
483 if (MODEST_IS_MSG_EDIT_WINDOW (window))
486 return !window_has_modals (window);
490 on_window_destroy (ModestWindow *window,
492 ModestHildon2WindowMgr *self)
494 gboolean no_propagate = FALSE;
496 if (!window_can_close (window))
499 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
500 gboolean sent = FALSE;
501 sent = modest_msg_edit_window_get_sent (MODEST_MSG_EDIT_WINDOW (window));
502 /* Save currently edited message to Drafts if it was not sent */
503 if (!sent && modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (window))) {
505 if (!modest_ui_actions_on_save_to_drafts (NULL, MODEST_MSG_EDIT_WINDOW (window)))
510 /* Unregister window */
511 modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (self), window);
512 no_propagate = FALSE;
518 modest_hildon2_window_mgr_unregister_window (ModestWindowMgr *self,
519 ModestWindow *window)
522 ModestHildon2WindowMgrPrivate *priv;
523 gulong *tmp, handler_id;
524 gboolean check_close_all = FALSE;
527 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
528 g_return_if_fail (MODEST_IS_WINDOW (window));
530 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
532 win = g_list_find (priv->window_list, window);
534 g_warning ("Trying to unregister a window that has not being registered yet");
538 /* Remember this for the end of the method */
539 if (MODEST_IS_FOLDER_WINDOW (window))
540 check_close_all = TRUE;
542 /* Remove the viewer window handler from the hash table. The
543 HashTable could not exist if the main window was closed
544 when there were other windows remaining */
545 if (MODEST_IS_MSG_VIEW_WINDOW (window) && priv->viewer_handlers) {
546 tmp = (gulong *) g_hash_table_lookup (priv->viewer_handlers, window);
547 /* If the viewer was created without a main window
548 (for example when opening a message through D-Bus
549 the viewer handlers was not registered */
551 g_signal_handler_disconnect (window, *tmp);
552 g_hash_table_remove (priv->viewer_handlers, window);
556 /* Remove from list & hash table */
557 priv->window_list = g_list_remove_link (priv->window_list, win);
558 tmp = g_hash_table_lookup (priv->destroy_handlers, window);
561 g_hash_table_remove (priv->destroy_handlers, window);
563 /* cancel open and receive operations */
564 cancel_window_operations (window);
566 /* Check if it's the topmost window, and remove the window from the stack.
567 * This is needed for the cases there's no other topmost window that will
568 * replace it in topmost handler.
570 if (window == priv->current_top)
571 priv->current_top = NULL;
573 /* Disconnect the "window-state-event" handler, we won't need it anymore */
574 if (priv->window_state_uids) {
575 priv->window_state_uids =
576 modest_signal_mgr_disconnect (priv->window_state_uids,
578 "notify::is-topmost");
581 /* Disconnect the "delete-event" handler, we won't need it anymore */
582 g_signal_handler_disconnect (window, handler_id);
584 /* Destroy the window */
585 g_object_unref (win->data);
588 MODEST_WINDOW_MGR_CLASS (parent_class)->unregister_window (self, window);
590 /* We have to get the number of windows here in order not to
591 emit the signal too many times */
592 num_windows = modest_window_mgr_get_num_windows (self);
594 /* Check if we have to destroy the accounts window as
595 well. This happens if we only have one or none remote
597 if (check_close_all) {
598 ModestTnyAccountStore *acc_store = modest_runtime_get_account_store ();
599 if (modest_tny_account_store_get_num_remote_accounts (acc_store) < 2)
600 modest_window_mgr_close_all_windows (self);
603 /* If there are no more windows registered emit the signal */
604 if (num_windows == 0)
605 g_signal_emit_by_name (self, "window-list-empty");
610 modest_hildon2_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
613 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
619 modest_hildon2_window_mgr_get_fullscreen_mode (ModestWindowMgr *self)
625 modest_hildon2_window_mgr_show_toolbars (ModestWindowMgr *self,
627 gboolean show_toolbars,
630 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
636 modest_hildon2_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show)
638 ModestHildon2WindowMgrPrivate *priv;
639 ModestWindow *result;
641 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
642 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
644 /* TODO: make this return NULL always */
646 result = MODEST_WINDOW_MGR_CLASS (parent_class)->get_main_window (self, FALSE);
647 /* create the main window, if it hasn't been created yet */
648 if (!result && show) {
649 /* modest_window_mgr_register_window will set priv->main_window */
650 result = modest_main_window_new ();
651 /* We have to remove all other windows */
652 if (!modest_window_mgr_close_all_windows (self)) {
653 gtk_widget_destroy (GTK_WIDGET (result));
656 if (!modest_window_mgr_register_window (self, result, NULL)) {
657 gtk_widget_destroy (GTK_WIDGET (result));
661 g_debug ("%s: created main window: %p\n", __FUNCTION__, result);
665 gtk_widget_show_all (GTK_WIDGET (result));
666 gtk_window_present (GTK_WINDOW (result));
674 modest_hildon2_window_mgr_get_modal (ModestWindowMgr *self)
676 ModestHildon2WindowMgrPrivate *priv;
677 GList *toplevel_list;
680 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
681 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
684 toplevel_list = gtk_window_list_toplevels ();
685 while (toplevel_list) {
686 if (gtk_window_is_active (toplevel_list->data)) {
687 toplevel = toplevel_list->data;
690 toplevel_list = g_list_next (toplevel_list);
698 modest_hildon2_window_mgr_set_modal (ModestWindowMgr *self,
702 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
703 g_return_if_fail (GTK_IS_WINDOW (window));
705 gtk_window_set_modal (window, TRUE);
706 gtk_window_set_transient_for (window, parent);
707 gtk_window_set_destroy_with_parent (window, TRUE);
710 static ModestWindow *
711 modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self)
713 ModestWindow *initial_window = NULL;
714 ModestTnyAccountStore *acc_store;
716 /* Always create accounts window. We'll decide later if we
717 want to show it or not, depending the number of accounts */
718 initial_window = MODEST_WINDOW (modest_accounts_window_new ());
719 modest_window_mgr_register_window (self, initial_window, NULL);
721 /* If there are less than 2 remote accounts then directly show
722 the folder window and do not show the accounts window */
723 acc_store = modest_runtime_get_account_store ();
724 if (modest_tny_account_store_get_num_remote_accounts (acc_store) < 2) {
725 ModestAccountMgr *mgr;
727 /* Show first the accounts window to add it to the
728 stack. This has to be changed when the new
729 stackable API is available. There will be a method
730 to show all the windows that will only show the
731 last one to the user. The current code shows both
732 windows, one after the other */
733 gtk_widget_show (GTK_WIDGET (initial_window));
735 initial_window = MODEST_WINDOW (modest_folder_window_new (NULL));
736 mgr = modest_runtime_get_account_mgr ();
737 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (initial_window),
738 modest_account_mgr_get_default_account (mgr));
739 modest_window_mgr_register_window (self, initial_window, NULL);
742 return initial_window;
746 static ModestWindow *
747 modest_hildon2_window_mgr_get_current_top (ModestWindowMgr *self)
749 ModestHildon2WindowMgrPrivate *priv;
751 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
752 return priv->current_top;
756 find_folder_window (gconstpointer a,
759 return (MODEST_IS_FOLDER_WINDOW (a)) ? 0 : 1;
763 modest_hildon2_window_mgr_get_folder_window (ModestHildon2WindowMgr *self)
765 ModestHildon2WindowMgrPrivate *priv;
768 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
770 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
772 window = g_list_find_custom (priv->window_list,
776 return (window != NULL) ? MODEST_WINDOW (window->data) : NULL;
780 modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self)
782 ModestHildon2WindowMgrPrivate *priv = NULL;
784 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
786 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
788 return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;
792 osso_display_event_cb (osso_display_state_t state,
795 ModestHildon2WindowMgrPrivate *priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (data);
797 priv->display_state = state;
799 /* Stop blinking if the screen becomes on */
800 if (priv->display_state == OSSO_DISPLAY_ON)
801 modest_platform_remove_new_mail_notifications (TRUE);