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 "modest-hildon1-window-mgr.h"
32 #include "modest-msg-edit-window.h"
33 #include "modest-main-window.h"
34 #include "modest-conf.h"
35 #include "modest-defs.h"
36 #include "modest-signal-mgr.h"
37 #include "modest-runtime.h"
38 #include "modest-platform.h"
39 #include "modest-ui-actions.h"
40 #include "modest-debug.h"
41 #include "modest-tny-folder.h"
43 /* 'private'/'protected' functions */
44 static void modest_hildon1_window_mgr_class_init (ModestHildon1WindowMgrClass *klass);
45 static void modest_hildon1_window_mgr_instance_init (ModestHildon1WindowMgr *obj);
46 static void modest_hildon1_window_mgr_finalize (GObject *obj);
48 static gboolean on_window_destroy (ModestWindow *window,
50 ModestHildon1WindowMgr *self);
52 static gboolean on_modal_window_close (GtkWidget *widget,
56 static void on_modal_dialog_destroy (GtkObject *object,
59 static void on_modal_dialog_close (GtkDialog *dialog,
63 static const gchar* get_show_toolbar_key (GType window_type,
66 static gboolean modest_hildon1_window_mgr_register_window (ModestWindowMgr *self,
68 ModestWindow *parent);
69 static void modest_hildon1_window_mgr_unregister_window (ModestWindowMgr *self,
70 ModestWindow *window);
71 static void modest_hildon1_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
73 static gboolean modest_hildon1_window_mgr_get_fullscreen_mode (ModestWindowMgr *self);
74 static void modest_hildon1_window_mgr_show_toolbars (ModestWindowMgr *self,
76 gboolean show_toolbars,
78 static ModestWindow* modest_hildon1_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show);
79 static GtkWindow *modest_hildon1_window_mgr_get_modal (ModestWindowMgr *self);
80 static void modest_hildon1_window_mgr_set_modal (ModestWindowMgr *self,
83 static gboolean modest_hildon1_window_mgr_find_registered_header (ModestWindowMgr *self,
86 static GList *modest_hildon1_window_mgr_get_window_list (ModestWindowMgr *self);
88 typedef struct _ModestHildon1WindowMgrPrivate ModestHildon1WindowMgrPrivate;
89 struct _ModestHildon1WindowMgrPrivate {
92 GQueue *modal_windows;
94 gboolean fullscreen_mode;
96 GHashTable *destroy_handlers;
97 GHashTable *viewer_handlers;
98 GSList *window_state_uids;
102 GSList *modal_handler_uids;
103 ModestWindow *current_top;
105 #define MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
106 MODEST_TYPE_HILDON1_WINDOW_MGR, \
107 ModestHildon1WindowMgrPrivate))
109 static GObjectClass *parent_class = NULL;
112 modest_hildon1_window_mgr_get_type (void)
114 static GType my_type = 0;
116 static const GTypeInfo my_info = {
117 sizeof(ModestHildon1WindowMgrClass),
118 NULL, /* base init */
119 NULL, /* base finalize */
120 (GClassInitFunc) modest_hildon1_window_mgr_class_init,
121 NULL, /* class finalize */
122 NULL, /* class data */
123 sizeof(ModestHildon1WindowMgr),
125 (GInstanceInitFunc) modest_hildon1_window_mgr_instance_init,
128 my_type = g_type_register_static (MODEST_TYPE_WINDOW_MGR,
129 "ModestHildon1WindowMgr",
136 modest_hildon1_window_mgr_class_init (ModestHildon1WindowMgrClass *klass)
138 GObjectClass *gobject_class;
139 ModestWindowMgrClass *mgr_class;
141 gobject_class = (GObjectClass*) klass;
142 mgr_class = (ModestWindowMgrClass *) klass;
144 parent_class = g_type_class_peek_parent (klass);
145 gobject_class->finalize = modest_hildon1_window_mgr_finalize;
146 mgr_class->register_window = modest_hildon1_window_mgr_register_window;
147 mgr_class->unregister_window = modest_hildon1_window_mgr_unregister_window;
148 mgr_class->set_fullscreen_mode = modest_hildon1_window_mgr_set_fullscreen_mode;
149 mgr_class->get_fullscreen_mode = modest_hildon1_window_mgr_get_fullscreen_mode;
150 mgr_class->show_toolbars = modest_hildon1_window_mgr_show_toolbars;
151 mgr_class->get_main_window = modest_hildon1_window_mgr_get_main_window;
152 mgr_class->get_modal = modest_hildon1_window_mgr_get_modal;
153 mgr_class->set_modal = modest_hildon1_window_mgr_set_modal;
154 mgr_class->find_registered_header = modest_hildon1_window_mgr_find_registered_header;
155 mgr_class->get_window_list = modest_hildon1_window_mgr_get_window_list;
157 g_type_class_add_private (gobject_class, sizeof(ModestHildon1WindowMgrPrivate));
162 modest_hildon1_window_mgr_instance_init (ModestHildon1WindowMgr *obj)
164 ModestHildon1WindowMgrPrivate *priv;
166 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE(obj);
167 priv->window_list = NULL;
168 priv->fullscreen_mode = FALSE;
169 priv->current_top = NULL;
170 priv->window_state_uids = NULL;
172 priv->modal_windows = g_queue_new ();
173 priv->queue_lock = g_mutex_new ();
175 /* Could not initialize it from gconf, singletons are not
177 priv->destroy_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
178 priv->viewer_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
180 priv->closing_time = 0;
182 priv->modal_handler_uids = NULL;
186 modest_hildon1_window_mgr_finalize (GObject *obj)
188 ModestHildon1WindowMgrPrivate *priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE(obj);
190 modest_signal_mgr_disconnect_all_and_destroy (priv->window_state_uids);
191 priv->window_state_uids = NULL;
193 if (priv->window_list) {
194 GList *iter = priv->window_list;
195 /* unregister pending windows */
197 ModestWindow *window = (ModestWindow *) iter->data;
198 iter = g_list_next (iter);
199 modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (obj), window);
201 g_list_free (priv->window_list);
202 priv->window_list = NULL;
205 /* Free the hash table with the handlers */
206 if (priv->destroy_handlers) {
207 g_hash_table_destroy (priv->destroy_handlers);
208 priv->destroy_handlers = NULL;
211 if (priv->viewer_handlers) {
212 g_hash_table_destroy (priv->viewer_handlers);
213 priv->viewer_handlers = NULL;
216 modest_signal_mgr_disconnect_all_and_destroy (priv->modal_handler_uids);
217 priv->modal_handler_uids = NULL;
219 if (priv->modal_windows) {
220 g_mutex_lock (priv->queue_lock);
221 g_queue_free (priv->modal_windows);
222 priv->modal_windows = NULL;
223 g_mutex_unlock (priv->queue_lock);
225 g_mutex_free (priv->queue_lock);
227 /* Do not unref priv->main_window because it does not hold a
231 G_OBJECT_CLASS(parent_class)->finalize (obj);
235 modest_hildon1_window_mgr_new (void)
237 return MODEST_WINDOW_MGR(g_object_new(MODEST_TYPE_HILDON1_WINDOW_MGR, NULL));
241 modest_hildon1_window_mgr_close_all_windows (ModestWindowMgr *self)
243 ModestHildon1WindowMgrPrivate *priv = NULL;
244 gboolean ret_value = FALSE;
245 ModestWindow *main_window;
247 g_return_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self));
248 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
250 /* If there is a main window then try to close it, and it will
251 close the others if needed */
252 main_window = modest_window_mgr_get_main_window (self, FALSE);
254 g_signal_emit_by_name (main_window, "delete-event", NULL, &ret_value);
256 GList *wins = NULL, *next = NULL;
258 /* delete-event handler actually removes window_list item, */
259 wins = priv->window_list;
261 next = g_list_next (wins);
262 g_signal_emit_by_name (G_OBJECT (wins->data), "delete-event", NULL, &ret_value);
269 compare_msguids (ModestWindow *win,
272 const gchar *msg_uid;
274 if ((!MODEST_IS_MSG_EDIT_WINDOW (win)) && (!MODEST_IS_MSG_VIEW_WINDOW (win)))
277 /* Get message uid from msg window */
278 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
279 msg_uid = modest_msg_edit_window_get_message_uid (MODEST_MSG_EDIT_WINDOW (win));
280 if (msg_uid && uid &&!strcmp (msg_uid, uid))
283 msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
286 if (msg_uid && uid &&!strcmp (msg_uid, uid))
293 modest_hildon1_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *header,
296 ModestHildon1WindowMgrPrivate *priv = NULL;
298 gboolean has_header, has_window = FALSE;
301 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self), FALSE);
302 g_return_val_if_fail (TNY_IS_HEADER(header), FALSE);
304 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
306 has_header = MODEST_WINDOW_MGR_CLASS (parent_class)->find_registered_header (self, header, win);
308 uid = modest_tny_folder_get_header_unique_id (header);
310 item = g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids);
314 if ((!MODEST_IS_MSG_VIEW_WINDOW(item->data)) &&
315 (!MODEST_IS_MSG_EDIT_WINDOW (item->data)))
316 g_debug ("not a valid window!");
318 g_debug ("found a window");
319 *win = MODEST_WINDOW (item->data);
325 return has_header || has_window;
329 modest_hildon1_window_mgr_get_window_list (ModestWindowMgr *self)
331 ModestHildon1WindowMgrPrivate *priv;
333 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self), NULL);
334 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
336 return g_list_copy (priv->window_list);
340 get_show_toolbar_key (GType window_type,
343 const gchar *key = NULL;
345 if (window_type == MODEST_TYPE_MAIN_WINDOW)
347 MODEST_CONF_MAIN_WINDOW_SHOW_TOOLBAR_FULLSCREEN :
348 MODEST_CONF_MAIN_WINDOW_SHOW_TOOLBAR;
349 else if (window_type == MODEST_TYPE_MSG_VIEW_WINDOW)
351 MODEST_CONF_MSG_VIEW_WINDOW_SHOW_TOOLBAR_FULLSCREEN :
352 MODEST_CONF_MSG_VIEW_WINDOW_SHOW_TOOLBAR;
353 else if (window_type == MODEST_TYPE_MSG_EDIT_WINDOW)
355 MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR_FULLSCREEN :
356 MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR;
358 g_return_val_if_reached (NULL);
363 #ifndef MODEST_TOOLKIT_GTK
365 on_window_is_topmost (GObject *gobject,
369 ModestHildon1WindowMgr *self;
370 ModestHildon1WindowMgrPrivate *priv;
371 ModestWindow *win = (ModestWindow *) gobject;
373 g_return_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (user_data));
375 self = MODEST_HILDON1_WINDOW_MGR (user_data);
376 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
378 if (hildon_window_get_is_topmost (HILDON_WINDOW (win)))
379 priv->current_top = win;
384 on_window_state_event (GtkWidget *widget,
385 GdkEventWindowState *event,
388 ModestHildon1WindowMgr *self;
389 ModestHildon1WindowMgrPrivate *priv;
391 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (user_data), FALSE);
393 self = MODEST_HILDON1_WINDOW_MGR (user_data);
394 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
397 if (event->changed_mask & GDK_WINDOW_STATE_WITHDRAWN)
398 g_print ("GDK_WINDOW_STATE_WITHDRAWN\n");
399 if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED)
400 g_print ("GDK_WINDOW_STATE_ICONIFIED\n");
401 if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
402 g_print ("GDK_WINDOW_STATE_MAXIMIZED\n");
403 if (event->changed_mask & GDK_WINDOW_STATE_STICKY)
404 g_print ("GDK_WINDOW_STATE_STICKY\n");
405 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
406 g_print ("GDK_WINDOW_STATE_FULLSCREEN\n");
407 if (event->changed_mask & GDK_WINDOW_STATE_ABOVE)
408 g_print ("GDK_WINDOW_STATE_ABOVE\n");
409 if (event->changed_mask & GDK_WINDOW_STATE_BELOW)
410 g_print ("GDK_WINDOW_STATE_BELOW\n");
412 if (event->changed_mask & GDK_WINDOW_STATE_WITHDRAWN ||
413 event->changed_mask & GDK_WINDOW_STATE_ABOVE) {
414 priv->current_top = MODEST_WINDOW (widget);
422 modest_hildon1_window_mgr_register_window (ModestWindowMgr *self,
423 ModestWindow *window,
424 ModestWindow *parent)
427 ModestHildon1WindowMgrPrivate *priv;
430 ModestWindow *main_window;
432 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self), FALSE);
433 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
435 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
437 win = g_list_find (priv->window_list, window);
439 /* this is for the case we want to register the window and it was already
440 * registered. We leave silently.
445 if (!MODEST_WINDOW_MGR_CLASS (parent_class)->register_window (self, window, parent))
448 /* Add to list. Keep a reference to the window */
449 g_object_ref (window);
450 priv->window_list = g_list_prepend (priv->window_list, window);
452 /* Listen to window state changes. Unfortunately
453 window-state-event does not properly work for the Maemo
454 version, so we need to use is-topmost and the ifdef */
455 #ifndef MODEST_TOOLKIT_GTK
456 priv->window_state_uids =
457 modest_signal_mgr_connect (priv->window_state_uids,
459 "notify::is-topmost",
460 G_CALLBACK (on_window_is_topmost),
463 priv->window_state_uids =
464 modest_signal_mgr_connect (priv->window_state_uids,
466 "window-state-event",
467 G_CALLBACK (on_window_state_event),
470 /* Listen to object destruction */
471 handler_id = g_malloc0 (sizeof (gint));
472 *handler_id = g_signal_connect (window, "delete-event", G_CALLBACK (on_window_destroy), self);
473 g_hash_table_insert (priv->destroy_handlers, window, handler_id);
475 main_window = modest_window_mgr_get_main_window (self, FALSE);
476 /* If there is a msg view window, let the main window listen the msg-changed signal */
477 if (MODEST_IS_MSG_VIEW_WINDOW(window) && main_window) {
479 handler = g_malloc0 (sizeof (gulong));
480 *handler = g_signal_connect (window, "msg-changed",
481 G_CALLBACK (modest_main_window_on_msg_view_window_msg_changed),
483 g_hash_table_insert (priv->viewer_handlers, window, handler);
486 /* Put into fullscreen if needed */
487 if (priv->fullscreen_mode)
488 gtk_window_fullscreen (GTK_WINDOW (window));
490 /* Show/hide toolbar & fullscreen */
491 key = get_show_toolbar_key (G_TYPE_FROM_INSTANCE (window), priv->fullscreen_mode);
492 modest_window_show_toolbar (window, modest_conf_get_bool (modest_runtime_get_conf (), key, NULL));
498 cancel_window_operations (ModestWindow *window)
500 GSList* pending_ops = NULL;
502 /* cancel open and receive operations */
503 pending_ops = modest_mail_operation_queue_get_by_source (modest_runtime_get_mail_operation_queue (),
505 while (pending_ops != NULL) {
506 ModestMailOperationTypeOperation type;
507 GSList* tmp_list = NULL;
509 type = modest_mail_operation_get_type_operation (MODEST_MAIL_OPERATION (pending_ops->data));
510 if (type == MODEST_MAIL_OPERATION_TYPE_RECEIVE || type == MODEST_MAIL_OPERATION_TYPE_OPEN) {
511 modest_mail_operation_cancel (pending_ops->data);
513 g_object_unref (G_OBJECT (pending_ops->data));
514 tmp_list = pending_ops;
515 pending_ops = g_slist_next (pending_ops);
516 g_slist_free_1 (tmp_list);
523 on_window_destroy (ModestWindow *window,
525 ModestHildon1WindowMgr *self)
527 gint dialog_response = GTK_RESPONSE_NONE;
528 gboolean no_propagate = FALSE;
530 /* Specific stuff first */
531 if (MODEST_IS_MAIN_WINDOW (window)) {
532 ModestHildon1WindowMgrPrivate *priv;
533 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
535 /* If more than one window already opened */
536 if (g_list_length (priv->window_list) > 1) {
538 /* Present the window if it's not visible now */
539 if (!gtk_window_has_toplevel_focus (GTK_WINDOW (window))) {
540 gtk_window_present (GTK_WINDOW (window));
541 priv->current_top = window;
543 /* Create the confirmation dialog MSG-NOT308 */
544 dialog_response = modest_platform_run_confirmation_dialog (
545 GTK_WINDOW (window), _("emev_nc_close_windows"));
547 /* If the user wants to close all the windows */
548 if ((dialog_response == GTK_RESPONSE_OK)
549 || (dialog_response == GTK_RESPONSE_ACCEPT)
550 || (dialog_response == GTK_RESPONSE_YES)) {
551 GList *iter = priv->window_list;
553 if (iter->data != window) {
554 GList *tmp = iter->next;
555 on_window_destroy (MODEST_WINDOW (iter->data),
560 iter = g_list_next (iter);
568 /* Do not unregister it, just hide */
569 gtk_widget_hide_all (GTK_WIDGET (window));
571 /* Cancel pending operations */
572 cancel_window_operations (window);
574 /* Fake the window system, make it think that there is no window */
575 if (modest_window_mgr_num_windows (MODEST_WINDOW_MGR (self)) == 0)
576 g_signal_emit_by_name (self, "window-list-empty");
581 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
582 gboolean sent = FALSE;
583 gint response = GTK_RESPONSE_ACCEPT;
584 sent = modest_msg_edit_window_get_sent (MODEST_MSG_EDIT_WINDOW (window));
585 /* Save currently edited message to Drafts if it was not sent */
586 if (!sent && modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (window))) {
588 /* Raise the window if it's minimized */
589 if (!gtk_window_has_toplevel_focus (GTK_WINDOW (window)))
590 gtk_window_present (GTK_WINDOW (window));
593 modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
594 _("mcen_nc_no_email_message_modified_save_changes"));
596 if (response == GTK_RESPONSE_OK)
597 if (!modest_ui_actions_on_save_to_drafts (NULL, MODEST_MSG_EDIT_WINDOW (window)))
601 /* Unregister window */
602 modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (self), window);
610 disconnect_msg_changed (gpointer key,
615 handler_id = GPOINTER_TO_UINT(value);
617 if (key && G_IS_OBJECT(key))
618 g_signal_handler_disconnect (G_OBJECT (key), handler_id);
622 modest_hildon1_window_mgr_unregister_window (ModestWindowMgr *self,
623 ModestWindow *window)
626 ModestHildon1WindowMgrPrivate *priv;
627 gulong *tmp, handler_id;
629 g_return_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self));
630 g_return_if_fail (MODEST_IS_WINDOW (window));
632 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
634 win = g_list_find (priv->window_list, window);
636 g_warning ("Trying to unregister a window that has not being registered yet");
640 /* If it's the main window unset it */
641 if (MODEST_IS_MAIN_WINDOW (window)) {
642 modest_window_mgr_set_main_window (self, NULL);
644 /* Disconnect all emissions of msg-changed */
645 if (priv->viewer_handlers) {
646 g_hash_table_foreach (priv->viewer_handlers,
647 disconnect_msg_changed,
649 g_hash_table_destroy (priv->viewer_handlers);
650 priv->viewer_handlers = NULL;
654 /* Remove the viewer window handler from the hash table. The
655 HashTable could not exist if the main window was closed
656 when there were other windows remaining */
657 if (MODEST_IS_MSG_VIEW_WINDOW (window) && priv->viewer_handlers) {
658 tmp = (gulong *) g_hash_table_lookup (priv->viewer_handlers, window);
659 /* If the viewer was created without a main window
660 (for example when opening a message through D-Bus
661 the viewer handlers was not registered */
663 g_signal_handler_disconnect (window, *tmp);
664 g_hash_table_remove (priv->viewer_handlers, window);
668 /* Remove from list & hash table */
669 priv->window_list = g_list_remove_link (priv->window_list, win);
670 tmp = g_hash_table_lookup (priv->destroy_handlers, window);
673 g_hash_table_remove (priv->destroy_handlers, window);
675 /* cancel open and receive operations */
676 cancel_window_operations (window);
678 /* Check if it's the topmost window, and remove the window from the stack.
679 * This is needed for the cases there's no other topmost window that will
680 * replace it in topmost handler.
682 if (window == priv->current_top)
683 priv->current_top = NULL;
685 /* Disconnect the "window-state-event" handler, we won't need it anymore */
686 if (priv->window_state_uids) {
687 #ifndef MODEST_TOOLKIT_GTK
688 priv->window_state_uids =
689 modest_signal_mgr_disconnect (priv->window_state_uids,
691 "notify::is-topmost");
693 priv->window_state_uids =
694 modest_signal_mgr_disconnect (priv->window_state_uids,
696 "window-state-event");
700 /* Disconnect the "delete-event" handler, we won't need it anymore */
701 g_signal_handler_disconnect (window, handler_id);
703 /* Destroy the window */
704 g_object_unref (win->data);
707 MODEST_WINDOW_MGR_CLASS (parent_class)->unregister_window (self, window);
709 /* If there are no more windows registered emit the signal */
710 if (modest_window_mgr_num_windows (self) == 0)
711 g_signal_emit_by_name (self, "window-list-empty");
717 modest_hildon1_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
720 ModestHildon1WindowMgrPrivate *priv;
724 g_return_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self));
726 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
728 /* If there is no change do nothing */
729 if (priv->fullscreen_mode == on)
732 priv->fullscreen_mode = on;
734 conf = modest_runtime_get_conf ();
737 win = priv->window_list;
740 const gchar *key = NULL;
742 /* Getting this from gconf everytime is not that
743 expensive, we'll do it just a few times */
744 key = get_show_toolbar_key (G_TYPE_FROM_INSTANCE (win->data), on);
745 show = modest_conf_get_bool (conf, key, NULL);
747 /* Set fullscreen/unfullscreen */
749 gtk_window_fullscreen (GTK_WINDOW (win->data));
751 gtk_window_unfullscreen (GTK_WINDOW (win->data));
753 /* Show/Hide toolbar */
754 modest_window_show_toolbar (MODEST_WINDOW (win->data), show);
756 win = g_list_next (win);
761 modest_hildon1_window_mgr_get_fullscreen_mode (ModestWindowMgr *self)
763 ModestHildon1WindowMgrPrivate *priv;
765 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self), FALSE);
767 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
769 return priv->fullscreen_mode;
773 modest_hildon1_window_mgr_show_toolbars (ModestWindowMgr *self,
775 gboolean show_toolbars,
778 ModestHildon1WindowMgrPrivate *priv;
780 const gchar *key = NULL;
782 g_return_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self));
784 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
785 conf = modest_runtime_get_conf ();
787 /* If nothing changes then return */
788 key = get_show_toolbar_key (window_type, fullscreen);
789 conf = modest_runtime_get_conf ();
790 if (modest_conf_get_bool (conf, key, NULL) == show_toolbars)
794 modest_conf_set_bool (conf, key, show_toolbars, NULL);
796 /* Apply now if the view mode is the right one */
797 if ((fullscreen && priv->fullscreen_mode) ||
798 (!fullscreen && !priv->fullscreen_mode)) {
800 GList *win = priv->window_list;
803 if (G_TYPE_FROM_INSTANCE (win->data) == window_type)
804 modest_window_show_toolbar (MODEST_WINDOW (win->data),
806 win = g_list_next (win);
812 modest_hildon1_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show)
814 ModestHildon1WindowMgrPrivate *priv;
815 ModestWindow *result;
817 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self), NULL);
818 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
820 result = MODEST_WINDOW_MGR_CLASS (parent_class)->get_main_window (self, FALSE);
821 /* create the main window, if it hasn't been created yet */
822 if (!result && show) {
823 /* modest_window_mgr_register_window will set priv->main_window */
824 result = modest_main_window_new ();
825 modest_window_mgr_register_window (self, result, NULL);
826 gtk_widget_show_all (GTK_WIDGET (result));
827 gtk_window_present (GTK_WINDOW (result));
829 g_debug ("%s: created main window: %p\n", __FUNCTION__, result);
838 modest_hildon1_window_mgr_get_modal (ModestWindowMgr *self)
840 ModestHildon1WindowMgrPrivate *priv;
842 g_return_val_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self), NULL);
843 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
845 return g_queue_peek_head (priv->modal_windows);
850 modest_hildon1_window_mgr_set_modal (ModestWindowMgr *self,
854 GtkWindow *old_modal;
855 ModestHildon1WindowMgrPrivate *priv;
857 g_return_if_fail (MODEST_IS_HILDON1_WINDOW_MGR (self));
858 g_return_if_fail (GTK_IS_WINDOW (window));
860 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
861 g_mutex_lock (priv->queue_lock);
862 old_modal = g_queue_peek_head (priv->modal_windows);
863 g_mutex_unlock (priv->queue_lock);
866 /* make us transient wrt the main window then */
867 if (priv->current_top && ((GtkWindow *) priv->current_top != window)) {
868 gtk_window_set_transient_for (window, GTK_WINDOW(priv->current_top));
870 ModestWindow *main_win = modest_window_mgr_get_main_window (self, FALSE);
871 if (GTK_WINDOW(main_win) != window) /* they should not be the same */
872 gtk_window_set_transient_for (window, GTK_WINDOW(main_win));
874 gtk_window_set_modal (window, TRUE);
876 /* un-modalize the old one; the one on top should be the
878 gtk_window_set_transient_for (window, GTK_WINDOW(old_modal));
879 gtk_window_set_modal (window, TRUE);
882 /* this will be the new modal window */
883 g_mutex_lock (priv->queue_lock);
884 g_queue_push_head (priv->modal_windows, window);
885 g_mutex_unlock (priv->queue_lock);
887 if (GTK_IS_DIALOG (window)) {
888 /* Note that response is not always enough because it
889 could be captured and removed easily by dialogs but
890 works for most of situations */
891 priv->modal_handler_uids =
892 modest_signal_mgr_connect (priv->modal_handler_uids,
895 G_CALLBACK (on_modal_dialog_close),
897 /* We need this as well because dialogs are often
898 destroyed with gtk_widget_destroy and this one will
899 prevent response from happening */
900 priv->modal_handler_uids =
901 modest_signal_mgr_connect (priv->modal_handler_uids,
904 G_CALLBACK (on_modal_dialog_destroy),
907 priv->modal_handler_uids =
908 modest_signal_mgr_connect (priv->modal_handler_uids,
911 G_CALLBACK (on_modal_window_close),
914 /* Destroy width parent */
915 gtk_window_set_destroy_with_parent (window, TRUE);
921 idle_top_modal (gpointer data)
923 ModestWindowMgr *self = MODEST_WINDOW_MGR (data);
924 ModestHildon1WindowMgrPrivate *priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
927 /* Get the top modal */
928 g_mutex_lock (priv->queue_lock);
929 topmost = (GtkWindow *) g_queue_peek_head (priv->modal_windows);
930 g_mutex_unlock (priv->queue_lock);
934 gdk_threads_enter ();
935 gtk_window_present (topmost);
936 /* It seems that the window looses modality if some
937 other is shown on top of it after set_transient_for
939 gtk_window_set_modal (topmost, TRUE);
940 gdk_threads_leave ();
947 remove_modal_from_queue (GtkWidget *widget,
948 ModestWindowMgr *self)
950 ModestHildon1WindowMgrPrivate *priv;
953 priv = MODEST_HILDON1_WINDOW_MGR_GET_PRIVATE (self);
955 /* Remove from queue. We don't use remove, because we want to
956 exit if the widget does not belong to the queue */
957 g_mutex_lock (priv->queue_lock);
958 item = g_queue_find (priv->modal_windows, widget);
960 g_warning ("Trying to remove a modal window that is not registered");
961 g_mutex_unlock (priv->queue_lock);
964 g_queue_unlink (priv->modal_windows, item);
965 g_mutex_unlock (priv->queue_lock);
967 /* Disconnect handler */
968 priv->modal_handler_uids =
969 modest_signal_mgr_disconnect (priv->modal_handler_uids,
971 GTK_IS_DIALOG (widget) ?
974 if (GTK_IS_DIALOG (widget))
975 priv->modal_handler_uids =
976 modest_signal_mgr_disconnect (priv->modal_handler_uids,
980 /* Schedule the next one for being shown */
981 g_idle_add (idle_top_modal, self);
985 on_modal_window_close (GtkWidget *widget,
989 ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
991 /* Remove modal window from queue */
992 remove_modal_from_queue (widget, self);
999 on_modal_dialog_close (GtkDialog *dialog,
1003 ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
1005 /* Remove modal window from queue. Note that if "destroy"
1006 signal was invoked before the response the window could be
1008 remove_modal_from_queue (GTK_WIDGET (dialog), self);
1012 on_modal_dialog_destroy (GtkObject *object,
1015 ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
1017 /* Remove modal window from queue */
1018 remove_modal_from_queue (GTK_WIDGET (object), self);