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