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-mailboxes-window.h"
35 #include "modest-header-window.h"
36 #include "modest-main-window.h"
37 #include "modest-conf.h"
38 #include "modest-defs.h"
39 #include "modest-signal-mgr.h"
40 #include "modest-runtime.h"
41 #include "modest-platform.h"
42 #include "modest-ui-actions.h"
43 #include "modest-debug.h"
44 #include "modest-tny-folder.h"
45 #include "modest-folder-window.h"
46 #include "modest-accounts-window.h"
47 #include "modest-maemo-utils.h"
48 #include "modest-utils.h"
49 #include "modest-tny-msg.h"
50 #include <tny-merge-folder.h>
52 /* 'private'/'protected' functions */
53 static void modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass);
54 static void modest_hildon2_window_mgr_instance_init (ModestHildon2WindowMgr *obj);
55 static void modest_hildon2_window_mgr_finalize (GObject *obj);
57 static gboolean on_window_destroy (ModestWindow *window,
59 ModestHildon2WindowMgr *self);
61 static gboolean modest_hildon2_window_mgr_register_window (ModestWindowMgr *self,
63 ModestWindow *parent);
64 static void modest_hildon2_window_mgr_unregister_window (ModestWindowMgr *self,
65 ModestWindow *window);
66 static void modest_hildon2_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
68 static gboolean modest_hildon2_window_mgr_get_fullscreen_mode (ModestWindowMgr *self);
69 static void modest_hildon2_window_mgr_show_toolbars (ModestWindowMgr *self,
71 gboolean show_toolbars,
73 static ModestWindow* modest_hildon2_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show);
74 static GtkWindow *modest_hildon2_window_mgr_get_modal (ModestWindowMgr *self);
75 static void modest_hildon2_window_mgr_set_modal (ModestWindowMgr *self,
78 static gboolean modest_hildon2_window_mgr_find_registered_header (ModestWindowMgr *self,
81 static GList *modest_hildon2_window_mgr_get_window_list (ModestWindowMgr *self);
82 static gboolean modest_hildon2_window_mgr_close_all_windows (ModestWindowMgr *self);
83 static gboolean window_can_close (ModestWindow *window);
84 static gboolean window_has_modals (ModestWindow *window);
85 static ModestWindow *modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self);
86 static ModestWindow *modest_hildon2_window_mgr_get_current_top (ModestWindowMgr *self);
87 static gboolean modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self);
88 static void osso_display_event_cb (osso_display_state_t state,
90 static void on_account_removed (TnyAccountStore *acc_store,
94 typedef struct _ModestHildon2WindowMgrPrivate ModestHildon2WindowMgrPrivate;
95 struct _ModestHildon2WindowMgrPrivate {
98 GQueue *modal_windows;
100 gboolean fullscreen_mode;
102 GHashTable *destroy_handlers;
103 GHashTable *viewer_handlers;
104 GSList *window_state_uids;
108 GSList *modal_handler_uids;
109 ModestWindow *current_top;
111 gulong accounts_handler;
114 osso_display_state_t display_state;
116 #define MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
117 MODEST_TYPE_HILDON2_WINDOW_MGR, \
118 ModestHildon2WindowMgrPrivate))
120 static GObjectClass *parent_class = NULL;
123 modest_hildon2_window_mgr_get_type (void)
125 static GType my_type = 0;
127 static const GTypeInfo my_info = {
128 sizeof(ModestHildon2WindowMgrClass),
129 NULL, /* base init */
130 NULL, /* base finalize */
131 (GClassInitFunc) modest_hildon2_window_mgr_class_init,
132 NULL, /* class finalize */
133 NULL, /* class data */
134 sizeof(ModestHildon2WindowMgr),
136 (GInstanceInitFunc) modest_hildon2_window_mgr_instance_init,
139 my_type = g_type_register_static (MODEST_TYPE_WINDOW_MGR,
140 "ModestHildon2WindowMgr",
147 modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass)
149 GObjectClass *gobject_class;
150 ModestWindowMgrClass *mgr_class;
152 gobject_class = (GObjectClass*) klass;
153 mgr_class = (ModestWindowMgrClass *) klass;
155 parent_class = g_type_class_peek_parent (klass);
156 gobject_class->finalize = modest_hildon2_window_mgr_finalize;
157 mgr_class->register_window = modest_hildon2_window_mgr_register_window;
158 mgr_class->unregister_window = modest_hildon2_window_mgr_unregister_window;
159 mgr_class->set_fullscreen_mode = modest_hildon2_window_mgr_set_fullscreen_mode;
160 mgr_class->get_fullscreen_mode = modest_hildon2_window_mgr_get_fullscreen_mode;
161 mgr_class->show_toolbars = modest_hildon2_window_mgr_show_toolbars;
162 mgr_class->get_main_window = modest_hildon2_window_mgr_get_main_window;
163 mgr_class->get_modal = modest_hildon2_window_mgr_get_modal;
164 mgr_class->set_modal = modest_hildon2_window_mgr_set_modal;
165 mgr_class->find_registered_header = modest_hildon2_window_mgr_find_registered_header;
166 mgr_class->get_window_list = modest_hildon2_window_mgr_get_window_list;
167 mgr_class->close_all_windows = modest_hildon2_window_mgr_close_all_windows;
168 mgr_class->show_initial_window = modest_hildon2_window_mgr_show_initial_window;
169 mgr_class->get_current_top = modest_hildon2_window_mgr_get_current_top;
170 mgr_class->screen_is_on = modest_hildon2_window_mgr_screen_is_on;
172 g_type_class_add_private (gobject_class, sizeof(ModestHildon2WindowMgrPrivate));
177 modest_hildon2_window_mgr_instance_init (ModestHildon2WindowMgr *obj)
179 ModestHildon2WindowMgrPrivate *priv;
181 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE(obj);
182 priv->window_list = NULL;
183 priv->fullscreen_mode = FALSE;
184 priv->window_state_uids = NULL;
186 priv->modal_windows = g_queue_new ();
187 priv->queue_lock = g_mutex_new ();
189 /* Could not initialize it from gconf, singletons are not
191 priv->destroy_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
192 priv->viewer_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
194 priv->closing_time = 0;
196 priv->modal_handler_uids = NULL;
197 priv->display_state = OSSO_DISPLAY_ON;
199 /* Listen for changes in the screen, we don't want to show a
200 led pattern when the display is on for example */
201 osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
202 osso_display_event_cb,
208 modest_hildon2_window_mgr_finalize (GObject *obj)
210 ModestHildon2WindowMgrPrivate *priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE(obj);
211 ModestTnyAccountStore *acc_store;
213 modest_signal_mgr_disconnect_all_and_destroy (priv->window_state_uids);
214 priv->window_state_uids = NULL;
216 osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
219 acc_store = modest_runtime_get_account_store ();
220 if (acc_store && g_signal_handler_is_connected (acc_store, priv->accounts_handler))
221 g_signal_handler_disconnect (acc_store, priv->accounts_handler);
223 if (priv->window_list) {
224 GList *iter = priv->window_list;
225 /* unregister pending windows */
227 ModestWindow *window = (ModestWindow *) iter->data;
228 iter = g_list_next (iter);
229 modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (obj), window);
231 g_list_free (priv->window_list);
232 priv->window_list = NULL;
235 /* Free the hash table with the handlers */
236 if (priv->destroy_handlers) {
237 g_hash_table_destroy (priv->destroy_handlers);
238 priv->destroy_handlers = NULL;
241 if (priv->viewer_handlers) {
242 g_hash_table_destroy (priv->viewer_handlers);
243 priv->viewer_handlers = NULL;
246 modest_signal_mgr_disconnect_all_and_destroy (priv->modal_handler_uids);
247 priv->modal_handler_uids = NULL;
249 if (priv->modal_windows) {
250 g_mutex_lock (priv->queue_lock);
251 g_queue_free (priv->modal_windows);
252 priv->modal_windows = NULL;
253 g_mutex_unlock (priv->queue_lock);
255 g_mutex_free (priv->queue_lock);
257 /* Do not unref priv->main_window because it does not hold a
260 G_OBJECT_CLASS(parent_class)->finalize (obj);
264 modest_hildon2_window_mgr_new (void)
266 return MODEST_WINDOW_MGR(g_object_new(MODEST_TYPE_HILDON2_WINDOW_MGR, NULL));
270 modest_hildon2_window_mgr_close_all_windows (ModestWindowMgr *self)
272 ModestHildon2WindowMgrPrivate *priv = NULL;
273 gboolean ret_value = FALSE;
275 HildonWindowStack *stack;
276 gboolean failed = FALSE;
278 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
279 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
281 stack = hildon_window_stack_get_default ();
283 while ((window = hildon_window_stack_peek (stack)) != NULL) {
284 g_signal_emit_by_name (G_OBJECT (window), "delete-event", NULL, &ret_value);
285 if (ret_value == TRUE) {
295 compare_msguids (ModestWindow *win,
298 const gchar *msg_uid;
300 if ((!MODEST_IS_MSG_EDIT_WINDOW (win)) && (!MODEST_IS_MSG_VIEW_WINDOW (win)))
303 /* Get message uid from msg window */
304 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
305 msg_uid = modest_msg_edit_window_get_message_uid (MODEST_MSG_EDIT_WINDOW (win));
306 if (msg_uid && uid &&!strcmp (msg_uid, uid))
309 msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
312 if (msg_uid && uid &&!strcmp (msg_uid, uid))
319 compare_headers (ModestWindow *win,
322 TnyHeader *my_header;
325 if (!MODEST_IS_MSG_VIEW_WINDOW (win))
328 /* Get message uid from msg window */
329 my_header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
331 if (my_header == header)
333 g_object_unref (my_header);
340 modest_hildon2_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *header,
343 ModestHildon2WindowMgrPrivate *priv = NULL;
345 gboolean has_header, has_window = FALSE;
348 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
349 g_return_val_if_fail (TNY_IS_HEADER(header), FALSE);
351 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
353 has_header = MODEST_WINDOW_MGR_CLASS (parent_class)->find_registered_header (self, header, win);
355 uid = modest_tny_folder_get_header_unique_id (header);
357 item = g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids);
361 if ((!MODEST_IS_MSG_VIEW_WINDOW(item->data)) &&
362 (!MODEST_IS_MSG_EDIT_WINDOW (item->data)))
363 g_debug ("not a valid window!");
365 g_debug ("found a window");
366 *win = MODEST_WINDOW (item->data);
372 return has_header || has_window;
376 modest_hildon2_window_mgr_get_window_list (ModestWindowMgr *self)
378 ModestHildon2WindowMgrPrivate *priv;
380 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
381 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
383 return g_list_copy (priv->window_list);
387 modest_hildon2_window_mgr_register_window (ModestWindowMgr *self,
388 ModestWindow *window,
389 ModestWindow *parent)
392 ModestHildon2WindowMgrPrivate *priv;
394 HildonWindowStack *stack;
395 gboolean nested_msg = FALSE;
396 ModestWindow *current_top;
398 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
399 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
401 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
403 stack = hildon_window_stack_get_default ();
404 current_top = (ModestWindow *) hildon_window_stack_peek (stack);
406 win = g_list_find (priv->window_list, window);
408 /* this is for the case we want to register the window
409 and it was already registered */
410 gtk_window_present (GTK_WINDOW (window));
414 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
417 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (window));
420 uid = modest_tny_folder_get_header_unique_id (header);
422 /* Embedded messages do not have uid */
424 if (g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids)) {
425 g_debug ("%s found another view window showing the same header", __FUNCTION__);
427 g_object_unref (header);
432 if (g_list_find_custom (priv->window_list, header, (GCompareFunc) compare_headers)) {
433 g_debug ("%s found another view window showing the same header", __FUNCTION__);
434 g_object_unref (header);
438 g_object_unref (header);
442 if (MODEST_IS_FOLDER_WINDOW (current_top) && MODEST_IS_FOLDER_WINDOW (window)) {
443 gtk_window_present (GTK_WINDOW (window));
447 if (MODEST_IS_MAILBOXES_WINDOW (current_top) && MODEST_IS_MAILBOXES_WINDOW (window)) {
448 gtk_window_present (GTK_WINDOW (window));
452 /* Mailboxes window can not replace folder windows */
453 if (MODEST_IS_FOLDER_WINDOW (current_top) && MODEST_IS_MAILBOXES_WINDOW (window)) {
454 gtk_window_present (GTK_WINDOW (current_top));
458 /* Trying to open a folders window and a mailboxes window at
459 the same time from the accounts window is not allowed */
460 if (MODEST_IS_MAILBOXES_WINDOW (current_top) &&
461 MODEST_IS_FOLDER_WINDOW (window) &&
462 MODEST_IS_ACCOUNTS_WINDOW (parent)) {
463 gtk_window_present (GTK_WINDOW (window));
467 if (MODEST_IS_HEADER_WINDOW (current_top) && MODEST_IS_HEADER_WINDOW (window)) {
468 g_debug ("Trying to register a second header window is not allowed");
469 gtk_window_present (GTK_WINDOW (current_top));
473 if (!MODEST_WINDOW_MGR_CLASS (parent_class)->register_window (self, window, parent))
476 /* Add to list. Keep a reference to the window */
477 g_object_ref (window);
478 priv->window_list = g_list_prepend (priv->window_list, window);
480 nested_msg = MODEST_IS_MSG_VIEW_WINDOW (window) &&
481 MODEST_IS_MSG_VIEW_WINDOW (parent);
483 /* Close views if they're being shown. Nevertheless we must
484 allow nested messages */
486 (MODEST_IS_MSG_EDIT_WINDOW (current_top) ||
487 MODEST_IS_MSG_VIEW_WINDOW (current_top))) {
490 /* If the current view has modal dialogs then
491 we fail to register the new view */
492 if ((current_top != NULL) &&
493 window_has_modals (MODEST_WINDOW (current_top))) {
494 /* Window on top but it has opened dialogs */
498 /* Close the current view */
499 g_signal_emit_by_name (G_OBJECT (current_top), "delete-event", NULL, &retval);
500 if (retval == TRUE) {
501 /* Cancelled closing top window, then we fail to register */
506 /* Listen to object destruction */
507 handler_id = g_malloc0 (sizeof (gint));
508 *handler_id = g_signal_connect (window, "delete-event", G_CALLBACK (on_window_destroy), self);
509 g_hash_table_insert (priv->destroy_handlers, window, handler_id);
511 /* Show toolbar always */
512 modest_window_show_toolbar (window, TRUE);
516 /* Add to list. Keep a reference to the window */
517 priv->window_list = g_list_remove (priv->window_list, window);
518 g_object_unref (window);
519 current_top = (ModestWindow *) hildon_window_stack_peek (stack);
521 gtk_window_present (GTK_WINDOW (current_top));
526 cancel_window_operations (ModestWindow *window)
528 GSList* pending_ops = NULL;
530 /* cancel open and receive operations */
531 pending_ops = modest_mail_operation_queue_get_by_source (modest_runtime_get_mail_operation_queue (),
533 while (pending_ops != NULL) {
534 ModestMailOperationTypeOperation type;
535 GSList* tmp_list = NULL;
537 type = modest_mail_operation_get_type_operation (MODEST_MAIL_OPERATION (pending_ops->data));
538 if (type == MODEST_MAIL_OPERATION_TYPE_RECEIVE || type == MODEST_MAIL_OPERATION_TYPE_OPEN) {
539 modest_mail_operation_cancel (pending_ops->data);
541 g_object_unref (G_OBJECT (pending_ops->data));
542 tmp_list = pending_ops;
543 pending_ops = g_slist_next (pending_ops);
544 g_slist_free_1 (tmp_list);
549 window_has_modals (ModestWindow *window)
553 gboolean retvalue = FALSE;
555 /* First we fetch all toplevels */
556 toplevels = gtk_window_list_toplevels ();
557 for (node = toplevels; node != NULL; node = g_list_next (node)) {
558 if (GTK_IS_WINDOW (node->data) &&
559 gtk_window_get_transient_for (GTK_WINDOW (node->data)) == GTK_WINDOW (window) &&
560 GTK_WIDGET_VISIBLE (node->data)) {
565 g_list_free (toplevels);
570 window_can_close (ModestWindow *window)
572 /* An editor can be always closed no matter the dialogs it has
574 if (MODEST_IS_MSG_EDIT_WINDOW (window))
577 return !window_has_modals (window);
581 on_window_destroy (ModestWindow *window,
583 ModestHildon2WindowMgr *self)
585 gboolean no_propagate = FALSE;
587 if (!window_can_close (window))
590 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
591 gboolean sent = FALSE;
592 sent = modest_msg_edit_window_get_sent (MODEST_MSG_EDIT_WINDOW (window));
593 /* Save currently edited message to Drafts if it was not sent */
594 if (!sent && modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (window))) {
595 ModestMsgEditWindow *edit_window;
598 edit_window = MODEST_MSG_EDIT_WINDOW (window);
599 data = modest_msg_edit_window_get_msg_data (edit_window);
603 guint64 parts_size, available_size, expected_size;
605 available_size = modest_utils_get_available_space (NULL);
606 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
607 expected_size = modest_tny_msg_estimate_size (data->plain_body,
611 modest_msg_edit_window_free_msg_data (edit_window, data);
614 /* If there is not enough space
615 available for saving the message
616 then show an error and close the
617 window without saving */
618 if (expected_size >= available_size) {
619 modest_platform_run_information_dialog (GTK_WINDOW (edit_window),
620 _("mail_in_ui_save_error"),
623 if (!modest_ui_actions_on_save_to_drafts (NULL, MODEST_MSG_EDIT_WINDOW (window)))
627 g_warning ("Edit window without message data. This is probably a bug");
632 /* Unregister window */
633 modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (self), window);
634 no_propagate = FALSE;
640 modest_hildon2_window_mgr_unregister_window (ModestWindowMgr *self,
641 ModestWindow *window)
644 ModestHildon2WindowMgrPrivate *priv;
645 gulong *tmp, handler_id;
648 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
649 g_return_if_fail (MODEST_IS_WINDOW (window));
651 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
653 win = g_list_find (priv->window_list, window);
655 g_warning ("Trying to unregister a window that has not being registered yet");
659 /* Remove the viewer window handler from the hash table. The
660 HashTable could not exist if the main window was closed
661 when there were other windows remaining */
662 if (MODEST_IS_MSG_VIEW_WINDOW (window) && priv->viewer_handlers) {
663 tmp = (gulong *) g_hash_table_lookup (priv->viewer_handlers, window);
664 /* If the viewer was created without a main window
665 (for example when opening a message through D-Bus
666 the viewer handlers was not registered */
668 g_signal_handler_disconnect (window, *tmp);
669 g_hash_table_remove (priv->viewer_handlers, window);
673 /* Remove from list & hash table */
674 priv->window_list = g_list_remove_link (priv->window_list, win);
675 tmp = g_hash_table_lookup (priv->destroy_handlers, window);
678 g_hash_table_remove (priv->destroy_handlers, window);
680 /* cancel open and receive operations */
681 cancel_window_operations (window);
683 /* Disconnect the "window-state-event" handler, we won't need it anymore */
684 if (priv->window_state_uids) {
685 priv->window_state_uids =
686 modest_signal_mgr_disconnect (priv->window_state_uids,
688 "notify::is-topmost");
691 /* Disconnect the "delete-event" handler, we won't need it anymore */
692 g_signal_handler_disconnect (window, handler_id);
694 /* Destroy the window */
695 g_object_unref (win->data);
698 MODEST_WINDOW_MGR_CLASS (parent_class)->unregister_window (self, window);
700 /* We have to get the number of windows here in order not to
701 emit the signal too many times */
702 num_windows = modest_window_mgr_get_num_windows (self);
704 /* If there are no more windows registered emit the signal */
705 if (num_windows == 0)
706 g_signal_emit_by_name (self, "window-list-empty");
711 modest_hildon2_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
714 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
720 modest_hildon2_window_mgr_get_fullscreen_mode (ModestWindowMgr *self)
726 modest_hildon2_window_mgr_show_toolbars (ModestWindowMgr *self,
728 gboolean show_toolbars,
731 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
737 modest_hildon2_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show)
739 ModestHildon2WindowMgrPrivate *priv;
740 ModestWindow *result;
742 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
743 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
745 /* TODO: make this return NULL always */
747 result = MODEST_WINDOW_MGR_CLASS (parent_class)->get_main_window (self, FALSE);
748 /* create the main window, if it hasn't been created yet */
749 if (!result && show) {
750 /* modest_window_mgr_register_window will set priv->main_window */
751 result = modest_main_window_new ();
752 /* We have to remove all other windows */
753 if (!modest_window_mgr_close_all_windows (self)) {
754 gtk_widget_destroy (GTK_WIDGET (result));
757 if (!modest_window_mgr_register_window (self, result, NULL)) {
758 gtk_widget_destroy (GTK_WIDGET (result));
762 g_debug ("%s: created main window: %p\n", __FUNCTION__, result);
766 gtk_widget_show_all (GTK_WIDGET (result));
767 gtk_window_present (GTK_WINDOW (result));
775 modest_hildon2_window_mgr_get_modal (ModestWindowMgr *self)
777 ModestHildon2WindowMgrPrivate *priv;
778 GList *toplevel_list;
781 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
782 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
785 toplevel_list = gtk_window_list_toplevels ();
786 while (toplevel_list) {
787 if (gtk_window_is_active (toplevel_list->data)) {
788 toplevel = toplevel_list->data;
791 toplevel_list = g_list_next (toplevel_list);
799 modest_hildon2_window_mgr_set_modal (ModestWindowMgr *self,
803 g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self));
804 g_return_if_fail (GTK_IS_WINDOW (window));
806 gtk_window_set_modal (window, TRUE);
807 gtk_window_set_transient_for (window, parent);
808 gtk_window_set_destroy_with_parent (window, TRUE);
812 on_account_removed (TnyAccountStore *acc_store,
816 HildonWindowStack *stack;
817 ModestWindow *current_top;
818 gboolean has_accounts;
820 /* Ignore transport account removals */
821 if (TNY_IS_TRANSPORT_ACCOUNT (account))
824 stack = hildon_window_stack_get_default ();
825 current_top = (ModestWindow *) hildon_window_stack_peek (stack);
826 has_accounts = modest_account_mgr_has_accounts (modest_runtime_get_account_mgr (), TRUE);
828 /* if we're showing the header view of the currently deleted
829 account, or the outbox and we deleted the last account,
830 then close the window */
831 if (current_top && MODEST_IS_HEADER_WINDOW (current_top)) {
832 ModestHeaderView *header_view;
834 gboolean deleted = FALSE;
836 header_view = modest_header_window_get_header_view (MODEST_HEADER_WINDOW (current_top));
837 folder = modest_header_view_get_folder (header_view);
841 /* Close if it's my account */
842 if (!TNY_IS_MERGE_FOLDER (folder)) {
843 TnyAccount *my_account;
845 my_account = tny_folder_get_account (folder);
847 if (my_account == account) {
848 g_signal_emit_by_name (G_OBJECT (current_top),
853 g_object_unref (my_account);
857 /* Close if viewing outbox and no account left */
858 if (tny_folder_get_folder_type (folder) == TNY_FOLDER_TYPE_OUTBOX) {
860 g_signal_emit_by_name (G_OBJECT (current_top),
866 g_object_unref (folder);
869 current_top = (ModestWindow *) hildon_window_stack_peek (stack);
875 static ModestWindow *
876 modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self)
878 ModestWindow *initial_window = NULL;
879 ModestHildon2WindowMgrPrivate *priv;
881 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
883 /* Connect to the account store "account-removed" signal". We
884 do this here because in the init the singletons are still
885 not initialized properly */
886 if (!g_signal_handler_is_connected (modest_runtime_get_account_store (),
887 priv->accounts_handler)) {
888 priv->accounts_handler = g_signal_connect (modest_runtime_get_account_store (),
890 G_CALLBACK (on_account_removed),
894 /* Return accounts window */
895 initial_window = MODEST_WINDOW (modest_accounts_window_new ());
896 modest_window_mgr_register_window (self, initial_window, NULL);
898 return initial_window;
902 static ModestWindow *
903 modest_hildon2_window_mgr_get_current_top (ModestWindowMgr *self)
905 HildonWindowStack *stack;
906 stack = hildon_window_stack_get_default ();
907 return (ModestWindow *) hildon_window_stack_peek (stack);
911 find_folder_window (gconstpointer a,
914 return (MODEST_IS_FOLDER_WINDOW (a)) ? 0 : 1;
918 modest_hildon2_window_mgr_get_folder_window (ModestHildon2WindowMgr *self)
920 ModestHildon2WindowMgrPrivate *priv;
923 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), NULL);
925 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
927 window = g_list_find_custom (priv->window_list,
931 return (window != NULL) ? MODEST_WINDOW (window->data) : NULL;
935 modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self)
937 ModestHildon2WindowMgrPrivate *priv = NULL;
939 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE);
941 priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (self);
943 return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;
947 osso_display_event_cb (osso_display_state_t state,
950 ModestHildon2WindowMgrPrivate *priv = MODEST_HILDON2_WINDOW_MGR_GET_PRIVATE (data);
952 priv->display_state = state;
954 /* Stop blinking if the screen becomes on */
955 if (priv->display_state == OSSO_DISPLAY_ON)
956 modest_platform_remove_new_mail_notifications (TRUE);