fix bug 2986, 'Down and Delete buttons have same hotkey in filtering config' and...
[claws.git] / src / prefs_matcher.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
35
36 #if !GTK_CHECK_VERSION(3, 0, 0)
37 #include "gtkcmoptionmenu.h"
38 #endif
39 #include "main.h"
40 #include "prefs_gtk.h"
41 #include "prefs_matcher.h"
42 #include "prefs_common.h"
43 #include "mainwindow.h"
44 #include "foldersel.h"
45 #include "manage_window.h"
46 #include "inc.h"
47 #include "matcher.h"
48 #include "utils.h"
49 #include "gtkutils.h"
50 #include "alertpanel.h"
51 #include "folder.h"
52 #include "description_window.h"
53 #include "combobox.h"
54
55 #include "matcher_parser.h"
56 #include "colorlabel.h"
57 #include "tags.h"
58 #ifndef USE_NEW_ADDRBOOK
59         #include "addressbook.h"
60 #endif
61
62 #ifndef USE_NEW_ADDRBOOK
63 static void prefs_matcher_addressbook_select(void);
64 #endif
65 static void prefs_matcher_test_info(GtkWidget *widget, GtkWidget *parent);
66
67 enum {
68         PREFS_MATCHER_COND,
69         PREFS_MATCHER_COND_VALID,
70         N_PREFS_MATCHER_COLUMNS
71 };
72
73 /*!
74  *\brief        UI data for matcher dialog
75  */
76 static struct Matcher {
77         GtkWidget *window;
78
79         GtkWidget *ok_btn;
80
81         GtkWidget *match_combo;
82         GtkWidget *header_addr_combo;
83         GtkWidget *bool_op_combo;
84         GtkWidget *criteria_label2;
85         GtkWidget *criteria_combo;
86         GtkWidget *criteria_combo2;
87         GtkWidget *match_combo2;
88         GtkWidget *match_label;
89         GtkWidget *match_label2;
90         GtkWidget *headers_combo;
91         GtkWidget *upper_filler;
92         GtkWidget *lower_filler;
93
94         GtkWidget *header_entry;
95         GtkWidget *header_addr_entry;
96         GtkWidget *string_entry;
97         GtkWidget *numeric_entry;
98         GtkWidget *numeric_label;
99         GtkWidget *addressbook_folder_combo;
100         GtkWidget *case_checkbtn;
101 #ifndef G_OS_WIN32
102         GtkWidget *regexp_checkbtn;
103 #endif
104 #if !GTK_CHECK_VERSION(3, 0, 0)
105         GtkWidget *color_optmenu;
106 #endif
107
108         GtkWidget *test_btn;
109         GtkWidget *addressbook_select_btn;
110
111         GtkTreeModel *model_age;
112         GtkTreeModel *model_age_units;
113         GtkTreeModel *model_contain;
114         GtkTreeModel *model_found;
115         GtkTreeModel *model_flags;
116         GtkTreeModel *model_headers;
117         GtkTreeModel *model_partial;
118         GtkTreeModel *model_phrase;
119         GtkTreeModel *model_score;
120         GtkTreeModel *model_set;
121         GtkTreeModel *model_size;
122         GtkTreeModel *model_size_units;
123         GtkTreeModel *model_tags;
124         GtkTreeModel *model_test;
125         GtkTreeModel *model_thread;
126         
127         GtkWidget *cond_list_view;
128
129         gint selected_criteria; /*!< selected criteria in combobox */ 
130 } matcher;
131
132 /*!
133  *\brief        Conditions with a negate counterpart (like unread and ~unread)
134  *              have the same CRITERIA_XXX id). I.e. both unread and ~unread
135  *              have criteria id CRITERIA_UNREAD. This id is passed as the
136  *              first parameter to #matcherprop_new and #matcherprop_unquote_new.
137  */             
138 enum {
139         CRITERIA_ALL = 0,
140
141         CRITERIA_SUBJECT = 1,
142         CRITERIA_FROM = 2,
143         CRITERIA_TO = 3,
144         CRITERIA_CC = 4,
145         CRITERIA_TO_OR_CC = 5,
146         CRITERIA_NEWSGROUPS = 6,
147         CRITERIA_INREPLYTO = 7,
148         CRITERIA_REFERENCES = 8,
149         CRITERIA_AGE_GREATER = 9,
150         CRITERIA_AGE_LOWER = 10,
151         CRITERIA_HEADER = 11,
152         CRITERIA_HEADERS_PART = 12,
153         CRITERIA_BODY_PART = 13,
154         CRITERIA_MESSAGE = 14,
155
156         CRITERIA_UNREAD = 15,
157         CRITERIA_NEW = 16,
158         CRITERIA_MARKED = 17,
159         CRITERIA_DELETED = 18,
160         CRITERIA_REPLIED = 19,
161         CRITERIA_FORWARDED = 20,
162         CRITERIA_LOCKED = 21,
163         CRITERIA_SPAM = 22,
164         CRITERIA_COLORLABEL = 23,
165         CRITERIA_IGNORE_THREAD = 24,
166         CRITERIA_WATCH_THREAD = 25,
167
168         CRITERIA_SCORE_GREATER = 26,
169         CRITERIA_SCORE_LOWER = 27,
170         CRITERIA_SCORE_EQUAL = 28,
171
172         CRITERIA_TEST = 29,
173
174         CRITERIA_SIZE_GREATER = 30,
175         CRITERIA_SIZE_SMALLER = 31,
176         CRITERIA_SIZE_EQUAL   = 32,
177         
178         CRITERIA_PARTIAL = 33,
179
180         CRITERIA_FOUND_IN_ADDRESSBOOK = 34,
181         
182         CRITERIA_TAG = 35,
183         CRITERIA_TAGGED = 36,
184
185         CRITERIA_HAS_ATTACHMENT = 37,
186         CRITERIA_SIGNED = 38,
187
188         CRITERIA_AGE_GREATER_HOURS = 39,
189         CRITERIA_AGE_LOWER_HOURS = 40
190 };
191
192 enum {
193         MATCH_ALL       = 0,
194         MATCH_HEADER    = 1,
195         MATCH_AGE       = 2,
196         MATCH_PHRASE    = 3,
197         MATCH_FLAG      = 4,
198         MATCH_LABEL     = 5,
199         MATCH_THREAD    = 6,
200         MATCH_SCORE     = 7,
201         MATCH_SIZE      = 8,
202         MATCH_PARTIAL   = 9,
203         MATCH_ABOOK     = 10,
204         MATCH_TAGS      = 11,
205         MATCH_TEST      = 12
206 };
207
208 enum {
209         AGE_HOURS = 0,
210         AGE_DAYS  = 1,
211         AGE_WEEKS = 2
212 };
213
214 enum {
215         SIZE_UNIT_BYTES  = 0,
216         SIZE_UNIT_KBYTES = 1,
217         SIZE_UNIT_MBYTES = 2
218 };
219
220 #define MB_SIZE 0x100000
221 #define KB_SIZE 0x000400
222
223 enum {
224         THREAD_IGNORED = 0,
225         THREAD_NOT_IGNORED = 1,
226         THREAD_WATCHED = 2,
227         THREAD_NOT_WATCHED = 3
228 };
229
230 /*!
231  *\brief        Contains predicate      
232  */
233 enum {
234         PREDICATE_CONTAINS = 0,
235         PREDICATE_DOES_NOT_CONTAIN = 1
236 };
237
238 /*!
239  *\brief        Enabled predicate
240  */
241 enum {
242         PREDICATE_FLAG_ENABLED = 0,
243         PREDICATE_FLAG_DISABLED = 1
244 };
245
246 /*!
247  *\brief        Hooks
248  */
249 static PrefsMatcherSignal *matchers_callback;
250
251 /* widget creating functions */
252 static void prefs_matcher_create        (void);
253
254 static void prefs_matcher_set_dialog    (MatcherList *matchers);
255 static void prefs_matcher_list_view_set_row     (GtkTreeIter *row, 
256                                                  MatcherProp *prop);
257
258 /* callback functions */
259
260 static void prefs_matcher_register_cb   (void);
261 static void prefs_matcher_substitute_cb (void);
262 static void prefs_matcher_delete_cb     (void);
263 static void prefs_matcher_up            (void);
264 static void prefs_matcher_down          (void);
265 static gboolean prefs_matcher_key_pressed(GtkWidget     *widget,
266                                          GdkEventKey    *event,
267                                          gpointer        data);
268 static void prefs_matcher_ok            (void);
269 static void prefs_matcher_cancel        (void);
270 static gint prefs_matcher_deleted       (GtkWidget *widget, GdkEventAny *event,
271                                          gpointer data);
272 static void prefs_matcher_criteria_select       (GtkWidget *widget,
273                                                  gpointer   user_data);
274 static void prefs_matcher_second_criteria_sel   (GtkWidget *widget,
275                                                  gpointer   user_data);
276 static void prefs_matcher_set_model             (GtkWidget *wiget,
277                                                  GtkTreeModel *model);
278 static MatcherList *prefs_matcher_get_list      (void);
279
280 static GtkListStore* prefs_matcher_create_data_store    (void);
281
282 static void prefs_matcher_list_view_insert_matcher      (GtkWidget *list_view,
283                                                          GtkTreeIter *row_iter,
284                                                          const gchar *matcher,
285                                                          gboolean is_valid);
286
287 static GtkWidget *prefs_matcher_list_view_create        (void);
288
289 static void prefs_matcher_create_list_view_columns      (GtkWidget *list_view);
290
291 static gboolean prefs_matcher_selected                  (GtkTreeSelection *selector,
292                                                          GtkTreeModel *model, 
293                                                          GtkTreePath *path,
294                                                          gboolean currently_selected,
295                                                          gpointer data);
296
297 static int header_name_to_crit(const gchar *header)
298 {
299         if (header == NULL)
300                 return CRITERIA_HEADER;
301
302         if (!strcasecmp(header, "Subject"))
303                 return CRITERIA_SUBJECT;
304         if (!strcasecmp(header, "From"))
305                 return CRITERIA_FROM;
306         if (!strcasecmp(header, "To"))
307                 return CRITERIA_TO;
308         if (!strcasecmp(header, "Cc"))
309                 return CRITERIA_CC;
310         if (!strcasecmp(header, "To or Cc"))
311                 return CRITERIA_TO_OR_CC;
312         if (!strcasecmp(header, "In-Reply-To"))
313                 return CRITERIA_INREPLYTO;
314         if (!strcasecmp(header, "Newsgroups"))
315                 return CRITERIA_NEWSGROUPS;
316         if (!strcasecmp(header, "References"))
317                 return CRITERIA_REFERENCES;
318
319         return CRITERIA_HEADER;
320 }
321
322 static void prefs_matcher_models_create(void)
323 {
324         GtkListStore *store;
325         GtkTreeIter iter;
326         
327         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
328         COMBOBOX_ADD(store, _("more than"), CRITERIA_AGE_GREATER);
329         COMBOBOX_ADD(store, _("less than"), CRITERIA_AGE_LOWER);
330         matcher.model_age = GTK_TREE_MODEL(store);
331
332         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
333         COMBOBOX_ADD(store, _("hours"), AGE_HOURS);
334         COMBOBOX_ADD(store, _("days"), AGE_DAYS);
335         COMBOBOX_ADD(store, _("weeks"), AGE_WEEKS);
336         matcher.model_age_units = GTK_TREE_MODEL(store);
337
338         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
339         COMBOBOX_ADD(store, _("higher than"), CRITERIA_SCORE_GREATER);
340         COMBOBOX_ADD(store, _("lower than"), CRITERIA_SCORE_LOWER);
341         COMBOBOX_ADD(store, _("exactly"), CRITERIA_SCORE_EQUAL);
342         matcher.model_score = GTK_TREE_MODEL(store);
343         
344         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
345         COMBOBOX_ADD(store, _("greater than"), CRITERIA_SIZE_GREATER);
346         COMBOBOX_ADD(store, _("smaller than"), CRITERIA_SIZE_SMALLER);
347         COMBOBOX_ADD(store, _("exactly"), CRITERIA_SIZE_EQUAL);
348         matcher.model_size = GTK_TREE_MODEL(store);
349
350         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
351         COMBOBOX_ADD(store, _("bytes"), SIZE_UNIT_BYTES);
352         COMBOBOX_ADD(store, _("kilobytes"), SIZE_UNIT_KBYTES);
353         COMBOBOX_ADD(store, _("megabytes"), SIZE_UNIT_MBYTES);
354         matcher.model_size_units = GTK_TREE_MODEL(store);
355         
356         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
357         COMBOBOX_ADD(store, _("contains"), 0);
358         COMBOBOX_ADD(store, _("doesn't contain"), 0);
359         matcher.model_contain = GTK_TREE_MODEL(store);
360         
361         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
362         COMBOBOX_ADD(store, "Subject", CRITERIA_SUBJECT);
363         COMBOBOX_ADD(store, "From", CRITERIA_FROM);
364         COMBOBOX_ADD(store, "To", CRITERIA_TO);
365         COMBOBOX_ADD(store, "Cc", CRITERIA_CC);
366         COMBOBOX_ADD(store, "To or Cc", CRITERIA_TO_OR_CC);
367         COMBOBOX_ADD(store, "In-Reply-To", CRITERIA_INREPLYTO);
368         COMBOBOX_ADD(store, "Newsgroups", CRITERIA_NEWSGROUPS);
369         COMBOBOX_ADD(store, "References", CRITERIA_REFERENCES);
370         COMBOBOX_ADD(store, "Sender", CRITERIA_HEADER);
371         COMBOBOX_ADD(store, "X-ML-Name", CRITERIA_HEADER);
372         COMBOBOX_ADD(store, "X-List", CRITERIA_HEADER);
373         COMBOBOX_ADD(store, "X-Sequence", CRITERIA_HEADER);
374         COMBOBOX_ADD(store, "X-Mailer", CRITERIA_HEADER);
375         COMBOBOX_ADD(store, "X-BeenThere", CRITERIA_HEADER);
376         COMBOBOX_ADD(store, "List-Post", CRITERIA_HEADER);
377         COMBOBOX_ADD(store, "List-Id", CRITERIA_HEADER);
378         matcher.model_headers = GTK_TREE_MODEL(store);
379         
380         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
381         COMBOBOX_ADD(store, _("headers part"), CRITERIA_HEADERS_PART);
382         COMBOBOX_ADD(store, _("body part"), CRITERIA_BODY_PART);
383         COMBOBOX_ADD(store, _("whole message"), CRITERIA_MESSAGE);
384         matcher.model_phrase = GTK_TREE_MODEL(store);
385         
386         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
387         COMBOBOX_ADD(store, _("Unread"), CRITERIA_UNREAD);
388         COMBOBOX_ADD(store, _("New"), CRITERIA_NEW);
389         COMBOBOX_ADD(store, _("Marked"), CRITERIA_MARKED);
390         COMBOBOX_ADD(store, _("Deleted"), CRITERIA_DELETED);
391         COMBOBOX_ADD(store, _("Replied"), CRITERIA_REPLIED);
392         COMBOBOX_ADD(store, _("Forwarded"), CRITERIA_FORWARDED);
393         COMBOBOX_ADD(store, _("Locked"), CRITERIA_LOCKED);
394         COMBOBOX_ADD(store, _("Spam"), CRITERIA_SPAM);
395         COMBOBOX_ADD(store, _("Has attachment"), CRITERIA_HAS_ATTACHMENT);
396         COMBOBOX_ADD(store, _("Signed"), CRITERIA_SIGNED);
397         matcher.model_flags = GTK_TREE_MODEL(store);
398         
399         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
400         COMBOBOX_ADD(store, _("set"), 0);
401         COMBOBOX_ADD(store, _("not set"), 1);
402         matcher.model_set = GTK_TREE_MODEL(store);
403
404         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
405         COMBOBOX_ADD(store, _("yes"), CRITERIA_PARTIAL);
406         COMBOBOX_ADD(store, _("no"), CRITERIA_PARTIAL);
407         matcher.model_partial = GTK_TREE_MODEL(store);
408
409         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
410         COMBOBOX_ADD(store, _("Any tags"), CRITERIA_TAGGED);
411         COMBOBOX_ADD(store, _("Specific tag"), CRITERIA_TAG);
412         matcher.model_tags = GTK_TREE_MODEL(store);
413
414         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
415         COMBOBOX_ADD(store, _("ignored"), CRITERIA_IGNORE_THREAD);
416         COMBOBOX_ADD(store, _("not ignored"), CRITERIA_IGNORE_THREAD);
417         COMBOBOX_ADD(store, _("watched"), CRITERIA_WATCH_THREAD);
418         COMBOBOX_ADD(store, _("not watched"), CRITERIA_WATCH_THREAD);
419         matcher.model_thread = GTK_TREE_MODEL(store);
420         
421         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
422         COMBOBOX_ADD(store, _("found"), 0);
423         COMBOBOX_ADD(store, _("not found"), 1);
424         matcher.model_found = GTK_TREE_MODEL(store);
425
426         store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
427         COMBOBOX_ADD(store, _("0 (Passed)"), 0);
428         COMBOBOX_ADD(store, _("non-0 (Failed)"), 1);
429         matcher.model_test = GTK_TREE_MODEL(store);
430 }
431
432 /*!
433  *\brief        Opens the matcher dialog with a list of conditions
434  *
435  *\param        matchers List of conditions
436  *\param        cb Callback
437  *
438  */
439 void prefs_matcher_open(MatcherList *matchers, PrefsMatcherSignal *cb)
440 {
441         inc_lock();
442
443         if (!matcher.window) {
444                 prefs_matcher_models_create();
445                 prefs_matcher_create();
446         } else {
447 #if !GTK_CHECK_VERSION(3, 0, 0)
448                 /* update color label menu */
449                 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(matcher.color_optmenu),
450                                 colorlabel_create_color_menu());
451 #endif
452         }
453
454         manage_window_set_transient(GTK_WINDOW(matcher.window));
455         gtk_widget_grab_focus(matcher.ok_btn);
456
457         matchers_callback = cb;
458
459         prefs_matcher_set_dialog(matchers);
460
461         gtk_widget_show(matcher.window);
462         gtk_window_set_modal(GTK_WINDOW(matcher.window), TRUE);
463 }
464
465 /*!
466  *\brief        Save Gtk object size to prefs dataset
467  */
468 static void prefs_matcher_size_allocate_cb(GtkWidget *widget,
469                                          GtkAllocation *allocation)
470 {
471         cm_return_if_fail(allocation != NULL);
472
473         prefs_common.matcherwin_width = allocation->width;
474         prefs_common.matcherwin_height = allocation->height;
475 }
476
477 /*!
478  *\brief        Create the matcher dialog
479  */
480 static void prefs_matcher_create(void)
481 {
482         GtkWidget *window;
483         GtkWidget *vbox;
484         GtkWidget *ok_btn;
485         GtkWidget *cancel_btn;
486         GtkWidget *confirm_area;
487
488         GtkWidget *vbox1;
489         GtkWidget *frame;
490         GtkWidget *table;
491         GtkWidget *upper_hbox;
492         GtkWidget *lower_hbox;
493         GtkWidget *match_hbox;
494         GtkWidget *criteria_combo;
495         GtkWidget *criteria_label;
496         GtkWidget *match_label;
497         GtkWidget *criteria_label2;
498         GtkWidget *headers_combo;
499         GtkWidget *match_combo2;
500         GtkWidget *match_label2;
501
502         GtkWidget *hbox;
503         GtkWidget *upper_filler;
504         GtkWidget *lower_filler;
505         
506         GtkWidget *criteria_combo2;
507         GtkWidget *header_entry;
508         GtkWidget *header_addr_combo;
509         GtkWidget *header_addr_entry;
510         GtkWidget *string_entry;
511         GtkWidget *addressbook_folder_combo;
512         GtkWidget *match_combo;
513         GtkWidget *bool_op_combo;
514         GtkWidget *bool_op_label;
515
516         GtkWidget *numeric_hbox;
517         GtkWidget *numeric_entry;
518         GtkWidget *numeric_label;
519         
520 #ifndef G_OS_WIN32
521         GtkWidget *regexp_checkbtn;
522 #endif
523         GtkWidget *case_checkbtn;
524
525         GtkWidget *reg_hbox;
526         GtkWidget *btn_hbox;
527         GtkWidget *arrow;
528         GtkWidget *reg_btn;
529         GtkWidget *subst_btn;
530         GtkWidget *del_btn;
531
532         GtkWidget *cond_hbox;
533         GtkWidget *cond_scrolledwin;
534         GtkWidget *cond_list_view;
535
536         GtkWidget *btn_vbox;
537         GtkWidget *up_btn;
538         GtkWidget *down_btn;
539
540         GtkWidget *test_btn;
541         GtkWidget *addressbook_select_btn;
542 #if !GTK_CHECK_VERSION(3, 0, 0)
543         GtkWidget *color_optmenu;
544 #endif
545
546         static GdkGeometry geometry;
547         GtkSizeGroup *size_group;
548         GtkListStore *store;
549         GtkTreeIter iter;
550
551         debug_print("Creating matcher configuration window...\n");
552
553         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_matcher");
554         gtk_container_set_border_width(GTK_CONTAINER(window), 4);
555         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
556
557         vbox = gtk_vbox_new(FALSE, 6);
558         gtk_container_add(GTK_CONTAINER(window), vbox);
559
560         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
561                                       &ok_btn, GTK_STOCK_OK, NULL, NULL);
562         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
563         gtk_widget_grab_default(ok_btn);
564
565         gtk_window_set_title(GTK_WINDOW(window),
566                              _("Condition configuration"));
567         g_signal_connect(G_OBJECT(window), "delete_event",
568                          G_CALLBACK(prefs_matcher_deleted), NULL);
569         g_signal_connect(G_OBJECT(window), "size_allocate",
570                          G_CALLBACK(prefs_matcher_size_allocate_cb), NULL);
571         g_signal_connect(G_OBJECT(window), "key_press_event",
572                          G_CALLBACK(prefs_matcher_key_pressed), NULL);
573         MANAGE_WINDOW_SIGNALS_CONNECT(window);
574         g_signal_connect(G_OBJECT(ok_btn), "clicked",
575                          G_CALLBACK(prefs_matcher_ok), NULL);
576         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
577                          G_CALLBACK(prefs_matcher_cancel), NULL);
578
579         vbox1 = gtk_vbox_new(FALSE, VSPACING);
580         gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
581         gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
582
583         frame = gtk_frame_new(_("Rule"));
584         gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5);
585         gtk_box_pack_start(GTK_BOX(vbox1), frame, FALSE, FALSE, 0);
586         
587         table = gtk_table_new(3, 3, FALSE);
588         gtk_container_add(GTK_CONTAINER(frame), table);
589         gtk_widget_set_size_request(frame, -1, 105);
590         
591         upper_hbox = gtk_hbox_new(FALSE, HSPACING_NARROW);
592         hbox = gtk_hbox_new(FALSE, 0);
593         gtk_box_pack_start(GTK_BOX(hbox), upper_hbox, FALSE, FALSE, 0);
594         gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(""), TRUE, TRUE, 0);
595         gtk_table_attach(GTK_TABLE(table), hbox, 2, 3, 0, 1, 
596                         GTK_FILL, GTK_SHRINK, 2, 2);
597         
598         lower_hbox = gtk_hbox_new(FALSE, HSPACING_NARROW);
599         hbox = gtk_hbox_new(FALSE, 0);
600         gtk_box_pack_start(GTK_BOX(hbox), lower_hbox, FALSE, FALSE, 0);
601         gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(""), TRUE, TRUE, 0);
602         gtk_table_attach(GTK_TABLE(table), hbox,2, 3, 1, 2, 
603                          GTK_FILL, GTK_SHRINK, 2, 2);
604         
605         size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
606         gtk_size_group_add_widget(size_group, upper_hbox);
607         gtk_size_group_add_widget(size_group, lower_hbox);
608         
609         /* criteria combo box */
610         criteria_label = gtk_label_new(_("Match criteria:"));
611         gtk_misc_set_alignment(GTK_MISC(criteria_label), 1, 0.5);
612         gtk_widget_set_size_request(criteria_label, 100, -1);
613         gtk_table_attach(GTK_TABLE(table), criteria_label, 0, 1, 0, 1, 
614                          GTK_FILL, GTK_SHRINK, 2, 2);
615
616         criteria_combo = gtkut_sc_combobox_create(NULL, FALSE);
617         store = GTK_LIST_STORE(gtk_combo_box_get_model(
618                                 GTK_COMBO_BOX(criteria_combo)));
619         COMBOBOX_ADD(store, _("All messages"), 0);
620         COMBOBOX_ADD(store, _("Header"), 1);
621         COMBOBOX_ADD(store, _("Age"), 2);
622         COMBOBOX_ADD(store, _("Phrase"), 3);
623         COMBOBOX_ADD(store, _("Flags"), 4);
624         COMBOBOX_ADD(store, _("Color labels"), 5);
625         COMBOBOX_ADD(store, _("Thread"), 6);
626         COMBOBOX_ADD(store, _("Score"), 7);
627         COMBOBOX_ADD(store, _("Size"), 8);
628         COMBOBOX_ADD(store, _("Partially downloaded"), 9);
629         COMBOBOX_ADD(store, _("Address book"), 10);
630         COMBOBOX_ADD(store, _("Tags"), 11);
631         COMBOBOX_ADD(store, _("External program test"), 12);
632
633         gtk_widget_set_size_request(criteria_combo, 150, -1);
634         gtk_combo_box_set_active(GTK_COMBO_BOX(criteria_combo), MATCH_ALL);
635         gtk_table_attach(GTK_TABLE(table), criteria_combo, 1, 2, 0, 1,
636                          GTK_FILL, GTK_SHRINK, 2, 2);
637         g_signal_connect(G_OBJECT(criteria_combo), "changed",
638                          G_CALLBACK(prefs_matcher_criteria_select),
639                          NULL);
640         
641         upper_filler = gtk_label_new("");
642         gtk_box_pack_start(GTK_BOX(upper_hbox), upper_filler, TRUE, TRUE, 0); 
643         
644         lower_filler = gtk_label_new("");
645         gtk_box_pack_start(GTK_BOX(lower_hbox), lower_filler, TRUE, TRUE, 0);
646                          
647         criteria_label2 = gtk_label_new("");
648         gtk_box_pack_start(GTK_BOX(upper_hbox), criteria_label2, FALSE, FALSE, 0);
649
650         /* headers combo box entry */
651 #if !GTK_CHECK_VERSION(2, 24, 0)
652         headers_combo = gtk_combo_box_entry_new_with_model(matcher.model_headers, 0);
653 #else
654         headers_combo = gtk_combo_box_new_with_model_and_entry(matcher.model_headers);
655         GtkCellRenderer *cell = gtk_cell_renderer_text_new();
656         gtk_cell_renderer_set_alignment(cell, 0.0, 0.5);
657         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(headers_combo), cell, TRUE);
658         gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(headers_combo), 0);
659 #endif
660         gtk_widget_set_size_request(headers_combo, 100, -1);
661         gtk_box_pack_start(GTK_BOX(upper_hbox), headers_combo, TRUE, TRUE, 0);
662         header_entry = gtk_bin_get_child(GTK_BIN((headers_combo)));
663         
664         criteria_combo2 = gtkut_sc_combobox_create(NULL, TRUE);
665         prefs_matcher_set_model(criteria_combo2, matcher.model_phrase);
666         gtk_box_pack_start(GTK_BOX(upper_hbox), criteria_combo2, TRUE, TRUE, 0);
667         g_signal_connect(G_OBJECT(criteria_combo2), "changed",
668                          G_CALLBACK(prefs_matcher_second_criteria_sel),
669                          NULL);
670
671         /* book/folder value */
672         addressbook_folder_combo = combobox_text_new(TRUE, _("Any"), NULL);
673         gtk_widget_set_size_request(addressbook_folder_combo, 150, -1);
674         gtk_box_pack_start(GTK_BOX(upper_hbox), addressbook_folder_combo, TRUE, TRUE, 0);                        
675
676         addressbook_select_btn = gtk_button_new_with_label(_("Select..."));
677         gtk_box_pack_start(GTK_BOX(upper_hbox), addressbook_select_btn, FALSE, FALSE, 0);
678 #ifndef USE_NEW_ADDRBOOK
679         g_signal_connect(G_OBJECT (addressbook_select_btn), "clicked",
680                          G_CALLBACK(prefs_matcher_addressbook_select),
681                          NULL);
682 #else
683         gtk_widget_set_sensitive(GTK_WIDGET(addressbook_select_btn), FALSE);
684 #endif
685         match_label = gtk_label_new("");
686         gtk_misc_set_alignment(GTK_MISC(match_label), 1, 0.5);
687         gtk_table_attach(GTK_TABLE(table), match_label, 0, 1, 1, 2,
688                          GTK_FILL, GTK_SHRINK, 2, 2);
689
690         match_hbox = gtk_hbox_new(FALSE, 0);
691         gtk_table_attach(GTK_TABLE(table), match_hbox, 1, 2, 1, 2,
692                          GTK_FILL, GTK_SHRINK, 2, 2); 
693
694         match_combo = gtkut_sc_combobox_create(NULL, TRUE);
695         gtk_box_pack_start(GTK_BOX(match_hbox), match_combo, TRUE, TRUE, 0);
696         
697 #if !GTK_CHECK_VERSION(3, 0, 0)
698         /* color labels combo */
699         color_optmenu = gtk_cmoption_menu_new();
700         gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
701                                  colorlabel_create_color_menu());
702         gtk_box_pack_start(GTK_BOX(match_hbox), color_optmenu, FALSE, FALSE, 0);
703 #endif
704         
705         /* address header name */
706         header_addr_combo = combobox_text_new(TRUE,
707                               C_("Filtering Matcher Menu", "All"), _("Any"),
708                               "From", "To", "Cc", "Reply-To", "Sender", NULL);
709         gtk_box_pack_start(GTK_BOX(match_hbox), header_addr_combo, FALSE, FALSE, 0);
710         header_addr_entry = gtk_bin_get_child(GTK_BIN((header_addr_combo)));
711         gtk_widget_set_size_request(header_addr_combo, 150, -1);
712         
713         match_label2 = gtk_label_new("");
714         gtk_box_pack_start(GTK_BOX(lower_hbox), match_label2, FALSE, FALSE, 0);
715
716         /* numeric value */
717         numeric_hbox = gtk_hbox_new(FALSE, HSPACING_NARROW);
718         gtk_box_pack_start(GTK_BOX(lower_hbox), numeric_hbox, FALSE, FALSE, 0);
719
720         numeric_entry = gtk_spin_button_new_with_range(0, 1000, 1);
721         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(numeric_entry), 0);
722         gtk_box_pack_start(GTK_BOX(numeric_hbox), numeric_entry, FALSE, FALSE, 0);
723         
724         numeric_label = gtk_label_new("");
725         gtk_box_pack_start(GTK_BOX(numeric_hbox), numeric_label, FALSE, FALSE, 0);
726         gtk_box_pack_end(GTK_BOX(numeric_hbox), gtk_label_new(""), TRUE, TRUE, 0);
727
728         match_combo2 = gtkut_sc_combobox_create(NULL, TRUE);
729         gtk_box_pack_start(GTK_BOX(lower_hbox), match_combo2, TRUE, TRUE, 0);
730         
731         /* string value */
732         string_entry = gtk_entry_new();
733         gtk_box_pack_start(GTK_BOX(lower_hbox), string_entry, TRUE, TRUE, 0);
734
735         hbox = gtk_hbox_new(FALSE, HSPACING_NARROW);
736         gtk_size_group_add_widget(size_group, hbox);
737         PACK_CHECK_BUTTON(hbox, case_checkbtn, _("Case sensitive"));
738 #ifndef G_OS_WIN32
739         PACK_CHECK_BUTTON(hbox, regexp_checkbtn, _("Use regexp"));
740 #endif
741         gtk_box_pack_end(GTK_BOX(hbox), gtk_label_new(""), TRUE, TRUE, 0);
742         gtk_table_attach(GTK_TABLE(table), hbox, 2, 3, 2, 3,
743                          GTK_FILL, GTK_SHRINK, 4, 0);
744
745         /* test info button */
746         test_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
747         gtk_box_pack_start(GTK_BOX(lower_hbox), test_btn, FALSE, FALSE, 0);
748         g_signal_connect(G_OBJECT (test_btn), "clicked",
749                          G_CALLBACK(prefs_matcher_test_info),
750                          window);
751
752         /* register / substitute / delete */
753         reg_hbox = gtk_hbox_new(FALSE, HSPACING_NARROW);
754         gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
755
756         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
757         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
758         gtk_widget_set_size_request(arrow, -1, 16);
759
760         btn_hbox = gtk_hbox_new(FALSE, HSPACING_NARROW);
761         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
762
763         reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
764         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
765         g_signal_connect(G_OBJECT(reg_btn), "clicked",
766                          G_CALLBACK(prefs_matcher_register_cb), NULL);
767
768         subst_btn = gtkut_get_replace_btn(_("_Replace"));
769         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
770         g_signal_connect(G_OBJECT(subst_btn), "clicked",
771                          G_CALLBACK(prefs_matcher_substitute_cb),
772                          NULL);
773
774         del_btn = gtk_button_new_with_mnemonic (_("Re_move"));
775         gtk_button_set_image(GTK_BUTTON(del_btn),
776                         gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_BUTTON));
777         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
778         g_signal_connect(G_OBJECT(del_btn), "clicked",
779                          G_CALLBACK(prefs_matcher_delete_cb), NULL);
780
781         cond_hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
782         gtk_box_pack_start(GTK_BOX(vbox1), cond_hbox, TRUE, TRUE, 0);
783
784         cond_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
785         gtk_widget_set_size_request(cond_scrolledwin, -1, 150);
786         gtk_box_pack_start(GTK_BOX(cond_hbox), cond_scrolledwin,
787                            TRUE, TRUE, 0);
788         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cond_scrolledwin),
789                                        GTK_POLICY_AUTOMATIC,
790                                        GTK_POLICY_AUTOMATIC);
791
792         cond_list_view = prefs_matcher_list_view_create();                                     
793         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(cond_scrolledwin),
794                                             GTK_SHADOW_ETCHED_IN);
795         gtk_container_add(GTK_CONTAINER(cond_scrolledwin), cond_list_view);
796
797         btn_vbox = gtk_vbox_new(FALSE, VBOX_BORDER);
798         gtk_box_pack_start(GTK_BOX(cond_hbox), btn_vbox, FALSE, FALSE, 0);
799
800         up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
801         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
802         g_signal_connect(G_OBJECT(up_btn), "clicked",
803                          G_CALLBACK(prefs_matcher_up), NULL);
804
805         down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
806         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
807         g_signal_connect(G_OBJECT(down_btn), "clicked",
808                          G_CALLBACK(prefs_matcher_down), NULL);
809
810         /* boolean operation */
811         GtkWidget *hbox_bool = gtk_hbox_new(FALSE, HSPACING_NARROW);
812         gtk_box_pack_start(GTK_BOX(vbox1), hbox_bool, FALSE, FALSE, 0);
813
814         bool_op_label = gtk_label_new(_("Message must match"));
815         gtk_box_pack_start(GTK_BOX(hbox_bool), bool_op_label,
816                            FALSE, FALSE, 0);
817
818         bool_op_combo = combobox_text_new(FALSE, _("at least one"), 
819                                           _("all"), NULL);
820         gtk_box_pack_start(GTK_BOX(hbox_bool), bool_op_combo,
821                            FALSE, FALSE, 0);
822         gtk_box_pack_start(GTK_BOX(hbox_bool), gtk_label_new(_("of above rules")),
823                            FALSE, FALSE, 0);
824         gtk_box_pack_start(GTK_BOX(hbox_bool), gtk_label_new(""),
825                            TRUE, TRUE, 0);
826         
827         if (!geometry.min_height) {
828                 geometry.min_width = 550;
829                 geometry.min_height = 368;
830         }
831
832         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
833                                       GDK_HINT_MIN_SIZE);
834         gtk_widget_set_size_request(window, prefs_common.matcherwin_width,
835                                     prefs_common.matcherwin_height);
836
837         gtk_widget_show_all(window);
838
839         matcher.window    = window;
840
841         matcher.ok_btn = ok_btn;
842
843         matcher.criteria_combo = criteria_combo;
844         matcher.criteria_combo2 = criteria_combo2;
845         matcher.header_entry = header_entry;
846         matcher.header_addr_combo = header_addr_combo;
847         matcher.header_addr_entry = header_addr_entry;
848         matcher.string_entry = string_entry;
849         matcher.numeric_entry = numeric_entry;
850         matcher.numeric_label = numeric_label;
851         matcher.addressbook_folder_combo = addressbook_folder_combo;
852         matcher.match_combo = match_combo;
853         matcher.case_checkbtn = case_checkbtn;
854 #ifndef G_OS_WIN32
855         matcher.regexp_checkbtn = regexp_checkbtn;
856 #endif
857         matcher.bool_op_combo = bool_op_combo;
858         matcher.test_btn = test_btn;
859 #ifndef USE_NEW_ADDRBOOK
860         matcher.addressbook_select_btn = addressbook_select_btn;
861 #endif
862 #if !GTK_CHECK_VERSION(3, 0, 0)
863         matcher.color_optmenu = color_optmenu;
864 #endif
865         matcher.match_label = match_label;
866         matcher.criteria_label2 = criteria_label2;
867         matcher.headers_combo = headers_combo;
868         matcher.match_combo2 = match_combo2;
869         matcher.match_label2 = match_label2;
870         matcher.upper_filler = upper_filler;
871         matcher.lower_filler = lower_filler;
872         
873         matcher.cond_list_view = cond_list_view;
874
875         matcher.selected_criteria = -1;
876         prefs_matcher_criteria_select(criteria_combo, NULL);
877 }
878
879 /*!
880  *\brief        Set the contents of a row
881  *
882  *\param        row Index of row to set
883  *\param        prop Condition to set
884  *
885  *\return       gint Row index \a prop has been added
886  */
887 static void prefs_matcher_list_view_set_row(GtkTreeIter *row, MatcherProp *prop)
888 {
889         gchar *matcher_str;
890
891         if (prop == NULL) {
892                 prefs_matcher_list_view_insert_matcher(matcher.cond_list_view,
893                                                        NULL, _("(New)"), FALSE);
894                 return;                                                
895         }
896
897         matcher_str = matcherprop_to_string(prop);
898         if (!row)
899                 prefs_matcher_list_view_insert_matcher(matcher.cond_list_view,
900                                                        NULL, matcher_str,
901                                                        TRUE);
902         else
903                 prefs_matcher_list_view_insert_matcher(matcher.cond_list_view,
904                                                        row, matcher_str, 
905                                                        TRUE);
906         g_free(matcher_str);
907 }
908
909 static gboolean match_combo2_model_set(void)
910 {
911         GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(matcher.match_combo2));
912         if (model == matcher.model_age_units ||
913             model == matcher.model_found ||
914             model == matcher.model_partial ||
915             model == matcher.model_phrase ||
916             model == matcher.model_set ||
917             model == matcher.model_size_units ||
918             model == matcher.model_tags ||
919             model == matcher.model_thread)
920                 return TRUE;
921         else
922                 debug_print("match_combo2 model unset.\n");
923
924         return FALSE;
925 }
926
927 static gboolean match_combo_model_set(void)
928 {
929         GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(matcher.match_combo));
930         if (model == matcher.model_age ||
931             model == matcher.model_contain ||
932             model == matcher.model_flags ||
933             model == matcher.model_score ||
934             model == matcher.model_size ||
935             model == matcher.model_test)
936                 return TRUE;
937         else
938                 debug_print("match_combo model unset.\n");
939
940         return FALSE;
941 }
942
943 /*!
944  *\brief        Clears a condition in the list widget
945  */
946 static void prefs_matcher_reset_condition(void)
947 {
948         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo), MATCH_ALL);
949         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2), 0);
950         if (match_combo_model_set())
951                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo), 0);
952         if (match_combo2_model_set())
953                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2), 0);
954 #if !GTK_CHECK_VERSION(3, 0, 0)
955         gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(matcher.color_optmenu), 0);
956 #endif
957         gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
958         gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), "");
959         gtk_entry_set_text(GTK_ENTRY(matcher.header_addr_entry), "");
960         gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), "");
961         gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))), "");
962 #ifndef G_OS_WIN32
963         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
964 #endif
965         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
966 }
967
968 /*!
969  *\brief        Initializes dialog with a set of conditions
970  *
971  *\param        matchers List of conditions
972  */
973 static void prefs_matcher_set_dialog(MatcherList *matchers)
974 {
975         GSList *cur;
976         gboolean bool_op = 1;
977         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
978                                 (GTK_TREE_VIEW(matcher.cond_list_view)));
979
980         gtk_list_store_clear(store);                            
981
982         prefs_matcher_list_view_set_row(NULL, NULL);
983         if (matchers != NULL) {
984                 for (cur = matchers->matchers; cur != NULL;
985                      cur = g_slist_next(cur)) {
986                         MatcherProp *prop;
987                         prop = (MatcherProp *) cur->data;
988                         prefs_matcher_list_view_set_row(NULL, prop);
989                 }
990
991                 bool_op = matchers->bool_and;
992         }
993         
994         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.bool_op_combo), bool_op);
995
996         prefs_matcher_reset_condition();
997         
998         combobox_set_sensitive(GTK_COMBO_BOX(matcher.criteria_combo), MATCH_TAGS,
999                         (tags_get_size() > 0) ? TRUE : FALSE);
1000 }
1001
1002 /*!
1003  *\brief        Converts current conditions in list box in
1004  *              a matcher list used by the matcher.
1005  *
1006  *\return       MatcherList * List of conditions.
1007  */
1008 static MatcherList *prefs_matcher_get_list(void)
1009 {
1010         gchar *matcher_str;
1011         MatcherProp *prop;
1012         gboolean bool_and;
1013         GSList *matcher_list;
1014         MatcherList *matchers;
1015         GtkTreeModel *model;
1016         GtkTreeIter iter;
1017
1018         model = gtk_tree_view_get_model(GTK_TREE_VIEW(matcher.cond_list_view));
1019         if (!gtk_tree_model_get_iter_first(model, &iter))
1020                 return NULL;
1021
1022         matcher_list = NULL;
1023
1024         do {
1025                 gboolean is_valid;
1026         
1027                 gtk_tree_model_get(model, &iter,
1028                                    PREFS_MATCHER_COND, &matcher_str,
1029                                    PREFS_MATCHER_COND_VALID, &is_valid,
1030                                    -1);
1031                 
1032                 if (is_valid) {
1033                         /* tmp = matcher_str; */
1034                         prop = matcher_parser_get_prop(matcher_str);
1035                         g_free(matcher_str);
1036                         if (prop == NULL)
1037                                 break;
1038                         
1039                         matcher_list = g_slist_append(matcher_list, prop);
1040                 }
1041         } while (gtk_tree_model_iter_next(model, &iter));
1042
1043         bool_and = gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.bool_op_combo));
1044
1045         matchers = matcherlist_new(matcher_list, bool_and);
1046
1047         return matchers;
1048 }
1049
1050 /*!
1051  *\brief        Maps a keyword id (see #get_matchparser_tab_id) to a 
1052  *              criteria type (see first parameter of #matcherprop_new
1053  *              or #matcherprop_unquote_new)
1054  *
1055  *\param        matching_id Id returned by the matcher parser.
1056  *
1057  *\return       gint One of the CRITERIA_xxx constants.
1058  */
1059 static gint prefs_matcher_get_criteria_from_matching(gint matching_id)
1060 {
1061         switch(matching_id) {
1062         case MATCHCRITERIA_ALL:
1063                 return CRITERIA_ALL;
1064         case MATCHCRITERIA_NOT_UNREAD:
1065         case MATCHCRITERIA_UNREAD:
1066                 return CRITERIA_UNREAD;
1067         case MATCHCRITERIA_NOT_NEW:
1068         case MATCHCRITERIA_NEW:
1069                 return CRITERIA_NEW;
1070         case MATCHCRITERIA_NOT_MARKED:
1071         case MATCHCRITERIA_MARKED:
1072                 return CRITERIA_MARKED;
1073         case MATCHCRITERIA_NOT_DELETED:
1074         case MATCHCRITERIA_DELETED:
1075                 return CRITERIA_DELETED;
1076         case MATCHCRITERIA_NOT_REPLIED:
1077         case MATCHCRITERIA_REPLIED:
1078                 return CRITERIA_REPLIED;
1079         case MATCHCRITERIA_NOT_FORWARDED:
1080         case MATCHCRITERIA_FORWARDED:
1081                 return CRITERIA_FORWARDED;
1082         case MATCHCRITERIA_LOCKED:
1083         case MATCHCRITERIA_NOT_LOCKED:
1084                 return CRITERIA_LOCKED;
1085         case MATCHCRITERIA_NOT_SPAM:
1086         case MATCHCRITERIA_SPAM:
1087                 return CRITERIA_SPAM;
1088         case MATCHCRITERIA_HAS_ATTACHMENT:
1089         case MATCHCRITERIA_HAS_NO_ATTACHMENT:
1090                 return CRITERIA_HAS_ATTACHMENT;
1091         case MATCHCRITERIA_SIGNED:
1092         case MATCHCRITERIA_NOT_SIGNED:
1093                 return CRITERIA_SIGNED;
1094         case MATCHCRITERIA_PARTIAL:
1095         case MATCHCRITERIA_NOT_PARTIAL:
1096                 return CRITERIA_PARTIAL;
1097 #if !GTK_CHECK_VERSION(3, 0, 0)
1098         case MATCHCRITERIA_COLORLABEL:
1099         case MATCHCRITERIA_NOT_COLORLABEL:
1100                 return CRITERIA_COLORLABEL;
1101 #endif
1102         case MATCHCRITERIA_IGNORE_THREAD:
1103         case MATCHCRITERIA_NOT_IGNORE_THREAD:
1104                 return CRITERIA_IGNORE_THREAD;
1105         case MATCHCRITERIA_WATCH_THREAD:
1106         case MATCHCRITERIA_NOT_WATCH_THREAD:
1107                 return CRITERIA_WATCH_THREAD;
1108         case MATCHCRITERIA_NOT_SUBJECT:
1109         case MATCHCRITERIA_SUBJECT:
1110                 return CRITERIA_SUBJECT;
1111         case MATCHCRITERIA_NOT_FROM:
1112         case MATCHCRITERIA_FROM:
1113                 return CRITERIA_FROM;
1114         case MATCHCRITERIA_NOT_TO:
1115         case MATCHCRITERIA_TO:
1116                 return CRITERIA_TO;
1117         case MATCHCRITERIA_NOT_CC:
1118         case MATCHCRITERIA_CC:
1119                 return CRITERIA_CC;
1120         case MATCHCRITERIA_NOT_NEWSGROUPS:
1121         case MATCHCRITERIA_NEWSGROUPS:
1122                 return CRITERIA_NEWSGROUPS;
1123         case MATCHCRITERIA_NOT_INREPLYTO:
1124         case MATCHCRITERIA_INREPLYTO:
1125                 return CRITERIA_INREPLYTO;
1126         case MATCHCRITERIA_NOT_REFERENCES:
1127         case MATCHCRITERIA_REFERENCES:
1128                 return CRITERIA_REFERENCES;
1129         case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
1130         case MATCHCRITERIA_TO_OR_CC:
1131                 return CRITERIA_TO_OR_CC;
1132         case MATCHCRITERIA_NOT_TAG:
1133         case MATCHCRITERIA_TAG:
1134                 return CRITERIA_TAG;
1135         case MATCHCRITERIA_NOT_TAGGED:
1136         case MATCHCRITERIA_TAGGED:
1137                 return CRITERIA_TAGGED;
1138         case MATCHCRITERIA_NOT_BODY_PART:
1139         case MATCHCRITERIA_BODY_PART:
1140                 return CRITERIA_BODY_PART;
1141         case MATCHCRITERIA_NOT_MESSAGE:
1142         case MATCHCRITERIA_MESSAGE:
1143                 return CRITERIA_MESSAGE;
1144         case MATCHCRITERIA_NOT_HEADERS_PART:
1145         case MATCHCRITERIA_HEADERS_PART:
1146                 return CRITERIA_HEADERS_PART;
1147         case MATCHCRITERIA_NOT_HEADER:
1148         case MATCHCRITERIA_HEADER:
1149                 return CRITERIA_HEADER;
1150         case MATCHCRITERIA_AGE_GREATER_HOURS:
1151                 return CRITERIA_AGE_GREATER_HOURS;
1152         case MATCHCRITERIA_AGE_LOWER_HOURS:
1153                 return CRITERIA_AGE_LOWER_HOURS;
1154         case MATCHCRITERIA_AGE_GREATER:
1155                 return CRITERIA_AGE_GREATER;
1156         case MATCHCRITERIA_AGE_LOWER:
1157                 return CRITERIA_AGE_LOWER;
1158         case MATCHCRITERIA_SCORE_GREATER:
1159                 return CRITERIA_SCORE_GREATER;
1160         case MATCHCRITERIA_SCORE_LOWER:
1161                 return CRITERIA_SCORE_LOWER;
1162         case MATCHCRITERIA_SCORE_EQUAL:
1163                 return CRITERIA_SCORE_EQUAL;
1164         case MATCHCRITERIA_NOT_TEST:
1165         case MATCHCRITERIA_TEST:
1166                 return CRITERIA_TEST;
1167         case MATCHCRITERIA_SIZE_GREATER:
1168                 return CRITERIA_SIZE_GREATER;
1169         case MATCHCRITERIA_SIZE_SMALLER:
1170                 return CRITERIA_SIZE_SMALLER;
1171         case MATCHCRITERIA_SIZE_EQUAL:
1172                 return CRITERIA_SIZE_EQUAL;
1173         case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
1174         case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
1175                 return CRITERIA_FOUND_IN_ADDRESSBOOK;
1176         default:
1177                 return -1;
1178         }
1179 }
1180
1181 /*!
1182  *\brief        Returns the matcher keyword id from a criteria id
1183  *
1184  *\param        criteria_id Criteria id (should not be the negate
1185  *              one)
1186  *
1187  *\return       gint A matcher keyword id. See #get_matchparser_tab_id.
1188  */
1189 static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
1190 {
1191         switch (criteria_id) {
1192         case CRITERIA_ALL:
1193                 return MATCHCRITERIA_ALL;
1194         case CRITERIA_UNREAD:
1195                 return MATCHCRITERIA_UNREAD;
1196         case CRITERIA_NEW:
1197                 return MATCHCRITERIA_NEW;
1198         case CRITERIA_MARKED:
1199                 return MATCHCRITERIA_MARKED;
1200         case CRITERIA_DELETED:
1201                 return MATCHCRITERIA_DELETED;
1202         case CRITERIA_REPLIED:
1203                 return MATCHCRITERIA_REPLIED;
1204         case CRITERIA_FORWARDED:
1205                 return MATCHCRITERIA_FORWARDED;
1206         case CRITERIA_LOCKED:
1207                 return MATCHCRITERIA_LOCKED;
1208         case CRITERIA_SPAM:
1209                 return MATCHCRITERIA_SPAM;
1210         case CRITERIA_HAS_ATTACHMENT:
1211                 return MATCHCRITERIA_HAS_ATTACHMENT;
1212         case CRITERIA_SIGNED:
1213                 return MATCHCRITERIA_SIGNED;
1214         case CRITERIA_PARTIAL:
1215                 return MATCHCRITERIA_PARTIAL;
1216 #if !GTK_CHECK_VERSION(3, 0, 0)
1217         case CRITERIA_COLORLABEL:
1218                 return MATCHCRITERIA_COLORLABEL;
1219 #endif
1220         case CRITERIA_IGNORE_THREAD:
1221                 return MATCHCRITERIA_IGNORE_THREAD;
1222         case CRITERIA_WATCH_THREAD:
1223                 return MATCHCRITERIA_WATCH_THREAD;
1224         case CRITERIA_SUBJECT:
1225                 return MATCHCRITERIA_SUBJECT;
1226         case CRITERIA_FROM:
1227                 return MATCHCRITERIA_FROM;
1228         case CRITERIA_TO:
1229                 return MATCHCRITERIA_TO;
1230         case CRITERIA_CC:
1231                 return MATCHCRITERIA_CC;
1232         case CRITERIA_TO_OR_CC:
1233                 return MATCHCRITERIA_TO_OR_CC;
1234         case CRITERIA_TAG:
1235                 return MATCHCRITERIA_TAG;
1236         case CRITERIA_TAGGED:
1237                 return MATCHCRITERIA_TAGGED;
1238         case CRITERIA_NEWSGROUPS:
1239                 return MATCHCRITERIA_NEWSGROUPS;
1240         case CRITERIA_INREPLYTO:
1241                 return MATCHCRITERIA_INREPLYTO;
1242         case CRITERIA_REFERENCES:
1243                 return MATCHCRITERIA_REFERENCES;
1244         case CRITERIA_AGE_GREATER:
1245                 return MATCHCRITERIA_AGE_GREATER;
1246         case CRITERIA_AGE_LOWER:
1247                 return MATCHCRITERIA_AGE_LOWER;
1248         case CRITERIA_AGE_GREATER_HOURS:
1249                 return MATCHCRITERIA_AGE_GREATER_HOURS;
1250         case CRITERIA_AGE_LOWER_HOURS:
1251                 return MATCHCRITERIA_AGE_LOWER_HOURS;
1252         case CRITERIA_SCORE_GREATER:
1253                 return MATCHCRITERIA_SCORE_GREATER;
1254         case CRITERIA_SCORE_LOWER:
1255                 return MATCHCRITERIA_SCORE_LOWER;
1256         case CRITERIA_SCORE_EQUAL:
1257                 return MATCHCRITERIA_SCORE_EQUAL;
1258         case CRITERIA_HEADER:
1259                 return MATCHCRITERIA_HEADER;
1260         case CRITERIA_HEADERS_PART:
1261                 return MATCHCRITERIA_HEADERS_PART;
1262         case CRITERIA_BODY_PART:
1263                 return MATCHCRITERIA_BODY_PART;
1264         case CRITERIA_MESSAGE:
1265                 return MATCHCRITERIA_MESSAGE;
1266         case CRITERIA_TEST:
1267                 return MATCHCRITERIA_TEST;
1268         case CRITERIA_SIZE_GREATER:
1269                 return MATCHCRITERIA_SIZE_GREATER;
1270         case CRITERIA_SIZE_SMALLER:
1271                 return MATCHCRITERIA_SIZE_SMALLER;
1272         case CRITERIA_SIZE_EQUAL:
1273                 return MATCHCRITERIA_SIZE_EQUAL;
1274         case CRITERIA_FOUND_IN_ADDRESSBOOK:
1275                 return MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1276         default:
1277                 return -1;
1278         }
1279 }
1280
1281 /*!
1282  *\brief        Returns the negate matcher keyword id from a matcher keyword
1283  *              id.
1284  *
1285  *\param        matcher_criteria Matcher keyword id. 
1286  *
1287  *\return       gint A matcher keyword id. See #get_matchparser_tab_id.
1288  */
1289 static gint prefs_matcher_not_criteria(gint matcher_criteria)
1290 {
1291         switch(matcher_criteria) {
1292         case MATCHCRITERIA_UNREAD:
1293                 return MATCHCRITERIA_NOT_UNREAD;
1294         case MATCHCRITERIA_NEW:
1295                 return MATCHCRITERIA_NOT_NEW;
1296         case MATCHCRITERIA_MARKED:
1297                 return MATCHCRITERIA_NOT_MARKED;
1298         case MATCHCRITERIA_DELETED:
1299                 return MATCHCRITERIA_NOT_DELETED;
1300         case MATCHCRITERIA_REPLIED:
1301                 return MATCHCRITERIA_NOT_REPLIED;
1302         case MATCHCRITERIA_FORWARDED:
1303                 return MATCHCRITERIA_NOT_FORWARDED;
1304         case MATCHCRITERIA_LOCKED:
1305                 return MATCHCRITERIA_NOT_LOCKED;
1306         case MATCHCRITERIA_SPAM:
1307                 return MATCHCRITERIA_NOT_SPAM;
1308         case MATCHCRITERIA_HAS_ATTACHMENT:
1309                 return MATCHCRITERIA_HAS_NO_ATTACHMENT;
1310         case MATCHCRITERIA_SIGNED:
1311                 return MATCHCRITERIA_NOT_SIGNED;
1312         case MATCHCRITERIA_PARTIAL:
1313                 return MATCHCRITERIA_NOT_PARTIAL;
1314 #if !GTK_CHECK_VERSION(3, 0, 0)
1315         case MATCHCRITERIA_COLORLABEL:
1316                 return MATCHCRITERIA_NOT_COLORLABEL;
1317 #endif
1318         case MATCHCRITERIA_IGNORE_THREAD:
1319                 return MATCHCRITERIA_NOT_IGNORE_THREAD;
1320         case MATCHCRITERIA_WATCH_THREAD:
1321                 return MATCHCRITERIA_NOT_WATCH_THREAD;
1322         case MATCHCRITERIA_SUBJECT:
1323                 return MATCHCRITERIA_NOT_SUBJECT;
1324         case MATCHCRITERIA_FROM:
1325                 return MATCHCRITERIA_NOT_FROM;
1326         case MATCHCRITERIA_TO:
1327                 return MATCHCRITERIA_NOT_TO;
1328         case MATCHCRITERIA_CC:
1329                 return MATCHCRITERIA_NOT_CC;
1330         case MATCHCRITERIA_TO_OR_CC:
1331                 return MATCHCRITERIA_NOT_TO_AND_NOT_CC;
1332         case MATCHCRITERIA_TAG:
1333                 return MATCHCRITERIA_NOT_TAG;
1334         case MATCHCRITERIA_TAGGED:
1335                 return MATCHCRITERIA_NOT_TAGGED;
1336         case MATCHCRITERIA_NEWSGROUPS:
1337                 return MATCHCRITERIA_NOT_NEWSGROUPS;
1338         case MATCHCRITERIA_INREPLYTO:
1339                 return MATCHCRITERIA_NOT_INREPLYTO;
1340         case MATCHCRITERIA_REFERENCES:
1341                 return MATCHCRITERIA_NOT_REFERENCES;
1342         case MATCHCRITERIA_HEADER:
1343                 return MATCHCRITERIA_NOT_HEADER;
1344         case MATCHCRITERIA_HEADERS_PART:
1345                 return MATCHCRITERIA_NOT_HEADERS_PART;
1346         case MATCHCRITERIA_MESSAGE:
1347                 return MATCHCRITERIA_NOT_MESSAGE;
1348         case MATCHCRITERIA_TEST:
1349                 return MATCHCRITERIA_NOT_TEST;
1350         case MATCHCRITERIA_BODY_PART:
1351                 return MATCHCRITERIA_NOT_BODY_PART;
1352         case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
1353                 return MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1354         default:
1355                 return matcher_criteria;
1356         }
1357 }
1358
1359 static gint prefs_matcher_get_criteria(void)
1360 {
1361         gint match_criteria = gtk_combo_box_get_active(GTK_COMBO_BOX(
1362                                         matcher.criteria_combo));
1363         const gchar *header = NULL;
1364           
1365         switch (match_criteria) {
1366         case MATCH_ABOOK:
1367                 return CRITERIA_FOUND_IN_ADDRESSBOOK;   
1368         case MATCH_ALL:
1369                 return CRITERIA_ALL;
1370         case MATCH_AGE:
1371         case MATCH_SCORE:
1372         case MATCH_SIZE:
1373         case MATCH_FLAG:
1374                 return combobox_get_active_data(GTK_COMBO_BOX(
1375                                         matcher.match_combo));
1376         case MATCH_HEADER:
1377                 header = gtk_entry_get_text(GTK_ENTRY(matcher.header_entry));
1378                 return header_name_to_crit(header);
1379 #if !GTK_CHECK_VERSION(3, 0, 0)
1380         case MATCH_LABEL:
1381                 return CRITERIA_COLORLABEL;
1382 #endif
1383         case MATCH_PARTIAL:
1384                 return CRITERIA_PARTIAL;
1385         case MATCH_TEST:
1386                 return CRITERIA_TEST;
1387         case MATCH_PHRASE:
1388         case MATCH_TAGS:
1389         case MATCH_THREAD:
1390                 return combobox_get_active_data(GTK_COMBO_BOX(
1391                                         matcher.criteria_combo2));
1392         }
1393         
1394         return -1;
1395 }
1396
1397 static gint prefs_matcher_get_pred(const gint criteria)
1398 {
1399         switch(criteria) {
1400         case CRITERIA_SUBJECT:
1401         case CRITERIA_FROM:
1402         case CRITERIA_TO:
1403         case CRITERIA_CC:
1404         case CRITERIA_TO_OR_CC:
1405         case CRITERIA_NEWSGROUPS:
1406         case CRITERIA_INREPLYTO:
1407         case CRITERIA_REFERENCES:
1408         case CRITERIA_HEADER:
1409         case CRITERIA_HEADERS_PART:
1410         case CRITERIA_BODY_PART:
1411         case CRITERIA_MESSAGE:
1412         case CRITERIA_TAG:
1413         case CRITERIA_TAGGED:
1414         case CRITERIA_TEST:
1415                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo));
1416         case CRITERIA_FOUND_IN_ADDRESSBOOK:
1417         case CRITERIA_UNREAD:
1418         case CRITERIA_NEW:
1419         case CRITERIA_MARKED:
1420         case CRITERIA_DELETED:
1421         case CRITERIA_REPLIED:
1422         case CRITERIA_FORWARDED:
1423         case CRITERIA_LOCKED:
1424         case CRITERIA_SPAM:
1425         case CRITERIA_HAS_ATTACHMENT:
1426         case CRITERIA_SIGNED:
1427         case CRITERIA_COLORLABEL:
1428                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo2));
1429         case CRITERIA_WATCH_THREAD:
1430                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.criteria_combo2)) - 2;
1431         case CRITERIA_IGNORE_THREAD:
1432         case CRITERIA_PARTIAL:
1433                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.criteria_combo2));
1434         }
1435         
1436         return 0;
1437 }
1438
1439 /*!
1440  *\brief        Converts the text in the selected row to a 
1441  *              matcher structure
1442  *
1443  *\return       MatcherProp * Newly allocated matcher structure.
1444  */
1445 static MatcherProp *prefs_matcher_dialog_to_matcher(void)
1446 {
1447         MatcherProp *matcherprop;
1448         gint criteria;
1449         gint matchtype;
1450         gint value_pred;
1451         gint value_criteria = prefs_matcher_get_criteria();
1452         gboolean use_regexp;
1453         gboolean case_sensitive;
1454         const gchar *header;
1455         const gchar *expr;
1456         gint value, sel;
1457
1458         if (value_criteria == -1)
1459                 return NULL;
1460
1461 #ifndef G_OS_WIN32
1462         use_regexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn));
1463 #else
1464         use_regexp = FALSE;
1465 #endif
1466         case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn));
1467
1468         if (use_regexp) {
1469                 if (case_sensitive)
1470                         matchtype = MATCHTYPE_REGEXP;
1471                 else
1472                         matchtype = MATCHTYPE_REGEXPCASE;
1473         }
1474         else {
1475                 if (case_sensitive)
1476                         matchtype = MATCHTYPE_MATCH;
1477                 else
1478                         matchtype = MATCHTYPE_MATCHCASE;
1479         }
1480
1481         header = NULL;
1482         expr = NULL;
1483         value = 0;
1484
1485         switch (value_criteria) {
1486         case CRITERIA_ALL:
1487         case CRITERIA_UNREAD:
1488         case CRITERIA_NEW:
1489         case CRITERIA_MARKED:
1490         case CRITERIA_DELETED:
1491         case CRITERIA_REPLIED:
1492         case CRITERIA_FORWARDED:
1493         case CRITERIA_LOCKED:
1494         case CRITERIA_SPAM:
1495         case CRITERIA_HAS_ATTACHMENT:
1496         case CRITERIA_SIGNED:
1497         case CRITERIA_PARTIAL:
1498         case CRITERIA_IGNORE_THREAD:
1499         case CRITERIA_WATCH_THREAD:
1500         case CRITERIA_TAGGED:
1501                 break;
1502
1503         case CRITERIA_SUBJECT:
1504         case CRITERIA_FROM:
1505         case CRITERIA_TO:
1506         case CRITERIA_CC:
1507         case CRITERIA_TO_OR_CC:
1508         case CRITERIA_TAG:
1509         case CRITERIA_NEWSGROUPS:
1510         case CRITERIA_INREPLYTO:
1511         case CRITERIA_REFERENCES:
1512         case CRITERIA_HEADERS_PART:
1513         case CRITERIA_BODY_PART:
1514         case CRITERIA_MESSAGE:
1515                 expr = gtk_entry_get_text(GTK_ENTRY(matcher.string_entry));
1516                 
1517                 if(*expr == '\0') {
1518                         alertpanel_error(_("Search pattern is not set."));
1519                         return NULL;
1520                 }
1521                 break;
1522
1523         case CRITERIA_TEST:
1524                 expr = gtk_entry_get_text(GTK_ENTRY(matcher.string_entry));
1525                 
1526                 if(*expr == '\0') {
1527                         alertpanel_error(_("Test command is not set."));
1528                         return NULL;
1529                 }
1530                 break;
1531
1532         case CRITERIA_AGE_GREATER:
1533         case CRITERIA_AGE_LOWER:
1534                 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
1535                                                          matcher.numeric_entry));
1536                 sel = gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo2));
1537                 if(sel == AGE_WEEKS)
1538                         value *= 7;
1539                 else if (sel == AGE_HOURS) {
1540                         if (value_criteria == CRITERIA_AGE_GREATER)
1541                                 value_criteria = CRITERIA_AGE_GREATER_HOURS;
1542                         else 
1543                                 value_criteria = CRITERIA_AGE_LOWER_HOURS;
1544                 }
1545                 break;
1546                         
1547         case CRITERIA_SCORE_GREATER:
1548         case CRITERIA_SCORE_LOWER:
1549         case CRITERIA_SCORE_EQUAL:
1550                 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
1551                                                          matcher.numeric_entry));
1552                 break;
1553                                                          
1554         case CRITERIA_SIZE_GREATER:
1555         case CRITERIA_SIZE_SMALLER:
1556         case CRITERIA_SIZE_EQUAL:
1557                 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
1558                                                          matcher.numeric_entry));
1559                 sel = gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo2));
1560                 if(sel == SIZE_UNIT_MBYTES)
1561                         value *= MB_SIZE;
1562                 if(sel == SIZE_UNIT_KBYTES)
1563                         value *= KB_SIZE;
1564                 break;
1565                 
1566 #if !GTK_CHECK_VERSION(3, 0, 0)
1567         case CRITERIA_COLORLABEL:
1568                 value = colorlabel_get_color_menu_active_item
1569                         (gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU
1570                                 (matcher.color_optmenu))); 
1571                 break;
1572 #endif
1573
1574         case CRITERIA_HEADER:
1575                 header = gtk_entry_get_text(GTK_ENTRY(matcher.header_entry));
1576                 expr = gtk_entry_get_text(GTK_ENTRY(matcher.string_entry));
1577
1578                 if (*header == '\0') {
1579                     alertpanel_error(_("Header name is not set."));
1580                     return NULL;
1581                 }
1582                 
1583                 if(*expr == '\0') {
1584                         alertpanel_error(_("Search pattern is not set."));
1585                         return NULL;
1586                 } 
1587                 break;
1588
1589         case CRITERIA_FOUND_IN_ADDRESSBOOK:
1590                 header = gtk_entry_get_text(GTK_ENTRY(matcher.header_addr_entry));
1591                 expr = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))));
1592
1593                 if (*header == '\0') {
1594                     alertpanel_error(_("Header name is not set."));
1595                     return NULL;
1596                 }
1597                 if (*expr == '\0') {
1598                         gchar *tmp;
1599
1600                         if (g_utf8_collate(header, C_("Filtering Matcher Menu", "All")) == 0)
1601                                 tmp = g_strdup(_("all addresses in all headers"));
1602                         else
1603                         if (g_utf8_collate(header, _("Any")) == 0)
1604                                 tmp = g_strdup(_("any address in any header"));
1605                         else
1606                                 tmp = g_strdup_printf(_("the address(es) in header '%s'"), header);
1607                         alertpanel_error(_("Book/folder path is not set.\n\n"
1608                                                 "If you want to match %s against the whole address book, "
1609                                                 "you have to select '%s' from the book/folder drop-down list."),
1610                                                 tmp, _("Any"));
1611                         g_free(tmp);
1612                     return NULL;
1613                 }
1614                 /* store UNtranslated "Any"/"All" in matcher expressions */
1615                 if (g_utf8_collate(header, C_("Filtering Matcher Menu", "All")) == 0)
1616                         header = "All";
1617                 else
1618                         if (g_utf8_collate(header, _("Any")) == 0)
1619                                 header = "Any";
1620                 if (g_utf8_collate(expr, _("Any")) == 0)
1621                         expr = "Any";
1622                 break;
1623         }
1624
1625         criteria = prefs_matcher_get_matching_from_criteria(value_criteria);
1626
1627         value_pred = prefs_matcher_get_pred(value_criteria);
1628         if(value_pred)
1629                 criteria = prefs_matcher_not_criteria(criteria);
1630
1631         matcherprop = matcherprop_new(criteria, header, matchtype,
1632                                       expr, value);
1633
1634         return matcherprop;
1635 }
1636
1637 /*!
1638  *\brief        Signal handler for register button
1639  */
1640 static void prefs_matcher_register_cb(void)
1641 {
1642         MatcherProp *matcherprop;
1643         
1644         matcherprop = prefs_matcher_dialog_to_matcher();
1645         if (matcherprop == NULL)
1646                 return;
1647
1648         prefs_matcher_list_view_set_row(NULL, matcherprop);
1649
1650         matcherprop_free(matcherprop);
1651         
1652         prefs_matcher_reset_condition();
1653 }
1654
1655 /*!
1656  *\brief        Signal handler for substitute button
1657  */
1658 static void prefs_matcher_substitute_cb(void)
1659 {
1660         MatcherProp *matcherprop;
1661         GtkTreeIter row;
1662         GtkTreeSelection *selection;
1663         GtkTreeModel *model;
1664         gboolean is_valid;
1665
1666         selection = gtk_tree_view_get_selection
1667                         (GTK_TREE_VIEW(matcher.cond_list_view));
1668         
1669         if (!gtk_tree_selection_get_selected(selection, &model, &row))
1670                 return;
1671         
1672         gtk_tree_model_get(model, &row, 
1673                            PREFS_MATCHER_COND_VALID, &is_valid,
1674                            -1);
1675         if (!is_valid)
1676                 return;
1677
1678         matcherprop = prefs_matcher_dialog_to_matcher();
1679         if (matcherprop == NULL)
1680                 return;
1681
1682         prefs_matcher_list_view_set_row(&row, matcherprop);
1683
1684         matcherprop_free(matcherprop);
1685 }
1686
1687 /*!
1688  *\brief        Signal handler for delete button
1689  */
1690 static void prefs_matcher_delete_cb(void)
1691 {
1692         GtkTreeIter row;
1693         GtkTreeSelection *selection;
1694         GtkTreeModel *model;
1695         gboolean is_valid;
1696
1697         selection = gtk_tree_view_get_selection
1698                         (GTK_TREE_VIEW(matcher.cond_list_view));
1699         
1700         if (!gtk_tree_selection_get_selected(selection, &model, &row))
1701                 return;
1702                 
1703         gtk_tree_model_get(model, &row, 
1704                            PREFS_MATCHER_COND_VALID, &is_valid,
1705                            -1);
1706
1707         if (!is_valid)
1708                 return;
1709
1710         gtk_list_store_remove(GTK_LIST_STORE(model), &row);             
1711
1712         prefs_matcher_reset_condition();
1713 }
1714
1715 /*!
1716  *\brief        Signal handler for 'move up' button
1717  */
1718 static void prefs_matcher_up(void)
1719 {
1720         GtkTreePath *prev, *sel, *try;
1721         GtkTreeIter isel;
1722         GtkListStore *store = NULL;
1723         GtkTreeModel *model = NULL;
1724         GtkTreeIter iprev;
1725         
1726         if (!gtk_tree_selection_get_selected
1727                 (gtk_tree_view_get_selection
1728                         (GTK_TREE_VIEW(matcher.cond_list_view)),
1729                  &model,        
1730                  &isel))
1731                 return;
1732         store = (GtkListStore *)model;
1733         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1734         if (!sel)
1735                 return;
1736         
1737         /* no move if we're at row 0 or 1, looks phony, but other
1738          * solutions are more convoluted... */
1739         try = gtk_tree_path_copy(sel);
1740         if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1741                 gtk_tree_path_free(try);
1742                 gtk_tree_path_free(sel);
1743                 return;
1744         }
1745         gtk_tree_path_free(try);
1746
1747         prev = gtk_tree_path_copy(sel);         
1748         if (gtk_tree_path_prev(prev)) {
1749                 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1750                                         &iprev, prev);
1751                 gtk_list_store_swap(store, &iprev, &isel);
1752                 /* XXX: GTK2 select row?? */
1753         }
1754
1755         gtk_tree_path_free(sel);
1756         gtk_tree_path_free(prev);
1757 }
1758
1759 /*!
1760  *\brief        Signal handler for 'move down' button
1761  */
1762 static void prefs_matcher_down(void)
1763 {
1764         GtkListStore *store = NULL;
1765         GtkTreeModel *model = NULL;
1766         GtkTreeIter next, sel;
1767         GtkTreePath *try;
1768         
1769         if (!gtk_tree_selection_get_selected
1770                 (gtk_tree_view_get_selection
1771                         (GTK_TREE_VIEW(matcher.cond_list_view)),
1772                  &model,
1773                  &sel))
1774                 return;
1775         store = (GtkListStore *)model;
1776         try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1777         if (!try) 
1778                 return;
1779         
1780         /* move when not at row 0 ... */
1781         if (gtk_tree_path_prev(try)) {
1782                 next = sel;
1783                 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1784                         gtk_list_store_swap(store, &next, &sel);
1785         }
1786                 
1787         gtk_tree_path_free(try);
1788 }
1789
1790 static void prefs_matcher_enable_widget(GtkWidget* widget, const gboolean enable)
1791 {
1792         cm_return_if_fail(widget != NULL);
1793
1794         if(enable == TRUE) {
1795                 gtk_widget_set_sensitive(widget, TRUE);
1796                 gtk_widget_show(widget);        
1797         } else {
1798                 gtk_widget_set_sensitive(widget, FALSE);
1799                 gtk_widget_hide(widget);
1800         }
1801 }
1802
1803 static void prefs_matcher_set_model(GtkWidget *widget, GtkTreeModel *model)
1804 {
1805         cm_return_if_fail(widget != NULL);
1806         cm_return_if_fail(model != NULL);
1807         
1808         gtk_combo_box_set_model(GTK_COMBO_BOX(widget), model);
1809         gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1810 }
1811
1812 static void prefs_matcher_second_criteria_sel(GtkWidget *widget,
1813                                               gpointer user_data)
1814 {
1815         gint criteria = gtk_combo_box_get_active(GTK_COMBO_BOX(
1816                                                 matcher.criteria_combo));
1817         gint criteria2 = combobox_get_active_data(GTK_COMBO_BOX(
1818                                                 matcher.criteria_combo2));
1819         
1820         if(criteria != MATCH_PHRASE && criteria != MATCH_TAGS) return;
1821         
1822         if(criteria == MATCH_PHRASE) {
1823                 switch(criteria2) {
1824                 case CRITERIA_HEADERS_PART:
1825                         gtk_label_set_text(GTK_LABEL(matcher.match_label),
1826                                         _("Headers part"));
1827                         break;
1828                 case CRITERIA_BODY_PART:
1829                         gtk_label_set_text(GTK_LABEL(matcher.match_label),
1830                                         _("Body part"));
1831                         break;  
1832                 case CRITERIA_MESSAGE:
1833                         gtk_label_set_text(GTK_LABEL(matcher.match_label),
1834                                         _("Whole message"));
1835                         break;
1836                 }
1837         }
1838         
1839         if(criteria == MATCH_TAGS) {
1840                 if(criteria2 == CRITERIA_TAGGED) {
1841                         prefs_matcher_enable_widget(matcher.upper_filler, FALSE);
1842                         prefs_matcher_enable_widget(matcher.match_label2, TRUE);
1843                         prefs_matcher_enable_widget(matcher.string_entry, FALSE);
1844                         prefs_matcher_enable_widget(matcher.case_checkbtn, FALSE);
1845 #ifndef G_OS_WIN32
1846                         prefs_matcher_enable_widget(matcher.regexp_checkbtn, FALSE);
1847 #endif
1848                 } else {
1849                         prefs_matcher_enable_widget(matcher.upper_filler, TRUE);
1850                         prefs_matcher_enable_widget(matcher.match_label2, FALSE);
1851                         prefs_matcher_enable_widget(matcher.string_entry, TRUE);
1852                         prefs_matcher_enable_widget(matcher.case_checkbtn, TRUE);
1853 #ifndef G_OS_WIN32
1854                         prefs_matcher_enable_widget(matcher.regexp_checkbtn, TRUE);
1855                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
1856                                                 matcher.regexp_checkbtn), FALSE);
1857 #endif
1858                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
1859                                                 matcher.case_checkbtn), FALSE);
1860                 }
1861         }
1862 }
1863
1864 #define MATCH_COMBO_IS_ENABLED(x) (x != MATCH_ALL && x != MATCH_ABOOK && \
1865                 x != MATCH_PARTIAL && x != MATCH_THREAD && x != MATCH_LABEL) ? TRUE : FALSE
1866 #define MATCH_CASE_REGEXP(x) (x == MATCH_HEADER || x == MATCH_PHRASE) ? TRUE : FALSE 
1867 #define MATCH_NUMERIC(x) (x == MATCH_AGE || x == MATCH_SCORE || \
1868                           x == MATCH_SIZE) ? TRUE : FALSE
1869
1870 /*!
1871  *\brief        Change widgets depending on the selected condition
1872  *
1873  *\param        criteria combo widget
1874  *\param        user_data Not used      
1875  */
1876 static void prefs_matcher_criteria_select(GtkWidget *widget,
1877                                           gpointer user_data)
1878 {
1879         gint value, old_value;
1880
1881         old_value = matcher.selected_criteria;
1882         matcher.selected_criteria = value = gtk_combo_box_get_active
1883                 (GTK_COMBO_BOX(matcher.criteria_combo));
1884
1885         if (old_value == matcher.selected_criteria)
1886                 return;
1887
1888         prefs_matcher_enable_widget(matcher.criteria_label2,
1889                                     (value == MATCH_ABOOK   ||
1890                                      value == MATCH_PHRASE  ||
1891                                      value == MATCH_HEADER  ||
1892                                      value == MATCH_PARTIAL ||
1893                                      value == MATCH_TAGS    ||
1894                                      value == MATCH_THREAD));
1895         prefs_matcher_enable_widget(matcher.headers_combo,
1896                                     (value == MATCH_HEADER));
1897         prefs_matcher_enable_widget(matcher.criteria_combo2,
1898                                     (value == MATCH_PHRASE  ||
1899                                      value == MATCH_PARTIAL ||
1900                                      value == MATCH_TAGS    ||
1901                                      value == MATCH_THREAD));
1902         prefs_matcher_enable_widget(matcher.match_combo2,
1903                                     (value == MATCH_ABOOK ||
1904                                      value == MATCH_AGE   ||
1905                                      value == MATCH_FLAG  ||
1906                                      value == MATCH_LABEL ||
1907                                      value == MATCH_SIZE));
1908         prefs_matcher_enable_widget(matcher.match_label2,
1909                                     (value == MATCH_ABOOK ||
1910                                      value == MATCH_FLAG  ||
1911                                      value == MATCH_LABEL ||
1912                                      value == MATCH_TAGS));
1913         prefs_matcher_enable_widget(matcher.header_addr_combo,
1914                                     (value == MATCH_ABOOK));
1915         prefs_matcher_enable_widget(matcher.string_entry,
1916                                     (MATCH_CASE_REGEXP(value) ||
1917                                      value == MATCH_TEST));
1918         prefs_matcher_enable_widget(matcher.numeric_entry,
1919                                     MATCH_NUMERIC(value));
1920         prefs_matcher_enable_widget(matcher.numeric_label,
1921                                     (value == MATCH_SCORE));
1922         prefs_matcher_enable_widget(matcher.addressbook_folder_combo,
1923                                     (value == MATCH_ABOOK));
1924         prefs_matcher_enable_widget(matcher.match_combo,
1925                                     MATCH_COMBO_IS_ENABLED(value));
1926         prefs_matcher_enable_widget(matcher.case_checkbtn,
1927                                     MATCH_CASE_REGEXP(value));
1928 #ifndef G_OS_WIN32
1929         prefs_matcher_enable_widget(matcher.regexp_checkbtn,
1930                                     MATCH_CASE_REGEXP(value));
1931 #endif
1932         prefs_matcher_enable_widget(matcher.test_btn,
1933                                     (value == MATCH_TEST));
1934         prefs_matcher_enable_widget(matcher.addressbook_select_btn,
1935                                     (value == MATCH_ABOOK));
1936 #if !GTK_CHECK_VERSION(3, 0, 0)
1937         prefs_matcher_enable_widget(matcher.color_optmenu,
1938                                     (value == MATCH_LABEL));
1939 #endif
1940         prefs_matcher_enable_widget(matcher.upper_filler,
1941                                     MATCH_CASE_REGEXP(value));
1942         prefs_matcher_enable_widget(matcher.lower_filler,
1943                                     (value == MATCH_ABOOK));
1944                                 
1945         gtk_label_set_text(GTK_LABEL(matcher.match_label), "");
1946         gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), "");
1947
1948         switch(value) {
1949         case MATCH_ABOOK:
1950                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.header_addr_combo), 0);  
1951                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.addressbook_folder_combo), 0);
1952                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_found);
1953                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("in"));
1954                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Header"));
1955                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("content is"));
1956                 break;
1957         case MATCH_AGE:
1958                 prefs_matcher_set_model(matcher.match_combo, matcher.model_age);
1959                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_age_units);
1960                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(
1961                                   matcher.numeric_entry), 0, 1000);
1962                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
1963                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2), AGE_DAYS);
1964                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Age is"));
1965                 break;
1966         case MATCH_FLAG:
1967                 prefs_matcher_set_model(matcher.match_combo, matcher.model_flags);
1968                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_set);
1969                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Flag"));
1970                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("is"));
1971                 break;
1972         case MATCH_HEADER:
1973                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.headers_combo), 0);
1974                 prefs_matcher_set_model(matcher.match_combo, matcher.model_contain);
1975                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("Name:"));
1976                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Header"));
1977 #ifndef G_OS_WIN32
1978                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
1979 #endif
1980                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
1981                 break;
1982 #if !GTK_CHECK_VERSION(3, 0, 0)
1983         case MATCH_LABEL:
1984                 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(matcher.color_optmenu), 0);
1985                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_set);
1986                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Label"));
1987                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("is"));
1988                 break;
1989 #endif
1990         case MATCH_PARTIAL:
1991                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_partial);
1992                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("Value:"));
1993                 break;
1994         case MATCH_PHRASE:
1995                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_phrase);
1996                 prefs_matcher_set_model(matcher.match_combo, matcher.model_contain);
1997                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("in"));
1998 #ifndef G_OS_WIN32
1999                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
2000 #endif
2001                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
2002                 prefs_matcher_second_criteria_sel(NULL, NULL);
2003                 break;  
2004         case MATCH_SCORE:
2005                 prefs_matcher_set_model(matcher.match_combo, matcher.model_score);
2006                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(
2007                                           matcher.numeric_entry), -1000, 1000);
2008                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
2009                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Score is"));
2010                 gtk_label_set_text(GTK_LABEL(matcher.numeric_label), _("points"));
2011                 break;  
2012         case MATCH_SIZE:
2013                 prefs_matcher_set_model(matcher.match_combo, matcher.model_size);
2014                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_size_units);
2015                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2016                                          SIZE_UNIT_KBYTES);
2017                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(
2018                                           matcher.numeric_entry), 0, 100000);
2019                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
2020                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Size is"));
2021                 break;
2022         case MATCH_TAGS:
2023                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_tags);
2024                 prefs_matcher_set_model(matcher.match_combo, matcher.model_contain);
2025                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("Scope:"));
2026                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Message"));
2027                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("tags"));
2028                 prefs_matcher_second_criteria_sel(NULL, NULL);
2029                 break;
2030         case MATCH_THREAD:
2031                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_thread);
2032                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("type is"));
2033                 break;
2034         case MATCH_TEST:
2035                 prefs_matcher_set_model(matcher.match_combo, matcher.model_test);
2036                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Program returns"));
2037                 break;
2038         }       
2039 }
2040
2041 /*!
2042  *\brief        Handle key press
2043  *
2044  *\param        widget Widget receiving key press
2045  *\param        event Key event
2046  *\param        data User data
2047  */
2048 static gboolean prefs_matcher_key_pressed(GtkWidget *widget, GdkEventKey *event,
2049                                      gpointer data)
2050 {
2051         if (event && event->keyval == GDK_KEY_Escape) {
2052                 prefs_matcher_cancel();
2053                 return TRUE;            
2054         }
2055         return FALSE;
2056 }
2057
2058 /*!
2059  *\brief        Cancel matcher dialog
2060  */
2061 static void prefs_matcher_cancel(void)
2062 {
2063         gtk_widget_hide(matcher.window);
2064         gtk_window_set_modal(GTK_WINDOW(matcher.window), FALSE);
2065         inc_unlock();
2066 }
2067
2068 /*!
2069  *\brief        Accept current matchers
2070  */
2071 static void prefs_matcher_ok(void)
2072 {
2073         MatcherList *matchers;
2074         MatcherProp *matcherprop;
2075         AlertValue val;
2076         gchar *matcher_str = NULL;
2077         gchar *str = NULL;
2078         gint row = 1;
2079         GtkTreeModel *model;
2080         GtkTreeIter iter;
2081
2082         matchers = prefs_matcher_get_list();
2083
2084         if (matchers != NULL) {
2085                 matcherprop = prefs_matcher_dialog_to_matcher();
2086                 if (matcherprop != NULL) {
2087                         str = matcherprop_to_string(matcherprop);
2088                         matcherprop_free(matcherprop);
2089                         if (strcmp(str, "all") != 0) {
2090                                 model = gtk_tree_view_get_model(GTK_TREE_VIEW
2091                                                 (matcher.cond_list_view));
2092
2093                                 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
2094                                         gtk_tree_model_get(model, &iter,
2095                                                            PREFS_MATCHER_COND, &matcher_str,
2096                                                            -1);
2097                                         if (matcher_str && strcmp(matcher_str, str) == 0) 
2098                                                 break;
2099                                         row++;
2100                                         g_free(matcher_str);
2101                                         matcher_str = NULL;
2102                                 }
2103
2104                                 if (!matcher_str || strcmp(matcher_str, str) != 0) {
2105                                         val = alertpanel(_("Entry not saved"),
2106                                                  _("The entry was not saved.\nClose anyway?"),
2107                                                  GTK_STOCK_CLOSE, _("+_Continue editing"), NULL);
2108                                         if (G_ALERTDEFAULT != val) {
2109                                                 g_free(matcher_str);                                             
2110                                                 g_free(str);
2111                                                 return;
2112                                         }
2113                                 }
2114                                 g_free(matcher_str);
2115                         }
2116                 }
2117                 g_free(str);
2118                 gtk_widget_hide(matcher.window);
2119                 gtk_window_set_modal(GTK_WINDOW(matcher.window), FALSE);
2120                 if (matchers_callback != NULL)
2121                         matchers_callback(matchers);
2122                 matcherlist_free(matchers);
2123         }
2124         inc_unlock();
2125 }
2126
2127 /*!
2128  *\brief        Called when closing dialog box
2129  *
2130  *\param        widget Dialog widget
2131  *\param        event Event info
2132  *\param        data User data
2133  *
2134  *\return       gint TRUE
2135  */
2136 static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
2137                                   gpointer data)
2138 {
2139         prefs_matcher_cancel();
2140         return TRUE;
2141 }
2142
2143 /*
2144  * Strings describing test format strings
2145  * 
2146  * When adding new lines, remember to put 2 strings for each line
2147  */
2148 static gchar *test_desc_strings[] = {
2149         "%%",   N_("literal %"),
2150         "%s",   N_("Subject"),
2151         "%f",   N_("From"),
2152         "%t",   N_("To"),
2153         "%c",   N_("Cc"),
2154         "%d",   N_("Date"),
2155         "%i",   N_("Message-ID"),
2156         "%n",   N_("Newsgroups"),
2157         "%r",   N_("References"),
2158         "%F",   N_("filename (should not be modified)"),
2159         "\\n",  N_("new line"),
2160         "\\",   N_("escape character for quotes"),
2161         "\\\"", N_("quote character"),
2162         NULL,   NULL
2163 };
2164
2165 static DescriptionWindow test_desc_win = { 
2166         NULL,
2167         NULL, 
2168         TRUE,
2169         2,
2170         N_("Match Type: 'Test'"),
2171         N_("'Test' allows you to test a message or message element "
2172            "using an external program or script. The program will "
2173            "return either 0 or 1.\n\n"
2174            "The following symbols can be used:"),
2175         test_desc_strings
2176 };
2177
2178
2179
2180 /*!
2181  *\brief        Show Test action's info
2182  */
2183 static void prefs_matcher_test_info(GtkWidget *widget, GtkWidget *parent)
2184 {
2185         test_desc_win.parent = parent;
2186         description_window_create(&test_desc_win);
2187 }
2188
2189 #ifndef USE_NEW_ADDRBOOK
2190 static void prefs_matcher_addressbook_select(void)
2191 {
2192         const gchar *folderpath = NULL;
2193         gchar *new_path = NULL;
2194
2195         folderpath = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))));
2196         new_path = addressbook_folder_selection(folderpath);
2197         if (new_path) {
2198                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))), new_path);
2199                 g_free(new_path);
2200         } 
2201 }
2202 #endif
2203
2204 /*
2205  * list view
2206  */
2207
2208 static GtkListStore* prefs_matcher_create_data_store(void)
2209 {
2210         return gtk_list_store_new(N_PREFS_MATCHER_COLUMNS,
2211                                   G_TYPE_STRING,        
2212                                   G_TYPE_BOOLEAN,
2213                                   -1);
2214 }
2215
2216 static void prefs_matcher_list_view_insert_matcher(GtkWidget *list_view,
2217                                                    GtkTreeIter *row_iter,
2218                                                    const gchar *matcher,
2219                                                    gboolean is_valid) 
2220 {
2221         GtkTreeIter iter;
2222         GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model
2223                                         (GTK_TREE_VIEW(list_view)));
2224
2225         if (row_iter == NULL) {
2226                 /* append new */
2227                 gtk_list_store_append(list_store, &iter);
2228         } else {
2229                 /* change existing */
2230                 iter = *row_iter;
2231         }
2232
2233         gtk_list_store_set(list_store, &iter,
2234                            PREFS_MATCHER_COND, matcher,
2235                            PREFS_MATCHER_COND_VALID, is_valid,
2236                            -1);
2237 }
2238
2239 static GtkWidget *prefs_matcher_list_view_create(void)
2240 {
2241         GtkTreeView *list_view;
2242         GtkTreeSelection *selector;
2243         GtkTreeModel *model;
2244
2245         model = GTK_TREE_MODEL(prefs_matcher_create_data_store());
2246         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
2247         g_object_unref(model);  
2248         
2249         gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
2250         gtk_tree_view_set_reorderable(list_view, TRUE);
2251         
2252         selector = gtk_tree_view_get_selection(list_view);
2253         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
2254         gtk_tree_selection_set_select_function(selector, prefs_matcher_selected,
2255                                                NULL, NULL);
2256
2257         /* create the columns */
2258         prefs_matcher_create_list_view_columns(GTK_WIDGET(list_view));
2259
2260         return GTK_WIDGET(list_view);
2261 }
2262
2263 static void prefs_matcher_create_list_view_columns(GtkWidget *list_view)
2264 {
2265         GtkTreeViewColumn *column;
2266         GtkCellRenderer *renderer;
2267
2268         renderer = gtk_cell_renderer_text_new();
2269         column = gtk_tree_view_column_new_with_attributes
2270                 (_("Current condition rules"),
2271                  renderer,
2272                  "text", PREFS_MATCHER_COND,
2273                  NULL);
2274         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
2275 }
2276
2277 static void prefs_matcher_set_criteria(const gint criteria)
2278 {
2279         gint match_criteria = 0;
2280         
2281         switch (criteria) {
2282         case CRITERIA_FOUND_IN_ADDRESSBOOK:
2283                 match_criteria = MATCH_ABOOK;
2284                 break;  
2285         case CRITERIA_ALL:
2286                 match_criteria = MATCH_ALL;
2287                 break;
2288         case CRITERIA_AGE_GREATER:
2289         case CRITERIA_AGE_LOWER:
2290         case CRITERIA_AGE_GREATER_HOURS:
2291         case CRITERIA_AGE_LOWER_HOURS:
2292                 match_criteria = MATCH_AGE;
2293                 break;
2294         case CRITERIA_SCORE_GREATER:
2295         case CRITERIA_SCORE_LOWER:
2296         case CRITERIA_SCORE_EQUAL:
2297                 match_criteria = MATCH_SCORE;
2298                 break;
2299         case CRITERIA_SIZE_GREATER:
2300         case CRITERIA_SIZE_SMALLER:
2301         case CRITERIA_SIZE_EQUAL:
2302                 match_criteria = MATCH_SIZE;
2303                 break;
2304         case CRITERIA_SUBJECT:
2305         case CRITERIA_FROM:
2306         case CRITERIA_TO:
2307         case CRITERIA_CC:
2308         case CRITERIA_TO_OR_CC:
2309         case CRITERIA_NEWSGROUPS:
2310         case CRITERIA_INREPLYTO:
2311         case CRITERIA_REFERENCES:
2312         case CRITERIA_HEADER:
2313                 match_criteria = MATCH_HEADER;
2314                 break;
2315         case CRITERIA_HEADERS_PART:
2316         case CRITERIA_BODY_PART:
2317         case CRITERIA_MESSAGE:
2318                 match_criteria = MATCH_PHRASE;
2319                 break;
2320         case CRITERIA_TEST:
2321                 match_criteria = MATCH_TEST;
2322                 break;
2323 #if !GTK_CHECK_VERSION(3, 0, 0)
2324         case CRITERIA_COLORLABEL:
2325                 match_criteria = MATCH_LABEL;
2326                 break;
2327 #endif
2328         case CRITERIA_TAG:
2329         case CRITERIA_TAGGED:
2330                 match_criteria = MATCH_TAGS;
2331                 break;
2332         case CRITERIA_UNREAD:
2333         case CRITERIA_NEW:
2334         case CRITERIA_MARKED:
2335         case CRITERIA_DELETED:
2336         case CRITERIA_REPLIED:
2337         case CRITERIA_FORWARDED:
2338         case CRITERIA_LOCKED:
2339         case CRITERIA_SPAM:
2340         case CRITERIA_HAS_ATTACHMENT:
2341         case CRITERIA_SIGNED:
2342                 match_criteria = MATCH_FLAG;
2343                 break;
2344         case CRITERIA_PARTIAL:
2345                 match_criteria = MATCH_PARTIAL;
2346                 break;
2347         case CRITERIA_IGNORE_THREAD:
2348         case CRITERIA_WATCH_THREAD:
2349                 match_criteria = MATCH_THREAD;
2350                 break;
2351         }
2352         
2353         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo),
2354                                  match_criteria);
2355         
2356         switch(match_criteria) {
2357         case MATCH_HEADER:
2358                 if(criteria != CRITERIA_HEADER)
2359                         combobox_select_by_data(GTK_COMBO_BOX(
2360                                                 matcher.headers_combo),
2361                                                 criteria);
2362                 break;
2363         case MATCH_AGE:
2364         case MATCH_SCORE:
2365         case MATCH_SIZE:
2366         case MATCH_FLAG:
2367                 combobox_select_by_data(GTK_COMBO_BOX(
2368                                         matcher.match_combo), criteria);
2369                 break;
2370         case MATCH_PHRASE:
2371         case MATCH_TAGS:
2372                 combobox_select_by_data(GTK_COMBO_BOX(
2373                                         matcher.criteria_combo2), criteria);
2374                 break;
2375         }
2376 }
2377
2378 static gboolean prefs_matcher_selected(GtkTreeSelection *selector,
2379                                        GtkTreeModel *model, 
2380                                        GtkTreePath *path,
2381                                        gboolean currently_selected,
2382                                        gpointer data)
2383 {
2384         gchar *matcher_str;
2385         MatcherProp *prop;
2386         gboolean negative_cond;
2387         gint criteria;
2388         GtkWidget *menu;
2389         GtkTreeIter iter;
2390         gboolean is_valid;
2391
2392         if (currently_selected)
2393                 return TRUE;
2394
2395         if (!gtk_tree_model_get_iter(model, &iter, path))
2396                 return TRUE;
2397
2398         gtk_tree_model_get(model, &iter, 
2399                            PREFS_MATCHER_COND_VALID,  &is_valid,
2400                            PREFS_MATCHER_COND, &matcher_str,
2401                            -1);
2402         
2403         if (!is_valid) {
2404                 g_free(matcher_str);
2405                 prefs_matcher_reset_condition();
2406                 return TRUE;
2407         }
2408
2409         negative_cond = FALSE;
2410
2411         prop = matcher_parser_get_prop(matcher_str);
2412         if (prop == NULL) {
2413                 g_free(matcher_str);
2414                 return TRUE;
2415         }               
2416
2417         criteria = prefs_matcher_get_criteria_from_matching(prop->criteria);
2418         prefs_matcher_set_criteria(criteria);
2419
2420         switch(prop->criteria) {
2421         case MATCHCRITERIA_NOT_UNREAD:
2422         case MATCHCRITERIA_NOT_NEW:
2423         case MATCHCRITERIA_NOT_MARKED:
2424         case MATCHCRITERIA_NOT_DELETED:
2425         case MATCHCRITERIA_NOT_REPLIED:
2426         case MATCHCRITERIA_NOT_FORWARDED:
2427         case MATCHCRITERIA_NOT_LOCKED:
2428         case MATCHCRITERIA_NOT_SPAM:
2429         case MATCHCRITERIA_HAS_NO_ATTACHMENT:
2430         case MATCHCRITERIA_NOT_SIGNED:
2431         case MATCHCRITERIA_NOT_PARTIAL:
2432         case MATCHCRITERIA_NOT_COLORLABEL:
2433         case MATCHCRITERIA_NOT_IGNORE_THREAD:
2434         case MATCHCRITERIA_NOT_WATCH_THREAD:
2435         case MATCHCRITERIA_NOT_SUBJECT:
2436         case MATCHCRITERIA_NOT_FROM:
2437         case MATCHCRITERIA_NOT_TO:
2438         case MATCHCRITERIA_NOT_CC:
2439         case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
2440         case MATCHCRITERIA_NOT_TAG:
2441         case MATCHCRITERIA_NOT_TAGGED:
2442         case MATCHCRITERIA_NOT_NEWSGROUPS:
2443         case MATCHCRITERIA_NOT_INREPLYTO:
2444         case MATCHCRITERIA_NOT_REFERENCES:
2445         case MATCHCRITERIA_NOT_HEADER:
2446         case MATCHCRITERIA_NOT_HEADERS_PART:
2447         case MATCHCRITERIA_NOT_MESSAGE:
2448         case MATCHCRITERIA_NOT_BODY_PART:
2449         case MATCHCRITERIA_NOT_TEST:
2450         case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
2451                 negative_cond = TRUE;
2452                 break;
2453         }
2454         
2455         switch(prop->criteria) {
2456         case MATCHCRITERIA_ALL:
2457                 break;
2458
2459         case MATCHCRITERIA_NOT_SUBJECT:
2460         case MATCHCRITERIA_NOT_FROM:
2461         case MATCHCRITERIA_NOT_TO:
2462         case MATCHCRITERIA_NOT_CC:
2463         case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
2464         case MATCHCRITERIA_NOT_TAG:
2465         case MATCHCRITERIA_NOT_NEWSGROUPS:
2466         case MATCHCRITERIA_NOT_INREPLYTO:
2467         case MATCHCRITERIA_NOT_REFERENCES:
2468         case MATCHCRITERIA_NOT_HEADERS_PART:
2469         case MATCHCRITERIA_NOT_BODY_PART:
2470         case MATCHCRITERIA_NOT_MESSAGE:
2471         case MATCHCRITERIA_NOT_TEST:
2472         case MATCHCRITERIA_SUBJECT:
2473         case MATCHCRITERIA_FROM:
2474         case MATCHCRITERIA_TO:
2475         case MATCHCRITERIA_CC:
2476         case MATCHCRITERIA_TO_OR_CC:
2477         case MATCHCRITERIA_TAG:
2478         case MATCHCRITERIA_NEWSGROUPS:
2479         case MATCHCRITERIA_INREPLYTO:
2480         case MATCHCRITERIA_REFERENCES:
2481         case MATCHCRITERIA_HEADERS_PART:
2482         case MATCHCRITERIA_BODY_PART:
2483         case MATCHCRITERIA_MESSAGE:
2484         case MATCHCRITERIA_TEST:
2485                 gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), prop->expr);
2486                 break;
2487
2488         case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
2489         case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
2490         {
2491                 gchar *header;
2492                 gchar *expr;
2493
2494                 /* matcher expressions contain UNtranslated "Any"/"All",
2495                   select the relevant translated combo item */
2496                 if (strcasecmp(prop->header, "All") == 0)
2497                         header = (gchar*)C_("Filtering Matcher Menu", "All");
2498                 else
2499                         if (strcasecmp(prop->header, "Any") == 0)
2500                                 header = _("Any");
2501                         else
2502                                 header = prop->header;
2503                 if (strcasecmp(prop->expr, "Any") == 0)
2504                         expr = _("Any");
2505                 else
2506                         expr = prop->expr;
2507
2508                 gtk_entry_set_text(GTK_ENTRY(matcher.header_addr_entry), header);
2509                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))), expr);
2510                 break;
2511         }
2512
2513         case MATCHCRITERIA_AGE_GREATER:
2514         case MATCHCRITERIA_AGE_LOWER:
2515                 if(prop->value >= 7 && !(prop->value % 7)) {
2516                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2517                                                  AGE_WEEKS);
2518                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2519                                         matcher.numeric_entry), prop->value/7);
2520                 } else {
2521                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2522                                                  AGE_DAYS);
2523                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2524                                         matcher.numeric_entry), prop->value);
2525                 }
2526                 break;
2527                 
2528         case MATCHCRITERIA_AGE_GREATER_HOURS:
2529         case MATCHCRITERIA_AGE_LOWER_HOURS:
2530                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2531                                          AGE_HOURS);
2532                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2533                                 matcher.numeric_entry), prop->value);
2534                 break;
2535                 
2536         case MATCHCRITERIA_SCORE_GREATER:
2537         case MATCHCRITERIA_SCORE_LOWER:
2538         case MATCHCRITERIA_SCORE_EQUAL:
2539                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry),
2540                                           prop->value);
2541                 break;
2542
2543         case MATCHCRITERIA_SIZE_GREATER:
2544         case MATCHCRITERIA_SIZE_SMALLER:
2545         case MATCHCRITERIA_SIZE_EQUAL:
2546                 if(prop->value >= MB_SIZE && !(prop->value % MB_SIZE)) {
2547                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2548                                                  SIZE_UNIT_MBYTES);
2549                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2550                                         matcher.numeric_entry), prop->value/MB_SIZE);
2551                 } else if(prop->value >= KB_SIZE && !(prop->value % KB_SIZE)) {
2552                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2553                                                  SIZE_UNIT_KBYTES);
2554                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2555                                         matcher.numeric_entry), prop->value/KB_SIZE);
2556                 } else {
2557                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2558                                                  SIZE_UNIT_BYTES);
2559                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2560                                         matcher.numeric_entry), prop->value);           
2561                 }
2562                 break;
2563
2564 #if !GTK_CHECK_VERSION(3, 0, 0)
2565         case MATCHCRITERIA_NOT_COLORLABEL:
2566         case MATCHCRITERIA_COLORLABEL:
2567                 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(matcher.color_optmenu),
2568                                             prop->value + 1);
2569                 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(matcher.color_optmenu));
2570                 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
2571                 break;
2572 #endif
2573
2574         case MATCHCRITERIA_NOT_HEADER:
2575         case MATCHCRITERIA_HEADER:
2576                 gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), prop->header);
2577                 gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), prop->expr);
2578                 break;
2579         }
2580
2581         switch(criteria) {
2582         case CRITERIA_SUBJECT:
2583         case CRITERIA_FROM:
2584         case CRITERIA_TO:
2585         case CRITERIA_CC:
2586         case CRITERIA_TO_OR_CC:
2587         case CRITERIA_NEWSGROUPS:
2588         case CRITERIA_INREPLYTO:
2589         case CRITERIA_REFERENCES:
2590         case CRITERIA_HEADER:
2591         case CRITERIA_HEADERS_PART:
2592         case CRITERIA_BODY_PART:
2593         case CRITERIA_MESSAGE:
2594         case CRITERIA_TAG:
2595         case CRITERIA_TAGGED:
2596         case CRITERIA_TEST:
2597                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo),
2598                                         negative_cond ? PREDICATE_DOES_NOT_CONTAIN :
2599                                                         PREDICATE_CONTAINS);
2600                 break;
2601         case CRITERIA_FOUND_IN_ADDRESSBOOK:
2602         case CRITERIA_UNREAD:
2603         case CRITERIA_NEW:
2604         case CRITERIA_MARKED:
2605         case CRITERIA_DELETED:
2606         case CRITERIA_REPLIED:
2607         case CRITERIA_FORWARDED:
2608         case CRITERIA_LOCKED:
2609         case CRITERIA_SPAM:
2610         case CRITERIA_HAS_ATTACHMENT:
2611         case CRITERIA_SIGNED:
2612         case CRITERIA_COLORLABEL:
2613                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2614                                          negative_cond ? PREDICATE_FLAG_DISABLED :
2615                                                          PREDICATE_FLAG_ENABLED);
2616                 break;
2617         case CRITERIA_WATCH_THREAD:
2618                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2),
2619                                          negative_cond ? THREAD_NOT_WATCHED :
2620                                                          THREAD_WATCHED);
2621                 break;
2622         case CRITERIA_IGNORE_THREAD:
2623                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2),
2624                                          negative_cond ? THREAD_NOT_IGNORED :
2625                                                          THREAD_IGNORED);
2626                 break;  
2627         case CRITERIA_PARTIAL:
2628                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2),
2629                                          negative_cond ? PREDICATE_FLAG_DISABLED :
2630                                                          PREDICATE_FLAG_ENABLED);
2631                 break;
2632         }
2633
2634         switch(prop->matchtype) {
2635         case MATCHTYPE_MATCH:
2636 #ifndef G_OS_WIN32
2637                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
2638 #endif
2639                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), TRUE);
2640                 break;
2641
2642         case MATCHTYPE_MATCHCASE:
2643 #ifndef G_OS_WIN32
2644                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
2645 #endif
2646                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
2647                 break;
2648
2649         case MATCHTYPE_REGEXP:
2650 #ifndef G_OS_WIN32
2651                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), TRUE);
2652 #endif
2653                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), TRUE);
2654                 break;
2655
2656         case MATCHTYPE_REGEXPCASE:
2657 #ifndef G_OS_WIN32
2658                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), TRUE);
2659 #endif
2660                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
2661                 break;
2662         }
2663
2664         g_free(matcher_str);
2665         return TRUE;
2666 }
2667