filtering dialog box and some changes
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Thu, 17 May 2001 10:57:37 +0000 (10:57 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Thu, 17 May 2001 10:57:37 +0000 (10:57 +0000)
12 files changed:
ChangeLog.claws
src/Makefile.am
src/filtering.c
src/filtering.h
src/mainwindow.c
src/matcher.c
src/matcher.h
src/prefs_account.c
src/prefs_filtering.c [new file with mode: 0644]
src/prefs_filtering.h [new file with mode: 0644]
src/prefs_matcher.c
src/prefs_scoring.c

index 8f24803..47e3d3f 100644 (file)
@@ -1,3 +1,28 @@
+2001-05-17 [hoa]
+
+* src/Makefile.am
+       added prefs_filtering.c
+
+* src/filtering.[ch]
+* src/matcher.[ch]
+       removed action : forward_news and forward_news_as_attachement
+       (forward and forward_as_attachement can be used instead)
+
+* src/mainwindow.c
+       added menu option to access filtering configuration
+
+* src/prefs_account.c
+       changed mail_command default to /usr/sbin/sendmail
+
+* added src/prefs_filtering.[ch]
+       dialog box for filtering configuration
+
+* src/prefs_matcher.c
+       added function prefs_matcher_get_criteria_from_matching()
+
+* src/prefs_scoring.c
+       reset the dialog when register or substitute is clicked
+
 2001-05-15 [hoa]
 
        * src/Makefile.am
index d2b9564..2c1b32e 100644 (file)
@@ -84,7 +84,8 @@ sylpheed_SOURCES = \
        matcher.c matcher.h \
        prefs_matcher.c prefs_matcher.h \
        prefs_scoring.c prefs_scoring.h \
-       filtering.c filtering.h
+       filtering.c filtering.h \
+       prefs_filtering.c prefs_filtering.h
 
 EXTRA_DIST = \
        pixmaps/clip.xpm \
index a9440e0..ce392f3 100644 (file)
 
 GSList * prefs_filtering = NULL;
 
-FilteringAction * filteringaction_new(int type, gchar * dest_folder,
-                                     int account_id, gchar * address,
-                                     gchar * newsgroups)
+FilteringAction * filteringaction_new(int type, int account_id,
+                                     gchar * destination)
 {
        FilteringAction * action;
 
        action = g_new0(FilteringAction, 1);
 
-       action->type = type;;
-       if (dest_folder)
-               action->dest_folder = g_strdup(dest_folder);
-       if (address)
-               action->address = address;
+       action->type = type;
+       action->account_id = account_id;
+       if (destination)
+               action->destination = g_strdup(destination);
 
        return action;
 }
 
 void filteringaction_free(FilteringAction * action)
 {
-       if (action->dest_folder)
-               g_free(action->dest_folder);
-       if (action->address)
-               g_free(action->address);
-       if (action->newsgroups)
-               g_free(action->newsgroups);
+       if (action->destination)
+               g_free(action->destination);
        g_free(action);
 }
 
@@ -47,9 +41,7 @@ FilteringAction * filteringaction_parse(gchar ** str)
 {
        FilteringAction * action;
        gchar * tmp;
-       gchar * dest_folder = NULL;
-       gchar * address = NULL;
-       gchar * newsgroups = NULL;
+       gchar * destination = NULL;
        gint account_id = 0;
        gint key;
 
@@ -59,13 +51,18 @@ FilteringAction * filteringaction_parse(gchar ** str)
 
        switch (key) {
        case MATCHING_ACTION_MOVE:
-               dest_folder = matcher_parse_str(&tmp);
-               if (tmp == NULL)
+               destination = matcher_parse_str(&tmp);
+               if (tmp == NULL) {
+                       * str = NULL;
                        return NULL;
-
+               }
                break;
        case MATCHING_ACTION_COPY:
-               dest_folder = matcher_parse_str(&tmp);
+               destination = matcher_parse_str(&tmp);
+               if (tmp == NULL) {
+                       * str = NULL;
+                       return NULL;
+               }
                break;
        case MATCHING_ACTION_DELETE:
                break;
@@ -79,42 +76,30 @@ FilteringAction * filteringaction_parse(gchar ** str)
                break;
        case MATCHING_ACTION_FORWARD:
                account_id = matcher_parse_number(&tmp);
-               if (tmp == NULL)
+               if (tmp == NULL) {
+                       * str = NULL;
                        return NULL;
+               }
 
-               address = matcher_parse_str(&tmp);
-               if (tmp == NULL)
+               destination = matcher_parse_str(&tmp);
+               if (tmp == NULL) {
+                       * str = NULL;
                        return NULL;
+               }
 
                break;
        case MATCHING_ACTION_FORWARD_AS_ATTACHEMENT:
                account_id = matcher_parse_number(&tmp);
-               if (tmp == NULL)
-                       return NULL;
-
-               address = matcher_parse_str(&tmp);
-               if (tmp == NULL)
-                       return NULL;
-
-               break;
-       case MATCHING_ACTION_FORWARD_NEWS:
-               account_id = matcher_parse_number(&tmp);
-               if (tmp == NULL)
-                       return NULL;
-
-               newsgroups = matcher_parse_str(&tmp);
-               if (tmp == NULL)
-                       return NULL;
-
-               break;
-       case MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT:
-               account_id = matcher_parse_number(&tmp);
-               if (tmp == NULL)
+               if (tmp == NULL) {
+                       * str = NULL;
                        return NULL;
+               }
 
-               newsgroups = matcher_parse_str(&tmp);
-               if (tmp == NULL)
+               destination = matcher_parse_str(&tmp);
+               if (tmp == NULL) {
+                       * str = NULL;
                        return NULL;
+               }
 
                break;
        default:
@@ -123,8 +108,7 @@ FilteringAction * filteringaction_parse(gchar ** str)
        }
 
        * str = tmp;
-       action = filteringaction_new(key, dest_folder,
-                                    account_id, address, newsgroups);
+       action = filteringaction_new(key, account_id, destination);
 
        return action;
 }
@@ -220,7 +204,7 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
 
        switch(action->type) {
        case MATCHING_ACTION_MOVE:
-               dest_folder = folder_find_item_from_path(action->dest_folder);
+               dest_folder = folder_find_item_from_path(action->destination);
                if (!dest_folder)
                        return FALSE;
 
@@ -248,7 +232,7 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
                return TRUE;
 
        case MATCHING_ACTION_COPY:
-               dest_folder = folder_find_item_from_path(action->dest_folder);
+               dest_folder = folder_find_item_from_path(action->destination);
                if (!dest_folder)
                        return FALSE;
 
@@ -266,7 +250,7 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
                return TRUE;
 
        case MATCHING_ACTION_DELETE:
-               if (folder_item_remove_msg(dest_folder, info->msgnum) == -1)
+               if (folder_item_remove_msg(info->folder, info->msgnum) == -1)
                        return FALSE;
 
                info->flags = 0;
@@ -306,14 +290,6 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
 
                return FALSE;
 
-       case MATCHING_ACTION_FORWARD_NEWS:
-
-               return FALSE;
-
-       case MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT:
-
-               return FALSE;
-
        default:
                return FALSE;
        }
@@ -360,8 +336,6 @@ static gboolean filteringprop_apply(FilteringProp * filtering, MsgInfo * info,
                case MATCHING_ACTION_MARK_AS_UNREAD:
                case MATCHING_ACTION_FORWARD:
                case MATCHING_ACTION_FORWARD_AS_ATTACHEMENT:
-               case MATCHING_ACTION_FORWARD_NEWS:
-               case MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT:
                        return FALSE;
                default:
                        return FALSE;
@@ -472,25 +446,6 @@ void prefs_filtering_read_config(void)
        fclose(fp);
 }
 
-/*
-struct _FilteringAction {
-       int type;
-       gchar * dest_folder;
-       gchar * address;
-       gchar * newsgroups;
-}
-
-       MATCHING_ACTION_MOVE,
-       MATCHING_ACTION_COPY,
-       MATCHING_ACTION_DELETE,
-       MATCHING_ACTION_MARK,
-       MATCHING_ACTION_MARK_AS_READ,
-       MATCHING_ACTION_FORWARD,
-       MATCHING_ACTION_FORWARD_AS_ATTACHEMENT,
-       MATCHING_ACTION_FORWARD_NEWS,
-       MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT,
-*/
-
 gchar * filteringaction_to_string(FilteringAction * action)
 {
        gchar * command_str;
@@ -506,8 +461,8 @@ gchar * filteringaction_to_string(FilteringAction * action)
        switch(action->type) {
        case MATCHING_ACTION_MOVE:
        case MATCHING_ACTION_COPY:
-               return g_strconcat(command_str, " ", action->dest_folder,
-                                  NULL);
+               return g_strconcat(command_str, " \"", action->destination,
+                                  "\"", NULL);
 
        case MATCHING_ACTION_DELETE:
        case MATCHING_ACTION_MARK:
@@ -521,13 +476,7 @@ gchar * filteringaction_to_string(FilteringAction * action)
        case MATCHING_ACTION_FORWARD_AS_ATTACHEMENT:
                account_id_str = itos(action->account_id);
                return g_strconcat(command_str, " ", account_id_str,
-                                  " \"", action->address, "\"", NULL);
-
-       case MATCHING_ACTION_FORWARD_NEWS:
-       case MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT:
-               account_id_str = itos(action->account_id);
-               return g_strconcat(command_str, " ", account_id_str,
-                                  " \"", action->newsgroups, "\"", NULL);
+                                  " \"", action->destination, "\"", NULL);
 
        default:
                return NULL;
index aaaf77f..f8bf063 100644 (file)
@@ -8,10 +8,8 @@
 
 struct _FilteringAction {
        gint type;
-       gchar * dest_folder;
        gint account_id;
-       gchar * address;
-       gchar * newsgroups;
+       gchar * destination;
 };
 
 typedef struct _FilteringAction FilteringAction;
@@ -26,9 +24,8 @@ typedef struct _FilteringProp FilteringProp;
 extern GSList * prefs_filtering;
 
 
-FilteringAction * filteringaction_new(int type, gchar * dest_folder,
-                                     int account_id, gchar * address,
-                                     gchar * newsgroups);
+FilteringAction * filteringaction_new(int type, int account_id,
+                                     gchar * destination);
 void filteringaction_free(FilteringAction * action);
 FilteringAction * filteringaction_parse(gchar ** str);
 
index 66fd45b..bbc87f0 100644 (file)
@@ -323,6 +323,9 @@ static void prefs_filter_open_cb (MainWindow        *mainwin,
 static void prefs_scoring_open_cb (MainWindow  *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void prefs_filtering_open_cb (MainWindow        *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 static void prefs_account_open_cb(MainWindow   *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
@@ -525,6 +528,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, prefs_filter_open_cb, 0, NULL},
        {N_("/_Configuration/_Scoring ..."),
                                                NULL, prefs_scoring_open_cb, 0, NULL},
+       {N_("/_Configuration/_Filtering ..."),
+                                               NULL, prefs_filtering_open_cb, 0, NULL},
        {N_("/_Configuration/_Preferences per account..."),
                                                NULL, prefs_account_open_cb, 0, NULL},
        {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
@@ -2090,6 +2095,12 @@ static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
        prefs_scoring_open();
 }
 
+static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
+                                   GtkWidget *widget)
+{
+       prefs_filtering_open();
+}
+
 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
                                  GtkWidget *widget)
 {
index afc0b1f..58a9ce7 100644 (file)
@@ -81,8 +81,6 @@ static MatchParser matchparser_tab[] = {
        {MATCHING_ACTION_MARK_AS_UNREAD, "mark_as_unread"},
        {MATCHING_ACTION_FORWARD, "forward"},
        {MATCHING_ACTION_FORWARD_AS_ATTACHEMENT, "forward_as_attachement"},
-       {MATCHING_ACTION_FORWARD_NEWS, "forward_news"},
-       {MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT, "forward_news_as_attachement"}
 };
 
 gchar * get_matchparser_tab_str(gint id)
index d3a4f88..5a065c4 100644 (file)
@@ -68,8 +68,6 @@ enum {
        MATCHING_ACTION_MARK_AS_UNREAD,
        MATCHING_ACTION_FORWARD,
        MATCHING_ACTION_FORWARD_AS_ATTACHEMENT,
-       MATCHING_ACTION_FORWARD_NEWS,
-       MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT,
 
        MATCHING_MATCH,
        MATCHING_REGEXP,
index d743534..e171d06 100644 (file)
@@ -183,7 +183,7 @@ static PrefParam param[] = {
        {"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
         &basic.mailcmd_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
 
-       {"mail_command", "mail", &tmp_ac_prefs.mail_command, P_STRING,
+       {"mail_command", "/usr/sbin/sendmail", &tmp_ac_prefs.mail_command, P_STRING,
         &basic.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
 
        {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
diff --git a/src/prefs_filtering.c b/src/prefs_filtering.c
new file mode 100644 (file)
index 0000000..256d1c1
--- /dev/null
@@ -0,0 +1,950 @@
+/*
+ * 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_filtering.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 "filtering.h"
+
+static struct Filtering {
+       GtkWidget *window;
+
+       GtkWidget *ok_btn;
+       GtkWidget *cond_entry;
+       GtkWidget *action_list;
+       GtkWidget *action_combo;
+       GtkWidget *account_list;
+       GtkWidget *account_combo;
+       GtkWidget *dest_entry;
+       GtkWidget *dest_btn;
+
+       GtkWidget *cond_clist;
+} filtering;
+
+#define VSPACING               12
+#define VSPACING_NARROW                4
+#define DEFAULT_ENTRY_WIDTH    80
+#define PREFSBUFSIZE           1024
+
+/* widget creating functions */
+static void prefs_filtering_create             (void);
+
+static void prefs_filtering_set_dialog (void);
+static void prefs_filtering_set_list   (void);
+
+/* callback functions */
+/* static void prefs_filtering_select_dest_cb  (void); */
+static void prefs_filtering_register_cb        (void);
+static void prefs_filtering_substitute_cb      (void);
+static void prefs_filtering_delete_cb  (void);
+static void prefs_filtering_up         (void);
+static void prefs_filtering_down               (void);
+static void prefs_filtering_select             (GtkCList       *clist,
+                                        gint            row,
+                                        gint            column,
+                                        GdkEvent       *event);
+
+static gint prefs_filtering_deleted    (GtkWidget      *widget,
+                                        GdkEventAny    *event,
+                                        gpointer        data);
+static void prefs_filtering_key_pressed        (GtkWidget      *widget,
+                                        GdkEventKey    *event,
+                                        gpointer        data);
+static void prefs_filtering_cancel             (void);
+static void prefs_filtering_ok         (void);
+
+static void prefs_filtering_condition_define   (void);
+static gint prefs_filtering_clist_set_row(gint row, FilteringProp * prop);
+static void prefs_filtering_select_dest(void);
+static void prefs_filtering_action_select(GtkList *list,
+                                         GtkWidget *widget,
+                                         gpointer user_data);
+static void prefs_filtering_reset_dialog(void);
+
+enum {
+       ACTION_MOVE = 0,
+       ACTION_COPY = 1,
+       ACTION_DELETE = 2,
+       ACTION_MARK = 3,
+       ACTION_UNMARK = 4,
+       ACTION_MARK_AS_READ = 5,
+       ACTION_MARK_AS_UNREAD = 6,
+       ACTION_FORWARD = 7,
+       ACTION_FORWARD_AS_ATTACHEMENT =8
+};
+
+static gint get_sel_from_list(GtkList * list)
+{
+       gint row = 0;
+       void * sel;
+       GList * child;
+
+       sel = list->selection->data;
+       for(child = list->children ; child != NULL ;
+           child = g_list_next(child)) {
+               if (child->data == sel)
+                       return row;
+               row ++;
+       }
+       
+       return row;
+}
+
+static gint get_account_id_from_list_id(gint list_id)
+{
+       GList * accounts;
+
+       for (accounts = account_get_list() ; accounts != NULL;
+            accounts = accounts->next) {
+               PrefsAccount *ac = (PrefsAccount *)accounts->data;
+
+               if (list_id == 0)
+                       return ac->account_id;
+               list_id--;
+       }
+       return 0;
+}
+
+static gint get_list_id_from_account_id(gint account_id)
+{
+       GList * accounts;
+       gint list_id = 0;
+
+       for (accounts = account_get_list() ; accounts != NULL;
+            accounts = accounts->next) {
+               PrefsAccount *ac = (PrefsAccount *)accounts->data;
+
+               if (account_id == ac->account_id)
+                       return list_id;
+               list_id++;
+       }
+       return 0;
+}
+
+static gint prefs_filtering_get_matching_from_action(gint action_id)
+{
+       switch(action_id) {
+       case ACTION_MOVE:
+               return MATCHING_ACTION_MOVE;
+       case ACTION_COPY:
+               return MATCHING_ACTION_COPY;
+       case ACTION_DELETE:
+               return MATCHING_ACTION_DELETE;
+       case ACTION_MARK:
+               return MATCHING_ACTION_MARK;
+       case ACTION_UNMARK:
+               return MATCHING_ACTION_UNMARK;
+       case ACTION_MARK_AS_READ:
+               return MATCHING_ACTION_MARK_AS_READ;
+       case ACTION_MARK_AS_UNREAD:
+               return MATCHING_ACTION_MARK_AS_UNREAD;
+       case ACTION_FORWARD:
+               return MATCHING_ACTION_FORWARD;
+       case ACTION_FORWARD_AS_ATTACHEMENT:
+               return MATCHING_ACTION_FORWARD_AS_ATTACHEMENT;
+       default:
+               return -1;
+       }
+}
+
+gchar * action_text [] = {
+       "Move", "Copy", "Delete",
+       "Mark", "Unmark", "Mark as read", "Mark as unread",
+       "Forward", "Forward as attachement"
+};
+
+void prefs_filtering_open(void)
+{
+       inc_autocheck_timer_remove();
+
+       if (!filtering.window) {
+               prefs_filtering_create();
+       }
+
+       manage_window_set_transient(GTK_WINDOW(filtering.window));
+       gtk_widget_grab_focus(filtering.ok_btn);
+
+       prefs_filtering_set_dialog();
+
+       gtk_widget_show(filtering.window);
+}
+
+static void prefs_filtering_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 *action_label;
+       GtkWidget *action_list;
+       GtkWidget *action_combo;
+       GtkWidget *account_label;
+       GtkWidget *account_list;
+       GtkWidget *account_combo;
+       GtkWidget *dest_label;
+       GtkWidget *dest_entry;
+       GtkWidget *dest_btn;
+
+       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;
+
+       GList *combo_items;
+       gint i;
+
+       GList *accounts;
+       GList * cur;
+
+       gchar *title[] = {_("Registered rules")};
+
+       debug_print(_("Creating filtering 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),
+                             _("Filtering setting"));
+       gtk_signal_connect (GTK_OBJECT(window), "delete_event",
+                           GTK_SIGNAL_FUNC(prefs_filtering_deleted), NULL);
+       gtk_signal_connect (GTK_OBJECT(window), "key_press_event",
+                           GTK_SIGNAL_FUNC(prefs_filtering_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_filtering_ok), NULL);
+       gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_filtering_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_filtering_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);
+
+       action_label = gtk_label_new (_("Action"));
+       gtk_widget_show (action_label);
+       gtk_misc_set_alignment (GTK_MISC (action_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), action_label, FALSE, FALSE, 0);
+
+       action_combo = gtk_combo_new ();
+       gtk_widget_show (action_combo);
+       gtk_widget_set_usize (action_combo, 200, -1);
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
+                              FALSE);
+
+       combo_items = NULL;
+
+       for(i = 0 ; i < (gint) (sizeof(action_text) / sizeof(gchar *)) ;
+           i++) {
+               combo_items = g_list_append(combo_items,
+                                           (gpointer) _(action_text[i]));
+       }
+       gtk_combo_set_popdown_strings(GTK_COMBO(action_combo), combo_items);
+
+       g_list_free(combo_items);
+
+       gtk_box_pack_start (GTK_BOX (hbox1), action_combo,
+                           TRUE, TRUE, 0);
+       action_list = GTK_COMBO(action_combo)->list;
+       gtk_signal_connect (GTK_OBJECT (action_list), "select-child",
+                           GTK_SIGNAL_FUNC (prefs_filtering_action_select),
+                           NULL);
+
+       /* accounts */
+
+       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);
+
+       account_label = gtk_label_new (_("Account"));
+       gtk_widget_show (account_label);
+       gtk_misc_set_alignment (GTK_MISC (account_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), account_label, FALSE, FALSE, 0);
+
+       account_combo = gtk_combo_new ();
+       gtk_widget_show (account_combo);
+
+       combo_items = NULL;
+       for (accounts = account_get_list() ; accounts != NULL;
+            accounts = accounts->next) {
+               PrefsAccount *ac = (PrefsAccount *)accounts->data;
+               GtkWidget *menuitem;
+               gchar *name;
+
+               name = g_strdup_printf("%s <%s> (%s)",
+                                      ac->name, ac->address,
+                                      ac->account_name);
+               combo_items = g_list_append(combo_items, (gpointer) name);
+       }
+
+       gtk_combo_set_popdown_strings(GTK_COMBO(account_combo), combo_items);
+
+       for(cur = g_list_first(combo_items) ; cur != NULL ;
+           cur = g_list_next(cur))
+               g_free(cur->data);
+       g_list_free(combo_items);
+
+       gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
+                           TRUE, TRUE, 0);
+       account_list = GTK_COMBO(account_combo)->list;
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
+                              FALSE);
+
+       /* destination */
+
+       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);
+
+       dest_label = gtk_label_new (_("Destination"));
+       gtk_widget_show (dest_label);
+       gtk_misc_set_alignment (GTK_MISC (dest_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), dest_label, FALSE, FALSE, 0);
+
+       dest_entry = gtk_entry_new ();
+       gtk_widget_show (dest_entry);
+       gtk_widget_set_usize (dest_entry, 300, -1);
+       gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
+
+       dest_btn = gtk_button_new_with_label (_("Select ..."));
+       gtk_widget_show (dest_btn);
+       gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
+       gtk_signal_connect (GTK_OBJECT (dest_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_filtering_select_dest),
+                           NULL);
+
+       /* 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_filtering_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_filtering_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_filtering_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_filtering_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_filtering_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_filtering_down), NULL);
+
+       gtk_widget_show_all(window);
+
+       filtering.window    = window;
+       filtering.ok_btn = ok_btn;
+
+       filtering.cond_entry = cond_entry;
+       filtering.action_list = action_list;
+       filtering.action_combo = action_combo;
+       filtering.account_list = account_list;
+       filtering.account_combo = account_combo;
+       filtering.dest_entry = dest_entry;
+       filtering.dest_btn = dest_btn;
+
+       filtering.cond_clist   = cond_clist;
+}
+
+static void prefs_filtering_set_dialog(void)
+{
+       GtkCList *clist = GTK_CLIST(filtering.cond_clist);
+       GSList *cur;
+
+       gtk_clist_freeze(clist);
+       gtk_clist_clear(clist);
+
+       prefs_filtering_clist_set_row(-1, NULL);
+       for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur)) {
+               FilteringProp * prop = (FilteringProp *) cur->data;
+
+               prefs_filtering_clist_set_row(-1, prop);
+       }
+
+       gtk_clist_thaw(clist);
+
+       prefs_filtering_reset_dialog();
+}
+
+static void prefs_filtering_reset_dialog(void)
+{
+       gtk_list_select_item(GTK_LIST(filtering.action_list), 0);
+       gtk_list_select_item(GTK_LIST(filtering.account_list), 0);
+       gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), "");
+       gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), "");
+}
+
+static void prefs_filtering_set_list(void)
+{
+       gint row = 1;
+       FilteringProp *prop;
+       GSList * cur;
+       gchar * filtering_str;
+       gchar * tmp;
+
+       for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur))
+               filteringprop_free((FilteringProp *) cur->data);
+       g_slist_free(prefs_filtering);
+       prefs_filtering = NULL;
+
+       while (gtk_clist_get_text(GTK_CLIST(filtering.cond_clist),
+                                 row, 0, &filtering_str)) {
+               if (strcmp(filtering_str, _("(New)")) != 0) {
+                       tmp = filtering_str;
+                       prop = filteringprop_parse(&tmp);
+                       if (prop != NULL)
+                               prefs_filtering = g_slist_append(prefs_filtering,
+                                                              prop);
+               }
+               row++;
+       }
+}
+
+static gint prefs_filtering_clist_set_row(gint row, FilteringProp * prop)
+{
+       GtkCList *clist = GTK_CLIST(filtering.cond_clist);
+       gchar * str;
+       gchar *cond_str[1];
+
+       if (prop == NULL) {
+               cond_str[0] = _("(New)");
+               return gtk_clist_append(clist, cond_str);
+       }
+
+       str = filteringprop_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_filtering_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(filtering.cond_entry), str);
+               g_free(str);
+       }
+}
+
+static void prefs_filtering_condition_define(void)
+{
+       gchar * cond_str;
+       MatcherList * matchers = NULL;
+
+       cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.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_filtering_condition_define_done);
+
+       if (matchers != NULL)
+               matcherlist_free(matchers);
+}
+
+
+/* register / substitute delete buttons */
+
+
+static FilteringProp * prefs_filtering_dialog_to_filtering(void)
+{
+       MatcherList * cond;
+       gchar * cond_str;
+       FilteringProp * prop;
+       FilteringAction * action;
+       gchar * tmp;
+       gint list_id;
+       gint action_id;
+       gint action_type;
+       gint account_id;
+       gchar * destination;
+       
+       cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
+       if (*cond_str == '\0') {
+               alertpanel_error(_("Score is not set."));
+               return;
+       }
+
+       action_id = get_sel_from_list(GTK_LIST(filtering.action_list));
+       action_type = prefs_filtering_get_matching_from_action(action_id);
+       list_id = get_sel_from_list(GTK_LIST(filtering.account_list));
+       account_id = get_account_id_from_list_id(list_id);
+
+       switch (action_id) {
+       case ACTION_MOVE:
+       case ACTION_COPY:
+       case ACTION_FORWARD:
+       case ACTION_FORWARD_AS_ATTACHEMENT:
+               destination = gtk_entry_get_text(GTK_ENTRY(filtering.dest_entry));
+               if (*destination == '\0') {
+                       alertpanel_error(_("Destination is not set."));
+                       return;
+               }
+               break;
+       default:
+               destination = NULL;
+               break;
+       }
+       
+       action = filteringaction_new(action_type, account_id, destination);
+
+       tmp = cond_str;
+       cond = matcherlist_parse(&tmp);
+
+       if (tmp == NULL) {
+               alertpanel_error(_("Match string is not valid."));
+               filteringaction_free(action);
+               return;
+       }
+
+       prop = filteringprop_new(cond, action);
+
+       return prop;
+}
+
+static void prefs_filtering_register_cb(void)
+{
+       FilteringProp * prop;
+       
+       prop = prefs_filtering_dialog_to_filtering();
+       if (prop == NULL)
+               return;
+       prefs_filtering_clist_set_row(-1, prop);
+
+       filteringprop_free(prop);
+}
+
+static void prefs_filtering_substitute_cb(void)
+{
+       GtkCList *clist = GTK_CLIST(filtering.cond_clist);
+       gint row;
+       FilteringProp * prop;
+       
+       if (!clist->selection) return;
+
+       row = GPOINTER_TO_INT(clist->selection->data);
+       if (row == 0) return;
+
+       prop = prefs_filtering_dialog_to_filtering();
+       if (prop == NULL)
+               return;
+       prefs_filtering_clist_set_row(row, prop);
+
+       filteringprop_free(prop);
+}
+
+static void prefs_filtering_delete_cb(void)
+{
+       GtkCList *clist = GTK_CLIST(filtering.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_filtering_up(void)
+{
+       GtkCList *clist = GTK_CLIST(filtering.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_filtering_down(void)
+{
+       GtkCList *clist = GTK_CLIST(filtering.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_filtering_select_set(FilteringProp * prop)
+{
+       FilteringAction * action;
+       gchar * matcher_str;
+       gint list_id;
+
+       prefs_filtering_reset_dialog();
+
+       action = prop->action;
+
+       matcher_str = matcherlist_to_string(prop->matchers);
+       if (matcher_str == NULL) {
+               filteringprop_free(prop);
+               return;
+       }
+
+       gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), matcher_str);
+
+       if (action->destination)
+               gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry),
+                                  action->destination);
+       else
+               gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), "");
+
+       switch(action->type) {
+       case MATCHING_ACTION_MOVE:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_MOVE);
+               break;
+       case MATCHING_ACTION_COPY:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_COPY);
+               break;
+       case MATCHING_ACTION_DELETE:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_DELETE);
+               break;
+       case MATCHING_ACTION_MARK:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_MARK);
+               break;
+       case MATCHING_ACTION_UNMARK:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_UNMARK);
+               break;
+       case MATCHING_ACTION_MARK_AS_READ:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_MARK_AS_READ);
+               break;
+       case MATCHING_ACTION_MARK_AS_UNREAD:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_MARK_AS_UNREAD);
+               break;
+       case MATCHING_ACTION_FORWARD:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_FORWARD);
+               list_id = get_list_id_from_account_id(action->account_id);
+               gtk_list_select_item(GTK_LIST(filtering.account_list),
+                                    list_id);
+               break;
+       case MATCHING_ACTION_FORWARD_AS_ATTACHEMENT:
+               list_id = get_list_id_from_account_id(action->account_id);
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_FORWARD_AS_ATTACHEMENT);
+               gtk_list_select_item(GTK_LIST(filtering.account_list),
+                                    list_id);
+               break;
+       }
+
+       g_free(matcher_str);
+}
+
+static void prefs_filtering_select(GtkCList *clist, gint row, gint column,
+                               GdkEvent *event)
+{
+       FilteringProp * prop;
+       gchar * tmp;
+       gchar * filtering_str;
+
+       if (row == 0) {
+               prefs_filtering_reset_dialog();
+               return;
+       }
+
+        if (!gtk_clist_get_text(GTK_CLIST(filtering.cond_clist),
+                               row, 0, &filtering_str))
+               return;
+       
+       tmp = filtering_str;
+       prop = filteringprop_parse(&tmp);
+       if (tmp == NULL)
+               return;
+
+       prefs_filtering_select_set(prop);
+
+       filteringprop_free(prop);
+}
+
+static void prefs_filtering_select_dest(void)
+{
+       FolderItem *dest;
+
+       dest = foldersel_folder_sel(NULL);
+       if (!dest) return;
+
+       gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), dest->path);
+}
+
+static void prefs_filtering_action_select(GtkList *list,
+                                         GtkWidget *widget,
+                                         gpointer user_data)
+{
+       gint value;
+
+       value = get_sel_from_list(GTK_LIST(filtering.action_list));
+
+       switch (value) {
+       case ACTION_MOVE:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
+               gtk_widget_show(filtering.dest_btn);
+               break;
+       case ACTION_COPY:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
+               gtk_widget_show(filtering.dest_btn);
+               break;
+       case ACTION_DELETE:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       case ACTION_MARK:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       case ACTION_UNMARK:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       case ACTION_MARK_AS_READ:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       case ACTION_MARK_AS_UNREAD:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       case ACTION_FORWARD:
+               gtk_widget_set_sensitive(filtering.account_combo, TRUE);
+               gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       case ACTION_FORWARD_AS_ATTACHEMENT:
+               gtk_widget_set_sensitive(filtering.account_combo, TRUE);
+               gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
+               gtk_widget_hide(filtering.dest_btn);
+               break;
+       }
+}
+
+static gint prefs_filtering_deleted(GtkWidget *widget, GdkEventAny *event,
+                                gpointer data)
+{
+       prefs_filtering_cancel();
+       return TRUE;
+}
+
+static void prefs_filtering_key_pressed(GtkWidget *widget, GdkEventKey *event,
+                                    gpointer data)
+{
+       if (event && event->keyval == GDK_Escape)
+               prefs_filtering_cancel();
+}
+
+static void prefs_filtering_ok(void)
+{
+       prefs_filtering_set_list();
+       prefs_filtering_write_config();
+       gtk_widget_hide(filtering.window);
+}
+
+static void prefs_filtering_cancel(void)
+{
+       prefs_filtering_read_config();
+       gtk_widget_hide(filtering.window);
+}
diff --git a/src/prefs_filtering.h b/src/prefs_filtering.h
new file mode 100644 (file)
index 0000000..09f1019
--- /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_FILTERING_H__
+#define __PREFS_FILTERING_H__
+
+/*
+void prefs_scoring_read_config (void);
+void prefs_scoring_write_config        (void);
+*/
+void prefs_filtering_open              (void);
+
+#endif /* __PREFS_FILTERING_H__ */
index d499b94..1f35d0f 100644 (file)
@@ -144,7 +144,7 @@ gchar * criteria_text [] = {
        "Score greater than", "Score lower than"
 };
 
