[evolution] Introduce an EShellView::execute-search signal.



commit 53268d5516083c47607dbd3acbbd6bafd6d15747
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Sep 2 15:21:35 2009 -0400

    Introduce an EShellView::execute-search signal.
    
    This addresses bug #593896 but is also a cleaner design than before.
    It introduces an EShellView::execute-search signal and renames the
    "search-execute" action to "search-quick" to clarify that it's only
    meant for the "quick" search bar in the main window.
    
    Shell view subclasses should implement the execute_search() method to
    actually execute a search.
    
    e_shell_view_execute_search() emits the new signal.

 doc/reference/shell/eshell-sections.txt         |    1 +
 doc/reference/shell/tmpl/e-shell-view.sgml      |    8 +
 doc/reference/shell/tmpl/eshell-unused.sgml     |    7 +
 doc/reference/shell/tmpl/shell-actions.sgml     |    8 -
 modules/addressbook/e-book-shell-view-actions.c |   30 +---
 modules/addressbook/e-book-shell-view-private.c |  108 ---------
 modules/addressbook/e-book-shell-view-private.h |    2 -
 modules/addressbook/e-book-shell-view.c         |  107 +++++++++
 modules/calendar/e-cal-shell-view-actions.c     |   30 +---
 modules/calendar/e-cal-shell-view-private.c     |  155 -------------
 modules/calendar/e-cal-shell-view.c             |  157 +++++++++++++
 modules/calendar/e-memo-shell-view-actions.c    |   30 +---
 modules/calendar/e-memo-shell-view-private.c    |  107 ---------
 modules/calendar/e-memo-shell-view-private.h    |    2 -
 modules/calendar/e-memo-shell-view.c            |  104 +++++++++
 modules/calendar/e-task-shell-view-actions.c    |   30 +---
 modules/calendar/e-task-shell-view-private.c    |  182 +---------------
 modules/calendar/e-task-shell-view-private.h    |    2 -
 modules/calendar/e-task-shell-view.c            |  177 +++++++++++++++
 modules/mail/e-mail-shell-view-actions.c        |   76 +------
 modules/mail/e-mail-shell-view-private.c        |  244 ---------------------
 modules/mail/e-mail-shell-view-private.h        |    7 +-
 modules/mail/e-mail-shell-view.c                |  267 +++++++++++++++++++++++
 shell/e-shell-content.c                         |   72 ++++---
 shell/e-shell-view.c                            |   36 +++
 shell/e-shell-view.h                            |    7 +-
 shell/e-shell-window-actions.c                  |   51 +++--
 shell/e-shell-window-actions.h                  |    4 +-
 shell/e-shell-window.c                          |    3 +
 29 files changed, 976 insertions(+), 1038 deletions(-)
---
diff --git a/doc/reference/shell/eshell-sections.txt b/doc/reference/shell/eshell-sections.txt
index 8bfb57b..3404319 100644
--- a/doc/reference/shell/eshell-sections.txt
+++ b/doc/reference/shell/eshell-sections.txt
@@ -237,6 +237,7 @@ e_shell_view_get_shell_taskbar
 e_shell_view_get_shell_window
 e_shell_view_get_state_key_file
 e_shell_view_set_state_dirty
+e_shell_view_execute_search
 e_shell_view_update_actions
 e_shell_view_show_popup_menu
 e_shell_view_new_view_instance
diff --git a/doc/reference/shell/tmpl/e-shell-view.sgml b/doc/reference/shell/tmpl/e-shell-view.sgml
index 408e869..03fe571 100644
--- a/doc/reference/shell/tmpl/e-shell-view.sgml
+++ b/doc/reference/shell/tmpl/e-shell-view.sgml
@@ -23,6 +23,13 @@ EShellView
 </para>
 
 
+<!-- ##### SIGNAL EShellView::execute-search ##### -->
+<para>
+
+</para>
+
+ eshellview: the object which received the signal.
+
 <!-- ##### SIGNAL EShellView::toggled ##### -->
 <para>
 
@@ -100,6 +107,7 @@ EShellView
 @new_shell_sidebar: 
 @new_shell_taskbar: 
 @toggled: 
+ execute_search: 
 @update_actions: 
 
 <!-- ##### FUNCTION e_shell_view_get_name ##### -->
diff --git a/doc/reference/shell/tmpl/eshell-unused.sgml b/doc/reference/shell/tmpl/eshell-unused.sgml
index 827e2a9..5f6b668 100644
--- a/doc/reference/shell/tmpl/eshell-unused.sgml
+++ b/doc/reference/shell/tmpl/eshell-unused.sgml
@@ -701,6 +701,13 @@ intelligent
 
 @window: 
 
+<!-- ##### MACRO E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE ##### -->
+<para>
+
+</para>
+
+ window: 
+
 <!-- ##### MACRO E_SUMMARY_STORAGE_NAME ##### -->
 <para>
 
diff --git a/doc/reference/shell/tmpl/shell-actions.sgml b/doc/reference/shell/tmpl/shell-actions.sgml
index 60001d6..d0fa5d6 100644
--- a/doc/reference/shell/tmpl/shell-actions.sgml
+++ b/doc/reference/shell/tmpl/shell-actions.sgml
@@ -153,14 +153,6 @@ Shell Actions
 @window: 
 
 
-<!-- ##### MACRO E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE ##### -->
-<para>
-
-</para>
-
- window: 
-
-
 <!-- ##### MACRO E_SHELL_WINDOW_ACTION_SEARCH_OPTIONS ##### -->
 <para>
 
diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c
index bbe6137..1d875ba 100644
--- a/modules/addressbook/e-book-shell-view-actions.c
+++ b/modules/addressbook/e-book-shell-view-actions.c
@@ -582,33 +582,11 @@ action_gal_save_custom_view_cb (GtkAction *action,
 }
 
 static void
-action_search_execute_cb (GtkAction *action,
-                          EBookShellView *book_shell_view)
-{
-	EShellView *shell_view;
-
-	/* All shell views respond to the activation of this action,
-	 * which is defined by EShellWindow.  But only the currently
-	 * active shell view proceeds with executing the search. */
-	shell_view = E_SHELL_VIEW (book_shell_view);
-	if (!e_shell_view_is_active (shell_view))
-		return;
-
-	e_book_shell_view_execute_search (book_shell_view);
-}
-
-static void
 action_search_filter_cb (GtkRadioAction *action,
                          GtkRadioAction *current,
-                         EBookShellView *book_shell_view)
+                         EShellView *shell_view)
 {
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-
-	shell_view = E_SHELL_VIEW (book_shell_view);
-	shell_window = e_shell_view_get_shell_window (shell_view);
-
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 }
 
 static GtkActionEntry contact_entries[] = {
@@ -1004,10 +982,6 @@ e_book_shell_view_actions_init (EBookShellView *book_shell_view)
 		ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
 		G_CALLBACK (action_gal_save_custom_view_cb), book_shell_view);
 
-	g_signal_connect (
-		ACTION (SEARCH_EXECUTE), "activate",
-		G_CALLBACK (action_search_execute_cb), book_shell_view);
-
 	e_binding_new (
 		ACTION (CONTACT_PREVIEW), "active",
 		ACTION (CONTACT_VIEW_CLASSIC), "sensitive");
diff --git a/modules/addressbook/e-book-shell-view-private.c b/modules/addressbook/e-book-shell-view-private.c
index 6770800..55a2e8c 100644
--- a/modules/addressbook/e-book-shell-view-private.c
+++ b/modules/addressbook/e-book-shell-view-private.c
@@ -516,114 +516,6 @@ e_book_shell_view_private_finalize (EBookShellView *book_shell_view)
 }
 
 void
-e_book_shell_view_execute_search (EBookShellView *book_shell_view)
-{
-	EBookShellContent *book_shell_content;
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-	EShellContent *shell_content;
-	GtkRadioAction *action;
-	GString *string;
-	EAddressbookView *view;
-	EAddressbookModel *model;
-	FilterRule *rule;
-	const gchar *format;
-	const gchar *text;
-	gchar *query;
-	gchar *temp;
-	gint value;
-
-	shell_view = E_SHELL_VIEW (book_shell_view);
-	if (!e_shell_view_is_active (shell_view))
-		return;
-
-	shell_content = e_shell_view_get_shell_content (shell_view);
-	text = e_shell_content_get_search_text (shell_content);
-
-	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = GTK_RADIO_ACTION (ACTION (CONTACT_SEARCH_ANY_FIELD_CONTAINS));
-	value = gtk_radio_action_get_current_value (action);
-
-	if (text == NULL || *text == '\0') {
-		text = "";
-		value = CONTACT_SEARCH_ANY_FIELD_CONTAINS;
-	}
-
-	switch (value) {
-		case CONTACT_SEARCH_NAME_CONTAINS:
-			format = "(contains \"full_name\" %s)";
-			break;
-
-		case CONTACT_SEARCH_EMAIL_BEGINS_WITH:
-			format = "(beginswith \"email\" %s)";
-			break;
-
-		default:
-			text = "";
-			/* fall through */
-
-		case CONTACT_SEARCH_ANY_FIELD_CONTAINS:
-			format = "(contains \"x-evolution-any-field\" %s)";
-			break;
-	}
-
-	/* Build the query. */
-	string = g_string_new ("");
-	e_sexp_encode_string (string, text);
-	query = g_strdup_printf (format, string->str);
-	g_string_free (string, TRUE);
-
-	/* Apply selected filter. */
-	value = e_shell_content_get_filter_value (shell_content);
-	switch (value) {
-		case CONTACT_FILTER_ANY_CATEGORY:
-			break;
-
-		case CONTACT_FILTER_UNMATCHED:
-			temp = g_strdup_printf (
-				"(and (not (and (exists \"CATEGORIES\") "
-				"(not (is \"CATEGORIES\" \"\")))) %s)",
-				query);
-			g_free (query);
-			query = temp;
-			break;
-
-		default:
-		{
-			GList *categories;
-			const gchar *category_name;
-
-			categories = e_categories_get_list ();
-			category_name = g_list_nth_data (categories, value);
-			g_list_free (categories);
-
-			temp = g_strdup_printf (
-				"(and (is \"category_list\" \"%s\") %s)",
-				category_name, query);
-			g_free (query);
-			query = temp;
-		}
-	}
-
-	/* XXX This is wrong.  We need to programmatically construct a
-	 *     FilterRule, tell it to build code, and pass the resulting
-	 *     expression string to EAddressbookModel. */
-	rule = filter_rule_new ();
-	e_shell_content_set_search_rule (shell_content, rule);
-	g_object_unref (rule);
-
-	/* Submit the query. */
-	book_shell_content = book_shell_view->priv->book_shell_content;
-	view = e_book_shell_content_get_current_view (book_shell_content);
-	model = e_addressbook_view_get_model (view);
-	e_addressbook_model_set_query (model, query);
-	g_free (query);
-
-	e_book_shell_content_set_preview_contact (book_shell_content, NULL);
-	book_shell_view->priv->preview_index = -1;
-}
-
-void
 e_book_shell_view_editor_weak_notify (EditorUidClosure *closure,
                                       GObject *where_the_object_was)
 {
diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h
index 31165e4..8b8da3f 100644
--- a/modules/addressbook/e-book-shell-view-private.h
+++ b/modules/addressbook/e-book-shell-view-private.h
@@ -119,8 +119,6 @@ void		e_book_shell_view_private_finalize
 
 void		e_book_shell_view_actions_init
 					(EBookShellView *book_shell_view);
-void		e_book_shell_view_execute_search
-					(EBookShellView *book_shell_view);
 void		e_book_shell_view_editor_weak_notify
 					(EditorUidClosure *closure,
 					 GObject *where_the_object_was);
diff --git a/modules/addressbook/e-book-shell-view.c b/modules/addressbook/e-book-shell-view.c
index ea48bb5..f7019b0 100644
--- a/modules/addressbook/e-book-shell-view.c
+++ b/modules/addressbook/e-book-shell-view.c
@@ -121,6 +121,112 @@ book_shell_view_constructed (GObject *object)
 }
 
 static void
