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