2005-08-30 [colin] 1.9.13cvs72
[claws.git] / src / folderview.c
index c3ef2409383f63b817b728a1a3a420f53032cda7..a7e715be3e07f84734a836d49fceefa475e39d49 100644 (file)
 #include "hooks.h"
 #include "folderutils.h"
 #include "partial_download.h"
+#include "prefs_folder_column.h"
 
-typedef enum
-{
-       COL_FOLDER      = 0,
-       COL_NEW         = 1,
-       COL_UNREAD      = 2,
-       COL_TOTAL       = 3
-} FolderColumnPos;
-
-#define N_FOLDER_COLS          4
 #define COL_FOLDER_WIDTH       150
 #define COL_NUM_WIDTH          32
 
@@ -361,64 +353,111 @@ static void create_ifactories(gpointer key, gpointer value, gpointer data)
        g_hash_table_insert(folderview->popups, fpopup->klass, factory);
 }
 
-FolderView *folderview_create(void)
+static void folderview_column_set_titles(FolderView *folderview)
+{
+       GtkWidget *ctree = folderview->ctree;
+       GtkWidget *label_new;
+       GtkWidget *label_unread;
+       GtkWidget *label_total;
+       GtkWidget *hbox_new;
+       GtkWidget *hbox_unread;
+       GtkWidget *hbox_total;
+       gint *col_pos = folderview->col_pos;
+       
+       debug_print("setting titles...\n");
+       gtk_widget_realize(folderview->ctree);
+       gtk_widget_show_all(folderview->scrolledwin);
+       
+       /* 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);
+       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, 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_pos[F_COL_NEW],hbox_new);
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_UNREAD],hbox_unread);
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_TOTAL],hbox_total);
+}
+
+GtkWidget *folderview_ctree_create(FolderView *folderview)
 {
-       FolderView *folderview;
-       GtkWidget *scrolledwin;
        GtkWidget *ctree;
+       gint *col_pos;
+       FolderColumnState *col_state;
+       FolderColumnType type;
        gchar *titles[N_FOLDER_COLS];
        gint i;
+       GtkWidget *scrolledwin = folderview->scrolledwin;
 
-       debug_print("Creating folder view...\n");
-       folderview = g_new0(FolderView, 1);
+       debug_print("creating tree...\n");
+       memset(titles, 0, sizeof(titles));
 
-       titles[COL_FOLDER] = _("Folder");
-       titles[COL_NEW]    = _("New");
-       titles[COL_UNREAD] = _("Unread");
-       titles[COL_TOTAL]  = _("#");
+       col_state = prefs_folder_column_get_config();
+       memset(titles, 0, sizeof(titles));
 
-       scrolledwin = gtk_scrolled_window_new(NULL, NULL);
-       gtk_scrolled_window_set_policy
-               (GTK_SCROLLED_WINDOW(scrolledwin),
-                GTK_POLICY_AUTOMATIC,
-                prefs_common.folderview_vscrollbar_policy);
-       gtk_widget_set_size_request(scrolledwin,
-                            prefs_common.folderview_width,
-                            prefs_common.folderview_height);
+       col_pos = folderview->col_pos;
+
+       for (i = 0; i < N_FOLDER_COLS; i++) {
+               folderview->col_state[i] = col_state[i];
+               type = col_state[i].type;
+               col_pos[type] = i;
+       }
 
-       ctree = gtk_sctree_new_with_titles(N_FOLDER_COLS, COL_FOLDER, titles);
+       titles[col_pos[F_COL_FOLDER]] = _("Folder");
+       titles[col_pos[F_COL_NEW]]    = _("New");
+       titles[col_pos[F_COL_UNREAD]] = _("Unread");
+       titles[col_pos[F_COL_TOTAL]]  = _("#");
+
+       ctree = gtk_sctree_new_with_titles(N_FOLDER_COLS, col_pos[F_COL_FOLDER],
+                                          titles);
        
-       gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
        gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
-       gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_NEW,
+       gtk_clist_set_column_justification(GTK_CLIST(ctree), col_pos[F_COL_NEW],
                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_UNREAD,
+       gtk_clist_set_column_justification(GTK_CLIST(ctree),
+                                          col_pos[F_COL_UNREAD],
                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_TOTAL,
+       gtk_clist_set_column_justification(GTK_CLIST(ctree), 
+                                          col_pos[F_COL_TOTAL],
                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_FOLDER,
-                                  prefs_common.folder_col_folder);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_NEW,
-                                  prefs_common.folder_col_new);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_UNREAD,        
-                                  prefs_common.folder_col_unread);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_TOTAL,
-                                  prefs_common.folder_col_total);
        gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_DOTTED);
        gtk_ctree_set_expander_style(GTK_CTREE(ctree),
                                     GTK_CTREE_EXPANDER_SQUARE);
        gtk_ctree_set_indent(GTK_CTREE(ctree), CTREE_INDENT);
        gtk_clist_set_compare_func(GTK_CLIST(ctree), folderview_clist_compare);
 
-       /* create popup factories */
-       folderview->popups = g_hash_table_new(g_str_hash, g_str_equal);
-       g_hash_table_foreach(folderview_popups, create_ifactories, folderview);
-
        /* don't let title buttons take key focus */
-       for (i = 0; i < N_FOLDER_COLS; i++)
+       for (i = 0; i < N_FOLDER_COLS; i++) {
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
                                       GTK_CAN_FOCUS);
-
+               gtk_clist_set_column_width(GTK_CLIST(ctree), col_pos[i],
+                                  prefs_common.folder_col_size[i]);
+               gtk_clist_set_column_visibility
+                       (GTK_CLIST(ctree), i, col_state[i].visible);
+       }
 
        g_signal_connect(G_OBJECT(ctree), "key_press_event",
                         G_CALLBACK(folderview_key_pressed),
@@ -465,7 +504,58 @@ FolderView *folderview_create(void)
                         G_CALLBACK(folderview_drag_end_cb),
                         folderview);
 
