kill score / folder scoring / buf fixed for local account prefs
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Fri, 1 Jun 2001 11:06:33 +0000 (11:06 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Fri, 1 Jun 2001 11:06:33 +0000 (11:06 +0000)
15 files changed:
ChangeLog.claws
src/folderview.c
src/main.c
src/mainwindow.c
src/prefs_account.c
src/prefs_common.c
src/prefs_common.h
src/prefs_folder_item.c
src/prefs_folder_item.h
src/prefs_scoring.c
src/prefs_scoring.h
src/scoring.c
src/scoring.h
src/summaryview.c
src/summaryview.h

index c03e288..a7aa802 100644 (file)
@@ -1,3 +1,20 @@
+2001-06-01 [hoa]
+
+       * src/folderview.c
+       * src/prefs_folder_item.[ch]
+       * src/prefs_scoring.[ch]
+       * src/scoring.[ch]
+       * src/summaryview.[ch]
+       * src/main.c
+       * src/mainwindow.c
+       * src/prefs_common.[ch]
+               support for folder scoring
+               kill score and important score for messages
+       
+       * src/prefs_account.c
+               some display bug fixed for local account
+               preferences
+
 2001-05-31 [alfons]
 
        * src/summaryview.c:
index 8d7d7f5..ee55891 100644 (file)
@@ -204,6 +204,8 @@ static void folderview_drag_received_cb  (GtkWidget        *widget,
                                          guint             info,
                                          guint             time,
                                          FolderView       *folderview);
+static void folderview_scoring_cb(FolderView *folderview, guint action,
+                                 GtkWidget *widget);
 
 static GtkItemFactoryEntry folderview_mbox_popup_entries[] =
 {
@@ -213,7 +215,8 @@ static GtkItemFactoryEntry folderview_mbox_popup_entries[] =
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _mailbox"),        NULL, folderview_remove_mailbox_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Property..."),           NULL, NULL, 0, NULL}
+       {N_("/_Property..."),           NULL, NULL, 0, NULL},
+       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 static GtkItemFactoryEntry folderview_mail_popup_entries[] =
@@ -224,7 +227,8 @@ static GtkItemFactoryEntry folderview_mail_popup_entries[] =
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _mailbox"),        NULL, folderview_remove_mailbox_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Property..."),           NULL, NULL, 0, NULL}
+       {N_("/_Property..."),           NULL, NULL, 0, NULL},
+       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 static GtkItemFactoryEntry folderview_imap_popup_entries[] =
@@ -235,7 +239,8 @@ static GtkItemFactoryEntry folderview_imap_popup_entries[] =
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _IMAP4 server"),   NULL, folderview_rm_imap_server_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Property..."),           NULL, NULL, 0, NULL}
+       {N_("/_Property..."),           NULL, NULL, 0, NULL},
+       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 static GtkItemFactoryEntry folderview_news_popup_entries[] =
@@ -246,7 +251,8 @@ static GtkItemFactoryEntry folderview_news_popup_entries[] =
        {N_("/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/Remove _news server"),     NULL, folderview_rm_news_server_cb, 0, NULL},
        {N_("/---"),                     NULL, NULL, 0, "<Separator>"},
-       {N_("/_Property..."),            NULL, NULL, 0, NULL}
+       {N_("/_Property..."),            NULL, NULL, 0, NULL},
+       {N_("/_Scoring..."),            NULL, folderview_scoring_cb, 0, NULL}
 };
 
 
@@ -1133,6 +1139,8 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        } else if (folder->type == F_MH && item->stype != F_NORMAL) {
                menu_set_sensitive(folderview->mail_factory,
                                   "/Create new folder...", TRUE);
+               menu_set_sensitive(folderview->mail_factory,
+                                  "/Scoring...", TRUE);
        } else if (folder->type == F_MH) {
                menu_set_sensitive(folderview->mail_factory,
                                   "/Create new folder...", TRUE);
@@ -1140,6 +1148,8 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                                   "/Rename folder...", TRUE);
                menu_set_sensitive(folderview->mail_factory,
                                   "/Delete folder", TRUE);
+               menu_set_sensitive(folderview->mail_factory,
+                                  "/Scoring...", TRUE);
        } else if (folder->type == F_IMAP && item->parent == NULL) {
                menu_set_sensitive(folderview->imap_factory,
                                   "/Create new folder...", TRUE);
@@ -1150,6 +1160,8 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                                   "/Create new folder...", TRUE);
                menu_set_sensitive(folderview->imap_factory,
                                   "/Delete folder", TRUE);
+               menu_set_sensitive(folderview->imap_factory,
+                                  "/Scoring...", TRUE);
        } else if (folder->type == F_NEWS && item->parent == NULL) {
                menu_set_sensitive(folderview->news_factory,
                                   "/Subscribe to newsgroup...", TRUE);
@@ -1160,6 +1172,8 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                                   "/Subscribe to newsgroup...", TRUE);
                menu_set_sensitive(folderview->news_factory,
                                   "/Remove newsgroup", TRUE);
