X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-window-mgr.c;h=e750488965e205960aad5f4eed99d7c57c8f370f;hb=0cd3bbc169fe8d5a35d6d61555668244b4d04067;hp=5913806b46fa4a00ac170e2f33c9c0c57e3ff6b4;hpb=7d07f29b865a0c42691c73affa6ab618dad8b3b3;p=modest diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index 5913806..e750488 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" @@ -66,10 +67,14 @@ 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 void modest_window_mgr_create_caches_default (ModestWindowMgr *self); static void modest_window_mgr_on_queue_changed (ModestMailOperationQueue *queue, ModestMailOperation *mail_op, ModestMailOperationQueueNotification type, @@ -161,10 +166,12 @@ modest_window_mgr_class_init (ModestWindowMgrClass *klass) 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; g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate)); @@ -227,7 +234,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 +242,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 @@ -375,11 +382,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); @@ -469,21 +477,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 +536,19 @@ 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() and automatic updates are + disabled*/ + if (modest_window_mgr_get_num_windows (self) == 0) { + gboolean auto_update; + auto_update = modest_conf_get_bool (modest_runtime_get_conf (), + MODEST_CONF_AUTO_UPDATE, NULL); + if (!auto_update) + tny_device_reset (modest_runtime_get_device ()); + } + return MODEST_WINDOW_MGR_GET_CLASS (self)->register_window (self, window, parent); } @@ -536,8 +580,6 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, return FALSE; } else { priv->main_window = window; - load_new_view (self); - load_new_editor (self); } } @@ -546,15 +588,14 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, 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)); @@ -581,13 +622,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); @@ -906,8 +943,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; @@ -949,6 +989,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 +1143,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 +1155,4 @@ modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self, return account_ops; } +