diff options
author | Federico Mena Quintero <federico@ximian.com> | 2001-04-13 00:29:56 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2001-04-13 00:29:56 +0800 |
commit | 3b562b0b9f81cdd6cedea7c7c53272a98568e63a (patch) | |
tree | 16f563e4357fa6268bbd5930e29f5f17a258e81f /calendar/gui/e-day-view.c | |
parent | b1c4145cd9bde65773aa668939e8557986c205c5 (diff) | |
download | gsoc2013-evolution-3b562b0b9f81cdd6cedea7c7c53272a98568e63a.tar.gz gsoc2013-evolution-3b562b0b9f81cdd6cedea7c7c53272a98568e63a.tar.zst gsoc2013-evolution-3b562b0b9f81cdd6cedea7c7c53272a98568e63a.zip |
New function to restart a query for the day view. (query_obj_updated_cb):
2001-04-12 Federico Mena Quintero <federico@ximian.com>
* gui/e-day-view.c (update_query): New function to restart a query
for the day view.
(query_obj_updated_cb): Renamed from obj_updated_cb(); updated for
queries instead of calendar clients.
(query_obj_removed_cb): Likewise.
(cal_opened_cb): Just update_query() instead of queueing reloading
all the events.
(e_day_view_set_cal_client): Likewise.
(e_day_view_set_query): Likewise.
(e_day_view_set_selected_time_range): Likewise.
(e_day_view_set_days_shown): Likewise.
(e_day_view_recalc_work_week): Likewise.
(e_day_view_queue_reload_events): Removed function now that events
are updated entirely by the query.
(e_day_view_reload_events_idle_cb): Likewise.
(e_day_view_reload_events): Likewise.
(e_day_view_init): Use a pretty arrow instead of GDK_TOP_LEFT_ARROW.
* gui/e-week-view.c: Analogous changes to the ones in e-day-view.c.
(e_week_view_init): Use a pretty arrow instead of GDK_TOP_LEFT_ARROW.
* cal-util/timeutil.c (isodate_from_time_t): Return a g_strdup()ed
version of the string instead of a pointer to a static buffer.
(time_from_isodate): Resurrected function. Polished up to our
current standards of paranoia.
* pcs/query.c (func_time_now): New function (time-now).
(func_make_time): New function (make-time ISODATE).
(func_time_add_day): New function (time-add-day TIME N).
(func_time_day_begin): New function (time-day-begin TIME).
(func_time_day_end): New function (time-day-end TIME).
(func_occur_in_time_range): Use time_t values instead of ints.
(match_component): Free the stringized component. Free the ESexp
result value.
* gui/e-day-view.h: Removed a couple of unused prototypes.
* pcs/query.c (query_destroy): Oops, disconnect from the backend.
* pcs/cal.c (Cal_get_query): Duplicate the query reference before
we return it.
* gui/calendar-commands.c (pixmaps): Fixed paths to image files.
svn path=/trunk/; revision=9266
Diffstat (limited to 'calendar/gui/e-day-view.c')
-rw-r--r-- | calendar/gui/e-day-view.c | 283 |
1 files changed, 161 insertions, 122 deletions
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) { |