+               menu_set_sensitive(folderview->news_factory,
+                                  "/Scoring...", TRUE);
        }
        if (folder->type == F_MBOX && item->parent == NULL) {
                menu_set_sensitive(folderview->mbox_factory,
@@ -1169,6 +1183,8 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        } else if (folder->type == F_MBOX && item->stype != F_NORMAL) {
                menu_set_sensitive(folderview->mbox_factory,
                                   "/Create new folder...", TRUE);
+               menu_set_sensitive(folderview->mbox_factory,
+                                  "/Scoring...", TRUE);
        } else if (folder->type == F_MBOX) {
                menu_set_sensitive(folderview->mbox_factory,
                                   "/Create new folder...", TRUE);
@@ -1176,6 +1192,8 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                                   "/Rename folder...", TRUE);
                menu_set_sensitive(folderview->mbox_factory,
                                   "/Delete folder", TRUE);
+               menu_set_sensitive(folderview->mbox_factory,
+                                  "/Scoring...", TRUE);
        }
 
        if (folder->type == F_MH)
@@ -1986,3 +2004,18 @@ static gint folderview_compare_name(gconstpointer a, gconstpointer b)
        if (!item->path) return -1;
        return strcmp2(g_basename(item->path), name);
 }
+
+static void folderview_scoring_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_scoring_open(item);
+}
index b18dfe8..e7ab3ff 100644 (file)
@@ -231,7 +231,6 @@ int main(int argc, char *argv[])
        prefs_filter_write_config();
        prefs_display_header_read_config();
        prefs_display_header_write_config();
-       prefs_scoring_read_config();
        prefs_filtering_read_config();
 
        gtkut_widget_init();
@@ -253,6 +252,8 @@ int main(int argc, char *argv[])
        account_set_missing_folder();
        folderview_set(folderview);
 
+       prefs_scoring_read_config();
+
        inc_autocheck_timer_init(mainwin);
 
        if (cmd.receive_all || prefs_common.chk_on_startup)
index d77226a..c2353d1 100644 (file)
@@ -690,6 +690,10 @@ MainWindow *main_window_create(SeparateType type)
        folderview->color_normal.red = folderview->color_normal.green =
                folderview->color_normal.blue = 0;
 
+       summaryview->color_important.red = 0;
+       summaryview->color_marked.green = 0;
+       summaryview->color_important.blue = (guint16)65535;
+
        color[0] = summaryview->color_marked;
        color[1] = summaryview->color_dim;
        color[2] = summaryview->color_normal;
@@ -753,10 +757,14 @@ MainWindow *main_window_create(SeparateType type)
        gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
                                           GUINT_TO_POINTER(SEPARATE_MESSAGE));
 
+       /*
        menu_set_sensitive(ifactory, "/Summary/Thread view",
                           prefs_common.enable_thread ? FALSE : TRUE);
        menu_set_sensitive(ifactory, "/Summary/Unthread view",
                           prefs_common.enable_thread ? TRUE : FALSE);
+       */
+       main_window_set_thread_option(mainwin);
+
        menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
 
        /* set account selection menu */
