X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-window-mgr.c;h=a7d8a241011db7199cb215d7912945ea05155cf3;hb=ccdfe35c4e5ac57fffc0442f3770a3c118185e64;hp=5913806b46fa4a00ac170e2f33c9c0c57e3ff6b4;hpb=7d07f29b865a0c42691c73affa6ab618dad8b3b3;p=modest diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index 5913806..a7d8a24 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -33,6 +33,7 @@ #include "modest-tny-folder.h" #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" @@ -57,7 +58,9 @@ static void modest_window_mgr_show_toolbars_default (ModestWindowMgr *self, GType window_type, gboolean show_toolbars, gboolean fullscreen); +#ifndef MODEST_TOOLKIT_HILDON2 static ModestWindow* modest_window_mgr_get_main_window_default (ModestWindowMgr *self, gboolean show); +#endif static GtkWindow *modest_window_mgr_get_modal_default (ModestWindowMgr *self); static void modest_window_mgr_set_modal_default (ModestWindowMgr *self, GtkWindow *window, @@ -66,10 +69,15 @@ static gboolean modest_window_mgr_close_all_windows_default (ModestWindowMgr *se static gboolean modest_window_mgr_find_registered_header_default (ModestWindowMgr *self, TnyHeader *header, ModestWindow **win); +static gboolean modest_window_mgr_find_registered_message_uid_default (ModestWindowMgr *self, + const gchar *msg_uid, + ModestWindow **win); 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, ModestMailOperationQueueNotification type, @@ -78,6 +86,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 { @@ -90,11 +99,12 @@ typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate; struct _ModestWindowMgrPrivate { guint banner_counter; +#ifndef MODEST_TOOLKIT_HILDON2 ModestWindow *main_window; - +#endif GSList *windows_that_prevent_hibernation; GSList *preregistered_uids; - + guint closing_time; GtkWidget *cached_view; @@ -156,15 +166,21 @@ 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; +#ifndef MODEST_TOOLKIT_HILDON2 mgr_class->get_main_window = modest_window_mgr_get_main_window_default; +#endif 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; mgr_class->find_registered_header = modest_window_mgr_find_registered_header_default; + mgr_class->find_registered_message_uid = modest_window_mgr_find_registered_message_uid_default; mgr_class->get_window_list = modest_window_mgr_get_window_list_default; mgr_class->show_initial_window = modest_window_mgr_show_initial_window_default; 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)); @@ -227,7 +243,7 @@ load_new_view (ModestWindowMgr *self) { ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); if ((priv->cached_view == NULL) && (priv->idle_load_view_id == 0)) - priv->idle_load_view_id = g_idle_add ((GSourceFunc) idle_load_view, self); + priv->idle_load_view_id = g_timeout_add (2500, (GSourceFunc) idle_load_view, self); } static void @@ -235,7 +251,7 @@ load_new_editor (ModestWindowMgr *self) { ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); if ((priv->cached_editor == NULL) && (priv->idle_load_editor_id == 0)) - priv->idle_load_editor_id = g_idle_add ((GSourceFunc) idle_load_editor, self); + priv->idle_load_editor_id = g_timeout_add (5000, (GSourceFunc) idle_load_editor, self); } static void @@ -245,8 +261,9 @@ modest_window_mgr_init (ModestWindowMgr *obj) priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj); priv->banner_counter = 0; +#ifndef MODEST_TOOLKIT_HILDON2 priv->main_window = NULL; - +#endif priv->preregistered_uids = NULL; priv->closing_time = 0; @@ -375,11 +392,12 @@ modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header, co g_return_if_fail (TNY_IS_HEADER(header)); priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - uid = modest_tny_folder_get_header_unique_id (header); - - if (uid == NULL) + if (alt_uid != NULL) { uid = g_strdup (alt_uid); - + } else { + uid = modest_tny_folder_get_header_unique_id (header); + } + if (!has_uid (priv->preregistered_uids, uid)) { MODEST_DEBUG_BLOCK(g_debug ("registering new uid %s", uid);); priv->preregistered_uids = append_uid (priv->preregistered_uids, uid); @@ -427,11 +445,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); + } } @@ -469,21 +488,44 @@ static gboolean modest_window_mgr_find_registered_header_default (ModestWindowMgr *self, TnyHeader *header, ModestWindow **win) { + gchar* uid = NULL; + + g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); + g_return_val_if_fail (TNY_IS_HEADER(header), FALSE); + + uid = modest_tny_folder_get_header_unique_id (header); + + if (uid) + return modest_window_mgr_find_registered_message_uid (self, uid, win); + else + return FALSE; +} + +gboolean +modest_window_mgr_find_registered_message_uid (ModestWindowMgr *self, const gchar *msg_uid, + ModestWindow **win) +{ + return MODEST_WINDOW_MGR_GET_CLASS (self)->find_registered_message_uid (self, msg_uid, win); +} + +static gboolean +modest_window_mgr_find_registered_message_uid_default (ModestWindowMgr *self, const gchar *msg_uid, + ModestWindow **win) +{ ModestWindowMgrPrivate *priv = NULL; gchar* uid = NULL; gboolean has_header = FALSE; g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); - g_return_val_if_fail (TNY_IS_HEADER(header), FALSE); - + g_return_val_if_fail (msg_uid && msg_uid[0] != '\0', FALSE); + priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - uid = modest_tny_folder_get_header_unique_id (header); - if (win) *win = NULL; - has_header = has_uid (priv->preregistered_uids, uid); + has_header = has_uid (priv->preregistered_uids, msg_uid); + g_free (uid); return has_header; } @@ -505,6 +547,15 @@ 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) { + if (tny_device_is_forced (modest_runtime_get_device ())) + tny_device_reset (modest_runtime_get_device ()); + } + return MODEST_WINDOW_MGR_GET_CLASS (self)->register_window (self, window, parent); } @@ -516,7 +567,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); @@ -528,37 +579,24 @@ 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; - load_new_view (self); - load_new_editor (self); - } - } /* remove from the list of pre-registered uids */ if (MODEST_IS_MSG_VIEW_WINDOW(window)) { const gchar *uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (window)); - if (!has_uid (priv->preregistered_uids, uid)) - g_debug ("weird: no uid for window (%s)", uid); - MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid ? uid : "");); - - priv->preregistered_uids = - remove_uid (priv->preregistered_uids, - modest_msg_view_window_get_message_uid - (MODEST_MSG_VIEW_WINDOW (window))); + + if (has_uid (priv->preregistered_uids, uid)) { + priv->preregistered_uids = + remove_uid (priv->preregistered_uids, + modest_msg_view_window_get_message_uid + (MODEST_MSG_VIEW_WINDOW (window))); + } } 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 = @@ -581,13 +619,9 @@ static void modest_window_mgr_unregister_window_default (ModestWindowMgr *self, ModestWindow *window) { - ModestWindowMgrPrivate *priv; - g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); g_return_if_fail (MODEST_IS_WINDOW (window)); - priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - /* Save state */ modest_window_save_state (window); @@ -626,7 +660,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, @@ -635,7 +669,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, @@ -644,37 +678,28 @@ modest_window_mgr_show_toolbars_default (ModestWindowMgr *self, return; } +#ifndef MODEST_TOOLKIT_HILDON2 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* +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* +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; + return NULL; } @@ -682,13 +707,13 @@ 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; } - +#endif GtkWindow * modest_window_mgr_get_modal (ModestWindowMgr *self) @@ -817,9 +842,11 @@ modest_window_mgr_get_num_windows (ModestWindowMgr *self) g_list_free (window_list); } +#ifndef MODEST_TOOLKIT_HILDON2 /* 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--; +#endif return num_windows + priv->banner_counter; } @@ -906,8 +933,11 @@ modest_window_mgr_show_initial_window (ModestWindowMgr *self) /* 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); + 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; @@ -916,9 +946,13 @@ modest_window_mgr_show_initial_window (ModestWindowMgr *self) 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 } @@ -949,6 +983,19 @@ modest_window_mgr_screen_is_on_default (ModestWindowMgr *self) 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) { @@ -1090,7 +1137,7 @@ modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self, if (account != NULL) { const gchar *current_name; - current_name = tny_account_get_name (account); + current_name = tny_account_get_id (account); if (current_name && strcmp (current_name, account_name) == 0) account_ops ++; g_object_unref (account); @@ -1102,3 +1149,80 @@ 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; +} +