2005-01-24 [colin] 1.0.0cvs10.1
[claws.git] / src / folderview.c
index 0e133132d25b90b537c9a3749d1c0eae6e71c019..dd440f02e7766e98480dc9f6de07a3cbc31d7d06 100644 (file)
@@ -991,6 +991,51 @@ static gboolean folderview_have_unread_children(FolderView *folderview,
        return FALSE;
 }
 
+static gboolean folderview_search_matching_recursive(GtkCTree *ctree,
+                                                  GtkCTreeNode *node)
+{
+       FolderItem *item;
+
+       if (node) {
+               item = gtk_ctree_node_get_row_data(ctree, node);
+               if (item) {
+                       if (item->search_match)
+                               return TRUE;
+               }
+               node = GTK_CTREE_ROW(node)->children;
+       } else
+               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
+
+       while (node) {
+               if (folderview_search_matching_recursive(ctree, node) == TRUE)
+                       return TRUE;
+               node = GTK_CTREE_ROW(node)->sibling;
+       }
+
+       return FALSE;
+}
+
+static gboolean folderview_have_matching_children(FolderView *folderview,
+                                               GtkCTreeNode *node)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+
+       if (!node)
+               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
+       if (!node)
+               return FALSE;
+
+       node = GTK_CTREE_ROW(node)->children;
+
+       while (node) {
+               if (folderview_search_matching_recursive(ctree, node) == TRUE)
+                       return TRUE;
+               node = GTK_CTREE_ROW(node)->sibling;
+       }
+
+       return FALSE;
+}
+
 static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
@@ -1005,6 +1050,7 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        gchar *name;
        gchar *str;
        gboolean add_unread_mark;
+       gboolean add_sub_match_mark;
        gboolean use_bold, use_color;
 
        item = gtk_ctree_node_get_row_data(ctree, node);
@@ -1084,6 +1130,16 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        }
        name = folder_item_get_name(item);
 
+       if (!GTK_CTREE_ROW(node)->expanded) {
+               add_unread_mark = folderview_have_unread_children(
+                                       folderview, node);
+               add_sub_match_mark = folderview_have_matching_children(
+                                       folderview, node);
+       } else {
+               add_unread_mark = FALSE;
+               add_sub_match_mark = FALSE;
+       }
+
        if (item->search_match) {
                if (!searchicon) {
                        stock_pixmap_gdk(folderview->ctree, STOCK_PIXMAP_QUICKSEARCH,
@@ -1093,12 +1149,6 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
                mask = openmask = searchmask;
        }
 
-       if (!GTK_CTREE_ROW(node)->expanded &&
-           folderview_have_unread_children(folderview, node))
-               add_unread_mark = TRUE;
-       else
-               add_unread_mark = FALSE;
-
        if (item->stype == F_QUEUE && item->total_msgs > 0 &&
            prefs_common.display_folder_unread) {
                str = g_strdup_printf("%s (%d%s)", name, item->total_msgs,
@@ -1107,12 +1157,13 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
                                        xpm, mask, openxpm, openmask,
                                        FALSE, GTK_CTREE_ROW(node)->expanded);
                g_free(str);
-       } else if ((item->unread_msgs > 0 || add_unread_mark) &&
-                prefs_common.display_folder_unread) {
+       } else if (((item->unread_msgs > 0 || add_unread_mark) &&
+                   prefs_common.display_folder_unread) 
+                  || add_sub_match_mark) {
 
                if (item->unread_msgs > 0)
                        str = g_strdup_printf("%s (%d%s%s)", name, item->unread_msgs,
-                                             add_unread_mark ? "+" : "", 
+                                             add_unread_mark || add_sub_match_mark ? "+" : "", 
                                              item->unreadmarked_msgs > 0 ? "!":"");
                else
                        str = g_strdup_printf("%s (+)", name);