/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
-#if !GTK_CHECK_VERSION(3, 0, 0)
#include "gtk/gtksctree.h"
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "prefs_gtk.h"
#include "manage_window.h"
#include "alertpanel.h"
+#include "advsearch.h"
#include "matcher.h"
#include "matcher_parser.h"
#include "prefs_matcher.h"
#include "manual.h"
#include "prefs_common.h"
+#include "statusbar.h"
static struct SummarySearchWindow {
GtkWidget *window;
GtkWidget *bool_optmenu;
+ GtkWidget *from_label;
GtkWidget *from_entry;
+ GtkWidget *to_label;
GtkWidget *to_entry;
+ GtkWidget *subject_label;
GtkWidget *subject_entry;
+ GtkWidget *body_label;
GtkWidget *body_entry;
+ GtkWidget *adv_condition_label;
GtkWidget *adv_condition_entry;
GtkWidget *adv_condition_btn;
GtkWidget *adv_search_checkbtn;
SummaryView *summaryview;
- MatcherList *matcher_list;
+ AdvancedSearch *advsearch;
+ gboolean is_fast;
+ gboolean matcher_is_outdated;
+ gboolean search_in_progress;
+ GHashTable *matched_msgnums;
gboolean is_searching;
gboolean from_entry_has_focus;
gboolean adv_condition_entry_has_focus;
} search_window;
+static gchar* add_history_get(GtkWidget *from, GList **history);
+
static void summary_search_create (void);
+static gboolean summary_search_verify_match (MsgInfo *msg);
+static gboolean summary_search_prepare_matcher ();
+static gboolean summary_search_prereduce_msg_list ();
+
static void summary_search_execute (gboolean backward,
gboolean search_all);
static void adv_condition_btn_clicked (GtkButton *button,
gpointer data);
+static void optmenu_changed (GtkComboBox *widget, gpointer user_data);
static void from_changed (void);
static void to_changed (void);
static void subject_changed (void);
static void body_changed (void);
static void adv_condition_changed (void);
+static void case_changed (GtkToggleButton *togglebutton, gpointer user_data);
static gboolean from_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
gpointer data);
gpointer data);
static gboolean adv_condition_entry_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
gpointer data);
-#ifndef MAEMO
static gboolean key_pressed (GtkWidget *widget,
GdkEventKey *event,
gpointer data);
-#endif
-#if !GTK_CHECK_VERSION(2,14,0)
-/* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
#define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
- gboolean in_btn = FALSE; \
- if (GTK_IS_BUTTON(widget)) \
- in_btn = GTK_BUTTON(widget)->in_button; \
gtk_widget_set_sensitive(widget, sensitive); \
- if (GTK_IS_BUTTON(widget)) \
- GTK_BUTTON(widget)->in_button = in_btn; \
}
-#else
-#define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
- gtk_widget_set_sensitive(widget, sensitive); \
+
+static gchar* add_history_get(GtkWidget *from, GList **history)
+{
+ gchar *result;
+
+ result = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(from));
+ if (!result)
+ result = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(from))), 0, -1);
+
+ if (result && result[0] != '\0') {
+ /* add to history */
+ combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(from));
+ *history = add_history(*history, result);
+ combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(from), *history);
+
+ return result;
+ } else {
+ g_free(result);
+ return NULL;
+ }
}
-#endif
void summary_search(SummaryView *summaryview)
{
{
gtk_widget_hide(search_window.close_btn);
gtk_widget_show(search_window.stop_btn);
+ GTK_BUTTON_SET_SENSITIVE(search_window.clear_btn, FALSE)
GTK_BUTTON_SET_SENSITIVE(search_window.all_btn, FALSE)
GTK_BUTTON_SET_SENSITIVE(search_window.prev_btn, FALSE)
GTK_BUTTON_SET_SENSITIVE(search_window.next_btn, FALSE)
+ gtk_widget_set_sensitive(search_window.adv_condition_label, FALSE);
+ gtk_widget_set_sensitive(search_window.adv_condition_entry, FALSE);
+ gtk_widget_set_sensitive(search_window.adv_condition_btn, FALSE);
+ gtk_widget_set_sensitive(search_window.to_label, FALSE);
+ gtk_widget_set_sensitive(search_window.to_entry, FALSE);
+ gtk_widget_set_sensitive(search_window.from_label, FALSE);
+ gtk_widget_set_sensitive(search_window.from_entry, FALSE);
+ gtk_widget_set_sensitive(search_window.subject_label, FALSE);
+ gtk_widget_set_sensitive(search_window.subject_entry, FALSE);
+ gtk_widget_set_sensitive(search_window.body_label, FALSE);
+ gtk_widget_set_sensitive(search_window.body_entry, FALSE);
+ gtk_widget_set_sensitive(search_window.bool_optmenu, FALSE);
+ gtk_widget_set_sensitive(search_window.clear_btn, FALSE);
+ gtk_widget_set_sensitive(search_window.case_checkbtn, FALSE);
+ gtk_widget_set_sensitive(search_window.adv_search_checkbtn, FALSE);
}
static void summary_hide_stop_button(void)
{
+ GTK_BUTTON_SET_SENSITIVE(search_window.clear_btn, TRUE)
gtk_widget_hide(search_window.stop_btn);
gtk_widget_show(search_window.close_btn);
+ if (gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn))) {
+ gtk_widget_set_sensitive(search_window.adv_condition_label, TRUE);
+ gtk_widget_set_sensitive(search_window.adv_condition_entry, TRUE);
+ gtk_widget_set_sensitive(search_window.adv_condition_btn, TRUE);
+ gtk_widget_set_sensitive(search_window.case_checkbtn, FALSE);
+ gtk_widget_set_sensitive(search_window.bool_optmenu, FALSE);
+ } else {
+ gtk_widget_set_sensitive(search_window.to_label, TRUE);
+ gtk_widget_set_sensitive(search_window.to_entry, TRUE);
+ gtk_widget_set_sensitive(search_window.from_label, TRUE);
+ gtk_widget_set_sensitive(search_window.from_entry, TRUE);
+ gtk_widget_set_sensitive(search_window.subject_label, TRUE);
+ gtk_widget_set_sensitive(search_window.subject_entry, TRUE);
+ gtk_widget_set_sensitive(search_window.body_label, TRUE);
+ gtk_widget_set_sensitive(search_window.body_entry, TRUE);
+ gtk_widget_set_sensitive(search_window.case_checkbtn, TRUE);
+ gtk_widget_set_sensitive(search_window.bool_optmenu, TRUE);
+ }
+ gtk_widget_set_sensitive(search_window.clear_btn, TRUE);
gtk_widget_set_sensitive(search_window.all_btn, TRUE);
gtk_widget_set_sensitive(search_window.prev_btn, TRUE);
gtk_widget_set_sensitive(search_window.next_btn, TRUE);
+ gtk_widget_set_sensitive(search_window.adv_search_checkbtn, TRUE);
}
static void summary_search_create(void)
gtk_container_set_border_width(GTK_CONTAINER (window), 8);
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
-#ifdef MAEMO
- maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
-#else
g_signal_connect(G_OBJECT(window), "key_press_event",
G_CALLBACK(key_pressed), NULL);
-#endif
MANAGE_WINDOW_SIGNALS_CONNECT(window);
vbox1 = gtk_vbox_new (FALSE, 0);
COMBOBOX_ADD(menu, _("Match any of the following"), 0);
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(bool_optmenu), &iter);
COMBOBOX_ADD(menu, _("Match all of the following"), 1);
+ g_signal_connect(G_OBJECT(bool_optmenu), "changed",
+ G_CALLBACK(optmenu_changed), NULL);
clear_btn = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
gtk_widget_show(clear_btn);
gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
- from_entry = gtk_combo_box_entry_new_text ();
+ from_entry = gtk_combo_box_text_new_with_entry ();
gtk_combo_box_set_active(GTK_COMBO_BOX(from_entry), -1);
if (prefs_common.summary_search_from_history)
- combobox_set_popdown_strings(GTK_COMBO_BOX(from_entry),
+ combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(from_entry),
prefs_common.summary_search_from_history);
gtk_widget_show (from_entry);
gtk_table_attach (GTK_TABLE (table1), from_entry, 1, 3, 0, 1,
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((from_entry)))),
"focus_out_event", G_CALLBACK(from_entry_focus_evt_out), NULL);
- to_entry = gtk_combo_box_entry_new_text ();
+ to_entry = gtk_combo_box_text_new_with_entry ();
gtk_combo_box_set_active(GTK_COMBO_BOX(to_entry), -1);
if (prefs_common.summary_search_to_history)
- combobox_set_popdown_strings(GTK_COMBO_BOX(to_entry),
+ combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(to_entry),
prefs_common.summary_search_to_history);
gtk_widget_show (to_entry);
gtk_table_attach (GTK_TABLE (table1), to_entry, 1, 3, 1, 2,
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((to_entry)))),
"focus_out_event", G_CALLBACK(to_entry_focus_evt_out), NULL);
- subject_entry = gtk_combo_box_entry_new_text ();
+ subject_entry = gtk_combo_box_text_new_with_entry ();
gtk_combo_box_set_active(GTK_COMBO_BOX(subject_entry), -1);
if (prefs_common.summary_search_subject_history)
- combobox_set_popdown_strings(GTK_COMBO_BOX(subject_entry),
+ combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(subject_entry),
prefs_common.summary_search_subject_history);
gtk_widget_show (subject_entry);
gtk_table_attach (GTK_TABLE (table1), subject_entry, 1, 3, 2, 3,
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((subject_entry)))),
"focus_out_event", G_CALLBACK(subject_entry_focus_evt_out), NULL);
- body_entry = gtk_combo_box_entry_new_text ();
+ body_entry = gtk_combo_box_text_new_with_entry ();
gtk_combo_box_set_active(GTK_COMBO_BOX(body_entry), -1);
if (prefs_common.summary_search_body_history)
- combobox_set_popdown_strings(GTK_COMBO_BOX(body_entry),
+ combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(body_entry),
prefs_common.summary_search_body_history);
gtk_widget_show (body_entry);
gtk_table_attach (GTK_TABLE (table1), body_entry, 1, 3, 3, 4,
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((body_entry)))),
"focus_out_event", G_CALLBACK(body_entry_focus_evt_out), NULL);
- adv_condition_entry = gtk_combo_box_entry_new_text ();
+ adv_condition_entry = gtk_combo_box_text_new_with_entry ();
gtk_combo_box_set_active(GTK_COMBO_BOX(adv_condition_entry), -1);
if (prefs_common.summary_search_adv_condition_history)
- combobox_set_popdown_strings(GTK_COMBO_BOX(adv_condition_entry),
+ combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(adv_condition_entry),
prefs_common.summary_search_adv_condition_history);
gtk_widget_show (adv_condition_entry);
gtk_table_attach (GTK_TABLE (table1), adv_condition_entry, 1, 2, 4, 5,
gtk_widget_show (case_checkbtn);
gtk_box_pack_start (GTK_BOX (checkbtn_hbox), case_checkbtn,
FALSE, FALSE, 0);
+ g_signal_connect(G_OBJECT(case_checkbtn), "changed",
+ G_CALLBACK(case_changed), NULL);
adv_search_checkbtn = gtk_check_button_new_with_label (_("Extended Search"));
gtk_widget_show (adv_search_checkbtn);
gtk_box_pack_start (GTK_BOX (checkbtn_hbox), adv_search_checkbtn,
FALSE, FALSE, 0);
+ g_signal_connect(G_OBJECT(adv_search_checkbtn), "changed",
+ G_CALLBACK(case_changed), NULL);
confirm_area = gtk_hbutton_box_new();
gtk_widget_show (confirm_area);
gtkut_stock_button_add_help(confirm_area, &help_btn);
all_btn = gtk_button_new_with_mnemonic(_("Find _all"));
- gtkut_widget_set_can_default(all_btn, TRUE);
+ gtk_widget_set_can_default(all_btn, TRUE);
gtk_box_pack_start(GTK_BOX(confirm_area), all_btn, TRUE, TRUE, 0);
gtk_widget_show(all_btn);
prev_btn = gtk_button_new_from_stock(GTK_STOCK_GO_BACK);
- gtkut_widget_set_can_default(prev_btn, TRUE);
+ gtk_widget_set_can_default(prev_btn, TRUE);
gtk_box_pack_start(GTK_BOX(confirm_area), prev_btn, TRUE, TRUE, 0);
gtk_widget_show(prev_btn);
next_btn = gtk_button_new_from_stock(GTK_STOCK_GO_FORWARD);
- gtkut_widget_set_can_default(next_btn, TRUE);
+ gtk_widget_set_can_default(next_btn, TRUE);
gtk_box_pack_start(GTK_BOX(confirm_area), next_btn, TRUE, TRUE, 0);
gtk_widget_show(next_btn);
close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
- gtkut_widget_set_can_default(close_btn, TRUE);
+ gtk_widget_set_can_default(close_btn, TRUE);
gtk_box_pack_start(GTK_BOX(confirm_area), close_btn, TRUE, TRUE, 0);
gtk_widget_show(close_btn);
/* stop button hidden */
stop_btn = gtk_button_new_from_stock(GTK_STOCK_STOP);
- gtkut_widget_set_can_default(stop_btn, TRUE);
+ gtk_widget_set_can_default(stop_btn, TRUE);
gtk_box_pack_start(GTK_BOX(confirm_area), stop_btn, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox1), confirm_area, FALSE, FALSE, 0);
gtk_widget_grab_default(next_btn);
SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, bool_optmenu)
+ SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, from_label)
SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, from_entry)
+ SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, to_label)
SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, to_entry)
+ SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, subject_label)
SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, subject_entry)
+ SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, body_label)
SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, body_entry)
SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_label)
SET_TOGGLE_SENSITIVITY(adv_search_checkbtn, adv_condition_entry)
search_window.window = window;
search_window.bool_optmenu = bool_optmenu;
+ search_window.from_label = from_label;
search_window.from_entry = from_entry;
+ search_window.to_label = to_label;
search_window.to_entry = to_entry;
+ search_window.subject_label = subject_label;
search_window.subject_entry = subject_entry;
+ search_window.body_label = body_label;
search_window.body_entry = body_entry;
+ search_window.adv_condition_label = adv_condition_label;
search_window.adv_condition_entry = adv_condition_entry;
search_window.adv_condition_btn = adv_condition_btn;
search_window.case_checkbtn = case_checkbtn;
search_window.next_btn = next_btn;
search_window.close_btn = close_btn;
search_window.stop_btn = stop_btn;
- search_window.matcher_list = NULL;
+ search_window.advsearch = NULL;
+ search_window.matcher_is_outdated = TRUE;
+ search_window.search_in_progress = FALSE;
+ search_window.matched_msgnums = NULL;
search_window.is_searching = is_searching;
-#ifdef MAEMO
- maemo_window_full_screen_if_needed(GTK_WINDOW(search_window.window));
-#endif
}
-static void summary_search_execute(gboolean backward, gboolean search_all)
+static gboolean summary_search_verify_match(MsgInfo *msg)
+{
+ gpointer msgnum = GUINT_TO_POINTER(msg->msgnum);
+
+ if (g_hash_table_lookup(search_window.matched_msgnums, msgnum) != NULL)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static gboolean summary_search_progress_cb(gpointer data, guint at, guint matched, guint total)
+{
+ if (!search_window.is_searching) {
+ search_window.matcher_is_outdated = TRUE;
+ return FALSE;
+ }
+
+ return summaryview_search_root_progress(search_window.summaryview, at, matched, total);
+}
+
+static gboolean summary_search_prepare_matcher()
{
- SummaryView *summaryview = search_window.summaryview;
- GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
- GtkCMCTreeNode *node;
- MsgInfo *msginfo;
gboolean adv_search;
gboolean bool_and = FALSE;
gboolean case_sens = FALSE;
- gboolean all_searched = FALSE;
- gboolean matched = FALSE;
- gboolean body_matched = FALSE;
+ gchar *matcher_str;
+ gint match_type;
gchar *from_str = NULL, *to_str = NULL, *subject_str = NULL;
gchar *body_str = NULL;
- gchar *adv_condition = NULL;
- gboolean is_fast = TRUE;
- gint interval = 1000;
- gint i = 0;
GSList *matchers = NULL;
- if (summary_is_locked(summaryview)) {
- return;
+ if (!search_window.matcher_is_outdated)
+ return TRUE;
+
+ if (search_window.advsearch == NULL) {
+ search_window.advsearch = advsearch_new();
+ advsearch_set_on_error_cb(search_window.advsearch, NULL, NULL); /* TODO */
+ advsearch_set_on_progress_cb(search_window.advsearch,
+ summary_search_progress_cb, NULL);
}
- summary_lock(summaryview);
adv_search = gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn));
+ (GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn));
- if (search_window.matcher_list != NULL) {
- matcherlist_free(search_window.matcher_list);
- search_window.matcher_list = NULL;
- }
if (adv_search) {
- adv_condition = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.adv_condition_entry));
- if (!adv_condition)
- adv_condition = gtk_editable_get_chars(
- GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.adv_condition_entry))),0,-1);
- if (adv_condition && adv_condition[0] != '\0') {
-
- /* add to history */
- combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.adv_condition_entry));
- prefs_common.summary_search_adv_condition_history = add_history(
- prefs_common.summary_search_adv_condition_history, adv_condition);
- combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.adv_condition_entry),
- prefs_common.summary_search_adv_condition_history);
-
- search_window.matcher_list = matcher_parser_get_cond((gchar*)adv_condition, &is_fast);
- if (!is_fast)
- interval = 100;
- /* TODO: check for condition parsing error and show an error dialog */
- g_free(adv_condition);
- } else {
- /* TODO: warn if no search condition? (or make buttons enabled only when
- at least one search condition has been set */
- summary_unlock(summaryview);
- return;
- }
+ matcher_str = add_history_get(search_window.adv_condition_entry, &prefs_common.summary_search_adv_condition_history);
} else {
- bool_and = combobox_get_active_data(
- GTK_COMBO_BOX(search_window.bool_optmenu));
- case_sens = gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON(search_window.case_checkbtn));
-
- from_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.from_entry));
- to_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.to_entry));
- subject_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.subject_entry));
- body_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.body_entry));
-
- if (!from_str)
- from_str = gtk_editable_get_chars(
- GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.from_entry))),0,-1);
- if (!to_str)
- to_str = gtk_editable_get_chars(
- GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.to_entry))),0,-1);
- if (!subject_str)
- subject_str = gtk_editable_get_chars(
- GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.subject_entry))),0,-1);
- if (!body_str)
- body_str = gtk_editable_get_chars(
- GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.body_entry))),0,-1);
-
- if (!from_str || !to_str || !subject_str || !body_str) {
+ MatcherList *matcher_list;
+ bool_and = combobox_get_active_data(GTK_COMBO_BOX(search_window.bool_optmenu));
+ case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_window.case_checkbtn));
+
+ from_str = add_history_get(search_window.from_entry, &prefs_common.summary_search_from_history);
+ to_str = add_history_get(search_window.to_entry, &prefs_common.summary_search_to_history);
+ subject_str = add_history_get(search_window.subject_entry, &prefs_common.summary_search_subject_history);
+ body_str = add_history_get(search_window.body_entry, &prefs_common.summary_search_body_history);
+
+ if (!from_str && !to_str && !subject_str && !body_str) {
/* TODO: warn if no search criteria? (or make buttons enabled only when
* at least one search criteria has been set */
- summary_unlock(summaryview);
- return;
- }
- if ( (from_str[0] == '\0') &&
- (to_str[0] == '\0') &&
- (subject_str[0] == '\0') &&
- (body_str[0] == '\0')) {
- /* TODO: warn if no search criteria? (or make buttons enabled only when
- at least one search criteria has been set */
- summary_unlock(summaryview);
- return;
+ return FALSE;
}
- /* add to history */
- if (from_str[0] != '\0') {
- MatcherProp *prop = matcherprop_new(MATCHCRITERIA_FROM,
- NULL, case_sens ? MATCHTYPE_MATCH:MATCHTYPE_MATCHCASE,
- from_str, 0);
+ match_type = case_sens ? MATCHTYPE_MATCH : MATCHTYPE_MATCHCASE;
+
+ if (from_str) {
+ MatcherProp *prop = matcherprop_new(MATCHCRITERIA_FROM, NULL, match_type, from_str, 0);
matchers = g_slist_append(matchers, prop);
- combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.from_entry));
- prefs_common.summary_search_from_history = add_history(
- prefs_common.summary_search_from_history, from_str);
- combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.from_entry),
- prefs_common.summary_search_from_history);
}
- if (to_str[0] != '\0') {
- MatcherProp *prop = matcherprop_new(MATCHCRITERIA_TO,
- NULL, case_sens ? MATCHTYPE_MATCH:MATCHTYPE_MATCHCASE,
- to_str, 0);
+ if (to_str) {
+ MatcherProp *prop = matcherprop_new(MATCHCRITERIA_TO, NULL, match_type, to_str, 0);
matchers = g_slist_append(matchers, prop);
- combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.to_entry));
- prefs_common.summary_search_to_history = add_history(
- prefs_common.summary_search_to_history, to_str);
- combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.to_entry),
- prefs_common.summary_search_to_history);
}
- if (subject_str[0] != '\0') {
- MatcherProp *prop = matcherprop_new(MATCHCRITERIA_SUBJECT,
- NULL, case_sens ? MATCHTYPE_MATCH:MATCHTYPE_MATCHCASE,
- subject_str, 0);
+ if (subject_str) {
+ MatcherProp *prop = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, match_type, subject_str, 0);
matchers = g_slist_append(matchers, prop);
- combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.subject_entry));
- prefs_common.summary_search_subject_history = add_history(
- prefs_common.summary_search_subject_history, subject_str);
- combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.subject_entry),
- prefs_common.summary_search_subject_history);
}
- if (body_str[0] != '\0') {
- MatcherProp *prop = matcherprop_new(MATCHCRITERIA_BODY_PART,
- NULL, case_sens ? MATCHTYPE_MATCH:MATCHTYPE_MATCHCASE,
- body_str, 0);
+ if (body_str) {
+ MatcherProp *prop = matcherprop_new(MATCHCRITERIA_BODY_PART, NULL, match_type, body_str, 0);
matchers = g_slist_append(matchers, prop);
- combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.body_entry));
- prefs_common.summary_search_body_history = add_history(
- prefs_common.summary_search_body_history, body_str);
- combobox_set_popdown_strings(GTK_COMBO_BOX(search_window.body_entry),
- prefs_common.summary_search_body_history);
}
- search_window.matcher_list = matcherlist_new(matchers, bool_and);
+ g_free(from_str);
+ g_free(to_str);
+ g_free(subject_str);
+ g_free(body_str);
+
+ matcher_list = matcherlist_new(matchers, bool_and);
+ if (!matcher_list)
+ return FALSE;
+
+ matcher_str = matcherlist_to_string(matcher_list);
+ matcherlist_free(matcher_list);
}
+ if (!matcher_str)
+ return FALSE;
+
+ advsearch_set(search_window.advsearch, ADVANCED_SEARCH_EXTENDED,
+ matcher_str);
+
+ debug_print("Advsearch set: %s\n", matcher_str);
+ g_free(matcher_str);
+
+ if (!advsearch_has_proper_predicate(search_window.advsearch))
+ return FALSE;
+
+ search_window.matcher_is_outdated = FALSE;
+
+ return TRUE;
+}
+
+static gboolean summary_search_prereduce_msg_list()
+{
+ MsgInfoList *msglist = NULL;
+ MsgNumberList *msgnums = NULL;
+ MsgNumberList *cur;
+ SummaryView *summaryview = search_window.summaryview;
+ gboolean result;
+ FolderItem *item = summaryview->folder_item;
+ static GdkCursor *watch_cursor = NULL;
+ if (!watch_cursor)
+ watch_cursor = gdk_cursor_new(GDK_WATCH);
+
+ if (search_window.matcher_is_outdated && !summary_search_prepare_matcher())
+ return FALSE;
+
+ main_window_cursor_wait(mainwindow_get_mainwindow());
+ gdk_window_set_cursor(gtk_widget_get_window(search_window.window), watch_cursor);
+ statusbar_print_all(_("Searching in %s... \n"),
+ item->path ? item->path : "(null)");
+
+ result = advsearch_search_msgs_in_folders(search_window.advsearch,
+ &msglist, item, FALSE);
+ statusbar_pop_all();
+ statusbar_progress_all(0, 0, 0);
+ gdk_window_set_cursor(gtk_widget_get_window(search_window.window), NULL);
+ main_window_cursor_normal(mainwindow_get_mainwindow());
+
+ if (!result)
+ return FALSE;
+
+ msgnums = procmsg_get_number_list_for_msgs(msglist);
+ procmsg_msg_list_free(msglist);
+
+ if (search_window.matched_msgnums == NULL)
+ search_window.matched_msgnums = g_hash_table_new(g_direct_hash, NULL);
+
+ g_hash_table_remove_all(search_window.matched_msgnums);
+
+ for (cur = msgnums; cur != NULL; cur = cur->next)
+ g_hash_table_insert(search_window.matched_msgnums, cur->data, GINT_TO_POINTER(1));
+
+ g_slist_free(msgnums);
+
+ return TRUE;
+}
+
+static void summary_search_execute(gboolean backward, gboolean search_all)
+{
+ SummaryView *summaryview = search_window.summaryview;
+ GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
+ GtkCMCTreeNode *node;
+ MsgInfo *msginfo;
+ gboolean all_searched = FALSE;
+ gboolean matched = FALSE;
+ gint i = 0;
+
+ if (summary_is_locked(summaryview))
+ return;
+
+ summary_lock(summaryview);
search_window.is_searching = TRUE;
main_window_cursor_wait(summaryview->mainwin);
summary_show_stop_button();
+ if (search_window.matcher_is_outdated && !summary_search_prereduce_msg_list())
+ goto exit;
+
if (search_all) {
summary_freeze(summaryview);
summary_unselect_all(summaryview);
node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
backward = FALSE;
} else if (!summaryview->selected) {
- if (backward) {
+ /* no selection, search from from list start */
+ if (backward)
node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list_end);
- } else {
+ else
node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
- }
if (!node) {
search_window.is_searching = FALSE;
return;
}
} else {
- if (backward) {
- node = gtkut_ctree_node_prev
- (ctree, summaryview->selected);
- } else {
- node = gtkut_ctree_node_next
- (ctree, summaryview->selected);
- }
+ /* search from current selection */
+ if (backward)
+ node = gtkut_ctree_node_prev(ctree, summaryview->selected);
+ else
+ node = gtkut_ctree_node_next(ctree, summaryview->selected);
}
for (; search_window.is_searching; i++) {
gchar *str;
AlertValue val;
- if (search_all) {
+ if (search_all)
break;
- }
if (all_searched) {
alertpanel_full(_("Search failed"),
_("Search string not found."),
- GTK_STOCK_CLOSE, NULL, NULL, FALSE,
- NULL, ALERT_WARNING, G_ALERTDEFAULT);
+ GTK_STOCK_CLOSE, NULL, NULL, ALERTFOCUS_FIRST,
+ FALSE, NULL, ALERT_WARNING);
break;
}
str = _("End of list reached; continue from beginning?");
val = alertpanel(_("Search finished"), str,
- GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
+ GTK_STOCK_NO, GTK_STOCK_YES, NULL,
+ ALERTFOCUS_SECOND);
if (G_ALERTALTERNATE == val) {
if (backward) {
- node = GTK_CMCTREE_NODE
- (GTK_CMCLIST(ctree)->row_list_end);
+ node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list_end);
} else {
- node = GTK_CMCTREE_NODE
- (GTK_CMCLIST(ctree)->row_list);
+ node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
}
all_searched = TRUE;
manage_window_focus_in(search_window.window, NULL, NULL);
- } else {
+ } else
break;
- }
}
msginfo = gtk_cmctree_node_get_row_data(ctree, node);
- body_matched = FALSE;
- matched = matcherlist_match(search_window.matcher_list, msginfo);
+ if (msginfo)
+ matched = summary_search_verify_match(msginfo);
+ else
+ matched = FALSE;
if (matched) {
if (search_all) {
gtk_cmctree_select(ctree, node);
} else {
- if (messageview_is_visible
- (summaryview->messageview)) {
- summary_unlock(summaryview);
- summary_select_node
- (summaryview, node, TRUE, TRUE);
- summary_lock(summaryview);
- if (body_matched) {
- messageview_search_string
- (summaryview->messageview,
- body_str, case_sens);
- }
- } else {
- summary_select_node
- (summaryview, node, FALSE, TRUE);
- }
+ summary_unlock(summaryview);
+ summary_select_node(summaryview, node,
+ OPEN_SELECTED_ON_SEARCH_RESULTS);
+ summary_lock(summaryview);
break;
}
}
+ if (i % (search_window.is_fast ? 1000 : 100) == 0)
+ GTK_EVENTS_FLUSH();
+
node = backward ? gtkut_ctree_node_prev(ctree, node)
: gtkut_ctree_node_next(ctree, node);
- if (i % interval == 0)
- GTK_EVENTS_FLUSH();
}
- g_free(from_str);
- g_free(to_str);
- g_free(subject_str);
- g_free(body_str);
-
+exit:
search_window.is_searching = FALSE;
summary_hide_stop_button();
main_window_cursor_normal(summaryview->mainwin);
- if (search_all) {
- summary_thaw(summaryview);
- }
+ if (search_all)
+ summary_thaw_with_status(summaryview);
summary_unlock(summaryview);
}
if (search_window.is_searching) {
search_window.is_searching = FALSE;
}
+ search_window.matcher_is_outdated = TRUE;
}
static void summary_search_prev_clicked(GtkButton *button, gpointer data)
}
str = matcherlist_to_string(matchers);
+ search_window.matcher_is_outdated = TRUE;
if (str != NULL) {
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((search_window.adv_condition_entry)))), str);
/* re-use the current search value if it's a condition expression,
otherwise ignore it silently */
- cond_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.adv_condition_entry));
+ cond_str = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(search_window.adv_condition_entry));
if (cond_str && *cond_str != '\0') {
matchers = matcher_parser_get_cond((gchar*)cond_str, NULL);
}
}
};
+static void optmenu_changed(GtkComboBox *widget, gpointer user_data)
+{
+ search_window.matcher_is_outdated = TRUE;
+}
+
static void from_changed(void)
{
if (!search_window.from_entry_has_focus)
gtk_widget_grab_focus(search_window.from_entry);
+ search_window.matcher_is_outdated = TRUE;
}
static void to_changed(void)
{
if (!search_window.to_entry_has_focus)
gtk_widget_grab_focus(search_window.to_entry);
+ search_window.matcher_is_outdated = TRUE;
}
static void subject_changed(void)
{
if (!search_window.subject_entry_has_focus)
gtk_widget_grab_focus(search_window.subject_entry);
+ search_window.matcher_is_outdated = TRUE;
}
static void body_changed(void)
{
if (!search_window.body_entry_has_focus)
gtk_widget_grab_focus(search_window.body_entry);
+ search_window.matcher_is_outdated = TRUE;
}
static void adv_condition_changed(void)
{
if (!search_window.adv_condition_entry_has_focus)
gtk_widget_grab_focus(search_window.adv_condition_entry);
+ search_window.matcher_is_outdated = TRUE;
+}
+
+static void case_changed(GtkToggleButton *togglebutton, gpointer user_data)
+{
+ search_window.matcher_is_outdated = TRUE;
}
static gboolean from_entry_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
search_window.adv_condition_entry_has_focus = FALSE;
return FALSE;
}
-#ifndef MAEMO
+
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
gpointer data)
{
return FALSE;
}
-#endif