add and adapt Thomas Link's subject simplification patch
[claws.git] / src / folderview.c
index 4de8dc8eb53681f27650524ecf96b7abfad52a91..b8fd33a6c8fc5b310e2f7a0c0f4c2cc1f6135779 100644 (file)
 #include "mainwindow.h"
 #include "folderview.h"
 #include "summaryview.h"
+#include "summary_search.h"
 #include "inputdialog.h"
 #include "grouplistdialog.h"
 #include "manage_window.h"
 #include "alertpanel.h"
 #include "menu.h"
+#include "stock_pixmap.h"
 #include "procmsg.h"
 #include "utils.h"
 #include "gtkutils.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/trash.xpm"
-
 typedef enum
 {
        COL_FOLDER      = 0,
@@ -100,14 +96,22 @@ static GtkStyle *bold_tgtfold_style;
 
 static GdkPixmap *inboxxpm;
 static GdkBitmap *inboxxpmmask;
+static GdkPixmap *inboxhrmxpm;
+static GdkBitmap *inboxhrmxpmmask;
 static GdkPixmap *outboxxpm;
 static GdkBitmap *outboxxpmmask;
+static GdkPixmap *outboxhrmxpm;
+static GdkBitmap *outboxhrmxpmmask;
 static GdkPixmap *folderxpm;
 static GdkBitmap *folderxpmmask;
 static GdkPixmap *folderopenxpm;
 static GdkBitmap *folderopenxpmmask;
+static GdkPixmap *folderopenhrmxpm;
+static GdkBitmap *folderopenhrmxpmmask;
 static GdkPixmap *trashxpm;
 static GdkBitmap *trashxpmmask;
+static GdkPixmap *trashhrmxpm;
+static GdkBitmap *trashhrmxpmmask;
 
 static void folderview_select_node      (FolderView    *folderview,
                                          GtkCTreeNode  *node);
@@ -197,6 +201,10 @@ static void folderview_rm_news_server_cb(FolderView        *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
 
+static void folderview_search_cb       (FolderView     *folderview,
+                                        guint           action,
+                                        GtkWidget      *widget);
+
 static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                                          GdkDragContext *context,
                                          gint            x,
@@ -217,6 +225,8 @@ static void folderview_drag_received_cb  (GtkWidget        *widget,
                                          FolderView       *folderview);
 static void folderview_scoring_cb(FolderView *folderview, guint action,
                                  GtkWidget *widget);
+static void folderview_processing_cb(FolderView *folderview, guint action,
+                                    GtkWidget *widget);
 static void folderview_property_cb(FolderView *folderview, guint action, GtkWidget *widget);
 
 static GtkItemFactoryEntry folderview_mbox_popup_entries[] =
@@ -228,6 +238,7 @@ static GtkItemFactoryEntry folderview_mbox_popup_entries[] =
        {N_("/Remove _mailbox"),        NULL, folderview_remove_mailbox_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/_Property..."),           NULL, NULL, 0, NULL},
+       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
        {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
@@ -238,12 +249,14 @@ static GtkItemFactoryEntry folderview_mail_popup_entries[] =
        {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_("/Re_scan folder tree"),    NULL, folderview_update_tree_cb, 1, 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},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
+       {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Property..."),           NULL, folderview_property_cb, 0, NULL},
-       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
+       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
+       {N_("/S_coring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 static GtkItemFactoryEntry folderview_imap_popup_entries[] =
@@ -253,12 +266,14 @@ static GtkItemFactoryEntry folderview_imap_popup_entries[] =
        {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_("/Re_scan folder tree"),    NULL, folderview_update_tree_cb, 1, 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},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
+       {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Property..."),           NULL, NULL, 0, NULL},
-       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
+       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
+       {N_("/S_coring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 static GtkItemFactoryEntry folderview_news_popup_entries[] =
@@ -269,8 +284,10 @@ static GtkItemFactoryEntry folderview_news_popup_entries[] =
        {N_("/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _news account"),    NULL, folderview_rm_news_server_cb, 0, NULL},
        {N_("/---"),                     NULL, NULL, 0, "<Separator>"},
+       {N_("/_Search folder..."),       NULL, folderview_search_cb, 0, NULL},
        {N_("/_Property..."),            NULL, NULL, 0, NULL},
-       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
+       {N_("/_Processing..."),          NULL, folderview_processing_cb, 0, NULL},
+       {N_("/S_coring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 
@@ -396,7 +413,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);
@@ -429,11 +446,14 @@ void folderview_init(FolderView *folderview)
 {
        GtkWidget *ctree = folderview->ctree;
 
-       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, trashxpm, trashxpmmask, trash_xpm);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX, &inboxxpm, &inboxxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX,
+                        &outboxxpm, &outboxxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_CLOSE,
+                        &folderxpm, &folderxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_OPEN,
+                        &folderopenxpm, &folderopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH, &trashxpm, &trashxpmmask);
 
        if (!normalfont)
                normalfont = gdk_fontset_load(NORMAL_FONT);
@@ -580,11 +600,19 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row,
 
        item = gtk_ctree_node_get_row_data(ctree, row);
        if (!item) return;
+
+       /* 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
+        * values. It then enters this function, but leaves it
+        * because new, unread and total are the same... */
+#ifndef CLAWS   
        if (prev_row     == row    &&
            item->new    == new    &&
            item->unread == unread &&
-           item->total  == total)
+           item->total  == total) 
                return;
+#endif         
 
        prev_row = row;
 
@@ -851,37 +879,75 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
 
        switch (item->stype) {
        case F_INBOX:
-               xpm = openxpm = inboxxpm;
-               mask = openmask = inboxxpmmask;
+               xpm = inboxxpm;
+               mask = inboxxpmmask;
+               if (item->hide_read_msgs) {
+                       openxpm = inboxhrmxpm;
+                       openmask = inboxhrmxpmmask;
+               } else {
+                       openxpm = inboxxpm;
+                       openmask = inboxxpmmask;
+               }
                name = g_strdup(_("Inbox"));
                break;
        case F_OUTBOX:
-               xpm = openxpm = outboxxpm;
-               mask = openmask = outboxxpmmask;
+               xpm = outboxxpm;
+               mask =outboxxpmmask;
+               if (item->hide_read_msgs) {
+                       openxpm = outboxhrmxpm;
+                       openmask = outboxhrmxpmmask;
+               } else {
+                       openxpm = outboxxpm;
+                       openmask = outboxxpmmask;
+               }
                name = g_strdup(_("Outbox"));
                break;
        case F_QUEUE:
-               xpm = openxpm = outboxxpm;
-               mask = openmask = outboxxpmmask;
+               xpm = outboxxpm;
+               mask =outboxxpmmask;
+               if (item->hide_read_msgs) {
+                       openxpm = outboxhrmxpm;
+                       openmask = outboxhrmxpmmask;
+               } else {
+                       openxpm = outboxxpm;
+                       openmask = outboxxpmmask;
+               }
                name = g_strdup(_("Queue"));
                break;
        case F_TRASH:
-               xpm = openxpm = trashxpm;
-               mask = openmask = trashxpmmask;
+               xpm = trashxpm;
+               mask = trashxpmmask;
+               if (item->hide_read_msgs) {
+                       openxpm = trashhrmxpm;
+                       openmask = trashhrmxpmmask;
+               } else {
+                       openxpm = trashxpm;
+                       openmask = trashxpmmask;
+               }
                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;
-               openxpm = folderopenxpm;
-               openmask = folderopenxpmmask;
+               if (item->hide_read_msgs) {
+                       openxpm = folderopenhrmxpm;
+                       openmask = folderopenhrmxpmmask;
+               } else {
+                       openxpm = folderopenxpm;
+                       openmask = folderopenxpmmask;
+               }
                if (!item->parent) {
                        switch (item->folder->type) {
                        case F_MH:
@@ -1202,7 +1268,9 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        gboolean rescan_tree     = FALSE;
        gboolean remove_tree     = FALSE;
        gboolean folder_property = FALSE;
+       gboolean folder_processing  = FALSE;
        gboolean folder_scoring  = FALSE;
+       gboolean search_folder = FALSE;
 
        if (!event) return;
 
@@ -1248,16 +1316,22 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                new_folder = TRUE;
                if (item->parent == NULL)
                        update_tree = remove_tree = TRUE;
+               else
+                       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;
                        else if (item->stype == F_NORMAL)
-                               rename_folder = delete_folder = folder_property = folder_scoring = TRUE;
+                               rename_folder = delete_folder = folder_property = folder_scoring = folder_processing = TRUE;
                        else if (item->stype == F_INBOX)
-                               folder_property = folder_scoring = TRUE;
+                               folder_property = folder_scoring = folder_processing = TRUE;
+                       else if (item->stype == F_TRASH)
+                               folder_processing = TRUE;
+                       else if (item->stype == F_OUTBOX)
+                               folder_processing = TRUE;
                } else if (FOLDER_TYPE(folder) == F_NEWS) {
                        if (item->parent != NULL)
-                               delete_folder = folder_scoring = TRUE;
+                               delete_folder = folder_scoring = folder_processing = TRUE;
                }
        }
 
@@ -1274,7 +1348,9 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                SET_SENS(mail_factory, "/Rescan folder tree", rescan_tree);
                SET_SENS(mail_factory, "/Remove mailbox", remove_tree);
                SET_SENS(mail_factory, "/Property...", folder_property);
+               SET_SENS(mail_factory, "/Processing...", folder_processing);
                SET_SENS(mail_factory, "/Scoring...", folder_scoring);
+               SET_SENS(mail_factory, "/Search folder...", search_folder);
        } else if (FOLDER_TYPE(folder) == F_IMAP) {
                popup = folderview->imap_popup;
                menu_set_insensitive_all(GTK_MENU_SHELL(popup));
@@ -1284,13 +1360,17 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                SET_SENS(imap_factory, "/Update folder tree", 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);
                SET_SENS(imap_factory, "/Scoring...", folder_scoring);
+               SET_SENS(imap_factory, "/Search folder...", search_folder);
        } else if (FOLDER_TYPE(folder) == F_NEWS) {
                popup = folderview->news_popup;
                menu_set_insensitive_all(GTK_MENU_SHELL(popup));
                SET_SENS(news_factory, "/Subscribe to newsgroup...", new_folder);
                SET_SENS(news_factory, "/Remove newsgroup", delete_folder);
                SET_SENS(news_factory, "/Remove news account", remove_tree);
+               SET_SENS(news_factory, "/Search folder...", search_folder);
+               SET_SENS(news_factory, "/Processing...", folder_processing);
                SET_SENS(news_factory, "/Scoring...", folder_scoring);
        } else if (FOLDER_TYPE(folder) == F_MBOX) {
                popup = folderview->mbox_popup;
@@ -1298,6 +1378,7 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                SET_SENS(mbox_factory, "/Create new folder...", new_folder);
                SET_SENS(mbox_factory, "/Rename folder...", rename_folder);
                SET_SENS(mbox_factory, "/Delete folder", delete_folder);
+               SET_SENS(mbox_factory, "/Processing...", folder_processing);
                SET_SENS(mbox_factory, "/Scoring...", folder_scoring);
        } else
                return;
@@ -2132,6 +2213,12 @@ static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
        folder_write_list();
 }
 
+static void folderview_search_cb(FolderView *folderview, guint action,
+                                GtkWidget *widget)
+{
+       summary_search(folderview->summaryview);
+}
+
 static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                                          GdkDragContext *context,
                                          gint            x,
@@ -2168,8 +2255,12 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
        }
 
        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);
@@ -2206,8 +2297,18 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
        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);
-               gtk_drag_finish(drag_context, TRUE, TRUE, time);
+               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:
+                               summary_move_selected_to(folderview->summaryview, item);
+                               gtk_drag_finish(drag_context, TRUE, TRUE, time);
+                               break;
+               }
        } else
                gtk_drag_finish(drag_context, FALSE, FALSE, time);
 }
@@ -2236,7 +2337,24 @@ static void folderview_scoring_cb(FolderView *folderview, guint action,
        prefs_scoring_open(item);
 }
 
-static void folderview_property_cb(FolderView *folderview, guint action, GtkWidget *widget) {
+static void folderview_processing_cb(FolderView *folderview, guint action,
+                                    GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+
+       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);
+
+       prefs_filtering_open(item);
+}
+
+static void folderview_property_cb(FolderView *folderview, guint action, 
+                                  GtkWidget *widget) 
+{
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
 
@@ -2246,10 +2364,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;