-gint get_sel_from_list(GtkList * list)
+static gint get_sel_from_list(GtkList * list)
 {
        gint row = 0;
        void * sel;
@@ -676,6 +676,80 @@ static MatcherList * prefs_matcher_get_list(void)
        return matchers;
 }
 
+static gint prefs_matcher_get_criteria_from_matching(gint matching_id)
+{
+       switch(matching_id) {
+       case MATCHING_ALL:
+               return CRITERIA_ALL;
+       case MATCHING_NOT_UNREAD:
+       case MATCHING_UNREAD:
+               return CRITERIA_UNREAD;
+       case MATCHING_NOT_NEW:
+       case MATCHING_NEW:
+               return CRITERIA_NEW;
+       case MATCHING_NOT_MARKED:
+       case MATCHING_MARKED:
+               return CRITERIA_MARKED;
+       case MATCHING_NOT_DELETED:
+       case MATCHING_DELETED:
+               return CRITERIA_DELETED;
+               break;
+       case MATCHING_NOT_REPLIED:
+       case MATCHING_REPLIED:
+               return CRITERIA_REPLIED;
+       case MATCHING_NOT_FORWARDED:
+       case MATCHING_FORWARDED:
+               return CRITERIA_FORWARDED;
+       case MATCHING_NOT_SUBJECT:
+       case MATCHING_SUBJECT:
+               return CRITERIA_SUBJECT;
+       case MATCHING_NOT_FROM:
+       case MATCHING_FROM:
+               return CRITERIA_FROM;
+       case MATCHING_NOT_TO:
+       case MATCHING_TO:
+               return CRITERIA_TO;
+       case MATCHING_NOT_CC:
+       case MATCHING_CC:
+               return CRITERIA_CC;
+       case MATCHING_NOT_NEWSGROUPS:
+       case MATCHING_NEWSGROUPS:
+               return CRITERIA_NEWSGROUPS;
+       case MATCHING_NOT_INREPLYTO:
+       case MATCHING_INREPLYTO:
+               return CRITERIA_INREPLYTO;
+       case MATCHING_NOT_REFERENCES:
+       case MATCHING_REFERENCES:
+               return CRITERIA_REFERENCES;
+       case MATCHING_NOT_TO_AND_NOT_CC:
+       case MATCHING_TO_OR_CC:
+               return CRITERIA_TO_OR_CC;
+       case MATCHING_NOT_BODY_PART:
+       case MATCHING_BODY_PART:
+               return CRITERIA_BODY_PART;
+       case MATCHING_NOT_MESSAGE:
+       case MATCHING_MESSAGE:
+               return CRITERIA_MESSAGE;
+               break;
+       case MATCHING_NOT_HEADERS_PART:
+       case MATCHING_HEADERS_PART:
+               return CRITERIA_HEADERS_PART;
+       case MATCHING_NOT_HEADER:
+       case MATCHING_HEADER:
+               return CRITERIA_HEADER;
+       case MATCHING_AGE_GREATER:
+               return CRITERIA_AGE_GREATER;
+       case MATCHING_AGE_LOWER:
+               return CRITERIA_AGE_LOWER;
+       case MATCHING_SCORE_GREATER:
+               return CRITERIA_SCORE_GREATER;
+       case MATCHING_SCORE_LOWER:
+               return CRITERIA_SCORE_LOWER;
+       default:
+               return -1;
+       }
+}
+
 static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
 {
        switch (criteria_id) {
@@ -995,6 +1069,7 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
        gchar * tmp;
        MatcherProp * prop;
        gboolean negative_cond;
+       gint criteria;
 
        if (!gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
                                row, 0, &matcher_str))
@@ -1012,156 +1087,31 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
        if (tmp == NULL)
                return;
 
-       switch(prop->criteria) {
-       case MATCHING_ALL:
+       criteria = prefs_matcher_get_criteria_from_matching(prop->criteria);
+       if (criteria != -1)
                gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_ALL);
-               break;
+                                    criteria);
 
