2005-01-24 [colin] 1.0.0cvs10.1
[claws.git] / src / folderview.c
index ef8161e82291f4c28ca24bc6a7b302b69060465d..dd440f02e7766e98480dc9f6de07a3cbc31d7d06 100644 (file)
@@ -62,6 +62,7 @@
 #include "statusbar.h"
 #include "hooks.h"
 #include "folderutils.h"
+#include "partial_download.h"
 
 typedef enum
 {
@@ -127,6 +128,8 @@ static GdkPixmap *newxpm;
 static GdkBitmap *newxpmmask;
 static GdkPixmap *unreadxpm;
 static GdkBitmap *unreadxpmmask;
+static GdkPixmap *readxpm;
+static GdkBitmap *readxpmmask;
 static GdkPixmap *draftsxpm;
 static GdkBitmap *draftsxpmmask;
 static GdkPixmap *draftsopenxpm;
@@ -178,6 +181,10 @@ static void mark_all_read_cb            (FolderView    *folderview,
                                          guint           action,
                                          GtkWidget      *widget);
 
+static void folderview_empty_trash_cb  (FolderView     *folderview,
+                                        guint           action,
+                                        GtkWidget      *widget);
+
 static void folderview_search_cb       (FolderView     *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -232,9 +239,15 @@ static GtkItemFactoryEntry folderview_common_popup_entries[] =
        {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
        {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
-       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
+       {N_("/Pr_ocessing..."),         NULL, folderview_processing_cb, 0, NULL},
 };
 
+static GtkItemFactoryEntry folder_view_trash_popup_entries[] = {
+       {N_("/------"),                 NULL, NULL, 0, "<Separator>"},
+       {N_("/Empty trash..."),         NULL, folderview_empty_trash_cb, 0, NULL},
+};
+
+
 GtkTargetEntry folderview_drag_types[] =
 {
        {"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
@@ -328,12 +341,10 @@ FolderView *folderview_create(void)
        
        gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
        gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
-#ifndef CLAWS /* text instead of pixmaps */
        gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_NEW,
                                           GTK_JUSTIFY_RIGHT);
        gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_UNREAD,
                                           GTK_JUSTIFY_RIGHT);
-#endif                                    
        gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_TOTAL,
                                           GTK_JUSTIFY_RIGHT);
        gtk_clist_set_column_width(GTK_CLIST(ctree), COL_FOLDER,
@@ -426,9 +437,11 @@ void folderview_init(FolderView *folderview)
        GtkWidget *ctree = folderview->ctree;
        GtkWidget *label_new;
        GtkWidget *label_unread;
+       GtkWidget *label_total;
        GtkWidget *hbox_new;
        GtkWidget *hbox_unread;
-       
+       GtkWidget *hbox_total;
+               
        gtk_widget_realize(ctree);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE, &inboxxpm, &inboxxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE_HRM, &inboxhrmxpm, &inboxhrmxpmmask);
@@ -459,22 +472,32 @@ void folderview_init(FolderView *folderview)
                         &newxpm, &newxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_UNREAD,
                         &unreadxpm, &unreadxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_READ,
+                        &readxpm, &readxpmmask);
                
        label_new = gtk_pixmap_new(newxpm, newxpmmask);
        label_unread = gtk_pixmap_new(unreadxpm, unreadxpmmask);
+       label_total = gtk_pixmap_new(readxpm, readxpmmask);
 
        hbox_new = gtk_hbox_new(FALSE, 4);
        hbox_unread = gtk_hbox_new(FALSE, 4);
+       hbox_total = gtk_hbox_new(FALSE, 4);
 
        /* left justified */
-       gtk_box_pack_start(GTK_BOX(hbox_new),label_new,FALSE,FALSE,0);
-       gtk_box_pack_start(GTK_BOX(hbox_unread),label_unread,FALSE,FALSE,0);
+       gtk_box_pack_start(GTK_BOX(hbox_new), label_new, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_new), 1, 0.5);
+       gtk_box_pack_start(GTK_BOX(hbox_unread), label_unread, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_unread), 1, 0.5);
+       gtk_box_pack_start(GTK_BOX(hbox_total), label_total, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_total), 1, 0.5);
 
        gtk_widget_show_all(hbox_new);
        gtk_widget_show_all(hbox_unread);
+       gtk_widget_show_all(hbox_total);
 
        gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_NEW,hbox_new);
        gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_UNREAD,hbox_unread);
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_TOTAL,hbox_total);
                        
        if (!normal_style) {
                PangoFontDescription *font_desc;
@@ -563,7 +586,7 @@ static void mark_all_read_cb(FolderView *folderview, guint action,
 {
        FolderItem *item;
 
-       item = folderview_get_selected(folderview);
+       item = folderview_get_selected_item(folderview);
        if (item == NULL)
                return;
 
@@ -635,6 +658,14 @@ void folderview_select_next_unread(FolderView *folderview)
                folderview_select_node(folderview, node);
 }
 
+FolderItem *folderview_get_selected_item(FolderView *folderview)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+
+       if (!folderview->selected) return NULL;
+       return gtk_ctree_node_get_row_data(ctree, folderview->selected);
+}
+
 void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
@@ -960,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);
@@ -968,9 +1044,13 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        FolderItem *item;
        GdkPixmap *xpm, *openxpm;
        GdkBitmap *mask, *openmask;
+       static GdkPixmap *searchicon;
+       static GdkBitmap *searchmask;
+
        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);