@@ -2051,27 +2059,40 @@ static void set_charset_cb(MainWindow *mainwin, guint action,
 void main_window_set_thread_option(MainWindow *mainwin)
 {
        GtkItemFactory *ifactory;
+       gboolean no_item = FALSE;
 
        ifactory = gtk_item_factory_from_widget(mainwin->menubar);
 
-       if (mainwin->summaryview->folder_item->prefs->enable_thread) {
+       if (mainwin->summaryview == NULL)
+               no_item = TRUE;
+       else if (mainwin->summaryview->folder_item == NULL)
+               no_item = TRUE;
+
+       if (no_item) {
                menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
-               menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
-               summary_thread_build(mainwin->summaryview);
+               menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
        }
        else {
-               menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
-               menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
-               summary_unthread(mainwin->summaryview);
+               if (mainwin->summaryview->folder_item->prefs->enable_thread) {
+                       menu_set_sensitive(ifactory,
+                                          "/Summary/Thread view",   FALSE);
+                       menu_set_sensitive(ifactory,
+                                          "/Summary/Unthread view", TRUE);
+                       summary_thread_build(mainwin->summaryview);
+               }
+               else {
+                       menu_set_sensitive(ifactory,
+                                          "/Summary/Thread view",   TRUE);
+                       menu_set_sensitive(ifactory,
+                                          "/Summary/Unthread view", FALSE);
+                       summary_unthread(mainwin->summaryview);
+               }
+               prefs_folder_item_save_config(mainwin->summaryview->folder_item);
        }
-       prefs_folder_item_save_config(mainwin->summaryview->folder_item);
 }
 
 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
-       /*
-       ifactory = gtk_item_factory_from_widget(widget);
-       */
        mainwin->summaryview->folder_item->prefs->enable_thread =
                !mainwin->summaryview->folder_item->prefs->enable_thread;
        main_window_set_thread_option(mainwin);
@@ -2212,7 +2233,7 @@ static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
                                  GtkWidget *widget)
 {
-       prefs_scoring_open();
+       prefs_scoring_open(NULL);
 }
 
 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
index 19acf63..8fcccd9 100644 (file)
@@ -742,7 +742,7 @@ static void prefs_account_basic_create(void)
 
        localmbox_entry = gtk_entry_new ();
        gtk_widget_show (localmbox_entry);
-       gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 2, 3,
+       gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 0, 1,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
 
@@ -754,7 +754,7 @@ static void prefs_account_basic_create(void)
 
        mailcmd_entry = gtk_entry_new ();
        gtk_widget_show (mailcmd_entry);
-       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 5, 6,
+       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 7, 8,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
 
@@ -787,7 +787,7 @@ static void prefs_account_basic_create(void)
 
        localmbox_label = gtk_label_new (_("Local mailbox file"));
        gtk_widget_show (localmbox_label);
-       gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 2, 3,
+       gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 0, 1,
                          GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment (GTK_MISC (localmbox_label), 1, 0.5);
 /*     gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
@@ -802,7 +802,7 @@ static void prefs_account_basic_create(void)
        mailcmd_chkbtn = gtk_check_button_new_with_label
                (_("Use mail command rather than SMTP server"));
        gtk_widget_show (mailcmd_chkbtn);
-       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_chkbtn, 0, 4, 4, 5,
+       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_chkbtn, 0, 4, 6, 7,
                          GTK_EXPAND | GTK_FILL,
                          0, 0, TABLE_YPAD);
        gtk_signal_connect(GTK_OBJECT(mailcmd_chkbtn), "toggled",
@@ -811,7 +811,7 @@ static void prefs_account_basic_create(void)
 
        mailcmd_label = gtk_label_new (_("command to send mails"));
        gtk_widget_show (mailcmd_label);
-       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 5, 6,
+       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 7, 8,
                          GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment (GTK_MISC (mailcmd_label), 1, 0.5);
 /*     gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
@@ -1421,8 +1421,8 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_hide(basic.nntpauth_chkbtn);
                gtk_widget_set_sensitive(basic.recvserv_label, FALSE);
                gtk_widget_set_sensitive(basic.recvserv_entry, FALSE);
-               gtk_widget_show(basic.recvserv_label);
-               gtk_widget_show(basic.recvserv_entry);
+               gtk_widget_hide(basic.recvserv_label);
+               gtk_widget_hide(basic.recvserv_entry);
                gtk_widget_show(basic.smtpserv_label);
                gtk_widget_show(basic.smtpserv_entry);
                gtk_widget_show(basic.localmbox_label);
@@ -1432,10 +1432,10 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_show(basic.mailcmd_chkbtn);
 /*             gtk_table_set_row_spacing */
 /*                     (GTK_TABLE (basic.serv_table), 3, VSPACING_NARROW); */
-               gtk_widget_set_sensitive(basic.uid_label,  FALSE);
-               gtk_widget_set_sensitive(basic.pass_label, FALSE);
-               gtk_widget_set_sensitive(basic.uid_entry,  FALSE);
-               gtk_widget_set_sensitive(basic.pass_entry, FALSE);
+               gtk_widget_set_sensitive(basic.uid_label,  TRUE);
+               gtk_widget_set_sensitive(basic.pass_label, TRUE);
+               gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
+               gtk_widget_set_sensitive(basic.pass_entry, TRUE);
                gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
                prefs_account_mailcmd_toggled
                        (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
@@ -1555,4 +1555,8 @@ static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
        gtk_widget_set_sensitive(basic.mailcmd_label, use_mailcmd);
        gtk_widget_set_sensitive(basic.smtpserv_entry, !use_mailcmd);
        gtk_widget_set_sensitive(basic.smtpserv_label, !use_mailcmd);
+       gtk_widget_set_sensitive(basic.uid_label,  !use_mailcmd);
+       gtk_widget_set_sensitive(basic.pass_label, !use_mailcmd);
+       gtk_widget_set_sensitive(basic.uid_entry,  !use_mailcmd);
+       gtk_widget_set_sensitive(basic.pass_entry, !use_mailcmd);
 }
index fa39f40..336ac40 100644 (file)
@@ -317,8 +317,10 @@ static PrefParam param[] = {
         P_STRING, &display.entry_datefmt,
         prefs_set_data_from_entry, prefs_set_entry},
 
+       /*
        {"enable_thread", "TRUE", &prefs_common.enable_thread, P_BOOL,
         NULL, NULL, NULL},
+       */
        {"toolbar_style", "3", &prefs_common.toolbar_style, P_ENUM,
         NULL, NULL, NULL},
        {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL,
@@ -535,6 +537,11 @@ static PrefParam param[] = {
         &prefs_common.ext_editor_cmd, P_STRING,
         &other.exteditor_entry, prefs_set_data_from_entry, prefs_set_entry},
 
+       {"kill_score", "-9999", &prefs_common.kill_score, P_INT,
+        NULL, NULL, NULL},
+       {"important_score", "9999", &prefs_common.important_score, P_INT,
+        NULL, NULL, NULL},
+
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
index 0087a2d..b1637b9 100644 (file)
@@ -73,7 +73,7 @@ struct _PrefsCommon
        ToolbarStyle toolbar_style;
        gboolean show_statusbar;
        gboolean trans_hdr;
-       gboolean enable_thread;
+       /* gboolean enable_thread; */
        gboolean enable_hscrollbar;
        gboolean swap_from;
        gboolean use_addr_book;
@@ -82,6 +82,9 @@ struct _PrefsCommon
        /* Filtering */
        GSList *fltlist;
 
+       gint kill_score;
+       gint important_score;
+
        gboolean show_mark;
        gboolean show_unread;
        gboolean show_mime;
index 177883d..57b07e1 100644 (file)
@@ -23,38 +23,35 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"enable_thread", "TRUE", &tmp_prefs.enable_thread, P_BOOL,
         NULL, NULL, NULL},
+       {"kill_score", "-9999", &tmp_prefs.kill_score, P_INT,
+        NULL, NULL, NULL},
+       {"important_score", "9999", &tmp_prefs.important_score, P_INT,
+        NULL, NULL, NULL},
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
 void prefs_folder_item_read_config(FolderItem * item)
 {
-       gchar * path;
+       gchar * id;
+
+       id = folder_item_get_identifier(item);
 
-       path = folder_item_get_path(item);
-       /*
-       if (!is_dir_exist(path))
-               make_dir_hier(path);
-       */
-       prefs_read_config(param, path, FOLDERITEM_RC);
-       g_free(path);
+       prefs_read_config(param, id, FOLDERITEM_RC);
+       g_free(id);
 
        * item->prefs = tmp_prefs;
 }
 
 void prefs_folder_item_save_config(FolderItem * item)
 {      
-       gchar * path;
+       gchar * id;
 
        tmp_prefs = * item->prefs;
 
-       path = folder_item_get_path(item);
-       /*
-       if (!is_dir_exist(path))
-               make_dir_hier(path);
-       */
+       id = folder_item_get_identifier(item);
 
-       prefs_save_config(param, path, FOLDERITEM_RC);
-       g_free(path);
+       prefs_save_config(param, id, FOLDERITEM_RC);
+       g_free(id);
 }
 
 void prefs_folder_item_set_config(FolderItem * item,
@@ -107,6 +104,8 @@ PrefsFolderItem * prefs_folder_item_new(void)
        tmp_prefs.sort_by_subject = FALSE;
        tmp_prefs.sort_by_score = FALSE;
        tmp_prefs.sort_descending = FALSE;
+       tmp_prefs.kill_score = -9999;
+       tmp_prefs.important_score = 9999;
 
        * prefs = tmp_prefs;
        
@@ -115,6 +114,8 @@ PrefsFolderItem * prefs_folder_item_new(void)
 
 void prefs_folder_item_free(PrefsFolderItem * prefs)
 {
+       if (prefs->scoring != NULL)
+               prefs_scoring_free(prefs->scoring);
        g_free(prefs);
 }
 
index 6b03f52..8e62729 100644 (file)
@@ -19,7 +19,11 @@ struct _PrefsFolderItem {
 
        gboolean enable_thread;
 
+       gint kill_score;
+       gint important_score;
+
        GSList * scoring;
+       GSList * processing;
 };
 
 typedef struct _PrefsFolderItem PrefsFolderItem;
index 79e1018..abd329a 100644 (file)
@@ -53,6 +53,8 @@ static struct Scoring {
        GtkWidget *ok_btn;
        GtkWidget *cond_entry;
        GtkWidget *score_entry;
+       GtkWidget *kill_score_entry;
+       GtkWidget *important_score_entry;
 
        GtkWidget *cond_clist;
 } scoring;
@@ -101,7 +103,12 @@ static gint prefs_scoring_clist_set_row(gint row, ScoringProp * prop);
 static void prefs_scoring_select_set_dialog(ScoringProp * prop);
 static void prefs_scoring_reset_dialog(void);
 
-void prefs_scoring_open(void)
+
+static FolderItem * cur_item = NULL;
+static gint cur_important_score;
+static gint cur_kill_score;
+
+void prefs_scoring_open(FolderItem * item)
 {
        inc_autocheck_timer_remove();
 
@@ -112,6 +119,8 @@ void prefs_scoring_open(void)
        manage_window_set_transient(GTK_WINDOW(scoring.window));
        gtk_widget_grab_focus(scoring.ok_btn);
 
+       cur_item = item;
+
        prefs_scoring_set_dialog(NULL);
 
        gtk_widget_show(scoring.window);
@@ -165,6 +174,9 @@ static void prefs_scoring_create(void)
        GtkWidget *up_btn;
        GtkWidget *down_btn;
 
+       GtkWidget *important_score_entry;
+       GtkWidget *kill_score_entry;
+
        gchar *title[] = {_("Registered rules")};
 
        debug_print(_("Creating scoring setting window...\n"));
@@ -316,6 +328,32 @@ static void prefs_scoring_create(void)
        gtk_signal_connect (GTK_OBJECT (down_btn), "clicked",
                            GTK_SIGNAL_FUNC (prefs_scoring_down), NULL);
 
+       hbox1 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox1);
+       gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
+
+       score_label = gtk_label_new (_("Kill score"));
+       gtk_widget_show (score_label);
+       gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
+
+       kill_score_entry = gtk_entry_new ();
+       gtk_widget_show (kill_score_entry);
+       gtk_widget_set_usize (kill_score_entry, 50, -1);
+       gtk_box_pack_start (GTK_BOX (hbox1), kill_score_entry,
+                           FALSE, FALSE, 0);
+
+       score_label = gtk_label_new (_("Important score"));
+       gtk_widget_show (score_label);
+       gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
+
+       important_score_entry = gtk_entry_new ();
+       gtk_widget_show (important_score_entry);
+       gtk_widget_set_usize (important_score_entry, 50, -1);
+       gtk_box_pack_start (GTK_BOX (hbox1), important_score_entry,
+                           FALSE, FALSE, 0);
+
        gtk_widget_show_all(window);
 
        scoring.window    = window;
@@ -323,6 +361,8 @@ static void prefs_scoring_create(void)
 
        scoring.cond_entry = cond_entry;
        scoring.score_entry = score_entry;
+       scoring.kill_score_entry = kill_score_entry;
+       scoring.important_score_entry = important_score_entry;
 
        scoring.cond_clist   = cond_clist;
 }
@@ -331,6 +371,8 @@ static void prefs_scoring_set_dialog(ScoringProp * cond)
 {
        GtkCList *clist = GTK_CLIST(scoring.cond_clist);
        GSList *cur;
+       GSList * prefs_scoring;
+       gchar * score_str;
 
        if (cond == NULL)
                prefs_scoring_reset_dialog();
@@ -341,12 +383,31 @@ static void prefs_scoring_set_dialog(ScoringProp * cond)
        gtk_clist_clear(clist);
 
        prefs_scoring_clist_set_row(-1, NULL);
-       for(cur = prefs_scoring ; cur != NULL ; cur = g_slist_next(cur)) {
-               ScoringProp * prop = (ScoringProp *) cur->data;
+       if (cur_item == NULL) {
+               prefs_scoring = global_scoring;
+               cur_kill_score = prefs_common.kill_score;
+               cur_important_score = prefs_common.important_score;
+       }
+       else {
+               prefs_scoring = cur_item->prefs->scoring;
+               cur_kill_score = cur_item->prefs->kill_score;
+               cur_important_score = cur_item->prefs->important_score;
+       }
 
+       for(cur = prefs_scoring ; cur != NULL ;
+           cur = g_slist_next(cur)) {
+               ScoringProp * prop = (ScoringProp *) cur->data;
+               
                prefs_scoring_clist_set_row(-1, prop);
        }
 
+       score_str = itos(cur_kill_score);
+       gtk_entry_set_text(GTK_ENTRY(scoring.kill_score_entry),
+                          score_str);
+       score_str = itos(cur_important_score);
+       gtk_entry_set_text(GTK_ENTRY(scoring.important_score_entry),
+                          score_str);
+
        gtk_clist_thaw(clist);
 }
 
@@ -363,8 +424,15 @@ static void prefs_scoring_set_list(void)
        GSList * cur;
        gchar * scoring_str;
        gchar * tmp;
+       GSList * prefs_scoring;
+
+       if (cur_item == NULL)
+               prefs_scoring = global_scoring;
+       else
+               prefs_scoring = cur_item->prefs->scoring;
 
-       for(cur = prefs_scoring ; cur != NULL ; cur = g_slist_next(cur))
+       for(cur = prefs_scoring ; cur != NULL ;
+           cur = g_slist_next(cur))
                scoringprop_free((ScoringProp *) cur->data);
        g_slist_free(prefs_scoring);
        prefs_scoring = NULL;
@@ -380,6 +448,20 @@ static void prefs_scoring_set_list(void)
                }
                row++;
        }
