show pixmap in mark and locked column headers and a bugfix by adding locked and score...
[claws.git] / src / summaryview.c
index 3b8f9aee1833df2ba7ebc0c0d0f92f37c2f9b66c..8cb9ab359d0659b1b2b0d26ee34149069caaae13 100644 (file)
@@ -46,6 +46,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <regex.h>
 
 #include "intl.h"
 #include "main.h"
@@ -65,6 +66,7 @@
 #include "compose.h"
 #include "utils.h"
 #include "gtkutils.h"
+#include "stock_pixmap.h"
 #include "filesel.h"
 #include "manage_window.h"
 #include "alertpanel.h"
 #include "folder.h"
 #include "colorlabel.h"
 #include "inc.h"
+#include "imap.h"
 #include "addressbook.h"
 #include "addr_compl.h"
 #include "scoring.h"
 #include "prefs_folder_item.h"
 #include "filtering.h"
-
-#include "pixmaps/dir-open.xpm"
-#include "pixmaps/mark.xpm"
-#include "pixmaps/deleted.xpm"
-#include "pixmaps/new.xpm"
-#include "pixmaps/unread.xpm"
-#include "pixmaps/replied.xpm"
-#include "pixmaps/forwarded.xpm"
-#include "pixmaps/clip.xpm"
-#include "pixmaps/ignorethread.xpm"
-#include "pixmaps/locked.xpm"
+#include "string_match.h"
 
 #define STATUSBAR_PUSH(mainwin, str) \
 { \
@@ -119,9 +112,6 @@ static GtkStyle *small_style;
 static GtkStyle *small_marked_style;
 static GtkStyle *small_deleted_style;
 
-static GdkPixmap *folderxpm;
-static GdkBitmap *folderxpmmask;
-
 static GdkPixmap *markxpm;
 static GdkBitmap *markxpmmask;
 static GdkPixmap *deletedxpm;
@@ -253,6 +243,9 @@ static void summary_unthread_for_exec_func  (GtkCTree       *ctree,
                                                 GtkCTreeNode   *node,
                                                 gpointer        data);
 
+void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
+                             GSList * mlist);
+
 void summary_processing(SummaryView *summaryview, GSList * mlist);
 static void summary_filter_func                (GtkCTree               *ctree,
                                         GtkCTreeNode           *node,
@@ -533,21 +526,24 @@ void summary_init(SummaryView *summaryview)
        GtkStyle *style;
        GtkWidget *pixmap;
 
-       PIXMAP_CREATE(summaryview->ctree, markxpm, markxpmmask, mark_xpm);
-       PIXMAP_CREATE(summaryview->ctree, deletedxpm, deletedxpmmask,
-                     deleted_xpm);
-       PIXMAP_CREATE(summaryview->ctree, newxpm, newxpmmask, new_xpm);
-       PIXMAP_CREATE(summaryview->ctree, unreadxpm, unreadxpmmask, unread_xpm);
-       PIXMAP_CREATE(summaryview->ctree, repliedxpm, repliedxpmmask,
-                     replied_xpm);
-       PIXMAP_CREATE(summaryview->ctree, forwardedxpm, forwardedxpmmask,
-                     forwarded_xpm);
-       PIXMAP_CREATE(summaryview->ctree, ignorethreadxpm, ignorethreadxpmmask,
-                     ignorethread_xpm);
-       PIXMAP_CREATE(summaryview->ctree, lockedxpm, lockedxpmmask, locked_xpm);                      
-       PIXMAP_CREATE(summaryview->ctree, clipxpm, clipxpmmask, clip_xpm);
-       PIXMAP_CREATE(summaryview->hbox, folderxpm, folderxpmmask,
-                     dir_open_xpm);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_MARK,
+                        &markxpm, &markxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_DELETED,
+                        &deletedxpm, &deletedxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_NEW,
+                        &newxpm, &newxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_UNREAD,
+                        &unreadxpm, &unreadxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_REPLIED,
+                        &repliedxpm, &repliedxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_FORWARDED,
+                        &forwardedxpm, &forwardedxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_CLIP,
+                        &clipxpm, &clipxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_LOCKED,
+                        &lockedxpm, &lockedxpmmask);
+       stock_pixmap_gdk(summaryview->ctree, STOCK_PIXMAP_IGNORETHREAD,
+                        &ignorethreadxpm, &ignorethreadxpmmask);
 
        if (!small_style) {
                small_style = gtk_style_copy
@@ -583,7 +579,7 @@ void summary_init(SummaryView *summaryview)
        gtk_widget_set_style(summaryview->statlabel_select, style);
        gtk_widget_set_style(summaryview->statlabel_msgs, style);
 
-       pixmap = gtk_pixmap_new(folderxpm, folderxpmmask);
+       pixmap = stock_pixmap_widget(summaryview->hbox, STOCK_PIXMAP_DIR_OPEN);
        gtk_box_pack_start(GTK_BOX(summaryview->hbox), pixmap, FALSE, FALSE, 4);
        gtk_box_reorder_child(GTK_BOX(summaryview->hbox), pixmap, 0);
        gtk_widget_show(pixmap);
@@ -708,9 +704,8 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
                        return FALSE;
                }
                folder_update_op_count();
