clean up a little
[claws.git] / src / folderview.c
index 66ba0b08c74aef178758676a91dda902fe6215d3..2ddca2549c821931b4f65b8a75e14bd3023ec4c7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "manage_window.h"
 #include "alertpanel.h"
 #include "menu.h"
+#include "stock_pixmap.h"
 #include "procmsg.h"
 #include "utils.h"
 #include "gtkutils.h"
 #include "prefs_common.h"
 #include "prefs_account.h"
+#include "prefs_filter.h"
 #include "account.h"
 #include "folder.h"
 #include "inc.h"
 
-#include "pixmaps/inbox.xpm"
-#include "pixmaps/outbox.xpm"
-#include "pixmaps/dir-close.xpm"
-#include "pixmaps/dir-open.xpm"
-#include "pixmaps/dir-open-hrm.xpm"
-#include "pixmaps/trash.xpm"
-
 typedef enum
 {
        COL_FOLDER      = 0,
@@ -100,18 +95,50 @@ static GtkStyle *bold_style;
 static GtkStyle *bold_color_style;
 static GtkStyle *bold_tgtfold_style;
 
-static GdkPixmap *inboxxpm;
+static GdkBitmap *inboxxpm;
 static GdkBitmap *inboxxpmmask;
+static GdkPixmap *inboxhrmxpm;
+static GdkBitmap *inboxhrmxpmmask;
+static GdkPixmap *inboxopenxpm;
+static GdkBitmap *inboxopenxpmmask;
+static GdkPixmap *inboxopenhrmxpm;
+static GdkBitmap *inboxopenhrmxpmmask;
 static GdkPixmap *outboxxpm;
 static GdkBitmap *outboxxpmmask;
+static GdkPixmap *outboxhrmxpm;
+static GdkBitmap *outboxhrmxpmmask;
+static GdkPixmap *outboxopenxpm;
+static GdkBitmap *outboxopenxpmmask;
+static GdkPixmap *outboxopenhrmxpm;
+static GdkBitmap *outboxopenhrmxpmmask;
 static GdkPixmap *folderxpm;
 static GdkBitmap *folderxpmmask;
+static GdkPixmap *folderhrmxpm;
+static GdkBitmap *folderhrmxpmmask;
 static GdkPixmap *folderopenxpm;
 static GdkBitmap *folderopenxpmmask;
 static GdkPixmap *folderopenhrmxpm;
 static GdkBitmap *folderopenhrmxpmmask;
+static GdkPixmap *trashopenxpm;
+static GdkBitmap *trashopenxpmmask;
+static GdkPixmap *trashopenhrmxpm;
+static GdkBitmap *trashopenhrmxpmmask;
 static GdkPixmap *trashxpm;
 static GdkBitmap *trashxpmmask;
+static GdkPixmap *trashhrmxpm;
+static GdkBitmap *trashhrmxpmmask;
+static GdkPixmap *queuexpm;
+static GdkBitmap *queuexpmmask;
+static GdkPixmap *queuehrmxpm;
+static GdkBitmap *queuehrmxpmmask;
+static GdkPixmap *queueopenxpm;
+static GdkBitmap *queueopenxpmmask;
+static GdkPixmap *queueopenhrmxpm;
+static GdkBitmap *queueopenhrmxpmmask;
+static GdkPixmap *newxpm;
+static GdkBitmap *newxpmmask;
+static GdkPixmap *unreadxpm;
+static GdkBitmap *unreadxpmmask;
 
 static void folderview_select_node      (FolderView    *folderview,
                                          GtkCTreeNode  *node);
@@ -162,6 +189,9 @@ static void folderview_update_tree_cb       (FolderView     *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
 
+static void mark_all_read_cb            (FolderView    *folderview,
+                                         guint           action,
+                                         GtkWidget      *widget);
 static void folderview_new_folder_cb   (FolderView     *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -244,11 +274,14 @@ static GtkItemFactoryEntry folderview_mbox_popup_entries[] =
 
 static GtkItemFactoryEntry folderview_mail_popup_entries[] =
 {
+       {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
+       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Create _new folder..."),  NULL, folderview_new_folder_cb,    0, NULL},
        {N_("/_Rename folder..."),      NULL, folderview_rename_folder_cb, 0, NULL},
        {N_("/_Delete folder"),         NULL, folderview_delete_folder_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Update folder tree"),    NULL, folderview_update_tree_cb, 0, NULL},
+       {N_("/_Check for new messages"),
+                                       NULL, folderview_update_tree_cb, 0, NULL},
        {N_("/R_escan folder tree"),    NULL, folderview_update_tree_cb, 1, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _mailbox"),        NULL, folderview_remove_mailbox_cb, 0, NULL},
@@ -261,11 +294,14 @@ static GtkItemFactoryEntry folderview_mail_popup_entries[] =
 
 static GtkItemFactoryEntry folderview_imap_popup_entries[] =
 {
+       {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
+       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Create _new folder..."),  NULL, folderview_new_imap_folder_cb, 0, NULL},
        {N_("/_Rename folder..."),      NULL, NULL, 0, NULL},
        {N_("/_Delete folder"),         NULL, folderview_rm_imap_folder_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Update folder tree"),    NULL, folderview_update_tree_cb, 0, NULL},
+       {N_("/_Check for new messages"),
+                                       NULL, folderview_update_tree_cb, 0, NULL},
        {N_("/R_escan folder tree"),    NULL, folderview_update_tree_cb, 1, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _IMAP4 account"),  NULL, folderview_rm_imap_server_cb, 0, NULL},
@@ -278,6 +314,8 @@ static GtkItemFactoryEntry folderview_imap_popup_entries[] =
 
 static GtkItemFactoryEntry folderview_news_popup_entries[] =
 {
+       {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
+       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/_Subscribe to newsgroup..."),
                                         NULL, folderview_new_news_group_cb, 0, NULL},
        {N_("/_Remove newsgroup"),       NULL, folderview_rm_news_group_cb, 0, NULL},
@@ -296,8 +334,7 @@ FolderView *folderview_create(void)
        FolderView *folderview;
        GtkWidget *scrolledwin;
        GtkWidget *ctree;
-       gchar *titles[N_FOLDER_COLS] = {_("Folder"), _("New"),
-                                       _("Unread"), _("#")};
+       gchar *titles[N_FOLDER_COLS];
        GtkWidget *mail_popup;
        GtkWidget *news_popup;
        GtkWidget *imap_popup;
@@ -312,6 +349,11 @@ FolderView *folderview_create(void)
        debug_print(_("Creating folder view...\n"));
        folderview = g_new0(FolderView, 1);
 
+       titles[COL_FOLDER] = _("Folder");
+       titles[COL_NEW]    = _("New");
+       titles[COL_UNREAD] = _("Unread");
+       titles[COL_TOTAL]  = _("#");
+
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_AUTOMATIC,
@@ -321,12 +363,15 @@ FolderView *folderview_create(void)
                             prefs_common.folderview_height);
 
        ctree = gtk_ctree_new_with_titles(N_FOLDER_COLS, COL_FOLDER, titles);
+       
        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,
@@ -413,7 +458,7 @@ FolderView *folderview_create(void)
        gtk_drag_dest_set(ctree, GTK_DEST_DEFAULT_ALL &
                          ~GTK_DEST_DEFAULT_HIGHLIGHT,
                          summary_drag_types, 1,
-                         GDK_ACTION_MOVE);
+                         GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT);
        gtk_signal_connect(GTK_OBJECT(ctree), "drag_motion",
                           GTK_SIGNAL_FUNC(folderview_drag_motion_cb),
                           folderview);
@@ -445,14 +490,56 @@ FolderView *folderview_create(void)
 void folderview_init(FolderView *folderview)
 {
        GtkWidget *ctree = folderview->ctree;
+       GtkWidget *label_new;
+       GtkWidget *label_unread;
+       GtkWidget *hbox_new;
+       GtkWidget *hbox_unread;
+
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE, &inboxxpm, &inboxxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE_HRM, &inboxhrmxpm, &inboxhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_OPEN, &inboxopenxpm, &inboxopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_OPEN_HRM, &inboxopenhrmxpm, &inboxopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_CLOSE, &outboxxpm, &outboxxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_CLOSE_HRM, &outboxhrmxpm, &outboxhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_OPEN, &outboxopenxpm, &outboxopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_OPEN_HRM, &outboxopenhrmxpm, &outboxopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_CLOSE, &folderxpm, &folderxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_CLOSE_HRM, &folderhrmxpm, &folderhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_OPEN, &folderopenxpm, &folderopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_OPEN_HRM, &folderopenhrmxpm, &folderopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_OPEN, &trashopenxpm, &trashopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_OPEN_HRM, &trashopenhrmxpm, &trashopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_CLOSE, &trashxpm, &trashxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_CLOSE_HRM, &trashhrmxpm, &trashhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_CLOSE, &queuexpm, &queuexpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_CLOSE_HRM, &queuehrmxpm, &queuehrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN, &queueopenxpm, &queueopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN_HRM, &queueopenhrmxpm, &queueopenhrmxpmmask);
+
+       /* CLAWS: titles for "New" and "Unread" show new & unread pixmaps
+        * instead text (text overflows making them unreadable and ugly) */
+        stock_pixmap_gdk(ctree, STOCK_PIXMAP_NEW,
+                        &newxpm, &newxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_UNREAD,
+                        &unreadxpm, &unreadxpmmask);
+               
+       label_new = gtk_pixmap_new(newxpm, newxpmmask);
+       label_unread = gtk_pixmap_new(unreadxpm, unreadxpmmask);
+
+       hbox_new = gtk_hbox_new(FALSE, 4);
+       hbox_unread = 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_widget_show_all(hbox_new);
+       gtk_widget_show_all(hbox_unread);
+
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_NEW,hbox_new);
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_UNREAD,hbox_unread);
+                       
 
-       PIXMAP_CREATE(ctree, inboxxpm, inboxxpmmask, inbox_xpm);
-       PIXMAP_CREATE(ctree, outboxxpm, outboxxpmmask, outbox_xpm);
-       PIXMAP_CREATE(ctree, folderxpm, folderxpmmask, dir_close_xpm);
-       PIXMAP_CREATE(ctree, folderopenxpm, folderopenxpmmask, dir_open_xpm);
-       PIXMAP_CREATE(ctree, folderopenhrmxpm, folderopenhrmxpmmask,
-                     dir_open_hrm_xpm);
-       PIXMAP_CREATE(ctree, trashxpm, trashxpmmask, trash_xpm);
 
        if (!normalfont)
                normalfont = gdk_fontset_load(NORMAL_FONT);
@@ -524,6 +611,13 @@ void folderview_select(FolderView *folderview, FolderItem *item)
                folder_update_op_count();
 }
 
+static void mark_all_read_cb(FolderView *folderview, guint action,
+                             GtkWidget *widget)
+{
+       if (folderview->selected)
+               summary_mark_all_read(folderview->summaryview);
+}
+
 static void folderview_select_node(FolderView *folderview, GtkCTreeNode *node)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
@@ -531,8 +625,8 @@ static void folderview_select_node(FolderView *folderview, GtkCTreeNode *node)
        g_return_if_fail(node != NULL);
 
        folderview->open_folder = TRUE;
-       gtk_ctree_select(ctree, node);
        gtkut_ctree_set_focus_row(ctree, node);
+       gtk_ctree_select(ctree, node);
        if (folderview->summaryview->messages > 0)
                gtk_widget_grab_focus(folderview->summaryview->ctree);
        else
@@ -588,18 +682,26 @@ void folderview_select_next_unread(FolderView *folderview)
                folderview_select_node(folderview, node);
 }
 
-void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row,
-                              gint new, gint unread, gint total)
+void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        static GtkCTreeNode *prev_row = NULL;
        FolderItem *item;
+       gint new, unread, total;
+       gchar *new_str, *unread_str, *total_str;
 
        if (!row) return;
 
        item = gtk_ctree_node_get_row_data(ctree, row);
        if (!item) return;
 
+       gtk_ctree_node_get_text(ctree, row, COL_NEW, &new_str);
+       gtk_ctree_node_get_text(ctree, row, COL_UNREAD, &unread_str);
+       gtk_ctree_node_get_text(ctree, row, COL_TOTAL, &total_str);
+       new = atoi(new_str);
+       unread = atoi(unread_str);
+       total = atoi(total_str);
+
        /* CLAWS: don't know why but this always seems to be true
         * when deleting messages. Somewhere claws does a folder
         * scan which sets all new, unread & total to the correct
@@ -609,16 +711,12 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row,
        if (prev_row     == row    &&
            item->new    == new    &&
            item->unread == unread &&
-           item->total  == total) 
+           item->total  == total)
                return;
 #endif         
 
        prev_row = row;
 
-       item->new    = new;
-       item->unread = unread;
-       item->total  = total;
-
        folderview_update_node(folderview, row);
 }
 
@@ -688,7 +786,7 @@ static GtkWidget *label_window_create(const gchar *str)
        return window;
 }
 
-void folderview_update_tree(Folder *folder)
+void folderview_rescan_tree(Folder *folder)
 {
        GtkWidget *window;
 
@@ -710,7 +808,7 @@ void folderview_update_tree(Folder *folder)
        inc_unlock();
 }
 
-void folderview_update_all(void)
+void folderview_rescan_all(void)
 {
        GList *list;
        GtkWidget *window;
@@ -734,7 +832,7 @@ void folderview_update_all(void)
        inc_unlock();
 }
 
-void folderview_update_all_node(void)
+void folderview_check_new(Folder *folder)
 {
        GList *list;
        FolderItem *item;
@@ -753,9 +851,10 @@ void folderview_update_all_node(void)
                for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
                     node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
                        item = gtk_ctree_node_get_row_data(ctree, node);
-                       if (!item || !FOLDER_IS_LOCAL(item->folder) ||
-                           !item->path)
-                               continue;
+                       if (!item || !item->path || !item->folder) continue;
+                       if (folder && folder != item->folder) continue;
+                       if (!folder && !FOLDER_IS_LOCAL(item->folder)) continue;
+
                        folderview_scan_tree_func(item->folder, item, NULL);
                        folder_item_scan(item);
                        folderview_update_node(folderview, node);
@@ -878,39 +977,82 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
 
        switch (item->stype) {
        case F_INBOX:
-               xpm = openxpm = inboxxpm;
-               mask = openmask = inboxxpmmask;
+               if (item->hide_read_msgs) {
+                       xpm = inboxhrmxpm;
+                       mask = inboxhrmxpmmask;
+                       openxpm = inboxopenhrmxpm;
+                       openmask = inboxopenhrmxpmmask;
+               } else {
+                       xpm = inboxxpm;
+                       mask = inboxxpmmask;
+                       openxpm = inboxopenxpm;
+                       openmask = inboxopenxpmmask;
+               }
                name = g_strdup(_("Inbox"));
                break;
        case F_OUTBOX:
-               xpm = openxpm = outboxxpm;
-               mask = openmask = outboxxpmmask;
+               if (item->hide_read_msgs) {
+                       xpm = outboxhrmxpm;
+                       mask = outboxhrmxpmmask;
+                       openxpm = outboxopenhrmxpm;
+                       openmask = outboxopenhrmxpmmask;
+               } else {
+                       xpm = outboxxpm;
+                       mask = outboxxpmmask;
+                       openxpm = outboxopenxpm;
+                       openmask = outboxopenxpmmask;
+               }
                name = g_strdup(_("Outbox"));
                break;
        case F_QUEUE:
-               xpm = openxpm = outboxxpm;
-               mask = openmask = outboxxpmmask;
+               if (item->hide_read_msgs) {
+                       xpm = queuehrmxpm;
+                       mask = queuehrmxpmmask;
+                       openxpm = queueopenhrmxpm;
+                       openmask = queueopenhrmxpmmask;
+               } else {
+                       xpm = queuexpm;
+                       mask = queuexpmmask;
+                       openxpm = queueopenxpm;
+                       openmask = queueopenxpmmask;
+               }
                name = g_strdup(_("Queue"));
                break;
        case F_TRASH:
-               xpm = openxpm = trashxpm;
-               mask = openmask = trashxpmmask;
+               if (item->hide_read_msgs) {
+                       xpm = trashhrmxpm;
+                       mask = trashhrmxpmmask;
+                       openxpm = trashopenhrmxpm;
+                       openmask = trashopenhrmxpmmask;
+               } else {
+                       xpm = trashxpm;
+                       mask = trashxpmmask;
+                       openxpm = trashopenxpm;
+                       openmask = trashopenxpmmask;
+               }
                name = g_strdup(_("Trash"));
                break;
        case F_DRAFT:
                xpm = folderxpm;
                mask = folderxpmmask;
-               openxpm = folderopenxpm;
-               openmask = folderopenxpmmask;
+               if (item->hide_read_msgs) {
+                       openxpm = folderopenhrmxpm;
+                       openmask = folderopenhrmxpmmask;
+               } else {
+                       openxpm = folderopenxpm;
+                       openmask = folderopenxpmmask;
+               }
                name = g_strdup(_("Draft"));
                break;
        default:
-               xpm = folderxpm;
-               mask = folderxpmmask;
                if (item->hide_read_msgs) {
+                       xpm = folderhrmxpm;
+                       mask = folderhrmxpmmask;
                        openxpm = folderopenhrmxpm;
                        openmask = folderopenhrmxpmmask;
                } else {
+                       xpm = folderxpm;
+                       mask = folderxpmmask;
                        openxpm = folderopenxpm;
                        openmask = folderopenxpmmask;
                }
@@ -1227,6 +1369,7 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        FolderItem *item;
        Folder *folder;
        GtkWidget *popup;
+       gboolean mark_all_read   = FALSE;
        gboolean new_folder      = FALSE;
        gboolean rename_folder   = FALSE;
        gboolean delete_folder   = FALSE;
@@ -1283,7 +1426,7 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                if (item->parent == NULL)
                        update_tree = remove_tree = TRUE;
                else
-                       search_folder = TRUE;
+                       mark_all_read = search_folder = TRUE;
                if (FOLDER_IS_LOCAL(folder) || FOLDER_TYPE(folder) == F_IMAP || FOLDER_TYPE(folder) == F_MBOX) {
                        if (item->parent == NULL)
                                update_tree = rescan_tree = TRUE;
@@ -1299,18 +1442,24 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                        if (item->parent != NULL)
                                delete_folder = folder_scoring = folder_processing = TRUE;
                }
+               if (item->unread < 1) 
+                       mark_all_read = FALSE;
        }
 
 #define SET_SENS(factory, name, sens) \
        menu_set_sensitive(folderview->factory, name, sens)
+       
+       mark_all_read = mark_all_read && 
+                       (item == folderview->summaryview->folder_item);
 
        if (FOLDER_IS_LOCAL(folder)) {
                popup = folderview->mail_popup;
                menu_set_insensitive_all(GTK_MENU_SHELL(popup));
+               SET_SENS(mail_factory, "/Mark all read", mark_all_read);
                SET_SENS(mail_factory, "/Create new folder...", new_folder);
                SET_SENS(mail_factory, "/Rename folder...", rename_folder);
                SET_SENS(mail_factory, "/Delete folder", delete_folder);
-               SET_SENS(mail_factory, "/Update folder tree", update_tree);
+               SET_SENS(mail_factory, "/Check for new messages", update_tree);
                SET_SENS(mail_factory, "/Rescan folder tree", rescan_tree);
                SET_SENS(mail_factory, "/Remove mailbox", remove_tree);
                SET_SENS(mail_factory, "/Property...", folder_property);
@@ -1320,10 +1469,11 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        } else if (FOLDER_TYPE(folder) == F_IMAP) {
                popup = folderview->imap_popup;
                menu_set_insensitive_all(GTK_MENU_SHELL(popup));
+               SET_SENS(imap_factory, "/Mark all read", mark_all_read);
                SET_SENS(imap_factory, "/Create new folder...", new_folder);
                SET_SENS(imap_factory, "/Rename folder...", rename_folder);
                SET_SENS(imap_factory, "/Delete folder", delete_folder);
-               SET_SENS(imap_factory, "/Update folder tree", update_tree);
+               SET_SENS(imap_factory, "/Check for new messages", update_tree);
                SET_SENS(imap_factory, "/Rescan folder tree", rescan_tree);
                SET_SENS(imap_factory, "/Remove IMAP4 account", remove_tree);
                SET_SENS(imap_factory, "/Processing...", folder_processing);
@@ -1332,8 +1482,12 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        } else if (FOLDER_TYPE(folder) == F_NEWS) {
                popup = folderview->news_popup;
                menu_set_insensitive_all(GTK_MENU_SHELL(popup));
+               SET_SENS(news_factory, "/Mark all read", mark_all_read);
                SET_SENS(news_factory, "/Subscribe to newsgroup...", new_folder);
                SET_SENS(news_factory, "/Remove newsgroup", delete_folder);
+#if 0
+               SET_SENS(news_factory, "/Check for new messages", update_tree);
+#endif
                SET_SENS(news_factory, "/Remove news account", remove_tree);
                SET_SENS(news_factory, "/Search folder...", search_folder);
                SET_SENS(news_factory, "/Processing...", folder_processing);
@@ -1362,15 +1516,12 @@ static void folderview_button_released(GtkWidget *ctree, GdkEventButton *event,
 
        if (event->button == 1 && folderview->open_folder == FALSE &&
            folderview->opened != NULL) {
-               gtk_ctree_select(GTK_CTREE(ctree), folderview->opened);
                gtkut_ctree_set_focus_row(GTK_CTREE(ctree),
                                          folderview->opened);
+               gtk_ctree_select(GTK_CTREE(ctree), folderview->opened);
        }
 }
 
-#define BREAK_ON_MODIFIER_KEY() \
-       if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
-
 static void folderview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                   FolderView *folderview)
 {
@@ -1378,24 +1529,23 @@ static void folderview_key_pressed(GtkWidget *widget, GdkEventKey *event,
 
        switch (event->keyval) {
        case GDK_Return:
-       case GDK_space:
                if (folderview->selected) {
                        folderview_select_node(folderview,
                                               folderview->selected);
                }
                break;
-       case GDK_v:
-       case GDK_V:
-       case GDK_g:
-       case GDK_G:
-       case GDK_x:
-       case GDK_X:
-       case GDK_w:
-       case GDK_D:
-       case GDK_Q:
-               BREAK_ON_MODIFIER_KEY();
-               summary_pass_key_press_event(folderview->summaryview, event);
+       case GDK_space:
+               if (folderview->selected) {
+                       if (folderview->opened == folderview->selected &&
+                           folderview->summaryview->messages == 0)
+                               folderview_select_next_unread(folderview);
+                       else
+                               folderview_select_node(folderview,
+                                                      folderview->selected);
+               }
+               break;
        default:
+               break;
        }
 }
 
@@ -1414,8 +1564,8 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
        }
 
        if (!can_select) {
-               gtk_ctree_select(ctree, folderview->opened);
                gtkut_ctree_set_focus_row(ctree, folderview->opened);
+               gtk_ctree_select(ctree, folderview->opened);
                return;
        }
 
@@ -1453,10 +1603,14 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
        opened = summary_show(folderview->summaryview, item, FALSE);
 
        if (!opened) {
-               gtk_ctree_select(ctree, folderview->opened);
                gtkut_ctree_set_focus_row(ctree, folderview->opened);
-       } else
+               gtk_ctree_select(ctree, folderview->opened);
+       } else {
                folderview->opened = row;
+               if (gtk_ctree_node_is_visible(ctree, row)
+                   != GTK_VISIBILITY_FULL)
+                       gtk_ctree_node_moveto(ctree, row, -1, 0.5, 0);
+       }
 
        folderview->open_folder = FALSE;
        can_select = TRUE;
@@ -1489,9 +1643,9 @@ static void folderview_popup_close(GtkMenuShell *menu_shell,
 {
        if (!folderview->opened) return;
 
-       gtk_ctree_select(GTK_CTREE(folderview->ctree), folderview->opened);
        gtkut_ctree_set_focus_row(GTK_CTREE(folderview->ctree),
                                  folderview->opened);
+       gtk_ctree_select(GTK_CTREE(folderview->ctree), folderview->opened);
 }
 
 static void folderview_col_resized(GtkCList *clist, gint column, gint width,
@@ -1511,6 +1665,7 @@ static void folderview_col_resized(GtkCList *clist, gint column, gint width,
                prefs_common.folder_col_total = width;
                break;
        default:
+               break;
        }
 }
 
@@ -1552,9 +1707,9 @@ static void folderview_update_tree_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->folder != NULL);
 
        if (action == 0)
-               folderview_update_all_node();
+               folderview_check_new(item->folder);
        else
-               folderview_update_tree(item->folder);
+               folderview_rescan_tree(item->folder);
 }
 
 static void folderview_new_folder_cb(FolderView *folderview, guint action,
@@ -1678,6 +1833,8 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        FolderItem *item;
        gchar *new_folder;
        gchar *message;
+       gchar *old_path;
+       gchar *new_path;
 
        if (!folderview->selected) return;
 
@@ -1709,12 +1866,30 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
                return;
        }
 
+       Xstrdup_a(old_path, item->path, {g_free(new_folder); return;});
+
        if (item->folder->rename_folder(item->folder, item, new_folder) < 0) {
                g_free(new_folder);
                return;
        }
+
+       if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
+               gchar *dirname;
+               dirname = g_dirname(item->path);
+               new_path = g_strconcat(dirname, G_DIR_SEPARATOR_S, new_folder, NULL);
+               g_free(dirname);
+       } else
+               new_path = g_strdup(new_folder);
+
        g_free(new_folder);
 
+       prefs_filter_rename_path(old_path, new_path);
+
+       if (FOLDER_TYPE(item->folder) == F_MH)
+               prefs_filtering_rename_path(old_path, new_path);
+
+       g_free(new_path);
+
        gtk_clist_freeze(GTK_CLIST(ctree));
 
        folderview_update_node(folderview, folderview->selected);
@@ -1794,6 +1969,7 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
        FolderItem *item;
        gchar *message;
        AlertValue avalue;
+       gchar *old_path;
 
        if (!folderview->selected) return;
 
@@ -1811,12 +1987,19 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
        g_free(message);
        if (avalue != G_ALERTDEFAULT) return;
 
+       Xstrdup_a(old_path, item->path, return);
+
        if (item->folder->remove_folder(item->folder, item) < 0) {
                alertpanel_error(_("Can't remove the folder `%s'."),
                                 item->path);
                return;
        }
 
+       prefs_filter_delete_path(old_path);
+
+       if (FOLDER_TYPE(item->folder) == F_MH)
+               prefs_filtering_delete_path(old_path);
+
        if (folderview->opened == folderview->selected ||
            gtk_ctree_is_ancestor(ctree,
                                  folderview->selected,
@@ -2052,7 +2235,7 @@ static void folderview_new_news_group_cb(FolderView *folderview, guint action,
                GNode *next = gnode->next;
 
                item = FOLDER_ITEM(gnode->data);
-               if (g_slist_find_custom(new_subscr, item->name,
+               if (g_slist_find_custom(new_subscr, item->path,
                                        (GCompareFunc)g_strcasecmp) != NULL) {
                        gnode = next;
                        continue;
@@ -2193,36 +2376,39 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                                          FolderView     *folderview)
 {
        gint row, column;
-       FolderItem *item, *current_item;
+       FolderItem *item, *src_item;
        GtkCTreeNode *node = NULL;
        gboolean acceptable = FALSE;
 
-       if (gtk_clist_get_selection_info(GTK_CLIST(widget),
-                                        x - 24, y - 24, &row, &column)) {
+       if (gtk_clist_get_selection_info
+               (GTK_CLIST(widget), x - 24, y - 24, &row, &column)) {
                node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
                item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
-               current_item = folderview->summaryview->folder_item;
-               if (item != NULL &&
-                   item->path != NULL &&
-                   current_item != NULL &&
-                   current_item != item) {
-                       switch (item->folder->type){
+               src_item = folderview->summaryview->folder_item;
+               if (item && item->folder && item->path &&
+                   src_item && src_item != item) {
+                       switch (item->folder->type) {
                        case F_MH:
-                               if (current_item->folder->type == F_MH)
-                                   acceptable = TRUE;
-                               break;
                        case F_IMAP:
-                               if (current_item->folder->account == item->folder->account)
-                                   acceptable = TRUE;
+                               acceptable = TRUE;
                                break;
                        default:
+                               break;
                        }
                }
        }
 
        if (acceptable) {
+               gtk_signal_handler_block_by_func
+                       (GTK_OBJECT(widget),
+                        GTK_SIGNAL_FUNC(folderview_selected), folderview);
                gtk_ctree_select(GTK_CTREE(widget), node);
-               gdk_drag_status(context, context->suggested_action, time);
+               gtk_signal_handler_unblock_by_func
+                       (GTK_OBJECT(widget),
+                        GTK_SIGNAL_FUNC(folderview_selected), folderview);
+               gdk_drag_status(context, 
+                                       (context->actions == GDK_ACTION_COPY ?
+                                       GDK_ACTION_COPY : GDK_ACTION_MOVE) , time);
        } else {
                gtk_ctree_select(GTK_CTREE(widget), folderview->opened);
                gdk_drag_status(context, 0, time);
@@ -2249,18 +2435,33 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                                        FolderView       *folderview)
 {
        gint row, column;
-       FolderItem *item;
+       FolderItem *item, *src_item;
        GtkCTreeNode *node;
 
-       if (gtk_clist_get_selection_info(GTK_CLIST(widget),
-                                        x - 24, y - 24, &row, &column) == 0)
+       if (gtk_clist_get_selection_info
+               (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0)
                return;
 
        node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
        item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
-       if (item != NULL) {
-               summary_move_selected_to(folderview->summaryview, item);
+       src_item = folderview->summaryview->folder_item;
+       if (item && src_item) {
+               switch (drag_context->action) {
+                       case GDK_ACTION_COPY:
+                               summary_copy_selected_to(folderview->summaryview, item);
+                               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+                               break;
+                       case GDK_ACTION_MOVE:
+                       case GDK_ACTION_DEFAULT:
+                       default:
+               if (src_item->folder->type != item->folder->type ||
+                   (item->folder->type == F_IMAP &&
+                    src_item->folder != item->folder))
+                       summary_copy_selected_to(folderview->summaryview, item);
+               else
+                       summary_move_selected_to(folderview->summaryview, item);
                gtk_drag_finish(drag_context, TRUE, TRUE, time);
+               }
        } else
                gtk_drag_finish(drag_context, FALSE, FALSE, time);
 }
@@ -2304,7 +2505,9 @@ static void folderview_processing_cb(FolderView *folderview, guint action,
        prefs_filtering_open(item);
 }
 
-static void folderview_property_cb(FolderView *folderview, guint action, GtkWidget *widget) {
+static void folderview_property_cb(FolderView *folderview, guint action, 
+                                  GtkWidget *widget) 
+{
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
 
@@ -2314,10 +2517,11 @@ static void folderview_property_cb(FolderView *folderview, guint action, GtkWidg
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       prefs_folder_item_create(item);
+       prefs_folder_item_create(folderview, item);
 }
 
-void folderview_set_target_folder_color(gint color_op) {
+void folderview_set_target_folder_color(gint color_op) 
+{
        gint firstone = 1;
        GList *list;
        FolderView *folderview;
@@ -2332,3 +2536,9 @@ void folderview_set_target_folder_color(gint color_op) {
                }
        }
 }
+
+void folderview_reflect_prefs_pixmap_theme(FolderView *folderview)
+{
+       folderview_init(folderview);
+       folderview_set_all();
+}