+
+       cur_kill_score = atoi(gtk_entry_get_text(GTK_ENTRY(scoring.kill_score_entry)));
+       cur_important_score = atoi(gtk_entry_get_text(GTK_ENTRY(scoring.important_score_entry)));
+
+       if (cur_item == NULL) {
+               global_scoring = prefs_scoring;
+               prefs_common.kill_score = cur_kill_score;
+               prefs_common.important_score = cur_important_score;
+       }
+       else {
+               cur_item->prefs->scoring = prefs_scoring;
+               cur_item->prefs->kill_score = cur_kill_score;
+               cur_item->prefs->important_score = cur_important_score;
+       }
 }
 
 static gint prefs_scoring_clist_set_row(gint row, ScoringProp * prop)
@@ -643,6 +725,8 @@ static void prefs_scoring_ok(void)
 {
        prefs_scoring_set_list();
        prefs_scoring_write_config();
+       if (cur_item != NULL)
+               prefs_folder_item_save_config(cur_item);
        gtk_widget_hide(scoring.window);
 }
 
index f89089c..92d6dea 100644 (file)
 void prefs_scoring_read_config (void);
 void prefs_scoring_write_config        (void);
 */
+void prefs_scoring_open(FolderItem * item);
+     /*
 void prefs_scoring_open                (void);
+     */
 void prefs_scoring_open_with_scoring(ScoringProp * prop);
 
 #endif /* __PREFS_SCORING_H__ */