-       }
-        
-       summary_write_cache(summaryview);
+       } else
+               summary_write_cache(summaryview);
         
        summaryview->folderview->opened = selected_node;
 
@@ -816,6 +811,14 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
                mlist = not_killed;
        }
 
+       if (item->prefs->enable_simplify_subject
+           && item->prefs->simplify_subject_regexp != NULL
+           && strlen(item->prefs->simplify_subject_regexp) != 0) {
+               summary_simplify_subject(summaryview, 
+                                        item->prefs->simplify_subject_regexp,
+                                        mlist);
+       }
+
        STATUSBAR_POP(summaryview->mainwin);
 
        /* set ctree and hash table from the msginfo list
@@ -1039,7 +1042,6 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
        menu_set_sensitive(ifactory, "/Reply to sender",          sens);
        menu_set_sensitive(ifactory, "/Reply to all",             sens);
        menu_set_sensitive(ifactory, "/Forward",                  TRUE);
-       menu_set_sensitive(ifactory, "/Forward as attachment",    TRUE);
        menu_set_sensitive(ifactory, "/Bounce",                   TRUE);
 
        menu_set_sensitive(ifactory, "/Add sender to address book", sens);
@@ -1766,14 +1768,16 @@ static void summary_set_column_titles(SummaryView *summaryview)
                SORT_BY_FROM,
                SORT_BY_DATE,
                SORT_BY_SIZE,
-               SORT_BY_NUMBER
+               SORT_BY_NUMBER,
+               SORT_BY_SCORE,
+               SORT_BY_LOCKED
        };
 
        for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
                type = summaryview->col_state[pos].type;
 
-               single_char = (type == S_COL_MIME ||
-                              type == S_COL_MARK || type == S_COL_UNREAD);
+               /* CLAWS: mime and unread are single char headers */
+               single_char = (type == S_COL_MIME || type == S_COL_UNREAD);
                justify = (type == S_COL_NUMBER || type == S_COL_SIZE)
                        ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT;
 
@@ -1787,6 +1791,11 @@ static void summary_set_column_titles(SummaryView *summaryview)
                        else
                                title = col_label[type];
                        break;
+               /* CLAWS: dummies for mark and locked headers */        
+               case S_COL_MARK:        
+               case S_COL_LOCKED:
+                       title = "";
+                       break;
                default:
                        title = gettext(col_label[type]);
                }
@@ -1802,8 +1811,17 @@ static void summary_set_column_titles(SummaryView *summaryview)
                        continue;
                }
 
-               hbox = gtk_hbox_new(FALSE, 4);
-               label = gtk_label_new(title);
+               /* CLAWS: changed so that locked and mark headers
+                * show a pixmap instead of single character */
+               hbox  = gtk_hbox_new(FALSE, 4);
+               
+               if (type == S_COL_LOCKED)
+                       label = gtk_pixmap_new(lockedxpm, lockedxpmmask);
+               else if (type == S_COL_MARK) 
+                       label = gtk_pixmap_new(markxpm, markxpmmask);
+               else 
+                       label = gtk_label_new(title);
+               
                if (justify == GTK_JUSTIFY_RIGHT)
                        gtk_box_pack_end(GTK_BOX(hbox), label,
                                         FALSE, FALSE, 0);