+       gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
+
+       return ctree;
+}
+
+void folderview_set_column_order(FolderView *folderview)
+{
+       GtkWidget *ctree;
+       FolderItem *item = folderview_get_selected_item(folderview);
+       GtkWidget *scrolledwin = folderview->scrolledwin;
+
+       debug_print("recreating tree...\n");
+       gtk_widget_destroy(folderview->ctree);
+
+       folderview->ctree = ctree = folderview_ctree_create(folderview);
+       gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
+                                           GTK_CLIST(ctree)->hadjustment);
+       gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
+                                           GTK_CLIST(ctree)->vadjustment);
+       gtk_widget_show(ctree);
+       
+       folderview_set(folderview);
+       folderview_column_set_titles(folderview);
+
+       folderview_select(folderview,item);
+}
+
+FolderView *folderview_create(void)
+{
+       FolderView *folderview;
+       GtkWidget *scrolledwin;
+       GtkWidget *ctree;
+
+       debug_print("Creating folder view...\n");
+       folderview = g_new0(FolderView, 1);
+
+       scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy
+               (GTK_SCROLLED_WINDOW(scrolledwin),
+                GTK_POLICY_AUTOMATIC,
+                prefs_common.folderview_vscrollbar_policy);
+       gtk_widget_set_size_request(scrolledwin,
+                            prefs_common.folderview_width,
+                            prefs_common.folderview_height);
+
        folderview->scrolledwin  = scrolledwin;
+       ctree = folderview_ctree_create(folderview);
+       
+       /* create popup factories */
+       folderview->popups = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_foreach(folderview_popups, create_ifactories, folderview);
+
        folderview->ctree        = ctree;
 
        folderview->folder_update_callback_id =
@@ -474,7 +564,7 @@ FolderView *folderview_create(void)
                hooks_register_hook(FOLDER_ITEM_UPDATE_HOOKLIST, folderview_update_item_claws, (gpointer) folderview);
 
        gtk_widget_show_all(scrolledwin);
-
+       
        folderview->target_list = gtk_target_list_new(folderview_drag_types, 1);
        folderview_list = g_list_append(folderview_list, folderview);
 
@@ -484,14 +574,7 @@ FolderView *folderview_create(void)
 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);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_OPEN, &inboxopenxpm, &inboxopenxpmmask);
