+
+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)) {
+ if (!modest_ui_actions_run_account_setup_wizard (window)) {
+ g_debug ("%s: couldn't show account setup wizard", __FUNCTION__);
+ }
+ }
+ }
+
+ return window;
+}
+
+static ModestWindow *
+modest_window_mgr_show_initial_window_default (ModestWindowMgr *self)
+{
+#ifndef MODEST_TOOLKIT_HILDON2
+ /* By default it returns the main window creating it if
+ needed */
+ return modest_window_mgr_get_main_window (self, TRUE);
+#else
+ return NULL;
+#endif
+}
+
+
+ModestWindow *
+modest_window_mgr_get_current_top (ModestWindowMgr *self)
+{
+ return MODEST_WINDOW_MGR_GET_CLASS (self)->get_current_top (self);
+}
+
+
+static ModestWindow *
+modest_window_mgr_get_current_top_default (ModestWindowMgr *self)
+{
+ g_return_val_if_reached (NULL);
+}
+
+gboolean
+modest_window_mgr_screen_is_on (ModestWindowMgr *self)
+{
+ return MODEST_WINDOW_MGR_GET_CLASS (self)->screen_is_on (self);
+}
+
+static gboolean
+modest_window_mgr_screen_is_on_default (ModestWindowMgr *self)
+{
+ /* Default implementation is assuming screen is always on */
+
+ return TRUE;
+}
+
+void
+modest_window_mgr_create_caches (ModestWindowMgr *mgr)
+{
+ MODEST_WINDOW_MGR_GET_CLASS (mgr)->create_caches (mgr);
+}
+
+static void
+modest_window_mgr_create_caches_default (ModestWindowMgr *self)
+{
+ load_new_editor (self);
+ load_new_view (self);
+}
+
+static gboolean
+tny_list_find (TnyList *list, GObject *item)
+{
+ TnyIterator *iterator;
+ gboolean found = FALSE;
+
+ for (iterator = tny_list_create_iterator (list);
+ !tny_iterator_is_done (iterator) && !found;
+ tny_iterator_next (iterator)) {
+ GObject *current = tny_iterator_get_current (iterator);
+ if (current == item)
+ found = TRUE;
+ g_object_unref (current);
+ }
+ g_object_unref (iterator);
+
+ return found;
+}
+
+static void
+modest_window_mgr_on_queue_changed (ModestMailOperationQueue *queue,
+ ModestMailOperation *mail_op,
+ ModestMailOperationQueueNotification type,
+ ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv;
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* We register to track progress */
+ if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
+ priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+ G_OBJECT (mail_op),
+ "operation-started",
+ G_CALLBACK (on_mail_operation_started),
+ self);
+ priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+ G_OBJECT (mail_op),
+ "operation-finished",
+ G_CALLBACK (on_mail_operation_finished),
+ self);
+ } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
+ priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
+ G_OBJECT (mail_op),
+ "operation-started");
+ priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
+ G_OBJECT (mail_op),
+ "operation-finished");
+ if (tny_list_find (priv->progress_operations, G_OBJECT (mail_op))) {
+ tny_list_remove (priv->progress_operations, G_OBJECT (mail_op));
+ g_signal_emit (self, signals[PROGRESS_LIST_CHANGED_SIGNAL], 0);
+ }
+ }
+}
+
+static void
+on_mail_operation_started (ModestMailOperation *mail_op,
+ gpointer user_data)
+{
+ ModestWindowMgr *self;
+ ModestWindowMgrPrivate *priv;
+ ModestMailOperationTypeOperation op_type;
+
+ self = MODEST_WINDOW_MGR (user_data);
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* First we check if the operation is a send receive operation,
+ * If now, we don't handle this */
+ op_type = modest_mail_operation_get_type_operation (mail_op);
+ if (op_type != MODEST_MAIL_OPERATION_TYPE_SEND &&
+ op_type != MODEST_MAIL_OPERATION_TYPE_SEND_AND_RECEIVE) {
+ return;
+ }
+
+ if (!tny_list_find (priv->progress_operations, G_OBJECT (mail_op))) {
+ tny_list_prepend (priv->progress_operations, G_OBJECT (mail_op));
+ g_signal_emit (self, signals[PROGRESS_LIST_CHANGED_SIGNAL], 0);
+ }
+}
+
+static void
+on_mail_operation_finished (ModestMailOperation *mail_op,
+ gpointer user_data)
+{
+ ModestWindowMgr *self;
+ ModestWindowMgrPrivate *priv;
+
+ self = MODEST_WINDOW_MGR (user_data);
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ if (tny_list_find (priv->progress_operations, G_OBJECT (mail_op))) {
+ tny_list_remove (priv->progress_operations, G_OBJECT (mail_op));
+ g_signal_emit (self, signals[PROGRESS_LIST_CHANGED_SIGNAL], 0);
+ }
+}
+
+TnyList *
+modest_window_mgr_get_progress_operations (ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv;
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ return tny_list_copy (priv->progress_operations);
+}
+
+gboolean
+modest_window_mgr_has_progress_operation (ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv;
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ return tny_list_get_length (priv->progress_operations) > 0;
+}
+
+gboolean
+modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self,
+ const gchar *account_name)
+{
+ ModestWindowMgrPrivate *priv;
+ gint account_ops = 0;
+ TnyIterator *iterator;
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ if (account_name == NULL)
+ return 0;
+
+ for (iterator = tny_list_create_iterator (priv->progress_operations);
+ !tny_iterator_is_done (iterator);
+ tny_iterator_next (iterator)) {
+ ModestMailOperation *mail_op;
+ TnyAccount *account;
+
+ mail_op= MODEST_MAIL_OPERATION (tny_iterator_get_current (iterator));
+ account = modest_mail_operation_get_account (mail_op);
+
+ if (account != NULL) {
+ const gchar *current_name;
+
+ current_name = tny_account_get_id (account);
+ if (current_name && strcmp (current_name, account_name) == 0)
+ account_ops ++;
+ g_object_unref (account);
+ }
+
+ g_object_unref (mail_op);
+ }
+ g_object_unref (iterator);
+
+ 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 <hildon/hildon.h>
+ /* 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;
+}
+