@@ -2268,6 +2286,15 @@ static void summary_display_msg(SummaryView *summaryview, GtkCTreeNode *row,
                summaryview->newmsgs--;
        if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
                summaryview->unread--;
+       if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags) || 
+           MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+               MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
+               if (MSG_IS_IMAP(msginfo->flags))
+                       imap_msg_unset_perm_flags(msginfo, MSG_NEW | MSG_UNREAD);
+               summary_set_row_marks(summaryview, row);
+               gtk_clist_thaw(GTK_CLIST(ctree));
+               summary_status_show(summaryview);
+       }
 
        if (new_window) {
                MessageView *msgview;
@@ -2599,9 +2626,10 @@ static void summary_mark_row(SummaryView *summaryview, GtkCTreeNode *row)
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
        MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MOVE | MSG_COPY);
        MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_set_perm_flags(msginfo, MSG_MARKED);
        CHANGE_FLAGS(msginfo);
        summary_set_row_marks(summaryview, row);
-       imap_do_mark(msginfo);
        debug_print(_("Message %s/%d is marked\n"), msginfo->folder->path, msginfo->msgnum);
 }
 
@@ -2632,6 +2660,8 @@ static void summary_lock_row(SummaryView *summaryview, GtkCTreeNode *row)
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
        MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MOVE | MSG_COPY);
        MSG_SET_PERM_FLAGS(msginfo->flags, MSG_LOCKED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_set_perm_flags(msginfo, MSG_LOCKED);
        CHANGE_FLAGS(msginfo);
        summary_set_row_marks(summaryview, row);
        debug_print(_("Message %d is locked\n"), msginfo->msgnum);
@@ -2663,6 +2693,8 @@ static void summary_mark_row_as_read(SummaryView *summaryview,
        if (MSG_IS_NEW(msginfo->flags) ||
            MSG_IS_UNREAD(msginfo->flags)) {
                MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
+               if (MSG_IS_IMAP(msginfo->flags))
+                       imap_msg_unset_perm_flags(msginfo, MSG_NEW | MSG_UNREAD);
                CHANGE_FLAGS(msginfo);
                summary_set_row_marks(summaryview, row);
                debug_print(_("Message %d is marked as read\n"),
@@ -2715,8 +2747,12 @@ static void summary_mark_row_as_unread(SummaryView *summaryview,
                summaryview->deleted--;
        }
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED | MSG_FORWARDED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
        if (!MSG_IS_UNREAD(msginfo->flags)) {
                MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
+               if (MSG_IS_IMAP(msginfo->flags))
+                       imap_msg_set_perm_flags(msginfo, MSG_UNREAD);
                summaryview->unread++;
                debug_print(_("Message %d is marked as unread\n"),
                            msginfo->msgnum);
@@ -2766,6 +2802,8 @@ static void summary_delete_row(SummaryView *summaryview, GtkCTreeNode *row)
        }
        msginfo->to_folder = NULL;
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_unset_perm_flags(msginfo, MSG_MARKED);
        MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MOVE | MSG_COPY);
        MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
        CHANGE_FLAGS(msginfo);
@@ -2891,10 +2929,11 @@ static void summary_unmark_row(SummaryView *summaryview, GtkCTreeNode *row)
        }
        msginfo->to_folder = NULL;
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_MARKED | MSG_DELETED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_unset_perm_flags(msginfo, MSG_MARKED);
        MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MOVE | MSG_COPY);
        CHANGE_FLAGS(msginfo);
        summary_set_row_marks(summaryview, row);
-       imap_do_unmark(msginfo);
        debug_print(_("Message %s/%d is unmarked\n"),
                    msginfo->folder->path, msginfo->msgnum);
 }