@@ -538,39 +621,6 @@ void folderview_init(FolderView *folderview)
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN_HRM_MARK, &m_queueopenhrmxpm, &m_queueopenhrmxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_DRAFTS_CLOSE_MARK, &m_draftsxpm, &m_draftsxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_DRAFTS_OPEN_MARK, &m_draftsopenxpm, &m_draftsopenxpmmask);
-
-       /* 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);
-       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, 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;
@@ -756,15 +806,16 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
        FolderItem *item;
        gint new, unread, total;
        gchar *new_str, *unread_str, *total_str;
+       gint *col_pos = folderview->col_pos;
 
        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);
+       gtk_ctree_node_get_text(ctree, row, col_pos[F_COL_NEW], &new_str);
+       gtk_ctree_node_get_text(ctree, row, col_pos[F_COL_UNREAD], &unread_str);
+       gtk_ctree_node_get_text(ctree, row, col_pos[F_COL_TOTAL], &total_str);
        new = atoi(new_str);
        unread = atoi(unread_str);
        total = atoi(total_str);
@@ -777,7 +828,7 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
 void folderview_append_item(FolderItem *item)
 {
        GList *list;
-
+       
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
        if (folder_item_parent(item)) return;
@@ -786,6 +837,7 @@ void folderview_append_item(FolderItem *item)
                FolderView *folderview = (FolderView *)list->data;
                GtkCTree *ctree = GTK_CTREE(folderview->ctree);
                GtkCTreeNode *node, *child;
+               gint *col_pos = folderview->col_pos;
 
                node = gtk_ctree_find_by_row_data(ctree, NULL, 
                                                  folder_item_parent(item));
@@ -797,7 +849,7 @@ void folderview_append_item(FolderItem *item)
 
                                gtk_clist_freeze(GTK_CLIST(ctree));
 
-                               text[COL_FOLDER] = item->name;
+                               text[col_pos[F_COL_FOLDER]] = item->name;
                                child = gtk_ctree_insert_node
                                        (ctree, node, NULL, text,
                                         FOLDER_SPACING,
@@ -989,14 +1041,19 @@ static gboolean folderview_have_new_children_sub(FolderView *folderview,
                                                 FolderItem *item,
                                                 gboolean in_sub)
 {
-       GNode *node = item->folder->node;
+       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->new_msgs > 0 ||
-           (item->stype == F_QUEUE && item->total_msgs > 0))) {
+           (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0))) {
                return TRUE;
        }
 
@@ -1023,14 +1080,19 @@ static gboolean folderview_have_unread_children_sub(FolderView *folderview,
                                                    FolderItem *item, 
                                                    gboolean in_sub)
 {
-       GNode *node = item->folder->node;
+       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->unread_msgs > 0 ||
-           (item->stype == F_QUEUE && item->total_msgs > 0))) {
+           (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0))) {
                return TRUE;
        }
 
@@ -1058,7 +1120,12 @@ static gboolean folderview_have_matching_children_sub(FolderView *folderview,
                                                      FolderItem *item,
                                                      gboolean in_sub)
 {
-       GNode *node = item->folder->node;
+       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;
@@ -1103,6 +1170,7 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        gboolean add_unread_mark;
        gboolean add_sub_match_mark;
        gboolean use_bold, use_color;
+       gint *col_pos = folderview->col_pos;
 
        item = gtk_ctree_node_get_row_data(ctree, node);
        g_return_if_fail(item != NULL);
@@ -1208,7 +1276,7 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
                mask = openmask = searchmask;
        }
 
-       if (item->stype == F_QUEUE && item->total_msgs > 0 &&
+       if (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0 &&
            prefs_common.display_folder_unread) {
                str = g_strdup_printf("%s (%d%s)", name, item->total_msgs,
                                      add_unread_mark ? "+" : "");
@@ -1242,19 +1310,20 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        g_free(name);
 
        if (!folder_item_parent(item)) {
-               gtk_ctree_node_set_text(ctree, node, COL_NEW,    "-");
-               gtk_ctree_node_set_text(ctree, node, COL_UNREAD, "-");
-               gtk_ctree_node_set_text(ctree, node, COL_TOTAL,  "-");
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_NEW],    "-");
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_UNREAD], "-");
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_TOTAL],  "-");
        } else {
-               gtk_ctree_node_set_text(ctree, node, COL_NEW,    itos(item->new_msgs));
-               gtk_ctree_node_set_text(ctree, node, COL_UNREAD, itos(item->unread_msgs));
-               gtk_ctree_node_set_text(ctree, node, COL_TOTAL,  itos(item->total_msgs));
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_NEW],    itos(item->new_msgs));
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_UNREAD], itos(item->unread_msgs));
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_TOTAL],  itos(item->total_msgs));
        }
 
-       if (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
-           item->stype == F_TRASH) {
+       if (folder_has_parent_of_type(item, F_OUTBOX) ||
+           folder_has_parent_of_type(item, F_DRAFT) ||
+           folder_has_parent_of_type(item, F_TRASH)) {
                use_bold = use_color = FALSE;
-       } else if (item->stype == F_QUEUE) {
+       } else if (folder_has_parent_of_type(item, F_QUEUE)) {
                /* highlight queue folder if there are any messages */
                use_bold = use_color = (item->total_msgs > 0);
        } else {
@@ -1503,6 +1572,8 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        FolderViewPopup *fpopup;
        GtkItemFactory *fpopup_factory;
        GtkWidget *popup;
+       FolderItem *special_trash = NULL;
+       PrefsAccount *ac;
 
        if (!event) return FALSE;
 
@@ -1567,11 +1638,14 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        if (fpopup->set_sensitivity != NULL)
                fpopup->set_sensitivity(fpopup_factory, item);
 
-       if (item == folder->trash &&
+       if (NULL != (ac = account_find_from_item(item)))
+               special_trash = account_get_special_folder(ac, F_TRASH);
+
+       if ((item == folder->trash || item == special_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) {
+       } else if (item != folder->trash && (special_trash == NULL || item != special_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]);
        }
@@ -1584,8 +1658,11 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
                 folderview->selected == folderview->opened);
        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);
