scoring dialog box finished
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Thu, 10 May 2001 23:00:27 +0000 (23:00 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Thu, 10 May 2001 23:00:27 +0000 (23:00 +0000)
19 files changed:
ChangeLog.claws
src/Makefile.am
src/grouplist_dialog.c
src/main.c
src/mainwindow.c
src/mainwindow.h
src/matcher.c
src/matcher.h
src/messageview.c
src/news.c
src/prefs_account.c
src/prefs_display_header.c
src/prefs_matcher.c
src/prefs_matcher.h
src/prefs_scoring.c [new file with mode: 0644]
src/prefs_scoring.h [new file with mode: 0644]
src/scoring.c
src/scoring.h
src/summaryview.c

index c86762d..1e79072 100644 (file)
@@ -1,3 +1,35 @@
+2001-05-11 [hoa]
+
+       * src/main.c
+       * src/messageview.c
+       * src/prefs_account.c
+       * src/prefs_display_header.c
+               removed warning
+       * src/Makefile.am
+               added prefs_scoring.[ch]
+       * src/grouplist_dialog.c
+               display an error dialog box if the group list
+               cannot be fetched.
+       * src/mainwindow.[ch]
+               added main_window_set_thread_option() function
+               scoring dialog box enabled
+       * src/matcher.[ch]
+               added flags matching unread /new / marked
+               / deleted / replied / forwarded
+       * src/news.c
+               newsgroups are now finally in newscache
+       * src/prefs_matcher.[ch]
+               finished preferences for matching dialog
+       * added src/prefs_scoring.[ch]
+               scoring dialog box completed
+       * src/scoring.[ch]
+               conversion to string : added scoringprop_to_string()
+               write config for preferences :
+               added prefs_scoring_write_config()
+       * src/summaryview.c
+               threads can be enabled/disabled independently
+               for each folder
+
 2001-05-10 [alfons]
 
        0.4.67claws1
index 84667a5..b8c8be1 100644 (file)
@@ -82,7 +82,8 @@ sylpheed_SOURCES = \
        scoring.c scoring.h \
        prefs_folder_item.c prefs_folder_item.h \
        matcher.c matcher.h \
-       prefs_matcher.c prefs_matcher.h
+       prefs_matcher.c prefs_matcher.h \
+       prefs_scoring.c prefs_scoring.h
 
 EXTRA_DIST = \
        pixmaps/clip.xpm \
index 882a72c..8bd650a 100644 (file)
@@ -202,6 +202,10 @@ static void grouplist_dialog_set_list(void)
 
        group_selected = NULL;
        group_list = news_get_group_list(item);
+       if (group_list == NULL) {
+               alertpanel_error(_("Can't retrieve group list."));
+               return;
+       }
 
        gtk_clist_clear(GTK_CLIST(group_clist));
        for(elt = group_list; elt != NULL ; elt = elt->next)
index c9147cd..7173d11 100644 (file)
@@ -57,6 +57,7 @@
 #include "prefs_common.h"
 #include "prefs_filter.h"
 #include "prefs_account.h"
+#include "scoring.h"
 #include "prefs_display_header.h"
 #include "account.h"
 #include "procmsg.h"
index 0049f04..66fd45b 100644 (file)
@@ -57,7 +57,9 @@
 #include "export.h"
 #include "prefs_common.h"
 #include "prefs_filter.h"
+#include "prefs_scoring.h"
 #include "prefs_account.h"
+#include "prefs_folder_item.h"
 #include "account.h"
 #include "addressbook.h"
 #include "headerwindow.h"
@@ -318,7 +320,7 @@ static void prefs_common_open_cb (MainWindow        *mainwin,
 static void prefs_filter_open_cb (MainWindow   *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
-static void prefs_matcher_open_cb (MainWindow  *mainwin,
+static void prefs_scoring_open_cb (MainWindow  *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 static void prefs_account_open_cb(MainWindow   *mainwin,
@@ -522,7 +524,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Configuration/_Filter setting..."),
                                                NULL, prefs_filter_open_cb, 0, NULL},
        {N_("/_Configuration/_Scoring ..."),
-                                               NULL, prefs_matcher_open_cb, 0, NULL},
+                                               NULL, prefs_scoring_open_cb, 0, NULL},
        {N_("/_Configuration/_Preferences per account..."),
                                                NULL, prefs_account_open_cb, 0, NULL},
        {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
@@ -1921,23 +1923,49 @@ static void set_charset_cb(MainWindow *mainwin, guint action,
        debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
 }
 
-static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+void main_window_set_thread_option(MainWindow *mainwin)
 {
        GtkItemFactory *ifactory;
 
+       ifactory = gtk_item_factory_from_widget(mainwin->menubar);
+
+       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);
+}
+
+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);
 
+       /*
        if (0 == action) {
                summary_thread_build(mainwin->summaryview);
-               prefs_common.enable_thread = TRUE;
+               mainwin->summaryview->folder_item->prefs->enable_thread =
+                       TRUE;
                menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
                menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
        } else {
                summary_unthread(mainwin->summaryview);
-               prefs_common.enable_thread = FALSE;
+               mainwin->summaryview->folder_item->prefs->enable_thread =
+                       FALSE;
                menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
                menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
        }
+       */
 }
 
 static void set_display_item_cb(MainWindow *mainwin, guint action,
@@ -2056,10 +2084,10 @@ static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
        prefs_filter_open();
 }
 
-static void prefs_matcher_open_cb(MainWindow *mainwin, guint action,
+static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
                                  GtkWidget *widget)
 {
-       prefs_matcher_open(NULL);
+       prefs_scoring_open();
 }
 
 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
index b7028fa..a1c816c 100644 (file)
@@ -133,5 +133,6 @@ void main_window_set_toolbar_sensitive      (MainWindow     *mainwin,
 void main_window_set_menu_sensitive    (MainWindow     *mainwin,
                                         gint            selection);
 void main_window_popup                 (MainWindow     *mainwin);
+void main_window_set_thread_option      (MainWindow *mainwin);
 
 #endif /* __MAINWINDOW_H__ */
index dbb4922..284f291 100644 (file)
@@ -15,8 +15,22 @@ struct _MatchParser {
 typedef struct _MatchParser MatchParser;
 
 MatchParser matchparser_tab[] = {
-       /* msginfo */
+       /* msginfo flags */
        {MATCHING_ALL, "all"},
+       {MATCHING_UNREAD, "unread"},
+       {MATCHING_NOT_UNREAD, "~unread"},
+       {MATCHING_NEW, "new"},
+       {MATCHING_NOT_NEW, "~new"},
+       {MATCHING_MARKED, "marked"},
+       {MATCHING_NOT_MARKED, "~marked"},
+       {MATCHING_DELETED, "deleted"},
+       {MATCHING_NOT_DELETED, "~deleted"},
+       {MATCHING_REPLIED, "replied"},
+       {MATCHING_NOT_REPLIED, "~replied"},
+       {MATCHING_FORWARDED, "forwarded"},
+       {MATCHING_NOT_FORWARDED, "~forwarded"},
+
+       /* msginfo headers */
        {MATCHING_SUBJECT, "subject"},
        {MATCHING_NOT_SUBJECT, "~subject"},
        {MATCHING_FROM, "from"},
@@ -103,6 +117,18 @@ MatcherProp * matcherprop_parse(gchar ** str)
                return prop;
 
        case MATCHING_ALL:
+       case MATCHING_UNREAD:
+       case MATCHING_NOT_UNREAD:
+       case MATCHING_NEW:
+       case MATCHING_NOT_NEW:
+       case MATCHING_MARKED:
+       case MATCHING_NOT_MARKED:
+       case MATCHING_DELETED:
+       case MATCHING_NOT_DELETED:
+       case MATCHING_REPLIED:
+       case MATCHING_NOT_REPLIED:
+       case MATCHING_FORWARDED:
+       case MATCHING_NOT_FORWARDED:
                prop = matcherprop_new(key, NULL, 0, NULL, 0);
                *str = tmp;
 
@@ -201,13 +227,15 @@ gint matcher_parse_keyword(gchar ** str)
                p++;
 
        start = p;
+
+       while (!matcher_is_blank(*p) && (*p != '\0'))
+               p++;
        
        match = -1;
        for(i = 0 ; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)) ;
            i++) {
-               if (strncasecmp(matchparser_tab[i].str, p,
-                               strlen(matchparser_tab[i].str)) == 0) {
-                       p += strlen(matchparser_tab[i].str);
+               if (strncasecmp(matchparser_tab[i].str, start,
+                               p - start) == 0) {
                        match = i;
                        break;
                }
@@ -392,9 +420,10 @@ void matcherprop_free(MatcherProp * prop)
 static gboolean matcherprop_string_match(MatcherProp * prop, gchar * str)
 {
        gchar * str1;
+       gchar * str2;
 
        if (str == NULL)
-               str = "";
+               return FALSE;
 
        switch(prop->matchtype) {
        case MATCHING_REGEXP:
@@ -410,25 +439,27 @@ static gboolean matcherprop_string_match(MatcherProp * prop, gchar * str)
                        }
                }
                if (prop->preg == NULL)
-                       return 0;
+                       return FALSE;
                
                if (regexec(prop->preg, str, 0, NULL, 0) == 0)
-                       return 1;
+                       return TRUE;
                else
-                       return 0;
+                       return FALSE;
 
        case MATCHING_MATCH:
                return (strstr(str, prop->expr) != NULL);
 
        case MATCHING_MATCHCASE:
-               g_strup(prop->expr);
+               str2 = alloca(strlen(prop->expr) + 1);
+               strcpy(str2, prop->expr);
+               g_strup(str2);
                str1 = alloca(strlen(str) + 1);
                strcpy(str1, str);
                g_strup(str1);
-               return (strstr(str1, prop->expr) != NULL);
+               return (strstr(str1, str2) != NULL);
                
        default:
-               return 0;
+               return FALSE;
        }
 }
 
@@ -442,6 +473,30 @@ gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info)
        switch(prop->criteria) {
        case MATCHING_ALL:
                return 1;
+       case MATCHING_UNREAD:
+               return MSG_IS_UNREAD(info->flags);
+       case MATCHING_NOT_UNREAD:
+               return !MSG_IS_UNREAD(info->flags);
+       case MATCHING_NEW:
+               return MSG_IS_NEW(info->flags);
+       case MATCHING_NOT_NEW:
+               return !MSG_IS_NEW(info->flags);
+       case MATCHING_MARKED:
+               return MSG_IS_MARKED(info->flags);
+       case MATCHING_NOT_MARKED:
+               return !MSG_IS_MARKED(info->flags);
+       case MATCHING_DELETED:
+               return MSG_IS_DELETED(info->flags);
+       case MATCHING_NOT_DELETED:
+               return !MSG_IS_DELETED(info->flags);
+       case MATCHING_REPLIED:
+               return MSG_IS_REPLIED(info->flags);
+       case MATCHING_NOT_REPLIED:
+               return !MSG_IS_REPLIED(info->flags);
+       case MATCHING_FORWARDED:
+               return MSG_IS_FORWARDED(info->flags);
+       case MATCHING_NOT_FORWARDED:
+               return !MSG_IS_FORWARDED(info->flags);
        case MATCHING_SUBJECT:
                return matcherprop_string_match(prop, info->subject);
        case MATCHING_NOT_SUBJECT:
@@ -494,10 +549,12 @@ MatcherList * matcherlist_parse(gchar ** str)
        gchar * save;
        MatcherList * cond;
        gboolean main_bool_and = TRUE;
+       GSList * l;
 
        tmp = * str;
 
        matcher = matcherprop_parse(&tmp);
+
        if (tmp == NULL) {
                * str = NULL;
                return NULL;
@@ -518,6 +575,11 @@ MatcherList * matcherlist_parse(gchar ** str)
                                        g_slist_append(matchers_list, matcher);
                        }
                        else {
+                               for(l = matchers_list ; l != NULL ;
+                                   l = g_slist_next(l))
+                                       matcherprop_free((MatcherProp *)
+                                                        l->data);
+                               g_slist_free(matchers_list);
                                * str = NULL;
                                return NULL;
                        }
@@ -546,6 +608,7 @@ MatcherList * matcherlist_new(GSList * matchers, gboolean bool_and)
 void matcherlist_free(MatcherList * cond)
 {
        GSList * l;
+
        for(l = cond->matchers ; l != NULL ; l = g_slist_next(l)) {
                matcherprop_free((MatcherProp *) l->data);
        }
@@ -914,7 +977,7 @@ static void matcherprop_print(MatcherProp * matcher)
 
 gchar * matcherprop_to_string(MatcherProp * matcher)
 {
-       gchar * matcher_str;
+       gchar * matcher_str = NULL;
        gchar * criteria_str;
        gchar * matchtype_str;
        int i;
@@ -938,6 +1001,18 @@ gchar * matcherprop_to_string(MatcherProp * matcher)
                return g_strdup_printf("%s %i", criteria_str, matcher->age);
                break;
        case MATCHING_ALL:
+       case MATCHING_UNREAD:
+       case MATCHING_NOT_UNREAD:
+       case MATCHING_NEW:
+       case MATCHING_NOT_NEW:
+       case MATCHING_MARKED:
+       case MATCHING_NOT_MARKED:
+       case MATCHING_DELETED:
+       case MATCHING_NOT_DELETED:
+       case MATCHING_REPLIED:
+       case MATCHING_NOT_REPLIED:
+       case MATCHING_FORWARDED:
+       case MATCHING_NOT_FORWARDED:
                return g_strdup(criteria_str);
        }
 
index 85c7761..0b1de6a 100644 (file)
@@ -8,7 +8,22 @@
 #include "procmsg.h"
 
 enum {
+       /* msginfo flags */
        MATCHING_ALL,
+       MATCHING_UNREAD,
+       MATCHING_NOT_UNREAD,
+       MATCHING_NEW,
+       MATCHING_NOT_NEW,
+       MATCHING_MARKED,
+       MATCHING_NOT_MARKED,
+       MATCHING_DELETED,
+       MATCHING_NOT_DELETED,
+       MATCHING_REPLIED,
+       MATCHING_NOT_REPLIED,
+       MATCHING_FORWARDED,
+       MATCHING_NOT_FORWARDED,
+
+       /* msginfo headers */
        MATCHING_SUBJECT,
        MATCHING_NOT_SUBJECT,
        MATCHING_FROM,
@@ -23,6 +38,8 @@ enum {
        MATCHING_AGE_LOWER,
        MATCHING_NEWSGROUPS,
        MATCHING_NOT_NEWSGROUPS,
+
+       /* file content */
        MATCHING_HEADER,
        MATCHING_NOT_HEADER,
        MATCHING_MESSAGE,
@@ -31,7 +48,9 @@ enum {
        MATCHING_NOT_HEADERS_PART,
        MATCHING_BODY_PART,
        MATCHING_NOT_BODY_PART,
+
        MATCHING_SCORE,
+
        MATCHING_MATCH,
        MATCHING_REGEXP,
        MATCHING_MATCHCASE,
index b50b3b2..7322fb9 100644 (file)
@@ -46,6 +46,7 @@
 #include "rfc2015.h"
 #include "account.h"
 #include "alertpanel.h"
+#include "send.h"
 
 static void messageview_change_view_type(MessageView   *messageview,
                                         MessageType     type);
index 08fa7c0..f970e2d 100644 (file)
@@ -439,6 +439,7 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
 
                msginfo->folder = item;
                msginfo->flags = MSG_NEW|MSG_UNREAD|MSG_NEWS;
+               msginfo->newsgroups = g_strdup(item->path);
 
                if (!newlist)
                        llast = newlist = g_slist_append(newlist, msginfo);
index fc7ef41..9522fa0 100644 (file)
@@ -44,6 +44,7 @@
 #include "gtkutils.h"
 #include "utils.h"
 #include "alertpanel.h"
+#include "prefs_headers.h"
 
 static gboolean cancelled;
 
index 36a97a6..3a7dde2 100644 (file)
@@ -125,7 +125,7 @@ static void prefs_display_header_set_default(void)
        gint i;
        DisplayHeaderProp *dp;
 
-       for(i = 0; i < sizeof(defaults) / sizeof(defaults[0]); i++) {
+       for(i = 0; i < (gint) (sizeof(defaults) / sizeof(defaults[0])); i++) {
                dp = display_header_prop_read_str(defaults[i]);
                prefs_common.disphdr_list =
                        g_slist_append(prefs_common.disphdr_list, dp);
index 4800c69..62e9414 100644 (file)
@@ -52,17 +52,21 @@ static struct Matcher {
        GtkWidget *ok_btn;
 
        GtkWidget *predicate_combo;
+       GtkWidget *predicate_flag_combo;
        GtkWidget *header_combo;
 
        GtkWidget *criteria_list;
+
        GtkWidget *predicate_list;
+       GtkWidget *predicate_label;
+       GtkWidget *predicate_flag_list;
+
        GtkWidget *bool_op_list;
 
        GtkWidget *header_entry;
        GtkWidget *header_label;
        GtkWidget *value_entry;
        GtkWidget *value_label;
-       GtkWidget *predicate_label;
        GtkWidget *case_chkbtn;
        GtkWidget *regexp_chkbtn;
 
@@ -73,6 +77,7 @@ static struct Matcher {
 
 enum {
        CRITERIA_ALL = 0,
+
        CRITERIA_SUBJECT = 1,
        CRITERIA_FROM = 2,
        CRITERIA_TO = 3,
@@ -84,24 +89,53 @@ enum {
        CRITERIA_HEADER = 9,
        CRITERIA_HEADERS_PART = 10,
        CRITERIA_BODY_PART = 11,
-       CRITERIA_MESSAGE = 12
+       CRITERIA_MESSAGE = 12,
+
+       CRITERIA_UNREAD = 13,
+       CRITERIA_NEW = 14,
+       CRITERIA_MARKED = 15,
+       CRITERIA_DELETED = 16,
+       CRITERIA_REPLIED = 17,
+       CRITERIA_FORWARDED = 18
+};
+
+enum {
+       BOOL_OP_OR = 0,
+       BOOL_OP_AND = 1
 };
 
 gchar * bool_op_text [] = {
        "or", "and"
 };
 
+enum {
+       PREDICATE_CONTAINS = 0,
+       PREDICATE_DOES_NOT_CONTAIN = 1
+};
+
 gchar * predicate_text [] = {
        "contains", "does not contain"
 };
 
+enum {
+       PREDICATE_FLAG_ENABLED = 0,
+       PREDICATE_FLAG_DISABLED = 1
+};
+
+gchar * predicate_flag_text [] = {
+       "flag enabled", "flag disabled"
+};
+
 gchar * criteria_text [] = {
        "All messages", "Subject",
        "From", "To", "Cc", "To or Cc",
        "Newsgroups",
        "Age greater than", "Age lower than",
        "Header", "Headers part",
-       "Body part", "Whole message"
+       "Body part", "Whole message",
+       "Unread flag", "New flag",
+       "Marked flag", "Deleted flag",
+       "Replied flag", "Forwarded flag"
 };
 
 gint get_sel_from_list(GtkList * list)
@@ -121,12 +155,7 @@ gint get_sel_from_list(GtkList * list)
        return row;
 }
 
-enum {
-       PREDICATE_CONTAINS = 0,
-       PREDICATE_DOES_NOT_CONTAIN = 1
-};
-
-static MatcherList * tmp_matchers;
+static PrefsMatcherSignal * matchers_callback;
 
 #define VSPACING               12
 #define VSPACING_NARROW                4
@@ -136,7 +165,7 @@ static MatcherList * tmp_matchers;
 /* widget creating functions */
 static void prefs_matcher_create       (void);
 
-static void prefs_matcher_set_dialog   (void);
+static void prefs_matcher_set_dialog   (MatcherList * matchers);
 
 /*
 static void prefs_matcher_set_list     (void);
@@ -168,9 +197,9 @@ static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
 static void prefs_matcher_criteria_select(GtkList *list,
                                          GtkWidget *widget,
                                          gpointer user_data);
-static void prefs_matcher_set_list(void);
+static MatcherList * prefs_matcher_get_list(void);
 
-void prefs_matcher_open(MatcherList * matchers)
+void prefs_matcher_open(MatcherList * matchers, PrefsMatcherSignal * cb)
 {
        inc_autocheck_timer_remove();
 
@@ -181,8 +210,9 @@ void prefs_matcher_open(MatcherList * matchers)
        manage_window_set_transient(GTK_WINDOW(matcher.window));
        gtk_widget_grab_focus(matcher.ok_btn);
 
-       tmp_matchers = matchers;
-       prefs_matcher_set_dialog();
+       matchers_callback = cb;
+
+       prefs_matcher_set_dialog(matchers);
 
        gtk_widget_show(matcher.window);
 }
@@ -212,6 +242,8 @@ static void prefs_matcher_create(void)
        GtkWidget *value_entry;
        GtkWidget *predicate_combo;
        GtkWidget *predicate_list;
+       GtkWidget *predicate_flag_combo;
+       GtkWidget *predicate_flag_list;
        GtkWidget *predicate_label;
        GtkWidget *bool_op_combo;
        GtkWidget *bool_op_list;
@@ -258,13 +290,6 @@ static void prefs_matcher_create(void)
        gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default (ok_btn);
 
-       /*
-       gtkut_button_set_create (&confirm_area, &close_btn, _("Close"),
-                                NULL, NULL, NULL, NULL);
-       gtk_widget_show (confirm_area);
-       gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
-       gtk_widget_grab_default (close_btn);*/
-
        gtk_window_set_title (GTK_WINDOW(window),
                              _("Condition setting"));
        gtk_signal_connect (GTK_OBJECT(window), "delete_event",
@@ -288,7 +313,7 @@ static void prefs_matcher_create(void)
        table1 = gtk_table_new (2, 3, FALSE);
        gtk_widget_show (table1);
 
-       gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, FALSE, 0);
        gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
        gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
 
@@ -352,24 +377,24 @@ static void prefs_matcher_create(void)
        gtk_widget_show (value_label);
        gtk_misc_set_alignment (GTK_MISC (value_label), 0, 0.5);
        gtk_table_attach (GTK_TABLE (table1), value_label, 2, 3, 0, 1,
-                         GTK_FILL, 0, 0, 0);
+                         GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
 
        value_entry = gtk_entry_new ();
        gtk_widget_show (value_entry);
        gtk_widget_set_usize (value_entry, 200, -1);
        gtk_table_attach (GTK_TABLE (table1), value_entry, 2, 3, 1, 2,
-                         0, 0, 0, 0);
+                         GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
 
 
        /* predicate */
 
        vbox2 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox2);
-       gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
 
        hbox1 = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox1);
-       gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
 
        predicate_label = gtk_label_new (_("Predicate"));
        gtk_widget_show (predicate_label);
@@ -397,9 +422,31 @@ static void prefs_matcher_create(void)
        gtk_box_pack_start (GTK_BOX (hbox1), predicate_combo,
                            FALSE, FALSE, 0);
 
+       /* predicate flag */
+
+       predicate_flag_combo = gtk_combo_new ();
+       gtk_widget_hide (predicate_flag_combo);
+       gtk_widget_set_usize (predicate_flag_combo, 120, -1);
+       predicate_flag_list = GTK_COMBO(predicate_flag_combo)->list;
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(predicate_flag_combo)->entry), FALSE);
+
+       combo_items = NULL;
+
+       for(i = 0 ; i < (gint) (sizeof(predicate_text) / sizeof(gchar *)) ;
+           i++) {
+               combo_items = g_list_append(combo_items, (gpointer) _(predicate_flag_text[i]));
+       }
+       gtk_combo_set_popdown_strings(GTK_COMBO(predicate_flag_combo),
+                                     combo_items);
+
+       g_list_free(combo_items);
+
+       gtk_box_pack_start (GTK_BOX (hbox1), predicate_flag_combo,
+                           FALSE, FALSE, 0);
+
        vbox3 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox3);
-       gtk_box_pack_start (GTK_BOX (hbox1), vbox3, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox1), vbox3, FALSE, FALSE, 0);
 
        PACK_CHECK_BUTTON (vbox3, case_chkbtn, _("Case sensitive"));
        PACK_CHECK_BUTTON (vbox3, regexp_chkbtn, _("Use regexp"));
@@ -465,7 +512,7 @@ static void prefs_matcher_create(void)
        g_list_free(combo_items);
 
        gtk_box_pack_start (GTK_BOX (btn_hbox), bool_op_combo,
-                           FALSE, TRUE, 0);
+                           FALSE, FALSE, 0);
 
        cond_hbox = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (cond_hbox);
@@ -522,6 +569,8 @@ static void prefs_matcher_create(void)
        matcher.predicate_label = predicate_label;
        matcher.predicate_list = predicate_list;
        matcher.predicate_combo = predicate_combo;
+       matcher.predicate_flag_list = predicate_flag_list;
+       matcher.predicate_flag_combo = predicate_flag_combo;
        matcher.case_chkbtn = case_chkbtn;
        matcher.regexp_chkbtn = regexp_chkbtn;
        matcher.bool_op_list = bool_op_list;
@@ -559,7 +608,7 @@ static void prefs_matcher_reset_condition(void)
        gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), "");
 }
 
- static void prefs_matcher_set_dialog(void)
+static void prefs_matcher_set_dialog(MatcherList * matchers)
 {
        GtkCList *clist = GTK_CLIST(matcher.cond_clist);
        GSList * cur;
@@ -569,17 +618,17 @@ static void prefs_matcher_reset_condition(void)
        gtk_clist_clear(clist);
 
        prefs_matcher_clist_set_row(-1, NULL);
-       if (tmp_matchers != NULL) {
-               for (cur = tmp_matchers->matchers ; cur != NULL ;
+       if (matchers != NULL) {
+               for (cur = matchers->matchers ; cur != NULL ;
                     cur = g_slist_next(cur)) {
                        MatcherProp * prop;
                        prop = (MatcherProp *) cur->data;
                        prefs_matcher_clist_set_row(-1, prop);
-                       matcherprop_free(prop);
                }
 
-               bool_op = tmp_matchers->bool_and;
+               bool_op = matchers->bool_and;
        }
+
        gtk_clist_thaw(clist);
 
        gtk_list_select_item(GTK_LIST(matcher.bool_op_list), bool_op);
@@ -587,25 +636,17 @@ static void prefs_matcher_reset_condition(void)
        prefs_matcher_reset_condition();
 }
 
-static void prefs_matcher_set_list(void)
+static MatcherList * prefs_matcher_get_list(void)
 {
        gchar * matcher_str;
        MatcherProp * prop;
        gint row = 1;
-       GSList * l;
        gchar * tmp;
+       gboolean bool_and;
+       GSList * matcher_list;
+       MatcherList * matchers;
 
-       if (tmp_matchers == NULL)
-               return;
-
-       /* free old */
-
-       for(l = tmp_matchers->matchers ; l != NULL ; l = g_slist_next(l))
-               matcherprop_free((MatcherProp *) l->data);
-       g_slist_free(tmp_matchers->matchers);
-       tmp_matchers->matchers = NULL;
-
-       /* set new */
+       matcher_list = NULL;
 
        while (gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
                                  row, 0, &matcher_str)) {
@@ -617,14 +658,16 @@ static void prefs_matcher_set_list(void)
                        if (tmp == NULL)
                                break;
                        
-                       tmp_matchers->matchers =
-                               g_slist_append(tmp_matchers->matchers, prop);
+                       matcher_list = g_slist_append(matcher_list, prop);
                }
                row ++;
        }
 
-       tmp_matchers->bool_and = get_sel_from_list(GTK_LIST(matcher.bool_op_list));
+       bool_and = get_sel_from_list(GTK_LIST(matcher.bool_op_list));
 
+       matchers = matcherlist_new(matcher_list, bool_and);
+
+       return matchers;
 }
 
 static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
@@ -632,6 +675,18 @@ static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
        switch (criteria_id) {
        case CRITERIA_ALL:
                return MATCHING_ALL;
+       case CRITERIA_UNREAD:
+               return MATCHING_UNREAD;
+       case CRITERIA_NEW:
+               return MATCHING_NEW;
+       case CRITERIA_MARKED:
+               return MATCHING_MARKED;
+       case CRITERIA_DELETED:
+               return MATCHING_DELETED;
+       case CRITERIA_REPLIED:
+               return MATCHING_REPLIED;
+       case CRITERIA_FORWARDED:
+               return MATCHING_FORWARDED;
        case CRITERIA_SUBJECT:
                return MATCHING_SUBJECT;
        case CRITERIA_FROM:
@@ -664,6 +719,18 @@ static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
 static gint prefs_matcher_not_criteria(gint matcher_criteria)
 {
        switch(matcher_criteria) {
+       case MATCHING_UNREAD:
+               return MATCHING_NOT_UNREAD;
+       case MATCHING_NEW:
+               return MATCHING_NOT_NEW;
+       case MATCHING_MARKED:
+               return MATCHING_NOT_MARKED;
+       case MATCHING_DELETED:
+               return MATCHING_NOT_DELETED;
+       case MATCHING_REPLIED:
+               return MATCHING_NOT_REPLIED;
+       case MATCHING_FORWARDED:
+               return MATCHING_NOT_FORWARDED;
        case MATCHING_SUBJECT:
                return MATCHING_NOT_SUBJECT;
        case MATCHING_FROM:
@@ -695,6 +762,7 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
        gint criteria;
        gint matchtype;
        gint value_pred;
+       gint value_pred_flag;
        gint value_criteria;
        gboolean use_regexp;
        gboolean case_sensitive;
@@ -708,12 +776,37 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
        criteria = prefs_matcher_get_matching_from_criteria(value_criteria);
 
        value_pred = get_sel_from_list(GTK_LIST(matcher.predicate_list));
+       value_pred_flag = get_sel_from_list(GTK_LIST(matcher.predicate_flag_list));
 
        use_regexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn));
        case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn));
 