+       switch(prop->criteria) {
        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:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_SUBJECT);
-               break;
-
        case MATCHING_NOT_FROM:
-               negative_cond = TRUE;
-       case MATCHING_FROM:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_FROM);
-               break;
-
        case MATCHING_NOT_TO:
-               negative_cond = TRUE;
-       case MATCHING_TO:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_TO);
-               break;
-
        case MATCHING_NOT_CC:
-               negative_cond = TRUE;
-       case MATCHING_CC:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_CC);
-               break;
-
        case MATCHING_NOT_NEWSGROUPS:
-               negative_cond = TRUE;
-       case MATCHING_NEWSGROUPS:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_NEWSGROUPS);
-               break;
-
        case MATCHING_NOT_INREPLYTO:
-               negative_cond = TRUE;
-       case MATCHING_INREPLYTO:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_INREPLYTO);
-               break;
-
        case MATCHING_NOT_REFERENCES:
-               negative_cond = TRUE;
-       case MATCHING_REFERENCES:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_REFERENCES);
-               break;
-
        case MATCHING_NOT_TO_AND_NOT_CC:
-               negative_cond = TRUE;
-       case MATCHING_TO_OR_CC:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_TO_OR_CC);
-               break;
-
        case MATCHING_NOT_BODY_PART:
