From d144f67aad71f1e437e9f3279de827f03078e346 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 29 Jun 2007 11:28:00 +0000 Subject: [PATCH] * update the modest-window-manager; together with the next patch, this fixes NB#57297 - we do this by adding modest_window_mgr_register_header, modest_window_mgr_find_registered_header. in the next patch, these will be called *before* actually opening the message, so it will be impossible to open the same message several times. the problem used to be that the windows were only registered after the message was retrieved, so plenty time to have doubles, esp. on a slow connection - also fix a bug where really the registered *window* is returned, instead of the GList* (casting hid this bug), this enables us to popup a msg-view-window if it was already opened for the activated message pmo-trunk-r2491 --- src/widgets/modest-details-dialog.c | 7 +- src/widgets/modest-window-mgr.c | 190 ++++++++++++++++++++++++++--------- src/widgets/modest-window-mgr.h | 41 +++++--- src/widgets/modest-window.c | 4 + 4 files changed, 180 insertions(+), 62 deletions(-) diff --git a/src/widgets/modest-details-dialog.c b/src/widgets/modest-details-dialog.c index a72b5e6..567ea59 100644 --- a/src/widgets/modest-details-dialog.c +++ b/src/widgets/modest-details-dialog.c @@ -268,7 +268,7 @@ modest_details_dialog_set_folder_default (ModestDetailsDialog *self, TnyFolder *folder) { TnyFolderStats *stats; - gchar *count = NULL, *size_s = NULL, *name = NULL; + gchar *count, *size_s, *name = NULL; gint size; /* Set window title */ @@ -290,9 +290,10 @@ modest_details_dialog_set_folder_default (ModestDetailsDialog *self, gint type = modest_tny_folder_get_local_folder_type (folder); if (type != TNY_FOLDER_TYPE_UNKNOWN) name = g_strdup(modest_local_folder_info_get_type_display_name (type)); - } else { + } + + if (!name) name = g_strdup (tny_folder_get_name (folder)); - } modest_details_dialog_add_data (self, _("mcen_fi_folder_properties_foldername"), name); modest_details_dialog_add_data (self, _("mcen_fi_folder_properties_messages"), count); diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index e8b583d..1d768e0 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -65,6 +65,7 @@ struct _ModestWindowMgrPrivate { gboolean show_toolbars_fullscreen; GSList *windows_that_prevent_hibernation; + GSList *preregistered_uids; GHashTable *destroy_handlers; }; #define MODEST_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -122,6 +123,8 @@ modest_window_mgr_init (ModestWindowMgr *obj) priv->main_window = NULL; priv->fullscreen_mode = FALSE; + priv->preregistered_uids = NULL; + /* Could not initialize it from gconf, singletons are not ready yet */ priv->show_toolbars = FALSE; @@ -146,6 +149,10 @@ modest_window_mgr_finalize (GObject *obj) priv->window_list = NULL; } + g_slist_foreach (priv->preregistered_uids, (GFunc)g_free, NULL); + g_slist_free (priv->preregistered_uids); + + /* Free the hash table with the handlers */ if (priv->destroy_handlers) { g_hash_table_destroy (priv->destroy_handlers); @@ -164,6 +171,134 @@ modest_window_mgr_new (void) return MODEST_WINDOW_MGR(g_object_new(MODEST_TYPE_WINDOW_MGR, NULL)); } + + + +/* do we have uid? */ +static gboolean +has_uid (GSList *list, const gchar *uid) +{ + GSList *cursor = list; + + if (!uid) + return FALSE; + + while (cursor) { + if (cursor->data && strcmp (cursor->data, uid) == 0) + return TRUE; + cursor = g_slist_next (cursor); + } + return FALSE; +} + + +/* remove all from the list have have uid = uid */ +static GSList* +remove_uid (GSList *list, const gchar *uid) +{ + GSList *cursor = list, *start = list; + + if (!uid) + return FALSE; + + while (cursor) { + GSList *next = g_slist_next (cursor); + if (cursor->data && strcmp (cursor->data, uid) == 0) { + g_free (cursor->data); + start = g_slist_delete_link (start, cursor); + } + cursor = next; + } + return start; +} + + +static GSList * +append_uid (GSList *list, const gchar *uid) +{ + return g_slist_append (list, g_strdup(uid)); +} + + + +void +modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header) +{ + ModestWindowMgrPrivate *priv; + gchar* uid; + + g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); + 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 (!has_uid (priv->preregistered_uids, uid)) + priv->preregistered_uids = append_uid (priv->preregistered_uids, uid); + + g_free (uid); +} + + + +static gint +compare_msguids (ModestWindow *win, + const gchar *uid) +{ + const gchar *msg_uid; + + if (!MODEST_IS_MSG_VIEW_WINDOW (win)) + return 1; + + /* Get message uid from msg window */ + msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win)); + + if (msg_uid && uid &&!strcmp (msg_uid, uid)) + return 0; + else + return 1; +} + + + +gboolean +modest_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *header, + ModestWindow **win) +{ + ModestWindowMgrPrivate *priv; + gchar* uid; + gboolean retval = FALSE; + GList *item = NULL; + + g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); + g_return_val_if_fail (TNY_IS_HEADER(header), FALSE); + + priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + uid = modest_tny_folder_get_header_unique_id (header); + + /* first, look for the window */ + /* note, the UID cannot be in both the window list and the preregistered uid list */ + if (priv->window_list) { + item = g_list_find_custom (priv->window_list, + uid, (GCompareFunc) compare_msguids); + if (item) + retval = TRUE; + if (win) + *win = item ? MODEST_WINDOW(item->data) : NULL; + } + + + /* IF It's not in the window list. maybe it's in our uid list... */ + retval = retval || has_uid (priv->preregistered_uids, uid); + + g_free (uid); + + return retval; +} + + + void modest_window_mgr_register_window (ModestWindowMgr *self, ModestWindow *window) @@ -195,6 +330,14 @@ modest_window_mgr_register_window (ModestWindowMgr *self, } } + /* remove from the list of pre-registered uids */ + if (MODEST_IS_MSG_VIEW_WINDOW(window)) { + priv->preregistered_uids = + remove_uid (priv->preregistered_uids, + modest_msg_view_window_get_message_uid + (MODEST_MSG_VIEW_WINDOW (window))); + } + /* Add to list. Keep a reference to the window */ g_object_ref (window); priv->window_list = g_list_prepend (priv->window_list, window); @@ -336,53 +479,6 @@ modest_window_mgr_unregister_window (ModestWindowMgr *self, } } -static gint -compare_msguids (ModestWindow *win, - const gchar *uid) -{ - const gchar *msg_uid; - - if (!MODEST_IS_MSG_VIEW_WINDOW (win)) - return 1; - - /* Get message uid from msg window */ - msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win)); - - if (msg_uid && uid &&!strcmp (msg_uid, uid)) - return 0; - else - return 1; -} - -ModestWindow* -modest_window_mgr_find_window_by_header (ModestWindowMgr *self, - TnyHeader *header) -{ - ModestWindowMgrPrivate *priv; - GList *win = NULL; - gchar *msg_uid; - - g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), NULL); - g_return_val_if_fail (TNY_IS_HEADER (header), NULL); - - priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); - msg_uid = modest_tny_folder_get_header_unique_id (header); - - /* Look for the window */ - if (priv->window_list) - win = g_list_find_custom (priv->window_list, - msg_uid, - (GCompareFunc) compare_msguids); - /* Free */ - g_free (msg_uid); - - /* Return the window */ - if (win) - return win->data; - else - return NULL; -} - void modest_window_mgr_set_fullscreen_mode (ModestWindowMgr *self, gboolean on) diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index 700faa2..9cc2134 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -87,18 +87,6 @@ void modest_window_mgr_unregister_window (ModestWindowMgr *self, ModestWindow *window); -/** - * modest_window_mgr_find_window_by_header: - * @self: the #ModestWindowMgr - * @msgid: the message uid - * - * Looks for a #ModestWindow that shows the message whose header is - * passed as argument - * - * Return value: the #ModestWindow if found, else NULL - **/ -ModestWindow* modest_window_mgr_find_window_by_header (ModestWindowMgr *self, - TnyHeader *header); /** * modest_window_mgr_set_fullscreen_mode: @@ -155,6 +143,35 @@ ModestWindow* modest_window_mgr_get_main_window (ModestWindowMgr *self); void modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self, GtkWindow *window); + +/** + * modest_window_mgr_find_registered_header + * @self: a #ModestWindowMgr + * @header: a valid #TnyHeader + * + * search for the given uid in both the list of preregistered uids and in the window list; + * if it's available in the window list, fill the *win out-param + * + * returns TRUE if found, FALSE otherwise + **/ +gboolean modest_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *header, + ModestWindow **win); + + +/** + * modest_window_mgr_register_header + * @self: a #ModestWindowMgr + * @header: a valid #TnyHeader + * + * register the uid, even before the window is created. thus, we know when + * some window creation might already be underway. the uid will automatically be + * removed when the window itself will registered + * + **/ +void modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header); + + + /** * modest_window_mgr_get_hibernation_is_prevented: * @self: a #ModestWindowMgr diff --git a/src/widgets/modest-window.c b/src/widgets/modest-window.c index 3407115..0a53285 100644 --- a/src/widgets/modest-window.c +++ b/src/widgets/modest-window.c @@ -293,6 +293,8 @@ modest_window_show_toolbar_default (ModestWindow *window, g_warning ("modest: You should implement %s", __FUNCTION__); } + + void modest_window_save_state (ModestWindow *window) { @@ -300,3 +302,5 @@ modest_window_save_state (ModestWindow *window) if (klass->save_state_func) klass->save_state_func (window); } + + -- 1.7.9.5