index dd93835..7b397cb 100644 (file)
 #include "matcher.h"
 #include "scoring.h"
 #include "prefs.h"
+#include "folder.h"
 
 #define PREFSBUFSIZE           1024
 
-GSList * prefs_scoring = NULL;
+
+GSList * global_scoring;
+/*
+gint global_kill_score = MIN_SCORE;
+gint global_important_score = MAX_SCORE;
+*/
 
 ScoringProp * scoringprop_parse(gchar ** str)
 {
@@ -136,6 +142,7 @@ static void scoringprop_print(ScoringProp * prop)
   if score is = MAX_SCORE (-999), no more match is done in the list
  */
 
+/*
 void prefs_scoring_read_config(void)
 {
        gchar *rcpath;
@@ -153,7 +160,6 @@ void prefs_scoring_read_config(void)
        }
        g_free(rcpath);
 
-       /* remove all scoring */
        while (prefs_scoring != NULL) {
                ScoringProp * scoring = (ScoringProp *) prefs_scoring->data;
                scoringprop_free(scoring);
@@ -174,7 +180,6 @@ void prefs_scoring_read_config(void)
                                                               scoring);
                        }
                        else {
-                               /* debug */
                                g_warning(_("syntax error : %s\n"), buf);
                        }
                }
@@ -182,6 +187,7 @@ void prefs_scoring_read_config(void)
 
        fclose(fp);
 }
