04516f17d016f155619ba41b1e13eb1201257820
[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_from_stock(GTK_STOCK_DELETE);
775         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
776         g_signal_connect(G_OBJECT(del_btn), "clicked",
777                          G_CALLBACK(prefs_matcher_delete_cb), NULL);
778
779         cond_hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
780         gtk_box_pack_start(GTK_BOX(vbox1), cond_hbox, TRUE, TRUE, 0);
781
782         cond_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
783         gtk_widget_set_size_request(cond_scrolledwin, -1, 150);
784         gtk_box_pack_start(GTK_BOX(cond_hbox), cond_scrolledwin,
785                            TRUE, TRUE, 0);
786         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cond_scrolledwin),
787                                        GTK_POLICY_AUTOMATIC,
788                                        GTK_POLICY_AUTOMATIC);
789
790         cond_list_view = prefs_matcher_list_view_create();                                     
791         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(cond_scrolledwin),
792                                             GTK_SHADOW_ETCHED_IN);
793         gtk_container_add(GTK_CONTAINER(cond_scrolledwin), cond_list_view);
794
795         btn_vbox = gtk_vbox_new(FALSE, VBOX_BORDER);
796         gtk_box_pack_start(GTK_BOX(cond_hbox), btn_vbox, FALSE, FALSE, 0);
797
798         up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
799         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
800         g_signal_connect(G_OBJECT(up_btn), "clicked",
801                          G_CALLBACK(prefs_matcher_up), NULL);
802
803         down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
804         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
805         g_signal_connect(G_OBJECT(down_btn), "clicked",
806                          G_CALLBACK(prefs_matcher_down), NULL);
807
808         /* boolean operation */
809         GtkWidget *hbox_bool = gtk_hbox_new(FALSE, HSPACING_NARROW);
810         gtk_box_pack_start(GTK_BOX(vbox1), hbox_bool, FALSE, FALSE, 0);
811
812         bool_op_label = gtk_label_new(_("Message must match"));
813         gtk_box_pack_start(GTK_BOX(hbox_bool), bool_op_label,
814                            FALSE, FALSE, 0);
815
816         bool_op_combo = combobox_text_new(FALSE, _("at least one"), 
817                                           _("all"), NULL);
818         gtk_box_pack_start(GTK_BOX(hbox_bool), bool_op_combo,
819                            FALSE, FALSE, 0);
820         gtk_box_pack_start(GTK_BOX(hbox_bool), gtk_label_new(_("of above rules")),
821                            FALSE, FALSE, 0);
822         gtk_box_pack_start(GTK_BOX(hbox_bool), gtk_label_new(""),
823                            TRUE, TRUE, 0);
824         
825         if (!geometry.min_height) {
826                 geometry.min_width = 550;
827                 geometry.min_height = 368;
828         }
829
830         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
831                                       GDK_HINT_MIN_SIZE);
832         gtk_widget_set_size_request(window, prefs_common.matcherwin_width,
833                                     prefs_common.matcherwin_height);
834
835         gtk_widget_show_all(window);
836
837         matcher.window    = window;
838
839         matcher.ok_btn = ok_btn;
840
841         matcher.criteria_combo = criteria_combo;
842         matcher.criteria_combo2 = criteria_combo2;
843         matcher.header_entry = header_entry;
844         matcher.header_addr_combo = header_addr_combo;
845         matcher.header_addr_entry = header_addr_entry;
846         matcher.string_entry = string_entry;
847         matcher.numeric_entry = numeric_entry;
848         matcher.numeric_label = numeric_label;
849         matcher.addressbook_folder_combo = addressbook_folder_combo;
850         matcher.match_combo = match_combo;
851         matcher.case_checkbtn = case_checkbtn;
852 #ifndef G_OS_WIN32
853         matcher.regexp_checkbtn = regexp_checkbtn;
854 #endif
855         matcher.bool_op_combo = bool_op_combo;
856         matcher.test_btn = test_btn;
857 #ifndef USE_NEW_ADDRBOOK
858         matcher.addressbook_select_btn = addressbook_select_btn;
859 #endif
860 #if !GTK_CHECK_VERSION(3, 0, 0)
861         matcher.color_optmenu = color_optmenu;
862 #endif
863         matcher.match_label = match_label;
864         matcher.criteria_label2 = criteria_label2;
865         matcher.headers_combo = headers_combo;
866         matcher.match_combo2 = match_combo2;
867         matcher.match_label2 = match_label2;
868         matcher.upper_filler = upper_filler;
869         matcher.lower_filler = lower_filler;
870         
871         matcher.cond_list_view = cond_list_view;
872
873         matcher.selected_criteria = -1;
874         prefs_matcher_criteria_select(criteria_combo, NULL);
875 }
876
877 /*!
878  *\brief        Set the contents of a row
879  *
880  *\param        row Index of row to set
881  *\param        prop Condition to set
882  *
883  *\return       gint Row index \a prop has been added
884  */
885 static void prefs_matcher_list_view_set_row(GtkTreeIter *row, MatcherProp *prop)
886 {
887         gchar *matcher_str;
888
889         if (prop == NULL) {
890                 prefs_matcher_list_view_insert_matcher(matcher.cond_list_view,
891                                                        NULL, _("(New)"), FALSE);
892                 return;                                                
893         }
894
895         matcher_str = matcherprop_to_string(prop);
896         if (!row)
897                 prefs_matcher_list_view_insert_matcher(matcher.cond_list_view,
898                                                        NULL, matcher_str,
899                                                        TRUE);
900         else
901                 prefs_matcher_list_view_insert_matcher(matcher.cond_list_view,
902                                                        row, matcher_str, 
903                                                        TRUE);
904         g_free(matcher_str);
905 }
906
907 static gboolean match_combo2_model_set(void)
908 {
909         GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(matcher.match_combo2));
910         if (model == matcher.model_age_units ||
911             model == matcher.model_found ||
912             model == matcher.model_partial ||
913             model == matcher.model_phrase ||
914             model == matcher.model_set ||
915             model == matcher.model_size_units ||
916             model == matcher.model_tags ||
917             model == matcher.model_thread)
918                 return TRUE;
919         else
920                 debug_print("match_combo2 model unset.\n");
921
922         return FALSE;
923 }
924
925 static gboolean match_combo_model_set(void)
926 {
927         GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(matcher.match_combo));
928         if (model == matcher.model_age ||
929             model == matcher.model_contain ||
930             model == matcher.model_flags ||
931             model == matcher.model_score ||
932             model == matcher.model_size ||
933             model == matcher.model_test)
934                 return TRUE;
935         else
936                 debug_print("match_combo model unset.\n");
937
938         return FALSE;
939 }
940
941 /*!
942  *\brief        Clears a condition in the list widget
943  */
944 static void prefs_matcher_reset_condition(void)
945 {
946         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo), MATCH_ALL);
947         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2), 0);
948         if (match_combo_model_set())
949                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo), 0);
950         if (match_combo2_model_set())
951                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2), 0);
952 #if !GTK_CHECK_VERSION(3, 0, 0)
953         gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(matcher.color_optmenu), 0);
954 #endif
955         gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
956         gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), "");
957         gtk_entry_set_text(GTK_ENTRY(matcher.header_addr_entry), "");
958         gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), "");
959         gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))), "");
960 #ifndef G_OS_WIN32
961         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
962 #endif
963         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
964 }
965
966 /*!
967  *\brief        Initializes dialog with a set of conditions
968  *
969  *\param        matchers List of conditions
970  */
971 static void prefs_matcher_set_dialog(MatcherList *matchers)
972 {
973         GSList *cur;
974         gboolean bool_op = 1;
975         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
976                                 (GTK_TREE_VIEW(matcher.cond_list_view)));
977
978         gtk_list_store_clear(store);                            
979
980         prefs_matcher_list_view_set_row(NULL, NULL);
981         if (matchers != NULL) {
982                 for (cur = matchers->matchers; cur != NULL;
983                      cur = g_slist_next(cur)) {
984                         MatcherProp *prop;
985                         prop = (MatcherProp *) cur->data;
986                         prefs_matcher_list_view_set_row(NULL, prop);
987                 }
988
989                 bool_op = matchers->bool_and;
990         }
991         
992         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.bool_op_combo), bool_op);
993
994         prefs_matcher_reset_condition();
995         
996         combobox_set_sensitive(GTK_COMBO_BOX(matcher.criteria_combo), MATCH_TAGS,
997                         (tags_get_size() > 0) ? TRUE : FALSE);
998 }
999
1000 /*!
1001  *\brief        Converts current conditions in list box in
1002  *              a matcher list used by the matcher.
1003  *
1004  *\return       MatcherList * List of conditions.
1005  */
1006 static MatcherList *prefs_matcher_get_list(void)
1007 {
1008         gchar *matcher_str;
1009         MatcherProp *prop;
1010         gboolean bool_and;
1011         GSList *matcher_list;
1012         MatcherList *matchers;
1013         GtkTreeModel *model;
1014         GtkTreeIter iter;
1015
1016         model = gtk_tree_view_get_model(GTK_TREE_VIEW(matcher.cond_list_view));
1017         if (!gtk_tree_model_get_iter_first(model, &iter))
1018                 return NULL;
1019
1020         matcher_list = NULL;
1021
1022         do {
1023                 gboolean is_valid;
1024         
1025                 gtk_tree_model_get(model, &iter,
1026                                    PREFS_MATCHER_COND, &matcher_str,
1027                                    PREFS_MATCHER_COND_VALID, &is_valid,
1028                                    -1);
1029                 
1030                 if (is_valid) {
1031                         /* tmp = matcher_str; */
1032                         prop = matcher_parser_get_prop(matcher_str);
1033                         g_free(matcher_str);
1034                         if (prop == NULL)
1035                                 break;
1036                         
1037                         matcher_list = g_slist_append(matcher_list, prop);
1038                 }
1039         } while (gtk_tree_model_iter_next(model, &iter));
1040
1041         bool_and = gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.bool_op_combo));
1042
1043         matchers = matcherlist_new(matcher_list, bool_and);
1044
1045         return matchers;
1046 }
1047
1048 /*!
1049  *\brief        Maps a keyword id (see #get_matchparser_tab_id) to a 
1050  *              criteria type (see first parameter of #matcherprop_new
1051  *              or #matcherprop_unquote_new)
1052  *
1053  *\param        matching_id Id returned by the matcher parser.
1054  *
1055  *\return       gint One of the CRITERIA_xxx constants.
1056  */
1057 static gint prefs_matcher_get_criteria_from_matching(gint matching_id)
1058 {
1059         switch(matching_id) {
1060         case MATCHCRITERIA_ALL:
1061                 return CRITERIA_ALL;
1062         case MATCHCRITERIA_NOT_UNREAD:
1063         case MATCHCRITERIA_UNREAD:
1064                 return CRITERIA_UNREAD;
1065         case MATCHCRITERIA_NOT_NEW:
1066         case MATCHCRITERIA_NEW:
1067                 return CRITERIA_NEW;
1068         case MATCHCRITERIA_NOT_MARKED:
1069         case MATCHCRITERIA_MARKED:
1070                 return CRITERIA_MARKED;
1071         case MATCHCRITERIA_NOT_DELETED:
1072         case MATCHCRITERIA_DELETED:
1073                 return CRITERIA_DELETED;
1074         case MATCHCRITERIA_NOT_REPLIED:
1075         case MATCHCRITERIA_REPLIED:
1076                 return CRITERIA_REPLIED;
1077         case MATCHCRITERIA_NOT_FORWARDED:
1078         case MATCHCRITERIA_FORWARDED:
1079                 return CRITERIA_FORWARDED;
1080         case MATCHCRITERIA_LOCKED:
1081         case MATCHCRITERIA_NOT_LOCKED:
1082                 return CRITERIA_LOCKED;
1083         case MATCHCRITERIA_NOT_SPAM:
1084         case MATCHCRITERIA_SPAM:
1085                 return CRITERIA_SPAM;
1086         case MATCHCRITERIA_HAS_ATTACHMENT:
1087         case MATCHCRITERIA_HAS_NO_ATTACHMENT:
1088                 return CRITERIA_HAS_ATTACHMENT;
1089         case MATCHCRITERIA_SIGNED:
1090         case MATCHCRITERIA_NOT_SIGNED:
1091                 return CRITERIA_SIGNED;
1092         case MATCHCRITERIA_PARTIAL:
1093         case MATCHCRITERIA_NOT_PARTIAL:
1094                 return CRITERIA_PARTIAL;
1095 #if !GTK_CHECK_VERSION(3, 0, 0)
1096         case MATCHCRITERIA_COLORLABEL:
1097         case MATCHCRITERIA_NOT_COLORLABEL:
1098                 return CRITERIA_COLORLABEL;
1099 #endif
1100         case MATCHCRITERIA_IGNORE_THREAD:
1101         case MATCHCRITERIA_NOT_IGNORE_THREAD:
1102                 return CRITERIA_IGNORE_THREAD;
1103         case MATCHCRITERIA_WATCH_THREAD:
1104         case MATCHCRITERIA_NOT_WATCH_THREAD:
1105                 return CRITERIA_WATCH_THREAD;
1106         case MATCHCRITERIA_NOT_SUBJECT:
1107         case MATCHCRITERIA_SUBJECT:
1108                 return CRITERIA_SUBJECT;
1109         case MATCHCRITERIA_NOT_FROM:
1110         case MATCHCRITERIA_FROM:
1111                 return CRITERIA_FROM;
1112         case MATCHCRITERIA_NOT_TO:
1113         case MATCHCRITERIA_TO:
1114                 return CRITERIA_TO;
1115         case MATCHCRITERIA_NOT_CC:
1116         case MATCHCRITERIA_CC:
1117                 return CRITERIA_CC;
1118         case MATCHCRITERIA_NOT_NEWSGROUPS:
1119         case MATCHCRITERIA_NEWSGROUPS:
1120                 return CRITERIA_NEWSGROUPS;
1121         case MATCHCRITERIA_NOT_INREPLYTO:
1122         case MATCHCRITERIA_INREPLYTO:
1123                 return CRITERIA_INREPLYTO;
1124         case MATCHCRITERIA_NOT_REFERENCES:
1125         case MATCHCRITERIA_REFERENCES:
1126                 return CRITERIA_REFERENCES;
1127         case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
1128         case MATCHCRITERIA_TO_OR_CC:
1129                 return CRITERIA_TO_OR_CC;
1130         case MATCHCRITERIA_NOT_TAG:
1131         case MATCHCRITERIA_TAG:
1132                 return CRITERIA_TAG;
1133         case MATCHCRITERIA_NOT_TAGGED:
1134         case MATCHCRITERIA_TAGGED:
1135                 return CRITERIA_TAGGED;
1136         case MATCHCRITERIA_NOT_BODY_PART:
1137         case MATCHCRITERIA_BODY_PART:
1138                 return CRITERIA_BODY_PART;
1139         case MATCHCRITERIA_NOT_MESSAGE:
1140         case MATCHCRITERIA_MESSAGE:
1141                 return CRITERIA_MESSAGE;
1142         case MATCHCRITERIA_NOT_HEADERS_PART:
1143         case MATCHCRITERIA_HEADERS_PART:
1144                 return CRITERIA_HEADERS_PART;
1145         case MATCHCRITERIA_NOT_HEADER:
1146         case MATCHCRITERIA_HEADER:
1147                 return CRITERIA_HEADER;
1148         case MATCHCRITERIA_AGE_GREATER_HOURS:
1149                 return CRITERIA_AGE_GREATER_HOURS;
1150         case MATCHCRITERIA_AGE_LOWER_HOURS:
1151                 return CRITERIA_AGE_LOWER_HOURS;
1152         case MATCHCRITERIA_AGE_GREATER:
1153                 return CRITERIA_AGE_GREATER;
1154         case MATCHCRITERIA_AGE_LOWER:
1155                 return CRITERIA_AGE_LOWER;
1156         case MATCHCRITERIA_SCORE_GREATER:
1157                 return CRITERIA_SCORE_GREATER;
1158         case MATCHCRITERIA_SCORE_LOWER:
1159                 return CRITERIA_SCORE_LOWER;
1160         case MATCHCRITERIA_SCORE_EQUAL:
1161                 return CRITERIA_SCORE_EQUAL;
1162         case MATCHCRITERIA_NOT_TEST:
1163         case MATCHCRITERIA_TEST:
1164                 return CRITERIA_TEST;
1165         case MATCHCRITERIA_SIZE_GREATER:
1166                 return CRITERIA_SIZE_GREATER;
1167         case MATCHCRITERIA_SIZE_SMALLER:
1168                 return CRITERIA_SIZE_SMALLER;
1169         case MATCHCRITERIA_SIZE_EQUAL:
1170                 return CRITERIA_SIZE_EQUAL;
1171         case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
1172         case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
1173                 return CRITERIA_FOUND_IN_ADDRESSBOOK;
1174         default:
1175                 return -1;
1176         }
1177 }
1178
1179 /*!
1180  *\brief        Returns the matcher keyword id from a criteria id
1181  *
1182  *\param        criteria_id Criteria id (should not be the negate
1183  *              one)
1184  *
1185  *\return       gint A matcher keyword id. See #get_matchparser_tab_id.
1186  */
1187 static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
1188 {
1189         switch (criteria_id) {
1190         case CRITERIA_ALL:
1191                 return MATCHCRITERIA_ALL;
1192         case CRITERIA_UNREAD:
1193                 return MATCHCRITERIA_UNREAD;
1194         case CRITERIA_NEW:
1195                 return MATCHCRITERIA_NEW;
1196         case CRITERIA_MARKED:
1197                 return MATCHCRITERIA_MARKED;
1198         case CRITERIA_DELETED:
1199                 return MATCHCRITERIA_DELETED;
1200         case CRITERIA_REPLIED:
1201                 return MATCHCRITERIA_REPLIED;
1202         case CRITERIA_FORWARDED:
1203                 return MATCHCRITERIA_FORWARDED;
1204         case CRITERIA_LOCKED:
1205                 return MATCHCRITERIA_LOCKED;
1206         case CRITERIA_SPAM:
1207                 return MATCHCRITERIA_SPAM;
1208         case CRITERIA_HAS_ATTACHMENT:
1209                 return MATCHCRITERIA_HAS_ATTACHMENT;
1210         case CRITERIA_SIGNED:
1211                 return MATCHCRITERIA_SIGNED;
1212         case CRITERIA_PARTIAL:
1213                 return MATCHCRITERIA_PARTIAL;
1214 #if !GTK_CHECK_VERSION(3, 0, 0)
1215         case CRITERIA_COLORLABEL:
1216                 return MATCHCRITERIA_COLORLABEL;
1217 #endif
1218         case CRITERIA_IGNORE_THREAD:
1219                 return MATCHCRITERIA_IGNORE_THREAD;
1220         case CRITERIA_WATCH_THREAD:
1221                 return MATCHCRITERIA_WATCH_THREAD;
1222         case CRITERIA_SUBJECT:
1223                 return MATCHCRITERIA_SUBJECT;
1224         case CRITERIA_FROM:
1225                 return MATCHCRITERIA_FROM;
1226         case CRITERIA_TO:
1227                 return MATCHCRITERIA_TO;
1228         case CRITERIA_CC:
1229                 return MATCHCRITERIA_CC;
1230         case CRITERIA_TO_OR_CC:
1231                 return MATCHCRITERIA_TO_OR_CC;
1232         case CRITERIA_TAG:
1233                 return MATCHCRITERIA_TAG;
1234         case CRITERIA_TAGGED:
1235                 return MATCHCRITERIA_TAGGED;
1236         case CRITERIA_NEWSGROUPS:
1237                 return MATCHCRITERIA_NEWSGROUPS;
1238         case CRITERIA_INREPLYTO:
1239                 return MATCHCRITERIA_INREPLYTO;
1240         case CRITERIA_REFERENCES:
1241                 return MATCHCRITERIA_REFERENCES;
1242         case CRITERIA_AGE_GREATER:
1243                 return MATCHCRITERIA_AGE_GREATER;
1244         case CRITERIA_AGE_LOWER:
1245                 return MATCHCRITERIA_AGE_LOWER;
1246         case CRITERIA_AGE_GREATER_HOURS:
1247                 return MATCHCRITERIA_AGE_GREATER_HOURS;
1248         case CRITERIA_AGE_LOWER_HOURS:
1249                 return MATCHCRITERIA_AGE_LOWER_HOURS;
1250         case CRITERIA_SCORE_GREATER:
1251                 return MATCHCRITERIA_SCORE_GREATER;
1252         case CRITERIA_SCORE_LOWER:
1253                 return MATCHCRITERIA_SCORE_LOWER;
1254         case CRITERIA_SCORE_EQUAL:
1255                 return MATCHCRITERIA_SCORE_EQUAL;
1256         case CRITERIA_HEADER:
1257                 return MATCHCRITERIA_HEADER;
1258         case CRITERIA_HEADERS_PART:
1259                 return MATCHCRITERIA_HEADERS_PART;
1260         case CRITERIA_BODY_PART:
1261                 return MATCHCRITERIA_BODY_PART;
1262         case CRITERIA_MESSAGE:
1263                 return MATCHCRITERIA_MESSAGE;
1264         case CRITERIA_TEST:
1265                 return MATCHCRITERIA_TEST;
1266         case CRITERIA_SIZE_GREATER:
1267                 return MATCHCRITERIA_SIZE_GREATER;
1268         case CRITERIA_SIZE_SMALLER:
1269                 return MATCHCRITERIA_SIZE_SMALLER;
1270         case CRITERIA_SIZE_EQUAL:
1271                 return MATCHCRITERIA_SIZE_EQUAL;
1272         case CRITERIA_FOUND_IN_ADDRESSBOOK:
1273                 return MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1274         default:
1275                 return -1;
1276         }
1277 }
1278
1279 /*!
1280  *\brief        Returns the negate matcher keyword id from a matcher keyword
1281  *              id.
1282  *
1283  *\param        matcher_criteria Matcher keyword id. 
1284  *
1285  *\return       gint A matcher keyword id. See #get_matchparser_tab_id.
1286  */
1287 static gint prefs_matcher_not_criteria(gint matcher_criteria)
1288 {
1289         switch(matcher_criteria) {
1290         case MATCHCRITERIA_UNREAD:
1291                 return MATCHCRITERIA_NOT_UNREAD;
1292         case MATCHCRITERIA_NEW:
1293                 return MATCHCRITERIA_NOT_NEW;
1294         case MATCHCRITERIA_MARKED:
1295                 return MATCHCRITERIA_NOT_MARKED;
1296         case MATCHCRITERIA_DELETED:
1297                 return MATCHCRITERIA_NOT_DELETED;
1298         case MATCHCRITERIA_REPLIED:
1299                 return MATCHCRITERIA_NOT_REPLIED;
1300         case MATCHCRITERIA_FORWARDED:
1301                 return MATCHCRITERIA_NOT_FORWARDED;
1302         case MATCHCRITERIA_LOCKED:
1303                 return MATCHCRITERIA_NOT_LOCKED;
1304         case MATCHCRITERIA_SPAM:
1305                 return MATCHCRITERIA_NOT_SPAM;
1306         case MATCHCRITERIA_HAS_ATTACHMENT:
1307                 return MATCHCRITERIA_HAS_NO_ATTACHMENT;
1308         case MATCHCRITERIA_SIGNED:
1309                 return MATCHCRITERIA_NOT_SIGNED;
1310         case MATCHCRITERIA_PARTIAL:
1311                 return MATCHCRITERIA_NOT_PARTIAL;
1312 #if !GTK_CHECK_VERSION(3, 0, 0)
1313         case MATCHCRITERIA_COLORLABEL:
1314                 return MATCHCRITERIA_NOT_COLORLABEL;
1315 #endif
1316         case MATCHCRITERIA_IGNORE_THREAD:
1317                 return MATCHCRITERIA_NOT_IGNORE_THREAD;
1318         case MATCHCRITERIA_WATCH_THREAD:
1319                 return MATCHCRITERIA_NOT_WATCH_THREAD;
1320         case MATCHCRITERIA_SUBJECT:
1321                 return MATCHCRITERIA_NOT_SUBJECT;
1322         case MATCHCRITERIA_FROM:
1323                 return MATCHCRITERIA_NOT_FROM;
1324         case MATCHCRITERIA_TO:
1325                 return MATCHCRITERIA_NOT_TO;
1326         case MATCHCRITERIA_CC:
1327                 return MATCHCRITERIA_NOT_CC;
1328         case MATCHCRITERIA_TO_OR_CC:
1329                 return MATCHCRITERIA_NOT_TO_AND_NOT_CC;
1330         case MATCHCRITERIA_TAG:
1331                 return MATCHCRITERIA_NOT_TAG;
1332         case MATCHCRITERIA_TAGGED:
1333                 return MATCHCRITERIA_NOT_TAGGED;
1334         case MATCHCRITERIA_NEWSGROUPS:
1335                 return MATCHCRITERIA_NOT_NEWSGROUPS;
1336         case MATCHCRITERIA_INREPLYTO:
1337                 return MATCHCRITERIA_NOT_INREPLYTO;
1338         case MATCHCRITERIA_REFERENCES:
1339                 return MATCHCRITERIA_NOT_REFERENCES;
1340         case MATCHCRITERIA_HEADER:
1341                 return MATCHCRITERIA_NOT_HEADER;
1342         case MATCHCRITERIA_HEADERS_PART:
1343                 return MATCHCRITERIA_NOT_HEADERS_PART;
1344         case MATCHCRITERIA_MESSAGE:
1345                 return MATCHCRITERIA_NOT_MESSAGE;
1346         case MATCHCRITERIA_TEST:
1347                 return MATCHCRITERIA_NOT_TEST;
1348         case MATCHCRITERIA_BODY_PART:
1349                 return MATCHCRITERIA_NOT_BODY_PART;
1350         case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
1351                 return MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1352         default:
1353                 return matcher_criteria;
1354         }
1355 }
1356
1357 static gint prefs_matcher_get_criteria(void)
1358 {
1359         gint match_criteria = gtk_combo_box_get_active(GTK_COMBO_BOX(
1360                                         matcher.criteria_combo));
1361         const gchar *header = NULL;
1362           
1363         switch (match_criteria) {
1364         case MATCH_ABOOK:
1365                 return CRITERIA_FOUND_IN_ADDRESSBOOK;   
1366         case MATCH_ALL:
1367                 return CRITERIA_ALL;
1368         case MATCH_AGE:
1369         case MATCH_SCORE:
1370         case MATCH_SIZE:
1371         case MATCH_FLAG:
1372                 return combobox_get_active_data(GTK_COMBO_BOX(
1373                                         matcher.match_combo));
1374         case MATCH_HEADER:
1375                 header = gtk_entry_get_text(GTK_ENTRY(matcher.header_entry));
1376                 return header_name_to_crit(header);
1377 #if !GTK_CHECK_VERSION(3, 0, 0)
1378         case MATCH_LABEL:
1379                 return CRITERIA_COLORLABEL;
1380 #endif
1381         case MATCH_PARTIAL:
1382                 return CRITERIA_PARTIAL;
1383         case MATCH_TEST:
1384                 return CRITERIA_TEST;
1385         case MATCH_PHRASE:
1386         case MATCH_TAGS:
1387         case MATCH_THREAD:
1388                 return combobox_get_active_data(GTK_COMBO_BOX(
1389                                         matcher.criteria_combo2));
1390         }
1391         
1392         return -1;
1393 }
1394
1395 static gint prefs_matcher_get_pred(const gint criteria)
1396 {
1397         switch(criteria) {
1398         case CRITERIA_SUBJECT:
1399         case CRITERIA_FROM:
1400         case CRITERIA_TO:
1401         case CRITERIA_CC:
1402         case CRITERIA_TO_OR_CC:
1403         case CRITERIA_NEWSGROUPS:
1404         case CRITERIA_INREPLYTO:
1405         case CRITERIA_REFERENCES:
1406         case CRITERIA_HEADER:
1407         case CRITERIA_HEADERS_PART:
1408         case CRITERIA_BODY_PART:
1409         case CRITERIA_MESSAGE:
1410         case CRITERIA_TAG:
1411         case CRITERIA_TAGGED:
1412         case CRITERIA_TEST:
1413                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo));
1414         case CRITERIA_FOUND_IN_ADDRESSBOOK:
1415         case CRITERIA_UNREAD:
1416         case CRITERIA_NEW:
1417         case CRITERIA_MARKED:
1418         case CRITERIA_DELETED:
1419         case CRITERIA_REPLIED:
1420         case CRITERIA_FORWARDED:
1421         case CRITERIA_LOCKED:
1422         case CRITERIA_SPAM:
1423         case CRITERIA_HAS_ATTACHMENT:
1424         case CRITERIA_SIGNED:
1425         case CRITERIA_COLORLABEL:
1426                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo2));
1427         case CRITERIA_WATCH_THREAD:
1428                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.criteria_combo2)) - 2;
1429         case CRITERIA_IGNORE_THREAD:
1430         case CRITERIA_PARTIAL:
1431                 return gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.criteria_combo2));
1432         }
1433         
1434         return 0;
1435 }
1436
1437 /*!
1438  *\brief        Converts the text in the selected row to a 
1439  *              matcher structure
1440  *
1441  *\return       MatcherProp * Newly allocated matcher structure.
1442  */
1443 static MatcherProp *prefs_matcher_dialog_to_matcher(void)
1444 {
1445         MatcherProp *matcherprop;
1446         gint criteria;
1447         gint matchtype;
1448         gint value_pred;
1449         gint value_criteria = prefs_matcher_get_criteria();
1450         gboolean use_regexp;
1451         gboolean case_sensitive;
1452         const gchar *header;
1453         const gchar *expr;
1454         gint value, sel;
1455
1456         if (value_criteria == -1)
1457                 return NULL;
1458
1459 #ifndef G_OS_WIN32
1460         use_regexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn));
1461 #else
1462         use_regexp = FALSE;
1463 #endif
1464         case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn));
1465
1466         if (use_regexp) {
1467                 if (case_sensitive)
1468                         matchtype = MATCHTYPE_REGEXP;
1469                 else
1470                         matchtype = MATCHTYPE_REGEXPCASE;
1471         }
1472         else {
1473                 if (case_sensitive)
1474                         matchtype = MATCHTYPE_MATCH;
1475                 else
1476                         matchtype = MATCHTYPE_MATCHCASE;
1477         }
1478
1479         header = NULL;
1480         expr = NULL;
1481         value = 0;
1482
1483         switch (value_criteria) {
1484         case CRITERIA_ALL:
1485         case CRITERIA_UNREAD:
1486         case CRITERIA_NEW:
1487         case CRITERIA_MARKED:
1488         case CRITERIA_DELETED:
1489         case CRITERIA_REPLIED:
1490         case CRITERIA_FORWARDED:
1491         case CRITERIA_LOCKED:
1492         case CRITERIA_SPAM:
1493         case CRITERIA_HAS_ATTACHMENT:
1494         case CRITERIA_SIGNED:
1495         case CRITERIA_PARTIAL:
1496         case CRITERIA_IGNORE_THREAD:
1497         case CRITERIA_WATCH_THREAD:
1498         case CRITERIA_TAGGED:
1499                 break;
1500
1501         case CRITERIA_SUBJECT:
1502         case CRITERIA_FROM:
1503         case CRITERIA_TO:
1504         case CRITERIA_CC:
1505         case CRITERIA_TO_OR_CC:
1506         case CRITERIA_TAG:
1507         case CRITERIA_NEWSGROUPS:
1508         case CRITERIA_INREPLYTO:
1509         case CRITERIA_REFERENCES:
1510         case CRITERIA_HEADERS_PART:
1511         case CRITERIA_BODY_PART:
1512         case CRITERIA_MESSAGE:
1513                 expr = gtk_entry_get_text(GTK_ENTRY(matcher.string_entry));
1514                 
1515                 if(*expr == '\0') {
1516                         alertpanel_error(_("Search pattern is not set."));
1517                         return NULL;
1518                 }
1519                 break;
1520
1521         case CRITERIA_TEST:
1522                 expr = gtk_entry_get_text(GTK_ENTRY(matcher.string_entry));
1523                 
1524                 if(*expr == '\0') {
1525                         alertpanel_error(_("Test command is not set."));
1526                         return NULL;
1527                 }
1528                 break;
1529
1530         case CRITERIA_AGE_GREATER:
1531         case CRITERIA_AGE_LOWER:
1532                 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
1533                                                          matcher.numeric_entry));
1534                 sel = gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo2));
1535                 if(sel == AGE_WEEKS)
1536                         value *= 7;
1537                 else if (sel == AGE_HOURS) {
1538                         if (value_criteria == CRITERIA_AGE_GREATER)
1539                                 value_criteria = CRITERIA_AGE_GREATER_HOURS;
1540                         else 
1541                                 value_criteria = CRITERIA_AGE_LOWER_HOURS;
1542                 }
1543                 break;
1544                         
1545         case CRITERIA_SCORE_GREATER:
1546         case CRITERIA_SCORE_LOWER:
1547         case CRITERIA_SCORE_EQUAL:
1548                 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
1549                                                          matcher.numeric_entry));
1550                 break;
1551                                                          
1552         case CRITERIA_SIZE_GREATER:
1553         case CRITERIA_SIZE_SMALLER:
1554         case CRITERIA_SIZE_EQUAL:
1555                 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
1556                                                          matcher.numeric_entry));
1557                 sel = gtk_combo_box_get_active(GTK_COMBO_BOX(matcher.match_combo2));
1558                 if(sel == SIZE_UNIT_MBYTES)
1559                         value *= MB_SIZE;
1560                 if(sel == SIZE_UNIT_KBYTES)
1561                         value *= KB_SIZE;
1562                 break;
1563                 
1564 #if !GTK_CHECK_VERSION(3, 0, 0)
1565         case CRITERIA_COLORLABEL:
1566                 value = colorlabel_get_color_menu_active_item
1567                         (gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU
1568                                 (matcher.color_optmenu))); 
1569                 break;
1570 #endif
1571
1572         case CRITERIA_HEADER:
1573                 header = gtk_entry_get_text(GTK_ENTRY(matcher.header_entry));
1574                 expr = gtk_entry_get_text(GTK_ENTRY(matcher.string_entry));
1575
1576                 if (*header == '\0') {
1577                     alertpanel_error(_("Header name is not set."));
1578                     return NULL;
1579                 }
1580                 
1581                 if(*expr == '\0') {
1582                         alertpanel_error(_("Search pattern is not set."));
1583                         return NULL;
1584                 } 
1585                 break;
1586
1587         case CRITERIA_FOUND_IN_ADDRESSBOOK:
1588                 header = gtk_entry_get_text(GTK_ENTRY(matcher.header_addr_entry));
1589                 expr = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))));
1590
1591                 if (*header == '\0') {
1592                     alertpanel_error(_("Header name is not set."));
1593                     return NULL;
1594                 }
1595                 if (*expr == '\0') {
1596                         gchar *tmp;
1597
1598                         if (g_utf8_collate(header, C_("Filtering Matcher Menu", "All")) == 0)
1599                                 tmp = g_strdup(_("all addresses in all headers"));
1600                         else
1601                         if (g_utf8_collate(header, _("Any")) == 0)
1602                                 tmp = g_strdup(_("any address in any header"));
1603                         else
1604                                 tmp = g_strdup_printf(_("the address(es) in header '%s'"), header);
1605                         alertpanel_error(_("Book/folder path is not set.\n\n"
1606                                                 "If you want to match %s against the whole address book, "
1607                                                 "you have to select '%s' from the book/folder drop-down list."),
1608                                                 tmp, _("Any"));
1609                         g_free(tmp);
1610                     return NULL;
1611                 }
1612                 /* store UNtranslated "Any"/"All" in matcher expressions */
1613                 if (g_utf8_collate(header, C_("Filtering Matcher Menu", "All")) == 0)
1614                         header = "All";
1615                 else
1616                         if (g_utf8_collate(header, _("Any")) == 0)
1617                                 header = "Any";
1618                 if (g_utf8_collate(expr, _("Any")) == 0)
1619                         expr = "Any";
1620                 break;
1621         }
1622
1623         criteria = prefs_matcher_get_matching_from_criteria(value_criteria);
1624
1625         value_pred = prefs_matcher_get_pred(value_criteria);
1626         if(value_pred)
1627                 criteria = prefs_matcher_not_criteria(criteria);
1628
1629         matcherprop = matcherprop_new(criteria, header, matchtype,
1630                                       expr, value);
1631
1632         return matcherprop;
1633 }
1634
1635 /*!
1636  *\brief        Signal handler for register button
1637  */
1638 static void prefs_matcher_register_cb(void)
1639 {
1640         MatcherProp *matcherprop;
1641         
1642         matcherprop = prefs_matcher_dialog_to_matcher();
1643         if (matcherprop == NULL)
1644                 return;
1645
1646         prefs_matcher_list_view_set_row(NULL, matcherprop);
1647
1648         matcherprop_free(matcherprop);
1649         
1650         prefs_matcher_reset_condition();
1651 }
1652
1653 /*!
1654  *\brief        Signal handler for substitute button
1655  */
1656 static void prefs_matcher_substitute_cb(void)
1657 {
1658         MatcherProp *matcherprop;
1659         GtkTreeIter row;
1660         GtkTreeSelection *selection;
1661         GtkTreeModel *model;
1662         gboolean is_valid;
1663
1664         selection = gtk_tree_view_get_selection
1665                         (GTK_TREE_VIEW(matcher.cond_list_view));
1666         
1667         if (!gtk_tree_selection_get_selected(selection, &model, &row))
1668                 return;
1669         
1670         gtk_tree_model_get(model, &row, 
1671                            PREFS_MATCHER_COND_VALID, &is_valid,
1672                            -1);
1673         if (!is_valid)
1674                 return;
1675
1676         matcherprop = prefs_matcher_dialog_to_matcher();
1677         if (matcherprop == NULL)
1678                 return;
1679
1680         prefs_matcher_list_view_set_row(&row, matcherprop);
1681
1682         matcherprop_free(matcherprop);
1683 }
1684
1685 /*!
1686  *\brief        Signal handler for delete button
1687  */
1688 static void prefs_matcher_delete_cb(void)
1689 {
1690         GtkTreeIter row;
1691         GtkTreeSelection *selection;
1692         GtkTreeModel *model;
1693         gboolean is_valid;
1694
1695         selection = gtk_tree_view_get_selection
1696                         (GTK_TREE_VIEW(matcher.cond_list_view));
1697         
1698         if (!gtk_tree_selection_get_selected(selection, &model, &row))
1699                 return;
1700                 
1701         gtk_tree_model_get(model, &row, 
1702                            PREFS_MATCHER_COND_VALID, &is_valid,
1703                            -1);
1704
1705         if (!is_valid)
1706                 return;
1707
1708         gtk_list_store_remove(GTK_LIST_STORE(model), &row);             
1709
1710         prefs_matcher_reset_condition();
1711 }
1712
1713 /*!
1714  *\brief        Signal handler for 'move up' button
1715  */
1716 static void prefs_matcher_up(void)
1717 {
1718         GtkTreePath *prev, *sel, *try;
1719         GtkTreeIter isel;
1720         GtkListStore *store = NULL;
1721         GtkTreeModel *model = NULL;
1722         GtkTreeIter iprev;
1723         
1724         if (!gtk_tree_selection_get_selected
1725                 (gtk_tree_view_get_selection
1726                         (GTK_TREE_VIEW(matcher.cond_list_view)),
1727                  &model,        
1728                  &isel))
1729                 return;
1730         store = (GtkListStore *)model;
1731         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1732         if (!sel)
1733                 return;
1734         
1735         /* no move if we're at row 0 or 1, looks phony, but other
1736          * solutions are more convoluted... */
1737         try = gtk_tree_path_copy(sel);
1738         if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1739                 gtk_tree_path_free(try);
1740                 gtk_tree_path_free(sel);
1741                 return;
1742         }
1743         gtk_tree_path_free(try);
1744
1745         prev = gtk_tree_path_copy(sel);         
1746         if (gtk_tree_path_prev(prev)) {
1747                 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1748                                         &iprev, prev);
1749                 gtk_list_store_swap(store, &iprev, &isel);
1750                 /* XXX: GTK2 select row?? */
1751         }
1752
1753         gtk_tree_path_free(sel);
1754         gtk_tree_path_free(prev);
1755 }
1756
1757 /*!
1758  *\brief        Signal handler for 'move down' button
1759  */
1760 static void prefs_matcher_down(void)
1761 {
1762         GtkListStore *store = NULL;
1763         GtkTreeModel *model = NULL;
1764         GtkTreeIter next, sel;
1765         GtkTreePath *try;
1766         
1767         if (!gtk_tree_selection_get_selected
1768                 (gtk_tree_view_get_selection
1769                         (GTK_TREE_VIEW(matcher.cond_list_view)),
1770                  &model,
1771                  &sel))
1772                 return;
1773         store = (GtkListStore *)model;
1774         try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1775         if (!try) 
1776                 return;
1777         
1778         /* move when not at row 0 ... */
1779         if (gtk_tree_path_prev(try)) {
1780                 next = sel;
1781                 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1782                         gtk_list_store_swap(store, &next, &sel);
1783         }
1784                 
1785         gtk_tree_path_free(try);
1786 }
1787
1788 static void prefs_matcher_enable_widget(GtkWidget* widget, const gboolean enable)
1789 {
1790         cm_return_if_fail(widget != NULL);
1791
1792         if(enable == TRUE) {
1793                 gtk_widget_set_sensitive(widget, TRUE);
1794                 gtk_widget_show(widget);        
1795         } else {
1796                 gtk_widget_set_sensitive(widget, FALSE);
1797                 gtk_widget_hide(widget);
1798         }
1799 }
1800
1801 static void prefs_matcher_set_model(GtkWidget *widget, GtkTreeModel *model)
1802 {
1803         cm_return_if_fail(widget != NULL);
1804         cm_return_if_fail(model != NULL);
1805         
1806         gtk_combo_box_set_model(GTK_COMBO_BOX(widget), model);
1807         gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1808 }
1809
1810 static void prefs_matcher_second_criteria_sel(GtkWidget *widget,
1811                                               gpointer user_data)
1812 {
1813         gint criteria = gtk_combo_box_get_active(GTK_COMBO_BOX(
1814                                                 matcher.criteria_combo));
1815         gint criteria2 = combobox_get_active_data(GTK_COMBO_BOX(
1816                                                 matcher.criteria_combo2));
1817         
1818         if(criteria != MATCH_PHRASE && criteria != MATCH_TAGS) return;
1819         
1820         if(criteria == MATCH_PHRASE) {
1821                 switch(criteria2) {
1822                 case CRITERIA_HEADERS_PART:
1823                         gtk_label_set_text(GTK_LABEL(matcher.match_label),
1824                                         _("Headers part"));
1825                         break;
1826                 case CRITERIA_BODY_PART:
1827                         gtk_label_set_text(GTK_LABEL(matcher.match_label),
1828                                         _("Body part"));
1829                         break;  
1830                 case CRITERIA_MESSAGE:
1831                         gtk_label_set_text(GTK_LABEL(matcher.match_label),
1832                                         _("Whole message"));
1833                         break;
1834                 }
1835         }
1836         
1837         if(criteria == MATCH_TAGS) {
1838                 if(criteria2 == CRITERIA_TAGGED) {
1839                         prefs_matcher_enable_widget(matcher.upper_filler, FALSE);
1840                         prefs_matcher_enable_widget(matcher.match_label2, TRUE);
1841                         prefs_matcher_enable_widget(matcher.string_entry, FALSE);
1842                         prefs_matcher_enable_widget(matcher.case_checkbtn, FALSE);
1843 #ifndef G_OS_WIN32
1844                         prefs_matcher_enable_widget(matcher.regexp_checkbtn, FALSE);
1845 #endif
1846                 } else {
1847                         prefs_matcher_enable_widget(matcher.upper_filler, TRUE);
1848                         prefs_matcher_enable_widget(matcher.match_label2, FALSE);
1849                         prefs_matcher_enable_widget(matcher.string_entry, TRUE);
1850                         prefs_matcher_enable_widget(matcher.case_checkbtn, TRUE);
1851 #ifndef G_OS_WIN32
1852                         prefs_matcher_enable_widget(matcher.regexp_checkbtn, TRUE);
1853                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
1854                                                 matcher.regexp_checkbtn), FALSE);
1855 #endif
1856                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
1857                                                 matcher.case_checkbtn), FALSE);
1858                 }
1859         }
1860 }
1861
1862 #define MATCH_COMBO_IS_ENABLED(x) (x != MATCH_ALL && x != MATCH_ABOOK && \
1863                 x != MATCH_PARTIAL && x != MATCH_THREAD && x != MATCH_LABEL) ? TRUE : FALSE
1864 #define MATCH_CASE_REGEXP(x) (x == MATCH_HEADER || x == MATCH_PHRASE) ? TRUE : FALSE 
1865 #define MATCH_NUMERIC(x) (x == MATCH_AGE || x == MATCH_SCORE || \
1866                           x == MATCH_SIZE) ? TRUE : FALSE
1867
1868 /*!
1869  *\brief        Change widgets depending on the selected condition
1870  *
1871  *\param        criteria combo widget
1872  *\param        user_data Not used      
1873  */
1874 static void prefs_matcher_criteria_select(GtkWidget *widget,
1875                                           gpointer user_data)
1876 {
1877         gint value, old_value;
1878
1879         old_value = matcher.selected_criteria;
1880         matcher.selected_criteria = value = gtk_combo_box_get_active
1881                 (GTK_COMBO_BOX(matcher.criteria_combo));
1882
1883         if (old_value == matcher.selected_criteria)
1884                 return;
1885
1886         prefs_matcher_enable_widget(matcher.criteria_label2,
1887                                     (value == MATCH_ABOOK   ||
1888                                      value == MATCH_PHRASE  ||
1889                                      value == MATCH_HEADER  ||
1890                                      value == MATCH_PARTIAL ||
1891                                      value == MATCH_TAGS    ||
1892                                      value == MATCH_THREAD));
1893         prefs_matcher_enable_widget(matcher.headers_combo,
1894                                     (value == MATCH_HEADER));
1895         prefs_matcher_enable_widget(matcher.criteria_combo2,
1896                                     (value == MATCH_PHRASE  ||
1897                                      value == MATCH_PARTIAL ||
1898                                      value == MATCH_TAGS    ||
1899                                      value == MATCH_THREAD));
1900         prefs_matcher_enable_widget(matcher.match_combo2,
1901                                     (value == MATCH_ABOOK ||
1902                                      value == MATCH_AGE   ||
1903                                      value == MATCH_FLAG  ||
1904                                      value == MATCH_LABEL ||
1905                                      value == MATCH_SIZE));
1906         prefs_matcher_enable_widget(matcher.match_label2,
1907                                     (value == MATCH_ABOOK ||
1908                                      value == MATCH_FLAG  ||
1909                                      value == MATCH_LABEL ||
1910                                      value == MATCH_TAGS));
1911         prefs_matcher_enable_widget(matcher.header_addr_combo,
1912                                     (value == MATCH_ABOOK));
1913         prefs_matcher_enable_widget(matcher.string_entry,
1914                                     (MATCH_CASE_REGEXP(value) ||
1915                                      value == MATCH_TEST));
1916         prefs_matcher_enable_widget(matcher.numeric_entry,
1917                                     MATCH_NUMERIC(value));
1918         prefs_matcher_enable_widget(matcher.numeric_label,
1919                                     (value == MATCH_SCORE));
1920         prefs_matcher_enable_widget(matcher.addressbook_folder_combo,
1921                                     (value == MATCH_ABOOK));
1922         prefs_matcher_enable_widget(matcher.match_combo,
1923                                     MATCH_COMBO_IS_ENABLED(value));
1924         prefs_matcher_enable_widget(matcher.case_checkbtn,
1925                                     MATCH_CASE_REGEXP(value));
1926 #ifndef G_OS_WIN32
1927         prefs_matcher_enable_widget(matcher.regexp_checkbtn,
1928                                     MATCH_CASE_REGEXP(value));
1929 #endif
1930         prefs_matcher_enable_widget(matcher.test_btn,
1931                                     (value == MATCH_TEST));
1932         prefs_matcher_enable_widget(matcher.addressbook_select_btn,
1933                                     (value == MATCH_ABOOK));
1934 #if !GTK_CHECK_VERSION(3, 0, 0)
1935         prefs_matcher_enable_widget(matcher.color_optmenu,
1936                                     (value == MATCH_LABEL));
1937 #endif
1938         prefs_matcher_enable_widget(matcher.upper_filler,
1939                                     MATCH_CASE_REGEXP(value));
1940         prefs_matcher_enable_widget(matcher.lower_filler,
1941                                     (value == MATCH_ABOOK));
1942                                 
1943         gtk_label_set_text(GTK_LABEL(matcher.match_label), "");
1944         gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), "");
1945
1946         switch(value) {
1947         case MATCH_ABOOK:
1948                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.header_addr_combo), 0);  
1949                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.addressbook_folder_combo), 0);
1950                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_found);
1951                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("in"));
1952                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Header"));
1953                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("content is"));
1954                 break;
1955         case MATCH_AGE:
1956                 prefs_matcher_set_model(matcher.match_combo, matcher.model_age);
1957                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_age_units);
1958                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(
1959                                   matcher.numeric_entry), 0, 1000);
1960                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
1961                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2), AGE_DAYS);
1962                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Age is"));
1963                 break;
1964         case MATCH_FLAG:
1965                 prefs_matcher_set_model(matcher.match_combo, matcher.model_flags);
1966                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_set);
1967                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Flag"));
1968                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("is"));
1969                 break;
1970         case MATCH_HEADER:
1971                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.headers_combo), 0);
1972                 prefs_matcher_set_model(matcher.match_combo, matcher.model_contain);
1973                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("Name:"));
1974                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Header"));
1975 #ifndef G_OS_WIN32
1976                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
1977 #endif
1978                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
1979                 break;
1980 #if !GTK_CHECK_VERSION(3, 0, 0)
1981         case MATCH_LABEL:
1982                 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(matcher.color_optmenu), 0);
1983                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_set);
1984                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Label"));
1985                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("is"));
1986                 break;
1987 #endif
1988         case MATCH_PARTIAL:
1989                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_partial);
1990                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("Value:"));
1991                 break;
1992         case MATCH_PHRASE:
1993                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_phrase);
1994                 prefs_matcher_set_model(matcher.match_combo, matcher.model_contain);
1995                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("in"));
1996 #ifndef G_OS_WIN32
1997                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
1998 #endif
1999                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
2000                 prefs_matcher_second_criteria_sel(NULL, NULL);
2001                 break;  
2002         case MATCH_SCORE:
2003                 prefs_matcher_set_model(matcher.match_combo, matcher.model_score);
2004                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(
2005                                           matcher.numeric_entry), -1000, 1000);
2006                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
2007                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Score is"));
2008                 gtk_label_set_text(GTK_LABEL(matcher.numeric_label), _("points"));
2009                 break;  
2010         case MATCH_SIZE:
2011                 prefs_matcher_set_model(matcher.match_combo, matcher.model_size);
2012                 prefs_matcher_set_model(matcher.match_combo2, matcher.model_size_units);
2013                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2014                                          SIZE_UNIT_KBYTES);
2015                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(
2016                                           matcher.numeric_entry), 0, 100000);
2017                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
2018                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Size is"));
2019                 break;
2020         case MATCH_TAGS:
2021                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_tags);
2022                 prefs_matcher_set_model(matcher.match_combo, matcher.model_contain);
2023                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("Scope:"));
2024                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Message"));
2025                 gtk_label_set_text(GTK_LABEL(matcher.match_label2), _("tags"));
2026                 prefs_matcher_second_criteria_sel(NULL, NULL);
2027                 break;
2028         case MATCH_THREAD:
2029                 prefs_matcher_set_model(matcher.criteria_combo2, matcher.model_thread);
2030                 gtk_label_set_text(GTK_LABEL(matcher.criteria_label2), _("type is"));
2031                 break;
2032         case MATCH_TEST:
2033                 prefs_matcher_set_model(matcher.match_combo, matcher.model_test);
2034                 gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Program returns"));
2035                 break;
2036         }       
2037 }
2038
2039 /*!
2040  *\brief        Handle key press
2041  *
2042  *\param        widget Widget receiving key press
2043  *\param        event Key event
2044  *\param        data User data
2045  */
2046 static gboolean prefs_matcher_key_pressed(GtkWidget *widget, GdkEventKey *event,
2047                                      gpointer data)
2048 {
2049         if (event && event->keyval == GDK_KEY_Escape) {
2050                 prefs_matcher_cancel();
2051                 return TRUE;            
2052         }
2053         return FALSE;
2054 }
2055
2056 /*!
2057  *\brief        Cancel matcher dialog
2058  */
2059 static void prefs_matcher_cancel(void)
2060 {
2061         gtk_widget_hide(matcher.window);
2062         gtk_window_set_modal(GTK_WINDOW(matcher.window), FALSE);
2063         inc_unlock();
2064 }
2065
2066 /*!
2067  *\brief        Accept current matchers
2068  */
2069 static void prefs_matcher_ok(void)
2070 {
2071         MatcherList *matchers;
2072         MatcherProp *matcherprop;
2073         AlertValue val;
2074         gchar *matcher_str = NULL;
2075         gchar *str = NULL;
2076         gint row = 1;
2077         GtkTreeModel *model;
2078         GtkTreeIter iter;
2079
2080         matchers = prefs_matcher_get_list();
2081
2082         if (matchers != NULL) {
2083                 matcherprop = prefs_matcher_dialog_to_matcher();
2084                 if (matcherprop != NULL) {
2085                         str = matcherprop_to_string(matcherprop);
2086                         matcherprop_free(matcherprop);
2087                         if (strcmp(str, "all") != 0) {
2088                                 model = gtk_tree_view_get_model(GTK_TREE_VIEW
2089                                                 (matcher.cond_list_view));
2090
2091                                 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
2092                                         gtk_tree_model_get(model, &iter,
2093                                                            PREFS_MATCHER_COND, &matcher_str,
2094                                                            -1);
2095                                         if (matcher_str && strcmp(matcher_str, str) == 0) 
2096                                                 break;
2097                                         row++;
2098                                         g_free(matcher_str);
2099                                         matcher_str = NULL;
2100                                 }
2101
2102                                 if (!matcher_str || strcmp(matcher_str, str) != 0) {
2103                                         val = alertpanel(_("Entry not saved"),
2104                                                  _("The entry was not saved.\nClose anyway?"),
2105                                                  GTK_STOCK_CLOSE, _("+_Continue editing"), NULL);
2106                                         if (G_ALERTDEFAULT != val) {
2107                                                 g_free(matcher_str);                                             
2108                                                 g_free(str);
2109                                                 return;
2110                                         }
2111                                 }
2112                                 g_free(matcher_str);
2113                         }
2114                 }
2115                 g_free(str);
2116                 gtk_widget_hide(matcher.window);
2117                 gtk_window_set_modal(GTK_WINDOW(matcher.window), FALSE);
2118                 if (matchers_callback != NULL)
2119                         matchers_callback(matchers);
2120                 matcherlist_free(matchers);
2121         }
2122         inc_unlock();
2123 }
2124
2125 /*!
2126  *\brief        Called when closing dialog box
2127  *
2128  *\param        widget Dialog widget
2129  *\param        event Event info
2130  *\param        data User data
2131  *
2132  *\return       gint TRUE
2133  */
2134 static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
2135                                   gpointer data)
2136 {
2137         prefs_matcher_cancel();
2138         return TRUE;
2139 }
2140
2141 /*
2142  * Strings describing test format strings
2143  * 
2144  * When adding new lines, remember to put 2 strings for each line
2145  */
2146 static gchar *test_desc_strings[] = {
2147         "%%",   N_("literal %"),
2148         "%s",   N_("Subject"),
2149         "%f",   N_("From"),
2150         "%t",   N_("To"),
2151         "%c",   N_("Cc"),
2152         "%d",   N_("Date"),
2153         "%i",   N_("Message-ID"),
2154         "%n",   N_("Newsgroups"),
2155         "%r",   N_("References"),
2156         "%F",   N_("filename (should not be modified)"),
2157         "\\n",  N_("new line"),
2158         "\\",   N_("escape character for quotes"),
2159         "\\\"", N_("quote character"),
2160         NULL,   NULL
2161 };
2162
2163 static DescriptionWindow test_desc_win = { 
2164         NULL,
2165         NULL, 
2166         TRUE,
2167         2,
2168         N_("Match Type: 'Test'"),
2169         N_("'Test' allows you to test a message or message element "
2170            "using an external program or script. The program will "
2171            "return either 0 or 1.\n\n"
2172            "The following symbols can be used:"),
2173         test_desc_strings
2174 };
2175
2176
2177
2178 /*!
2179  *\brief        Show Test action's info
2180  */
2181 static void prefs_matcher_test_info(GtkWidget *widget, GtkWidget *parent)
2182 {
2183         test_desc_win.parent = parent;
2184         description_window_create(&test_desc_win);
2185 }
2186
2187 #ifndef USE_NEW_ADDRBOOK
2188 static void prefs_matcher_addressbook_select(void)
2189 {
2190         const gchar *folderpath = NULL;
2191         gchar *new_path = NULL;
2192
2193         folderpath = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))));
2194         new_path = addressbook_folder_selection(folderpath);
2195         if (new_path) {
2196                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))), new_path);
2197                 g_free(new_path);
2198         } 
2199 }
2200 #endif
2201
2202 /*
2203  * list view
2204  */
2205
2206 static GtkListStore* prefs_matcher_create_data_store(void)
2207 {
2208         return gtk_list_store_new(N_PREFS_MATCHER_COLUMNS,
2209                                   G_TYPE_STRING,        
2210                                   G_TYPE_BOOLEAN,
2211                                   -1);
2212 }
2213
2214 static void prefs_matcher_list_view_insert_matcher(GtkWidget *list_view,
2215                                                    GtkTreeIter *row_iter,
2216                                                    const gchar *matcher,
2217                                                    gboolean is_valid) 
2218 {
2219         GtkTreeIter iter;
2220         GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model
2221                                         (GTK_TREE_VIEW(list_view)));
2222
2223         if (row_iter == NULL) {
2224                 /* append new */
2225                 gtk_list_store_append(list_store, &iter);
2226         } else {
2227                 /* change existing */
2228                 iter = *row_iter;
2229         }
2230
2231         gtk_list_store_set(list_store, &iter,
2232                            PREFS_MATCHER_COND, matcher,
2233                            PREFS_MATCHER_COND_VALID, is_valid,
2234                            -1);
2235 }
2236
2237 static GtkWidget *prefs_matcher_list_view_create(void)
2238 {
2239         GtkTreeView *list_view;
2240         GtkTreeSelection *selector;
2241         GtkTreeModel *model;
2242
2243         model = GTK_TREE_MODEL(prefs_matcher_create_data_store());
2244         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
2245         g_object_unref(model);  
2246         
2247         gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
2248         gtk_tree_view_set_reorderable(list_view, TRUE);
2249         
2250         selector = gtk_tree_view_get_selection(list_view);
2251         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
2252         gtk_tree_selection_set_select_function(selector, prefs_matcher_selected,
2253                                                NULL, NULL);
2254
2255         /* create the columns */
2256         prefs_matcher_create_list_view_columns(GTK_WIDGET(list_view));
2257
2258         return GTK_WIDGET(list_view);
2259 }
2260
2261 static void prefs_matcher_create_list_view_columns(GtkWidget *list_view)
2262 {
2263         GtkTreeViewColumn *column;
2264         GtkCellRenderer *renderer;
2265
2266         renderer = gtk_cell_renderer_text_new();
2267         column = gtk_tree_view_column_new_with_attributes
2268                 (_("Current condition rules"),
2269                  renderer,
2270                  "text", PREFS_MATCHER_COND,
2271                  NULL);
2272         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
2273 }
2274
2275 static void prefs_matcher_set_criteria(const gint criteria)
2276 {
2277         gint match_criteria = 0;
2278         
2279         switch (criteria) {
2280         case CRITERIA_FOUND_IN_ADDRESSBOOK:
2281                 match_criteria = MATCH_ABOOK;
2282                 break;  
2283         case CRITERIA_ALL:
2284                 match_criteria = MATCH_ALL;
2285                 break;
2286         case CRITERIA_AGE_GREATER:
2287         case CRITERIA_AGE_LOWER:
2288         case CRITERIA_AGE_GREATER_HOURS:
2289         case CRITERIA_AGE_LOWER_HOURS:
2290                 match_criteria = MATCH_AGE;
2291                 break;
2292         case CRITERIA_SCORE_GREATER:
2293         case CRITERIA_SCORE_LOWER:
2294         case CRITERIA_SCORE_EQUAL:
2295                 match_criteria = MATCH_SCORE;
2296                 break;
2297         case CRITERIA_SIZE_GREATER:
2298         case CRITERIA_SIZE_SMALLER:
2299         case CRITERIA_SIZE_EQUAL:
2300                 match_criteria = MATCH_SIZE;
2301                 break;
2302         case CRITERIA_SUBJECT:
2303         case CRITERIA_FROM:
2304         case CRITERIA_TO:
2305         case CRITERIA_CC:
2306         case CRITERIA_TO_OR_CC:
2307         case CRITERIA_NEWSGROUPS:
2308         case CRITERIA_INREPLYTO:
2309         case CRITERIA_REFERENCES:
2310         case CRITERIA_HEADER:
2311                 match_criteria = MATCH_HEADER;
2312                 break;
2313         case CRITERIA_HEADERS_PART:
2314         case CRITERIA_BODY_PART:
2315         case CRITERIA_MESSAGE:
2316                 match_criteria = MATCH_PHRASE;
2317                 break;
2318         case CRITERIA_TEST:
2319                 match_criteria = MATCH_TEST;
2320                 break;
2321 #if !GTK_CHECK_VERSION(3, 0, 0)
2322         case CRITERIA_COLORLABEL:
2323                 match_criteria = MATCH_LABEL;
2324                 break;
2325 #endif
2326         case CRITERIA_TAG:
2327         case CRITERIA_TAGGED:
2328                 match_criteria = MATCH_TAGS;
2329                 break;
2330         case CRITERIA_UNREAD:
2331         case CRITERIA_NEW:
2332         case CRITERIA_MARKED:
2333         case CRITERIA_DELETED:
2334         case CRITERIA_REPLIED:
2335         case CRITERIA_FORWARDED:
2336         case CRITERIA_LOCKED:
2337         case CRITERIA_SPAM:
2338         case CRITERIA_HAS_ATTACHMENT:
2339         case CRITERIA_SIGNED:
2340                 match_criteria = MATCH_FLAG;
2341                 break;
2342         case CRITERIA_PARTIAL:
2343                 match_criteria = MATCH_PARTIAL;
2344                 break;
2345         case CRITERIA_IGNORE_THREAD:
2346         case CRITERIA_WATCH_THREAD:
2347                 match_criteria = MATCH_THREAD;
2348                 break;
2349         }
2350         
2351         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo),
2352                                  match_criteria);
2353         
2354         switch(match_criteria) {
2355         case MATCH_HEADER:
2356                 if(criteria != CRITERIA_HEADER)
2357                         combobox_select_by_data(GTK_COMBO_BOX(
2358                                                 matcher.headers_combo),
2359                                                 criteria);
2360                 break;
2361         case MATCH_AGE:
2362         case MATCH_SCORE:
2363         case MATCH_SIZE:
2364         case MATCH_FLAG:
2365                 combobox_select_by_data(GTK_COMBO_BOX(
2366                                         matcher.match_combo), criteria);
2367                 break;
2368         case MATCH_PHRASE:
2369         case MATCH_TAGS:
2370                 combobox_select_by_data(GTK_COMBO_BOX(
2371                                         matcher.criteria_combo2), criteria);
2372                 break;
2373         }
2374 }
2375
2376 static gboolean prefs_matcher_selected(GtkTreeSelection *selector,
2377                                        GtkTreeModel *model, 
2378                                        GtkTreePath *path,
2379                                        gboolean currently_selected,
2380                                        gpointer data)
2381 {
2382         gchar *matcher_str;
2383         MatcherProp *prop;
2384         gboolean negative_cond;
2385         gint criteria;
2386         GtkWidget *menu;
2387         GtkTreeIter iter;
2388         gboolean is_valid;
2389
2390         if (currently_selected)
2391                 return TRUE;
2392
2393         if (!gtk_tree_model_get_iter(model, &iter, path))
2394                 return TRUE;
2395
2396         gtk_tree_model_get(model, &iter, 
2397                            PREFS_MATCHER_COND_VALID,  &is_valid,
2398                            PREFS_MATCHER_COND, &matcher_str,
2399                            -1);
2400         
2401         if (!is_valid) {
2402                 g_free(matcher_str);
2403                 prefs_matcher_reset_condition();
2404                 return TRUE;
2405         }
2406
2407         negative_cond = FALSE;
2408
2409         prop = matcher_parser_get_prop(matcher_str);
2410         if (prop == NULL) {
2411                 g_free(matcher_str);
2412                 return TRUE;
2413         }               
2414
2415         criteria = prefs_matcher_get_criteria_from_matching(prop->criteria);
2416         prefs_matcher_set_criteria(criteria);
2417
2418         switch(prop->criteria) {
2419         case MATCHCRITERIA_NOT_UNREAD:
2420         case MATCHCRITERIA_NOT_NEW:
2421         case MATCHCRITERIA_NOT_MARKED:
2422         case MATCHCRITERIA_NOT_DELETED:
2423         case MATCHCRITERIA_NOT_REPLIED:
2424         case MATCHCRITERIA_NOT_FORWARDED:
2425         case MATCHCRITERIA_NOT_LOCKED:
2426         case MATCHCRITERIA_NOT_SPAM:
2427         case MATCHCRITERIA_HAS_NO_ATTACHMENT:
2428         case MATCHCRITERIA_NOT_SIGNED:
2429         case MATCHCRITERIA_NOT_PARTIAL:
2430         case MATCHCRITERIA_NOT_COLORLABEL:
2431         case MATCHCRITERIA_NOT_IGNORE_THREAD:
2432         case MATCHCRITERIA_NOT_WATCH_THREAD:
2433         case MATCHCRITERIA_NOT_SUBJECT:
2434         case MATCHCRITERIA_NOT_FROM:
2435         case MATCHCRITERIA_NOT_TO:
2436         case MATCHCRITERIA_NOT_CC:
2437         case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
2438         case MATCHCRITERIA_NOT_TAG:
2439         case MATCHCRITERIA_NOT_TAGGED:
2440         case MATCHCRITERIA_NOT_NEWSGROUPS:
2441         case MATCHCRITERIA_NOT_INREPLYTO:
2442         case MATCHCRITERIA_NOT_REFERENCES:
2443         case MATCHCRITERIA_NOT_HEADER:
2444         case MATCHCRITERIA_NOT_HEADERS_PART:
2445         case MATCHCRITERIA_NOT_MESSAGE:
2446         case MATCHCRITERIA_NOT_BODY_PART:
2447         case MATCHCRITERIA_NOT_TEST:
2448         case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
2449                 negative_cond = TRUE;
2450                 break;
2451         }
2452         
2453         switch(prop->criteria) {
2454         case MATCHCRITERIA_ALL:
2455                 break;
2456
2457         case MATCHCRITERIA_NOT_SUBJECT:
2458         case MATCHCRITERIA_NOT_FROM:
2459         case MATCHCRITERIA_NOT_TO:
2460         case MATCHCRITERIA_NOT_CC:
2461         case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
2462         case MATCHCRITERIA_NOT_TAG:
2463         case MATCHCRITERIA_NOT_NEWSGROUPS:
2464         case MATCHCRITERIA_NOT_INREPLYTO:
2465         case MATCHCRITERIA_NOT_REFERENCES:
2466         case MATCHCRITERIA_NOT_HEADERS_PART:
2467         case MATCHCRITERIA_NOT_BODY_PART:
2468         case MATCHCRITERIA_NOT_MESSAGE:
2469         case MATCHCRITERIA_NOT_TEST:
2470         case MATCHCRITERIA_SUBJECT:
2471         case MATCHCRITERIA_FROM:
2472         case MATCHCRITERIA_TO:
2473         case MATCHCRITERIA_CC:
2474         case MATCHCRITERIA_TO_OR_CC:
2475         case MATCHCRITERIA_TAG:
2476         case MATCHCRITERIA_NEWSGROUPS:
2477         case MATCHCRITERIA_INREPLYTO:
2478         case MATCHCRITERIA_REFERENCES:
2479         case MATCHCRITERIA_HEADERS_PART:
2480         case MATCHCRITERIA_BODY_PART:
2481         case MATCHCRITERIA_MESSAGE:
2482         case MATCHCRITERIA_TEST:
2483                 gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), prop->expr);
2484                 break;
2485
2486         case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
2487         case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
2488         {
2489                 gchar *header;
2490                 gchar *expr;
2491
2492                 /* matcher expressions contain UNtranslated "Any"/"All",
2493                   select the relevant translated combo item */
2494                 if (strcasecmp(prop->header, "All") == 0)
2495                         header = (gchar*)C_("Filtering Matcher Menu", "All");
2496                 else
2497                         if (strcasecmp(prop->header, "Any") == 0)
2498                                 header = _("Any");
2499                         else
2500                                 header = prop->header;
2501                 if (strcasecmp(prop->expr, "Any") == 0)
2502                         expr = _("Any");
2503                 else
2504                         expr = prop->expr;
2505
2506                 gtk_entry_set_text(GTK_ENTRY(matcher.header_addr_entry), header);
2507                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((matcher.addressbook_folder_combo)))), expr);
2508                 break;
2509         }
2510
2511         case MATCHCRITERIA_AGE_GREATER:
2512         case MATCHCRITERIA_AGE_LOWER:
2513                 if(prop->value >= 7 && !(prop->value % 7)) {
2514                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2515                                                  AGE_WEEKS);
2516                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2517                                         matcher.numeric_entry), prop->value/7);
2518                 } else {
2519                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2520                                                  AGE_DAYS);
2521                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2522                                         matcher.numeric_entry), prop->value);
2523                 }
2524                 break;
2525                 
2526         case MATCHCRITERIA_AGE_GREATER_HOURS:
2527         case MATCHCRITERIA_AGE_LOWER_HOURS:
2528                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2529                                          AGE_HOURS);
2530                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2531                                 matcher.numeric_entry), prop->value);
2532                 break;
2533                 
2534         case MATCHCRITERIA_SCORE_GREATER:
2535         case MATCHCRITERIA_SCORE_LOWER:
2536         case MATCHCRITERIA_SCORE_EQUAL:
2537                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry),
2538                                           prop->value);
2539                 break;
2540
2541         case MATCHCRITERIA_SIZE_GREATER:
2542         case MATCHCRITERIA_SIZE_SMALLER:
2543         case MATCHCRITERIA_SIZE_EQUAL:
2544                 if(prop->value >= MB_SIZE && !(prop->value % MB_SIZE)) {
2545                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2546                                                  SIZE_UNIT_MBYTES);
2547                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2548                                         matcher.numeric_entry), prop->value/MB_SIZE);
2549                 } else if(prop->value >= KB_SIZE && !(prop->value % KB_SIZE)) {
2550                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2551                                                  SIZE_UNIT_KBYTES);
2552                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2553                                         matcher.numeric_entry), prop->value/KB_SIZE);
2554                 } else {
2555                         gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2556                                                  SIZE_UNIT_BYTES);
2557                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(
2558                                         matcher.numeric_entry), prop->value);           
2559                 }
2560                 break;
2561
2562 #if !GTK_CHECK_VERSION(3, 0, 0)
2563         case MATCHCRITERIA_NOT_COLORLABEL:
2564         case MATCHCRITERIA_COLORLABEL:
2565                 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(matcher.color_optmenu),
2566                                             prop->value + 1);
2567                 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(matcher.color_optmenu));
2568                 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
2569                 break;
2570 #endif
2571
2572         case MATCHCRITERIA_NOT_HEADER:
2573         case MATCHCRITERIA_HEADER:
2574                 gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), prop->header);
2575                 gtk_entry_set_text(GTK_ENTRY(matcher.string_entry), prop->expr);
2576                 break;
2577         }
2578
2579         switch(criteria) {
2580         case CRITERIA_SUBJECT:
2581         case CRITERIA_FROM:
2582         case CRITERIA_TO:
2583         case CRITERIA_CC:
2584         case CRITERIA_TO_OR_CC:
2585         case CRITERIA_NEWSGROUPS:
2586         case CRITERIA_INREPLYTO:
2587         case CRITERIA_REFERENCES:
2588         case CRITERIA_HEADER:
2589         case CRITERIA_HEADERS_PART:
2590         case CRITERIA_BODY_PART:
2591         case CRITERIA_MESSAGE:
2592         case CRITERIA_TAG:
2593         case CRITERIA_TAGGED:
2594         case CRITERIA_TEST:
2595                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo),
2596                                         negative_cond ? PREDICATE_DOES_NOT_CONTAIN :
2597                                                         PREDICATE_CONTAINS);
2598                 break;
2599         case CRITERIA_FOUND_IN_ADDRESSBOOK:
2600         case CRITERIA_UNREAD:
2601         case CRITERIA_NEW:
2602         case CRITERIA_MARKED:
2603         case CRITERIA_DELETED:
2604         case CRITERIA_REPLIED:
2605         case CRITERIA_FORWARDED:
2606         case CRITERIA_LOCKED:
2607         case CRITERIA_SPAM:
2608         case CRITERIA_HAS_ATTACHMENT:
2609         case CRITERIA_SIGNED:
2610         case CRITERIA_COLORLABEL:
2611                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2),
2612                                          negative_cond ? PREDICATE_FLAG_DISABLED :
2613                                                          PREDICATE_FLAG_ENABLED);
2614                 break;
2615         case CRITERIA_WATCH_THREAD:
2616                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2),
2617                                          negative_cond ? THREAD_NOT_WATCHED :
2618                                                          THREAD_WATCHED);
2619                 break;
2620         case CRITERIA_IGNORE_THREAD:
2621                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2),
2622                                          negative_cond ? THREAD_NOT_IGNORED :
2623                                                          THREAD_IGNORED);
2624                 break;  
2625         case CRITERIA_PARTIAL:
2626                 gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.criteria_combo2),
2627                                          negative_cond ? PREDICATE_FLAG_DISABLED :
2628                                                          PREDICATE_FLAG_ENABLED);
2629                 break;
2630         }
2631
2632         switch(prop->matchtype) {
2633         case MATCHTYPE_MATCH:
2634 #ifndef G_OS_WIN32
2635                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
2636 #endif
2637                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), TRUE);
2638                 break;
2639
2640         case MATCHTYPE_MATCHCASE:
2641 #ifndef G_OS_WIN32
2642                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), FALSE);
2643 #endif
2644                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
2645                 break;
2646
2647         case MATCHTYPE_REGEXP:
2648 #ifndef G_OS_WIN32
2649                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), TRUE);
2650 #endif
2651                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), TRUE);
2652                 break;
2653
2654         case MATCHTYPE_REGEXPCASE:
2655 #ifndef G_OS_WIN32
2656                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_checkbtn), TRUE);
2657 #endif
2658                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_checkbtn), FALSE);
2659                 break;
2660         }
2661
2662         g_free(matcher_str);
2663         return TRUE;
2664 }
2665