* src/summaryview.c
[claws.git] / src / summaryview.c
index 3cce3380357ef37b17fc937e3fd8def8ab37b52f..c63e67be069d69a7a9b47cec2d4c72a84e6180c1 100644 (file)
@@ -83,6 +83,7 @@
 #include "matcher_parser.h"
 #include "hooks.h"
 #include "description_window.h"
+#include "folderutils.h"
 
 #define SUMMARY_COL_MARK_WIDTH         10
 #define SUMMARY_COL_STATUS_WIDTH       13
@@ -202,11 +203,6 @@ static void summary_copy_row_to            (SummaryView            *summaryview,
                                         GtkCTreeNode           *row,
                                         FolderItem             *to_folder);
 
-static void summary_delete_duplicated_func
-                                       (GtkCTree               *ctree,
-                                        GtkCTreeNode           *node,
-                                        SummaryView            *summaryview);
-
 static void summary_execute_move       (SummaryView            *summaryview);
 static void summary_execute_move_func  (GtkCTree               *ctree,
                                         GtkCTreeNode           *node,
@@ -302,6 +298,9 @@ static void summary_add_address_cb  (SummaryView            *summaryview,
 static void summary_create_filter_cb   (SummaryView            *summaryview,
                                         guint                   action,
                                         GtkWidget              *widget);
+static void summary_create_processing_cb(SummaryView           *summaryview,
+                                        guint                   action,
+                                        GtkWidget              *widget);
 
 static void summary_mark_clicked       (GtkWidget              *button,
                                         SummaryView            *summaryview);
@@ -441,6 +440,15 @@ static GtkItemFactoryEntry summary_popup_entries[] =
                                        NULL, summary_create_filter_cb, FILTER_BY_TO, NULL},
        {N_("/Create f_ilter rule/by _Subject"),
                                        NULL, summary_create_filter_cb, FILTER_BY_SUBJECT, NULL},
+       {N_("/Create processing rule"), NULL, NULL,             0, "<Branch>"},
+       {N_("/Create processing rule/_Automatically"),
+                                       NULL, summary_create_processing_cb, FILTER_BY_AUTO, NULL},
+       {N_("/Create processing rule/by _From"),
+                                       NULL, summary_create_processing_cb, FILTER_BY_FROM, NULL},
+       {N_("/Create processing rule/by _To"),
+                                       NULL, summary_create_processing_cb, FILTER_BY_TO, NULL},
+       {N_("/Create processing rule/by _Subject"),
+                                       NULL, summary_create_processing_cb, FILTER_BY_SUBJECT, NULL},
        {N_("/---"),                    NULL, NULL,             0, "<Separator>"},
        {N_("/_View"),                  NULL, NULL,             0, "<Branch>"},
        {N_("/_View/Open in new _window"),
@@ -506,6 +514,7 @@ static gchar *search_descr_strings[] = {
        "T",     N_("marked messages"),
        "U",     N_("unread messages"),
        "x S",   N_("messages which contain S in References header"),
+       "X cmd", N_("messages returning 0 when passed to command"),
        "y S",   N_("messages which contain S in X-Label header"),
         "",     "" ,
        "&",     N_("logical AND operator"),
@@ -777,6 +786,8 @@ void summary_init(SummaryView *summaryview)
                small_deleted_style = gtk_style_copy(small_style);
                small_deleted_style->fg[GTK_STATE_NORMAL] =
                        summaryview->color_dim;
+
+               gtk_widget_set_style(summaryview->ctree, small_style);
        }
 
        style = gtk_style_copy(gtk_widget_get_style
@@ -940,7 +951,7 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item)
        summary_set_column_titles(summaryview);
 
        buf = NULL;
-       if (!item || !item->path || !item->parent || item->no_select) {
+       if (!item || !item->path || !folder_item_parent(item) || item->no_select) {
                g_free(buf);
                debug_print("empty folder\n\n");
                summary_set_hide_read_msgs_menu(summaryview, FALSE);
@@ -1338,6 +1349,7 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
 
                {"/Add sender to address book"  , M_SINGLE_TARGET_EXIST},
                {"/Create filter rule"          , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
+               {"/Create processing rule"      , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
 
                {"/View"                        , M_SINGLE_TARGET_EXIST},
                {"/View/Open in new window"     , M_SINGLE_TARGET_EXIST},
@@ -2382,8 +2394,7 @@ static void summary_set_header(SummaryView *summaryview, gchar *text[],
 
        text[col_pos[S_COL_FROM]] = msginfo->fromname ? msginfo->fromname :
                _("(No From)");
-       if (prefs_common.swap_from && msginfo->from && msginfo->to &&
-           !MSG_IS_NEWS(msginfo->flags)) {
+       if (prefs_common.swap_from && msginfo->from && msginfo->to) {
                gchar *addr = NULL;
 
                Xstrdup_a(addr, msginfo->from, return);
@@ -2944,7 +2955,6 @@ static void summary_mark_row_as_unread(SummaryView *summaryview,
        && procmsg_msg_has_marked_parent(msginfo))
                summaryview->unreadmarked++;
 
-       procmsg_msginfo_unset_flags(msginfo, MSG_REPLIED | MSG_FORWARDED, 0);
        procmsg_msginfo_set_flags(msginfo, MSG_UNREAD, 0);
        debug_print("Message %d is marked as unread\n",
                msginfo->msgnum);
@@ -3126,57 +3136,6 @@ void summary_delete(SummaryView *summaryview)
        main_window_cursor_normal(summaryview->mainwin);
 }
 
-void summary_delete_duplicated(SummaryView *summaryview)
-{
-       if (!summaryview->folder_item ||
-           FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
-       if (summaryview->folder_item->stype == F_TRASH) return;
-
-       main_window_cursor_wait(summaryview->mainwin);
-       debug_print("Deleting duplicated messages...");
-       STATUSBAR_PUSH(summaryview->mainwin,
-                      _("Deleting duplicated messages..."));
-
-       folder_item_update_freeze();
-       
-       gtk_ctree_pre_recursive(GTK_CTREE(summaryview->ctree), NULL,
-                               GTK_CTREE_FUNC(summary_delete_duplicated_func),
-                               summaryview);
-
-       if (prefs_common.immediate_exec)
-               summary_execute(summaryview);
-       else
-               summary_status_show(summaryview);
-
-       folder_item_update_thaw();
-
-       debug_print("done.\n");
-       STATUSBAR_POP(summaryview->mainwin);
-       main_window_cursor_normal(summaryview->mainwin);
-}
-
-static void summary_delete_duplicated_func(GtkCTree *ctree, GtkCTreeNode *node,
-                                          SummaryView *summaryview)
-{
-       GtkCTreeNode *found;
-       MsgInfo *msginfo;
-       MsgInfo *dup_msginfo;
-
-       msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
-       
-       if (!msginfo || !msginfo->msgid || !*msginfo->msgid) return;
-
-       found = g_hash_table_lookup(summaryview->msgid_table, msginfo->msgid);
-       
-       if (found && found != node) {
-               dup_msginfo = gtk_ctree_node_get_row_data(ctree, found);
-               /* prefer to delete the unread one */
-               if ((MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_UNREAD(dup_msginfo->flags))
-               ||  (MSG_IS_UNREAD(msginfo->flags) == MSG_IS_UNREAD(dup_msginfo->flags)))
-                       summary_delete_row(summaryview, node);
-       }
-}
-
 static void summary_unmark_row(SummaryView *summaryview, GtkCTreeNode *row)
 {
        GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
@@ -4018,11 +3977,38 @@ static void summary_filter_func(GtkCTree *ctree, GtkCTreeNode *node,
        filter_message_by_msginfo(filtering_rules, msginfo);
 }
 
-void summary_filter_open(SummaryView *summaryview, PrefsFilterType type)
+void summary_msginfo_filter_open(FolderItem * item, MsgInfo *msginfo,
+                                PrefsFilterType type, gint processing_rule)
 {
-       MsgInfo *msginfo;
        gchar *header = NULL;
        gchar *key = NULL;
+
+       procmsg_get_filter_keyword(msginfo, &header, &key, type);
+       
+       if (processing_rule) {
+               if (item == NULL)
+                       prefs_filtering_open(&pre_global_processing,
+                                            _("Processing rules to apply before folder rules"),
+                                            header, key);
+               else
+                       prefs_filtering_open(&item->prefs->processing,
+                                            _("Processing configuration"),
+                                            header, key);
+       }
+       else {
+               prefs_filtering_open(&filtering_rules,
+                                    _("Filtering configuration"),
+                                      header, key);
+       }
+       
+       g_free(header);
+       g_free(key);
+}
+
+void summary_filter_open(SummaryView *summaryview, PrefsFilterType type,
+                        gint processing_rule)
+{
+       MsgInfo *msginfo;
        FolderItem * item;
        
        if (!summaryview->selected) return;
@@ -4030,21 +4016,9 @@ void summary_filter_open(SummaryView *summaryview, PrefsFilterType type)
        msginfo = gtk_ctree_node_get_row_data(GTK_CTREE(summaryview->ctree),
                                              summaryview->selected);
        if (!msginfo) return;
-
-       procmsg_get_filter_keyword(msginfo, &header, &key, type);
        
        item = summaryview->folder_item;
-       if (item == NULL)
-               prefs_filtering_open(&pre_global_processing,
-                                    _("Processing rules to apply before folder rules"),
-                                    header, key);
-       else
-               prefs_filtering_open(&item->prefs->processing,
-                                    _("Processing configuration"),
-                                    header, key);
-
-       g_free(header);
-       g_free(key);
+       summary_msginfo_filter_open(item, msginfo, type, processing_rule);
 }
 
 /* color label */
@@ -4458,12 +4432,18 @@ static gint summary_key_pressed(GtkWidget *widget, GdkEventKey *event,
        GtkCTreeNode *node;
        MessageView *messageview;
        TextView *textview;
+       GtkAdjustment *adj;
 
        if (summary_is_locked(summaryview)) return TRUE;
        if (!event) return TRUE;
 
        switch (event->keyval) {
        case GDK_Left:          /* Move focus */
+               adj = gtk_scrolled_window_get_hadjustment
+                       (GTK_SCROLLED_WINDOW(summaryview->scrolledwin));
+               if (adj->lower != adj->value)
+                       break;
+               /* FALLTHROUGH */       
        case GDK_Escape:
                gtk_widget_grab_focus(summaryview->folderview->ctree);
                return TRUE;
@@ -4741,7 +4721,13 @@ static void summary_add_address_cb(SummaryView *summaryview,
 static void summary_create_filter_cb(SummaryView *summaryview,
                                     guint action, GtkWidget *widget)
 {
-       summary_filter_open(summaryview, (PrefsFilterType)action);
+       summary_filter_open(summaryview, (PrefsFilterType)action, 0);
+}
+
+static void summary_create_processing_cb(SummaryView *summaryview,
+                                        guint action, GtkWidget *widget)
+{
+       summary_filter_open(summaryview, (PrefsFilterType)action, 1);
 }
 
 static void summary_sort_by_column_click(SummaryView *summaryview,
@@ -4921,25 +4907,25 @@ CMP_FUNC_DEF(summary_cmp_by_to, to);
 
 #undef CMP_FUNC_DEF
 
-static gint summary_cmp_by_subject(GtkCList *clist,                     \
-                                  gconstpointer ptr1,                   \
-                                  gconstpointer ptr2)                   \
-{                                                                       \
-       MsgInfo *msginfo1 = ((GtkCListRow *)ptr1)->data;                 \
-       MsgInfo *msginfo2 = ((GtkCListRow *)ptr2)->data;                 \
-                                                                        \
-       if (!msginfo1->subject)                                          \
-               return (msginfo2->subject != NULL);                      \
-       if (!msginfo2->subject)                                          \
-               return -1;                                               \
-                                                                        \
-       return subject_compare_for_sort                                  \
-               (msginfo1->subject, msginfo2->subject);                  \
+static gint summary_cmp_by_subject(GtkCList *clist,
+                                  gconstpointer ptr1,
+                                  gconstpointer ptr2)
+{
+       MsgInfo *msginfo1 = ((GtkCListRow *)ptr1)->data;
+       MsgInfo *msginfo2 = ((GtkCListRow *)ptr2)->data;
+
+       if (!msginfo1->subject)
+               return (msginfo2->subject != NULL);
+       if (!msginfo2->subject)
+               return -1;
+
+       return subject_compare_for_sort
+               (msginfo1->subject, msginfo2->subject);
 }
 
- static gint summary_cmp_by_from(GtkCList *clist, gconstpointer ptr1,
-                                gconstpointer ptr2)
- {
+static gint summary_cmp_by_from(GtkCList *clist, gconstpointer ptr1,
+                               gconstpointer ptr2)
+{
        const gchar *str1, *str2;
        const GtkCListRow *r1 = (const GtkCListRow *) ptr1;
        const GtkCListRow *r2 = (const GtkCListRow *) ptr2;
@@ -4957,9 +4943,9 @@ static gint summary_cmp_by_subject(GtkCList *clist,                        \
                return -1;
  
        return strcasecmp(str1, str2);
- }
+}
  
- static gint summary_cmp_by_simplified_subject
+static gint summary_cmp_by_simplified_subject
        (GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
 {
        const FolderItemPrefs *prefs;
@@ -4988,7 +4974,7 @@ static gint summary_cmp_by_subject(GtkCList *clist,                        \
        if (!prefs)
                return -1;
        
-       return strcasecmp(str1, str2);
+       return subject_compare_for_sort(str1, str2);
 }
 
 static gint summary_cmp_by_score(GtkCList *clist,
@@ -5259,6 +5245,7 @@ void summary_reflect_prefs_pixmap_theme(SummaryView *summaryview)
 
        folderview_unselect(summaryview->folderview);
        folderview_select(summaryview->folderview, summaryview->folder_item);
+       summary_set_column_titles(summaryview);
 }
 
 /*