[anjal] Add unread thread state.



commit 64078a43d5674df43aecd5bc7a40e6a1d2948e59
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Wed Mar 18 17:12:48 2009 +0530

    Add unread thread state.
---
 src/em-tree-store.c |   47 ++++++++++++++++++++++++++++++++++++++++++-----
 src/em-tree-store.h |    1 +
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/src/em-tree-store.c b/src/em-tree-store.c
index ca249f8..108e639 100644
--- a/src/em-tree-store.c
+++ b/src/em-tree-store.c
@@ -43,6 +43,7 @@
 
 #define node_has_children(node) ((node->flags & EM_TREE_NODE_LEAF) == 0 && node->children.head != (EDListNode *)&node->children.tail)
 static time_t emts_thread_time (EMTreeStore *emts, EMTreeNode *node, char **);
+static gboolean emts_thread_unread (EMTreeStore *emts, EMTreeNode *node);
 
 struct _emts_folder {
 	struct _emts_folder *next;
@@ -82,7 +83,8 @@ struct _emts_column_info emts_column_info[EMTS_COL_NUMBER] = {
 	{ G_TYPE_STRING, "to", N_("To") },
 	{ G_TYPE_UINT, "flags", N_("Flags") },
 	{ G_TYPE_STRING, "threadcount", N_("Thread Count")},
-	{ G_TYPE_STRING, "threadpreview", N_("Thread Preview") }
+	{ G_TYPE_STRING, "threadpreview", N_("Thread Preview") },
+	{ G_TYPE_BOOLEAN, "unread", N_("Unread") }	
 };
 
 static EMTreeNode *
@@ -251,6 +253,9 @@ emts_get_value(GtkTreeModel *tree_model, GtkTreeIter  *iter, gint column, GValue
 		case EMTS_COL_DATE:
 			g_value_set_ulong(value, 0);
 			break;			 
+		case EMTS_COL_UNREAD:
+			 g_value_set_boolean (value, FALSE);
+			break;			 
 		case EMTS_COL_FLAGS:
 		case EMTS_COL_THREADPREVIEW:	 
 		case EMTS_COL_THREADCOUNT: {
@@ -267,14 +272,17 @@ emts_get_value(GtkTreeModel *tree_model, GtkTreeIter  *iter, gint column, GValue
 			/* FIXME: need to ref the info? */
 			g_value_set_pointer(value, node->info);
 			break;
-		case EMTS_COL_SUBJECT:
+		case EMTS_COL_SUBJECT: 
 			g_value_set_string(value, camel_message_info_subject(node->info));
 			break;
+		case EMTS_COL_UNREAD: 
+			 g_value_set_boolean(value, emts_thread_unread(tree_model, node));
+			break;			
 		case EMTS_COL_FROM: {
 			 char **str, *newstr = NULL;
 			 char *frn;
 			 int cnt = emts_node_count(node);
-			 gboolean unread = ((camel_message_info_flags(node->info)) & CAMEL_MESSAGE_SEEN) == 0;
+			 gboolean unread = emts_thread_unread(tree_model, node);
 			 
 			 str  = g_strsplit (camel_message_info_from(node->info), "<", 2);
 			 if (cnt)
@@ -321,9 +329,11 @@ emts_get_value(GtkTreeModel *tree_model, GtkTreeIter  *iter, gint column, GValue
 			 g_free(str);
 			 break;
 		}
-		case EMTS_COL_FLAGS:
-			 g_value_set_uint(value, (unsigned int)camel_message_info_flags(node->info));
+		case EMTS_COL_FLAGS: {
+			 EMTreeNode *lnode = g_hash_table_lookup(f->uid_table, node->latest_uid);
+			 g_value_set_uint(value, (unsigned int)camel_message_info_flags(lnode->info));
 			 break;
+		}
 		case EMTS_COL_DATE: {
 //			g_value_set_ulong(value, (unsigned long)camel_message_info_date_sent(node->info));
 			 char *uid= NULL;
@@ -1188,6 +1198,33 @@ emts_thread_time (EMTreeStore *emts, EMTreeNode *node, char **ret_uid)
 	 return dsent;
 }
 
+static gboolean
+emts_thread_unread (EMTreeStore *emts, EMTreeNode *node)
+{
+
+	 EMTreeNode *n, next;
+	 gboolean unread = FALSE;
+
+	 if (node->info) {
+		  unread = (camel_message_info_flags (node->info) & CAMEL_MESSAGE_SEEN) ? FALSE: TRUE;;
+	 }
+	 
+	 n = node->children.head;
+	 while (n && n != &node->children.tail && !unread) {
+		  unread = (camel_message_info_flags (n->info) & CAMEL_MESSAGE_SEEN) ? FALSE : TRUE;
+		  if (unread)
+			   break;
+		  if (node_has_children(n)) {			   
+			   unread = emts_thread_unread (emts, n->children.head);
+			   if (unread)
+					break;
+		  }
+		  n = n->next;
+	 }
+
+	 return unread;
+}
+
 time_t
 em_tree_store_thread_time (EMTreeStore *emts, const char *uid)
 {
diff --git a/src/em-tree-store.h b/src/em-tree-store.h
index 6005e70..830bd2f 100644
--- a/src/em-tree-store.h
+++ b/src/em-tree-store.h
@@ -71,6 +71,7 @@ typedef enum {
 	EMTS_COL_FLAGS,
 	EMTS_COL_THREADCOUNT,
 	EMTS_COL_THREADPREVIEW,
+	EMTS_COL_UNREAD,
 	EMTS_COL_NUMBER
 } emts_col_t;
 



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