[Commits] summary_search.c 1.15.2.71 1.15.2.72 summaryview.c 1.395.2.455 1.395.2.456 summaryview.h 1.68.2.62 1.68.2.63

colin at claws-mail.org colin at claws-mail.org
Wed Sep 26 10:54:07 CEST 2012


Update of /home/claws-mail/claws/src
In directory srv:/tmp/cvs-serv28093/src

Modified Files:
      Tag: gtk2
	summary_search.c summaryview.c summaryview.h 
Log Message:
2012-09-26 [colin]	3.8.1cvs76

	* src/summary_search.c
	* src/summaryview.c
	* src/summaryview.h
	* src/gtk/quicksearch.c
		Factorize search code in summary_search and
		add a progress indicator as that slows down
		the first result in case of body search.

Index: summaryview.h
===================================================================
RCS file: /home/claws-mail/claws/src/summaryview.h,v
retrieving revision 1.68.2.62
retrieving revision 1.68.2.63
diff -u -d -r1.68.2.62 -r1.68.2.63
--- summaryview.h	21 Sep 2012 10:19:43 -0000	1.68.2.62
+++ summaryview.h	26 Sep 2012 08:54:05 -0000	1.68.2.63
@@ -328,4 +328,5 @@
 void summary_relayout(SummaryView *summaryview);
 void summary_update_unread(SummaryView *summaryview, FolderItem *removed_item);
 gboolean summary_is_list(SummaryView *summaryview);
+gboolean summaryview_search_root_progress(gpointer data, guint at, guint matched, guint total);
 #endif /* __SUMMARY_H__ */

Index: summaryview.c
===================================================================
RCS file: /home/claws-mail/claws/src/summaryview.c,v
retrieving revision 1.395.2.455
retrieving revision 1.395.2.456
diff -u -d -r1.395.2.455 -r1.395.2.456
--- summaryview.c	26 Sep 2012 07:39:32 -0000	1.395.2.455
+++ summaryview.c	26 Sep 2012 08:54:05 -0000	1.395.2.456
@@ -1211,7 +1211,7 @@
 	return TRUE;
 }
 
-static gboolean summaryview_quicksearch_root_progress(gpointer data, guint at, guint matched, guint total)
+gboolean summaryview_search_root_progress(gpointer data, guint at, guint matched, guint total)
 {
 	SummaryView *summaryview = (SummaryView*) data;
 
@@ -1369,7 +1369,7 @@
 
 		folder_item_update_freeze();
 
-		quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_quicksearch_root_progress, summaryview);
+		quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_search_root_progress, summaryview);
 		quicksearch_run_on_folder(summaryview->quicksearch, summaryview->folder_item, &mlist);
 
 		folder_item_update_thaw();

Index: summary_search.c
===================================================================
RCS file: /home/claws-mail/claws/src/summary_search.c,v
retrieving revision 1.15.2.71
retrieving revision 1.15.2.72
diff -u -d -r1.15.2.71 -r1.15.2.72
--- summary_search.c	21 Sep 2012 10:19:43 -0000	1.15.2.71
+++ summary_search.c	26 Sep 2012 08:54:05 -0000	1.15.2.72
@@ -47,6 +47,7 @@
 #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"
@@ -79,12 +80,11 @@
 
 	SummaryView *summaryview;
 
-	MatcherList	*matcher_list;
+	AdvancedSearch	*advsearch;
 	gboolean	is_fast;
 	gboolean	matcher_is_outdated;
 	gboolean	search_in_progress;
 	GHashTable	*matched_msgnums;
-	GHashTable	*unverified_msgnums;
 
 	gboolean is_searching;
 	gboolean from_entry_has_focus;
@@ -515,11 +515,10 @@
 	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.unverified_msgnums = NULL;
 	search_window.is_searching = is_searching;
 #ifdef MAEMO
 	maemo_window_full_screen_if_needed(GTK_WINDOW(search_window.window));
@@ -532,31 +531,8 @@
 
 	if (g_hash_table_lookup(search_window.matched_msgnums, msgnum) != NULL)
 		return TRUE;
-
-	if (g_hash_table_lookup(search_window.unverified_msgnums, msgnum) != NULL) {
-		GSList *num = g_slist_prepend(NULL, msgnum);
-		gint match;
-
-		match = folder_item_search_msgs(msg->folder->folder,
-		      msg->folder,
-		      &num,
-		      NULL,
-		      search_window.matcher_list,
-		      NULL,
-		      NULL);
-
-		g_slist_free(num);
-		g_hash_table_remove(search_window.unverified_msgnums, msgnum);
-
-		if (match > 0) {
-			g_hash_table_insert(search_window.matched_msgnums, msgnum, GINT_TO_POINTER(1));
-			return TRUE;
-		} else {
-			return FALSE;
-		}
-	}
-
-	return FALSE;
+	else
+		return FALSE;
 }
 
 static gboolean summary_search_prepare_matcher()
