[evolution/kill-bonobo] Kill CalSearchBar.



commit b4c93f77e655cfd0a2a740502d7b67bc60df4523
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Jul 27 13:26:13 2009 -0400

    Kill CalSearchBar.
    
    Move calendar search logic to ECalShellView.

 calendar/gui/Makefile.am                        |    4 -
 calendar/gui/cal-search-bar.c                   |  920 -----------------------
 calendar/gui/cal-search-bar.h                   |   91 ---
 calendar/gui/ea-gnome-calendar.c                |   14 +-
 calendar/gui/gnome-cal.c                        |  112 +---
 calendar/gui/gnome-cal.h                        |    6 +-
 modules/addressbook/e-book-shell-view-private.c |    6 +-
 modules/calendar/e-cal-shell-view-private.c     |  151 ++++-
 modules/calendar/e-memo-shell-view-private.c    |    6 +-
 modules/calendar/e-task-shell-view-private.c    |    6 +-
 10 files changed, 178 insertions(+), 1138 deletions(-)
---
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 30a0c33..ff748ae 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -46,10 +46,6 @@ etspec_DATA =				\
 
 noinst_LTLIBRARIES = libcal-gui.la
 
-# Removed from SOURCES
-#	cal-search-bar.c
-# 	cal-search-bar.h
-
 libcal_gui_la_SOURCES =		\
 	e-attachment-handler-calendar.c		\
 	e-attachment-handler-calendar.h		\
diff --git a/calendar/gui/ea-gnome-calendar.c b/calendar/gui/ea-gnome-calendar.c
index 1cc75e5..78fd50f 100644
--- a/calendar/gui/ea-gnome-calendar.c
+++ b/calendar/gui/ea-gnome-calendar.c
@@ -260,7 +260,7 @@ ea_gnome_calendar_get_n_children (AtkObject* obj)
 
 	if (!GTK_ACCESSIBLE (obj)->widget)
 		return -1;
-	return 4;
+	return 3;
 }
 
 static AtkObject *
