From ea787be7184b4d0c5d093b3c560b8f1879839d73 Mon Sep 17 00:00:00 2001 From: Damon Chaplin Date: Thu, 4 May 2000 21:04:40 +0000 Subject: for the long events pass E_DAY_VIEW_LONG_EVENT as the day. Fixes SEGV. 2000-05-04 Damon Chaplin * gui/e-day-view.c (e_day_view_foreach_event_with_uid): for the long events pass E_DAY_VIEW_LONG_EVENT as the day. Fixes SEGV. * gui/calendar-commands.c: when we switch views, grab the focus. * gui/gnome-cal.c (gnome_calendar_tag_calendar): (gnome_calendar_mark_gtk_calendar_day): changed this so it uses cal_client_get_events_in_range(), and doesn't load any objects. Also just return if it isn't visible. * gui/calendar-commands.c (calendar_get_events_in_range): call g_list_sort() to sort the list rather than g_list_insert_sorted() for each element. It is much more efficient. Also changed it so that the co->ev_start/end fields are copied from the CalObjInstance rather than the parameters to the function (that is right, isn't it?) Also freed the list elements, and finally the list. (calendar_iterate): changed this to use cal_client_get_events_in_range since that is more efficient than getting all the uids and then loading and parsing all the events. * pcs/cal-backend.c (save): output the '... saved' message before freeing the string! * gui/gncal-todo.c (gncal_todo_update): * gui/e-week-view.c (e_week_view_update_event): * gui/e-day-view.c (e_day_view_update_event): * gui/calendar-commands.c (calendar_get_events_in_range): (calendar_iterate): free obj_string after it is parsed. svn path=/trunk/; revision=2802 --- calendar/gui/gnome-cal.c | 92 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 31 deletions(-) (limited to 'calendar/gui/gnome-cal.c') 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, @@ -813,33 +817,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? */ -- cgit v1.2.3