+*/
 
 gchar * scoringprop_to_string(ScoringProp * prop)
 {
@@ -201,6 +207,7 @@ gchar * scoringprop_to_string(ScoringProp * prop)
        return scoring_str;
 }
 
+/*
 void prefs_scoring_write_config(void)
 {
        gchar *rcpath;
@@ -241,3 +248,196 @@ void prefs_scoring_write_config(void)
                return;
        }
 }
+*/
+
+void prefs_scoring_free(GSList * prefs_scoring)
+{
+       while (prefs_scoring != NULL) {
+               ScoringProp * scoring = (ScoringProp *) prefs_scoring->data;
+               scoringprop_free(scoring);
+               prefs_scoring = g_slist_remove(prefs_scoring, scoring);
+       }
+}
+
+static gboolean prefs_scoring_free_func(GNode *node, gpointer data)
+{
+       FolderItem *item = node->data;
+
+       prefs_scoring_free(item->prefs->scoring);
+       item->prefs->scoring = NULL;
+
+       return FALSE;
+}
+
+static void prefs_scoring_clear()
+{
+       GList * cur;
+
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_scoring_free_func, NULL);
+       }
+
+       prefs_scoring_free(global_scoring);
+       global_scoring = NULL;
+}
+
+void prefs_scoring_read_config(void)
+{
+       gchar *rcpath;
+       FILE *fp;
+       gchar buf[PREFSBUFSIZE];
+       GSList * prefs_scoring = NULL;
+       FolderItem * item = NULL;
+
+       debug_print(_("Reading headers configuration...\n"));
+
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, SCORING_RC, NULL);
+       if ((fp = fopen(rcpath, "r")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
+               g_free(rcpath);
+               prefs_scoring = NULL;
+               return;
+       }
+       g_free(rcpath);
+
+       prefs_scoring_clear();
+
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               ScoringProp * scoring;
+               gchar * tmp;
+
+               g_strchomp(buf);
+
+               if (g_strcasecmp(buf, "[global]") == 0) {
+                       if (item != NULL) {
+                               item->prefs->scoring = prefs_scoring;
+                               item = NULL;
+                               prefs_scoring = global_scoring;
+                       }
+               }
+               else if ((*buf == '[') && buf[strlen(buf) - 1] == ']') {
+                       gchar * id;
+
+                       if (item == NULL)
+                               global_scoring = prefs_scoring;
+                       else
+                               item->prefs->scoring = prefs_scoring;
+
+                       id = buf + 1;
+                       id[strlen(id) - 1] = '\0';
+
+                       item = folder_find_item_from_identifier(id);
+                       if (item == NULL)
+                               prefs_scoring = global_scoring;
+                       else
+                               prefs_scoring = item->prefs->scoring;
+               }
+               else if ((*buf != '#') && (*buf != '\0')) {
+                       tmp = buf;
+                       scoring = scoringprop_parse(&tmp);
+                       if (tmp != NULL) {
+                               prefs_scoring = g_slist_append(prefs_scoring,
+                                                              scoring);
+                       }
+                       else {
+                               /* debug */
+                               g_warning(_("syntax error : %s\n"), buf);
+                       }
+               }
+       }
+
+       if (item == NULL)
+               global_scoring = prefs_scoring;
+       else
+               item->prefs->scoring = prefs_scoring;
+
+       fclose(fp);
+}
+
+static void prefs_scoring_write(FILE * fp, GSList * prefs_scoring)
+{
+       GSList * cur;
+
+       for (cur = prefs_scoring; cur != NULL; cur = cur->next) {
+               gchar *scoring_str;
+               ScoringProp * prop;
+
+               prop = (ScoringProp *) cur->data;
+               scoring_str = scoringprop_to_string(prop);
+               if (fputs(scoring_str, fp) == EOF ||
+                   fputc('\n', fp) == EOF) {
+                       FILE_OP_ERROR("scoring config", "fputs || fputc");
+                       g_free(scoring_str);
+                       return;
+               }
+               g_free(scoring_str);
+       }
+}
+
+static gboolean prefs_scoring_write_func(GNode *node, gpointer data)
+{
+       FolderItem *item = node->data;
+       FILE * fp = data;
+
+       if (item->prefs->scoring != NULL) {
+               gchar * id = folder_item_get_identifier(item);
+
+               fprintf(fp, "[%s]\n", id);
+               g_free(id);
+
+               prefs_scoring_write(fp, item->prefs->scoring);
+
+               fputc('\n', fp);
+       }
+
+       return FALSE;
+}
+
+static void prefs_scoring_save(FILE * fp)
+{
+       GList * cur;
+
+       fputs("[global]\n", fp);
+       prefs_scoring_write(fp, global_scoring);
+       fputc('\n', fp);
+
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_scoring_write_func, fp);
+       }
+}
+
+void prefs_scoring_write_config(void)
+{
+       gchar *rcpath;
+       PrefFile *pfile;
+       GSList *cur;
+       ScoringProp * prop;
+
+       debug_print(_("Writing scoring configuration...\n"));
+
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, SCORING_RC, NULL);
+
+       if ((pfile = prefs_write_open(rcpath)) == NULL) {
+               g_warning(_("failed to write configuration to file\n"));
+               g_free(rcpath);
+               return;
+       }
+
+
+       prefs_scoring_save(pfile->fp);
+
+       g_free(rcpath);
+
+       if (prefs_write_close(pfile) < 0) {
+               g_warning(_("failed to write configuration to file\n"));
+               return;
+       }
+}
index 2602e34..e8627ac 100644 (file)
@@ -16,8 +16,9 @@ struct _ScoringProp {
 
 typedef struct _ScoringProp ScoringProp;
 
-extern GSList * prefs_scoring;
-
+extern GSList * global_scoring;
+extern gint global_kill_score;
+extern gint global_important_score;
 
 ScoringProp * scoringprop_new(MatcherList * matchers, int score);
 void scoringprop_free(ScoringProp * prop);
@@ -32,4 +33,6 @@ void prefs_scoring_write_config(void);
 void prefs_scoring_read_config(void);
 gchar * scoringprop_to_string(ScoringProp * prop);
 
+void prefs_scoring_free(GSList * prefs_scoring);
+
 #endif
index 8aa41fe..6d62ca4 100644 (file)
@@ -575,6 +575,68 @@ void summary_init(SummaryView *summaryview)
        summary_set_menu_sensitive(summaryview);
 }
 