@@ -283,14 +283,6 @@ ea_gnome_calendar_ref_child (AtkObject *obj, gint i)
 
 	switch (i) {
 	case 0:
-		/* for the search bar */
-		childWidget = gnome_calendar_get_search_bar_widget (calendarWidget);
-		child = gtk_widget_get_accessible (childWidget);
-		atk_object_set_parent (child, obj);
-		atk_object_set_name (child, _("search bar"));
-		atk_object_set_description (child, _("evolution calendar search bar"));
-		break;
-	case 1:
 		/* for the day/week view */
 		view_type = gnome_calendar_get_view (calendarWidget);
 		view = gnome_calendar_get_calendar_view (calendarWidget, view_type);
@@ -298,12 +290,12 @@ ea_gnome_calendar_ref_child (AtkObject *obj, gint i)
 		child = gtk_widget_get_accessible (childWidget);
 		atk_object_set_parent (child, obj);
 		break;
-	case 2:
+	case 1:
 		/* for calendar */
 		childWidget = gnome_calendar_get_e_calendar_widget (calendarWidget);
 		child = gtk_widget_get_accessible (childWidget);
 		break;
-	case 3:
+	case 2:
 		/* for todo list */
 		childWidget = GTK_WIDGET (gnome_calendar_get_task_pad (calendarWidget));
 		child = gtk_widget_get_accessible (childWidget);
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index b848d8b..f0b20d3 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -96,8 +96,6 @@ struct _GnomeCalendarPrivate {
 
 	/* Widgets */
 
-	GtkWidget   *search_bar;
-
 	GtkWidget   *hpane;
 	GtkWidget   *notebook;
 	GtkWidget   *vpane;
@@ -800,14 +798,17 @@ update_query (GnomeCalendar *gcal)
 	message_push ((Message *) msg);
 }
 
-static void
-set_search_query (GnomeCalendar *gcal, const gchar *sexp)
+void
+gnome_calendar_set_search_query (GnomeCalendar *gcal,
+                                 const gchar *sexp,
+                                 gboolean range_search,
+                                 time_t start_range,
+                                 time_t end_range)
 {
 	GnomeCalendarPrivate *priv;
 	gint i;
 	time_t start, end;
 
-	g_return_if_fail (gcal != NULL);
 	g_return_if_fail (GNOME_IS_CALENDAR (gcal));
 	g_return_if_fail (sexp != NULL);
 
@@ -815,11 +816,13 @@ set_search_query (GnomeCalendar *gcal, const gchar *sexp)
 
 	/* Set the query on the date navigator */
 
-	if (priv->sexp)
-		g_free (priv->sexp);
-
+	g_free (priv->sexp);
 	priv->sexp = g_strdup (sexp);
 
+	priv->lview_select_daten_range = range_search;
+	start = start_range;
+	end = end_range;
+
 	d(g_print ("Changing the queries %s \n", sexp));
 
 	update_query (gcal);
@@ -829,7 +832,6 @@ set_search_query (GnomeCalendar *gcal, const gchar *sexp)
 	/* Set the query on the views */
 	if (i == GNOME_CAL_LIST_VIEW) {
 		if (!priv->lview_select_daten_range) {
-			cal_search_bar_get_time_range ((CalSearchBar *)priv->search_bar, &start, &end);
 			e_cal_model_set_search_query_with_time_range (e_calendar_view_get_model (priv->views [i]), sexp, start, end);
 		} else {
 			start = priv->base_view_time;
@@ -867,50 +869,6 @@ get_current_time (ECalendarItem *calitem, gpointer data)
 	return tmp_tm;
 }
 
-/* Callback used when the sexp changes in the calendar search bar */
-static void
-search_bar_sexp_changed_cb (CalSearchBar *cal_search, const gchar *sexp, gpointer data)
-{
-	GnomeCalendar *gcal;
-	const gchar *d_sexp = "occur-in-time-range?";
-
-	gcal = GNOME_CALENDAR (data);
-
-	/* Choose List view if the search made in the search bar is based on date */
-	if (sexp != NULL && strstr (sexp, d_sexp ) != NULL) {
-		gcal->priv->lview_select_daten_range = FALSE;
-		gtk_widget_hide (GTK_WIDGET (gcal->priv->date_navigator));
-		gnome_calendar_set_view (gcal, GNOME_CAL_LIST_VIEW);
-	} else {
-		gcal->priv->lview_select_daten_range = TRUE;
-		gtk_widget_show (GTK_WIDGET (gcal->priv->date_navigator));
-	}
-
-	set_search_query (gcal, sexp);
-}
-
-/* Callback used when the selected category in the search bar changes */
-static void
-search_bar_category_changed_cb (CalSearchBar *cal_search, const gchar *category, gpointer data)
-{
-	GnomeCalendar *gcal;
-	GnomeCalendarPrivate *priv;
-	ECalModel *model;
-	gint i;
-
-	gcal = GNOME_CALENDAR (data);
-	priv = gcal->priv;
-
-	for (i = 0; i < GNOME_CAL_LAST_VIEW; i++) {
-		e_calendar_view_set_default_category (E_CALENDAR_VIEW (priv->views[i]),
-						 category);
-	}
-
-	/* [KILL-BONOBO] Delete this when moved to ECalShellView.
-	model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo));
-	e_cal_model_set_default_category (model, category); */
-}
-
 static void
 view_selection_changed_cb (GtkWidget *view, GnomeCalendar *gcal)
 {
@@ -1248,29 +1206,6 @@ month_view_adjustment_changed_cb (GtkAdjustment *adjustment, GnomeCalendar *gcal
 }
 
 static void
-categories_changed_cb (gpointer object, gpointer user_data)
-{
-	GList *cat_list;
-	GPtrArray *cat_array;
-	GnomeCalendarPrivate *priv;
-	GnomeCalendar *gcal = user_data;
-
-	priv = gcal->priv;
-
-	cat_array = g_ptr_array_new ();
-	cat_list = e_categories_get_list ();
-	while (cat_list != NULL) {
-		if (e_categories_is_searchable ((const gchar *) cat_list->data))
-			g_ptr_array_add (cat_array, cat_list->data);
-		cat_list = g_list_remove (cat_list, cat_list->data);
-	}
-
-	cal_search_bar_set_categories ((CalSearchBar *)priv->search_bar, cat_array);
-
-	g_ptr_array_free (cat_array, TRUE);
-}
-
-static void
 view_progress_cb (ECalModel *model, const gchar *message, gint percent, ECalSourceType type, GnomeCalendar *gcal)
 {
 	if (type == E_CAL_SOURCE_TYPE_EVENT)
@@ -1321,16 +1256,6 @@ setup_widgets (GnomeCalendar *gcal)
 
 	priv = gcal->priv;
 
-	priv->search_bar = cal_search_bar_new (CAL_SEARCH_CALENDAR_DEFAULT);
-	g_signal_connect (priv->search_bar, "sexp_changed",
-			  G_CALLBACK (search_bar_sexp_changed_cb), gcal);
-	g_signal_connect (priv->search_bar, "category_changed",
-			  G_CALLBACK (search_bar_category_changed_cb), gcal);
-	categories_changed_cb (NULL, gcal);
-
-	gtk_widget_show (priv->search_bar);
-	gtk_box_pack_start (GTK_BOX (gcal), priv->search_bar, FALSE, FALSE, 6);
-
 	/* The main HPaned, with the notebook of calendar views on the left
 	   and the ECalendar and ToDo list on the right. */
 	priv->hpane = gtk_hpaned_new ();
@@ -1485,8 +1410,6 @@ gnome_calendar_init (GnomeCalendar *gcal)
 	if (non_intrusive_error_table == NULL)
 		non_intrusive_error_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 
-	e_categories_register_change_listener (G_CALLBACK (categories_changed_cb), gcal);
-
 	priv->todo_update_lock = g_mutex_new ();
 
 	priv->current_view_type = GNOME_CAL_DAY_VIEW;
@@ -1528,8 +1451,6 @@ gnome_calendar_destroy (GtkObject *object)
 		GList *l;
 		gint i;
 
-		e_categories_unregister_change_listener (G_CALLBACK (categories_changed_cb), gcal);
-
 		/* Clean up the clients */
 		for (l = priv->clients_list; l != NULL; l = l->next) {
 			g_signal_handlers_disconnect_matched (l->data, G_SIGNAL_MATCH_DATA,
@@ -2658,9 +2579,6 @@ gnome_calendar_new_task		(GnomeCalendar *gcal, time_t *dtstart, time_t *dtend)
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomp);
 
-	category = cal_search_bar_get_category (CAL_SEARCH_BAR (priv->search_bar));
-	e_cal_component_set_categories (comp, category);
-
 	dt.value = &itt;
 	dt.tzid = icaltimezone_get_tzid (e_cal_model_get_timezone (model));
 
@@ -3145,14 +3063,6 @@ gnome_calendar_get_e_calendar_widget (GnomeCalendar *gcal)
 	return GTK_WIDGET(gcal->priv->date_navigator);
 }
 
-GtkWidget *
-gnome_calendar_get_search_bar_widget (GnomeCalendar *gcal)
-{
-	g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
-
-	return GTK_WIDGET(gcal->priv->search_bar);
-}
-
 ECalMenu *gnome_calendar_get_calendar_menu (GnomeCalendar *gcal)
 {
 	g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h
index 7955aed..2560a04 100644
--- a/calendar/gui/gnome-cal.h
+++ b/calendar/gui/gnome-cal.h
@@ -112,6 +112,11 @@ gboolean   gnome_calendar_add_source      (GnomeCalendar *gcal, ESource *source)
 gboolean   gnome_calendar_remove_source   (GnomeCalendar *gcal, ESource *source);
 gboolean   gnome_calendar_remove_source_by_uid   (GnomeCalendar *gcal, const gchar *uid);
 gboolean   gnome_calendar_set_default_source (GnomeCalendar *gcal, ESource *source);
+void		gnome_calendar_set_search_query	(GnomeCalendar *gcal,
+						 const gchar *sexp,
+						 gboolean range_search,
+						 time_t start_range,
+						 time_t end_range);
 
 void       gnome_calendar_next		(GnomeCalendar *gcal);
 void       gnome_calendar_previous		(GnomeCalendar *gcal);
@@ -129,7 +134,6 @@ struct _ECalendarView *gnome_calendar_get_calendar_view (GnomeCalendar *gcal,
 							 GnomeCalendarViewType view_type);
 
 GtkWidget *gnome_calendar_get_e_calendar_widget (GnomeCalendar *gcal);
-GtkWidget *gnome_calendar_get_search_bar_widget (GnomeCalendar *gcal);
 GtkWidget *gnome_calendar_get_tag (GnomeCalendar *gcal);
 
 ECalMenu *gnome_calendar_get_calendar_menu (GnomeCalendar *gcal);
diff --git a/modules/addressbook/e-book-shell-view-private.c b/modules/addressbook/e-book-shell-view-private.c
index f930e6d..6770800 100644
--- a/modules/addressbook/e-book-shell-view-private.c
+++ b/modules/addressbook/e-book-shell-view-private.c
@@ -522,7 +522,7 @@ e_book_shell_view_execute_search (EBookShellView *book_shell_view)
 	EShellView *shell_view;
 	EShellWindow *shell_window;
 	EShellContent *shell_content;
-	GtkAction *action;
+	GtkRadioAction *action;
 	GString *string;
 	EAddressbookView *view;
 	EAddressbookModel *model;
@@ -541,8 +541,8 @@ e_book_shell_view_execute_search (EBookShellView *book_shell_view)
 	text = e_shell_content_get_search_text (shell_content);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = ACTION (CONTACT_SEARCH_ANY_FIELD_CONTAINS);
-	value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
+	action = GTK_RADIO_ACTION (ACTION (CONTACT_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
 
 	if (text == NULL || *text == '\0') {
 		text = "";
diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index 9af8e98..19d29a0 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -417,7 +417,156 @@ e_cal_shell_view_private_finalize (ECalShellView *cal_shell_view)
 void
 e_cal_shell_view_execute_search (ECalShellView *cal_shell_view)
 {
-	/* FIXME */
+	ECalShellContent *cal_shell_content;
+	ECalShellSidebar *cal_shell_sidebar;
+	EShellView *shell_view;
+	EShellWindow *shell_window;
+	EShellContent *shell_content;
+	GnomeCalendar *calendar;
+	ECalendar *mini_calendar;
+	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 (CAL_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;
+	range_start = range_end = 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;
+	mini_calendar = e_cal_shell_sidebar_get_mini_calendar (cal_shell_sidebar);
+
+	if (range_search) {
+		/* Switch to list view and hide the mini calendar. */
+		action = GTK_RADIO_ACTION (ACTION (CALENDAR_VIEW_LIST));
+		gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+		gtk_widget_hide (GTK_WIDGET (mini_calendar));
+	} else {
+		/* Ensure the mini calendar is visible. */
+		gtk_widget_show (GTK_WIDGET (mini_calendar));
+	}
+
+	/* 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
diff --git a/modules/calendar/e-memo-shell-view-private.c b/modules/calendar/e-memo-shell-view-private.c
index 69d6c0a..4953a38 100644
--- a/modules/calendar/e-memo-shell-view-private.c
+++ b/modules/calendar/e-memo-shell-view-private.c
@@ -303,7 +303,7 @@ e_memo_shell_view_execute_search (EMemoShellView *memo_shell_view)
 	EShellView *shell_view;
 	EShellWindow *shell_window;
 	EShellContent *shell_content;
-	GtkAction *action;
+	GtkRadioAction *action;
 	GString *string;
 	ECalComponentPreview *memo_preview;
 	EMemoTable *memo_table;
@@ -320,8 +320,8 @@ e_memo_shell_view_execute_search (EMemoShellView *memo_shell_view)
 	text = e_shell_content_get_search_text (shell_content);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = ACTION (MEMO_SEARCH_ANY_FIELD_CONTAINS);
-	value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
+	action = GTK_RADIO_ACTION (ACTION (MEMO_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
 
 	if (text == NULL || *text == '\0') {
 		text = "";
diff --git a/modules/calendar/e-task-shell-view-private.c b/modules/calendar/e-task-shell-view-private.c
index d6fd8e3..be281f1 100644
--- a/modules/calendar/e-task-shell-view-private.c
+++ b/modules/calendar/e-task-shell-view-private.c
@@ -412,7 +412,7 @@ e_task_shell_view_execute_search (ETaskShellView *task_shell_view)
 	EShellView *shell_view;
 	EShellWindow *shell_window;
 	EShellContent *shell_content;
-	GtkAction *action;
+	GtkRadioAction *action;
 	GString *string;
 	ECalComponentPreview *task_preview;
 	ECalendarTable *task_table;
@@ -432,8 +432,8 @@ e_task_shell_view_execute_search (ETaskShellView *task_shell_view)
 	text = e_shell_content_get_search_text (shell_content);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
-	action = ACTION (TASK_SEARCH_ANY_FIELD_CONTAINS);
-	value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
+	action = GTK_RADIO_ACTION (ACTION (TASK_SEARCH_ANY_FIELD_CONTAINS));
+	value = gtk_radio_action_get_current_value (action);
 
 	if (text == NULL || *text == '\0') {
 		text = "";



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