-       if (value_pred != PREDICATE_CONTAINS)
-               criteria = prefs_matcher_not_criteria(criteria);
+       switch (value_criteria) {
+       case CRITERIA_UNREAD:
+       case CRITERIA_NEW:
+       case CRITERIA_MARKED:
+       case CRITERIA_DELETED:
+       case CRITERIA_REPLIED:
+       case CRITERIA_FORWARDED:
+               if (value_pred_flag == PREDICATE_FLAG_DISABLED)
+                       criteria = prefs_matcher_not_criteria(criteria);
+               break;
+       case CRITERIA_SUBJECT:
+       case CRITERIA_FROM:
+       case CRITERIA_TO:
+       case CRITERIA_CC:
+       case CRITERIA_TO_OR_CC:
+       case CRITERIA_NEWSGROUPS:
+       case CRITERIA_HEADERS_PART:
+       case CRITERIA_BODY_PART:
+       case CRITERIA_MESSAGE:
+       case CRITERIA_AGE_GREATER:
+       case CRITERIA_AGE_LOWER:
+       case CRITERIA_HEADER:
+               if (value_pred == PREDICATE_DOES_NOT_CONTAIN)
+                       criteria = prefs_matcher_not_criteria(criteria);
+               break;
+       }
 
        if (use_regexp) {
                if (case_sensitive)
@@ -734,6 +827,12 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
 
        switch (value_criteria) {
        case CRITERIA_ALL:
+       case CRITERIA_UNREAD:
+       case CRITERIA_NEW:
+       case CRITERIA_MARKED:
+       case CRITERIA_DELETED:
+       case CRITERIA_REPLIED:
+       case CRITERIA_FORWARDED:
                break;
 
        case CRITERIA_SUBJECT:
@@ -747,11 +846,12 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
        case CRITERIA_MESSAGE:
                expr = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
 
+               /*
                if (*expr == '\0') {
                    alertpanel_error(_("Match string is not set."));
                    return NULL;
                }
-
+               */
                break;
 
        case CRITERIA_AGE_GREATER:
@@ -776,16 +876,17 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
                    alertpanel_error(_("Header name is not set."));
                    return NULL;
                }
+               /*
                if (*expr == '\0') {
                    alertpanel_error(_("Match string is not set."));
                    return NULL;
                }
-
+               */
                break;
        }
 
        matcherprop =  matcherprop_new(criteria, header, matchtype, expr, age);
