X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-window-mgr.c;h=411fb215c6f64c03ed21d3ddaf6d9d8c60391215;hp=87848b741dc9a95c6123fcb4b6d98c5542c064af;hb=HEAD;hpb=88eb74aedd2db05f0b752a25fd6316ff952e393d diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index 87848b7..411fb21 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -34,7 +34,6 @@ #include "modest-ui-actions.h" #include "modest-platform.h" #include "modest-defs.h" -#include "widgets/modest-main-window.h" #include "widgets/modest-msg-edit-window.h" #include "widgets/modest-msg-view-window.h" #include "modest-debug.h" @@ -58,7 +57,6 @@ static void modest_window_mgr_show_toolbars_default (ModestWindowMgr *self, GType window_type, gboolean show_toolbars, gboolean fullscreen); -static ModestWindow* modest_window_mgr_get_main_window_default (ModestWindowMgr *self, gboolean show); static GtkWindow *modest_window_mgr_get_modal_default (ModestWindowMgr *self); static void modest_window_mgr_set_modal_default (ModestWindowMgr *self, GtkWindow *window, @@ -74,6 +72,7 @@ static GList *modest_window_mgr_get_window_list_default (ModestWindowMgr *self); static ModestWindow *modest_window_mgr_show_initial_window_default (ModestWindowMgr *self); static ModestWindow *modest_window_mgr_get_current_top_default (ModestWindowMgr *self); static gboolean modest_window_mgr_screen_is_on_default (ModestWindowMgr *self); +static ModestWindow *modest_window_mgr_get_folder_window_default (ModestWindowMgr *self); static void modest_window_mgr_create_caches_default (ModestWindowMgr *self); static void modest_window_mgr_on_queue_changed (ModestMailOperationQueue *queue, ModestMailOperation *mail_op, @@ -83,6 +82,7 @@ static void on_mail_operation_started (ModestMailOperation *mail_op, gpointer user_data); static void on_mail_operation_finished (ModestMailOperation *mail_op, gpointer user_data); +static gboolean modest_window_mgr_close_all_but_initial_default (ModestWindowMgr *self); /* list my signals */ enum { @@ -95,11 +95,9 @@ typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate; struct _ModestWindowMgrPrivate { guint banner_counter; - ModestWindow *main_window; - GSList *windows_that_prevent_hibernation; GSList *preregistered_uids; - + guint closing_time; GtkWidget *cached_view; @@ -161,7 +159,6 @@ modest_window_mgr_class_init (ModestWindowMgrClass *klass) mgr_class->set_fullscreen_mode = modest_window_mgr_set_fullscreen_mode_default; mgr_class->get_fullscreen_mode = modest_window_mgr_get_fullscreen_mode_default; mgr_class->show_toolbars = modest_window_mgr_show_toolbars_default; - mgr_class->get_main_window = modest_window_mgr_get_main_window_default; mgr_class->get_modal = modest_window_mgr_get_modal_default; mgr_class->set_modal = modest_window_mgr_set_modal_default; mgr_class->close_all_windows = modest_window_mgr_close_all_windows_default; @@ -172,6 +169,8 @@ modest_window_mgr_class_init (ModestWindowMgrClass *klass) mgr_class->get_current_top = modest_window_mgr_get_current_top_default; mgr_class->screen_is_on = modest_window_mgr_screen_is_on_default; mgr_class->create_caches = modest_window_mgr_create_caches_default; + mgr_class->close_all_but_initial = modest_window_mgr_close_all_but_initial_default; + mgr_class->get_folder_window = modest_window_mgr_get_folder_window_default; g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate)); @@ -252,8 +251,6 @@ modest_window_mgr_init (ModestWindowMgr *obj) priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj); priv->banner_counter = 0; - priv->main_window = NULL; - priv->preregistered_uids = NULL; priv->closing_time = 0; @@ -435,11 +432,12 @@ modest_window_mgr_register_help_id (ModestWindowMgr *self, GtkWindow *win, const /* we don't need 'self', but for API consistency... */ g_return_if_fail (self && MODEST_IS_WINDOW_MGR(self)); - g_return_if_fail (win && GTK_IS_WINDOW(win)); g_return_if_fail (help_id); - - g_object_set_data_full (G_OBJECT(win), MODEST_WINDOW_HELP_ID_PARAM, - g_strdup(help_id), g_free); + + if (GTK_IS_WINDOW (win)) { + g_object_set_data_full (G_OBJECT(win), MODEST_WINDOW_HELP_ID_PARAM, + g_strdup(help_id), g_free); + } } @@ -536,16 +534,26 @@ modest_window_mgr_register_window (ModestWindowMgr *self, ModestWindow *window, ModestWindow *parent) { - /* If this is the first registered window then reset the - status of the TnyDevice as it might be forced to be offline - when modest is running in the background (see - modest_tny_account_store_new()) */ - if (modest_window_mgr_get_num_windows (self) == 0) { + gboolean no_windows, retval; + + no_windows = (modest_window_mgr_get_num_windows (self) == 0); + + retval = MODEST_WINDOW_MGR_GET_CLASS (self)->register_window (self, window, parent); + + if (no_windows) { + /* If this is the first registered window then reset the + status of the TnyDevice as it might be forced to be offline + when modest is running in the background (see + modest_tny_account_store_new()) */ if (tny_device_is_forced (modest_runtime_get_device ())) tny_device_reset (modest_runtime_get_device ()); + + /* Do also allow modest to shutdown when the + application is closed */ + modest_runtime_set_allow_shutdown (TRUE); } - return MODEST_WINDOW_MGR_GET_CLASS (self)->register_window (self, window, parent); + return retval; } static gboolean @@ -556,7 +564,7 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, ModestWindowMgrPrivate *priv; g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); - g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE); + g_return_val_if_fail (MODEST_IS_WINDOW (window), FALSE); priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); @@ -568,16 +576,6 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, self); } - /* Check that it's not a second main window */ - if (MODEST_IS_MAIN_WINDOW (window)) { - if (priv->main_window) { - g_warning ("%s: trying to register a second main window", - __FUNCTION__); - return FALSE; - } else { - priv->main_window = window; - } - } /* remove from the list of pre-registered uids */ if (MODEST_IS_MSG_VIEW_WINDOW(window)) { @@ -585,7 +583,7 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, (MODEST_MSG_VIEW_WINDOW (window)); MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid ? uid : "");); - + if (has_uid (priv->preregistered_uids, uid)) { priv->preregistered_uids = remove_uid (priv->preregistered_uids, @@ -595,7 +593,7 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, } else if (MODEST_IS_MSG_EDIT_WINDOW(window)) { const gchar *uid = modest_msg_edit_window_get_message_uid (MODEST_MSG_EDIT_WINDOW (window)); - + MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid);); priv->preregistered_uids = @@ -659,7 +657,7 @@ modest_window_mgr_get_fullscreen_mode_default (ModestWindowMgr *self) return FALSE; } -void +void modest_window_mgr_show_toolbars (ModestWindowMgr *self, GType window_type, gboolean show_toolbars, @@ -668,7 +666,7 @@ modest_window_mgr_show_toolbars (ModestWindowMgr *self, return MODEST_WINDOW_MGR_GET_CLASS (self)->show_toolbars (self, window_type, show_toolbars, fullscreen); } -static void +static void modest_window_mgr_show_toolbars_default (ModestWindowMgr *self, GType window_type, gboolean show_toolbars, @@ -677,52 +675,6 @@ modest_window_mgr_show_toolbars_default (ModestWindowMgr *self, return; } -void -modest_window_mgr_set_main_window (ModestWindowMgr *self, ModestWindow *win) -{ - ModestWindowMgrPrivate *priv; - - g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); - - priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - priv->main_window = win; -} - -ModestWindow* -modest_window_mgr_get_main_window (ModestWindowMgr *self, gboolean show) -{ - return MODEST_WINDOW_MGR_GET_CLASS (self)->get_main_window (self, show); -} - -static ModestWindow* -modest_window_mgr_get_main_window_default (ModestWindowMgr *self, gboolean show) -{ - ModestWindowMgrPrivate *priv; - - g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), NULL); - - priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - if (priv->main_window) - return priv->main_window; - - if (show) - return modest_main_window_new (); - else return NULL; -} - - -gboolean -modest_window_mgr_main_window_exists (ModestWindowMgr *self) -{ - ModestWindowMgrPrivate *priv; - - g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); - priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - - return priv->main_window != NULL; -} - - GtkWindow * modest_window_mgr_get_modal (ModestWindowMgr *self) { @@ -850,10 +802,6 @@ modest_window_mgr_get_num_windows (ModestWindowMgr *self) g_list_free (window_list); } - /* Do not take into account the main window if it was hidden */ - if (num_windows && priv->main_window && !GTK_WIDGET_VISIBLE (priv->main_window)) - num_windows--; - return num_windows + priv->banner_counter; } @@ -952,9 +900,9 @@ modest_window_mgr_show_initial_window (ModestWindowMgr *self) static ModestWindow * modest_window_mgr_show_initial_window_default (ModestWindowMgr *self) { - /* By default it returns the main window creating it if - needed */ - return modest_window_mgr_get_main_window (self, TRUE); + g_warning ("You must implement %s", __FUNCTION__); + + return NULL; } @@ -1152,3 +1100,79 @@ modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self, return account_ops; } +/* 'Protected method' must be only called by children */ +gboolean +_modest_window_mgr_close_active_modals (ModestWindowMgr *self) +{ + GtkWidget *modal; + + /* Exit if there are no windows */ + if (!modest_window_mgr_get_num_windows (self)) { + g_warning ("%s: there are no windows to close", __FUNCTION__); + return FALSE; + } + + /* Check that there is no active modal dialog */ + modal = (GtkWidget *) modest_window_mgr_get_modal (self); + while (modal && GTK_IS_DIALOG (modal)) { + GtkWidget *parent; + +#if defined(MODEST_TOOLKIT_HILDON2) || defined(MODEST_TOOLKIT_HILDON) +#include + /* If it's a hildon note then don't try to close it as + this is the default behaviour of WM, delete event + is not issued for this kind of notes as we want the + user to always click on a button */ + if (HILDON_IS_NOTE (modal)) { + gtk_window_present (GTK_WINDOW (modal)); + return FALSE; + } +#endif + + /* Get the parent */ + parent = (GtkWidget *) gtk_window_get_transient_for (GTK_WINDOW (modal)); + + /* Try to close it */ + gtk_dialog_response (GTK_DIALOG (modal), GTK_RESPONSE_DELETE_EVENT); + + /* Maybe the dialog was not closed, because a close + confirmation dialog for example. Then ignore the + register process */ + if (GTK_IS_WINDOW (modal)) { + gtk_window_present (GTK_WINDOW (modal)); + return FALSE; + } + + /* Get next modal */ + modal = parent; + } + return TRUE; +} + +gboolean +modest_window_mgr_close_all_but_initial (ModestWindowMgr *self) +{ + return MODEST_WINDOW_MGR_GET_CLASS (self)->close_all_but_initial (self); +} + +static gboolean +modest_window_mgr_close_all_but_initial_default (ModestWindowMgr *self) +{ + /* Empty default implementation */ + return FALSE; +} + +ModestWindow * +modest_window_mgr_get_folder_window (ModestWindowMgr *self) +{ + return MODEST_WINDOW_MGR_GET_CLASS (self)->get_folder_window (self); +} + +static ModestWindow * +modest_window_mgr_get_folder_window_default (ModestWindowMgr *self) +{ + /* Default implementation returns NULL always */ + + return NULL; +} +