From 38b186699f0cfd984f71dccb62b7006e07b0f0a8 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Fri, 1 Jun 2007 15:05:50 +0000 Subject: [PATCH] * Added a unique identifier per header * Fixes NB#58780 pmo-trunk-r2037 --- src/gnome/modest-msg-view-window.c | 27 ++++++++++++++---- src/maemo/modest-msg-view-window.c | 49 ++++++++++++++++---------------- src/modest-tny-folder.c | 23 +++++++++++++++ src/modest-tny-folder.h | 19 ++++++++++++- src/modest-ui-actions.c | 51 ++++++++++++++++++++++++++++++---- src/modest-ui-dimming-rules.c | 4 +-- src/widgets/modest-msg-view-window.h | 5 +++- src/widgets/modest-msg-view.c | 6 ++++ src/widgets/modest-window-mgr.c | 17 ++++++++---- src/widgets/modest-window-mgr.h | 10 +++---- 10 files changed, 160 insertions(+), 51 deletions(-) diff --git a/src/gnome/modest-msg-view-window.c b/src/gnome/modest-msg-view-window.c index 849b015..6b6258d 100644 --- a/src/gnome/modest-msg-view-window.c +++ b/src/gnome/modest-msg-view-window.c @@ -57,6 +57,8 @@ struct _ModestMsgViewWindowPrivate { GtkWidget *toolbar; GtkWidget *menubar; GtkWidget *msg_view; + + gchar *msg_uid; }; #define MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -160,9 +162,10 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj) ModestMsgViewWindowPrivate *priv; priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj); - priv->toolbar = NULL; - priv->menubar = NULL; - priv->msg_view = NULL; + priv->toolbar = NULL; + priv->menubar = NULL; + priv->msg_view = NULL; + priv->msg_uid = NULL; } @@ -195,7 +198,16 @@ init_window (ModestMsgViewWindow *obj, TnyMsg *msg) static void modest_msg_view_window_finalize (GObject *obj) -{ +{ + ModestMsgViewWindowPrivate *priv; + + priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj); + + if (priv->msg_uid) { + g_free (priv->msg_uid); + msg_uid = NULL; + } + G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -210,7 +222,9 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgViewWindow *self) ModestWindow * -modest_msg_view_window_new (TnyMsg *msg, const gchar *account) +modest_msg_view_window_new (TnyMsg *msg, + const gchar *account, + const gchar *msg_uid) { GObject *obj; ModestMsgViewWindowPrivate *priv; @@ -226,6 +240,8 @@ modest_msg_view_window_new (TnyMsg *msg, const gchar *account) priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj); parent_priv = MODEST_WINDOW_GET_PRIVATE(obj); + priv->msg_uid = g_strdup (msg_uid); + modest_window_set_active_account (MODEST_WINDOW(obj), account); parent_priv->ui_manager = gtk_ui_manager_new(); @@ -321,6 +337,7 @@ modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self) ModestWindow* modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account, + const gchar *msg_uid, GtkTreeModel *model, GtkTreeRowReference *row_reference) { diff --git a/src/maemo/modest-msg-view-window.c b/src/maemo/modest-msg-view-window.c index aad0670..3e9ecdd 100644 --- a/src/maemo/modest-msg-view-window.c +++ b/src/maemo/modest-msg-view-window.c @@ -153,6 +153,8 @@ struct _ModestMsgViewWindowPrivate { guint queue_change_handler; guint progress_bar_timeout; + + gchar *msg_uid; }; #define MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -239,6 +241,7 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj) priv->optimized_view = FALSE; priv->progress_bar_timeout = 0; + priv->msg_uid = NULL; } @@ -443,6 +446,11 @@ modest_msg_view_window_finalize (GObject *obj) priv->row_reference = NULL; } + if (priv->msg_uid) { + g_free (priv->msg_uid); + priv->msg_uid = NULL; + } + G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -456,13 +464,16 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgViewWindow *self) } ModestWindow * -modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account_name, - GtkTreeModel *model, GtkTreeRowReference *row_reference) +modest_msg_view_window_new_with_header_model (TnyMsg *msg, + const gchar *account_name, + const gchar *msg_uid, + GtkTreeModel *model, + GtkTreeRowReference *row_reference) { ModestMsgViewWindow *window = NULL; ModestMsgViewWindowPrivate *priv = NULL; - window = MODEST_MSG_VIEW_WINDOW(modest_msg_view_window_new (msg, account_name)); + window = MODEST_MSG_VIEW_WINDOW(modest_msg_view_window_new (msg, account_name, msg_uid)); g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL); priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window); @@ -480,7 +491,9 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account_ ModestWindow * -modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name) +modest_msg_view_window_new (TnyMsg *msg, + const gchar *account_name, + const gchar *msg_uid) { ModestMsgViewWindow *self = NULL; GObject *obj = NULL; @@ -499,6 +512,8 @@ modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name) parent_priv = MODEST_WINDOW_GET_PRIVATE(obj); self = MODEST_MSG_VIEW_WINDOW (obj); + priv->msg_uid = g_strdup (msg_uid); + parent_priv->ui_manager = gtk_ui_manager_new(); parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new(); @@ -654,23 +669,8 @@ modest_msg_view_window_get_message (ModestMsgViewWindow *self) const gchar* modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self) { - TnyMsg *msg; - TnyHeader *header; - const gchar *retval = NULL; - - msg = modest_msg_view_window_get_message (self); - - if (!msg) - return NULL; - - header = tny_msg_get_header (msg); - if (header) { - retval = tny_header_get_uid (header); - g_object_unref (header); - } - g_object_unref (msg); - - return retval; + ModestMsgViewWindowPrivate *priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self); + return (const gchar*) priv->msg_uid; } static void @@ -1536,18 +1536,17 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart /* message attachment */ TnyHeader *header = NULL; ModestWindowMgr *mgr; - ModestWindow *msg_win; + ModestWindow *msg_win = NULL; header = tny_msg_get_header (TNY_MSG (mime_part)); mgr = modest_runtime_get_window_mgr (); - /* TODO: this is not getting any uid */ - msg_win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header)); + msg_win = modest_window_mgr_find_window_by_header (mgr, header); if (!msg_win) { gchar *account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (window))); if (!account) account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ()); - msg_win = modest_msg_view_window_new (TNY_MSG (mime_part), account); + msg_win = modest_msg_view_window_new (TNY_MSG (mime_part), account, NULL); modest_window_mgr_register_window (mgr, msg_win); gtk_window_set_transient_for (GTK_WINDOW (msg_win), GTK_WINDOW (window)); } diff --git a/src/modest-tny-folder.c b/src/modest-tny-folder.c index ca6d3d1..0405fa7 100644 --- a/src/modest-tny-folder.c +++ b/src/modest-tny-folder.c @@ -279,3 +279,26 @@ modest_tny_folder_is_outbox_for_account (TnyFolder *folder, TnyAccount *account) #endif } +gchar* +modest_tny_folder_get_header_unique_id (TnyHeader *header) +{ + TnyFolder *folder; + gchar *url, *retval; + const gchar *uid; + + g_return_val_if_fail (TNY_IS_HEADER (header), NULL); + + folder = tny_header_get_folder (header); + if (!folder) + return NULL; + + url = tny_folder_get_url_string (folder); + uid = tny_header_get_uid (header); + + retval = g_strjoin ("/", url, uid, NULL); + + g_free (url); + g_object_unref (folder); + + return retval; +} diff --git a/src/modest-tny-folder.h b/src/modest-tny-folder.h index 9096911..1997d17 100644 --- a/src/modest-tny-folder.h +++ b/src/modest-tny-folder.h @@ -129,7 +129,24 @@ ModestTnyFolderRules modest_tny_folder_get_rules (TnyFolder *folder); * Returns: TRUE if this folder is the per-account outbox for the account. */ gboolean modest_tny_folder_is_outbox_for_account (TnyFolder *folder, - TnyAccount *account); + TnyAccount *account); + +/** + * modest_tny_msg_get_header_unique_id: + * @header: a #TnyHeader + * + * this function returns a unique id for a message summary, that's it + * a TnyHeader retrieved with tny_folder_get_headers (you can not use + * the TnyHeader returned by tny_msg_get_header because it has not an + * uid). + * + * This uid is built from the folder URL string and the header uid, + * the caller of the function must free the unique id when no longer + * needed + * + * Returns: a unique identificator for a header object + **/ +gchar* modest_tny_folder_get_header_unique_id (TnyHeader *header); G_END_DECLS diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 5c0fd62..f9d8a05 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -32,6 +32,7 @@ #endif /*HAVE_CONFIG_H*/ #include +#include #include #include #include @@ -235,12 +236,41 @@ modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win) gchar *message = NULL; gchar *desc = NULL; gint response; + gboolean found; + ModestWindowMgr *mgr; g_return_if_fail (MODEST_IS_WINDOW(win)); header_list = get_selected_headers (win); if (!header_list) return; + /* Check if any of the headers is already opened */ + iter = tny_list_create_iterator (header_list); + found = FALSE; + mgr = modest_runtime_get_window_mgr (); + while (!tny_iterator_is_done (iter) && !found) { + header = TNY_HEADER (tny_iterator_get_current (iter)); + if (modest_window_mgr_find_window_by_header (mgr, header)) + found = TRUE; + g_object_unref (header); + tny_iterator_next (iter); + } + g_object_unref (iter); + + if (found) { + gchar *num, *msg; + + num = g_strdup_printf ("%d", tny_list_get_length (header_list)); + msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num); + + modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg); + + g_free (msg); + g_free (num); + g_object_unref (header_list); + return; + } + /* Select message */ if (tny_list_get_length(header_list) > 1) message = g_strdup(_("emev_nc_delete_messages")); @@ -249,6 +279,8 @@ modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win) header = TNY_HEADER (tny_iterator_get_current (iter)); desc = g_strdup_printf ("%s", tny_header_get_subject (header)); message = g_strdup_printf(_("emev_nc_delete_message"), desc); + g_object_unref (header); + g_object_unref (iter); } /* Confirmation dialog */ @@ -275,7 +307,6 @@ modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win) g_free(message); g_free(desc); g_object_unref (header_list); - g_object_unref (iter); } @@ -548,6 +579,8 @@ open_msg_cb (ModestMailOperation *mail_op, if (folder_type == TNY_FOLDER_TYPE_DRAFTS) { win = modest_msg_edit_window_new (msg, account); } else { + gchar *uid = modest_tny_folder_get_header_unique_id (header); + if (MODEST_IS_MAIN_WINDOW (parent_win)) { GtkWidget *header_view; GtkTreeSelection *sel; @@ -568,16 +601,18 @@ open_msg_cb (ModestMailOperation *mail_op, g_list_free (sel_list); win = modest_msg_view_window_new_with_header_model (msg, - account, + account, + (const gchar*) uid, model, row_reference); gtk_tree_row_reference_free (row_reference); } else { - win = modest_msg_view_window_new (msg, account); + win = modest_msg_view_window_new (msg, account, (const gchar*) uid); } } else { - win = modest_msg_view_window_new (msg, account); + win = modest_msg_view_window_new (msg, account, (const gchar*) uid); } + g_free (uid); } /* Register and show new window */ @@ -636,9 +671,13 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win) TnyHeader *header; header = TNY_HEADER (tny_iterator_get_current (iter)); - window = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header)); - if (window) + window = modest_window_mgr_find_window_by_header (mgr, header); + if (window) { + /* Do not open again the message and present + the window to the user */ tny_list_remove (headers, G_OBJECT (header)); + gtk_window_present (GTK_WINDOW (window)); + } g_object_unref (header); tny_iterator_next (iter); diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index f5d81e7..82ad2de 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -544,9 +544,9 @@ _already_opened_msg (ModestWindow *win) /* Check dimmed rule (TODO: check focus on widgets */ mgr = modest_runtime_get_window_mgr (); iter = tny_list_create_iterator (selected_headers); - while (!tny_iterator_is_done (iter) && result) { + while (!tny_iterator_is_done (iter) && result) { header = TNY_HEADER (tny_iterator_get_current (iter)); - window = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header)); + window = modest_window_mgr_find_window_by_header (mgr, header); result = result && (window != NULL); g_object_unref (header); diff --git a/src/widgets/modest-msg-view-window.h b/src/widgets/modest-msg-view-window.h index 3e56737..b3d161c 100644 --- a/src/widgets/modest-msg-view-window.h +++ b/src/widgets/modest-msg-view-window.h @@ -75,7 +75,9 @@ GType modest_msg_view_window_get_type (void) G_GNUC_CONST; * * Returns: a new #ModestMsgViewWindow, or NULL in case of error */ -ModestWindow* modest_msg_view_window_new (TnyMsg *msg, const gchar *account); +ModestWindow* modest_msg_view_window_new (TnyMsg *msg, + const gchar *account, + const gchar *msg_uid); /** * modest_msg_view_window_new_with_header_model: @@ -93,6 +95,7 @@ ModestWindow* modest_msg_view_window_new (TnyMsg *msg, const gchar *ac */ ModestWindow* modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account, + const gchar *msg_uid, GtkTreeModel *model, GtkTreeRowReference *row_reference); diff --git a/src/widgets/modest-msg-view.c b/src/widgets/modest-msg-view.c index 66c205c..43185d7 100644 --- a/src/widgets/modest-msg-view.c +++ b/src/widgets/modest-msg-view.c @@ -1382,6 +1382,12 @@ modest_msg_view_set_message (ModestMsgView *self, TnyMsg *msg) } else { gtk_widget_hide_all (priv->attachments_box); } + +/* g_print ("---\nfilename %s\ncontent_location %s\ncontent_id%s\ncontent_type%s\n", */ +/* tny_mime_part_get_filename (body), */ +/* tny_mime_part_get_content_location (body), */ +/* tny_mime_part_get_content_id (body), */ +/* tny_mime_part_get_content_type (body)); */ } else set_empty_message (self); diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index cf575d8..93fce0c 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -30,6 +30,7 @@ #include #include "modest-window-mgr.h" #include "modest-runtime.h" +#include "modest-tny-folder.h" #include "widgets/modest-main-window.h" #include "widgets/modest-msg-edit-window.h" #include "widgets/modest-msg-view-window.h" @@ -294,6 +295,7 @@ compare_msguids (ModestWindow *win, /* Get message uid from msg window */ msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win)); + if (msg_uid && !strcmp (msg_uid, uid)) return 0; else @@ -301,23 +303,28 @@ compare_msguids (ModestWindow *win, } ModestWindow* -modest_window_mgr_find_window_by_msguid (ModestWindowMgr *self, - const gchar *msguid) +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 (msguid != NULL, 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, - msguid, + msg_uid, (GCompareFunc) compare_msguids); + /* Free */ + g_free (msg_uid); + /* Return the window */ if (win) return win->data; else @@ -496,5 +503,3 @@ void modest_window_mgr_save_state_for_all_windows (ModestWindowMgr *self) win = g_list_next (win); } } - - diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index 1a70a90..700faa2 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -88,17 +88,17 @@ void modest_window_mgr_unregister_window (ModestWindowMgr *self, /** - * modest_window_mgr_find_window_by_msguid: + * modest_window_mgr_find_window_by_header: * @self: the #ModestWindowMgr * @msgid: the message uid * - * Looks for a #ModestWindow that shows the message specified by the - * message uid passed as argument + * 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_msguid (ModestWindowMgr *self, - const gchar *msguid); +ModestWindow* modest_window_mgr_find_window_by_header (ModestWindowMgr *self, + TnyHeader *header); /** * modest_window_mgr_set_fullscreen_mode: -- 1.7.9.5