@@ -564,7 +540,7 @@
 	gboolean adv_search;
 	gboolean bool_and = FALSE;
 	gboolean case_sens = FALSE;
-	gchar *adv_condition = NULL;
+	gchar *matcher_str;
 	gint match_type;
 	gchar *from_str = NULL, *to_str = NULL, *subject_str = NULL;
 	gchar *body_str = NULL;
@@ -573,26 +549,21 @@
 	if (!search_window.matcher_is_outdated)
 		return TRUE;
 
-	if (search_window.matcher_list != NULL) {
-		matcherlist_free(search_window.matcher_list);
-		search_window.matcher_list = NULL;
+	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, 
+			summaryview_search_root_progress, 
+			search_window.summaryview);
 	}
 
 	adv_search = gtk_toggle_button_get_active
 		(GTK_TOGGLE_BUTTON(search_window.adv_search_checkbtn));
 
 	if (adv_search) {
-		adv_condition = add_history_get(search_window.adv_condition_entry, &prefs_common.summary_search_adv_condition_history);
-		if (adv_condition) {
-			search_window.matcher_list = matcher_parser_get_cond(adv_condition, &search_window.is_fast);
-			/* 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 */
-			return FALSE;
-		}
+		matcher_str = add_history_get(search_window.adv_condition_entry, &prefs_common.summary_search_adv_condition_history);
 	} else {
+		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));
 
@@ -625,13 +596,28 @@
 			MatcherProp *prop = matcherprop_new(MATCHCRITERIA_BODY_PART, NULL, match_type, body_str, 0);
 			matchers = g_slist_append(matchers, prop);
 		}
-		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;
 
@@ -640,64 +626,47 @@
 
 static gboolean summary_search_prereduce_msg_list()
 {
-	MsgInfo *msginfo;
-	FolderItem *folder;
-	gint matched_count;
+	MsgInfoList *msglist = NULL;
 	MsgNumberList *msgnums = NULL;
 	MsgNumberList *cur;
 	SummaryView *summaryview = search_window.summaryview;
-	GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
-	gboolean on_server;
+	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;
 	}
 
-	msginfo = gtk_cmctree_node_get_row_data(
-	        ctree,
-	        GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list));
-	folder = msginfo->folder;
-
-	on_server = folder->folder->klass->supports_server_search;
+	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)");
 
-	if (on_server) {
-		matched_count = folder_item_search_msgs(folder->folder,
-		              folder,
-		              &msgnums,
-		              &on_server,
-		              search_window.matcher_list,
-		              NULL,
-		              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 (matched_count < 0) {
-			alertpanel_error(_("Something went wrong during search. Please check you logs."));
-			return FALSE;
-		}
-	} else {
-		gboolean old_valid = TRUE;
+	if (!result)
+		return FALSE;
+	msgnums = procmsg_get_number_list_for_msgs(msglist);
+	procmsg_msg_list_free(msglist);
 
-		folder->folder->klass->get_num_list(folder->folder, folder, &msgnums, &old_valid);
-	}
+	if (search_window.matched_msgnums == NULL)
+		search_window.matched_msgnums = g_hash_table_new(g_direct_hash, NULL);
 
-	if (search_window.unverified_msgnums != NULL) {
-		g_hash_table_unref(search_window.unverified_msgnums);
-	}
-	if (search_window.matched_msgnums != NULL) {
-		g_hash_table_unref(search_window.matched_msgnums);
-	}
+	g_hash_table_remove_all(search_window.matched_msgnums);
 
-	search_window.unverified_msgnums = g_hash_table_new(g_direct_hash, NULL);
-	search_window.matched_msgnums = g_hash_table_new(g_direct_hash, NULL);
 	for (cur = msgnums; cur != NULL; cur = cur->next) {
-		g_hash_table_insert(search_window.unverified_msgnums, cur->data, GINT_TO_POINTER(1));
+		g_hash_table_insert(search_window.matched_msgnums, cur->data, GINT_TO_POINTER(1));
 	}
+
 	g_slist_free(msgnums);
-	
-	if (msginfo->folder->folder->klass->supports_server_search && on_server) {
-		GHashTable *tmp = search_window.matched_msgnums;
-		search_window.matched_msgnums = search_window.unverified_msgnums;
-		search_window.unverified_msgnums = tmp;
-	}
 
 	return TRUE;
 }



More information about the Commits mailing list