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