+GtkCTreeNode * summary_find_next_important_score(SummaryView *summaryview,
+                                                GtkCTreeNode *current_node)
+{
+       GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
+       GtkCTreeNode *node;
+       MsgInfo *msginfo;
+       gint best_score = MIN_SCORE;
+       GtkCTreeNode *best_node = NULL;
+
+       if (current_node)
+               //node = current_node;
+               node = GTK_CTREE_NODE_NEXT(current_node);
+       else
+               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
+
+       for (; node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
+               msginfo = gtk_ctree_node_get_row_data(ctree, node);
+               if (msginfo->score >= summaryview->important_score)
+                       break;
+               if (msginfo->score > best_score) {
+                       best_score = msginfo->score;
+                       best_node = node;
+               }
+       }
+
+       if (node != NULL)
+               return node;
+       else
+               return best_node;
+}
+
+GtkCTreeNode * summary_find_prev_important_score(SummaryView *summaryview,
+                                                GtkCTreeNode *current_node)
+{
+       GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
+       GtkCTreeNode *node;
+       MsgInfo *msginfo;
+       gint best_score = MIN_SCORE;
+       GtkCTreeNode *best_node = NULL;
+
+       if (current_node)
+               //node = current_node;
+               node = GTK_CTREE_NODE_PREV(current_node);
+       else
+               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
+
+       for (; node != NULL; node = GTK_CTREE_NODE_PREV(node)) {
+               msginfo = gtk_ctree_node_get_row_data(ctree, node);
+               if (msginfo->score >= summaryview->important_score)
+                       break;
+               if (msginfo->score > best_score) {
+                       best_score = msginfo->score;
+                       best_node = node;
+               }
+       }
+
+       if (node != NULL)
+               return node;
+       else
+               return best_node;
+}
+
 gboolean summary_show(SummaryView *summaryview, FolderItem *item,
                      gboolean update_cache)
 {
@@ -653,7 +715,36 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
        for(cur = mlist ; cur != NULL ; cur = g_slist_next(cur)) {
                MsgInfo * msginfo = (MsgInfo *) cur->data;
 
-               msginfo->score = score_message(prefs_scoring, msginfo);
+               msginfo->score = score_message(global_scoring, msginfo);
+               if (msginfo->score != MAX_SCORE &&
+                   msginfo->score != MIN_SCORE) {
+                       msginfo->score += score_message(item->prefs->scoring,
+                                                       msginfo);
+               }
+       }
+
+       summaryview->killed_messages = NULL;
+       if ((global_scoring || item->prefs->scoring) &&
+           (item->folder->type == F_NEWS)) {
+               GSList *not_killed;
+               gint kill_score;
+
+               not_killed = NULL;
+               kill_score = prefs_common.kill_score;
+               if (item->prefs->kill_score > kill_score)
+                       kill_score = item->prefs->kill_score;
+               for(cur = mlist ; cur != NULL ; cur = g_slist_next(cur)) {
+                       MsgInfo * msginfo = (MsgInfo *) cur->data;
+
+                       if (MSG_IS_NEWS(msginfo->flags) &&
+                           (msginfo->score <= kill_score))
+                               summaryview->killed_messages = g_slist_append(summaryview->killed_messages, msginfo);
+                       else
+                               not_killed = g_slist_append(not_killed,
+                                                           msginfo);
+               }
+               g_slist_free(mlist);
+               mlist = not_killed;
        }
 
        STATUSBAR_POP(summaryview->mainwin);
@@ -691,11 +782,30 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
        
        gtk_clist_thaw(GTK_CLIST(ctree));
 
+       /* sort before */
+       sort_mode = prefs_folder_item_get_sort_mode(item);
+       sort_type = prefs_folder_item_get_sort_type(item);
+
+       if (sort_mode != SORT_BY_NONE) {
+               summaryview->sort_mode = sort_mode;
+               if (sort_type == GTK_SORT_DESCENDING)
+                       summaryview->sort_type = GTK_SORT_ASCENDING;
+               else
+                       summaryview->sort_type = GTK_SORT_DESCENDING;
+
+               summary_sort(summaryview, sort_mode);
+       }
+
        if (is_refresh) {
                summary_select_by_msgnum(summaryview, prev_msgnum);
        } else {
                /* select first unread message */
-               node = summary_find_next_unread_msg(summaryview, NULL);
+               if (sort_mode == SORT_BY_SCORE)
+                       node = summary_find_next_important_score(summaryview,
+                                                                NULL);
+               else
+                       node = summary_find_next_unread_msg(summaryview, NULL);
+
                if (node == NULL && GTK_CLIST(ctree)->row_list != NULL)
                        node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list_end);
                if (node) {
@@ -720,20 +830,6 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
 
        main_window_cursor_normal(summaryview->mainwin);
 
-       /* sort before */
-       sort_mode = prefs_folder_item_get_sort_mode(item);
-       sort_type = prefs_folder_item_get_sort_type(item);
-
-       if (sort_mode != SORT_BY_NONE) {
-               summaryview->sort_mode = sort_mode;
-               if (sort_type == GTK_SORT_DESCENDING)
-                       summaryview->sort_type = GTK_SORT_ASCENDING;
-               else
-                       summaryview->sort_type = GTK_SORT_DESCENDING;
-
-               summary_sort(summaryview, sort_mode);
-       }
-
        return TRUE;
 }
 
@@ -741,9 +837,19 @@ void summary_clear_list(SummaryView *summaryview)
 {
        GtkCList *clist = GTK_CLIST(summaryview->ctree);
        gint optimal_width;
+       GSList * cur;
 
        gtk_clist_freeze(clist);
 
+       for(cur = summaryview->killed_messages ; cur != NULL ; 
+           cur = g_slist_next(cur)) {
+               MsgInfo * msginfo = (MsgInfo *) cur->data;
+
+               procmsg_msginfo_free(msginfo);
+       }
+       g_slist_free(summaryview->killed_messages);
+       summaryview->killed_messages = NULL;
+
        gtk_ctree_pre_recursive(GTK_CTREE(summaryview->ctree),
                                NULL, summary_free_msginfo_func, NULL);
 
@@ -1405,6 +1511,14 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
                msginfo->threadscore = msginfo->score;
        }
 
+       if (global_scoring || summaryview->folder_item->prefs->scoring) {
+               summaryview->important_score = prefs_common.important_score;
+               if (summaryview->folder_item->prefs->important_score <
+                   summaryview->important_score)
+                       summaryview->important_score =
+                               summaryview->folder_item->prefs->important_score;
+       }
+       
        /*      if (prefs_common.enable_thread) { */
        if (summaryview->folder_item->prefs->enable_thread) {
                for (; mlist != NULL; mlist = mlist->next) {
@@ -1423,6 +1537,7 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
                                (ctree, parent, NULL, text, 2,
                                 NULL, NULL, NULL, NULL, FALSE, TRUE);
                        GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
+
                        summary_set_marks_func(ctree, node, summaryview);
 
                        /* preserve previous node if the message is
@@ -1515,6 +1630,7 @@ gint summary_write_cache(SummaryView *summaryview)
        gint ver = CACHE_VERSION;
        gchar *buf;
        gchar *cachefile, *markfile;
+       GSList * cur;
 
        if (!summaryview->folder_item || !summaryview->folder_item->path)
                return -1;
@@ -1556,6 +1672,14 @@ gint summary_write_cache(SummaryView *summaryview)
 
        gtk_ctree_pre_recursive(ctree, NULL, summary_write_cache_func, &fps);
 
+       for(cur = summaryview->killed_messages ; cur != NULL ;
+           cur = g_slist_next(cur)) {
+               MsgInfo *msginfo = (MsgInfo *) cur->data;
+
+               procmsg_write_cache(msginfo, fps.cache_fp);
+               procmsg_write_flags(msginfo, fps.mark_fp);
+       }
+
        fclose(fps.cache_fp);
        fclose(fps.mark_fp);
 
@@ -1868,6 +1992,15 @@ static void summary_set_row_marks(SummaryView *summaryview, GtkCTreeNode *row)
                gtk_ctree_node_set_text(ctree, row, S_COL_MARK, "O");
                gtk_ctree_node_set_foreground(ctree, row,
                                              &summaryview->color_marked);
+       }
+       else if ((global_scoring ||
+                 summaryview->folder_item->prefs->scoring) &&
+                (msginfo->score >= summaryview->important_score) &&
+                ((msginfo->flags &
+                  (MSG_MARKED | MSG_MOVE | MSG_COPY)) == 0)) {
+               gtk_ctree_node_set_text(ctree, row, S_COL_MARK, "!");
+               gtk_ctree_node_set_foreground(ctree, row,
+                                             &summaryview->color_important);
        } else {
                gtk_ctree_node_set_text(ctree, row, S_COL_MARK, NULL);
        }
index 19f5008..afd3b79 100644 (file)
@@ -102,6 +102,7 @@ struct _SummaryView
        gboolean msg_is_toggled_on;
        gboolean display_msg;
 
+       GdkColor color_important;
        GdkColor color_marked;
        GdkColor color_dim;
        GdkColor color_normal;
@@ -114,6 +115,9 @@ struct _SummaryView
 
        FolderItem *folder_item;
 
+       GSList * killed_messages;
+       gint important_score;
+
        /* current message status */
        gint   newmsgs;
        gint   unread;