+book_shell_view_execute_search (EShellView *shell_view)
+{
+	EBookShellViewPrivate *priv;
+	EBookShellContent *book_shell_content;
+	EShellWindow *shell_window;
+	EShellContent *shell_content;
+	GtkRadioAction *action;
+	GString *string;
+	EAddressbookView *view;
+	EAddressbookModel *model;
+	FilterRule *rule;
+	const gchar *format;
+	const gchar *text;
+	gchar *query;
+	gchar *temp;
+	gint value;
+
+	priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (shell_view);
+
+	shell_content = e_shell_view_get_shell_content (shell_view);
+	text = e_shell_content_get_search_text (shell_content);
+
+	shell_window = e_shell_view_get_shell_window (shell_view);
+	action = GTK_RADIO_ACTION (ACTION (CONTACT_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
+
+	if (text == NULL || *text == '\0') {
+		text = "";
+		value = CONTACT_SEARCH_ANY_FIELD_CONTAINS;
+	}
+
+	switch (value) {
+		case CONTACT_SEARCH_NAME_CONTAINS:
+			format = "(contains \"full_name\" %s)";
+			break;
+
+		case CONTACT_SEARCH_EMAIL_BEGINS_WITH:
+			format = "(beginswith \"email\" %s)";
+			break;
+
+		default:
+			text = "";
+			/* fall through */
+
+		case CONTACT_SEARCH_ANY_FIELD_CONTAINS:
+			format = "(contains \"x-evolution-any-field\" %s)";
+			break;
+	}
+
+	/* Build the query. */
+	string = g_string_new ("");
+	e_sexp_encode_string (string, text);
+	query = g_strdup_printf (format, string->str);
+	g_string_free (string, TRUE);
+
+	/* Apply selected filter. */
+	value = e_shell_content_get_filter_value (shell_content);
+	switch (value) {
+		case CONTACT_FILTER_ANY_CATEGORY:
+			break;
+
+		case CONTACT_FILTER_UNMATCHED:
+			temp = g_strdup_printf (
+				"(and (not (and (exists \"CATEGORIES\") "
+				"(not (is \"CATEGORIES\" \"\")))) %s)",
+				query);
+			g_free (query);
+			query = temp;
+			break;
+
+		default:
+		{
+			GList *categories;
+			const gchar *category_name;
+
+			categories = e_categories_get_list ();
+			category_name = g_list_nth_data (categories, value);
+			g_list_free (categories);
+
+			temp = g_strdup_printf (
+				"(and (is \"category_list\" \"%s\") %s)",
+				category_name, query);
+			g_free (query);
+			query = temp;
+		}
+	}
+
+	/* XXX This is wrong.  We need to programmatically construct a
+	 *     FilterRule, tell it to build code, and pass the resulting
+	 *     expression string to EAddressbookModel. */
+	rule = filter_rule_new ();
+	e_shell_content_set_search_rule (shell_content, rule);
+	g_object_unref (rule);
+
+	/* Submit the query. */
+	book_shell_content = E_BOOK_SHELL_CONTENT (shell_content);
+	view = e_book_shell_content_get_current_view (book_shell_content);
+	model = e_addressbook_view_get_model (view);
+	e_addressbook_model_set_query (model, query);
+	g_free (query);
+
+	e_book_shell_content_set_preview_contact (book_shell_content, NULL);
+	priv->preview_index = -1;
+}
+
+static void
 book_shell_view_update_actions (EShellView *shell_view)
 {
 	EBookShellViewPrivate *priv;
@@ -277,6 +383,7 @@ book_shell_view_class_init (EBookShellViewClass *class)
 	shell_view_class->search_rules = "addresstypes.xml";
 	shell_view_class->new_shell_content = e_book_shell_content_new;
 	shell_view_class->new_shell_sidebar = e_book_shell_sidebar_new;
+	shell_view_class->execute_search = book_shell_view_execute_search;
 	shell_view_class->update_actions = book_shell_view_update_actions;
 }
 
diff --git a/modules/calendar/e-cal-shell-view-actions.c b/modules/calendar/e-cal-shell-view-actions.c
index b36c94b..3dfb488 100644
--- a/modules/calendar/e-cal-shell-view-actions.c
+++ b/modules/calendar/e-cal-shell-view-actions.c
@@ -1154,33 +1154,11 @@ action_gal_save_custom_view_cb (GtkAction *action,
 }
 
 static void
-action_search_execute_cb (GtkAction *action,
-                          ECalShellView *cal_shell_view)
-{
-	EShellView *shell_view;
-
-	/* All shell views respond to the activation of this action,
-	 * which is defined by EShellWindow.  But only the currently
-	 * active shell view proceeds with executing the search. */
-	shell_view = E_SHELL_VIEW (cal_shell_view);
-	if (!e_shell_view_is_active (shell_view))
-		return;
-
-	e_cal_shell_view_execute_search (cal_shell_view);
-}
-
-static void
 action_search_filter_cb (GtkRadioAction *action,
                          GtkRadioAction *current,
-                         ECalShellView *cal_shell_view)
+                         EShellView *shell_view)
 {
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-
-	shell_view = E_SHELL_VIEW (cal_shell_view);
-	shell_window = e_shell_view_get_shell_window (shell_view);
-
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 }
 
 static GtkActionEntry calendar_entries[] = {
@@ -1696,10 +1674,6 @@ e_cal_shell_view_actions_init (ECalShellView *cal_shell_view)
 		ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
 		G_CALLBACK (action_gal_save_custom_view_cb), cal_shell_view);
 
-	g_signal_connect (
-		ACTION (SEARCH_EXECUTE), "activate",
-		G_CALLBACK (action_search_execute_cb), cal_shell_view);
-
 	/* Initialize the memo and task pad actions. */
 	e_cal_shell_view_memopad_actions_init (cal_shell_view);
 	e_cal_shell_view_taskpad_actions_init (cal_shell_view);
diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index 3fe5994..d88c148 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -581,161 +581,6 @@ e_cal_shell_view_private_finalize (ECalShellView *cal_shell_view)
 }
 
 void