+       if (item == folder->trash || item == special_trash) {
+               GSList *msglist = folder_item_get_msg_list(item);
+               SET_SENS("/Empty trash...", msglist != NULL);
+               procmsg_msg_list_free(msglist);
+       }
 #undef SET_SENS
 
        popup = gtk_item_factory_get_widget(fpopup_factory, fpopup->path);
@@ -1780,30 +1857,15 @@ static void folderview_popup_close(GtkMenuShell *menu_shell,
 {
        if (!folderview->opened) return;
 
-       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,
                                   FolderView *folderview)
 {
-       switch (column) {
-       case COL_FOLDER:
-               prefs_common.folder_col_folder = width;
-               break;
-       case COL_NEW:
-               prefs_common.folder_col_new = width;
-               break;
-       case COL_UNREAD:
-               prefs_common.folder_col_unread = width;
-               break;
-       case COL_TOTAL:
-               prefs_common.folder_col_total = width;
-               break;
-       default:
-               break;
-       }
+       FolderColumnType type = folderview->col_state[column].type;
+
+       prefs_common.folder_col_size[type] = width;
 }
 
 void folderview_create_folder_node_recursive(FolderView *folderview, FolderItem *item)
@@ -1811,7 +1873,10 @@ void folderview_create_folder_node_recursive(FolderView *folderview, FolderItem
        GNode *srcnode;
 
        folderview_create_folder_node(folderview, item);
-       
+
+       if (!item || !item->folder || !item->folder->node)
+               return;
+
        srcnode = item->folder->node;   
        srcnode = g_node_find(srcnode, G_PRE_ORDER, G_TRAVERSE_ALL, item);
        srcnode = srcnode->children;
@@ -1829,14 +1894,15 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
        GtkCTreeNode *node, *parent_node;
-       
+       gint *col_pos = folderview->col_pos;
+
        parent_node = gtk_ctree_find_by_row_data(ctree, NULL, folder_item_parent(item));
        if (parent_node == NULL)
                return;
 
        gtk_clist_freeze(GTK_CLIST(ctree));
 
-       text[COL_FOLDER] = item->name;
+       text[col_pos[F_COL_FOLDER]] = item->name;
        node = gtk_ctree_insert_node(ctree, parent_node, NULL, text,
                                     FOLDER_SPACING,
                                     folderxpm, folderxpmmask,
@@ -1846,7 +1912,7 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        gtk_ctree_node_set_row_data(ctree, node, item);
        if (normal_style)
                gtk_ctree_node_set_row_style(ctree, node, normal_style);
-       folderview_sort_folders(folderview, folderview->selected, item->folder);
+       folderview_sort_folders(folderview, parent_node, item->folder);
 
        gtk_clist_thaw(GTK_CLIST(ctree));
 }
@@ -1859,16 +1925,22 @@ static void folderview_empty_trash_cb(FolderView *folderview, guint action,
        GSList *mlist = NULL;
        GSList *cur = NULL;
        if (!folderview->selected) return;
-       
+       FolderItem *special_trash = NULL;
+       PrefsAccount *ac;
+
        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 (NULL != (ac = account_find_from_item(item)))
+               special_trash = account_get_special_folder(ac, F_TRASH);
+
+       if (item != item->folder->trash && item != special_trash) return;
        
        if (prefs_common.ask_on_clean) {
                if (alertpanel(_("Empty trash"),
-                              _("Empty all messages in trash?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                              _("Delete all messages in trash?"),
+                              GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
                        return;
        }
        
@@ -1949,11 +2021,12 @@ void folderview_move_folder(FolderView *folderview, FolderItem *from_folder,
        from_parent = folder_item_parent(from_folder);
        
        if (prefs_common.warn_dnd) {
-               buf = g_strdup_printf(_("Do you really want to move folder `%s' to a "
-                                       "sub-folder of `%s' ?"), from_folder->name,
+               buf = g_strdup_printf(_("Do you really want to make folder '%s' a "
+                                       "sub-folder of '%s' ?"), from_folder->name,
                                        to_folder->name);
-               status = alertpanel_message_with_disable(_("Move folder"), buf, 
-                               _("Yes"), _("No"), NULL, ALERT_QUESTION);
+               status = alertpanel_full(_("Move folder"), buf,
+                                        GTK_STOCK_YES, GTK_STOCK_NO, NULL, TRUE,
+                                        NULL, ALERT_QUESTION, G_ALERTALTERNATE);
                g_free(buf);
 
                if (status != G_ALERTDEFAULT
@@ -1983,7 +2056,7 @@ void folderview_move_folder(FolderView *folderview, FolderItem *from_folder,
 
                folderview_sort_folders(folderview, 
                        gtk_ctree_find_by_row_data(GTK_CTREE(folderview->ctree), 
-                               NULL, folder_item_parent(new_folder)), new_folder->folder);
+                               NULL, to_folder), new_folder->folder);
                folderview_select(folderview, new_folder);
        } else {
                statusbar_verbosity_set(FALSE);         
@@ -2028,6 +2101,7 @@ static void folderview_processing_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
+       gchar *id, *title;
 
        if (!folderview->selected) return;
 
@@ -2035,8 +2109,12 @@ static void folderview_processing_cb(FolderView *folderview, guint action,
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       prefs_filtering_open(&item->prefs->processing,
-                            _("Processing configuration"), NULL, NULL);
+       id = folder_item_get_identifier(item);
+       title = g_strdup_printf (_("Processing configuration for folder %s"), id);
+       g_free (id);
+
+       prefs_filtering_open(&item->prefs->processing, title, NULL, NULL);
+       g_free (title);
 }
 
 void folderview_set_target_folder_color(gint color_op) 
@@ -2058,8 +2136,19 @@ void folderview_set_target_folder_color(gint color_op)
 
 void folderview_reflect_prefs_pixmap_theme(FolderView *folderview)
 {
+}
+
+void folderview_reflect_prefs(void)
+{
+       FolderView *folderview = mainwindow_get_mainwindow()->folderview;
+       normal_style = normal_color_style = bold_style = 
+               bold_color_style = bold_tgtfold_style = NULL;
+       FolderItem *item = folderview_get_selected_item(folderview);
        folderview_init(folderview);
+       folderview_column_set_titles(folderview);
        folderview_set_all();
+       if (item)
+               folderview_select(folderview, item);
 }
 
 static void drag_state_stop(FolderView *folderview)
@@ -2301,6 +2390,7 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
        } else {
                /* comes from folderview */
                char *source;
+               gboolean folder_is_normal = TRUE;
                
                source = data->data + 17;
                if (gtk_clist_get_selection_info
@@ -2313,7 +2403,15 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
                src_item = folder_find_item_from_identifier(source);
 
-               if (!item || item->no_select || !src_item || src_item->stype != F_NORMAL) {
+               folder_is_normal = 
+                       src_item != NULL &&
+                       src_item->stype == F_NORMAL &&
+                       !folder_has_parent_of_type(src_item, F_OUTBOX) &&
+                       !folder_has_parent_of_type(src_item, F_DRAFT) &&
+                       !folder_has_parent_of_type(src_item, F_QUEUE) &&
+                       !folder_has_parent_of_type(src_item, F_TRASH);
+               if (!item || item->no_select || !src_item 
+               ||  !folder_is_normal) {
                        gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
                        return;
                }