@@ -1050,11 +1130,24 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        }
        name = folder_item_get_name(item);
 
-       if (!GTK_CTREE_ROW(node)->expanded &&
-           folderview_have_unread_children(folderview, node))
-               add_unread_mark = TRUE;
-       else
+       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,
+                        &searchicon, &searchmask);
+               }
+               xpm = openxpm = searchicon;
+               mask = openmask = searchmask;
+       }
 
        if (item->stype == F_QUEUE && item->total_msgs > 0 &&
            prefs_common.display_folder_unread) {
@@ -1064,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);
@@ -1179,6 +1273,27 @@ void folderview_update_item(FolderItem *item, gboolean update_summary)
 }
 #endif
 
+void folderview_update_search_icon(FolderItem *item, gboolean matches)
+{
+       GList *list;
+       FolderView *folderview;
+       GtkCTree *ctree;
+       GtkCTreeNode *node;
+
+       g_return_if_fail(item != NULL);
+
+       for (list = folderview_list; list != NULL; list = list->next) {
+               folderview = (FolderView *)list->data;
+               ctree = GTK_CTREE(folderview->ctree);
+
+               node = gtk_ctree_find_by_row_data(ctree, NULL, item);
+               if (node) {
+                       item->search_match = matches;
+                       folderview_update_node(folderview, node);
+               }
+       }
+}
+
 gboolean folderview_update_item_claws(gpointer source, gpointer data)
 {
        FolderItemUpdateData *update_info = (FolderItemUpdateData *)source;
@@ -1383,15 +1498,25 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        if (fpopup->set_sensitivity != NULL)
                fpopup->set_sensitivity(fpopup_factory, item);
 
+       if (item == folder->trash &&
+           gtk_item_factory_get_item(fpopup_factory, "/Empty trash...") == NULL) {
+               gtk_item_factory_create_item(fpopup_factory, &folder_view_trash_popup_entries[0], folderview, 1);
+               gtk_item_factory_create_item(fpopup_factory, &folder_view_trash_popup_entries[1], folderview, 1);
+       } else if (item != folder->trash) {
+               gtk_item_factory_delete_entry(fpopup_factory, &folder_view_trash_popup_entries[0]);
+               gtk_item_factory_delete_entry(fpopup_factory, &folder_view_trash_popup_entries[1]);
+       }
+       
 #define SET_SENS(name, sens) \
        menu_set_sensitive(fpopup_factory, name, sens)
 
        SET_SENS("/Mark all read", item->unread_msgs >= 1);
        SET_SENS("/Search folder...", item->total_msgs >= 1 && 
                 folderview->selected == folderview->opened);
-       SET_SENS("/Properties...", TRUE);
+       SET_SENS("/Properties...", item->node->parent != NULL);
        SET_SENS("/Processing...", item->node->parent != NULL);
-
+       if (item == folder->trash)
+               SET_SENS("/Empty trash...", folder_item_get_msg_list(item) != NULL);
 #undef SET_SENS
 
        popup = gtk_item_factory_get_widget(fpopup_factory, fpopup->path);
@@ -1657,6 +1782,38 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        gtk_clist_thaw(GTK_CLIST(ctree));
 }
 
+static void folderview_empty_trash_cb(FolderView *folderview, guint action,
+                                     GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       GSList *mlist = NULL;
+       GSList *cur = NULL;
+       if (!folderview->selected) return;
+       
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       if (item != item->folder->trash) return;
+       
+       if (prefs_common.ask_on_clean) {
+               if (alertpanel(_("Empty trash"),
+                              _("Empty all messages in trash?"),
+                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                       return;
+       }
+       
+       mlist = folder_item_get_msg_list(item);
+       
+       for (cur = mlist ; cur != NULL ; cur = cur->next) {
+               MsgInfo * msginfo = (MsgInfo *) cur->data;
+               partial_mark_for_delete(msginfo);
+               procmsg_msginfo_free(msginfo);
+       }
+
+       folder_item_remove_all_msg(item);
+}
+
 static void folderview_search_cb(FolderView *folderview, guint action,
                                 GtkWidget *widget)
 {
@@ -1675,11 +1832,10 @@ static void folderview_property_cb(FolderView *folderview, guint action,
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       if (folder_item_parent(item) == NULL && item->folder->account)
-               account_open(item->folder->account);
-       else {
-               prefs_folder_item_open(item);
-       }
+       if (folder_item_parent(item) == NULL)
+               return;
+
+       prefs_folder_item_open(item);
 }
 
 static void folderview_recollapse_nodes(FolderView *folderview, GtkCTreeNode *node)
@@ -1774,7 +1930,7 @@ static gint folderview_clist_compare(GtkCList *clist,
        if (!item2->name)
                return -1;
 
-       return g_strcasecmp(item1->name, item2->name);
+       return g_utf8_collate(item1->name, item2->name);
 }
 
 static void folderview_processing_cb(FolderView *folderview, guint action,
@@ -2087,12 +2243,6 @@ static void folderview_drag_end_cb(GtkWidget         *widget,
        folderview->nodes_to_recollapse = NULL;
 }
 
-FolderItem *folderview_get_selected(FolderView *folderview)
-{
-       return (FolderItem *) gtk_ctree_node_get_row_data(
-               GTK_CTREE(folderview->ctree), folderview->selected);
-}
-
 void folderview_register_popup(FolderViewPopup *fpopup)
 {
        GList *folderviews;