[evolution] Bug 626724 - Folder tree mistakes "mark as unread" as new mail



commit dbb4c2472f54845f131f4df91aa11ec1d852b80a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Aug 12 08:48:20 2010 -0400

    Bug 626724 - Folder tree mistakes "mark as unread" as new mail

 mail/e-mail-reader.c        |   11 ++++++++++-
 mail/em-folder-tree-model.c |   42 +++++++++++++++++++++++++++++++++++++++---
 mail/em-folder-tree-model.h |    6 +++++-
 mail/message-list.c         |   10 ++++++++++
 4 files changed, 64 insertions(+), 5 deletions(-)
---
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 0cb67ce..5a0ef46 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -575,17 +575,26 @@ action_mail_mark_unread_cb (GtkAction *action,
                             EMailReader *reader)
 {
 	GtkWidget *message_list;
+	EMFolderTreeModel *model;
+	const gchar *folder_uri;
 	guint32 mask = CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_DELETED;
 	guint32 set  = 0;
+	guint n_marked;
 
 	message_list = e_mail_reader_get_message_list (reader);
 
-	e_mail_reader_mark_selected (reader, mask, set);
+	n_marked = e_mail_reader_mark_selected (reader, mask, set);
 
 	if (MESSAGE_LIST (message_list)->seen_id != 0) {
 		g_source_remove (MESSAGE_LIST (message_list)->seen_id);
 		MESSAGE_LIST (message_list)->seen_id = 0;
 	}
+
+	/* Notify the tree model that the user has marked messages as
+	 * unread so it doesn't mistake the event as new mail arriving. */
+	model = em_folder_tree_model_get_default ();
+	folder_uri = e_mail_reader_get_folder_uri (reader);
+	em_folder_tree_model_user_marked_unread (model, folder_uri, n_marked);
 }
 
 static void
diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c
index 8161027..82620f7 100644
--- a/mail/em-folder-tree-model.c
+++ b/mail/em-folder-tree-model.c
@@ -1312,14 +1312,50 @@ em_folder_tree_model_lookup_store_info (EMFolderTreeModel *model,
 
 GtkTreeRowReference *
 em_folder_tree_model_lookup_uri (EMFolderTreeModel *model,
-                                 const gchar *uri)
+                                 const gchar *folder_uri)
 {
 	GtkTreeRowReference *reference;
 
 	g_return_val_if_fail (EM_IS_FOLDER_TREE_MODEL (model), NULL);
-	g_return_val_if_fail (uri != NULL, NULL);
+	g_return_val_if_fail (folder_uri != NULL, NULL);
 
-	reference = g_hash_table_lookup (model->priv->uri_index, uri);
+	reference = g_hash_table_lookup (model->priv->uri_index, folder_uri);
 
 	return gtk_tree_row_reference_valid (reference) ? reference : NULL;
 }
+
+void
+em_folder_tree_model_user_marked_unread (EMFolderTreeModel *model,
+                                         const gchar *folder_uri,
+                                         guint n_marked)
+{
+	GtkTreeRowReference *reference;
+	GtkTreePath *path;
+	GtkTreeIter iter;
+	guint unread;
+
+	/* The user marked messages in the given folder as unread.
+	 * Update our unread counts so we don't misinterpret this
+	 * event as new mail arriving. */
+
+	g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model));
+	g_return_if_fail (folder_uri != NULL);
+
+	reference = em_folder_tree_model_lookup_uri (model, folder_uri);
+	g_return_if_fail (gtk_tree_row_reference_valid (reference));
+
+	path = gtk_tree_row_reference_get_path (reference);
+	gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
+	gtk_tree_path_free (path);
+
+	gtk_tree_model_get (
+		GTK_TREE_MODEL (model), &iter,
+		COL_UINT_UNREAD, &unread, -1);
+
+	unread += n_marked;
+
+	gtk_tree_store_set (
+		GTK_TREE_STORE (model), &iter,
+		COL_UINT_UNREAD_LAST_SEL, unread,
+		COL_UINT_UNREAD, unread, -1);
+}
diff --git a/mail/em-folder-tree-model.h b/mail/em-folder-tree-model.h
index 82775ae..25ed2d8 100644
--- a/mail/em-folder-tree-model.h
+++ b/mail/em-folder-tree-model.h
@@ -152,7 +152,11 @@ EMFolderTreeModelStoreInfo *
 GtkTreeRowReference *
 		em_folder_tree_model_lookup_uri
 					(EMFolderTreeModel *model,
-					 const gchar *uri);
+					 const gchar *folder_uri);
+void		em_folder_tree_model_user_marked_unread
+					(EMFolderTreeModel *model,
+					 const gchar *folder_uri,
+					 guint n_marked);
 
 G_END_DECLS
 
diff --git a/mail/message-list.c b/mail/message-list.c
index d218c9e..848bef2 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -3951,6 +3951,16 @@ on_click (ETree *tree, gint row, ETreePath path, gint col, GdkEvent *event, Mess
 	uid = camel_message_info_uid (info);
 	camel_folder_set_message_flags (list->folder, uid, flag, ~flags);
 
+	/* Notify the folder tree model that the user has marked a message
+	 * as unread so it doesn't mistake the event as new mail arriving. */
+	if (flag == CAMEL_MESSAGE_SEEN) {
+		EMFolderTreeModel *model;
+
+		model = em_folder_tree_model_get_default ();
+		em_folder_tree_model_user_marked_unread (
+			model, list->folder_uri, 1);
+	}
+
 	if (flag == CAMEL_MESSAGE_SEEN && list->seen_id) {
 		g_source_remove (list->seen_id);
 		list->seen_id = 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]