aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/calendar-commands.c10
-rw-r--r--calendar/gui/e-day-view.c283
-rw-r--r--calendar/gui/e-day-view.h20
-rw-r--r--calendar/gui/e-week-view.c282
-rw-r--r--calendar/gui/e-week-view.h10
5 files changed, 340 insertions, 265 deletions
diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c
index d31d252dfd..3556554d82 100644
--- a/calendar/gui/calendar-commands.c
+++ b/calendar/gui/calendar-commands.c
@@ -387,12 +387,12 @@ static EPixmap pixmaps [] =
E_PIXMAP ("/menu/File/Print/Print Preview", "print-preview.xpm"),
E_PIXMAP ("/menu/Actions/Component/CalendarNew", "new_appointment.xpm"),
E_PIXMAP ("/menu/Tools/Component/CalendarPreferences", "configure_16_calendar.xpm"),
- E_PIXMAP ("/Toolbar/New", "buttons/new_appointment.png"),
- E_PIXMAP ("/Toolbar/DayView", "buttons/dayview.xpm"),
- E_PIXMAP ("/Toolbar/WorkWeekView", "buttons/workweekview.xpm"),
- E_PIXMAP ("/Toolbar/WeekView", "buttons/weekview.xpm"),
- E_PIXMAP ("/Toolbar/MonthView", "buttons/monthview.xpm"),
+ E_PIXMAP ("/Toolbar/New", "buttons/new_appointment.png"),
+ E_PIXMAP ("/Toolbar/DayView", "buttons/dayview.xpm"),
+ E_PIXMAP ("/Toolbar/WorkWeekView", "buttons/workweekview.xpm"),
+ E_PIXMAP ("/Toolbar/WeekView", "buttons/weekview.xpm"),
+ E_PIXMAP ("/Toolbar/MonthView", "buttons/monthview.xpm"),
E_PIXMAP_END
};
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 828eff3419..b10382a3ea 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -253,9 +253,6 @@ static void e_day_view_foreach_event_with_uid (EDayView *day_view,
EDayViewForeachEventCallback callback,
gpointer data);
-static void e_day_view_queue_reload_events (EDayView *day_view);
-static gboolean e_day_view_reload_events_idle_cb (gpointer data);
-static void e_day_view_reload_events (EDayView *day_view);
static void e_day_view_free_events (EDayView *day_view);
static void e_day_view_free_event_array (EDayView *day_view,
GArray *array);
@@ -488,13 +485,14 @@ e_day_view_init (EDayView *day_view)
day_view->calendar = NULL;
day_view->client = NULL;
+ day_view->sexp = g_strdup ("#t"); /* match all by default */
+ day_view->query = NULL;
day_view->long_events = g_array_new (FALSE, FALSE,
sizeof (EDayViewEvent));
day_view->long_events_sorted = TRUE;
day_view->long_events_need_layout = FALSE;
day_view->long_events_need_reshape = FALSE;
- day_view->reload_events_idle_id = 0;
for (day = 0; day < E_DAY_VIEW_MAX_DAYS; day++) {
day_view->events[day] = g_array_new (FALSE, FALSE,
@@ -794,7 +792,7 @@ e_day_view_init (EDayView *day_view)
/* Create the cursors. */
- day_view->normal_cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
+ day_view->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR);
day_view->move_cursor = gdk_cursor_new (GDK_FLEUR);
day_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
day_view->resize_height_cursor = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW);
@@ -851,17 +849,23 @@ e_day_view_destroy (GtkObject *object)
e_day_view_stop_auto_scroll (day_view);
- if (day_view->reload_events_idle_id != 0) {
- g_source_remove (day_view->reload_events_idle_id);
- day_view->reload_events_idle_id = 0;
- }
-
if (day_view->client) {
gtk_signal_disconnect_by_data (GTK_OBJECT (day_view->client), day_view);
gtk_object_unref (GTK_OBJECT (day_view->client));
day_view->client = NULL;
}
+ if (day_view->sexp) {
+ g_free (day_view->sexp);
+ day_view->sexp = NULL;
+ }
+
+ if (day_view->query) {
+ gtk_signal_disconnect_by_data (GTK_OBJECT (day_view->query), day_view);
+ gtk_object_unref (GTK_OBJECT (day_view->query));
+ day_view->query = NULL;
+ }
+
if (day_view->large_font)
gdk_font_unref (day_view->large_font);
@@ -1372,23 +1376,11 @@ e_day_view_set_calendar (EDayView *day_view,
}
-/* Callback used when the calendar client finishes opening */
-static void
-cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
-{
- EDayView *day_view;
-
- day_view = E_DAY_VIEW (data);
-
- if (status != CAL_CLIENT_OPEN_SUCCESS)
- return;
-
- e_day_view_queue_reload_events (day_view);
-}
-
-/* Callback used when the calendar client tells us that an object changed */
+/* Callback used when a component is updated in the live query */
static void
-obj_updated_cb (CalClient *client, const char *uid, gpointer data)
+query_obj_updated_cb (CalQuery *query, const char *uid,
+ gboolean query_in_progress, int n_scanned, int total,
+ gpointer data)
{
EDayView *day_view;
EDayViewEvent *event;
@@ -1396,13 +1388,8 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
CalClientGetStatus status;
gint day, event_num;
- g_return_if_fail (E_IS_DAY_VIEW (data));
-
day_view = E_DAY_VIEW (data);
- /* Sanity check. */
- g_return_if_fail (client == day_view->client);
-
/* If our time hasn't been set yet, just return. */
if (day_view->lower == 0 && day_view->upper == 0)
return;
@@ -1416,7 +1403,7 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
break;
case CAL_CLIENT_GET_SYNTAX_ERROR:
- g_message ("obj_updated_cb(): Syntax error when getting object `%s'", uid);
+ g_message ("query_obj_updated_cb(): Syntax error when getting object `%s'", uid);
return;
case CAL_CLIENT_GET_NOT_FOUND:
@@ -1428,12 +1415,6 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
return;
}
- /* We only care about events. */
- if (cal_component_get_vtype (comp) != CAL_COMPONENT_EVENT) {
- gtk_object_unref (GTK_OBJECT (comp));
- return;
- }
-
/* If the event already exists and the dates didn't change, we can
update the event fairly easily without changing the events arrays
or computing a new layout. */
@@ -1481,10 +1462,9 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
gtk_widget_queue_draw (day_view->main_canvas);
}
-
-/* Callback used when the calendar client tells us that an object was removed */
+/* Callback used when a component is removed from the live query */
static void
-obj_removed_cb (CalClient *client, const char *uid, gpointer data)
+query_obj_removed_cb (CalQuery *query, const char *uid, gpointer data)
{
EDayView *day_view;
@@ -1498,6 +1478,117 @@ obj_removed_cb (CalClient *client, const char *uid, gpointer data)
gtk_widget_queue_draw (day_view->main_canvas);
}
+/* Callback used when a query ends */
+static void
+query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data)
+{
+ EDayView *day_view;
+
+ day_view = E_DAY_VIEW (data);
+
+ /* FIXME */
+
+ if (status != CAL_QUERY_DONE_SUCCESS)
+ fprintf (stderr, "query done: %s\n", error_str);
+}
+
+/* Callback used when an evaluation error occurs when running a query */
+static void
+query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data)
+{
+ EDayView *day_view;
+
+ day_view = E_DAY_VIEW (data);
+
+ /* FIXME */
+
+ fprintf (stderr, "eval error: %s\n", error_str);
+}
+
+
+/* Builds a complete query sexp for the day view by adding the predicates to
+ * filter only for VEVENTS that fit in the day view's time range.
+ */
+static char *
+adjust_query_sexp (EDayView *day_view, const char *sexp)
+{
+ char *start, *end;
+ char *new_sexp;
+
+ /* If the dates have not been set yet, we just want an empty query. */
+ if (day_view->lower == 0 || day_view->upper == 0)
+ return g_strdup ("#f");
+
+ start = isodate_from_time_t (day_view->lower);
+ end = isodate_from_time_t (day_view->upper);
+
+ new_sexp = g_strdup_printf ("(and (= (get-vtype) \"VEVENT\")"
+ " (occur-in-time-range? (make-time \"%s\")"
+ " (make-time \"%s\"))"
+ " %s)",
+ start, end,
+ sexp);
+
+ g_free (start);
+ g_free (end);
+
+ return new_sexp;
+}
+
+
+/* Restarts a query for the day view */
+static void
+update_query (EDayView *day_view)
+{
+ char *real_sexp;
+
+ e_day_view_free_events (day_view);
+ gtk_widget_queue_draw (day_view->top_canvas);
+ gtk_widget_queue_draw (day_view->main_canvas);
+
+ if (!(day_view->client
+ && cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED))
+ return;
+
+ if (day_view->query) {
+ gtk_signal_disconnect_by_data (GTK_OBJECT (day_view->query), day_view);
+ gtk_object_unref (GTK_OBJECT (day_view->query));
+ }
+
+ g_assert (day_view->sexp != NULL);
+ real_sexp = adjust_query_sexp (day_view, day_view->sexp);
+
+ day_view->query = cal_client_get_query (day_view->client, real_sexp);
+ g_free (real_sexp);
+
+ if (!day_view->query) {
+ g_message ("update_query(): Could not create the query");
+ return;
+ }
+
+ gtk_signal_connect (GTK_OBJECT (day_view->query), "obj_updated",
+ GTK_SIGNAL_FUNC (query_obj_updated_cb), day_view);
+ gtk_signal_connect (GTK_OBJECT (day_view->query), "obj_removed",
+ GTK_SIGNAL_FUNC (query_obj_removed_cb), day_view);
+ gtk_signal_connect (GTK_OBJECT (day_view->query), "query_done",
+ GTK_SIGNAL_FUNC (query_query_done_cb), day_view);
+ gtk_signal_connect (GTK_OBJECT (day_view->query), "eval_error",
+ GTK_SIGNAL_FUNC (query_eval_error_cb), day_view);
+}
+
+/* Callback used when the calendar client finishes opening */
+static void
+cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
+{
+ EDayView *day_view;
+
+ day_view = E_DAY_VIEW (data);
+
+ if (status != CAL_CLIENT_OPEN_SUCCESS)
+ return;
+
+ update_query (day_view);
+}
/**
* e_day_view_set_cal_client:
@@ -1530,17 +1621,35 @@ e_day_view_set_cal_client (EDayView *day_view,
day_view->client = client;
if (day_view->client) {
- if (cal_client_get_load_state (day_view->client) != CAL_CLIENT_LOAD_LOADED)
+ if (cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED)
+ update_query (day_view);
+ else
gtk_signal_connect (GTK_OBJECT (day_view->client), "cal_opened",
GTK_SIGNAL_FUNC (cal_opened_cb), day_view);
-
- gtk_signal_connect (GTK_OBJECT (day_view->client), "obj_updated",
- GTK_SIGNAL_FUNC (obj_updated_cb), day_view);
- gtk_signal_connect (GTK_OBJECT (day_view->client), "obj_removed",
- GTK_SIGNAL_FUNC (obj_removed_cb), day_view);
}
+}
- e_day_view_queue_reload_events (day_view);
+/**
+ * e_day_view_set_query:
+ * @day_view: A day view.
+ * @sexp: S-expression that defines the query.
+ *
+ * Sets the query sexp that the day view will use for filtering the displayed
+ * events.
+ **/
+void
+e_day_view_set_query (EDayView *day_view, const char *sexp)
+{
+ g_return_if_fail (day_view != NULL);
+ g_return_if_fail (E_IS_DAY_VIEW (day_view));
+ g_return_if_fail (sexp != NULL);
+
+ if (day_view->sexp)
+ g_free (day_view->sexp);
+
+ day_view->sexp = g_strdup (sexp);
+
+ update_query (day_view);
}
@@ -1943,7 +2052,7 @@ e_day_view_set_selected_time_range (EDayView *day_view,
/* See if we need to change the days shown. */
if (lower != day_view->lower) {
e_day_view_recalc_day_starts (day_view, lower);
- e_day_view_queue_reload_events (day_view);
+ update_query (day_view);
}
/* Set the selection. */
@@ -2140,7 +2249,8 @@ e_day_view_set_days_shown (EDayView *day_view,
e_day_view_recalc_day_starts (day_view, day_view->lower);
e_day_view_recalc_cell_sizes (day_view);
- e_day_view_queue_reload_events (day_view);
+
+ update_query (day_view);
}
@@ -2419,7 +2529,7 @@ e_day_view_recalc_work_week (EDayView *day_view)
day_view->selection_start_day = -1;
e_day_view_recalc_day_starts (day_view, lower);
- e_day_view_queue_reload_events (day_view);
+ update_query (day_view);
/* This updates the date navigator. */
e_day_view_update_calendar_selection_time (day_view);
@@ -3927,77 +4037,6 @@ e_day_view_abort_resize (EDayView *day_view,
}
-/* This frees any events currently loaded, and queues a reload. */
-static void
-e_day_view_queue_reload_events (EDayView *day_view)
-{
- e_day_view_free_events (day_view);
-
- if (day_view->reload_events_idle_id == 0) {
- /* We'll use a high idle priority here, so the events are
- reloaded before the canvas is updated. */
- day_view->reload_events_idle_id = g_idle_add_full
- (G_PRIORITY_HIGH_IDLE,
- e_day_view_reload_events_idle_cb, day_view, NULL);
- }
-}
-
-
-static gboolean
-e_day_view_reload_events_idle_cb (gpointer data)
-{
- EDayView *day_view;
-
- g_return_val_if_fail (E_IS_DAY_VIEW (data), FALSE);
-
- GDK_THREADS_ENTER ();
-
- day_view = E_DAY_VIEW (data);
-
- day_view->reload_events_idle_id = 0;
-
- e_day_view_reload_events (day_view);
-
- GDK_THREADS_LEAVE ();
- return FALSE;
-}
-
-
-static void
-e_day_view_reload_events (EDayView *day_view)
-{
- e_day_view_free_events (day_view);
-
- if (!(day_view->client
- && cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED))
- return;
-
- /* If both lower & upper are 0, then the time range hasn't been set,
- so we don't try to load any events. */
- if (day_view->lower != 0 || day_view->upper != 0) {
-#if 0
- g_print ("EDayView (%s) generating instances\n",
- day_view->work_week_view ? "Work Week" : "1 Day View");
-#endif
- cal_client_generate_instances (day_view->client,
- CALOBJ_TYPE_EVENT,
- day_view->lower,
- day_view->upper,
- e_day_view_add_event,
- day_view);
- }
-
- /* We need to do this to make sure the top canvas is resized. */
- day_view->long_events_need_layout = TRUE;
-
- e_day_view_check_layout (day_view);
- e_day_view_reshape_main_canvas_resize_bars (day_view);
-
- gtk_widget_queue_draw (day_view->top_canvas);
- gtk_widget_queue_draw (day_view->main_canvas);
-}
-
-
static void
e_day_view_free_events (EDayView *day_view)
{
diff --git a/calendar/gui/e-day-view.h b/calendar/gui/e-day-view.h
index 2379a76b87..18f8187951 100644
--- a/calendar/gui/e-day-view.h
+++ b/calendar/gui/e-day-view.h
@@ -235,6 +235,10 @@ struct _EDayView
/* Calendar client object we are monitoring */
CalClient *client;
+ /* S-expression for query and the query object */
+ char *sexp;
+ CalQuery *query;
+
/* The start and end of the days shown. */
time_t lower;
time_t upper;
@@ -270,9 +274,6 @@ struct _EDayView
gboolean long_events_need_reshape;
gboolean need_reshape[E_DAY_VIEW_MAX_DAYS];
- /* The id of our idle function to reload all events. */
- gint reload_events_idle_id;
-
/* The number of minutes per row. 5, 10, 15, 30 or 60. */
gint mins_per_row;
@@ -488,6 +489,9 @@ void e_day_view_set_calendar (EDayView *day_view,
void e_day_view_set_cal_client (EDayView *day_view,
CalClient *client);
+void e_day_view_set_query (EDayView *day_view,
+ const char *sexp);
+
/* This sets the selected time range. The EDayView will show the day or week
corresponding to the start time. If the start_time & end_time are not equal
and are both visible in the view, then the selection is set to those times,
@@ -501,16 +505,6 @@ void e_day_view_get_selected_time_range (EDayView *day_view,
time_t *start_time,
time_t *end_time);
-/* This is called when one event has been added or updated. */
-void e_day_view_update_event (EDayView *day_view,
- const gchar *uid);
-
-/* This removes all the events associated with the given uid. Note that for
- recurring events there may be more than one. If any events are found and
- removed we need to layout the events again. */
-void e_day_view_remove_event (EDayView *day_view,
- const gchar *uid);
-
/* Whether we are displaying a work-week, in which case the display always
starts on the first day of the working week. */
gboolean e_day_view_get_work_week_view (EDayView *day_view);
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 90a7b2c695..c06b568d9d 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -109,9 +109,6 @@ static gint e_week_view_convert_position_to_day (EWeekView *week_view,
static void e_week_view_update_selection (EWeekView *week_view,
gint day);
-static void e_week_view_queue_reload_events (EWeekView *week_view);
-static gboolean e_week_view_reload_events_idle_cb (gpointer data);
-static void e_week_view_reload_events (EWeekView *week_view);
static void e_week_view_free_events (EWeekView *week_view);
static gboolean e_week_view_add_event (CalComponent *comp,
time_t start,
@@ -257,13 +254,14 @@ e_week_view_init (EWeekView *week_view)
week_view->calendar = NULL;
week_view->client = NULL;
+ week_view->sexp = g_strdup ("#t"); /* match all by default */
+ week_view->query = NULL;
week_view->events = g_array_new (FALSE, FALSE,
sizeof (EWeekViewEvent));
week_view->events_sorted = TRUE;
week_view->events_need_layout = FALSE;
week_view->events_need_reshape = FALSE;
- week_view->reload_events_idle_id = 0;
week_view->spans = NULL;
@@ -383,7 +381,7 @@ e_week_view_init (EWeekView *week_view)
/* Create the cursors. */
- week_view->normal_cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
+ week_view->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR);
week_view->move_cursor = gdk_cursor_new (GDK_FLEUR);
week_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
week_view->last_cursor_set = NULL;
@@ -416,17 +414,23 @@ e_week_view_destroy (GtkObject *object)
e_week_view_free_events (week_view);
- if (week_view->reload_events_idle_id != 0) {
- g_source_remove (week_view->reload_events_idle_id);
- week_view->reload_events_idle_id = 0;
- }
-
if (week_view->client) {
gtk_signal_disconnect_by_data (GTK_OBJECT (week_view->client), week_view);
gtk_object_unref (GTK_OBJECT (week_view->client));
week_view->client = NULL;
}
+ if (week_view->sexp) {
+ g_free (week_view->sexp);
+ week_view->sexp = NULL;
+ }
+
+ if (week_view->query) {
+ gtk_signal_disconnect_by_data (GTK_OBJECT (week_view->query), week_view);
+ gtk_object_unref (GTK_OBJECT (week_view->query));
+ week_view->query = NULL;
+ }
+
if (week_view->small_font)
gdk_font_unref (week_view->small_font);
@@ -880,23 +884,11 @@ e_week_view_set_calendar (EWeekView *week_view,
}
-/* Callback used when the calendar client finishes opening */
-static void
-cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
-{
- EWeekView *week_view;
-
- week_view = E_WEEK_VIEW (data);
-
- if (status != CAL_CLIENT_OPEN_SUCCESS)
- return;
-
- e_week_view_queue_reload_events (week_view);
-}
-
-/* Callback used when the calendar client tells us that an object changed */
+/* Callback used when a component is updated in the live query */
static void
-obj_updated_cb (CalClient *client, const char *uid, gpointer data)
+query_obj_updated_cb (CalQuery *query, const char *uid,
+ gboolean query_in_progress, int n_scanned, int total,
+ gpointer data)
{
EWeekView *week_view;
EWeekViewEvent *event;
@@ -906,9 +898,6 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
week_view = E_WEEK_VIEW (data);
- /* Sanity check. */
- g_return_if_fail (client == week_view->client);
-
/* If we don't have a valid date set yet, just return. */
if (!g_date_valid (&week_view->first_day_shown))
return;
@@ -930,12 +919,6 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
return;
}
- /* We only care about events. */
- if (cal_component_get_vtype (comp) != CAL_COMPONENT_EVENT) {
- gtk_object_unref (GTK_OBJECT (comp));
- return;
- }
-
/* If the event already exists and the dates didn't change, we can
update the event fairly easily without changing the events arrays
or computing a new layout. */
@@ -981,9 +964,9 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
gtk_widget_queue_draw (week_view->main_canvas);
}
-/* Callback used when the calendar client tells us that an object was removed */
+/* Callback used when a component is removed from the live query */
static void
-obj_removed_cb (CalClient *client, const char *uid, gpointer data)
+query_obj_removed_cb (CalClient *client, const char *uid, gpointer data)
{
EWeekView *week_view;
@@ -996,6 +979,117 @@ obj_removed_cb (CalClient *client, const char *uid, gpointer data)
gtk_widget_queue_draw (week_view->main_canvas);
}
+/* Callback used when a query ends */
+static void
+query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data)
+{
+ EWeekView *week_view;
+
+ week_view = E_WEEK_VIEW (data);
+
+ /* FIXME */
+
+ if (status != CAL_QUERY_DONE_SUCCESS)
+ fprintf (stderr, "query done: %s\n", error_str);
+}
+
+/* Callback used when an evaluation error occurs when running a query */
+static void
+query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data)
+{
+ EWeekView *week_view;
+
+ week_view = E_WEEK_VIEW (data);
+
+ /* FIXME */
+
+ fprintf (stderr, "eval error: %s\n", error_str);
+}
+
+/* Builds a complete query sexp for the week view by adding the predicates to
+ * filter only for VEVENTS that fit in the week view's time range.
+ */
+static char *
+adjust_query_sexp (EWeekView *week_view, const char *sexp)
+{
+ int num_days;
+ char *start, *end;
+ char *new_sexp;
+
+ /* If the dates have not been set yet, we just want an empty query. */
+ if (!g_date_valid (&week_view->first_day_shown))
+ return g_strdup ("#f");
+
+ num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;
+
+ start = isodate_from_time_t (week_view->day_starts[0]);
+ end = isodate_from_time_t (week_view->day_starts[num_days]);
+
+ new_sexp = g_strdup_printf ("(and (= (get-vtype) \"VEVENT\")"
+ " (occur-in-time-range? (make-time \"%s\")"
+ " (make-time \"%s\"))"
+ " %s)",
+ start, end,
+ sexp);
+
+ g_free (start);
+ g_free (end);
+
+ return new_sexp;
+}
+
+/* Restarts a query for the week view */
+static void
+update_query (EWeekView *week_view)
+{
+ char *real_sexp;
+
+ e_week_view_free_events (week_view);
+ gtk_widget_queue_draw (week_view->main_canvas);
+
+ if (!(week_view->client
+ && cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED))
+ return;
+
+ if (week_view->query) {
+ gtk_signal_disconnect_by_data (GTK_OBJECT (week_view->query), week_view);
+ gtk_object_unref (GTK_OBJECT (week_view->query));
+ }
+
+ g_assert (week_view->sexp != NULL);
+ real_sexp = adjust_query_sexp (week_view, week_view->sexp);
+
+ week_view->query = cal_client_get_query (week_view->client, real_sexp);
+ g_free (real_sexp);
+
+ if (!week_view->query) {
+ g_message ("update_query(): Could not create the query");
+ return;
+ }
+
+ gtk_signal_connect (GTK_OBJECT (week_view->query), "obj_updated",
+ GTK_SIGNAL_FUNC (query_obj_updated_cb), week_view);
+ gtk_signal_connect (GTK_OBJECT (week_view->query), "obj_removed",
+ GTK_SIGNAL_FUNC (query_obj_removed_cb), week_view);
+ gtk_signal_connect (GTK_OBJECT (week_view->query), "query_done",
+ GTK_SIGNAL_FUNC (query_query_done_cb), week_view);
+ gtk_signal_connect (GTK_OBJECT (week_view->query), "eval_error",
+ GTK_SIGNAL_FUNC (query_eval_error_cb), week_view);
+}
+
+/* Callback used when the calendar client finishes opening */
+static void
+cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
+{
+ EWeekView *week_view;
+
+ week_view = E_WEEK_VIEW (data);
+
+ if (status != CAL_CLIENT_OPEN_SUCCESS)
+ return;
+
+ update_query (week_view);
+}
/**
* e_week_view_set_cal_client:
@@ -1028,17 +1122,35 @@ e_week_view_set_cal_client (EWeekView *week_view,
week_view->client = client;
if (week_view->client) {
- if (cal_client_get_load_state (week_view->client) != CAL_CLIENT_LOAD_LOADED)
+ if (cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED)
+ update_query (week_view);
+ else
gtk_signal_connect (GTK_OBJECT (week_view->client), "cal_opened",
GTK_SIGNAL_FUNC (cal_opened_cb), week_view);
-
- gtk_signal_connect (GTK_OBJECT (week_view->client), "obj_updated",
- GTK_SIGNAL_FUNC (obj_updated_cb), week_view);
- gtk_signal_connect (GTK_OBJECT (week_view->client), "obj_removed",
- GTK_SIGNAL_FUNC (obj_removed_cb), week_view);
}
+}
+
+/**
+ * e_week_view_set_query:
+ * @week_view: A week view.
+ * @sexp: S-expression that defines the query.
+ *
+ * Sets the query sexp that the week view will use for filtering the displayed
+ * events.
+ **/
+void
+e_week_view_set_query (EWeekView *week_view, const char *sexp)
+{
+ g_return_if_fail (week_view != NULL);
+ g_return_if_fail (E_IS_WEEK_VIEW (week_view));
+ g_return_if_fail (sexp != NULL);
+
+ if (week_view->sexp)
+ g_free (week_view->sexp);
- e_week_view_queue_reload_events (week_view);
+ week_view->sexp = g_strdup (sexp);
+
+ update_query (week_view);
}
@@ -1108,7 +1220,7 @@ e_week_view_set_selected_time_range (EWeekView *week_view,
start_time = time_add_day (start_time, -day_offset);
start_time = time_day_begin (start_time);
e_week_view_recalc_day_starts (week_view, start_time);
- e_week_view_queue_reload_events (week_view);
+ update_query (week_view);
}
/* Set the selection to the given days. */
@@ -1139,7 +1251,6 @@ e_week_view_set_selected_time_range (EWeekView *week_view,
if (update_adjustment_value)
gtk_adjustment_set_value (GTK_RANGE (week_view->vscrollbar)->adjustment, 0);
-
gtk_widget_queue_draw (week_view->main_canvas);
}
@@ -1227,7 +1338,7 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
g_date_to_struct_tm (&base_date, &start_tm);
start_time = mktime (&start_tm);
e_week_view_recalc_day_starts (week_view, start_time);
- e_week_view_queue_reload_events (week_view);
+ update_query (week_view);
}
/* Try to keep the previous selection, but if it is no longer shown
@@ -1256,7 +1367,6 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
if (update_adjustment_value)
gtk_adjustment_set_value (GTK_RANGE (week_view->vscrollbar)->adjustment, 0);
-
gtk_widget_queue_draw (week_view->main_canvas);
}
@@ -1364,8 +1474,7 @@ e_week_view_set_weeks_shown (EWeekView *week_view,
if (g_date_valid (&week_view->first_day_shown))
e_week_view_set_first_day_shown (week_view, &week_view->first_day_shown);
- /* Make sure the events are reloaded. */
- e_week_view_queue_reload_events (week_view);
+ update_query (week_view);
}
}
@@ -2019,77 +2128,6 @@ e_week_view_update_selection (EWeekView *week_view,
}
-/* This frees any events currently loaded, and queues a reload. */
-static void
-e_week_view_queue_reload_events (EWeekView *week_view)
-{
- e_week_view_free_events (week_view);
-
- if (week_view->reload_events_idle_id == 0) {
- /* We'll use a low priority here, so the user can scroll
- the view quickly. */
- week_view->reload_events_idle_id = g_idle_add_full
- (G_PRIORITY_LOW,
- e_week_view_reload_events_idle_cb, week_view, NULL);
- }
-}
-
-
-static gboolean
-e_week_view_reload_events_idle_cb (gpointer data)
-{
- EWeekView *week_view;
-
- g_return_val_if_fail (E_IS_WEEK_VIEW (data), FALSE);
-
- GDK_THREADS_ENTER ();
-
- week_view = E_WEEK_VIEW (data);
-
- week_view->reload_events_idle_id = 0;
-
- e_week_view_reload_events (week_view);
-
- GDK_THREADS_LEAVE ();
- return FALSE;
-}
-
-
-static void
-e_week_view_reload_events (EWeekView *week_view)
-{
- gint num_days;
-
- e_week_view_free_events (week_view);
-
- if (!(week_view->client
- && cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED))
- return;
-
- /* Only load events if the date range has been set. */
- if (g_date_valid (&week_view->first_day_shown)) {
- num_days = week_view->multi_week_view
- ? week_view->weeks_shown * 7 : 7;
-
-#if 0
- g_print ("EWeekView (%s) generating instances\n",
- week_view->multi_week_view ? "Month View" : "Week View");
-#endif
- cal_client_generate_instances (week_view->client,
- CALOBJ_TYPE_EVENT,
- week_view->day_starts[0],
- week_view->day_starts[num_days],
- e_week_view_add_event,
- week_view);
- }
-
- week_view->events_need_reshape = TRUE;
- e_week_view_check_layout (week_view);
-
- gtk_widget_queue_draw (week_view->main_canvas);
-}
-
-
static void
e_week_view_free_events (EWeekView *week_view)
{
@@ -2777,7 +2815,7 @@ e_week_view_on_adjustment_changed (GtkAdjustment *adjustment,
lower = time_day_begin (lower);
e_week_view_recalc_day_starts (week_view, lower);
- e_week_view_queue_reload_events (week_view);
+ update_query (week_view);
/* Update the selection, if needed. */
if (week_view->selection_start_day != -1) {
diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h
index 47362d0ee6..6717da9ea3 100644
--- a/calendar/gui/e-week-view.h
+++ b/calendar/gui/e-week-view.h
@@ -186,15 +186,16 @@ struct _EWeekView
/* Calendar client object we are monitoring */
CalClient *client;
+ /* S-expression for query and the query object */
+ char *sexp;
+ CalQuery *query;
+
/* The array of EWeekViewEvent elements. */
GArray *events;
gboolean events_sorted;
gboolean events_need_layout;
gboolean events_need_reshape;
- /* The id of our idle function to reload all events. */
- gint reload_events_idle_id;
-
/* An array of EWeekViewEventSpan elements. Each event has its own
space within this array, and uses the spans_index and num_spans
fields of the EWeekViewEvent struct to access it. */
@@ -363,6 +364,9 @@ void e_week_view_set_first_day_shown (EWeekView *week_view,
void e_week_view_set_cal_client (EWeekView *week_view,
CalClient *client);
+void e_week_view_set_query (EWeekView *week_view,
+ const char *sexp);
+
/* The selected time range. The EWeekView will show the corresponding
month and the days between start_time and end_time will be selected.
To select a single day, use the same value for start_time & end_time. */