-e_cal_shell_view_execute_search (ECalShellView *cal_shell_view)
-{
-	ECalShellContent *cal_shell_content;
-	ECalShellSidebar *cal_shell_sidebar;
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-	EShellContent *shell_content;
-	GnomeCalendar *calendar;
-	ECalendar *date_navigator;
-	GtkRadioAction *action;
-	GString *string;
-	FilterRule *rule;
-	const gchar *format;
-	const gchar *text;
-	time_t start_range;
-	time_t end_range;
-	gboolean range_search;
-	gchar *start, *end;
-	gchar *query;
-	gchar *temp;
-	gint value;
-
-	shell_view = E_SHELL_VIEW (cal_shell_view);
-	shell_content = e_shell_view_get_shell_content (shell_view);
-	text = e_shell_content_get_search_text (shell_content);
-
-	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = GTK_RADIO_ACTION (ACTION (CALENDAR_SEARCH_ANY_FIELD_CONTAINS));
-	value = gtk_radio_action_get_current_value (action);
-
-	if (text == NULL || *text == '\0') {
-		text = "";
-		value = CALENDAR_SEARCH_SUMMARY_CONTAINS;
-	}
-
-	switch (value) {
-		default:
-			text = "";
-			/* fall through */
-
-		case CALENDAR_SEARCH_SUMMARY_CONTAINS:
-			format = "(contains? \"summary\" %s)";
-			break;
-
-		case CALENDAR_SEARCH_DESCRIPTION_CONTAINS:
-			format = "(contains? \"description\" %s)";
-			break;
-
-		case CALENDAR_SEARCH_ANY_FIELD_CONTAINS:
-			format = "(contains? \"any\" %s)";
-			break;
-	}
-
-	/* Build the query. */
-	string = g_string_new ("");
-	e_sexp_encode_string (string, text);
-	query = g_strdup_printf (format, string->str);
-	g_string_free (string, TRUE);
-
-	range_search = FALSE;
-	start_range = end_range = 0;
-
-	/* Apply selected filter. */
-	value = e_shell_content_get_filter_value (shell_content);
-	switch (value) {
-		case CALENDAR_FILTER_ANY_CATEGORY:
-			break;
-
-		case CALENDAR_FILTER_UNMATCHED:
-			temp = g_strdup_printf (
-				"(and (has-categories? #f) %s)", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case CALENDAR_FILTER_ACTIVE_APPOINTMENTS:
-			/* Show a year's worth of appointments. */
-			start_range = time (NULL);
-			end_range = time_add_day (start_range, 365);
-			start = isodate_from_time_t (start_range);
-			end = isodate_from_time_t (end_range);
-
-			temp = g_strdup_printf (
-				"(and %s (occur-in-time-range? "
-				"(make-time \"%s\") (make-time \"%s\")))",
-				query, start, end);
-			g_free (query);
-			query = temp;
-
-			range_search = TRUE;
-			break;
-
-		case CALENDAR_FILTER_NEXT_7_DAYS_APPOINTMENTS:
-			start_range = time (NULL);
-			end_range = time_add_day (start_range, 7);
-			start = isodate_from_time_t (start_range);
-			end = isodate_from_time_t (end_range);
-
-			temp = g_strdup_printf (
-				"(and %s (occur-in-time-range? "
-				"(make-time \"%s\") (make-time \"%s\")))",
-				query, start, end);
-			g_free (query);
-			query = temp;
-
-			range_search = TRUE;
-			break;
-
-		default:
-		{
-			GList *categories;
-			const gchar *category_name;
-
-			categories = e_categories_get_list ();
-			category_name = g_list_nth_data (categories, value);
-			g_list_free (categories);
-
-			temp = g_strdup_printf (
-				"(and (has-categories? \"%s\") %s)",
-				category_name, query);
-			g_free (query);
-			query = temp;
-			break;
-		}
-	}
-
-	/* XXX This is wrong.  We need to programmatically construct a
-	 *     FilterRule, tell it to build code, and pass the resulting
-	 *     expressing string to ECalModel. */
-	rule = filter_rule_new ();
-	e_shell_content_set_search_rule (shell_content, rule);
-	g_object_unref (rule);
-
-	cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
-	date_navigator = e_cal_shell_sidebar_get_date_navigator (cal_shell_sidebar);
-
-	if (range_search) {
-		/* Switch to list view and hide the date navigator. */
-		action = GTK_RADIO_ACTION (ACTION (CALENDAR_VIEW_LIST));
-		gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
-		gtk_widget_hide (GTK_WIDGET (date_navigator));
-	} else {
-		/* Ensure the date navigator is visible. */
-		gtk_widget_show (GTK_WIDGET (date_navigator));
-	}
-
-	/* Submit the query. */
-	cal_shell_content = cal_shell_view->priv->cal_shell_content;
-	calendar = e_cal_shell_content_get_calendar (cal_shell_content);
-	gnome_calendar_set_search_query (
-		calendar, query, range_search, start_range, end_range);
-	g_free (query);
-}
-
-void
 e_cal_shell_view_open_event (ECalShellView *cal_shell_view,
                              ECalModelComponent *comp_data)
 {
diff --git a/modules/calendar/e-cal-shell-view.c b/modules/calendar/e-cal-shell-view.c
index d9d2179..32f12b6 100644
--- a/modules/calendar/e-cal-shell-view.c
+++ b/modules/calendar/e-cal-shell-view.c
@@ -52,6 +52,162 @@ cal_shell_view_constructed (GObject *object)
 }
 
 static void
+cal_shell_view_execute_search (EShellView *shell_view)
+{
+	ECalShellContent *cal_shell_content;
+	ECalShellSidebar *cal_shell_sidebar;
+	EShellWindow *shell_window;
+	EShellContent *shell_content;
+	EShellSidebar *shell_sidebar;
+	GnomeCalendar *calendar;
+	ECalendar *date_navigator;
+	GtkRadioAction *action;
+	GString *string;
+	FilterRule *rule;
+	const gchar *format;
+	const gchar *text;
+	time_t start_range;
+	time_t end_range;
+	gboolean range_search;
+	gchar *start, *end;
+	gchar *query;
+	gchar *temp;
+	gint value;
+
+	shell_window = e_shell_view_get_shell_window (shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
+	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
+
+	action = GTK_RADIO_ACTION (ACTION (CALENDAR_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
+
+	text = e_shell_content_get_search_text (shell_content);
+
+	if (text == NULL || *text == '\0') {
+		text = "";
+		value = CALENDAR_SEARCH_SUMMARY_CONTAINS;
+	}
+
+	switch (value) {
+		default:
+			text = "";
+			/* fall through */
+
+		case CALENDAR_SEARCH_SUMMARY_CONTAINS:
+			format = "(contains? \"summary\" %s)";
+			break;
+
+		case CALENDAR_SEARCH_DESCRIPTION_CONTAINS:
+			format = "(contains? \"description\" %s)";
+			break;
+
+		case CALENDAR_SEARCH_ANY_FIELD_CONTAINS:
+			format = "(contains? \"any\" %s)";
+			break;
+	}
+
+	/* Build the query. */
+	string = g_string_new ("");
+	e_sexp_encode_string (string, text);
+	query = g_strdup_printf (format, string->str);
+	g_string_free (string, TRUE);
+
+	range_search = FALSE;
+	start_range = end_range = 0;
+
+	/* Apply selected filter. */
+	value = e_shell_content_get_filter_value (shell_content);
+	switch (value) {
+		case CALENDAR_FILTER_ANY_CATEGORY:
+			break;
+
+		case CALENDAR_FILTER_UNMATCHED:
+			temp = g_strdup_printf (
+				"(and (has-categories? #f) %s)", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case CALENDAR_FILTER_ACTIVE_APPOINTMENTS:
+			/* Show a year's worth of appointments. */
+			start_range = time (NULL);
+			end_range = time_add_day (start_range, 365);
+			start = isodate_from_time_t (start_range);
+			end = isodate_from_time_t (end_range);
+
+			temp = g_strdup_printf (
+				"(and %s (occur-in-time-range? "
+				"(make-time \"%s\") (make-time \"%s\")))",
+				query, start, end);
+			g_free (query);
+			query = temp;
+
+			range_search = TRUE;
+			break;
+
+		case CALENDAR_FILTER_NEXT_7_DAYS_APPOINTMENTS:
+			start_range = time (NULL);
+			end_range = time_add_day (start_range, 7);
+			start = isodate_from_time_t (start_range);
+			end = isodate_from_time_t (end_range);
+
+			temp = g_strdup_printf (
+				"(and %s (occur-in-time-range? "
+				"(make-time \"%s\") (make-time \"%s\")))",
+				query, start, end);
+			g_free (query);
+			query = temp;
+
+			range_search = TRUE;
+			break;
+
+		default:
+		{
+			GList *categories;
+			const gchar *category_name;
+
+			categories = e_categories_get_list ();
+			category_name = g_list_nth_data (categories, value);
+			g_list_free (categories);
+
+			temp = g_strdup_printf (
+				"(and (has-categories? \"%s\") %s)",
+				category_name, query);
+			g_free (query);
+			query = temp;
+			break;
+		}
+	}
+
+	/* XXX This is wrong.  We need to programmatically construct a
+	 *     FilterRule, tell it to build code, and pass the resulting
+	 *     expressing string to ECalModel. */
+	rule = filter_rule_new ();
+	e_shell_content_set_search_rule (shell_content, rule);
+	g_object_unref (rule);
+
+	cal_shell_sidebar = E_CAL_SHELL_SIDEBAR (shell_sidebar);
+	date_navigator = e_cal_shell_sidebar_get_date_navigator (cal_shell_sidebar);
+
+	if (range_search) {
+		/* Switch to list view and hide the date navigator. */
+		action = GTK_RADIO_ACTION (ACTION (CALENDAR_VIEW_LIST));
+		gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+		gtk_widget_hide (GTK_WIDGET (date_navigator));
+	} else {
+		/* Ensure the date navigator is visible. */
+		gtk_widget_show (GTK_WIDGET (date_navigator));
+	}
+
+	/* Submit the query. */
+	cal_shell_content = E_CAL_SHELL_CONTENT (shell_content);
+	calendar = e_cal_shell_content_get_calendar (cal_shell_content);
+	gnome_calendar_set_search_query (
+		calendar, query, range_search, start_range, end_range);
+	g_free (query);
+}
+
+static void
 cal_shell_view_update_actions (EShellView *shell_view)
 {
 #if 0
@@ -178,6 +334,7 @@ cal_shell_view_class_init (ECalShellViewClass *class,
 	shell_view_class->search_rules = "caltypes.xml";
 	shell_view_class->new_shell_content = e_cal_shell_content_new;
 	shell_view_class->new_shell_sidebar = e_cal_shell_sidebar_new;
+	shell_view_class->execute_search = cal_shell_view_execute_search;
 	shell_view_class->update_actions = cal_shell_view_update_actions;
 }
 
diff --git a/modules/calendar/e-memo-shell-view-actions.c b/modules/calendar/e-memo-shell-view-actions.c
index 991c99b..99761b2 100644
--- a/modules/calendar/e-memo-shell-view-actions.c
+++ b/modules/calendar/e-memo-shell-view-actions.c
@@ -554,33 +554,11 @@ action_memo_view_cb (GtkRadioAction *action,
 }
 
 static void
-action_search_execute_cb (GtkAction *action,
-                          EMemoShellView *memo_shell_view)
-{
-	EShellView *shell_view;
-
-	/* All shell views respond to the activation of this action,
-	 * which is defined by EShellWindow.  But only the currently
-	 * active shell view proceeds with executing the search. */
-	shell_view = E_SHELL_VIEW (memo_shell_view);
-	if (!e_shell_view_is_active (shell_view))
-		return;
-
-	e_memo_shell_view_execute_search (memo_shell_view);
-}
-
-static void
 action_search_filter_cb (GtkRadioAction *action,
                          GtkRadioAction *current,
-                         EMemoShellView *memo_shell_view)
+                         EShellView *shell_view)
 {
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-
-	shell_view = E_SHELL_VIEW (memo_shell_view);
-	shell_window = e_shell_view_get_shell_window (shell_view);
-
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 }
 
 static GtkActionEntry memo_entries[] = {
@@ -930,10 +908,6 @@ e_memo_shell_view_actions_init (EMemoShellView *memo_shell_view)
 		ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
 		G_CALLBACK (action_gal_save_custom_view_cb), memo_shell_view);
 
-	g_signal_connect (
-		ACTION (SEARCH_EXECUTE), "activate",
-		G_CALLBACK (action_search_execute_cb), memo_shell_view);
-
 	e_binding_new (
 		ACTION (MEMO_PREVIEW), "active",
 		ACTION (MEMO_VIEW_CLASSIC), "sensitive");
diff --git a/modules/calendar/e-memo-shell-view-private.c b/modules/calendar/e-memo-shell-view-private.c
index da321d5..f1d331f 100644
--- a/modules/calendar/e-memo-shell-view-private.c
+++ b/modules/calendar/e-memo-shell-view-private.c
@@ -276,8 +276,6 @@ e_memo_shell_view_private_constructed (EMemoShellView *memo_shell_view)
 	e_memo_shell_view_update_sidebar (memo_shell_view);
 	e_memo_shell_view_update_search_filter (memo_shell_view);
 	e_memo_shell_view_update_timezone (memo_shell_view);
-
-	e_memo_shell_view_execute_search (memo_shell_view);
 }
 
 void
@@ -304,111 +302,6 @@ e_memo_shell_view_private_finalize (EMemoShellView *memo_shell_view)
 }
 
 void
-e_memo_shell_view_execute_search (EMemoShellView *memo_shell_view)
-{
-	EMemoShellContent *memo_shell_content;
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-	EShellContent *shell_content;
-	GtkRadioAction *action;
-	GString *string;
-	ECalComponentPreview *memo_preview;
-	EMemoTable *memo_table;
-	ECalModel *model;
-	FilterRule *rule;
-	const gchar *format;
-	const gchar *text;
-	gchar *query;
-	gchar *temp;
-	gint value;
-
-	shell_view = E_SHELL_VIEW (memo_shell_view);
-	shell_content = e_shell_view_get_shell_content (shell_view);
-	text = e_shell_content_get_search_text (shell_content);
-
-	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = GTK_RADIO_ACTION (ACTION (MEMO_SEARCH_ANY_FIELD_CONTAINS));
-	value = gtk_radio_action_get_current_value (action);
-
-	if (text == NULL || *text == '\0') {
-		text = "";
-		value = MEMO_SEARCH_SUMMARY_CONTAINS;
-	}
-
-	switch (value) {
-		default:
-			text = "";
-			/* fall through */
-
-		case MEMO_SEARCH_SUMMARY_CONTAINS:
-			format = "(contains? \"summary\" %s)";
-			break;
-
-		case MEMO_SEARCH_DESCRIPTION_CONTAINS:
-			format = "(contains? \"description\" %s)";
-			break;
-
-		case MEMO_SEARCH_ANY_FIELD_CONTAINS:
-			format = "(contains? \"any\" %s)";
-			break;
-	}
-
-	/* Build the query. */
-	string = g_string_new ("");
-	e_sexp_encode_string (string, text);
-	query = g_strdup_printf (format, string->str);
-	g_string_free (string, TRUE);
-
-	/* Apply selected filter. */
-	value = e_shell_content_get_filter_value (shell_content);
-	switch (value) {
-		case MEMO_FILTER_ANY_CATEGORY:
-			break;
-
-		case MEMO_FILTER_UNMATCHED:
-			temp = g_strdup_printf (
-				"(and (has-categories? #f) %s", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		default:
-		{
-			GList *categories;
-			const gchar *category_name;
-
-			categories = e_categories_get_list ();
-			category_name = g_list_nth_data (categories, value);
-			g_list_free (categories);
-
-			temp = g_strdup_printf (
-				"(and (has-categories? \"%s\") %s)",
-				category_name, query);
-			g_free (query);
-			query = temp;
-		}
-	}
-
-	/* XXX This is wrong.  We need to programmatically construct a
-	 *     FilterRule, tell it to build code, and pass the resulting
-	 *     expression string to ECalModel. */
-	rule = filter_rule_new ();
-	e_shell_content_set_search_rule (shell_content, rule);
-	g_object_unref (rule);
-
-	/* Submit the query. */
-	memo_shell_content = memo_shell_view->priv->memo_shell_content;
-	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
-	model = e_memo_table_get_model (memo_table);
-	e_cal_model_set_search_query (model, query);
-	g_free (query);
-
-	memo_preview =
-		e_memo_shell_content_get_memo_preview (memo_shell_content);
-	e_cal_component_preview_clear (memo_preview);
-}
-
-void
 e_memo_shell_view_open_memo (EMemoShellView *memo_shell_view,
                              ECalModelComponent *comp_data)
 {
diff --git a/modules/calendar/e-memo-shell-view-private.h b/modules/calendar/e-memo-shell-view-private.h
index 857e924..276e6e5 100644
--- a/modules/calendar/e-memo-shell-view-private.h
+++ b/modules/calendar/e-memo-shell-view-private.h
@@ -108,8 +108,6 @@ void		e_memo_shell_view_private_finalize
 
 void		e_memo_shell_view_actions_init
 					(EMemoShellView *memo_shell_view);
-void		e_memo_shell_view_execute_search
-					(EMemoShellView *memo_shell_view);
 void		e_memo_shell_view_open_memo
 					(EMemoShellView *memo_shell_view,
 					 ECalModelComponent *comp_data);
diff --git a/modules/calendar/e-memo-shell-view.c b/modules/calendar/e-memo-shell-view.c
index e2964b0..54dea9c 100644
--- a/modules/calendar/e-memo-shell-view.c
+++ b/modules/calendar/e-memo-shell-view.c
@@ -52,6 +52,109 @@ memo_shell_view_constructed (GObject *object)
 }
 
 static void
+memo_shell_view_execute_search (EShellView *shell_view)
+{
+	EMemoShellContent *memo_shell_content;
+	EShellWindow *shell_window;
+	EShellContent *shell_content;
+	GtkRadioAction *action;
+	GString *string;
+	ECalComponentPreview *memo_preview;
+	EMemoTable *memo_table;
+	ECalModel *model;
+	FilterRule *rule;
+	const gchar *format;
+	const gchar *text;
+	gchar *query;
+	gchar *temp;
+	gint value;
+
+	shell_content = e_shell_view_get_shell_content (shell_view);
+	text = e_shell_content_get_search_text (shell_content);
+
+	shell_window = e_shell_view_get_shell_window (shell_view);
+	action = GTK_RADIO_ACTION (ACTION (MEMO_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
+
+	if (text == NULL || *text == '\0') {
+		text = "";
+		value = MEMO_SEARCH_SUMMARY_CONTAINS;
+	}
+
+	switch (value) {
+		default:
+			text = "";
+			/* fall through */
+
+		case MEMO_SEARCH_SUMMARY_CONTAINS:
+			format = "(contains? \"summary\" %s)";
+			break;
+
+		case MEMO_SEARCH_DESCRIPTION_CONTAINS:
+			format = "(contains? \"description\" %s)";
+			break;
+
+		case MEMO_SEARCH_ANY_FIELD_CONTAINS:
+			format = "(contains? \"any\" %s)";
+			break;
+	}
+
+	/* Build the query. */
+	string = g_string_new ("");
+	e_sexp_encode_string (string, text);
+	query = g_strdup_printf (format, string->str);
+	g_string_free (string, TRUE);
+
+	/* Apply selected filter. */
+	value = e_shell_content_get_filter_value (shell_content);
+	switch (value) {
+		case MEMO_FILTER_ANY_CATEGORY:
+			break;
+
+		case MEMO_FILTER_UNMATCHED:
+			temp = g_strdup_printf (
+				"(and (has-categories? #f) %s", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		default:
+		{
+			GList *categories;
+			const gchar *category_name;
+
+			categories = e_categories_get_list ();
+			category_name = g_list_nth_data (categories, value);
+			g_list_free (categories);
+
+			temp = g_strdup_printf (
+				"(and (has-categories? \"%s\") %s)",
+				category_name, query);
+			g_free (query);
+			query = temp;
+		}
+	}
+
+	/* XXX This is wrong.  We need to programmatically construct a
+	 *     FilterRule, tell it to build code, and pass the resulting
+	 *     expression string to ECalModel. */
+	rule = filter_rule_new ();
+	e_shell_content_set_search_rule (shell_content, rule);
+	g_object_unref (rule);
+
+	/* Submit the query. */
+	memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content);
+	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
+	model = e_memo_table_get_model (memo_table);
+	e_cal_model_set_search_query (model, query);
+	g_free (query);
+
+	memo_preview =
+		e_memo_shell_content_get_memo_preview (memo_shell_content);
+	e_cal_component_preview_clear (memo_preview);
+}
+
+static void
 memo_shell_view_update_actions (EShellView *shell_view)
 {
 	EMemoShellViewPrivate *priv;
@@ -181,6 +284,7 @@ memo_shell_view_class_init (EMemoShellViewClass *class,
 	shell_view_class->search_rules = "memotypes.xml";
 	shell_view_class->new_shell_content = e_memo_shell_content_new;
 	shell_view_class->new_shell_sidebar = e_memo_shell_sidebar_new;
+	shell_view_class->execute_search = memo_shell_view_execute_search;
 	shell_view_class->update_actions = memo_shell_view_update_actions;
 }
 
diff --git a/modules/calendar/e-task-shell-view-actions.c b/modules/calendar/e-task-shell-view-actions.c
index 7b70ec1..7833873 100644
--- a/modules/calendar/e-task-shell-view-actions.c
+++ b/modules/calendar/e-task-shell-view-actions.c
@@ -42,33 +42,11 @@ action_gal_save_custom_view_cb (GtkAction *action,
 }
 
 static void
-action_search_execute_cb (GtkAction *action,
-                          ETaskShellView *task_shell_view)
-{
-	EShellView *shell_view;
-
-	/* All shell views respond to the activation of this action,
-	 * which is defined by EShellWindow.  But only the currently
-	 * active shell view proceeds with executing the search. */
-	shell_view = E_SHELL_VIEW (task_shell_view);
-	if (!e_shell_view_is_active (shell_view))
-		return;
-
-	e_task_shell_view_execute_search (task_shell_view);
-}
-
-static void
 action_search_filter_cb (GtkRadioAction *action,
                          GtkRadioAction *current,
-                         ETaskShellView *task_shell_view)
+                         EShellView *shell_view)
 {
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-
-	shell_view = E_SHELL_VIEW (task_shell_view);
-	shell_window = e_shell_view_get_shell_window (shell_view);
-
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 }
 
 static void
@@ -1130,10 +1108,6 @@ e_task_shell_view_actions_init (ETaskShellView *task_shell_view)
 		ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
 		G_CALLBACK (action_gal_save_custom_view_cb), task_shell_view);
 
-	g_signal_connect (
-		ACTION (SEARCH_EXECUTE), "activate",
-		G_CALLBACK (action_search_execute_cb), task_shell_view);
-
 	e_binding_new (
 		ACTION (TASK_PREVIEW), "active",
 		ACTION (TASK_VIEW_CLASSIC), "sensitive");
diff --git a/modules/calendar/e-task-shell-view-private.c b/modules/calendar/e-task-shell-view-private.c
index 3b49ddb..87bb698 100644
--- a/modules/calendar/e-task-shell-view-private.c
+++ b/modules/calendar/e-task-shell-view-private.c
@@ -41,7 +41,7 @@ task_shell_view_process_completed_tasks (ETaskShellView *task_shell_view)
 
 	/* Search query takes whether to show completed tasks into account,
 	 * so if the preference has changed we need to update the query. */
-	e_task_shell_view_execute_search (task_shell_view);
+	e_shell_view_execute_search (E_SHELL_VIEW (task_shell_view));
 
 	g_list_free (clients);
 }
@@ -354,8 +354,6 @@ e_task_shell_view_private_constructed (ETaskShellView *task_shell_view)
 	e_task_shell_view_update_sidebar (task_shell_view);
 	e_task_shell_view_update_search_filter (task_shell_view);
 	e_task_shell_view_update_timezone (task_shell_view);
-
-	e_task_shell_view_execute_search (task_shell_view);
 }
 
 void
@@ -387,184 +385,6 @@ e_task_shell_view_private_finalize (ETaskShellView *task_shell_view)
 }
 
 void
-e_task_shell_view_execute_search (ETaskShellView *task_shell_view)
-{
-	ETaskShellContent *task_shell_content;
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-	EShellContent *shell_content;
-	GtkRadioAction *action;
-	GString *string;
-	ECalComponentPreview *task_preview;
-	ECalendarTable *task_table;
-	ECalModel *model;
-	FilterRule *rule;
-	const gchar *format;
-	const gchar *text;
-	time_t start_range;
-	time_t end_range;
-	gchar *start, *end;
-	gchar *query;
-	gchar *temp;
-	gint value;
-
-	shell_view = E_SHELL_VIEW (task_shell_view);
-	shell_content = e_shell_view_get_shell_content (shell_view);
-	text = e_shell_content_get_search_text (shell_content);
-
-	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = GTK_RADIO_ACTION (ACTION (TASK_SEARCH_ANY_FIELD_CONTAINS));
-	value = gtk_radio_action_get_current_value (action);
-
-	if (text == NULL || *text == '\0') {
-		text = "";
-		value = TASK_SEARCH_SUMMARY_CONTAINS;
-	}
-
-	switch (value) {
-		default:
-			text = "";
-			/* fall through */
-
-		case TASK_SEARCH_SUMMARY_CONTAINS:
-			format = "(contains? \"summary\" %s)";
-			break;
-
-		case TASK_SEARCH_DESCRIPTION_CONTAINS:
-			format = "(contains? \"description\" %s)";
-			break;
-
-		case TASK_SEARCH_ANY_FIELD_CONTAINS:
-			format = "(contains? \"any\" %s)";
-			break;
-	}
-
-	/* Build the query. */
-	string = g_string_new ("");
-	e_sexp_encode_string (string, text);
-	query = g_strdup_printf (format, string->str);
-	g_string_free (string, TRUE);
-
-	/* Apply selected filter. */
-	value = e_shell_content_get_filter_value (shell_content);
-	switch (value) {
-		case TASK_FILTER_ANY_CATEGORY:
-			break;
-
-		case TASK_FILTER_UNMATCHED:
-			temp = g_strdup_printf (
-				"(and (has-categories? #f) %s)", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case TASK_FILTER_NEXT_7_DAYS_TASKS:
-			start_range = time (NULL);
-			end_range = time_add_day (start_range, 7);
-			start = isodate_from_time_t (start_range);
-			end = isodate_from_time_t (end_range);
-
-			temp = g_strdup_printf (
-				"(and %s (due-in-time-range? "
-				"(make-time \"%s\") (make-time \"%s\")))",
-				query, start, end);
-			g_free (query);
-			query = temp;
-			break;
-
-		case TASK_FILTER_ACTIVE_TASKS:
-			start_range = time (NULL);
-			end_range = time_add_day (start_range, 365);
-			start = isodate_from_time_t (start_range);
-			end = isodate_from_time_t (end_range);
-
-			temp = g_strdup_printf (
-				"(and %s (due-in-time-range? "
-				"(make-time \"%s\") (make-time \"%s\")) "
-				"(not (is-completed?)))",
-				query, start, end);
-			g_free (query);
-			query = temp;
-			break;
-
-		case TASK_FILTER_OVERDUE_TASKS:
-			start_range = 0;
-			end_range = time (NULL);
-			start = isodate_from_time_t (start_range);
-			end = isodate_from_time_t (end_range);
-
-			temp = g_strdup_printf (
-				"(and %s (due-in-time-range? "
-				"(make-time \"%s\") (make-time \"%s\")) "
-				"(not (is-completed?)))",
-				query, start, end);
-			g_free (query);
-			query = temp;
-			break;
-
-		case TASK_FILTER_COMPLETED_TASKS:
-			temp = g_strdup_printf (
-				"(and (is-completed?) %s)", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case TASK_FILTER_TASKS_WITH_ATTACHMENTS:
-			temp = g_strdup_printf (
-				"(and (has-attachments?) %s)", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		default:
-		{
-			GList *categories;
-			const gchar *category_name;
-
-			categories = e_categories_get_list ();
-			category_name = g_list_nth_data (categories, value);
-			g_list_free (categories);
-
-			temp = g_strdup_printf (
-				"(and (has-categories? \"%s\") %s)",
-				category_name, query);
-			g_free (query);
-			query = temp;
-			break;
-		}
-	}
-
-	/* Honor the user's preference to hide completed tasks. */
-	temp = calendar_config_get_hide_completed_tasks_sexp (FALSE);
-	if (temp != NULL) {
-		gchar *temp2;
-
-		temp2 = g_strdup_printf ("(and %s %s)", temp, query);
-		g_free (query);
-		g_free (temp);
-		query = temp2;
-	}
-
-	/* XXX This is wrong.  We need to programmatically construct a
-	 *     FilterRule, tell it to build code, and pass the resulting
-	 *     expression string to ECalModel. */
-	rule = filter_rule_new ();
-	e_shell_content_set_search_rule (shell_content, rule);
-	g_object_unref (rule);
-
-	/* Submit the query. */
-	task_shell_content = task_shell_view->priv->task_shell_content;
-	task_table = e_task_shell_content_get_task_table (task_shell_content);
-	model = e_calendar_table_get_model (task_table);
-	e_cal_model_set_search_query (model, query);
-	g_free (query);
-
-	task_preview =
-		e_task_shell_content_get_task_preview (task_shell_content);
-	e_cal_component_preview_clear (task_preview);
-}
-
-void
 e_task_shell_view_open_task (ETaskShellView *task_shell_view,
                              ECalModelComponent *comp_data)
 {
diff --git a/modules/calendar/e-task-shell-view-private.h b/modules/calendar/e-task-shell-view-private.h
index e612069..b369b4c 100644
--- a/modules/calendar/e-task-shell-view-private.h
+++ b/modules/calendar/e-task-shell-view-private.h
@@ -120,8 +120,6 @@ void		e_task_shell_view_private_finalize
 
 void		e_task_shell_view_actions_init
 					(ETaskShellView *task_shell_view);
-void		e_task_shell_view_execute_search
-					(ETaskShellView *task_shell_view);
 void		e_task_shell_view_open_task
 					(ETaskShellView *task_shell_view,
 					 ECalModelComponent *comp_data);
diff --git a/modules/calendar/e-task-shell-view.c b/modules/calendar/e-task-shell-view.c
index b1298ea..7237b1c 100644
--- a/modules/calendar/e-task-shell-view.c
+++ b/modules/calendar/e-task-shell-view.c
@@ -91,6 +91,182 @@ task_shell_view_constructed (GObject *object)
 }
 
 static void
+task_shell_view_execute_search (EShellView *shell_view)
+{
+	ETaskShellContent *task_shell_content;
+	EShellWindow *shell_window;
+	EShellContent *shell_content;
+	GtkRadioAction *action;
+	GString *string;
+	ECalComponentPreview *task_preview;
+	ECalendarTable *task_table;
+	ECalModel *model;
+	FilterRule *rule;
+	const gchar *format;
+	const gchar *text;
+	time_t start_range;
+	time_t end_range;
+	gchar *start, *end;
+	gchar *query;
+	gchar *temp;
+	gint value;
+
+	shell_content = e_shell_view_get_shell_content (shell_view);
+	text = e_shell_content_get_search_text (shell_content);
+
+	shell_window = e_shell_view_get_shell_window (shell_view);
+	action = GTK_RADIO_ACTION (ACTION (TASK_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
+
+	if (text == NULL || *text == '\0') {
+		text = "";
+		value = TASK_SEARCH_SUMMARY_CONTAINS;
+	}
+
+	switch (value) {
+		default:
+			text = "";
+			/* fall through */
+
+		case TASK_SEARCH_SUMMARY_CONTAINS:
+			format = "(contains? \"summary\" %s)";
+			break;
+
+		case TASK_SEARCH_DESCRIPTION_CONTAINS:
+			format = "(contains? \"description\" %s)";
+			break;
+
+		case TASK_SEARCH_ANY_FIELD_CONTAINS:
+			format = "(contains? \"any\" %s)";
+			break;
+	}
+
+	/* Build the query. */
+	string = g_string_new ("");
+	e_sexp_encode_string (string, text);
+	query = g_strdup_printf (format, string->str);
+	g_string_free (string, TRUE);
+
+	/* Apply selected filter. */
+	value = e_shell_content_get_filter_value (shell_content);
+	switch (value) {
+		case TASK_FILTER_ANY_CATEGORY:
+			break;
+
+		case TASK_FILTER_UNMATCHED:
+			temp = g_strdup_printf (
+				"(and (has-categories? #f) %s)", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case TASK_FILTER_NEXT_7_DAYS_TASKS:
+			start_range = time (NULL);
+			end_range = time_add_day (start_range, 7);
+			start = isodate_from_time_t (start_range);
+			end = isodate_from_time_t (end_range);
+
+			temp = g_strdup_printf (
+				"(and %s (due-in-time-range? "
+				"(make-time \"%s\") (make-time \"%s\")))",
+				query, start, end);
+			g_free (query);
+			query = temp;
+			break;
+
+		case TASK_FILTER_ACTIVE_TASKS:
+			start_range = time (NULL);
+			end_range = time_add_day (start_range, 365);
+			start = isodate_from_time_t (start_range);
+			end = isodate_from_time_t (end_range);
+
+			temp = g_strdup_printf (
+				"(and %s (due-in-time-range? "
+				"(make-time \"%s\") (make-time \"%s\")) "
+				"(not (is-completed?)))",
+				query, start, end);
+			g_free (query);
+			query = temp;
+			break;
+
+		case TASK_FILTER_OVERDUE_TASKS:
+			start_range = 0;
+			end_range = time (NULL);
+			start = isodate_from_time_t (start_range);
+			end = isodate_from_time_t (end_range);
+
+			temp = g_strdup_printf (
+				"(and %s (due-in-time-range? "
+				"(make-time \"%s\") (make-time \"%s\")) "
+				"(not (is-completed?)))",
+				query, start, end);
+			g_free (query);
+			query = temp;
+			break;
+
+		case TASK_FILTER_COMPLETED_TASKS:
+			temp = g_strdup_printf (
+				"(and (is-completed?) %s)", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case TASK_FILTER_TASKS_WITH_ATTACHMENTS:
+			temp = g_strdup_printf (
+				"(and (has-attachments?) %s)", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		default:
+		{
+			GList *categories;
+			const gchar *category_name;
+
+			categories = e_categories_get_list ();
+			category_name = g_list_nth_data (categories, value);
+			g_list_free (categories);
+
+			temp = g_strdup_printf (
+				"(and (has-categories? \"%s\") %s)",
+				category_name, query);
+			g_free (query);
+			query = temp;
+			break;
+		}
+	}
+
+	/* Honor the user's preference to hide completed tasks. */
+	temp = calendar_config_get_hide_completed_tasks_sexp (FALSE);
+	if (temp != NULL) {
+		gchar *temp2;
+
+		temp2 = g_strdup_printf ("(and %s %s)", temp, query);
+		g_free (query);
+		g_free (temp);
+		query = temp2;
+	}
+
+	/* XXX This is wrong.  We need to programmatically construct a
+	 *     FilterRule, tell it to build code, and pass the resulting
+	 *     expression string to ECalModel. */
+	rule = filter_rule_new ();
+	e_shell_content_set_search_rule (shell_content, rule);
+	g_object_unref (rule);
+
+	/* Submit the query. */
+	task_shell_content = E_TASK_SHELL_CONTENT (shell_content);
+	task_table = e_task_shell_content_get_task_table (task_shell_content);
+	model = e_calendar_table_get_model (task_table);
+	e_cal_model_set_search_query (model, query);
+	g_free (query);
+
+	task_preview =
+		e_task_shell_content_get_task_preview (task_shell_content);
+	e_cal_component_preview_clear (task_preview);
+}
+
+static void
 task_shell_view_update_actions (EShellView *shell_view)
 {
 	ETaskShellViewPrivate *priv;
@@ -255,6 +431,7 @@ task_shell_view_class_init (ETaskShellViewClass *class,
 	shell_view_class->search_rules = "tasktypes.xml";
 	shell_view_class->new_shell_content = e_task_shell_content_new;
 	shell_view_class->new_shell_sidebar = e_task_shell_sidebar_new;
+	shell_view_class->execute_search = task_shell_view_execute_search;
 	shell_view_class->update_actions = task_shell_view_update_actions;
 
 	g_object_class_install_property (
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index a16c752..adb288d 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -21,10 +21,6 @@
 
 #include "e-mail-shell-view-private.h"
 
-#define STATE_KEY_SEARCH_FILTER		"SearchFilter"
-#define STATE_KEY_SEARCH_SCOPE		"SearchScope"
-#define STATE_KEY_SEARCH_TEXT		"SearchText"
-
 static void
 action_gal_save_custom_view_cb (GtkAction *action,
                                 EMailShellView *mail_shell_view)
@@ -887,70 +883,22 @@ action_mail_view_cb (GtkRadioAction *action,
 }
 
 static void
-action_search_execute_cb (GtkAction *action,
-                          EMailShellView *mail_shell_view)
-{
-	EShellView *shell_view;
-	EShellContent *shell_content;
-	EMailReader *reader;
-	MessageList *message_list;
-	GKeyFile *key_file;
-	const gchar *folder_uri;
-
-	shell_view = E_SHELL_VIEW (mail_shell_view);
-	shell_content = e_shell_view_get_shell_content (shell_view);
-	key_file = e_shell_view_get_state_key_file (shell_view);
-
-	/* All shell views respond to the activation of this action,
-	 * which is defined by EShellWindow.  But only the currently
-	 * active shell view proceeds with executing the search. */
-	if (!e_shell_view_is_active (shell_view))
-		return;
-
-	reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content);
-	message_list = e_mail_reader_get_message_list (reader);
-	folder_uri = message_list->folder_uri;
-
-	if (folder_uri != NULL) {
-		const gchar *key;
-		const gchar *string;
-		gchar *group_name;
-
-		key = STATE_KEY_SEARCH_TEXT;
-		string = e_shell_content_get_search_text (shell_content);
-		group_name = g_strdup_printf ("Folder %s", folder_uri);
-
-		if (string != NULL && *string != '\0')
-			g_key_file_set_string (
-				key_file, group_name, key, string);
-		else
-			g_key_file_remove_key (
-				key_file, group_name, key, NULL);
-		e_shell_view_set_state_dirty (shell_view);
-
-		g_free (group_name);
-	}
-
-	e_mail_shell_view_execute_search (mail_shell_view);
-}
-
-static void
 action_search_filter_cb (GtkRadioAction *action,
                          GtkRadioAction *current,
-                         EMailShellView *mail_shell_view)
+                         EShellView *shell_view)
 {
-	EShellView *shell_view;
+	EShellContent *shell_content;
 	EShellWindow *shell_window;
 	EMailReader *reader;
 	MessageList *message_list;
 	GKeyFile *key_file;
 	const gchar *folder_uri;
 
-	shell_view = E_SHELL_VIEW (mail_shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
 	shell_window = e_shell_view_get_shell_window (shell_view);
 	key_file = e_shell_view_get_state_key_file (shell_view);
 
-	reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content);
+	reader = E_MAIL_READER (shell_content);
 	message_list = e_mail_reader_get_message_list (reader);
 	folder_uri = message_list->folder_uri;
 
@@ -969,26 +917,26 @@ action_search_filter_cb (GtkRadioAction *action,
 		g_free (group_name);
 	}
 
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 }
 
 static void
 action_search_scope_cb (GtkRadioAction *action,
                         GtkRadioAction *current,
-                        EMailShellView *mail_shell_view)
+                        EShellView *shell_view)
 {
-	EShellView *shell_view;
+	EShellContent *shell_content;
 	EShellWindow *shell_window;
 	EMailReader *reader;
 	MessageList *message_list;
 	GKeyFile *key_file;
 	const gchar *folder_uri;
 
-	shell_view = E_SHELL_VIEW (mail_shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
 	shell_window = e_shell_view_get_shell_window (shell_view);
 	key_file = e_shell_view_get_state_key_file (shell_view);
 
-	reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content);
+	reader = E_MAIL_READER (shell_content);
 	message_list = e_mail_reader_get_message_list (reader);
 	folder_uri = message_list->folder_uri;
 
@@ -1007,7 +955,7 @@ action_search_scope_cb (GtkRadioAction *action,
 		g_free (group_name);
 	}
 
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 }
 
 static GtkActionEntry mail_entries[] = {
@@ -1600,10 +1548,6 @@ e_mail_shell_view_actions_init (EMailShellView *mail_shell_view)
 	g_signal_connect (
 		ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
 		G_CALLBACK (action_gal_save_custom_view_cb), mail_shell_view);
-
-	g_signal_connect (
-		ACTION (SEARCH_EXECUTE), "activate",
-		G_CALLBACK (action_search_execute_cb), mail_shell_view);
 }
 
 /* Helper for e_mail_shell_view_update_popup_labels() */
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index 067900b..984c3ac 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -491,250 +491,6 @@ e_mail_shell_view_restore_state (EMailShellView *mail_shell_view)
 	g_free (group_name);
 }
 
-void
-e_mail_shell_view_execute_search (EMailShellView *mail_shell_view)
-{
-	EShell *shell;
-	EShellView *shell_view;
-	EShellWindow *shell_window;
-	EShellContent *shell_content;
-	EShellSettings *shell_settings;
-	EMFormatHTMLDisplay *html_display;
-	EMailShellContent *mail_shell_content;
-	MessageList *message_list;
-	FilterRule *rule;
-	EMailReader *reader;
-	CamelFolder *folder;
-	GtkAction *action;
-	GtkTreeModel *model;
-	GtkTreePath *path;
-	GtkTreeIter tree_iter;
-	GString *string;
-	GList *iter;
-	GSList *search_strings = NULL;
-	const gchar *folder_uri;
-	const gchar *text;
-	gboolean valid;
-	gchar *query;
-	gchar *temp;
-	gchar *tag;
-	gint value;
-
-	g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view));
-
-	shell_view = E_SHELL_VIEW (mail_shell_view);
-	shell_window = e_shell_view_get_shell_window (shell_view);
-	shell_content = e_shell_view_get_shell_content (shell_view);
-
-	shell = e_shell_window_get_shell (shell_window);
-	shell_settings = e_shell_get_shell_settings (shell);
-
-	mail_shell_content = mail_shell_view->priv->mail_shell_content;
-
-	reader = E_MAIL_READER (shell_content);
-	html_display = e_mail_reader_get_html_display (reader);
-	message_list = e_mail_reader_get_message_list (reader);
-
-	folder_uri = message_list->folder_uri;
-	folder = message_list->folder;
-
-	/* This returns a new object reference. */
-	model = e_shell_settings_get_object (
-		shell_settings, "mail-label-list-store");
-
-	text = e_shell_content_get_search_text (shell_content);
-	if (text == NULL || *text == '\0') {
-		query = g_strdup ("");
-		goto filter;
-	}
-
-	/* Replace variables in the selected rule with the
-	 * current search text and extract a query string. */
-
-	action = ACTION (MAIL_SEARCH_SUBJECT_OR_SENDER_CONTAINS);
-	value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
-	g_return_if_fail (value >= 0 && value < MAIL_NUM_SEARCH_RULES);
-	rule = mail_shell_view->priv->search_rules[value];
-
-	for (iter = rule->parts; iter != NULL; iter = iter->next) {
-		FilterPart *part = iter->data;
-		FilterElement *element = NULL;
-
-		if (strcmp (part->name, "subject") == 0)
-			element = filter_part_find_element (part, "subject");
-		else if (strcmp (part->name, "body") == 0)
-			element = filter_part_find_element (part, "word");
-		else if (strcmp (part->name, "sender") == 0)
-			element = filter_part_find_element (part, "sender");
-		else if (strcmp (part->name, "to") == 0)
-			element = filter_part_find_element (part, "recipient");
-
-		if (strcmp (part->name, "body") == 0) {
-			struct _camel_search_words *words;
-			gint ii;
-
-			words = camel_search_words_split ((guchar *) text);
-			for (ii = 0; ii < words->len; ii++)
-				search_strings = g_slist_prepend (
-					search_strings, g_strdup (
-					words->words[ii]->word));
-			camel_search_words_free (words);
-		}
-
-		if (element != NULL) {
-			FilterInput *input = FILTER_INPUT (element);
-			filter_input_set_value (input, text);
-		}
-	}
-
-	string = g_string_sized_new (1024);
-	filter_rule_build_code (rule, string);
-	query = g_string_free (string, FALSE);
-
-filter:
-
-	/* Apply selected filter. */
-
-	value = e_shell_content_get_filter_value (shell_content);
-	switch (value) {
-		case MAIL_FILTER_ALL_MESSAGES:
-			break;
-
-		case MAIL_FILTER_UNREAD_MESSAGES:
-			temp = g_strdup_printf (
-				"(and %s (match-all (not "
-				"(system-flag \"Seen\"))))", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case MAIL_FILTER_NO_LABEL:
-			string = g_string_sized_new (1024);
-			g_string_append_printf (
-				string, "(and %s (and ", query);
-			valid = gtk_tree_model_get_iter_first (
-				model, &tree_iter);
-			while (valid) {
-				tag = e_mail_label_list_store_get_tag (
-					E_MAIL_LABEL_LIST_STORE (model),
-					&tree_iter);
-				g_string_append_printf (
-					string, " (match-all (not (or "
-					"(= (user-tag \"label\") \"%s\") "
-					"(user-flag \"$Label%s\") "
-					"(user-flag \"%s\"))))",
-					tag, tag, tag);
-				g_free (tag);
-
-				valid = gtk_tree_model_iter_next (
-					model, &tree_iter);
-			}
-			g_string_append_len (string, "))", 2);
-			g_free (query);
-			query = g_string_free (string, FALSE);
-			break;
-
-		case MAIL_FILTER_READ_MESSAGES:
-			temp = g_strdup_printf (
-				"(and %s (match-all "
-				"(system-flag \"Seen\")))", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case MAIL_FILTER_RECENT_MESSAGES:
-			if (em_utils_folder_is_sent (folder, folder_uri))
-				temp = g_strdup_printf (
-					"(and %s (match-all "
-					"(> (get-sent-date) "
-					"(- (get-current-date) 86400))))",
-					query);
-			else
-				temp = g_strdup_printf (
-					"(and %s (match-all "
-					"(> (get-received-date) "
-					"(- (get-current-date) 86400))))",
-					query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case MAIL_FILTER_LAST_5_DAYS_MESSAGES:
-			if (em_utils_folder_is_sent (folder, folder_uri))
-				temp = g_strdup_printf (
-					"(and %s (match-all "
-					"(> (get-sent-date) "
-					"(- (get-current-date) 432000))))",
-					query);
-			else
-				temp = g_strdup_printf (
-					"(and %s (match-all "
-					"(> (get-received-date) "
-					"(- (get-current-date) 432000))))",
-					query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case MAIL_FILTER_MESSAGES_WITH_ATTACHMENTS:
-			temp = g_strdup_printf (
-				"(and %s (match-all "
-				"(system-flag \"Attachments\")))", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case MAIL_FILTER_IMPORTANT_MESSAGES:
-			temp = g_strdup_printf (
-				"(and %s (match-all "
-				"(system-flag \"Flagged\")))", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		case MAIL_FILTER_MESSAGES_NOT_JUNK:
-			temp = g_strdup_printf (
-				"(and %s (match-all (not "
-				"(system-flag \"junk\"))))", query);
-			g_free (query);
-			query = temp;
-			break;
-
-		default:
-			/* The action value also serves as a path for
-			 * the label list store.  That's why we number
-			 * the label actions from zero. */
-			path = gtk_tree_path_new_from_indices (value, -1);
-			gtk_tree_model_get_iter (model, &tree_iter, path);
-			gtk_tree_path_free (path);
-
-			tag = e_mail_label_list_store_get_tag (
-				E_MAIL_LABEL_LIST_STORE (model), &tree_iter);
-			temp = g_strdup_printf (
-				"(and %s (match-all (or "
-				"(= (user-tag \"label\") \"%s\") "
-				"(user-flag \"$Label%s\") "
-				"(user-flag \"%s\"))))",
-				query, tag, tag, tag);
-			g_free (tag);
-
-			g_free (query);
-			query = temp;
-			break;
-	}
-
-	message_list_set_search (message_list, query);
-
-	e_mail_shell_content_set_search_strings (
-		mail_shell_content, search_strings);
-
-	g_slist_foreach (search_strings, (GFunc) g_free, NULL);
-	g_slist_free (search_strings);
-
-	g_object_unref (model);
-	g_free (query);
-}
-
 /* Helper for e_mail_shell_view_create_filter_from_selected() */
 static void
 mail_shell_view_create_filter_cb (CamelFolder *folder,
diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h
index 988d494..30724b2 100644
--- a/modules/mail/e-mail-shell-view-private.h
+++ b/modules/mail/e-mail-shell-view-private.h
@@ -80,6 +80,11 @@
 /* ETable Specifications */
 #define ETSPEC_FILENAME		"message-list.etspec"
 
+/* State File Keys */
+#define STATE_KEY_SEARCH_FILTER		"SearchFilter"
+#define STATE_KEY_SEARCH_SCOPE		"SearchScope"
+#define STATE_KEY_SEARCH_TEXT		"SearchText"
+
 G_BEGIN_DECLS
 
 /* Filter items are displayed in ascending order.
@@ -153,8 +158,6 @@ void		e_mail_shell_view_actions_init
 					(EMailShellView *mail_shell_view);
 void		e_mail_shell_view_restore_state
 					(EMailShellView *mail_shell_view);
-void		e_mail_shell_view_execute_search
-					(EMailShellView *mail_shell_view);
 void		e_mail_shell_view_create_filter_from_selected
 					(EMailShellView *mail_shell_view,
 					 gint filter_type);
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index fb04590..493d761 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -82,6 +82,272 @@ mail_shell_view_toggled (EShellView *shell_view)
 }
 
 static void
+mail_shell_view_execute_search (EShellView *shell_view)
+{
+	EMailShellViewPrivate *priv;
+	EShell *shell;
+	EShellWindow *shell_window;
+	EShellContent *shell_content;
+	EShellSettings *shell_settings;
+	EMFormatHTMLDisplay *html_display;
+	EMailShellContent *mail_shell_content;
+	MessageList *message_list;
+	FilterRule *rule;
+	EMailReader *reader;
+	CamelFolder *folder;
+	GtkAction *action;
+	GtkTreeModel *model;
+	GtkTreePath *path;
+	GtkTreeIter tree_iter;
+	GString *string;
+	GList *iter;
+	GSList *search_strings = NULL;
+	const gchar *folder_uri;
+	const gchar *text;
+	gboolean valid;
+	gchar *query;
+	gchar *temp;
+	gchar *tag;
+	gint value;
+
+	priv = E_MAIL_SHELL_VIEW_GET_PRIVATE (shell_view);
+
+	shell_window = e_shell_view_get_shell_window (shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
+
+	shell = e_shell_window_get_shell (shell_window);
+	shell_settings = e_shell_get_shell_settings (shell);
+
+	mail_shell_content = E_MAIL_SHELL_CONTENT (shell_content);
+
+	reader = E_MAIL_READER (shell_content);
+	html_display = e_mail_reader_get_html_display (reader);
+	message_list = e_mail_reader_get_message_list (reader);
+
+	folder_uri = message_list->folder_uri;
+	folder = message_list->folder;
+
+	if (folder_uri != NULL) {
+		GKeyFile *key_file;
+		const gchar *key;
+		const gchar *string;
+		gchar *group_name;
+
+		key_file = e_shell_view_get_state_key_file (shell_view);
+
+		key = STATE_KEY_SEARCH_TEXT;
+		string = e_shell_content_get_search_text (shell_content);
+		group_name = g_strdup_printf ("Folder %s", folder_uri);
+
+		if (string != NULL && *string != '\0')
+			g_key_file_set_string (
+				key_file, group_name, key, string);
+		else
+			g_key_file_remove_key (
+				key_file, group_name, key, NULL);
+		e_shell_view_set_state_dirty (shell_view);
+
+		g_free (group_name);
+	}
+
+	/* This returns a new object reference. */
+	model = e_shell_settings_get_object (
+		shell_settings, "mail-label-list-store");
+
+	text = e_shell_content_get_search_text (shell_content);
+	if (text == NULL || *text == '\0') {
+		query = g_strdup ("");
+		goto filter;
+	}
+
+	/* Replace variables in the selected rule with the
+	 * current search text and extract a query string. */
+
+	action = ACTION (MAIL_SEARCH_SUBJECT_OR_SENDER_CONTAINS);
+	value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
+	g_return_if_fail (value >= 0 && value < MAIL_NUM_SEARCH_RULES);
+	rule = priv->search_rules[value];
+
+	for (iter = rule->parts; iter != NULL; iter = iter->next) {
+		FilterPart *part = iter->data;
+		FilterElement *element = NULL;
+
+		if (strcmp (part->name, "subject") == 0)
+			element = filter_part_find_element (part, "subject");
+		else if (strcmp (part->name, "body") == 0)
+			element = filter_part_find_element (part, "word");
+		else if (strcmp (part->name, "sender") == 0)
+			element = filter_part_find_element (part, "sender");
+		else if (strcmp (part->name, "to") == 0)
+			element = filter_part_find_element (part, "recipient");
+
+		if (strcmp (part->name, "body") == 0) {
+			struct _camel_search_words *words;
+			gint ii;
+
+			words = camel_search_words_split ((guchar *) text);
+			for (ii = 0; ii < words->len; ii++)
+				search_strings = g_slist_prepend (
+					search_strings, g_strdup (
+					words->words[ii]->word));
+			camel_search_words_free (words);
+		}
+
+		if (element != NULL) {
+			FilterInput *input = FILTER_INPUT (element);
+			filter_input_set_value (input, text);
+		}
+	}
+
+	string = g_string_sized_new (1024);
+	filter_rule_build_code (rule, string);
+	query = g_string_free (string, FALSE);
+
+filter:
+
+	/* Apply selected filter. */
+
+	value = e_shell_content_get_filter_value (shell_content);
+	switch (value) {
+		case MAIL_FILTER_ALL_MESSAGES:
+			break;
+
+		case MAIL_FILTER_UNREAD_MESSAGES:
+			temp = g_strdup_printf (
+				"(and %s (match-all (not "
+				"(system-flag \"Seen\"))))", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case MAIL_FILTER_NO_LABEL:
+			string = g_string_sized_new (1024);
+			g_string_append_printf (
+				string, "(and %s (and ", query);
+			valid = gtk_tree_model_get_iter_first (
+				model, &tree_iter);
+			while (valid) {
+				tag = e_mail_label_list_store_get_tag (
+					E_MAIL_LABEL_LIST_STORE (model),
+					&tree_iter);
+				g_string_append_printf (
+					string, " (match-all (not (or "
+					"(= (user-tag \"label\") \"%s\") "
+					"(user-flag \"$Label%s\") "
+					"(user-flag \"%s\"))))",
+					tag, tag, tag);
+				g_free (tag);
+
+				valid = gtk_tree_model_iter_next (
+					model, &tree_iter);
+			}
+			g_string_append_len (string, "))", 2);
+			g_free (query);
+			query = g_string_free (string, FALSE);
+			break;
+
+		case MAIL_FILTER_READ_MESSAGES:
+			temp = g_strdup_printf (
+				"(and %s (match-all "
+				"(system-flag \"Seen\")))", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case MAIL_FILTER_RECENT_MESSAGES:
+			if (em_utils_folder_is_sent (folder, folder_uri))
+				temp = g_strdup_printf (
+					"(and %s (match-all "
+					"(> (get-sent-date) "
+					"(- (get-current-date) 86400))))",
+					query);
+			else
+				temp = g_strdup_printf (
+					"(and %s (match-all "
+					"(> (get-received-date) "
+					"(- (get-current-date) 86400))))",
+					query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case MAIL_FILTER_LAST_5_DAYS_MESSAGES:
+			if (em_utils_folder_is_sent (folder, folder_uri))
+				temp = g_strdup_printf (
+					"(and %s (match-all "
+					"(> (get-sent-date) "
+					"(- (get-current-date) 432000))))",
+					query);
+			else
+				temp = g_strdup_printf (
+					"(and %s (match-all "
+					"(> (get-received-date) "
+					"(- (get-current-date) 432000))))",
+					query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case MAIL_FILTER_MESSAGES_WITH_ATTACHMENTS:
+			temp = g_strdup_printf (
+				"(and %s (match-all "
+				"(system-flag \"Attachments\")))", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case MAIL_FILTER_IMPORTANT_MESSAGES:
+			temp = g_strdup_printf (
+				"(and %s (match-all "
+				"(system-flag \"Flagged\")))", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		case MAIL_FILTER_MESSAGES_NOT_JUNK:
+			temp = g_strdup_printf (
+				"(and %s (match-all (not "
+				"(system-flag \"junk\"))))", query);
+			g_free (query);
+			query = temp;
+			break;
+
+		default:
+			/* The action value also serves as a path for
+			 * the label list store.  That's why we number
+			 * the label actions from zero. */
+			path = gtk_tree_path_new_from_indices (value, -1);
+			gtk_tree_model_get_iter (model, &tree_iter, path);
+			gtk_tree_path_free (path);
+
+			tag = e_mail_label_list_store_get_tag (
+				E_MAIL_LABEL_LIST_STORE (model), &tree_iter);
+			temp = g_strdup_printf (
+				"(and %s (match-all (or "
+				"(= (user-tag \"label\") \"%s\") "
+				"(user-flag \"$Label%s\") "
+				"(user-flag \"%s\"))))",
+				query, tag, tag, tag);
+			g_free (tag);
+
+			g_free (query);
+			query = temp;
+			break;
+	}
+
+	message_list_set_search (message_list, query);
+
+	e_mail_shell_content_set_search_strings (
+		mail_shell_content, search_strings);
+
+	g_slist_foreach (search_strings, (GFunc) g_free, NULL);
+	g_slist_free (search_strings);
+
+	g_object_unref (model);
+	g_free (query);
+}
+
+static void
 mail_shell_view_update_actions (EShellView *shell_view)
 {
 	EMailShellView *mail_shell_view;
@@ -221,6 +487,7 @@ mail_shell_view_class_init (EMailShellViewClass *class,
 	shell_view_class->new_shell_content = e_mail_shell_content_new;
 	shell_view_class->new_shell_sidebar = e_mail_shell_sidebar_new;
 	shell_view_class->toggled = mail_shell_view_toggled;
+	shell_view_class->execute_search = mail_shell_view_execute_search;
 	shell_view_class->update_actions = mail_shell_view_update_actions;
 }
 
diff --git a/shell/e-shell-content.c b/shell/e-shell-content.c
index 15c1a93..fe4ea24 100644
--- a/shell/e-shell-content.c
+++ b/shell/e-shell-content.c
@@ -95,26 +95,23 @@ shell_content_dialog_rule_changed (GtkWidget *dialog,
 }
 
 static void
-action_search_execute_cb (GtkAction *action,
-                          EShellContent *shell_content)
+shell_content_execute_search_cb (EShellView *shell_view,
+                                 EShellContent *shell_content)
 {
-	EShellView *shell_view;
 	EShellWindow *shell_window;
+	GtkAction *action;
 	GtkWidget *widget;
 	const gchar *search_text;
 	gboolean sensitive;
 
-	/* EShellView subclasses are responsible for actually
-	 * executing the search.  This is all cosmetic stuff. */
-
-	shell_view = e_shell_content_get_shell_view (shell_content);
-	shell_window = e_shell_view_get_shell_window (shell_view);
-
 	if (!e_shell_view_is_active (shell_view))
 		return;
 
-	widget = shell_content->priv->search_entry;
+	/* EShellView subclasses are responsible for actually
+	 * executing the search.  This is all cosmetic stuff. */
 
+	widget = shell_content->priv->search_entry;
+	shell_window = e_shell_view_get_shell_window (shell_view);
 	search_text = e_shell_content_get_search_text (shell_content);
 
 	if (search_text != NULL && *search_text != '\0') {
@@ -159,22 +156,38 @@ action_search_execute_cb (GtkAction *action,
 }
 
 static void
-shell_content_entry_activated_cb (EShellContent *shell_content,
-                                  GtkWidget *entry)
+shell_content_entry_activate_cb (EShellContent *shell_content,
+                                 GtkEntry *entry)
 {
+	EShellView *shell_view;
 	EShellWindow *shell_window;
+	GtkAction *action;
+
+	shell_view = e_shell_content_get_shell_view (shell_content);
+	shell_window = e_shell_view_get_shell_window (shell_view);
+
+	action = E_SHELL_WINDOW_ACTION_SEARCH_QUICK (shell_window);
+	gtk_action_activate (action);
+}
+
+static void
+shell_content_entry_changed_cb (EShellContent *shell_content,
+                                GtkEntry *entry)
+{
 	EShellView *shell_view;
+	EShellWindow *shell_window;
 	GtkAction *action;
+	const gchar *text;
+	gboolean sensitive;
 
 	shell_view = e_shell_content_get_shell_view (shell_content);
 	shell_window = e_shell_view_get_shell_window (shell_view);
 
-	/* Verify the shell view is active before proceeding. */
-	if (!e_shell_view_is_active (shell_view))
-		return;
+	text = gtk_entry_get_text (entry);
+	sensitive = (text != NULL && *text != '\0');
 
-	action = E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE (shell_window);
-	gtk_action_activate (action);
+	action = E_SHELL_WINDOW_ACTION_SEARCH_QUICK (shell_window);
+	gtk_action_set_sensitive (action, sensitive);
 }
 
 static void
@@ -563,6 +576,11 @@ shell_content_constructed (GObject *object)
 	shell_window = e_shell_view_get_shell_window (shell_view);
 	size_group = e_shell_view_get_size_group (shell_view);
 
+	g_signal_connect_after (
+		shell_view, "execute-search",
+		G_CALLBACK (shell_content_execute_search_cb),
+		shell_content);
+
 	widget = shell_content->priv->search_entry;
 
 	action = E_SHELL_WINDOW_ACTION_SEARCH_CLEAR (shell_window);
@@ -576,11 +594,6 @@ shell_content_constructed (GObject *object)
 		action, "tooltip",
 		widget, "secondary-icon-tooltip-text");
 
-	action = E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE (shell_window);
-	g_signal_connect (
-		action, "activate",
-		G_CALLBACK (action_search_execute_cb), shell_content);
-
 	action = E_SHELL_WINDOW_ACTION_SEARCH_OPTIONS (shell_window);
 	e_binding_new (
 		action, "sensitive",
@@ -918,7 +931,12 @@ shell_content_init (EShellContent *shell_content)
 
 	g_signal_connect_swapped (
 		widget, "activate",
-		G_CALLBACK (shell_content_entry_activated_cb),
+		G_CALLBACK (shell_content_entry_activate_cb),
+		shell_content);
+
+	g_signal_connect_swapped (
+		widget, "changed",
+		G_CALLBACK (shell_content_entry_changed_cb),
 		shell_content);
 
 	g_signal_connect_swapped (
@@ -1338,7 +1356,6 @@ e_shell_content_run_advanced_search_dialog (EShellContent *shell_content)
 {
 	EShellView *shell_view;
 	EShellWindow *shell_window;
-	GtkAction *action;
 	GtkWidget *dialog;
 	GtkWidget *widget;
 	FilterRule *rule;
@@ -1394,8 +1411,7 @@ run:
 
 	e_shell_content_set_search_rule (shell_content, rule);
 
-	action = E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE (shell_window);
-	gtk_action_activate (action);
+	e_shell_view_execute_search (shell_view);
 
 	if (response == GTK_RESPONSE_APPLY) {
 		if (!rule_context_find_rule (context, rule->name, rule->source))
@@ -1524,7 +1540,7 @@ e_shell_content_restore_state (EShellContent *shell_content,
 
 	/* Changing the combo boxes triggers searches, so block
 	 * the search action until the state is fully restored. */
-	action = e_shell_window_get_action (shell_window, "search-execute");
+	action = E_SHELL_WINDOW_ACTION_SEARCH_QUICK (shell_window);
 	gtk_action_block_activate (action);
 
 	key = STATE_KEY_SEARCH_FILTER;
@@ -1562,7 +1578,7 @@ e_shell_content_restore_state (EShellContent *shell_content,
 	e_shell_content_set_search_text (shell_content, string);
 	g_free (string);
 
-	action = e_shell_window_get_action (shell_window, "search-execute");
+	action = E_SHELL_WINDOW_ACTION_SEARCH_QUICK (shell_window);
 	gtk_action_unblock_activate (action);
 
 	/* Now execute the search. */
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index 5808f9e..9b740d4 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -69,6 +69,7 @@ enum {
 
 enum {
 	TOGGLED,
+	EXECUTE_SEARCH,
 	UPDATE_ACTIONS,
 	LAST_SIGNAL
 };
@@ -672,6 +673,23 @@ shell_view_class_init (EShellViewClass *class)
 		G_TYPE_NONE, 0);
 
 	/**
+	 * EShellView::execute-search
+	 * @shell_view: the #EShellView which emitted the signal
+	 *
+	 * #EShellView subclasses should override the
+	 * <structfield>execute_search</structfield> method in
+	 * #EShellViewClass to execute the current search conditions.
+	 **/
+	signals[EXECUTE_SEARCH] = g_signal_new (
+		"execute-search",
+		G_OBJECT_CLASS_TYPE (object_class),
+		G_SIGNAL_RUN_FIRST,
+		G_STRUCT_OFFSET (EShellViewClass, execute_search),
+		NULL, NULL,
+		g_cclosure_marshal_VOID__VOID,
+		G_TYPE_NONE, 0);
+
+	/**
 	 * EShellView::update-actions
 	 * @shell_view: the #EShellView which emitted the signal
 	 *
@@ -1097,6 +1115,24 @@ e_shell_view_set_state_dirty (EShellView *shell_view)
 }
 
 /**
+ * e_shell_view_execute_search:
+ * @shell_view: an #EShellView
+ *
+ * Emits the #EShellView:;execute-search signal.
+ *
+ * #EShellView subclasses should implement the
+ * <structfield>execute_search</structfield> method in #EShellViewClass
+ * to execute a search based on the current search conditions.
+ **/
+void
+e_shell_view_execute_search (EShellView *shell_view)
+{
+	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+
+	g_signal_emit (shell_view, signals[EXECUTE_SEARCH], 0);
+}
+
+/**
  * e_shell_view_update_actions:
  * @shell_view: an #EShellView
  *
diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h
index 1e5e03f..1a8a904 100644
--- a/shell/e-shell-view.h
+++ b/shell/e-shell-view.h
@@ -111,7 +111,10 @@ struct _EShellView {
  * @toggled:		Class method for the #EShellView::toggled signal.
  *			Subclasses should rarely need to override the
  *			default behavior.
- * @update_actions:	Class method for the #EShellView::update_actions
+ * @execute_search:	Class method for the #EShellView::execute-search
+ * 			signal.  There is no default behavior; subclasses
+ * 			should override this.
+ * @update_actions:	Class method for the #EShellView::update-actions
  *			signal.  There is no default behavior; subclasses
  *			should override this.
  *
@@ -150,6 +153,7 @@ struct _EShellViewClass {
 
 	/* Signals */
 	void		(*toggled)		(EShellView *shell_view);
+	void		(*execute_search)	(EShellView *shell_view);
 	void		(*update_actions)	(EShellView *shell_view);
 };
 
@@ -174,6 +178,7 @@ EShellTaskbar *	e_shell_view_get_shell_taskbar	(EShellView *shell_view);
 EShellWindow *	e_shell_view_get_shell_window	(EShellView *shell_view);
 GKeyFile *	e_shell_view_get_state_key_file	(EShellView *shell_view);
 void		e_shell_view_set_state_dirty	(EShellView *shell_view);
+void		e_shell_view_execute_search	(EShellView *shell_view);
 void		e_shell_view_update_actions	(EShellView *shell_view);
 void		e_shell_view_show_popup_menu	(EShellView *shell_view,
 						 const gchar *widget_path,
diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c
index 54cd47f..2fe4a17 100644
--- a/shell/e-shell-window-actions.c
+++ b/shell/e-shell-window-actions.c
@@ -719,7 +719,8 @@ action_custom_rule_cb (GtkAction *action,
 	g_return_if_fail (IS_FILTER_RULE (rule));
 
 	e_shell_content_set_search_rule (shell_content, rule);
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+
+	e_shell_view_execute_search (shell_view);
 }
 
 /**
@@ -1024,7 +1025,7 @@ action_search_clear_cb (GtkAction *action,
 	e_shell_content_set_search_rule (shell_content, NULL);
 	e_shell_content_set_search_text (shell_content, NULL);
 
-	gtk_action_activate (ACTION (SEARCH_EXECUTE));
+	e_shell_view_execute_search (shell_view);
 
 	e_shell_window_update_search_menu (shell_window);
 }
@@ -1054,15 +1055,6 @@ action_search_edit_cb (GtkAction *action,
 }
 
 /**
- * E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE:
- * @window: an #EShellWindow
- *
- * Activation of this action executes the current search conditions.
- *
- * Main menu item: Search -> Find Now
- **/
-
-/**
  * E_SHELL_WINDOW_ACTION_SEARCH_OPTIONS:
  * @window: an #EShellWindow
  *
@@ -1087,6 +1079,27 @@ action_search_options_cb (GtkAction *action,
 }
 
 /**
+ * E_SHELL_WINDOW_ACTION_SEARCH_QUICK:
+ * @window: an #EShellWindow
+ *
+ * Activation of this action executes the current search conditions.
+ *
+ * Main menu item: Search -> Find Now
+ **/
+static void
+action_search_quick_cb (GtkAction *action,
+                        EShellWindow *shell_window)
+{
+	EShellView *shell_view;
+	const gchar *view_name;
+
+	view_name = e_shell_window_get_active_view (shell_window);
+	shell_view = e_shell_window_get_shell_view (shell_window, view_name);
+
+	e_shell_view_execute_search (shell_view);
+}
+
+/**
  * E_SHELL_WINDOW_ACTION_SEARCH_SAVE:
  * @window: an #EShellWindow
  *
@@ -1523,13 +1536,6 @@ static GtkActionEntry shell_entries[] = {
 	  N_("Manage your saved searches"),
 	  G_CALLBACK (action_search_edit_cb) },
 
-	{ "search-execute",
-	  GTK_STOCK_FIND,
-	  N_("_Find Now"),
-	  "",      /* Block the default Ctrl+F. */
-	  N_("Execute the current search parameters"),
-	  NULL },  /* Handled by EShellContent and subclasses. */
-
 	{ "search-options",
 	  GTK_STOCK_FIND,
 	  NULL,
@@ -1537,6 +1543,13 @@ static GtkActionEntry shell_entries[] = {
 	  N_("Click here to change the search type"),
 	  G_CALLBACK (action_search_options_cb) },
 
+	{ "search-quick",
+	  GTK_STOCK_FIND,
+	  N_("_Find Now"),
+	  "",      /* Block the default Ctrl+F. */
+	  N_("Execute the current search parameters"),
+	  G_CALLBACK (action_search_quick_cb) },
+
 	{ "search-save",
 	  NULL,
 	  N_("_Save Search..."),
@@ -1872,6 +1885,8 @@ e_shell_window_actions_init (EShellWindow *shell_window)
 
 	/* Fine tuning. */
 
+	gtk_action_set_sensitive (ACTION (SEARCH_QUICK), FALSE);
+
 	g_object_set (ACTION (SEND_RECEIVE), "is-important", TRUE, NULL);
 
 	e_binding_new (
diff --git a/shell/e-shell-window-actions.h b/shell/e-shell-window-actions.h
index 757487b..dec9160 100644
--- a/shell/e-shell-window-actions.h
+++ b/shell/e-shell-window-actions.h
@@ -63,10 +63,10 @@
 	E_SHELL_WINDOW_ACTION ((window), "search-clear")
 #define E_SHELL_WINDOW_ACTION_SEARCH_EDIT(window) \
 	E_SHELL_WINDOW_ACTION ((window), "search-edit")
-#define E_SHELL_WINDOW_ACTION_SEARCH_EXECUTE(window) \
-	E_SHELL_WINDOW_ACTION ((window), "search-execute")
 #define E_SHELL_WINDOW_ACTION_SEARCH_OPTIONS(window) \
 	E_SHELL_WINDOW_ACTION ((window), "search-options")
+#define E_SHELL_WINDOW_ACTION_SEARCH_QUICK(window) \
+	E_SHELL_WINDOW_ACTION ((window), "search-quick")
 #define E_SHELL_WINDOW_ACTION_SEARCH_SAVE(window) \
 	E_SHELL_WINDOW_ACTION ((window), "search-save")
 #define E_SHELL_WINDOW_ACTION_SEND_RECEIVE(window) \
diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c
index 1939209..6b43877 100644
--- a/shell/e-shell-window.c
+++ b/shell/e-shell-window.c
@@ -106,6 +106,9 @@ shell_window_new_view (EShellBackend *shell_backend,
 		shell_view, "notify::view-id",
 		G_CALLBACK (e_shell_window_update_view_menu), shell_window);
 
+	/* Execute an initial search. */
+	e_shell_view_execute_search (shell_view);
+
 	return shell_view;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]