-       
+
        return matcherprop;
 }
 
@@ -892,6 +993,48 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
                                     CRITERIA_ALL);
                break;
 
+       case MATCHING_NOT_UNREAD:
+               negative_cond = TRUE;
+       case MATCHING_UNREAD:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_UNREAD);
+               break;
+
+       case MATCHING_NOT_NEW:
+               negative_cond = TRUE;
+       case MATCHING_NEW:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_NEW);
+               break;
+
+       case MATCHING_NOT_MARKED:
+               negative_cond = TRUE;
+       case MATCHING_MARKED:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_MARKED);
+               break;
+
+       case MATCHING_NOT_DELETED:
+               negative_cond = TRUE;
+       case MATCHING_DELETED:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_DELETED);
+               break;
+
+       case MATCHING_NOT_REPLIED:
+               negative_cond = TRUE;
+       case MATCHING_REPLIED:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_REPLIED);
+               break;
+
+       case MATCHING_NOT_FORWARDED:
+               negative_cond = TRUE;
+       case MATCHING_FORWARDED:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_FORWARDED);
+               break;
+
        case MATCHING_NOT_SUBJECT:
                negative_cond = TRUE;
        case MATCHING_SUBJECT:
@@ -1054,6 +1197,28 @@ static void prefs_matcher_criteria_select(GtkList *list,
                gtk_widget_set_sensitive(matcher.value_entry, FALSE);
                gtk_widget_set_sensitive(matcher.predicate_label, FALSE);
                gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_hide(matcher.predicate_combo);
+               gtk_widget_show(matcher.predicate_flag_combo);
+               gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
+               break;
+
+       case CRITERIA_UNREAD:
+       case CRITERIA_NEW:
+       case CRITERIA_MARKED:
+       case CRITERIA_DELETED:
+       case CRITERIA_REPLIED:
+       case CRITERIA_FORWARDED:
+               gtk_widget_set_sensitive(matcher.header_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.header_label, FALSE);
+               gtk_widget_set_sensitive(matcher.value_label, FALSE);
+               gtk_widget_set_sensitive(matcher.value_entry, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, TRUE);
+               gtk_widget_hide(matcher.predicate_combo);
+               gtk_widget_show(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
                break;
@@ -1073,6 +1238,9 @@ static void prefs_matcher_criteria_select(GtkList *list,
                gtk_widget_set_sensitive(matcher.value_entry, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_combo, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_show(matcher.predicate_combo);
+               gtk_widget_hide(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, TRUE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, TRUE);
                break;
@@ -1085,6 +1253,9 @@ static void prefs_matcher_criteria_select(GtkList *list,
                gtk_widget_set_sensitive(matcher.value_entry, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_label, FALSE);
                gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_show(matcher.predicate_combo);
+               gtk_widget_hide(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
                break;
@@ -1096,6 +1267,9 @@ static void prefs_matcher_criteria_select(GtkList *list,
                gtk_widget_set_sensitive(matcher.value_entry, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_combo, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_show(matcher.predicate_combo);
+               gtk_widget_hide(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, TRUE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, TRUE);
                break;
@@ -1116,8 +1290,18 @@ static void prefs_matcher_cancel(void)
 
 static void prefs_matcher_ok(void)
 {
-       prefs_matcher_set_list();
-       gtk_widget_hide(matcher.window);
+       MatcherList * matchers;
+
+       matchers = prefs_matcher_get_list();
+       if (matchers != NULL) {
+               gtk_widget_hide(matcher.window);
+               if (matchers_callback != NULL)
+                       matchers_callback(matchers);
+               matcherlist_free(matchers);
+       }
+       else {
+               gtk_widget_hide(matcher.window);
+       }
 }
 
 static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
index f2c8454..72c1c72 100644 (file)
 void prefs_matcher_read_config (void);
 void prefs_matcher_write_config        (void);
 */
-void prefs_matcher_open                (MatcherList * matchers);
+
+typedef void PrefsMatcherSignal(MatcherList * matchers);
+
+void prefs_matcher_open                (MatcherList * matchers,
+                                PrefsMatcherSignal * cb);
 
 #endif /* __PREFS_FILTER_H__ */
diff --git a/src/prefs_scoring.c b/src/prefs_scoring.c
new file mode 100644 (file)
index 0000000..a3fb96c
--- /dev/null
@@ -0,0 +1,605 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "intl.h"
+#include "main.h"
+#include "prefs.h"
+#include "prefs_matcher.h"
+#include "prefs_scoring.h"
+#include "prefs_common.h"
+#include "mainwindow.h"
+#include "foldersel.h"
+#include "manage_window.h"
+#include "inc.h"
+#include "utils.h"
+#include "gtkutils.h"
+#include "alertpanel.h"
+#include "folder.h"
+#include "scoring.h"
+
+static struct Scoring {
+       GtkWidget *window;
+
+       GtkWidget *ok_btn;
+       GtkWidget *cond_entry;
+       GtkWidget *score_entry;
+
+       GtkWidget *cond_clist;
+} scoring;
+
+/*
+   parameter name, default value, pointer to the prefs variable, data type,
+   pointer to the widget pointer,
+   pointer to the function for data setting,
+   pointer to the function for widget setting
+ */
+
+#define VSPACING               12
+#define VSPACING_NARROW                4
+#define DEFAULT_ENTRY_WIDTH    80
+#define PREFSBUFSIZE           1024
+
+/* widget creating functions */
+static void prefs_scoring_create               (void);
+
+static void prefs_scoring_set_dialog   (void);
+static void prefs_scoring_set_list     (void);
+
+/* callback functions */
+/* static void prefs_scoring_select_dest_cb    (void); */
+static void prefs_scoring_register_cb  (void);
+static void prefs_scoring_substitute_cb        (void);
+static void prefs_scoring_delete_cb    (void);
+static void prefs_scoring_up           (void);
+static void prefs_scoring_down         (void);
+static void prefs_scoring_select               (GtkCList       *clist,
+                                        gint            row,
+                                        gint            column,
+                                        GdkEvent       *event);
+
+static gint prefs_scoring_deleted      (GtkWidget      *widget,
+                                        GdkEventAny    *event,
+                                        gpointer        data);
+static void prefs_scoring_key_pressed  (GtkWidget      *widget,
+                                        GdkEventKey    *event,
+                                        gpointer        data);
+static void prefs_scoring_cancel               (void);
+static void prefs_scoring_ok           (void);
+
+static void prefs_scoring_condition_define     (void);
+static gint prefs_scoring_clist_set_row(gint row, ScoringProp * prop);
+
+void prefs_scoring_open(void)
+{
+       inc_autocheck_timer_remove();
+
+       if (!scoring.window) {
+               prefs_scoring_create();
+       }
+
+       manage_window_set_transient(GTK_WINDOW(scoring.window));
+       gtk_widget_grab_focus(scoring.ok_btn);
+
+       prefs_scoring_set_dialog();
+
+       gtk_widget_show(scoring.window);
+}
+
+static void prefs_scoring_create(void)
+{
+       GtkWidget *window;
+       GtkWidget *vbox;
+       GtkWidget *ok_btn;
+       GtkWidget *cancel_btn;
+       GtkWidget *confirm_area;
+
+       GtkWidget *vbox1;
+       GtkWidget *hbox1;
+       GtkWidget *reg_hbox;
+       GtkWidget *arrow;
+       GtkWidget *btn_hbox;
+
+       GtkWidget *cond_label;
+       GtkWidget *cond_entry;
+       GtkWidget *cond_btn;
+       GtkWidget *score_label;
+       GtkWidget *score_entry;
+
+       GtkWidget *reg_btn;
+       GtkWidget *subst_btn;
+       GtkWidget *del_btn;
+
+       GtkWidget *cond_hbox;
+       GtkWidget *cond_scrolledwin;
+       GtkWidget *cond_clist;
+
+       GtkWidget *btn_vbox;
+       GtkWidget *up_btn;
+       GtkWidget *down_btn;
+
+       gchar *title[] = {_("Registered rules")};
+
+       debug_print(_("Creating scoring setting window...\n"));
+
+       window = gtk_window_new (GTK_WINDOW_DIALOG);
+       gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+       gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
+       gtk_window_set_modal (GTK_WINDOW (window), TRUE);
+       gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
+
+       vbox = gtk_vbox_new (FALSE, 6);
+       gtk_widget_show (vbox);
+       gtk_container_add (GTK_CONTAINER (window), vbox);
+
+       gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
+                               &cancel_btn, _("Cancel"), NULL, NULL);
+       gtk_widget_show (confirm_area);
+       gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
+       gtk_widget_grab_default (ok_btn);
+
+       gtk_window_set_title (GTK_WINDOW(window),
+                             _("Scoring setting"));
+       gtk_signal_connect (GTK_OBJECT(window), "delete_event",
+                           GTK_SIGNAL_FUNC(prefs_scoring_deleted), NULL);
+       gtk_signal_connect (GTK_OBJECT(window), "key_press_event",
+                           GTK_SIGNAL_FUNC(prefs_scoring_key_pressed), NULL);
+       gtk_signal_connect (GTK_OBJECT(window), "focus_in_event",
+                           GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
+       gtk_signal_connect (GTK_OBJECT(window), "focus_out_event",
+                           GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
+       gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_scoring_ok), NULL);
+       gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_scoring_cancel), NULL);
+
+       vbox1 = gtk_vbox_new (FALSE, VSPACING);
+       gtk_widget_show (vbox1);
+       gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
+
+       cond_label = gtk_label_new (_("Condition"));
+       gtk_widget_show (cond_label);
+       gtk_misc_set_alignment (GTK_MISC (cond_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (vbox1), cond_label, FALSE, FALSE, 0);
+
+       hbox1 = gtk_hbox_new (FALSE, VSPACING);
+       gtk_widget_show (vbox1);
+       gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
+
+       cond_entry = gtk_entry_new ();
+       gtk_widget_show (cond_entry);
+       gtk_widget_set_usize (cond_entry, 300, -1);
+       gtk_box_pack_start (GTK_BOX (hbox1), cond_entry, TRUE, TRUE, 0);
+
+       cond_btn = gtk_button_new_with_label (_("Define ..."));
+       gtk_widget_show (cond_btn);
+       gtk_box_pack_start (GTK_BOX (hbox1), cond_btn, FALSE, FALSE, 0);
+       gtk_signal_connect (GTK_OBJECT (cond_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_scoring_condition_define),
+                           NULL);
+
+       hbox1 = gtk_hbox_new (FALSE, VSPACING);
+       gtk_widget_show (vbox1);
+       gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
+
+       score_label = gtk_label_new (_("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);
+
+       score_entry = gtk_entry_new ();
+       gtk_widget_show (score_entry);
+       gtk_widget_set_usize (score_entry, 50, -1);
+       gtk_box_pack_start (GTK_BOX (hbox1), score_entry, FALSE, FALSE, 0);
+
+       /* register / substitute / delete */
+
+       reg_hbox = gtk_hbox_new (FALSE, 4);
+       gtk_widget_show (reg_hbox);
+       gtk_box_pack_start (GTK_BOX (vbox1), reg_hbox, FALSE, FALSE, 0);
+
+       arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
+       gtk_widget_show (arrow);
+       gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
+       gtk_widget_set_usize (arrow, -1, 16);
+
+       btn_hbox = gtk_hbox_new (TRUE, 4);
+       gtk_widget_show (btn_hbox);
+       gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
+
+       reg_btn = gtk_button_new_with_label (_("Register"));
+       gtk_widget_show (reg_btn);
+       gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
+       gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_scoring_register_cb), NULL);
+
+       subst_btn = gtk_button_new_with_label (_(" Substitute "));
+       gtk_widget_show (subst_btn);
+       gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
+       gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_scoring_substitute_cb),
+                           NULL);
+
+       del_btn = gtk_button_new_with_label (_("Delete"));
+       gtk_widget_show (del_btn);
+       gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
+       gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_scoring_delete_cb), NULL);
+
+       cond_hbox = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (cond_hbox);
+       gtk_box_pack_start (GTK_BOX (vbox1), cond_hbox, TRUE, TRUE, 0);
+
+       cond_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
+       gtk_widget_show (cond_scrolledwin);
+       gtk_widget_set_usize (cond_scrolledwin, -1, 150);
+       gtk_box_pack_start (GTK_BOX (cond_hbox), cond_scrolledwin,
+                           TRUE, TRUE, 0);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (cond_scrolledwin),
+                                       GTK_POLICY_AUTOMATIC,
+                                       GTK_POLICY_AUTOMATIC);
+
+       cond_clist = gtk_clist_new_with_titles(1, title);
+       gtk_widget_show (cond_clist);
+       gtk_container_add (GTK_CONTAINER (cond_scrolledwin), cond_clist);
+       gtk_clist_set_column_width (GTK_CLIST (cond_clist), 0, 80);
+       gtk_clist_set_selection_mode (GTK_CLIST (cond_clist),
+                                     GTK_SELECTION_BROWSE);
+       GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (cond_clist)->column[0].button,
+                               GTK_CAN_FOCUS);
+       gtk_signal_connect (GTK_OBJECT (cond_clist), "select_row",
+                           GTK_SIGNAL_FUNC (prefs_scoring_select), NULL);
+
+       btn_vbox = gtk_vbox_new (FALSE, 8);
+       gtk_widget_show (btn_vbox);
+       gtk_box_pack_start (GTK_BOX (cond_hbox), btn_vbox, FALSE, FALSE, 0);
+
+       up_btn = gtk_button_new_with_label (_("Up"));
+       gtk_widget_show (up_btn);
+       gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
+       gtk_signal_connect (GTK_OBJECT (up_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_scoring_up), NULL);
+
+       down_btn = gtk_button_new_with_label (_("Down"));
+       gtk_widget_show (down_btn);
+       gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
+       gtk_signal_connect (GTK_OBJECT (down_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_scoring_down), NULL);
+
+       gtk_widget_show_all(window);
+
+       scoring.window    = window;
+       scoring.ok_btn = ok_btn;
+
+       scoring.cond_entry = cond_entry;
+       scoring.score_entry = score_entry;
+
+       scoring.cond_clist   = cond_clist;
+}
+
+static void prefs_scoring_set_dialog(void)
+{
+       GtkCList *clist = GTK_CLIST(scoring.cond_clist);
+       GSList *cur;
+
+       gtk_clist_freeze(clist);
+       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;
+
+               prefs_scoring_clist_set_row(-1, prop);
+       }
+
+       gtk_clist_thaw(clist);
+}
+
+static void prefs_scoring_set_list(void)
+{
+       gint row = 1;
+       ScoringProp *prop;
+       GSList * cur;
+       gchar * scoring_str;
+       gchar * tmp;
+
+       for(cur = prefs_scoring ; cur != NULL ; cur = g_slist_next(cur))
+               scoringprop_free((ScoringProp *) cur->data);
+       g_slist_free(prefs_scoring);
+       prefs_scoring = NULL;
+
+       while (gtk_clist_get_text(GTK_CLIST(scoring.cond_clist),
+                                 row, 0, &scoring_str)) {
+               if (strcmp(scoring_str, _("(New)")) != 0) {
+                       tmp = scoring_str;
+                       prop = scoringprop_parse(&tmp);
+                       if (prop != NULL)
+                               prefs_scoring = g_slist_append(prefs_scoring,
+                                                              prop);
+               }
+               row++;
+       }
+}
+
+static gint prefs_scoring_clist_set_row(gint row, ScoringProp * prop)
+{
+       GtkCList *clist = GTK_CLIST(scoring.cond_clist);
+       gchar * str;
+       gchar *cond_str[1];
+
+       if (prop == NULL) {
+               cond_str[0] = _("(New)");
+               return gtk_clist_append(clist, cond_str);
+       }
+
+       str = scoringprop_to_string(prop);
+       if (str == NULL) {
+               return -1;
+       }
+       cond_str[0] = str;
+
+       if (row < 0)
+               row = gtk_clist_append(clist, cond_str);
+       else
+               gtk_clist_set_text(clist, row, 0, cond_str[0]);
+       g_free(str);
+
+       return row;
+}
+
+static void prefs_scoring_condition_define_done(MatcherList * matchers)
+{
+       gchar * str;
+
+       if (matchers == NULL)
+               return;
+
+       str = matcherlist_to_string(matchers);
+
+       if (str != NULL) {
+               gtk_entry_set_text(GTK_ENTRY(scoring.cond_entry), str);
+               g_free(str);
+       }
+}
+
+static void prefs_scoring_condition_define(void)
+{
+       gchar * cond_str;
+       MatcherList * matchers = NULL;
+
+       cond_str = gtk_entry_get_text(GTK_ENTRY(scoring.cond_entry));
+
+       if (*cond_str != '\0') {
+               gchar * tmp;
+               
+               tmp = cond_str;
+               matchers = matcherlist_parse(&tmp);
+               if (tmp == NULL)
+                       alertpanel_error(_("Match string is not valid."));
+       }
+
+       prefs_matcher_open(matchers, prefs_scoring_condition_define_done);
+
+       if (matchers != NULL)
+               matcherlist_free(matchers);
+}
+
+
+/* register / substitute delete buttons */
+
+static void prefs_scoring_register_cb(void)
+{
+       MatcherList * cond;
+       gchar * cond_str;
+       gchar * score_str;
+       ScoringProp * prop;
+       gint score;
+       gchar * tmp;
+
+       cond_str = gtk_entry_get_text(GTK_ENTRY(scoring.cond_entry));
+       if (*cond_str == '\0') {
+               alertpanel_error(_("Score is not set."));
+               return;
+       }
+
+       score_str = gtk_entry_get_text(GTK_ENTRY(scoring.score_entry));
+       if (*score_str == '\0') {
+               alertpanel_error(_("Match string is not set."));
+               return;
+       }
+
+       score = atoi(score_str);
+       tmp = cond_str;
+       cond = matcherlist_parse(&tmp);
+
+       if (tmp == NULL) {
+               alertpanel_error(_("Match string is not valid."));
+               return;
+       }
+
+       prop = scoringprop_new(cond, score);
+
+       prefs_scoring_clist_set_row(-1, prop);
+
+       scoringprop_free(prop);
+}
+
+static void prefs_scoring_substitute_cb(void)
+{
+       GtkCList *clist = GTK_CLIST(scoring.cond_clist);
+       gint row;
+       MatcherList * cond;
+       gchar * cond_str;
+       gchar * score_str;
+       ScoringProp * prop;
+       gint score;
+       gchar * tmp;
+
+       if (!clist->selection) return;
+
+       row = GPOINTER_TO_INT(clist->selection->data);
+       if (row == 0) return;
+
+       cond_str = gtk_entry_get_text(GTK_ENTRY(scoring.cond_entry));
+       if (*cond_str == '\0') {
+               alertpanel_error(_("Score is not set."));
+               return;
+       }
+
+       score_str = gtk_entry_get_text(GTK_ENTRY(scoring.score_entry));
+       if (*score_str == '\0') {
+               alertpanel_error(_("Match string is not set."));
+               return;
+       }
+
+       score = atoi(score_str);
+       tmp = cond_str;
+       cond = matcherlist_parse(&tmp);
+
+       if (tmp == NULL) {
+               alertpanel_error(_("Match string is not valid."));
+               return;
+       }
+
+       prop = scoringprop_new(cond, score);
+
+       prefs_scoring_clist_set_row(row, prop);
+
+       scoringprop_free(prop);
+}
+
+static void prefs_scoring_delete_cb(void)
+{
+       GtkCList *clist = GTK_CLIST(scoring.cond_clist);
+       gint row;
+
+       if (!clist->selection) return;
+       row = GPOINTER_TO_INT(clist->selection->data);
+       if (row == 0) return;
+
+       if (alertpanel(_("Delete rule"),
+                      _("Do you really want to delete this rule?"),
+                      _("Yes"), _("No"), NULL) == G_ALERTALTERNATE)
+               return;
+
+       gtk_clist_remove(clist, row);
+}
+
+static void prefs_scoring_up(void)
+{
+       GtkCList *clist = GTK_CLIST(scoring.cond_clist);
+       gint row;
+
+       if (!clist->selection) return;
+
+       row = GPOINTER_TO_INT(clist->selection->data);
+       if (row > 1) {
+               gtk_clist_row_move(clist, row, row - 1);
+       }
+}
+
+static void prefs_scoring_down(void)
+{
+       GtkCList *clist = GTK_CLIST(scoring.cond_clist);
+       gint row;
+
+       if (!clist->selection) return;
+
+       row = GPOINTER_TO_INT(clist->selection->data);
+       if (row > 0 && row < clist->rows - 1) {
+               gtk_clist_row_move(clist, row, row + 1);
+       }
+}
+
+static void prefs_scoring_select(GtkCList *clist, gint row, gint column,
+                               GdkEvent *event)
+{
+       ScoringProp * prop;
+       gchar * tmp;
+
+       gchar * matcher_str;
+       gchar * scoring_str;
+       gchar * score_str;
+
+        if (!gtk_clist_get_text(GTK_CLIST(scoring.cond_clist),
+                               row, 0, &scoring_str))
+               return;
+       
+       tmp = scoring_str;
+       prop = scoringprop_parse(&tmp);
+       if (tmp == NULL)
+               return;
+
+       matcher_str = matcherlist_to_string(prop->matchers);
+       if (matcher_str == NULL) {
+               scoringprop_free(prop);
+               return;
+       }
+
+       score_str = itos(prop->score);
+
+       gtk_entry_set_text(GTK_ENTRY(scoring.cond_entry), matcher_str);
+       gtk_entry_set_text(GTK_ENTRY(scoring.score_entry), score_str);
+
+       g_free(matcher_str);
+       scoringprop_free(prop);
+}
+
+static gint prefs_scoring_deleted(GtkWidget *widget, GdkEventAny *event,
+                                gpointer data)
+{
+       prefs_scoring_cancel();
+       return TRUE;
+}
+
+static void prefs_scoring_key_pressed(GtkWidget *widget, GdkEventKey *event,
+                                    gpointer data)
+{
+       if (event && event->keyval == GDK_Escape)
+               prefs_scoring_cancel();
+}
+
+static void prefs_scoring_ok(void)
+{
+       prefs_scoring_set_list();
+       prefs_scoring_write_config();
+       gtk_widget_hide(scoring.window);
+}
+
+static void prefs_scoring_cancel(void)
+{
+       prefs_scoring_read_config();
+       gtk_widget_hide(scoring.window);
+}
diff --git a/src/prefs_scoring.h b/src/prefs_scoring.h
new file mode 100644 (file)
index 0000000..d7814fc
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PREFS_SCORING_H__
+#define __PREFS_SCORING_H__
+
+/*
+void prefs_scoring_read_config (void);
+void prefs_scoring_write_config        (void);
+*/
+void prefs_scoring_open                (void);
+
+#endif /* __PREFS_SCORING_H__ */
index 77dbacf..b9ad18f 100644 (file)
@@ -9,6 +9,7 @@
 #include "procheader.h"
 #include "matcher.h"
 #include "scoring.h"
