highlight queue if there are msgs in its sub-folders and the tree is collapsed
[claws.git] / src / folderview.c
index 209c6176c29a7be40887a73fefd81c5fc4869fc1..d9d3a754f0e5a8138f905701648bb306ddb8c444 100644 (file)
@@ -620,6 +620,7 @@ void folderview_init(FolderView *folderview)
 {
        GtkWidget *ctree = folderview->ctree;
        GdkColor gdk_color;
+       PangoFontDescription *normal_font;
 
        stock_pixbuf_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE, &inboxxpm);
        stock_pixbuf_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE_HRM, &inboxhrmxpm);
@@ -667,7 +668,14 @@ void folderview_init(FolderView *folderview)
        stock_pixbuf_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN_HRM_MARK, &m_queueopenhrmxpm);
        stock_pixbuf_gdk(ctree, STOCK_PIXMAP_DRAFTS_CLOSE_MARK, &m_draftsxpm);
        stock_pixbuf_gdk(ctree, STOCK_PIXMAP_DRAFTS_OPEN_MARK, &m_draftsopenxpm);
-                       
+
+       normal_font = pango_font_description_from_string(NORMAL_FONT);
+       if (normal_font) {
+               gtk_widget_modify_font(ctree, normal_font);
+               pango_font_description_free(normal_font);
+       }
+       gtk_cmclist_set_row_height(GTK_CMCLIST(ctree), 0);
+
        if (!normal_style) {
                PangoFontDescription *font_desc;
                normal_style = gtk_style_copy(gtk_widget_get_style(ctree));
@@ -687,6 +695,12 @@ void folderview_init(FolderView *folderview)
                gtkut_convert_int_to_gdk_color(prefs_common.color_new, &gdk_color);
                bold_style = gtk_style_copy(gtk_widget_get_style(ctree));
                if (prefs_common.derive_from_normal_font || !BOLD_FONT) {
+                       PangoFontDescription *font_desc;
+                       font_desc = pango_font_description_from_string(NORMAL_FONT);
+                       if (font_desc) {
+                               pango_font_description_free(bold_style->font_desc);
+                               bold_style->font_desc = font_desc;
+                       }
                        pango_font_description_set_weight
                                (bold_style->font_desc, PANGO_WEIGHT_BOLD);
                } else {
@@ -878,6 +892,8 @@ static GtkCMCTreeNode *folderview_find_next_with_flag(GtkCMCTree *ctree,
 
        for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
                item = gtk_cmctree_node_get_row_data(ctree, node);
+               if (!item)
+                       continue;
                if (item->stype == F_TRASH || item->stype == F_DRAFT)
                        continue;
                switch (flag) {
@@ -1173,6 +1189,43 @@ void folderview_check_new_all(void)
        inc_unlock();
 }
 
+static gboolean folderview_have_children_sub(FolderView *folderview,
+                                            FolderItem *item,
+                                            gboolean in_sub)
+{
+       GNode *node = NULL;
+       
+       if (!item || !item->folder || !item->folder->node)
+               return FALSE;
+               
+       node = item->folder->node;
+       
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
+
+       if (in_sub && item->total_msgs > 0) {
+               return TRUE;
+       }
+
+       while (node != NULL) {
+               if (node && node->data) {
+                       FolderItem *next_item = (FolderItem*) node->data;
+                       node = node->next;
+                       if (folderview_have_children_sub(folderview, 
+                                                        next_item, TRUE))
+                               return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+static gboolean folderview_have_children(FolderView *folderview,
+                                        FolderItem *item)
+{
+       return folderview_have_children_sub(folderview, item, FALSE);
+}
+
 static gboolean folderview_have_new_children_sub(FolderView *folderview,
                                                 FolderItem *item,
                                                 gboolean in_sub)
@@ -1524,6 +1577,10 @@ static void folderview_update_node(FolderView *folderview, GtkCMCTreeNode *node)
                                break;
                        }
                }
+               if (!GTK_CMCTREE_ROW(node)->expanded &&
+                   use_bold == FALSE &&
+                   folderview_have_children(folderview, item))
+                       use_bold = use_color = TRUE;
                procmsg_msg_list_free(list);
        } else {
                /* if unread messages exist, print with bold font */
@@ -1676,7 +1733,7 @@ static void set_special_folder(GtkCMCTree *ctree, FolderItem *item,
 
                                tmp = gtk_cmctree_node_get_row_data
                                        (ctree, sibling);
-                               if (tmp->stype != F_NORMAL)
+                               if (tmp && tmp->stype != F_NORMAL)
                                        sibling = GTK_CMCTREE_ROW(sibling)->sibling;
                                else
                                        break;
@@ -2656,22 +2713,21 @@ static void folderview_drag_data_get(GtkWidget        *widget,
                                     FolderView       *folderview)
 {
        FolderItem *item;
-       GList *cur;
+       GList *sel;
        gchar *source = NULL;
        if (info == TARGET_DUMMY) {
-               for (cur = GTK_CMCLIST(folderview->ctree)->selection;
-                    cur != NULL; cur = cur->next) {
-                       item = gtk_cmctree_node_get_row_data
-                               (GTK_CMCTREE(folderview->ctree), 
-                                GTK_CMCTREE_NODE(cur->data));
-                       if (item) {
-                               source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item));
-                               gtk_selection_data_set(selection_data,
-                                                      gtk_selection_data_get_target(selection_data), 8,
-                                                      source, strlen(source));
-                               break;
-                       } else
-                               return;
+               sel = GTK_CMCLIST(folderview->ctree)->selection;
+               if (!sel)
+                       return;
+
+               item = gtk_cmctree_node_get_row_data
+                       (GTK_CMCTREE(folderview->ctree),
+                        GTK_CMCTREE_NODE(sel->data));
+               if (item) {
+                       source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item));
+                       gtk_selection_data_set(selection_data,
+                                              gtk_selection_data_get_target(selection_data), 8,
+                                              source, strlen(source));
                }
        } else {
                g_warning("unknown info %d\n", info);
@@ -2709,6 +2765,8 @@ static gboolean folderview_update_folder(gpointer source, gpointer userdata)
                        if (folderview->opened == node)
                                folderview->opened = NULL;
                }
+       } else if (hookdata->update_flags & FOLDER_MOVE_FOLDERITEM) {
+               /* do nothing, it's done by the ADD and REMOVE) */
        } else if (hookdata->update_flags & (FOLDER_TREE_CHANGED | FOLDER_ADD_FOLDER | FOLDER_REMOVE_FOLDER))
                folderview_set(folderview);