2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <gtk/gtkwidget.h>
30 #include <gtk/gtkwindow.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtktable.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtklabel.h>
35 #include <gtk/gtkentry.h>
36 #include <gtk/gtkhbox.h>
37 #include <gtk/gtkcheckbutton.h>
38 #include <gtk/gtkhbbox.h>
39 #include <gtk/gtkbutton.h>
40 #include <gtk/gtkctree.h>
46 #include "summary_search.h"
47 #include "summaryview.h"
48 #include "messageview.h"
49 #include "mainwindow.h"
54 #include "prefs_gtk.h"
55 #include "manage_window.h"
56 #include "alertpanel.h"
58 #include "matcher_parser.h"
59 #include "prefs_matcher.h"
61 #include "prefs_common.h"
63 static struct SummarySearchWindow {
66 GtkWidget *bool_optmenu;
68 GtkWidget *from_entry;
70 GtkWidget *subject_entry;
71 GtkWidget *body_entry;
73 GtkWidget *adv_condition_entry;
74 GtkWidget *adv_condition_btn;
75 GtkWidget *adv_search_checkbtn;
77 GtkWidget *case_checkbtn;
87 SummaryView *summaryview;
89 MatcherList *matcher_list;
91 gboolean is_searching;
92 gboolean from_entry_has_focus;
93 gboolean to_entry_has_focus;
94 gboolean subject_entry_has_focus;
95 gboolean body_entry_has_focus;
96 gboolean adv_condition_entry_has_focus;
99 static void summary_search_create (void);
101 static void summary_search_execute (gboolean backward,
102 gboolean search_all);
104 static void summary_search_clear (GtkButton *button,
106 static void summary_search_prev_clicked (GtkButton *button,
108 static void summary_search_next_clicked (GtkButton *button,
110 static void summary_search_all_clicked (GtkButton *button,
112 static void summary_search_stop_clicked (GtkButton *button,
114 static void adv_condition_btn_clicked (GtkButton *button,
117 static void from_changed (void);
118 static void to_changed (void);
119 static void subject_changed (void);
120 static void body_changed (void);
121 static void adv_condition_changed (void);
123 static gboolean from_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
125 static gboolean from_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
127 static gboolean to_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
129 static gboolean to_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
131 static gboolean subject_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
133 static gboolean subject_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
135 static gboolean body_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
137 static gboolean body_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
139 static gboolean adv_condition_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
141 static gboolean adv_condition_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
144 static gboolean key_pressed (GtkWidget *widget,
149 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
150 gboolean in_btn = FALSE; \
151 if (GTK_IS_BUTTON(widget)) \
152 in_btn = GTK_BUTTON(widget)->in_button; \
153 gtk_widget_set_sensitive(widget, sensitive); \
154 if (GTK_IS_BUTTON(widget)) \
155 GTK_BUTTON(widget)->in_button = in_btn; \
158 void summary_search(SummaryView *summaryview)
160 if (!search_window.window) {
161 summary_search_create();
163 gtk_widget_hide(search_window.window);
166 search_window.summaryview = summaryview;
168 gtk_widget_grab_focus(search_window.next_btn);
169 gtk_widget_grab_focus(search_window.subject_entry);
170 gtk_widget_show(search_window.window);
173 static void summary_show_stop_button(void)
175 gtk_widget_hide(search_window.close_btn);
176 gtk_widget_show(search_window.stop_btn);
177 GTK_BUTTON_SET_SENSITIVE(search_window.all_btn, FALSE)
178 GTK_BUTTON_SET_SENSITIVE(search_window.prev_btn, FALSE)
179 GTK_BUTTON_SET_SENSITIVE(search_window.next_btn, FALSE)
182 static void summary_hide_stop_button(void)
184 gtk_widget_hide(search_window.stop_btn);
185 gtk_widget_show(search_window.close_btn);
186 gtk_widget_set_sensitive(search_window.all_btn, TRUE);
187 gtk_widget_set_sensitive(search_window.prev_btn, TRUE);
188 gtk_widget_set_sensitive(search_window.next_btn, TRUE);
191 static void summary_search_create(void)
195 GtkWidget *bool_hbox;
196 GtkWidget *bool_optmenu;
197 GtkWidget *bool_menu;
199 GtkWidget *clear_btn;
202 GtkWidget *from_label;
203 GtkWidget *from_entry;
206 GtkWidget *subject_label;
207 GtkWidget *subject_entry;
208 GtkWidget *body_label;
209 GtkWidget *body_entry;
210 GtkWidget *adv_condition_label;
211 GtkWidget *adv_condition_entry;
212 GtkWidget *adv_condition_btn;
214 GtkWidget *checkbtn_hbox;
215 GtkWidget *adv_search_checkbtn;
216 GtkWidget *case_checkbtn;
218 GtkWidget *confirm_area;
223 GtkWidget *close_btn;
225 GtkTooltips *tooltip;
227 gboolean is_searching = FALSE;
229 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "summary_search");
230 gtk_window_set_title(GTK_WINDOW (window), _("Search messages"));
231 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
232 gtk_container_set_border_width(GTK_CONTAINER (window), 8);
233 g_signal_connect(G_OBJECT(window), "delete_event",
234 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
236 maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
238 g_signal_connect(G_OBJECT(window), "key_press_event",
239 G_CALLBACK(key_pressed), NULL);
241 MANAGE_WINDOW_SIGNALS_CONNECT(window);
243 vbox1 = gtk_vbox_new (FALSE, 0);
244 gtk_widget_show (vbox1);
245 gtk_container_add (GTK_CONTAINER (window), vbox1);
247 bool_hbox = gtk_hbox_new(FALSE, 4);
248 gtk_widget_show(bool_hbox);
249 gtk_box_pack_start(GTK_BOX(vbox1), bool_hbox, FALSE, FALSE, 0);
251 bool_optmenu = gtk_option_menu_new();
252 gtk_widget_show(bool_optmenu);
253 gtk_box_pack_start(GTK_BOX(bool_hbox), bool_optmenu, FALSE, FALSE, 0);
255 bool_menu = gtk_menu_new();
256 MENUITEM_ADD(bool_menu, menuitem, _("Match any of the following"), 0);
257 MENUITEM_ADD(bool_menu, menuitem, _("Match all of the following"), 1);
258 gtk_option_menu_set_menu(GTK_OPTION_MENU(bool_optmenu), bool_menu);
260 clear_btn = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
261 gtk_widget_show(clear_btn);
262 gtk_box_pack_end(GTK_BOX(bool_hbox), clear_btn, FALSE, FALSE, 0);
264 table1 = gtk_table_new (5, 3, FALSE);
265 gtk_widget_show (table1);
266 gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);
267 gtk_container_set_border_width (GTK_CONTAINER (table1), 4);
268 gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
269 gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
271 from_entry = gtk_combo_box_entry_new_text ();
272 gtk_combo_box_set_active(GTK_COMBO_BOX(from_entry), -1);
273 if (prefs_common.summary_search_from_history)
274 combobox_set_popdown_strings(GTK_COMBO_BOX(from_entry),
275 prefs_common.summary_search_from_history);
276 gtk_widget_show (from_entry);
277 gtk_table_attach (GTK_TABLE (table1), from_entry, 1, 3, 0, 1,
278 GTK_EXPAND|GTK_FILL, 0, 0, 0);
279 g_signal_connect(G_OBJECT(from_entry), "changed",
280 G_CALLBACK(from_changed), NULL);
281 g_signal_connect(G_OBJECT(GTK_BIN(from_entry)->child),
282 "focus_in_event", G_CALLBACK(from_entry_focus_evt_in), NULL);
283 g_signal_connect(G_OBJECT(GTK_BIN(from_entry)->child),
284 "focus_out_event", G_CALLBACK(from_entry_focus_evt_out), NULL);
286 to_entry = gtk_combo_box_entry_new_text ();
287 gtk_combo_box_set_active(GTK_COMBO_BOX(to_entry), -1);
288 if (prefs_common.summary_search_to_history)
289 combobox_set_popdown_strings(GTK_COMBO_BOX(to_entry),
290 prefs_common.summary_search_to_history);
291 gtk_widget_show (to_entry);
292 gtk_table_attach (GTK_TABLE (table1), to_entry, 1, 3, 1, 2,
293 GTK_EXPAND|GTK_FILL, 0, 0, 0);
294 g_signal_connect(G_OBJECT(to_entry), "changed",
295 G_CALLBACK(to_changed), NULL);
296 g_signal_connect(G_OBJECT(GTK_BIN(to_entry)->child),
297 "focus_in_event", G_CALLBACK(to_entry_focus_evt_in), NULL);
298 g_signal_connect(G_OBJECT(GTK_BIN(to_entry)->child),
299 "focus_out_event", G_CALLBACK(to_entry_focus_evt_out), NULL);
301 subject_entry = gtk_combo_box_entry_new_text ();
302 gtk_combo_box_set_active(GTK_COMBO_BOX(subject_entry), -1);
303 if (prefs_common.summary_search_subject_history)
304 combobox_set_popdown_strings(GTK_COMBO_BOX(subject_entry),
305 prefs_common.summary_search_subject_history);
306 gtk_widget_show (subject_entry);
307 gtk_table_attach (GTK_TABLE (table1), subject_entry, 1, 3, 2, 3,
308 GTK_EXPAND|GTK_FILL, 0, 0, 0);
309 g_signal_connect(G_OBJECT(subject_entry), "changed",
310 G_CALLBACK(subject_changed), NULL);
311 g_signal_connect(G_OBJECT(GTK_BIN(subject_entry)->child),
312 "focus_in_event", G_CALLBACK(subject_entry_focus_evt_in), NULL);
313 g_signal_connect(G_OBJECT(GTK_BIN(subject_entry)->child),
314 "focus_out_event", G_CALLBACK(subject_entry_focus_evt_out), NULL);
316 body_entry = gtk_combo_box_entry_new_text ();
317 gtk_combo_box_set_active(GTK_COMBO_BOX(body_entry), -1);
318 if (prefs_common.summary_search_body_history)
319 combobox_set_popdown_strings(GTK_COMBO_BOX(body_entry),
320 prefs_common.summary_search_body_history);
321 gtk_widget_show (body_entry);
322 gtk_table_attach (GTK_TABLE (table1), body_entry, 1, 3, 3, 4,
323 GTK_EXPAND|GTK_FILL, 0, 0, 0);
324 g_signal_connect(G_OBJECT(body_entry), "changed",
325 G_CALLBACK(body_changed), NULL);
326 g_signal_connect(G_OBJECT(GTK_BIN(body_entry)->child),
327 "focus_in_event", G_CALLBACK(body_entry_focus_evt_in), NULL);
328 g_signal_connect(G_OBJECT(GTK_BIN(body_entry)->child),
329 "focus_out_event", G_CALLBACK(body_entry_focus_evt_out), NULL);
331 adv_condition_entry = gtk_combo_box_entry_new_text ();
332 gtk_combo_box_set_active(GTK_COMBO_BOX(adv_condition_entry), -1);
333 if (prefs_common.summary_search_adv_condition_history)
334 combobox_set_popdown_strings(GTK_COMBO_BOX(adv_condition_entry),
335 prefs_common.summary_search_adv_condition_history);
336 gtk_widget_show (adv_condition_entry);
337 gtk_table_attach (GTK_TABLE (table1), adv_condition_entry, 1, 2, 4, 5,
338 GTK_EXPAND|GTK_FILL, 0, 0, 0);
339 g_signal_connect(G_OBJECT(adv_condition_entry), "changed",
340 G_CALLBACK(adv_condition_changed), NULL);
341 g_signal_connect(G_OBJECT(GTK_BIN(adv_condition_entry)->child),
342 "focus_in_event", G_CALLBACK(adv_condition_entry_focus_evt_in), NULL);
343 g_signal_connect(G_OBJECT(GTK_BIN(adv_condition_entry)->child),
344 "focus_out_event", G_CALLBACK(adv_condition_entry_focus_evt_out), NULL);
346 adv_condition_btn = gtk_button_new_with_label(" ... ");
347 gtk_widget_show (adv_condition_btn);
348 gtk_table_attach (GTK_TABLE (table1), adv_condition_btn, 2, 3, 4, 5,
350 g_signal_connect(G_OBJECT (adv_condition_btn), "clicked",
351 G_CALLBACK(adv_condition_btn_clicked), search_window.window);
352 tooltip = gtk_tooltips_new();
353 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltip), adv_condition_btn,
354 _("Edit search criteria"), NULL);
356 from_label = gtk_label_new (_("From:"));
357 gtk_widget_show (from_label);
358 gtk_table_attach (GTK_TABLE (table1), from_label, 0, 1, 0, 1,
360 gtk_label_set_justify (GTK_LABEL (from_label), GTK_JUSTIFY_RIGHT);
361 gtk_misc_set_alignment (GTK_MISC (from_label), 1, 0.5);
363 to_label = gtk_label_new (_("To:"));
364 gtk_widget_show (to_label);
365 gtk_table_attach (GTK_TABLE (table1), to_label, 0, 1, 1, 2,
367 gtk_label_set_justify (GTK_LABEL (to_label), GTK_JUSTIFY_RIGHT);
368 gtk_misc_set_alignment (GTK_MISC (to_label), 1, 0.5);
370 subject_label = gtk_label_new (_("Subject:"));
371 gtk_widget_show (subject_label);
372 gtk_table_attach (GTK_TABLE (table1), subject_label, 0, 1, 2, 3,
374 gtk_label_set_justify (GTK_LABEL (subject_label), GTK_JUSTIFY_RIGHT);
375 gtk_misc_set_alignment (GTK_MISC (subject_label), 1, 0.5);
377 body_label = gtk_label_new (_("Body:"));
378 gtk_widget_show (body_label);
379 gtk_table_attach (GTK_TABLE (table1), body_label, 0, 1, 3, 4,
381 gtk_label_set_justify (GTK_LABEL (body_label), GTK_JUSTIFY_RIGHT);
382 gtk_misc_set_alignment (GTK_MISC (body_label), 1, 0.5);
384 adv_condition_label = gtk_label_new (_("Condition:"));
385 gtk_widget_show (adv_condition_label);
386 gtk_table_attach (GTK_TABLE (table1), adv_condition_label, 0, 1, 4, 5,
388 gtk_label_set_justify (GTK_LABEL (adv_condition_label), GTK_JUSTIFY_RIGHT);
389 gtk_misc_set_alignment (GTK_MISC (adv_condition_label), 1, 0.5);
391 checkbtn_hbox = gtk_hbox_new (FALSE, 8);
392 gtk_widget_show (checkbtn_hbox);
393 gtk_box_pack_start (GTK_BOX (vbox1), checkbtn_hbox, TRUE, TRUE, 0);
394 gtk_container_set_border_width (GTK_CONTAINER (checkbtn_hbox), 8);
396 case_checkbtn = gtk_check_button_new_with_label (_("Case sensitive"));
397 gtk_widget_show (case_checkbtn);
398 gtk_box_pack_start (GTK_BOX (checkbtn_hbox), case_checkbtn,
401 adv_search_checkbtn = gtk_check_button_new_with_label (_("Extended Search"));
402 gtk_widget_show (adv_search_checkbtn);
403 gtk_box_pack_start (GTK_BOX (checkbtn_hbox), adv_search_checkbtn,
406 confirm_area = gtk_hbutton_box_new();
407 gtk_widget_show (confirm_area);
408 gtk_button_box_set_layout(GTK_BUTTON_BOX(confirm_area),
410 gtk_box_set_spacing(GTK_BOX(confirm_area), 5);
412 gtkut_stock_button_add_help(confirm_area, &help_btn);
414 all_btn = gtk_button_new_with_mnemonic(_("Find _all"));
415 GTK_WIDGET_SET_FLAGS(all_btn, GTK_CAN_DEFAULT);
416 gtk_box_pack_start(GTK_BOX(confirm_area), all_btn, TRUE, TRUE, 0);
417 gtk_widget_show(all_btn);
419 prev_btn = gtk_button_new_from_stock(GTK_STOCK_GO_BACK);
420 GTK_WIDGET_SET_FLAGS(prev_btn, GTK_CAN_DEFAULT);
421 gtk_box_pack_start(GTK_BOX(confirm_area), prev_btn, TRUE, TRUE, 0);
422 gtk_widget_show(prev_btn);
424 next_btn = gtk_button_new_from_stock(GTK_STOCK_GO_FORWARD);
425 GTK_WIDGET_SET_FLAGS(next_btn, GTK_CAN_DEFAULT);
426 gtk_box_pack_start(GTK_BOX(confirm_area), next_btn, TRUE, TRUE, 0);
427 gtk_widget_show(next_btn);
429 close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
430 GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
431 gtk_box_pack_start(GTK_BOX(confirm_area), close_btn, TRUE, TRUE, 0);
432 gtk_widget_show(close_btn);
434 /* stop button hidden */
435 stop_btn = gtk_button_new_from_stock(GTK_STOCK_STOP);
436 GTK_WIDGET_SET_FLAGS(stop_btn, GTK_CAN_DEFAULT);
437 gtk_box_pack_start(GTK_BOX(confirm_area), stop_btn, TRUE, TRUE, 0);
439 gtk_box_pack_start (GTK_BOX (vbox1), confirm_area, FALSE, FALSE, 0);
440 gtk_widget_grab_default(next_btn);
442 SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, bool_menu)
443 SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, from_entry)
444 SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, to_entry)
445 SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, subject_entry)
446 SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, body_entry)
447 SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_label)
448 SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_entry)
449 SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_btn)
450 SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, case_checkbtn)
452 g_signal_connect(G_OBJECT(help_btn), "clicked",
453 G_CALLBACK(manual_open_with_anchor_cb),
454 MANUAL_ANCHOR_SEARCHING);
455 g_signal_connect(G_OBJECT(clear_btn), "clicked",
456 G_CALLBACK(summary_search_clear), NULL);
457 g_signal_connect(G_OBJECT(all_btn), "clicked",
458 G_CALLBACK(summary_search_all_clicked), NULL);
459 g_signal_connect(G_OBJECT(prev_btn), "clicked",
460 G_CALLBACK(summary_search_prev_clicked), NULL);
461 g_signal_connect(G_OBJECT(next_btn), "clicked",
462 G_CALLBACK(summary_search_next_clicked), NULL);
463 g_signal_connect_closure
464 (G_OBJECT(close_btn), "clicked",
465 g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide),
466 window, NULL), FALSE);
467 g_signal_connect(G_OBJECT(stop_btn), "clicked",
468 G_CALLBACK(summary_search_stop_clicked), NULL);
470 search_window.window = window;
471 search_window.bool_optmenu = bool_optmenu;
472 search_window.from_entry = from_entry;
473 search_window.to_entry = to_entry;
474 search_window.subject_entry = subject_entry;
475 search_window.body_entry = body_entry;
476 search_window.adv_condition_entry = adv_condition_entry;
477 search_window.adv_condition_btn = adv_condition_btn;
478 search_window.case_checkbtn = case_checkbtn;
479 search_window.adv_search_checkbtn = adv_search_checkbtn;
480 search_window.clear_btn = clear_btn;
481 search_window.help_btn = help_btn;
482 search_window.all_btn = all_btn;
483 search_window.prev_btn = prev_btn;
484 search_window.next_btn = next_btn;
485 search_window.close_btn = close_btn;
486 search_window.stop_btn = stop_btn;
487 search_window.matcher_list = NULL;
488 search_window.is_searching = is_searching;
490 maemo_window_full_screen_if_needed(GTK_WINDOW(search_window.window));
494 static void summary_search_execute(gboolean backward, gboolean search_all)
496 SummaryView *summaryview = search_window.summaryview;
497 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
501 gboolean bool_and = FALSE;
502 gboolean case_sens = FALSE;
503 gboolean all_searched = FALSE;
504 gboolean matched = FALSE;
505 gboolean body_matched = FALSE;
506 const gchar *from_str = NULL, *to_str = NULL, *subject_str = NULL;
507 const gchar *body_str = NULL, *adv_condition = NULL;
508 StrFindFunc str_find_func = NULL;
509 gboolean is_fast = TRUE;
510 gint interval = 1000;
513 if (summary_is_locked(summaryview)) {
516 summary_lock(summaryview);
518 adv_search = gtk_toggle_button_get_active
519 (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn));
522 if (search_window.matcher_list != NULL) {
523 matcherlist_free(search_window.matcher_list);
524 search_window.matcher_list = NULL;
526 adv_condition = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.adv_condition_entry));
527 if (adv_condition[0] != '\0') {
530 combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.adv_condition_entry));
531 prefs_common.summary_search_adv_condition_history = add_history(
532 prefs_common.summary_search_adv_condition_history, adv_condition);
533 combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.adv_condition_entry),
534 prefs_common.summary_search_adv_condition_history);
536 search_window.matcher_list = matcher_parser_get_cond((gchar*)adv_condition, &is_fast);
539 /* TODO: check for condition parsing error and show an error dialog */
541 /* TODO: warn if no search condition? (or make buttons enabled only when
542 at least one search condition has been set */
543 summary_unlock(summaryview);
547 bool_and = GPOINTER_TO_INT
548 (menu_get_option_menu_active_user_data
549 (GTK_OPTION_MENU(search_window.bool_optmenu)));
550 case_sens = gtk_toggle_button_get_active
551 (GTK_TOGGLE_BUTTON(search_window.case_checkbtn));
554 str_find_func = str_find;
556 str_find_func = str_case_find;
559 from_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.from_entry));
560 to_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.to_entry));
561 subject_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.subject_entry));
562 body_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.body_entry));
564 if ( (from_str[0] == '\0') &&
565 (to_str[0] == '\0') &&
566 (subject_str[0] == '\0') &&
567 (body_str[0] == '\0')) {
568 /* TODO: warn if no search criteria? (or make buttons enabled only when
569 at least one search criteria has been set */
570 summary_unlock(summaryview);
575 if (from_str[0] != '\0')
576 combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.from_entry));
577 prefs_common.summary_search_from_history = add_history(
578 prefs_common.summary_search_from_history, from_str);
579 combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.from_entry),
580 prefs_common.summary_search_from_history);
581 if (to_str[0] != '\0')
582 combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.to_entry));
583 prefs_common.summary_search_to_history = add_history(
584 prefs_common.summary_search_to_history, to_str);
585 combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.to_entry),
586 prefs_common.summary_search_to_history);
587 if (subject_str[0] != '\0')
588 combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.subject_entry));
589 prefs_common.summary_search_subject_history = add_history(
590 prefs_common.summary_search_subject_history, subject_str);
591 combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.subject_entry),
592 prefs_common.summary_search_subject_history);
593 if (body_str[0] != '\0')
594 combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.body_entry));
595 prefs_common.summary_search_body_history = add_history(
596 prefs_common.summary_search_body_history, body_str);
597 combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.body_entry),
598 prefs_common.summary_search_body_history);
601 search_window.is_searching = TRUE;
602 main_window_cursor_wait(summaryview->mainwin);
603 summary_show_stop_button();
606 summary_freeze(summaryview);
607 summary_unselect_all(summaryview);
608 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
610 } else if (!summaryview->selected) {
612 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list_end);
614 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
618 search_window.is_searching = FALSE;
619 summary_hide_stop_button();
620 main_window_cursor_normal(summaryview->mainwin);
621 summary_unlock(summaryview);
626 node = gtkut_ctree_node_prev
627 (ctree, summaryview->selected);
629 node = gtkut_ctree_node_next
630 (ctree, summaryview->selected);
634 for (; search_window.is_searching; i++) {
644 alertpanel_full(_("Search failed"),
645 _("Search string not found."),
646 GTK_STOCK_CLOSE, NULL, NULL, FALSE,
647 NULL, ALERT_WARNING, G_ALERTDEFAULT);
652 str = _("Beginning of list reached; continue from end?");
654 str = _("End of list reached; continue from beginning?");
656 val = alertpanel(_("Search finished"), str,
657 GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
658 if (G_ALERTALTERNATE == val) {
660 node = GTK_CTREE_NODE
661 (GTK_CLIST(ctree)->row_list_end);
663 node = GTK_CTREE_NODE
664 (GTK_CLIST(ctree)->row_list);
669 manage_window_focus_in(search_window.window, NULL, NULL);
675 msginfo = gtk_ctree_node_get_row_data(ctree, node);
676 body_matched = FALSE;
679 matched = matcherlist_match(search_window.matcher_list, msginfo);
684 if (!msginfo->from ||
685 !str_find_func(msginfo->from, from_str)) {
689 if (matched && *to_str) {
691 !str_find_func(msginfo->to, to_str)) {
695 if (matched && *subject_str) {
696 if (!msginfo->subject ||
697 !str_find_func(msginfo->subject, subject_str)) {
701 if (matched && *body_str) {
702 if (procmime_find_string(msginfo, body_str,
709 if (matched && !*from_str && !*to_str &&
710 !*subject_str && !*body_str) {
715 if (*from_str && msginfo->from) {
716 if (str_find_func(msginfo->from, from_str)) {
720 if (!matched && *to_str && msginfo->to) {
721 if (str_find_func(msginfo->to, to_str)) {
725 if (!matched && *subject_str && msginfo->subject) {
726 if (str_find_func(msginfo->subject, subject_str)) {
730 if (!matched && *body_str) {
731 if (procmime_find_string(msginfo, body_str,
742 gtk_ctree_select(ctree, node);
744 if (messageview_is_visible
745 (summaryview->messageview)) {
746 summary_unlock(summaryview);
748 (summaryview, node, TRUE, TRUE);
749 summary_lock(summaryview);
751 messageview_search_string
752 (summaryview->messageview,
753 body_str, case_sens);
757 (summaryview, node, FALSE, TRUE);
763 node = backward ? gtkut_ctree_node_prev(ctree, node)
764 : gtkut_ctree_node_next(ctree, node);
765 if (i % interval == 0)
769 search_window.is_searching = FALSE;
770 summary_hide_stop_button();
771 main_window_cursor_normal(summaryview->mainwin);
773 summary_thaw(summaryview);
775 summary_unlock(summaryview);
778 static void summary_search_clear(GtkButton *button, gpointer data)
780 if (gtk_toggle_button_get_active
781 (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn))) {
782 gtk_entry_set_text(GTK_ENTRY(GTK_BIN(search_window.adv_condition_entry)->child), "");
784 gtk_entry_set_text(GTK_ENTRY(GTK_BIN(search_window.from_entry)->child), "");
785 gtk_entry_set_text(GTK_ENTRY(GTK_BIN(search_window.to_entry)->child), "");
786 gtk_entry_set_text(GTK_ENTRY(GTK_BIN(search_window.subject_entry)->child), "");
787 gtk_entry_set_text(GTK_ENTRY(GTK_BIN(search_window.body_entry)->child), "");
790 if (search_window.is_searching) {
791 search_window.is_searching = FALSE;
795 static void summary_search_prev_clicked(GtkButton *button, gpointer data)
797 summary_search_execute(TRUE, FALSE);
800 static void summary_search_next_clicked(GtkButton *button, gpointer data)
802 summary_search_execute(FALSE, FALSE);
805 static void summary_search_all_clicked(GtkButton *button, gpointer data)
807 summary_search_execute(FALSE, TRUE);
810 static void adv_condition_btn_done(MatcherList * matchers)
815 mainwindow_get_mainwindow()->summaryview->quicksearch != NULL);
817 if (matchers == NULL) {
821 str = matcherlist_to_string(matchers);
824 gtk_entry_set_text(GTK_ENTRY(GTK_BIN(search_window.adv_condition_entry)->child), str);
829 static void summary_search_stop_clicked(GtkButton *button, gpointer data)
831 search_window.is_searching = FALSE;
834 static void adv_condition_btn_clicked(GtkButton *button, gpointer data)
836 const gchar * cond_str;
837 MatcherList * matchers = NULL;
839 g_return_if_fail( search_window.window != NULL );
841 /* re-use the current search value if it's a condition expression,
842 otherwise ignore it silently */
843 cond_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.adv_condition_entry));
844 if (*cond_str != '\0') {
845 matchers = matcher_parser_get_cond((gchar*)cond_str, NULL);
848 prefs_matcher_open(matchers, adv_condition_btn_done);
850 if (matchers != NULL) {
851 matcherlist_free(matchers);
855 static void from_changed(void)
857 if (!search_window.from_entry_has_focus)
858 gtk_widget_grab_focus(search_window.from_entry);
861 static void to_changed(void)
863 if (!search_window.to_entry_has_focus)
864 gtk_widget_grab_focus(search_window.to_entry);
867 static void subject_changed(void)
869 if (!search_window.subject_entry_has_focus)
870 gtk_widget_grab_focus(search_window.subject_entry);
873 static void body_changed(void)
875 if (!search_window.body_entry_has_focus)
876 gtk_widget_grab_focus(search_window.body_entry);
879 static void adv_condition_changed(void)
881 if (!search_window.adv_condition_entry_has_focus)
882 gtk_widget_grab_focus(search_window.adv_condition_entry);
885 static gboolean from_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
888 search_window.from_entry_has_focus = TRUE;
892 static gboolean from_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
895 search_window.from_entry_has_focus = FALSE;
899 static gboolean to_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
902 search_window.to_entry_has_focus = TRUE;
906 static gboolean to_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
909 search_window.to_entry_has_focus = FALSE;
913 static gboolean subject_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
916 search_window.subject_entry_has_focus = TRUE;
920 static gboolean subject_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
923 search_window.subject_entry_has_focus = FALSE;
927 static gboolean body_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
930 search_window.body_entry_has_focus = TRUE;
934 static gboolean body_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
937 search_window.body_entry_has_focus = FALSE;
941 static gboolean adv_condition_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
944 search_window.adv_condition_entry_has_focus = TRUE;
948 static gboolean adv_condition_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
951 search_window.adv_condition_entry_has_focus = FALSE;
955 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
958 if (event && (event->keyval == GDK_Escape)) {
960 - stop a running search
961 - close the search window if no search is running
963 if (!search_window.is_searching) {
964 gtk_widget_hide(search_window.window);
966 search_window.is_searching = FALSE;
970 if (event && (event->keyval == GDK_Return)) {
971 if (!search_window.is_searching) {
972 summary_search_execute(FALSE, FALSE);
976 if (event && (event->keyval == GDK_Down || event->keyval == GDK_Up)) {
977 if (search_window.from_entry_has_focus) {
978 combobox_set_value_from_arrow_key(
979 GTK_COMBO_BOX(search_window.from_entry),
983 if (search_window.to_entry_has_focus) {
984 combobox_set_value_from_arrow_key(
985 GTK_COMBO_BOX(search_window.to_entry),
989 if (search_window.subject_entry_has_focus) {
990 combobox_set_value_from_arrow_key(
991 GTK_COMBO_BOX(search_window.subject_entry),
995 if (search_window.body_entry_has_focus) {
996 combobox_set_value_from_arrow_key(
997 GTK_COMBO_BOX(search_window.body_entry),
1001 if (search_window.adv_condition_entry_has_focus) {
1002 combobox_set_value_from_arrow_key(
1003 GTK_COMBO_BOX(search_window.adv_condition_entry),