+#include "prefs.h"
 
 #define PREFSBUFSIZE           1024
 
@@ -17,7 +18,6 @@ GSList * prefs_scoring = NULL;
 ScoringProp * scoringprop_parse(gchar ** str)
 {
        gchar * tmp;
-       gchar * save;
        gint key;
        ScoringProp * scoring;
        gint score;
@@ -174,7 +174,7 @@ void prefs_scoring_read_config(void)
                                                               scoring);
                        }
                        else {
-                               // debug
+                               /* debug */
                                g_warning(_("syntax error : %s\n"), buf);
                        }
                }
@@ -182,3 +182,62 @@ void prefs_scoring_read_config(void)
 
        fclose(fp);
 }
+
+gchar * scoringprop_to_string(ScoringProp * prop)
+{
+       gchar * list_str;
+       gchar * score_str;
+       gchar * scoring_str;
+
+       list_str = matcherlist_to_string(prop->matchers);
+
+       if (list_str == NULL)
+               return NULL;
+
+       score_str = itos(prop->score);
+       scoring_str = g_strconcat(list_str, " score ", score_str, NULL);
+       g_free(list_str);
+
+       return scoring_str;
+}
+
+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;
+       }
+
+       for (cur = prefs_scoring; cur != NULL; cur = cur->next) {
+               gchar *scoring_str;
+
+               prop = (ScoringProp *) cur->data;
+               scoring_str = scoringprop_to_string(prop);
+               if (fputs(scoring_str, pfile->fp) == EOF ||
+                   fputc('\n', pfile->fp) == EOF) {
+                       FILE_OP_ERROR(rcpath, "fputs || fputc");
+                       prefs_write_close_revert(pfile);
+                       g_free(rcpath);
+                       g_free(scoring_str);
+                       return;
+               }
+               g_free(scoring_str);
+       }
+
+       g_free(rcpath);
+
+       if (prefs_write_close(pfile) < 0) {
+               g_warning(_("failed to write configuration to file\n"));
+               return;
+       }
+}
index 2d7122f..2602e34 100644 (file)
@@ -6,8 +6,8 @@
 #include "matcher.h"
 #include "procmsg.h"
 
-#define MAX_SCORE 999
-#define MIN_SCORE -999
+#define MAX_SCORE 9999
+#define MIN_SCORE -9999
 
 struct _ScoringProp {
        MatcherList * matchers;
@@ -28,6 +28,8 @@ ScoringProp * scoringprop_parse(gchar ** str);
 
 gint score_message(GSList * scoring_list, MsgInfo * info);
 
+void prefs_scoring_write_config(void);
 void prefs_scoring_read_config(void);
+gchar * scoringprop_to_string(ScoringProp * prop);
 
 #endif
index e940892..1be2859 100644 (file)
@@ -1400,8 +1400,11 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
 
        if (prefs_common.use_addr_book)
                start_address_completion();
+       
+       main_window_set_thread_option(summaryview->mainwin);
 
-       if (prefs_common.enable_thread) {
+       /*      if (prefs_common.enable_thread) { */
+       if (summaryview->folder_item->prefs->enable_thread) {
                for (; mlist != NULL; mlist = mlist->next) {
                        msginfo = (MsgInfo *)mlist->data;
                        parent = NULL;