-               negative_cond = TRUE;
-       case MATCHING_BODY_PART:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_BODY_PART);
-               break;
-
        case MATCHING_NOT_MESSAGE:
-               negative_cond = TRUE;
-       case MATCHING_MESSAGE:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_MESSAGE);
-               break;
-
        case MATCHING_NOT_HEADERS_PART:
-               negative_cond = TRUE;
-       case MATCHING_HEADERS_PART:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_HEADERS_PART);
-               break;
-
        case MATCHING_NOT_HEADER:
                negative_cond = TRUE;
-       case MATCHING_HEADER:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_HEADER);
-               break;
-
-       case MATCHING_AGE_GREATER:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_AGE_GREATER);
-               break;
-
-       case MATCHING_AGE_LOWER:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_AGE_LOWER);
-               break;
-
-       case MATCHING_SCORE_GREATER:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_SCORE_GREATER);
-               break;
-
-       case MATCHING_SCORE_LOWER:
-               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
-                                    CRITERIA_SCORE_LOWER);
                break;
        }
        
index 478475c..79e1018 100644 (file)
@@ -483,6 +483,8 @@ static void prefs_scoring_register_cb(void)
        prefs_scoring_clist_set_row(-1, prop);
 
        scoringprop_free(prop);
+
+       prefs_scoring_reset_dialog();
 }
 
 static void prefs_scoring_substitute_cb(void)
@@ -527,6 +529,8 @@ static void prefs_scoring_substitute_cb(void)
        prefs_scoring_clist_set_row(row, prop);
 
        scoringprop_free(prop);
+
+       prefs_scoring_reset_dialog();
 }
 
 static void prefs_scoring_delete_cb(void)
@@ -602,10 +606,15 @@ static void prefs_scoring_select(GtkCList *clist, gint row, gint column,
 
        gchar * scoring_str;
 
+       if (row == 0) {
+               prefs_scoring_reset_dialog();
+               return;
+       }
+
         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)