fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / summary_search.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/gtk.h>
31 #include "gtk/gtksctree.h"
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "main.h"
37 #include "summary_search.h"
38 #include "summaryview.h"
39 #include "messageview.h"
40 #include "mainwindow.h"
41 #include "menu.h"
42 #include "utils.h"
43 #include "gtkutils.h"
44 #include "combobox.h"
45 #include "prefs_gtk.h"
46 #include "manage_window.h"
47 #include "alertpanel.h"
48 #include "advsearch.h"
49 #include "matcher.h"
50 #include "matcher_parser.h"
51 #include "prefs_matcher.h"
52 #include "manual.h"
53 #include "prefs_common.h"
54 #include "statusbar.h"
55
56 static struct SummarySearchWindow {
57         GtkWidget *window;
58
59         GtkWidget *bool_optmenu;
60
61         GtkWidget *from_label;
62         GtkWidget *from_entry;
63         GtkWidget *to_label;
64         GtkWidget *to_entry;
65         GtkWidget *subject_label;
66         GtkWidget *subject_entry;
67         GtkWidget *body_label;
68         GtkWidget *body_entry;
69
70         GtkWidget *adv_condition_label;
71         GtkWidget *adv_condition_entry;
72         GtkWidget *adv_condition_btn;
73         GtkWidget *adv_search_checkbtn;
74
75         GtkWidget *case_checkbtn;
76
77         GtkWidget *clear_btn;
78         GtkWidget *help_btn;
79         GtkWidget *all_btn;
80         GtkWidget *prev_btn;
81         GtkWidget *next_btn;
82         GtkWidget *close_btn;
83         GtkWidget *stop_btn;
84
85         SummaryView *summaryview;
86
87         AdvancedSearch  *advsearch;
88         gboolean        is_fast;
89         gboolean        matcher_is_outdated;
90         gboolean        search_in_progress;
91         GHashTable      *matched_msgnums;
92
93         gboolean is_searching;
94         gboolean from_entry_has_focus;
95         gboolean to_entry_has_focus;
96         gboolean subject_entry_has_focus;
97         gboolean body_entry_has_focus;
98         gboolean adv_condition_entry_has_focus;
99 } search_window;
100
101 static gchar* add_history_get(GtkWidget *from, GList **history);
102
103 static void summary_search_create       (void);
104
105 static gboolean summary_search_verify_match             (MsgInfo *msg);
106 static gboolean summary_search_prepare_matcher          ();
107 static gboolean summary_search_prereduce_msg_list       ();
108
109 static void summary_search_execute      (gboolean        backward,
110                                          gboolean        search_all);
111
112 static void summary_search_clear        (GtkButton      *button,
113                                          gpointer        data);
114 static void summary_search_prev_clicked (GtkButton      *button,
115                                          gpointer        data);
116 static void summary_search_next_clicked (GtkButton      *button,
117                                          gpointer        data);
118 static void summary_search_all_clicked  (GtkButton      *button,
119                                          gpointer        data);
120 static void summary_search_stop_clicked (GtkButton      *button,
121                                          gpointer        data);
122 static void adv_condition_btn_clicked   (GtkButton      *button,
123                                          gpointer        data);
124
125 static void optmenu_changed                     (GtkComboBox *widget, gpointer user_data);
126 static void from_changed                        (void);
127 static void to_changed                          (void);
128 static void subject_changed                     (void);
129 static void body_changed                        (void);
130 static void adv_condition_changed       (void);
131 static void case_changed                        (GtkToggleButton *togglebutton, gpointer user_data);
132
133 static gboolean from_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
134                                   gpointer data);
135 static gboolean from_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
136                                   gpointer data);
137 static gboolean to_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
138                                   gpointer data);
139 static gboolean to_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
140                                   gpointer data);
141 static gboolean subject_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
142                                   gpointer data);
143 static gboolean subject_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
144                                   gpointer data);
145 static gboolean body_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
146                                   gpointer data);
147 static gboolean body_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
148                                   gpointer data);
149 static gboolean adv_condition_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
150                                   gpointer data);
151 static gboolean adv_condition_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
152                                   gpointer data);
153 static gboolean key_pressed             (GtkWidget      *widget,
154                                          GdkEventKey    *event,
155                                          gpointer        data);
156
157 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) {                                    \
158         gtk_widget_set_sensitive(widget, sensitive);                                    \
159 }
160
161 static gchar* add_history_get(GtkWidget *from, GList **history)
162 {
163         gchar *result;
164
165         result = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(from));
166         if (!result)
167                 result = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(from))), 0, -1);
168
169         if (result && result[0] != '\0') {
170                 /* add to history */
171                 combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(from));
172                 *history = add_history(*history, result);
173                 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(from), *history);
174
175                 return result;
176         } else {
177                 g_free(result);
178                 return NULL;
179         }
180 }
181
182 void summary_search(SummaryView *summaryview)
183 {
184         if (!search_window.window) {
185                 summary_search_create();
186         } else {
187                 gtk_widget_hide(search_window.window);
188         }
189
190         search_window.summaryview = summaryview;
191
192         gtk_widget_grab_focus(search_window.next_btn);
193         gtk_widget_grab_focus(search_window.subject_entry);
194         gtk_widget_show(search_window.window);
195 }
196
197 static void summary_show_stop_button(void)
198 {
199         gtk_widget_hide(search_window.close_btn);
200         gtk_widget_show(search_window.stop_btn);
201         GTK_BUTTON_SET_SENSITIVE(search_window.clear_btn, FALSE)
202         GTK_BUTTON_SET_SENSITIVE(search_window.all_btn, FALSE)
203         GTK_BUTTON_SET_SENSITIVE(search_window.prev_btn, FALSE)
204         GTK_BUTTON_SET_SENSITIVE(search_window.next_btn, FALSE)
205         gtk_widget_set_sensitive(search_window.adv_condition_label, FALSE);
206         gtk_widget_set_sensitive(search_window.adv_condition_entry, FALSE);
207         gtk_widget_set_sensitive(search_window.adv_condition_btn, FALSE);
208         gtk_widget_set_sensitive(search_window.to_label, FALSE);
209         gtk_widget_set_sensitive(search_window.to_entry, FALSE);
210         gtk_widget_set_sensitive(search_window.from_label, FALSE);
211         gtk_widget_set_sensitive(search_window.from_entry, FALSE);
212         gtk_widget_set_sensitive(search_window.subject_label, FALSE);
213         gtk_widget_set_sensitive(search_window.subject_entry, FALSE);
214         gtk_widget_set_sensitive(search_window.body_label, FALSE);
215         gtk_widget_set_sensitive(search_window.body_entry, FALSE);
216         gtk_widget_set_sensitive(search_window.bool_optmenu, FALSE);
217         gtk_widget_set_sensitive(search_window.clear_btn, FALSE);
218         gtk_widget_set_sensitive(search_window.case_checkbtn, FALSE);
219         gtk_widget_set_sensitive(search_window.adv_search_checkbtn, FALSE);
220 }
221
222 static void summary_hide_stop_button(void)
223 {
224         GTK_BUTTON_SET_SENSITIVE(search_window.clear_btn, TRUE)
225         gtk_widget_hide(search_window.stop_btn);
226         gtk_widget_show(search_window.close_btn);
227         if (gtk_toggle_button_get_active
228                         (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn))) {
229                 gtk_widget_set_sensitive(search_window.adv_condition_label, TRUE);
230                 gtk_widget_set_sensitive(search_window.adv_condition_entry, TRUE);
231                 gtk_widget_set_sensitive(search_window.adv_condition_btn, TRUE);
232                 gtk_widget_set_sensitive(search_window.case_checkbtn, FALSE);
233                 gtk_widget_set_sensitive(search_window.bool_optmenu, FALSE);
234         } else {
235                 gtk_widget_set_sensitive(search_window.to_label, TRUE);
236                 gtk_widget_set_sensitive(search_window.to_entry, TRUE);
237                 gtk_widget_set_sensitive(search_window.from_label, TRUE);
238                 gtk_widget_set_sensitive(search_window.from_entry, TRUE);
239                 gtk_widget_set_sensitive(search_window.subject_label, TRUE);
240                 gtk_widget_set_sensitive(search_window.subject_entry, TRUE);
241                 gtk_widget_set_sensitive(search_window.body_label, TRUE);
242                 gtk_widget_set_sensitive(search_window.body_entry, TRUE);
243                 gtk_widget_set_sensitive(search_window.case_checkbtn, TRUE);
244                 gtk_widget_set_sensitive(search_window.bool_optmenu, TRUE);
245         }
246         gtk_widget_set_sensitive(search_window.clear_btn, TRUE);
247         gtk_widget_set_sensitive(search_window.all_btn, TRUE);
248         gtk_widget_set_sensitive(search_window.prev_btn, TRUE);
249         gtk_widget_set_sensitive(search_window.next_btn, TRUE);
250         gtk_widget_set_sensitive(search_window.adv_search_checkbtn, TRUE);
251 }
252
253 static void summary_search_create(void)
254 {
255         GtkWidget *window;
256         GtkWidget *vbox1;
257         GtkWidget *bool_hbox;
258         GtkWidget *bool_optmenu;
259         GtkListStore *menu;
260         GtkTreeIter iter;
261         GtkWidget *clear_btn;
262
263         GtkWidget *table1;
264         GtkWidget *from_label;
265         GtkWidget *from_entry;
266         GtkWidget *to_label;
267         GtkWidget *to_entry;
268         GtkWidget *subject_label;
269         GtkWidget *subject_entry;
270         GtkWidget *body_label;
271         GtkWidget *body_entry;
272         GtkWidget *adv_condition_label;
273         GtkWidget *adv_condition_entry;
274         GtkWidget *adv_condition_btn;
275
276         GtkWidget *checkbtn_hbox;
277         GtkWidget *adv_search_checkbtn;
278         GtkWidget *case_checkbtn;
279
280         GtkWidget *confirm_area;
281         GtkWidget *help_btn;
282         GtkWidget *all_btn;
283         GtkWidget *prev_btn;
284         GtkWidget *next_btn;
285         GtkWidget *close_btn;
286         GtkWidget *stop_btn;
287         gboolean is_searching = FALSE;
288
289         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "summary_search");
290         gtk_window_set_title(GTK_WINDOW (window), _("Search messages"));
291         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
292         gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
293         gtk_container_set_border_width(GTK_CONTAINER (window), 8);
294         g_signal_connect(G_OBJECT(window), "delete_event",
295                          G_CALLBACK(gtk_widget_hide_on_delete), NULL);
296         g_signal_connect(G_OBJECT(window), "key_press_event",
297                          G_CALLBACK(key_pressed), NULL);
298         MANAGE_WINDOW_SIGNALS_CONNECT(window);
299
300         vbox1 = gtk_vbox_new (FALSE, 0);
301         gtk_widget_show (vbox1);
302         gtk_container_add (GTK_CONTAINER (window), vbox1);
303
304         bool_hbox = gtk_hbox_new(FALSE, 4);
305         gtk_widget_show(bool_hbox);
306         gtk_box_pack_start(GTK_BOX(vbox1), bool_hbox, FALSE, FALSE, 0);
307
308         bool_optmenu = gtkut_sc_combobox_create(NULL, FALSE);
309         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(bool_optmenu)));
310         gtk_widget_show(bool_optmenu);
311         gtk_box_pack_start(GTK_BOX(bool_hbox), bool_optmenu, FALSE, FALSE, 0);
312
313         COMBOBOX_ADD(menu, _("Match any of the following"), 0);
314         gtk_combo_box_set_active_iter(GTK_COMBO_BOX(bool_optmenu), &iter);
315         COMBOBOX_ADD(menu, _("Match all of the following"), 1);
316         g_signal_connect(G_OBJECT(bool_optmenu), "changed",
317                          G_CALLBACK(optmenu_changed), NULL);
318
319         clear_btn = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
320         gtk_widget_show(clear_btn);
321         gtk_box_pack_end(GTK_BOX(bool_hbox), clear_btn, FALSE, FALSE, 0);
322
323         table1 = gtk_table_new (5, 3, FALSE);
324         gtk_widget_show (table1);
325         gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);
326         gtk_container_set_border_width (GTK_CONTAINER (table1), 4);
327         gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
328         gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
329
330         from_entry = gtk_combo_box_text_new_with_entry ();
331         gtk_combo_box_set_active(GTK_COMBO_BOX(from_entry), -1);
332         if (prefs_common.summary_search_from_history)
333                 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(from_entry),
334                                 prefs_common.summary_search_from_history);
335         gtk_widget_show (from_entry);
336         gtk_table_attach (GTK_TABLE (table1), from_entry, 1, 3, 0, 1,
337                           GTK_EXPAND|GTK_FILL, 0, 0, 0);
338         g_signal_connect(G_OBJECT(from_entry), "changed",
339                          G_CALLBACK(from_changed), NULL);
340         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((from_entry)))),
341                          "focus_in_event", G_CALLBACK(from_entry_focus_evt_in), NULL);
342         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((from_entry)))),
343                          "focus_out_event", G_CALLBACK(from_entry_focus_evt_out), NULL);
344
345         to_entry = gtk_combo_box_text_new_with_entry ();
346         gtk_combo_box_set_active(GTK_COMBO_BOX(to_entry), -1);
347         if (prefs_common.summary_search_to_history)
348                 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(to_entry),
349                                 prefs_common.summary_search_to_history);
350         gtk_widget_show (to_entry);
351         gtk_table_attach (GTK_TABLE (table1), to_entry, 1, 3, 1, 2,
352                           GTK_EXPAND|GTK_FILL, 0, 0, 0);
353         g_signal_connect(G_OBJECT(to_entry), "changed",
354                          G_CALLBACK(to_changed), NULL);
355         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((to_entry)))),
356                          "focus_in_event", G_CALLBACK(to_entry_focus_evt_in), NULL);
357         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((to_entry)))),
358                          "focus_out_event", G_CALLBACK(to_entry_focus_evt_out), NULL);
359
360         subject_entry = gtk_combo_box_text_new_with_entry ();
361         gtk_combo_box_set_active(GTK_COMBO_BOX(subject_entry), -1);
362         if (prefs_common.summary_search_subject_history)
363                 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(subject_entry),
364                                 prefs_common.summary_search_subject_history);
365         gtk_widget_show (subject_entry);
366         gtk_table_attach (GTK_TABLE (table1), subject_entry, 1, 3, 2, 3,
367                           GTK_EXPAND|GTK_FILL, 0, 0, 0);
368         g_signal_connect(G_OBJECT(subject_entry), "changed",
369                          G_CALLBACK(subject_changed), NULL);
370         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((subject_entry)))),
371                          "focus_in_event", G_CALLBACK(subject_entry_focus_evt_in), NULL);
372         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((subject_entry)))),
373                          "focus_out_event", G_CALLBACK(subject_entry_focus_evt_out), NULL);
374
375         body_entry = gtk_combo_box_text_new_with_entry ();
376         gtk_combo_box_set_active(GTK_COMBO_BOX(body_entry), -1);
377         if (prefs_common.summary_search_body_history)
378                 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(body_entry),
379                                 prefs_common.summary_search_body_history);
380         gtk_widget_show (body_entry);
381         gtk_table_attach (GTK_TABLE (table1), body_entry, 1, 3, 3, 4,
382                           GTK_EXPAND|GTK_FILL, 0, 0, 0);
383         g_signal_connect(G_OBJECT(body_entry), "changed",
384                          G_CALLBACK(body_changed), NULL);
385         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((body_entry)))),
386                          "focus_in_event", G_CALLBACK(body_entry_focus_evt_in), NULL);
387         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((body_entry)))),
388                          "focus_out_event", G_CALLBACK(body_entry_focus_evt_out), NULL);
389
390         adv_condition_entry = gtk_combo_box_text_new_with_entry ();
391         gtk_combo_box_set_active(GTK_COMBO_BOX(adv_condition_entry), -1);
392         if (prefs_common.summary_search_adv_condition_history)
393                 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(adv_condition_entry),
394                                 prefs_common.summary_search_adv_condition_history);
395         gtk_widget_show (adv_condition_entry);
396         gtk_table_attach (GTK_TABLE (table1), adv_condition_entry, 1, 2, 4, 5,
397                           GTK_EXPAND|GTK_FILL, 0, 0, 0);
398         g_signal_connect(G_OBJECT(adv_condition_entry), "changed",
399                          G_CALLBACK(adv_condition_changed), NULL);
400         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((adv_condition_entry)))),
401                          "focus_in_event", G_CALLBACK(adv_condition_entry_focus_evt_in), NULL);
402         g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((adv_condition_entry)))),
403                          "focus_out_event", G_CALLBACK(adv_condition_entry_focus_evt_out), NULL);
404
405         adv_condition_btn = gtk_button_new_with_label(" ... ");
406         gtk_widget_show (adv_condition_btn);
407         gtk_table_attach (GTK_TABLE (table1), adv_condition_btn, 2, 3, 4, 5,
408                           GTK_FILL, 0, 0, 0);
409         g_signal_connect(G_OBJECT (adv_condition_btn), "clicked",
410                          G_CALLBACK(adv_condition_btn_clicked), search_window.window);
411
412         CLAWS_SET_TIP(adv_condition_btn,
413                              _("Edit search criteria"));
414
415         from_label = gtk_label_new (_("From:"));
416         gtk_widget_show (from_label);
417         gtk_table_attach (GTK_TABLE (table1), from_label, 0, 1, 0, 1,
418                           GTK_FILL, 0, 0, 0);
419         gtk_label_set_justify (GTK_LABEL (from_label), GTK_JUSTIFY_RIGHT);
420         gtk_misc_set_alignment (GTK_MISC (from_label), 1, 0.5);
421
422         to_label = gtk_label_new (_("To:"));
423         gtk_widget_show (to_label);
424         gtk_table_attach (GTK_TABLE (table1), to_label, 0, 1, 1, 2,
425                           GTK_FILL, 0, 0, 0);
426         gtk_label_set_justify (GTK_LABEL (to_label), GTK_JUSTIFY_RIGHT);
427         gtk_misc_set_alignment (GTK_MISC (to_label), 1, 0.5);
428
429         subject_label = gtk_label_new (_("Subject:"));
430         gtk_widget_show (subject_label);
431         gtk_table_attach (GTK_TABLE (table1), subject_label, 0, 1, 2, 3,
432                           GTK_FILL, 0, 0, 0);
433         gtk_label_set_justify (GTK_LABEL (subject_label), GTK_JUSTIFY_RIGHT);
434         gtk_misc_set_alignment (GTK_MISC (subject_label), 1, 0.5);
435
436         body_label = gtk_label_new (_("Body:"));
437         gtk_widget_show (body_label);
438         gtk_table_attach (GTK_TABLE (table1), body_label, 0, 1, 3, 4,
439                           GTK_FILL, 0, 0, 0);
440         gtk_label_set_justify (GTK_LABEL (body_label), GTK_JUSTIFY_RIGHT);
441         gtk_misc_set_alignment (GTK_MISC (body_label), 1, 0.5);
442
443         adv_condition_label = gtk_label_new (_("Condition:"));
444         gtk_widget_show (adv_condition_label);
445         gtk_table_attach (GTK_TABLE (table1), adv_condition_label, 0, 1, 4, 5,
446                           GTK_FILL, 0, 0, 0);
447         gtk_label_set_justify (GTK_LABEL (adv_condition_label), GTK_JUSTIFY_RIGHT);
448         gtk_misc_set_alignment (GTK_MISC (adv_condition_label), 1, 0.5);
449
450         checkbtn_hbox = gtk_hbox_new (FALSE, 8);
451         gtk_widget_show (checkbtn_hbox);
452         gtk_box_pack_start (GTK_BOX (vbox1), checkbtn_hbox, TRUE, TRUE, 0);
453         gtk_container_set_border_width (GTK_CONTAINER (checkbtn_hbox), 8);
454
455         case_checkbtn = gtk_check_button_new_with_label (_("Case sensitive"));
456         gtk_widget_show (case_checkbtn);
457         gtk_box_pack_start (GTK_BOX (checkbtn_hbox), case_checkbtn,
458                             FALSE, FALSE, 0);
459         g_signal_connect(G_OBJECT(case_checkbtn), "changed",
460                          G_CALLBACK(case_changed), NULL);
461
462         adv_search_checkbtn = gtk_check_button_new_with_label (_("Extended Search"));
463         gtk_widget_show (adv_search_checkbtn);
464         gtk_box_pack_start (GTK_BOX (checkbtn_hbox), adv_search_checkbtn,
465                             FALSE, FALSE, 0);
466         g_signal_connect(G_OBJECT(adv_search_checkbtn), "changed",
467                          G_CALLBACK(case_changed), NULL);
468
469         confirm_area = gtk_hbutton_box_new();
470         gtk_widget_show (confirm_area);
471         gtk_button_box_set_layout(GTK_BUTTON_BOX(confirm_area),
472                                   GTK_BUTTONBOX_END);
473         gtk_box_set_spacing(GTK_BOX(confirm_area), 5);
474
475         gtkut_stock_button_add_help(confirm_area, &help_btn);
476
477         all_btn = gtk_button_new_with_mnemonic(_("Find _all"));
478         gtk_widget_set_can_default(all_btn, TRUE);
479         gtk_box_pack_start(GTK_BOX(confirm_area), all_btn, TRUE, TRUE, 0);
480         gtk_widget_show(all_btn);
481
482         prev_btn = gtk_button_new_from_stock(GTK_STOCK_GO_BACK);
483         gtk_widget_set_can_default(prev_btn, TRUE);
484         gtk_box_pack_start(GTK_BOX(confirm_area), prev_btn, TRUE, TRUE, 0);
485         gtk_widget_show(prev_btn);
486
487         next_btn = gtk_button_new_from_stock(GTK_STOCK_GO_FORWARD);
488         gtk_widget_set_can_default(next_btn, TRUE);
489         gtk_box_pack_start(GTK_BOX(confirm_area), next_btn, TRUE, TRUE, 0);
490         gtk_widget_show(next_btn);
491
492         close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
493         gtk_widget_set_can_default(close_btn, TRUE);
494         gtk_box_pack_start(GTK_BOX(confirm_area), close_btn, TRUE, TRUE, 0);
495         gtk_widget_show(close_btn);
496
497         /* stop button hidden */
498         stop_btn = gtk_button_new_from_stock(GTK_STOCK_STOP);
499         gtk_widget_set_can_default(stop_btn, TRUE);
500         gtk_box_pack_start(GTK_BOX(confirm_area), stop_btn, TRUE, TRUE, 0);
501
502         gtk_box_pack_start (GTK_BOX (vbox1), confirm_area, FALSE, FALSE, 0);
503         gtk_widget_grab_default(next_btn);
504
505         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, bool_optmenu)
506         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, from_label)
507         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, from_entry)
508         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, to_label)
509         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, to_entry)
510         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, subject_label)
511         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, subject_entry)
512         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, body_label)
513         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, body_entry)
514         SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_label)
515         SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_entry)
516         SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_btn)
517         SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, case_checkbtn)
518
519         g_signal_connect(G_OBJECT(help_btn), "clicked",
520                          G_CALLBACK(manual_open_with_anchor_cb),
521                          MANUAL_ANCHOR_SEARCHING);
522         g_signal_connect(G_OBJECT(clear_btn), "clicked",
523                          G_CALLBACK(summary_search_clear), NULL);
524         g_signal_connect(G_OBJECT(all_btn), "clicked",
525                          G_CALLBACK(summary_search_all_clicked), NULL);
526         g_signal_connect(G_OBJECT(prev_btn), "clicked",
527                          G_CALLBACK(summary_search_prev_clicked), NULL);
528         g_signal_connect(G_OBJECT(next_btn), "clicked",
529                          G_CALLBACK(summary_search_next_clicked), NULL);
530         g_signal_connect_closure
531                 (G_OBJECT(close_btn), "clicked",
532                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide),
533              window, NULL), FALSE);
534         g_signal_connect(G_OBJECT(stop_btn), "clicked",
535                          G_CALLBACK(summary_search_stop_clicked), NULL);
536
537         search_window.window = window;
538         search_window.bool_optmenu = bool_optmenu;
539         search_window.from_label = from_label;
540         search_window.from_entry = from_entry;
541         search_window.to_label = to_label;
542         search_window.to_entry = to_entry;
543         search_window.subject_label = subject_label;
544         search_window.subject_entry = subject_entry;
545         search_window.body_label = body_label;
546         search_window.body_entry = body_entry;
547         search_window.adv_condition_label = adv_condition_label;
548         search_window.adv_condition_entry = adv_condition_entry;
549         search_window.adv_condition_btn = adv_condition_btn;
550         search_window.case_checkbtn = case_checkbtn;
551         search_window.adv_search_checkbtn = adv_search_checkbtn;
552         search_window.clear_btn = clear_btn;
553         search_window.help_btn = help_btn;
554         search_window.all_btn = all_btn;
555         search_window.prev_btn = prev_btn;
556         search_window.next_btn = next_btn;
557         search_window.close_btn = close_btn;
558         search_window.stop_btn = stop_btn;
559         search_window.advsearch = NULL;
560         search_window.matcher_is_outdated = TRUE;
561         search_window.search_in_progress = FALSE;
562         search_window.matched_msgnums = NULL;
563         search_window.is_searching = is_searching;
564 }
565
566 static gboolean summary_search_verify_match(MsgInfo *msg)
567 {
568         gpointer msgnum = GUINT_TO_POINTER(msg->msgnum);
569
570         if (g_hash_table_lookup(search_window.matched_msgnums, msgnum) != NULL)
571                 return TRUE;
572         else
573                 return FALSE;
574 }
575
576 static gboolean summary_search_progress_cb(gpointer data, guint at, guint matched, guint total)
577 {
578         if (!search_window.is_searching) {
579                 search_window.matcher_is_outdated = TRUE;
580                 return FALSE;
581         }
582
583         return summaryview_search_root_progress(search_window.summaryview, at, matched, total);
584 }
585
586 static gboolean summary_search_prepare_matcher()
587 {
588         gboolean adv_search;
589         gboolean bool_and = FALSE;
590         gboolean case_sens = FALSE;
591         gchar *matcher_str;
592         gint match_type;
593         gchar *from_str = NULL, *to_str = NULL, *subject_str = NULL;
594         gchar *body_str = NULL;
595         GSList *matchers = NULL;
596
597         if (!search_window.matcher_is_outdated)
598                 return TRUE;
599
600         if (search_window.advsearch == NULL) {
601                 search_window.advsearch = advsearch_new();
602                 advsearch_set_on_error_cb(search_window.advsearch, NULL, NULL); /* TODO */
603                 advsearch_set_on_progress_cb(search_window.advsearch, 
604                         summary_search_progress_cb, NULL);
605         }
606
607         adv_search = gtk_toggle_button_get_active
608                         (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn));
609
610         if (adv_search) {
611                 matcher_str = add_history_get(search_window.adv_condition_entry, &prefs_common.summary_search_adv_condition_history);
612         } else {
613                 MatcherList *matcher_list;
614                 bool_and = combobox_get_active_data(GTK_COMBO_BOX(search_window.bool_optmenu));
615                 case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_window.case_checkbtn));
616
617                 from_str    = add_history_get(search_window.from_entry, &prefs_common.summary_search_from_history);
618                 to_str      = add_history_get(search_window.to_entry, &prefs_common.summary_search_to_history);
619                 subject_str = add_history_get(search_window.subject_entry, &prefs_common.summary_search_subject_history);
620                 body_str    = add_history_get(search_window.body_entry, &prefs_common.summary_search_body_history);
621
622                 if (!from_str && !to_str && !subject_str && !body_str) {
623                         /* TODO: warn if no search criteria? (or make buttons enabled only when
624                          * at least one search criteria has been set */
625                         return FALSE;
626                 }
627
628                 match_type = case_sens ? MATCHTYPE_MATCH : MATCHTYPE_MATCHCASE;
629
630                 if (from_str) {
631                         MatcherProp *prop = matcherprop_new(MATCHCRITERIA_FROM, NULL, match_type, from_str, 0);
632                         matchers = g_slist_append(matchers, prop);
633                 }
634                 if (to_str) {
635                         MatcherProp *prop = matcherprop_new(MATCHCRITERIA_TO, NULL, match_type, to_str, 0);
636                         matchers = g_slist_append(matchers, prop);
637                 }
638                 if (subject_str) {
639                         MatcherProp *prop = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, match_type, subject_str, 0);
640                         matchers = g_slist_append(matchers, prop);
641                 }
642                 if (body_str) {
643                         MatcherProp *prop = matcherprop_new(MATCHCRITERIA_BODY_PART, NULL, match_type, body_str, 0);
644                         matchers = g_slist_append(matchers, prop);
645                 }
646                 g_free(from_str);
647                 g_free(to_str);
648                 g_free(subject_str);
649                 g_free(body_str);
650
651                 matcher_list = matcherlist_new(matchers, bool_and);
652                 if (!matcher_list)
653                         return FALSE;
654
655                 matcher_str = matcherlist_to_string(matcher_list);
656                 matcherlist_free(matcher_list);
657         }
658         if (!matcher_str)
659                 return FALSE;
660
661         advsearch_set(search_window.advsearch, ADVANCED_SEARCH_EXTENDED,
662                       matcher_str);
663
664         debug_print("Advsearch set: %s\n", matcher_str);
665         g_free(matcher_str);
666
667         if (!advsearch_has_proper_predicate(search_window.advsearch))
668                 return FALSE;
669
670         search_window.matcher_is_outdated = FALSE;
671
672         return TRUE;
673 }
674
675 static gboolean summary_search_prereduce_msg_list()
676 {
677         MsgInfoList *msglist = NULL;
678         MsgNumberList *msgnums = NULL;
679         MsgNumberList *cur;
680         SummaryView *summaryview = search_window.summaryview;
681         gboolean result;
682         FolderItem *item = summaryview->folder_item;
683         static GdkCursor *watch_cursor = NULL;
684         if (!watch_cursor)
685                 watch_cursor = gdk_cursor_new(GDK_WATCH);
686
687         if (search_window.matcher_is_outdated && !summary_search_prepare_matcher())
688                 return FALSE;
689
690         main_window_cursor_wait(mainwindow_get_mainwindow());
691         gdk_window_set_cursor(gtk_widget_get_window(search_window.window), watch_cursor);
692         statusbar_print_all(_("Searching in %s... \n"),
693                         item->path ? item->path : "(null)");
694
695         result = advsearch_search_msgs_in_folders(search_window.advsearch,
696                         &msglist, item, FALSE);
697         statusbar_pop_all();
698         statusbar_progress_all(0, 0, 0);
699         gdk_window_set_cursor(gtk_widget_get_window(search_window.window), NULL);
700         main_window_cursor_normal(mainwindow_get_mainwindow());
701
702         if (!result)
703                 return FALSE;
704
705         msgnums = procmsg_get_number_list_for_msgs(msglist);
706         procmsg_msg_list_free(msglist);
707
708         if (search_window.matched_msgnums == NULL)
709                 search_window.matched_msgnums = g_hash_table_new(g_direct_hash, NULL);
710
711         g_hash_table_remove_all(search_window.matched_msgnums);
712
713         for (cur = msgnums; cur != NULL; cur = cur->next)
714                 g_hash_table_insert(search_window.matched_msgnums, cur->data, GINT_TO_POINTER(1));
715
716         g_slist_free(msgnums);
717
718         return TRUE;
719 }
720
721 static void summary_search_execute(gboolean backward, gboolean search_all)
722 {
723         SummaryView *summaryview = search_window.summaryview;
724         GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
725         GtkCMCTreeNode *node;
726         MsgInfo *msginfo;
727         gboolean all_searched = FALSE;
728         gboolean matched = FALSE;
729         gint i = 0;
730
731         if (summary_is_locked(summaryview))
732                 return;
733
734         summary_lock(summaryview);
735
736         search_window.is_searching = TRUE;
737         main_window_cursor_wait(summaryview->mainwin);
738         summary_show_stop_button();
739
740         if (search_window.matcher_is_outdated && !summary_search_prereduce_msg_list())
741                 goto exit;
742
743         if (search_all) {
744                 summary_freeze(summaryview);
745                 summary_unselect_all(summaryview);
746                 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
747                 backward = FALSE;
748         } else if (!summaryview->selected) {
749                 /* no selection, search from from list start */
750                 if (backward)
751                         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list_end);
752                 else
753                         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
754
755                 if (!node) {
756                         search_window.is_searching = FALSE;
757                         summary_hide_stop_button();
758                         main_window_cursor_normal(summaryview->mainwin);
759                         summary_unlock(summaryview);
760                         return;
761                 }
762         } else {
763                 /* search from current selection */
764                 if (backward)
765                         node = gtkut_ctree_node_prev(ctree, summaryview->selected);
766                 else
767                         node = gtkut_ctree_node_next(ctree, summaryview->selected);
768         }
769
770         for (; search_window.is_searching; i++) {
771                 if (!node) {
772                         gchar *str;
773                         AlertValue val;
774
775                         if (search_all)
776                                 break;
777
778                         if (all_searched) {
779                                 alertpanel_full(_("Search failed"),
780                                                 _("Search string not found."),
781                                                 GTK_STOCK_CLOSE, NULL, NULL, ALERTFOCUS_FIRST,
782                                                 FALSE, NULL, ALERT_WARNING);
783                                 break;
784                         }
785
786                         if (backward)
787                                 str = _("Beginning of list reached; continue from end?");
788                         else
789                                 str = _("End of list reached; continue from beginning?");
790
791                         val = alertpanel(_("Search finished"), str,
792                                          GTK_STOCK_NO, GTK_STOCK_YES, NULL,
793                                          ALERTFOCUS_SECOND);
794                         if (G_ALERTALTERNATE == val) {
795                                 if (backward) {
796                                         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list_end);
797                                 } else {
798                                         node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
799                                 }
800
801                                 all_searched = TRUE;
802
803                                 manage_window_focus_in(search_window.window, NULL, NULL);
804                         } else
805                                 break;
806                 }
807
808                 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
809
810                 if (msginfo)
811                         matched = summary_search_verify_match(msginfo);
812                 else
813                         matched = FALSE;
814
815                 if (matched) {
816                         if (search_all) {
817                                 gtk_cmctree_select(ctree, node);
818                         } else {
819                                 summary_unlock(summaryview);
820                                 summary_select_node(summaryview, node,
821                                                 OPEN_SELECTED_ON_SEARCH_RESULTS);
822                                 summary_lock(summaryview);
823                                 break;
824                         }
825                 }
826
827                 if (i % (search_window.is_fast ? 1000 : 100) == 0)
828                         GTK_EVENTS_FLUSH();
829
830                 node = backward ? gtkut_ctree_node_prev(ctree, node)
831                                 : gtkut_ctree_node_next(ctree, node);
832         }
833
834 exit:
835         search_window.is_searching = FALSE;
836         summary_hide_stop_button();
837         main_window_cursor_normal(summaryview->mainwin);
838         if (search_all)
839                 summary_thaw_with_status(summaryview);
840         summary_unlock(summaryview);
841 }
842
843 static void summary_search_clear(GtkButton *button, gpointer data)
844 {
845         if (gtk_toggle_button_get_active
846                 (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn))) {
847                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.adv_condition_entry)))), "");
848         } else {
849                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.from_entry)))), "");
850                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.to_entry)))), "");
851                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.subject_entry)))), "");
852                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.body_entry)))), "");
853         }
854         /* stop searching */
855         if (search_window.is_searching) {
856                 search_window.is_searching = FALSE;
857         }
858         search_window.matcher_is_outdated = TRUE;
859 }
860
861 static void summary_search_prev_clicked(GtkButton *button, gpointer data)
862 {
863         summary_search_execute(TRUE, FALSE);
864 }
865
866 static void summary_search_next_clicked(GtkButton *button, gpointer data)
867 {
868         summary_search_execute(FALSE, FALSE);
869 }
870
871 static void summary_search_all_clicked(GtkButton *button, gpointer data)
872 {
873         summary_search_execute(FALSE, TRUE);
874 }
875
876 static void adv_condition_btn_done(MatcherList * matchers)
877 {
878         gchar *str;
879
880         cm_return_if_fail(
881                         mainwindow_get_mainwindow()->summaryview->quicksearch != NULL);
882
883         if (matchers == NULL) {
884                 return;
885         }
886
887         str = matcherlist_to_string(matchers);
888         search_window.matcher_is_outdated = TRUE;
889
890         if (str != NULL) {
891                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.adv_condition_entry)))), str);
892                 g_free(str);
893         }
894 }
895
896 static void summary_search_stop_clicked(GtkButton *button, gpointer data)
897 {
898         search_window.is_searching = FALSE;
899 }
900
901 static void adv_condition_btn_clicked(GtkButton *button, gpointer data)
902 {
903         const gchar * cond_str;
904         MatcherList * matchers = NULL;
905
906         cm_return_if_fail( search_window.window != NULL );
907
908         /* re-use the current search value if it's a condition expression,
909            otherwise ignore it silently */
910         cond_str = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(search_window.adv_condition_entry));
911         if (cond_str && *cond_str != '\0') {
912                 matchers = matcher_parser_get_cond((gchar*)cond_str, NULL);
913         }
914
915         prefs_matcher_open(matchers, adv_condition_btn_done);
916
917         if (matchers != NULL) {
918                 matcherlist_free(matchers);
919         }
920 };
921
922 static void optmenu_changed(GtkComboBox *widget, gpointer user_data)
923 {
924         search_window.matcher_is_outdated = TRUE;
925 }
926
927 static void from_changed(void)
928 {
929         if (!search_window.from_entry_has_focus)
930                 gtk_widget_grab_focus(search_window.from_entry);
931         search_window.matcher_is_outdated = TRUE;
932 }
933
934 static void to_changed(void)
935 {
936         if (!search_window.to_entry_has_focus)
937                 gtk_widget_grab_focus(search_window.to_entry);
938         search_window.matcher_is_outdated = TRUE;
939 }
940
941 static void subject_changed(void)
942 {
943         if (!search_window.subject_entry_has_focus)
944                 gtk_widget_grab_focus(search_window.subject_entry);
945         search_window.matcher_is_outdated = TRUE;
946 }
947
948 static void body_changed(void)
949 {
950         if (!search_window.body_entry_has_focus)
951                 gtk_widget_grab_focus(search_window.body_entry);
952         search_window.matcher_is_outdated = TRUE;
953 }
954
955 static void adv_condition_changed(void)
956 {
957         if (!search_window.adv_condition_entry_has_focus)
958                 gtk_widget_grab_focus(search_window.adv_condition_entry);
959         search_window.matcher_is_outdated = TRUE;
960 }
961
962 static void case_changed(GtkToggleButton *togglebutton, gpointer user_data)
963 {
964         search_window.matcher_is_outdated = TRUE;
965 }
966
967 static gboolean from_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
968                                   gpointer data)
969 {
970         search_window.from_entry_has_focus = TRUE;
971         return FALSE;
972 }
973
974 static gboolean from_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
975                                   gpointer data)
976 {
977         search_window.from_entry_has_focus = FALSE;
978         return FALSE;
979 }
980
981 static gboolean to_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
982                                   gpointer data)
983 {
984         search_window.to_entry_has_focus = TRUE;
985         return FALSE;
986 }
987
988 static gboolean to_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
989                                   gpointer data)
990 {
991         search_window.to_entry_has_focus = FALSE;
992         return FALSE;
993 }
994
995 static gboolean subject_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
996                                   gpointer data)
997 {
998         search_window.subject_entry_has_focus = TRUE;
999         return FALSE;
1000 }
1001
1002 static gboolean subject_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
1003                                   gpointer data)
1004 {
1005         search_window.subject_entry_has_focus = FALSE;
1006         return FALSE;
1007 }
1008
1009 static gboolean body_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
1010                                   gpointer data)
1011 {
1012         search_window.body_entry_has_focus = TRUE;
1013         return FALSE;
1014 }
1015
1016 static gboolean body_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
1017                                   gpointer data)
1018 {
1019         search_window.body_entry_has_focus = FALSE;
1020         return FALSE;
1021 }
1022
1023 static gboolean adv_condition_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
1024                                   gpointer data)
1025 {
1026         search_window.adv_condition_entry_has_focus = TRUE;
1027         return FALSE;
1028 }
1029
1030 static gboolean adv_condition_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
1031                                   gpointer data)
1032 {
1033         search_window.adv_condition_entry_has_focus = FALSE;
1034         return FALSE;
1035 }
1036
1037 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1038                             gpointer data)
1039 {
1040         if (event && (event->keyval == GDK_KEY_Escape)) {
1041                 /* ESC key will:
1042                         - stop a running search
1043                         - close the search window if no search is running
1044                 */
1045                 if (!search_window.is_searching) {
1046                         gtk_widget_hide(search_window.window);
1047                 } else {
1048                         search_window.is_searching = FALSE;
1049                 }
1050         }
1051
1052         if (event && (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter)) {
1053                 if (!search_window.is_searching) {
1054                         summary_search_execute(FALSE, FALSE);
1055                 }
1056         }
1057
1058         if (event && (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_Up)) {
1059                 if (search_window.from_entry_has_focus) {
1060                         combobox_set_value_from_arrow_key(
1061                                         GTK_COMBO_BOX(search_window.from_entry),
1062                                         event->keyval);
1063                         return TRUE;
1064                 }
1065                 if (search_window.to_entry_has_focus) {
1066                         combobox_set_value_from_arrow_key(
1067                                         GTK_COMBO_BOX(search_window.to_entry),
1068                                         event->keyval);
1069                         return TRUE;
1070                 }
1071                 if (search_window.subject_entry_has_focus) {
1072                         combobox_set_value_from_arrow_key(
1073                                         GTK_COMBO_BOX(search_window.subject_entry),
1074                                         event->keyval);
1075                         return TRUE;
1076                 }
1077                 if (search_window.body_entry_has_focus) {
1078                         combobox_set_value_from_arrow_key(
1079                                         GTK_COMBO_BOX(search_window.body_entry),
1080                                         event->keyval);
1081                         return TRUE;
1082                 }
1083                 if (search_window.adv_condition_entry_has_focus) {
1084                         combobox_set_value_from_arrow_key(
1085                                         GTK_COMBO_BOX(search_window.adv_condition_entry),
1086                                         event->keyval);
1087                         return TRUE;
1088                 }
1089         }
1090
1091         return FALSE;
1092 }