+
+
+void
+modest_window_mgr_set_modal (ModestWindowMgr *self,
+ GtkWindow *window,
+ GtkWindow *parent)
+{
+ MODEST_WINDOW_MGR_GET_CLASS (self)->set_modal (self, window, parent);
+}
+
+static void
+modest_window_mgr_set_modal_default (ModestWindowMgr *self,
+ GtkWindow *window,
+ GtkWindow *parent)
+{
+ return;
+}
+
+
+static void
+on_nonhibernating_window_hide(GtkWidget *widget, gpointer user_data)
+{
+ ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
+ ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* Forget this window,
+ * so hibernation will be allowed again if no windows are remembered: */
+ priv->windows_that_prevent_hibernation =
+ g_slist_remove (priv->windows_that_prevent_hibernation, GTK_WINDOW(widget));
+}
+
+static void
+on_nonhibernating_window_show(GtkWidget *widget, gpointer user_data)
+{
+ ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
+ ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ GtkWindow *window = GTK_WINDOW (widget);
+
+ priv->windows_that_prevent_hibernation =
+ g_slist_append (priv->windows_that_prevent_hibernation, window);
+
+ /* Allow hibernation again when the window has been hidden: */
+ g_signal_connect (window, "hide",
+ G_CALLBACK (on_nonhibernating_window_hide), self);
+}
+
+void
+modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self,
+ GtkWindow *window)
+{
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+
+ if (GTK_WIDGET_VISIBLE(window)) {
+ on_nonhibernating_window_show (GTK_WIDGET (window), self);
+ } else {
+ /* Wait for it to be shown: */
+ g_signal_connect (window, "show",
+ G_CALLBACK (on_nonhibernating_window_show), self);
+ }
+}
+
+gboolean
+modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self)
+{
+ g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE);
+
+ ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* Prevent hibernation if any open windows are currently
+ * preventing hibernation: */
+ return (g_slist_length (priv->windows_that_prevent_hibernation) > 0);
+}
+
+
+void
+modest_window_mgr_save_state_for_all_windows (ModestWindowMgr *self)
+{
+ GList *window_list;
+ GList *node;
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+
+ /* Iterate over all windows */
+ window_list = modest_window_mgr_get_window_list (self);
+ node = window_list;
+ while (node) {
+ ModestWindow *window = MODEST_WINDOW (node->data);
+ if (window) {
+ /* This calls the vfunc,
+ * so each window can do its own thing: */
+ modest_window_save_state (window);
+ }
+
+ node = g_list_next (node);
+ }
+ g_list_free (window_list);
+}
+
+guint
+modest_window_mgr_get_num_windows (ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv;
+ gint num_windows = 0;
+ GList *window_list;
+
+ g_return_val_if_fail (self && MODEST_IS_WINDOW_MGR(self), -1);
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
+
+ window_list = modest_window_mgr_get_window_list (self);
+
+ if (window_list) {
+ num_windows = g_list_length (window_list);
+ 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;
+}
+
+GtkWidget *
+modest_window_mgr_get_msg_edit_window (ModestWindowMgr *self)
+{
+ GtkWidget *result;
+ ModestWindowMgrPrivate *priv;
+
+ g_return_val_if_fail (self && MODEST_IS_WINDOW_MGR(self), NULL);
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
+
+ if (priv->cached_editor) {
+ result = priv->cached_editor;
+ priv->cached_editor = NULL;
+ load_new_editor (self);
+ } else {
+ result = g_object_new (MODEST_TYPE_MSG_EDIT_WINDOW, NULL);
+ }
+
+ return result;
+}
+
+GtkWidget *
+modest_window_mgr_get_msg_view_window (ModestWindowMgr *self)
+{
+ GtkWidget *result;
+ ModestWindowMgrPrivate *priv;
+
+ g_return_val_if_fail (self && MODEST_IS_WINDOW_MGR(self), NULL);
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
+
+ if (priv->cached_view) {
+ result = priv->cached_view;
+ priv->cached_view = NULL;
+ load_new_view (self);
+ } else {
+ result = g_object_new (MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
+ }
+
+ return result;
+}
+
+void
+modest_window_mgr_register_banner (ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ priv->banner_counter++;
+}
+
+void
+modest_window_mgr_unregister_banner (ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ priv->banner_counter--;
+ if (modest_window_mgr_get_num_windows (self) == 0)
+ g_signal_emit (self, signals[WINDOW_LIST_EMPTY_SIGNAL], 0);
+}
+
+ModestWindow *
+modest_window_mgr_show_initial_window (ModestWindowMgr *self)
+{
+ ModestWindow *window = NULL;
+
+ /* Call the children */
+ window = MODEST_WINDOW_MGR_GET_CLASS (self)->show_initial_window (self);
+
+ if (window) {
+ ModestAccountMgr *mgr;
+
+ /* Show the initial window */
+ gtk_widget_show (GTK_WIDGET (window));
+
+ /* If there are no accounts then show the account wizard */
+ mgr = modest_runtime_get_account_mgr();
+ if (!modest_account_mgr_has_accounts (mgr, TRUE))
+ modest_ui_actions_run_account_setup_wizard (window);
+ }
+
+ return window;
+}
+
+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);
+}