@@ -2904,8 +2943,7 @@ void summary_unmark(SummaryView *summaryview)
        GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
        GList *cur;
 
-       for (cur = GTK_CLIST(ctree)->selection; cur != NULL;
-            cur = cur->next)
+       for (cur = GTK_CLIST(ctree)->selection; cur != NULL; cur = cur->next)
                summary_unmark_row(summaryview, GTK_CTREE_NODE(cur->data));
 
        summary_status_show(summaryview);
@@ -2939,6 +2977,8 @@ static void summary_move_row_to(SummaryView *summaryview, GtkCTreeNode *row,
                        msginfo->to_folder->op_count--;
        }
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_MARKED | MSG_DELETED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_unset_perm_flags(msginfo, MSG_MARKED);
        MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_COPY);
        if (!MSG_IS_MOVE(msginfo->flags)) {
                MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MOVE);
@@ -3028,6 +3068,8 @@ static void summary_copy_row_to(SummaryView *summaryview, GtkCTreeNode *row,
                        msginfo->to_folder->op_count--;
        }
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_MARKED | MSG_DELETED);
+       if (MSG_IS_IMAP(msginfo->flags))
+               imap_msg_unset_perm_flags(msginfo, MSG_MARKED);
        MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MOVE);
        if (!MSG_IS_COPY(msginfo->flags)) {
                MSG_SET_TMP_FLAGS(msginfo->flags, MSG_COPY);
@@ -3590,6 +3632,17 @@ static void summary_unthread_for_exec_func(GtkCTree *ctree, GtkCTreeNode *node,
        }
 }
 
+void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
+                             GSList * mlist)
+{
+       GSList * cur;
+       for(cur = mlist ; cur != NULL ; cur = cur->next) {
+               MsgInfo * msginfo = (MsgInfo *) cur->data;
+               string_remove_all_matches(msginfo->subject, rexp, 
+                                         REG_EXTENDED, 0);
+       }
+}
+
 void summary_processing(SummaryView *summaryview, GSList * mlist)
 {
        GSList * processing_list;
@@ -4042,8 +4095,16 @@ void summary_set_column_order(SummaryView *summaryview)
        GtkWidget *scrolledwin = summaryview->scrolledwin;
        GtkWidget *pixmap;
        FolderItem *item;
+       guint selected_msgnum = summary_get_msgnum(summaryview, summaryview->selected);
+       guint displayed_msgnum = summary_get_msgnum(summaryview, summaryview->displayed);
 
+       
        item = summaryview->folder_item;
+
+       summary_lock(summaryview);
+       summary_write_cache(summaryview);
+       summary_unlock(summaryview);
+       
        summary_clear_all(summaryview);
        gtk_widget_destroy(summaryview->ctree);
 
@@ -4060,6 +4121,13 @@ void summary_set_column_order(SummaryView *summaryview)
        gtk_widget_show(ctree);
 
        summary_show(summaryview, item, FALSE);
+
+       summary_select_by_msgnum(summaryview, selected_msgnum);
+       summaryview->displayed = summary_find_msg_by_msgnum(summaryview, displayed_msgnum);
+       if (!summaryview->displayed)
+               messageview_clear(summaryview->messageview);
+       else
+               summary_redisplay_msg(summaryview);
 }
 
 
@@ -4344,6 +4412,8 @@ static void summary_selected(GtkCTree *ctree, GtkCTreeNode *row,
        case S_COL_MARK:
                if (MSG_IS_MARKED(msginfo->flags)) {
                        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
+                       if (MSG_IS_IMAP(msginfo->flags))
+                               imap_msg_unset_perm_flags(msginfo, MSG_MARKED);
                        CHANGE_FLAGS(msginfo);
                        summary_set_row_marks(summaryview, row);
                } else
@@ -4555,7 +4625,7 @@ static void summary_start_drag(GtkWidget *widget, gint button, GdkEvent *event,
        list = gtk_target_list_new(summary_drag_types, 1);
 
        context = gtk_drag_begin(widget, list,
-                                GDK_ACTION_MOVE, button, event);
+                                GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT, button, event);
        gtk_drag_set_icon_default(context);
 }