aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/calendar-commands.c132
-rw-r--r--calendar/gui/corba-cal.c1
-rw-r--r--calendar/gui/e-day-view.c30
-rw-r--r--calendar/gui/e-week-view-event-item.c8
-rw-r--r--calendar/gui/e-week-view.c56
-rw-r--r--calendar/gui/gncal-todo.c1
-rw-r--r--calendar/gui/gnome-cal.c92
7 files changed, 230 insertions, 90 deletions
diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c
index 3b3f0edab0..87d63140dd 100644
--- a/calendar/gui/calendar-commands.c
+++ b/calendar/gui/calendar-commands.c
@@ -295,6 +295,7 @@ show_day_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path)
{
GnomeCalendar *gcal = GNOME_CALENDAR (user_data);
gnome_calendar_set_view (gcal, "dayview");
+ gtk_widget_grab_focus (gcal->day_view);
}
static void
@@ -302,6 +303,7 @@ show_work_week_view_clicked (BonoboUIHandler *uih, void *user_data, const char *
{
GnomeCalendar *gcal = GNOME_CALENDAR (user_data);
gnome_calendar_set_view (gcal, "workweekview");
+ gtk_widget_grab_focus (gcal->work_week_view);
}
static void
@@ -309,6 +311,7 @@ show_week_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path)
{
GnomeCalendar *gcal = GNOME_CALENDAR (user_data);
gnome_calendar_set_view (gcal, "weekview");
+ gtk_widget_grab_focus (gcal->week_view);
}
static void
@@ -316,6 +319,7 @@ show_month_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path
{
GnomeCalendar *gcal = GNOME_CALENDAR (user_data);
gnome_calendar_set_view (gcal, "monthview");
+ gtk_widget_grab_focus (gcal->month_view);
}
static void
@@ -323,6 +327,7 @@ show_year_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path)
{
GnomeCalendar *gcal = GNOME_CALENDAR (user_data);
gnome_calendar_set_view (gcal, "yearview");
+ gtk_widget_grab_focus (gcal->year_view);
}
static void
@@ -454,7 +459,7 @@ static GnomeUIInfo gnome_toolbar_view_buttons [] = {
GNOMEUIINFO_RADIOITEM (N_("Day"), N_("Show 1 day"),
show_day_view_clicked,
dayview_xpm),
- GNOMEUIINFO_RADIOITEM (N_("5 Days"), N_("Show 5 days"),
+ GNOMEUIINFO_RADIOITEM (N_("5 Days"), N_("Show the working week"),
show_work_week_view_clicked,
workweekview_xpm),
GNOMEUIINFO_RADIOITEM (N_("Week"), N_("Show 1 week"),
@@ -806,36 +811,61 @@ calendar_iterate (GnomeCalendar *cal,
time_t start, time_t end,
calendarfn cb, void *closure)
{
- GList *l, *uids = 0;
+ GList *l, *cois;
+ GHashTable *cache;
+ CalObjFindStatus status;
+ CalObjInstance *coi;
+ char *uid, *obj_string;
+ iCalObject *ico;
- uids = cal_client_get_uids (cal->client, CALOBJ_TYPE_EVENT);
+ cois = cal_client_get_events_in_range (cal->client, start, end);
- for (l = uids; l; l = l->next){
- CalObjFindStatus status;
- iCalObject *ico;
- char *uid = l->data;
- char *obj_string = cal_client_get_object (cal->client, uid);
+ /* We use a hash table to keep a cache of uid->iCalObject, so for
+ recurring events we only load and parse the objects once. */
+ cache = g_hash_table_new (g_str_hash, g_str_equal);
- /*iCalObject *obj = string_to_ical_object (obj_string);*/
- status = ical_object_find_in_string (uid, obj_string, &ico);
- switch (status){
- case CAL_OBJ_FIND_SUCCESS:
- ical_object_generate_events (ico, start, end,
- cb, closure);
- break;
- case CAL_OBJ_FIND_SYNTAX_ERROR:
- printf("calendar_iterate: syntax error uid=%s\n",uid);
- break;
- case CAL_OBJ_FIND_NOT_FOUND:
- printf("calendar_iterate: obj not found uid=%s\n",uid);
- break;
+ for (l = cois; l; l = l->next) {
+ coi = l->data;
+ uid = coi->uid;
+
+ ico = g_hash_table_lookup (cache, uid);
+ if (!ico) {
+ obj_string = cal_client_get_object (cal->client, uid);
+
+ status = ical_object_find_in_string (uid, obj_string,
+ &ico);
+ g_free (obj_string);
+
+ switch (status) {
+ case CAL_OBJ_FIND_SUCCESS:
+ g_hash_table_insert (cache, ico->uid, ico);
+
+ break;
+ case CAL_OBJ_FIND_SYNTAX_ERROR:
+ printf ("calendar_iterate: syntax error uid=%s\n",
+ uid);
+ ico = NULL;
+ break;
+ case CAL_OBJ_FIND_NOT_FOUND:
+ printf ("calendar_iterate: obj not found uid=%s\n",
+ uid);
+ ico = NULL;
+ break;
+ }
}
- /* FIXME: add g_free (obj_string) ? */
+ if (ico)
+ (*cb) (ico, coi->start, coi->end, closure);
- g_free (l->data);
+ g_free (uid);
+ g_free (coi);
}
- g_list_free (uids);
+
+ g_list_free (cois);
+
+ /* Note that we don't need to free the hash keys since they are part
+ of the iCalObjects. */
+ g_hash_table_destroy (cache);
}
@@ -852,34 +882,38 @@ calendar_object_compare_by_start (gconstpointer a, gconstpointer b)
}
/* FIXME -- where should this (and calendar_object_compare_by_start) go? */
+/* FIXME -- for recurring events we should only load the iCalObject once. */
/* returns a list of events in the form of CalendarObject* */
-GList *calendar_get_events_in_range (CalClient *calc,
- time_t start, time_t end)
-{
- GList *l, *uids, *res = 0;
- uids = cal_client_get_events_in_range (calc, start, end);
+GList*
+calendar_get_events_in_range (CalClient *calc,
+ time_t start, time_t end)
+{
+ GList *l, *cois, *res = NULL;
+ CalObjFindStatus status;
+ CalObjInstance *coi;
+ char *uid, *obj_string;
+ iCalObject *ico;
+ CalendarObject *co;
- for (l = uids; l; l = l->next){
- CalObjFindStatus status;
- CalObjInstance *coi = l->data;
- char *uid = coi->uid;
- char *obj_string = cal_client_get_object (calc, uid);
- iCalObject *ico;
+ cois = cal_client_get_events_in_range (calc, start, end);
+ for (l = cois; l; l = l->next) {
+ coi = l->data;
+ uid = coi->uid;
+ obj_string = cal_client_get_object (calc, uid);
status = ical_object_find_in_string (uid, obj_string, &ico);
+ g_free (obj_string);
+
switch (status){
case CAL_OBJ_FIND_SUCCESS:
- {
- CalendarObject *co = g_new (CalendarObject, 1);
- co->ev_start = start;
- co->ev_end = end;
- co->ico = ico;
-
- res = g_list_insert_sorted (res, co,
- calendar_object_compare_by_start);
- break;
- }
+ co = g_new (CalendarObject, 1);
+ co->ev_start = coi->start;
+ co->ev_end = coi->end;
+ co->ico = ico;
+
+ res = g_list_prepend (res, co);
+ break;
case CAL_OBJ_FIND_SYNTAX_ERROR:
printf ("calendar_get_events_in_range: "
"syntax error uid=%s\n", uid);
@@ -890,7 +924,15 @@ GList *calendar_get_events_in_range (CalClient *calc,
break;
}
+ g_free (uid);
+ g_free (coi);
}
+ g_list_free (cois);
+
+ /* Sort the list here, since it is more efficient to sort it once
+ rather doing lots of sorted insertions. */
+ res = g_list_sort (res, calendar_object_compare_by_start);
+
return res;
}
diff --git a/calendar/gui/corba-cal.c b/calendar/gui/corba-cal.c
index 38e17256c4..72fd3bac1f 100644
--- a/calendar/gui/corba-cal.c
+++ b/calendar/gui/corba-cal.c
@@ -127,6 +127,7 @@ calendar_object_find_by_pilot (GnomeCalendar *cal, int pilot_id)
for (l = uids; l; l = l->next){
char *obj_string = cal_client_get_object (cal->calc, l->data);
iCalObject *obj = string_to_ical_object (obj_string);
+ g_free (obj_string);
if (obj->pilot_id == pilot_id)
return obj;
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 6a1383d180..655afd73dc 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -775,11 +775,11 @@ e_day_view_init (EDayView *day_view)
day_view->last_cursor_set_in_main_canvas = NULL;
/* Set up the drop sites. */
- gtk_drag_dest_set (GTK_WIDGET (day_view->top_canvas),
+ gtk_drag_dest_set (day_view->top_canvas,
GTK_DEST_DEFAULT_ALL,
target_table, n_targets,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
- gtk_drag_dest_set (GTK_WIDGET (day_view->main_canvas),
+ gtk_drag_dest_set (day_view->main_canvas,
GTK_DEST_DEFAULT_ALL,
target_table, n_targets,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
@@ -1034,6 +1034,8 @@ e_day_view_focus_in (GtkWidget *widget, GdkEventFocus *event)
g_return_val_if_fail (E_IS_DAY_VIEW (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
+ g_print ("In e_day_view_focus_in\n");
+
day_view = E_DAY_VIEW (widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
@@ -1054,6 +1056,8 @@ e_day_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
g_return_val_if_fail (E_IS_DAY_VIEW (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
+ g_print ("In e_day_view_focus_out\n");
+
day_view = E_DAY_VIEW (widget);
GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
@@ -1099,6 +1103,9 @@ e_day_view_update_event (EDayView *day_view,
g_return_if_fail (E_IS_DAY_VIEW (day_view));
#if 0
+ /* FIXME: Just for testing. */
+ chdir ("/home/damon/tmp");
+
g_print ("In e_day_view_update_event day_view:%p uid:%s\n",
day_view, uid);
#endif
@@ -1111,6 +1118,7 @@ e_day_view_update_event (EDayView *day_view,
/* Get the event from the server. */
obj_string = cal_client_get_object (day_view->calendar->client, uid);
status = ical_object_find_in_string (uid, obj_string, &ico);
+ g_free (obj_string);
switch (status) {
case CAL_OBJ_FIND_SUCCESS:
@@ -1132,6 +1140,7 @@ e_day_view_update_event (EDayView *day_view,
update the event fairly easily without changing the events arrays
or computing a new layout. */
if (e_day_view_find_event_from_uid (day_view, uid, &day, &event_num)) {
+ g_print (" updating existing event\n");
if (day == E_DAY_VIEW_LONG_EVENT)
event = &g_array_index (day_view->long_events,
EDayViewEvent, event_num);
@@ -1140,6 +1149,7 @@ e_day_view_update_event (EDayView *day_view,
EDayViewEvent, event_num);
if (ical_object_compare_dates (event->ico, ico)) {
+ g_print (" unchanged dates\n");
e_day_view_foreach_event_with_uid (day_view, uid, e_day_view_update_event_cb, ico);
gtk_widget_queue_draw (day_view->top_canvas);
gtk_widget_queue_draw (day_view->main_canvas);
@@ -1148,12 +1158,14 @@ e_day_view_update_event (EDayView *day_view,
/* The dates have changed, so we need to remove the
old occurrrences before adding the new ones. */
+ g_print (" changed dates\n");
e_day_view_foreach_event_with_uid (day_view, uid,
e_day_view_remove_event_cb,
NULL);
}
/* Add the occurrences of the event. */
+ g_print (" generating events\n");
ical_object_generate_events (ico, day_view->lower, day_view->upper,
e_day_view_add_event, day_view);
@@ -1175,6 +1187,9 @@ e_day_view_update_event_cb (EDayView *day_view,
ico = data;
+ g_print ("In e_day_view_update_event_cb day:%i event_num:%i\n",
+ day, event_num);
+
/* FIXME: When do ico's get freed? */
if (day == E_DAY_VIEW_LONG_EVENT) {
event = &g_array_index (day_view->long_events, EDayViewEvent,
@@ -1240,7 +1255,8 @@ e_day_view_foreach_event_with_uid (EDayView *day_view,
EDayViewEvent, event_num);
if (event->ico && event->ico->uid
&& !strcmp (uid, event->ico->uid)) {
- if (!(*callback) (day_view, day, event_num, data))
+ if (!(*callback) (day_view, E_DAY_VIEW_LONG_EVENT,
+ event_num, data))
return;
}
}
@@ -1405,9 +1421,13 @@ e_day_view_find_event_from_item (EDayView *day_view,
}
-/* Finds the day and index of the event containing the iCalObject.
+/* Finds the day and index of the event with the given uid.
If is is a long event, E_DAY_VIEW_LONG_EVENT is returned as the day.
- Returns TRUE if the event was found. */
+ Returns TRUE if an event with the uid was found.
+ Note that for recurring events there may be several EDayViewEvents, one
+ for each instance, all with the same iCalObject and uid. So only use this
+ function if you know the event doesn't recur or you are just checking to
+ see if any events with the uid exist. */
static gboolean
e_day_view_find_event_from_uid (EDayView *day_view,
const gchar *uid,
diff --git a/calendar/gui/e-week-view-event-item.c b/calendar/gui/e-week-view-event-item.c
index 3bacdc68f9..32d06381f4 100644
--- a/calendar/gui/e-week-view-event-item.c
+++ b/calendar/gui/e-week-view-event-item.c
@@ -646,6 +646,9 @@ e_week_view_event_item_button_press (EWeekViewEventItem *wveitem,
if (pos == E_WEEK_VIEW_POS_NONE)
return FALSE;
+ week_view->pressed_event_num = wveitem->event_num;
+ week_view->pressed_span_num = wveitem->span_num;
+
/* Ignore clicks on the event while editing. */
if (E_TEXT (span->text_item)->editing)
return FALSE;
@@ -653,9 +656,6 @@ e_week_view_event_item_button_press (EWeekViewEventItem *wveitem,
if (bevent->button.button == 1) {
/* Remember the item clicked and the mouse position,
so we can start a drag if the mouse moves. */
- week_view->pressed_event_num = wveitem->event_num;
- week_view->pressed_span_num = wveitem->span_num;
-
week_view->drag_event_x = bevent->button.x;
week_view->drag_event_y = bevent->button.y;
@@ -685,7 +685,7 @@ e_week_view_event_item_button_release (EWeekViewEventItem *wveitem,
week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent);
g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);
-#if 0
+#if 1
g_print ("In e_week_view_event_item_button_release\n");
#endif
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 6f371a10c4..bf01b66831 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -986,6 +986,7 @@ e_week_view_update_event (EWeekView *week_view,
/* Get the event from the server. */
obj_string = cal_client_get_object (week_view->calendar->client, uid);
status = ical_object_find_in_string (uid, obj_string, &ico);
+ g_free (obj_string);
switch (status) {
case CAL_OBJ_FIND_SUCCESS:
@@ -1318,7 +1319,11 @@ e_week_view_on_button_press (GtkWidget *widget,
{
gint x, y, day;
- /* If an event is pressed, just return. */
+#if 0
+ g_print ("In e_week_view_on_button_press\n");
+#endif
+
+ /* If an event is pressed just return. */
if (week_view->pressed_event_num != -1)
return FALSE;
@@ -1360,6 +1365,10 @@ e_week_view_on_button_release (GtkWidget *widget,
{
time_t start, end;
+#if 0
+ g_print ("In e_week_view_on_button_release\n");
+#endif
+
if (week_view->selection_drag_pos != E_WEEK_VIEW_DRAG_NONE) {
week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE;
gdk_pointer_ungrab (event->time);
@@ -1567,6 +1576,13 @@ e_week_view_add_event (iCalObject *ico,
/* Check that the event times are valid. */
num_days = week_view->display_month ? E_WEEK_VIEW_MAX_WEEKS * 7 : 7;
+
+#if 0
+ g_print ("View start:%li end:%li Event start:%li end:%li\n",
+ week_view->day_starts[0], week_view->day_starts[num_days],
+ start, end);
+#endif
+
g_return_val_if_fail (start <= end, TRUE);
g_return_val_if_fail (start < week_view->day_starts[num_days], TRUE);
g_return_val_if_fail (end > week_view->day_starts[0], TRUE);
@@ -2128,6 +2144,8 @@ e_week_view_start_editing_event (EWeekView *week_view,
ETextEventProcessor *event_processor = NULL;
ETextEventProcessorCommand command;
+ g_print ("In e_week_view_start_editing_event\n");
+
/* If we are already editing the event, just return. */
if (event_num == week_view->editing_event_num
&& span_num == week_view->editing_span_num)
@@ -2159,6 +2177,8 @@ e_week_view_start_editing_event (EWeekView *week_view,
gtk_signal_emit_by_name (GTK_OBJECT (event_processor),
"command", &command);
}
+
+ g_print ("Out e_week_view_start_editing_event\n");
}
@@ -2187,8 +2207,13 @@ e_week_view_on_text_item_event (GnomeCanvasItem *item,
{
gint event_num, span_num;
+#if 0
+ g_print ("In e_week_view_on_text_item_event\n");
+#endif
+
switch (event->type) {
case GDK_BUTTON_PRESS:
+ g_print (" button press\n");
if (!e_week_view_find_event_from_item (week_view, item,
&event_num, &span_num))
return FALSE;
@@ -2202,15 +2227,15 @@ e_week_view_on_text_item_event (GnomeCanvasItem *item,
return TRUE;
}
+ week_view->pressed_event_num = event_num;
+ week_view->pressed_span_num = span_num;
+
/* Only let the EText handle the event while editing. */
if (!E_TEXT (item)->editing) {
+ g_print (" stopping signal\n");
gtk_signal_emit_stop_by_name (GTK_OBJECT (item),
"event");
-
- week_view->pressed_event_num = event_num;
- week_view->pressed_span_num = span_num;
-
if (event) {
week_view->drag_event_x = event->button.x;
week_view->drag_event_y = event->button.y;
@@ -2219,10 +2244,14 @@ e_week_view_on_text_item_event (GnomeCanvasItem *item,
/* FIXME: Remember the day offset from the start of
the event. */
+
+ return TRUE;
}
break;
case GDK_BUTTON_RELEASE:
+ g_print (" button release\n");
if (!E_TEXT (item)->editing) {
+ g_print (" stopping signal\n");
gtk_signal_emit_stop_by_name (GTK_OBJECT (item),
"event");
@@ -2242,6 +2271,8 @@ e_week_view_on_text_item_event (GnomeCanvasItem *item,
week_view->pressed_event_num = -1;
return TRUE;
}
+ } else {
+ g_print (" EText may get button release event\n");
}
week_view->pressed_event_num = -1;
break;
@@ -2273,6 +2304,8 @@ e_week_view_on_editing_started (EWeekView *week_view,
&event_num, &span_num))
return;
+ g_print ("In e_week_view_on_editing_started event_num:%i span_num:%i\n", event_num, span_num);
+
week_view->editing_event_num = event_num;
week_view->editing_span_num = span_num;
@@ -2282,6 +2315,8 @@ e_week_view_on_editing_started (EWeekView *week_view,
e_week_view_reshape_event_span (week_view, event_num,
span_num);
}
+
+ g_print ("Out e_week_view_on_editing_started\n");
}
@@ -2294,6 +2329,11 @@ e_week_view_on_editing_stopped (EWeekView *week_view,
EWeekViewEventSpan *span;
gchar *text = NULL;
+ if (e_week_view_find_event_from_item (week_view, item,
+ &event_num, &span_num)) {
+ g_print ("In e_week_view_on_editing_stopped event_num:%i span_num:%i\n", event_num, span_num);
+ }
+
/* Note: the item we are passed here isn't reliable, so we just stop
the edit of whatever item was being edited. We also receive this
event twice for some reason. */
@@ -2372,6 +2412,12 @@ e_week_view_find_event_from_item (EWeekView *week_view,
}
+/* Finds the index of the event with the given uid.
+ Returns TRUE if an event with the uid was found.
+ Note that for recurring events there may be several EWeekViewEvents, one
+ for each instance, all with the same iCalObject and uid. So only use this
+ function if you know the event doesn't recur or you are just checking to
+ see if any events with the uid exist. */
static gboolean
e_week_view_find_event_from_uid (EWeekView *week_view,
const gchar *uid,
diff --git a/calendar/gui/gncal-todo.c b/calendar/gui/gncal-todo.c
index 67f682fd10..e9ec433076 100644
--- a/calendar/gui/gncal-todo.c
+++ b/calendar/gui/gncal-todo.c
@@ -869,6 +869,7 @@ gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags)
iCalObject *obj = NULL;
st = ical_object_find_in_string (uid, obj_string, &obj);
+ g_free (obj_string);
insert_in_clist (todo, obj);
g_free (uid);
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index 748a805e9f..f7a6eb5ac4 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -36,6 +36,10 @@ static void gnome_calendar_destroy (GtkObject *object);
static void gnome_calendar_update_view_times (GnomeCalendar *gcal,
GtkWidget *page);
static void gnome_calendar_update_gtk_calendar (GnomeCalendar *gcal);
+static int gnome_calendar_mark_gtk_calendar_day (GnomeCalendar *cal,
+ GtkCalendar *gtk_cal,
+ time_t start,
+ time_t end);
static void gnome_calendar_on_day_selected (GtkCalendar *calendar,
GnomeCalendar *gcal);
static void gnome_calendar_on_month_changed (GtkCalendar *calendar,
@@ -814,33 +818,6 @@ calendar_notify (time_t activation_time, CalendarAlarm *which, void *data)
}
/*
- * called from the calendar_iterate routine to mark the days of a GtkCalendar
- */
-static int
-mark_gtk_calendar_day (iCalObject *obj, time_t start, time_t end, void *c)
-{
- GtkCalendar *gtk_cal = c;
- struct tm tm_s, tm_e;
- gint start_day, end_day, day;
-
- tm_s = *localtime (&start);
- tm_e = *localtime (&end);
-
- start_day = tm_s.tm_mday;
- end_day = tm_e.tm_mday;
-
- /* If the event ends at midnight then really it ends on the previous
- day (unless it started at the same time). */
- if (start != end && tm_e.tm_hour == 0 && tm_e.tm_min == 0)
- end_day--;
-
- for (day = start_day; day <= end_day; day++)
- gtk_calendar_mark_day (gtk_cal, day);
-
- return TRUE;
-}
-
-/*
* Tags the dates with appointments in a GtkCalendar based on the
* GnomeCalendar contents
*/
@@ -849,18 +826,25 @@ gnome_calendar_tag_calendar (GnomeCalendar *cal, GtkCalendar *gtk_cal)
{
time_t month_begin, month_end;
struct tm tm;
+ GList *cois, *l;
g_return_if_fail (cal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (cal));
g_return_if_fail (gtk_cal != NULL);
g_return_if_fail (GTK_IS_CALENDAR (gtk_cal));
+ /* If the GtkCalendar isn't visible, we just return. */
+ if (!GTK_WIDGET_VISIBLE (cal->gtk_calendar))
+ return;
+
/* compute month_begin */
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
- tm.tm_mday = 1; /* setting this to zero is a no-no; it will set mktime back to the end of the
- previous month, which may be 28,29,30; this may chop some days from the calendar */
+ /* setting tm_day to zero is a no-no; it will set mktime back to the
+ end of the previous month, which may be 28,29,30; this may chop
+ some days from the calendar */
+ tm.tm_mday = 1;
tm.tm_mon = gtk_cal->month;
tm.tm_year = gtk_cal->year - 1900;
tm.tm_isdst= -1;
@@ -871,11 +855,57 @@ gnome_calendar_tag_calendar (GnomeCalendar *cal, GtkCalendar *gtk_cal)
gtk_calendar_freeze (gtk_cal);
gtk_calendar_clear_marks (gtk_cal);
- calendar_iterate (cal, month_begin, month_end,
- mark_gtk_calendar_day, gtk_cal);
+
+ cois = cal_client_get_events_in_range (cal->client, month_begin,
+ month_end);
+
+ for (l = cois; l; l = l->next) {
+ CalObjInstance *coi = l->data;
+
+ gnome_calendar_mark_gtk_calendar_day (cal, gtk_cal,
+ coi->start, coi->end);
+
+ g_free (coi->uid);
+ g_free (coi);
+ }
+
+ g_list_free (cois);
+
gtk_calendar_thaw (gtk_cal);
}
+
+/*
+ * This is called from gnome_calendar_tag_calendar to mark the days of a
+ * GtkCalendar on which the user has appointments.
+ */
+static int
+gnome_calendar_mark_gtk_calendar_day (GnomeCalendar *cal,
+ GtkCalendar *gtk_cal,
+ time_t start,
+ time_t end)
+{
+ struct tm tm_s, tm_e;
+ gint start_day, end_day, day;
+
+ tm_s = *localtime (&start);
+ tm_e = *localtime (&end);
+
+ start_day = tm_s.tm_mday;
+ end_day = tm_e.tm_mday;
+
+ /* If the event ends at midnight then really it ends on the previous
+ day (unless it started at the same time). */
+ if (start != end && tm_e.tm_hour == 0 && tm_e.tm_min == 0)
+ end_day--;
+
+ for (day = start_day; day <= end_day; day++)
+ gtk_calendar_mark_day (gtk_cal, day);
+
+ return TRUE;
+}
+
+
/* This is called when the day begin & end times, the AM/PM flag, or the
week_starts_on_monday flags are changed.
FIXME: Which of these options do we want the new views to support? */