diff options
author | nobody <nobody@localhost> | 2000-05-29 23:42:50 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2000-05-29 23:42:50 +0800 |
commit | 38c3f87fa2c50a71e095b4767d57ada6ce8867fe (patch) | |
tree | 47f7d2447d64eb8e27296917d78b128ddf21cde1 /calendar/cal-util | |
parent | ccb665a0262b51c92ca5a54a074dda0dec91a573 (diff) | |
download | gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.tar gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.tar.gz gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.tar.bz2 gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.tar.lz gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.tar.xz gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.tar.zst gsoc2013-evolution-38c3f87fa2c50a71e095b4767d57ada6ce8867fe.zip |
This commit was manufactured by cvs2svn to create tag 'GTKHTML_1_4'.GTKHTML_1_4
svn path=/tags/GTKHTML_1_4/; revision=3264
Diffstat (limited to 'calendar/cal-util')
-rw-r--r-- | calendar/cal-util/.cvsignore | 6 | ||||
-rw-r--r-- | calendar/cal-util/Makefile.am | 25 | ||||
-rw-r--r-- | calendar/cal-util/cal-recur.c | 1131 | ||||
-rw-r--r-- | calendar/cal-util/cal-recur.h | 102 | ||||
-rw-r--r-- | calendar/cal-util/cal-util.c | 100 | ||||
-rw-r--r-- | calendar/cal-util/cal-util.h | 68 | ||||
-rw-r--r-- | calendar/cal-util/calobj.c | 1810 | ||||
-rw-r--r-- | calendar/cal-util/calobj.h | 287 | ||||
-rw-r--r-- | calendar/cal-util/icalendar-save.c | 509 | ||||
-rw-r--r-- | calendar/cal-util/icalendar-save.h | 13 | ||||
-rw-r--r-- | calendar/cal-util/icalendar-test.c | 146 | ||||
-rw-r--r-- | calendar/cal-util/icalendar.c | 674 | ||||
-rw-r--r-- | calendar/cal-util/icalendar.h | 13 | ||||
-rw-r--r-- | calendar/cal-util/timeutil.c | 557 | ||||
-rw-r--r-- | calendar/cal-util/timeutil.h | 81 |
15 files changed, 0 insertions, 5522 deletions
diff --git a/calendar/cal-util/.cvsignore b/calendar/cal-util/.cvsignore deleted file mode 100644 index fe97f9aa2c..0000000000 --- a/calendar/cal-util/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -.libs -Makefile.in -Makefile -.deps -*.lo -*.la diff --git a/calendar/cal-util/Makefile.am b/calendar/cal-util/Makefile.am deleted file mode 100644 index f110e96394..0000000000 --- a/calendar/cal-util/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -INCLUDES = \ - -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ - -DG_LOG_DOMAIN=\"cal-util\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/calendar \ - -I. \ - -I.. \ - -I$(top_builddir) \ - $(GNOME_INCLUDEDIR) - -lib_LTLIBRARIES = libcal-util.la - -libcal_util_la_SOURCES = \ - cal-recur.c \ - cal-util.c \ - calobj.c \ - timeutil.c - -libcal_utilincludedir = $(includedir)/evolution/cal-util - -libcal_utilinclude_HEADERS = \ - cal-recur.h \ - cal-util.h \ - calobj.h \ - timeutil.h diff --git a/calendar/cal-util/cal-recur.c b/calendar/cal-util/cal-recur.c deleted file mode 100644 index 711ef5e64d..0000000000 --- a/calendar/cal-util/cal-recur.c +++ /dev/null @@ -1,1131 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Evolution calendar recurrence rule functions - * - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Damon Chaplin <damon@helixcode.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <string.h> -#include <cal-util/cal-recur.h> -#include <cal-util/timeutil.h> - - -/* - * Introduction to The Recurrence Generation Functions: - * - * Note: This is pretty complicated. See the iCalendar spec (RFC 2445) for - * the specification of the recurrence rules and lots of examples - * (sections 4.3.10 & 4.8.5). We also want to support the older - * vCalendar spec, though this should be easy since it is basically a - * subset of iCalendar. - * - * o An iCalendar event can have any number of recurrence rules specifying - * occurrences of the event, as well as dates & times of specific - * occurrences. It can also have any number of recurrence rules and - * specific dates & times specifying exceptions to the occurrences. - * So we first merge all the occurrences generated, eliminating any - * duplicates, then we generate all the exceptions and remove these to - * form the final set of occurrences. - * - * o There are 7 frequencies of occurrences: YEARLY, MONTHLY, WEEKLY, DAILY, - * HOURLY, MINUTELY & SECONDLY. The 'interval' property specifies the - * multiples of the frequency between each 'set' of occurrences. So for - * a YEARLY frequency with an interval of 3, we generate a set of occurrences - * for every 3rd year. We use complete years here - any generated - * occurrences that occur before the event's start (or after its end) - * are just discarded. - * - * o There are 8 frequency modifiers: BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, - * BYDAY, BYHOUR & BYSECOND. These can either add extra occurrences or - * filter out occurrences. For example 'FREQ=YEARLY;BYMONTH=1,2' produces - * 2 occurrences for each year rather than the default 1. And - * 'FREQ=DAILY; BYMONTH=1' filters out all occurrences except those in Jan. - * If the modifier works on periods which are less than the recurrence - * frequency, then extra occurrences are added, else occurrences are - * filtered. So we have 2 functions for each modifier - one to expand events - * and the other to filter. We use a table of functions for each frequency - * which points to the appropriate function to use for each modifier. - * - * o Any number of frequency modifiers can be used in a recurrence rule - * (though BYWEEKNO can only be used in a YEARLY rule). They are applied in - * the order given above. - * - * o After the set of occurrences for the frequency interval are generated, - * the BYSETPOS property is used to select which of the occurrences are - * finally output. If BYSETPOS is not specified then all the occurrences are - * output. - */ - - -#define CAL_OBJ_NUM_FILTERS 8 - -typedef gboolean (*CalObjFindStartFn) (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -typedef gboolean (*CalObjFindNextFn) (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); -typedef GArray* (*CalObjFilterFn) (Recurrence *recur, - GArray *occs); - -typedef struct _CalObjRecurVTable CalObjRecurVTable; -struct _CalObjRecurVTable { - CalObjFindStartFn find_start_position; - CalObjFindNextFn find_next_position; - CalObjFilterFn filters[CAL_OBJ_NUM_FILTERS]; -}; - - -static CalObjRecurVTable* cal_obj_get_vtable (Recurrence *recur); -static void cal_obj_sort_occurrences (GArray *occs); -static gint cal_obj_time_compare_func (const void *arg1, - const void *arg2); -static void cal_obj_remove_duplicates (GArray *occs); -static GArray* cal_obj_bysetpos_filter (GArray *occs); - - -static gboolean cal_obj_yearly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_yearly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static gboolean cal_obj_monthly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_monthly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static gboolean cal_obj_weekly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_weekly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static gboolean cal_obj_daily_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_daily_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static gboolean cal_obj_hourly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_hourly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static gboolean cal_obj_minutely_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_minutely_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static gboolean cal_obj_secondly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime); -static gboolean cal_obj_secondly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end); - -static GArray* cal_obj_bymonth_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_bymonth_filter (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byweekno_expand (Recurrence *recur, - GArray *occs); -#if 0 -/* This isn't used at present. */ -static GArray* cal_obj_byweekno_filter (Recurrence *recur, - GArray *occs); -#endif -static GArray* cal_obj_byyearday_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byyearday_filter (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_bymonthday_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_bymonthday_filter (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byday_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byday_filter (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byhour_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byhour_filter (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byminute_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_byminute_filter (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_bysecond_expand (Recurrence *recur, - GArray *occs); -static GArray* cal_obj_bysecond_filter (Recurrence *recur, - GArray *occs); - -static void cal_obj_time_add_days (CalObjTime *cotime, - gint days); - - -CalObjRecurVTable cal_obj_yearly_vtable = { - cal_obj_yearly_find_start_position, - cal_obj_yearly_find_next_position, - { - cal_obj_bymonth_expand, - cal_obj_byweekno_expand, - cal_obj_byyearday_expand, - cal_obj_bymonthday_expand, - cal_obj_byday_expand, - cal_obj_byhour_expand, - cal_obj_byminute_expand, - cal_obj_bysecond_expand - }, -}; - -CalObjRecurVTable cal_obj_monthly_vtable = { - cal_obj_monthly_find_start_position, - cal_obj_monthly_find_next_position, - { - cal_obj_bymonth_filter, - NULL, - cal_obj_byyearday_filter, - cal_obj_bymonthday_expand, - cal_obj_byday_expand, - cal_obj_byhour_expand, - cal_obj_byminute_expand, - cal_obj_bysecond_expand - }, -}; - -CalObjRecurVTable cal_obj_weekly_vtable = { - cal_obj_weekly_find_start_position, - cal_obj_weekly_find_next_position, - { - cal_obj_bymonth_filter, - NULL, - cal_obj_byyearday_filter, - cal_obj_bymonthday_filter, - cal_obj_byday_expand, - cal_obj_byhour_expand, - cal_obj_byminute_expand, - cal_obj_bysecond_expand - }, -}; - -CalObjRecurVTable cal_obj_daily_vtable = { - cal_obj_daily_find_start_position, - cal_obj_daily_find_next_position, - { - cal_obj_bymonth_filter, - NULL, - cal_obj_byyearday_filter, - cal_obj_bymonthday_filter, - cal_obj_byday_filter, - cal_obj_byhour_expand, - cal_obj_byminute_expand, - cal_obj_bysecond_expand - }, -}; - -CalObjRecurVTable cal_obj_hourly_vtable = { - cal_obj_hourly_find_start_position, - cal_obj_hourly_find_next_position, - { - cal_obj_bymonth_filter, - NULL, - cal_obj_byyearday_filter, - cal_obj_bymonthday_filter, - cal_obj_byday_filter, - cal_obj_byhour_filter, - cal_obj_byminute_expand, - cal_obj_bysecond_expand - }, -}; - -CalObjRecurVTable cal_obj_minutely_vtable = { - cal_obj_minutely_find_start_position, - cal_obj_minutely_find_next_position, - { - cal_obj_bymonth_filter, - NULL, - cal_obj_byyearday_filter, - cal_obj_bymonthday_filter, - cal_obj_byday_filter, - cal_obj_byhour_filter, - cal_obj_byminute_filter, - cal_obj_bysecond_expand - }, -}; - -CalObjRecurVTable cal_obj_secondly_vtable = { - cal_obj_secondly_find_start_position, - cal_obj_secondly_find_next_position, - { - cal_obj_bymonth_filter, - NULL, - cal_obj_byyearday_filter, - cal_obj_bymonthday_filter, - cal_obj_byday_filter, - cal_obj_byhour_filter, - cal_obj_byminute_filter, - cal_obj_bysecond_filter - }, -}; - - - - -/* Returns an unsorted array of time_t's resulting from expanding the - recurrence within the given interval. Each iCalendar event can have any - number of recurrence rules specifying occurrences of the event, as well as - any number of recurrence rules specifying exceptions. */ -GArray* -cal_obj_expand_recurrence (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end) -{ - CalObjRecurVTable *vtable; - CalObjTime occ; - GArray *all_occs, *occs; - gint filter; - - vtable = cal_obj_get_vtable (recur); - - /* This is the resulting array of CalObjTime elements. */ - all_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - /* Get the first period based on the frequency and the interval that - intersects the interval between start and end. */ - if ((*vtable->find_start_position) (event_start, event_end, recur, - interval_start, interval_end, - &occ)) - return all_occs; - - /* Loop until the event ends or we go past the end of the required - interval. */ - for (;;) { - - /* We start with just the one time in the set. */ - occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - g_array_append_val (occs, occ); - - /* Generate the set of occurrences for this period. */ - for (filter = 0; filter < CAL_OBJ_NUM_FILTERS; filter++) { - if (vtable->filters[filter]) - occs = (*vtable->filters[filter]) (recur, - occs); - } - - /* Sort the occurrences and remove duplicates. */ - cal_obj_sort_occurrences (occs); - cal_obj_remove_duplicates (occs); - - /* Apply the BYSETPOS property. */ - occs = cal_obj_bysetpos_filter (occs); - - /* Add the occurrences onto the main array. */ - g_array_append_vals (all_occs, occs->data, occs->len); - - /* Skip to the next period, or exit the loop if finished. */ - if ((*vtable->find_next_position) (&occ, event_end, recur, - interval_end)) - break; - } - - return all_occs; -} - - -/* Returns the function table corresponding to the recurrence frequency. */ -static CalObjRecurVTable* -cal_obj_get_vtable (Recurrence *recur) -{ - switch (recur->type) { - case RECUR_YEARLY: - return &cal_obj_yearly_vtable; - case RECUR_MONTHLY: - return &cal_obj_monthly_vtable; - case RECUR_WEEKLY: - return &cal_obj_weekly_vtable; - case RECUR_DAILY: - return &cal_obj_daily_vtable; - case RECUR_HOURLY: - return &cal_obj_hourly_vtable; - case RECUR_MINUTELY: - return &cal_obj_minutely_vtable; - case RECUR_SECONDLY: - return &cal_obj_secondly_vtable; - } - return NULL; -} - - -static void -cal_obj_sort_occurrences (GArray *occs) -{ - qsort (occs->data, occs->len, sizeof (CalObjTime), - cal_obj_time_compare_func); -} - - -static gint -cal_obj_time_compare_func (const void *arg1, - const void *arg2) -{ - CalObjTime *cotime1, *cotime2; - - cotime1 = (CalObjTime*) arg1; - cotime2 = (CalObjTime*) arg2; - - if (cotime1->year < cotime2->year) - return -1; - if (cotime1->year > cotime2->year) - return 1; - - if (cotime1->month < cotime2->month) - return -1; - if (cotime1->month > cotime2->month) - return 1; - - if (cotime1->day < cotime2->day) - return -1; - if (cotime1->day > cotime2->day) - return 1; - - if (cotime1->hour < cotime2->hour) - return -1; - if (cotime1->hour > cotime2->hour) - return 1; - - if (cotime1->minute < cotime2->minute) - return -1; - if (cotime1->minute > cotime2->minute) - return 1; - - if (cotime1->second < cotime2->second) - return -1; - if (cotime1->second > cotime2->second) - return 1; - - return 0; -} - - -static void -cal_obj_remove_duplicates (GArray *occs) -{ - CalObjTime *occ, *prev_occ = NULL; - gint len, i, j = 0; - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - - if (!prev_occ - || cal_obj_time_compare_func (occ, prev_occ) != 0) { - if (i != j) - g_array_index (occs, CalObjTime, j) - = g_array_index (occs, CalObjTime, i); - j++; - } - - prev_occ = occ; - } - - g_array_set_size (occs, j); -} - - -static GArray* -cal_obj_bysetpos_filter (GArray *occs) -{ - - return occs; -} - - - - -static gboolean -cal_obj_yearly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_yearly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - /* NOTE: The day may now be invalid, e.g. 29th Feb. - Make sure we remove these eventually. */ - cotime->year += recur->interval; - - if (cotime->year > event_end->year - || cotime->year > interval_end->year) - return TRUE; - - return FALSE; -} - - - -static gboolean -cal_obj_monthly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_monthly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - cotime->month += recur->interval; - cotime->year += cotime->month / 12; - cotime->month %= 12; - - if (cotime->year > event_end->year - || cotime->year > interval_end->year - || (cotime->year == event_end->year - && cotime->month > event_end->month) - || (cotime->year == interval_end->year - && cotime->month > interval_end->month)) - return TRUE; - - return FALSE; -} - - - -static gboolean -cal_obj_weekly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_weekly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - cal_obj_time_add_days (cotime, recur->interval); - - - - return FALSE; -} - - -static gboolean -cal_obj_daily_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_daily_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - - cal_obj_time_add_days (cotime, recur->interval); - - - return FALSE; -} - - -static gboolean -cal_obj_hourly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_hourly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_minutely_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_minutely_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_secondly_find_start_position (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end, - CalObjTime *cotime) -{ - - - return FALSE; -} - - -static gboolean -cal_obj_secondly_find_next_position (CalObjTime *cotime, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_end) -{ - - - return FALSE; -} - - - - - -/* If the BYMONTH rule is specified it expands each occurrence in occs, by - using each of the months in the bymonth list. */ -static GArray* -cal_obj_bymonth_expand (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - GList *elem; - gint len, i; - - /* If BYMONTH has not been specified, or the array is empty, just - return the array. */ - if (!recur->bymonth || occs->len == 0) - return occs; - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - - elem = recur->bymonth; - while (elem) { - /* NOTE: The day may now be invalid, e.g. 31st Feb. - Make sure we remove these eventually. */ - occ->month = GPOINTER_TO_INT (elem->data); - g_array_append_vals (new_occs, occ, 1); - elem = elem->next; - } - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - -/* If the BYMONTH rule is specified it filters out all occurrences in occs - which do not match one of the months in the bymonth list. */ -static GArray* -cal_obj_bymonth_filter (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - guint8 months[12]; - gint mon, len, i; - GList *elem; - - /* If BYMONTH has not been specified, or the array is empty, just - return the array. */ - elem = recur->bymonth; - if (!elem || occs->len == 0) - return occs; - - /* Create an array of months from bymonths for fast lookup. */ - memset (&months, 0, sizeof (months)); - while (elem) { - mon = GPOINTER_TO_INT (elem->data); - months[mon] = 1; - elem = elem->next; - } - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - if (months[occ->month]) - g_array_append_vals (new_occs, occ, 1); - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - - -static GArray* -cal_obj_byweekno_expand (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - -#if 0 -/* This isn't used at present. */ -static GArray* -cal_obj_byweekno_filter (Recurrence *recur, - GArray *occs) -{ - - return occs; -} -#endif - - -static GArray* -cal_obj_byyearday_expand (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - -static GArray* -cal_obj_byyearday_filter (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - - -static GArray* -cal_obj_bymonthday_expand (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - -static GArray* -cal_obj_bymonthday_filter (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - - -static GArray* -cal_obj_byday_expand (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - -static GArray* -cal_obj_byday_filter (Recurrence *recur, - GArray *occs) -{ - - return occs; -} - - - -/* If the BYHOUR rule is specified it expands each occurrence in occs, by - using each of the hours in the byhour list. */ -static GArray* -cal_obj_byhour_expand (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - GList *elem; - gint len, i; - - /* If BYHOUR has not been specified, or the array is empty, just - return the array. */ - if (!recur->byhour || occs->len == 0) - return occs; - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - - elem = recur->byhour; - while (elem) { - occ->hour = GPOINTER_TO_INT (elem->data); - g_array_append_vals (new_occs, occ, 1); - elem = elem->next; - } - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - -/* If the BYHOUR rule is specified it filters out all occurrences in occs - which do not match one of the hours in the byhour list. */ -static GArray* -cal_obj_byhour_filter (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - guint8 hours[24]; - gint hour, len, i; - GList *elem; - - /* If BYHOURUTE has not been specified, or the array is empty, just - return the array. */ - elem = recur->byhour; - if (!elem || occs->len == 0) - return occs; - - /* Create an array of hours from byhour for fast lookup. */ - memset (&hours, 0, sizeof (hours)); - while (elem) { - hour = GPOINTER_TO_INT (elem->data); - hours[hour] = 1; - elem = elem->next; - } - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - if (hours[occ->hour]) - g_array_append_vals (new_occs, occ, 1); - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - - -/* If the BYMINUTE rule is specified it expands each occurrence in occs, by - using each of the minutes in the byminute list. */ -static GArray* -cal_obj_byminute_expand (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - GList *elem; - gint len, i; - - /* If BYMINUTE has not been specified, or the array is empty, just - return the array. */ - if (!recur->byminute || occs->len == 0) - return occs; - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - - elem = recur->byminute; - while (elem) { - occ->minute = GPOINTER_TO_INT (elem->data); - g_array_append_vals (new_occs, occ, 1); - elem = elem->next; - } - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - -/* If the BYMINUTE rule is specified it filters out all occurrences in occs - which do not match one of the minutes in the byminute list. */ -static GArray* -cal_obj_byminute_filter (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - guint8 minutes[60]; - gint min, len, i; - GList *elem; - - /* If BYMINUTE has not been specified, or the array is empty, just - return the array. */ - elem = recur->byminute; - if (!elem || occs->len == 0) - return occs; - - /* Create an array of minutes from byminutes for fast lookup. */ - memset (&minutes, 0, sizeof (minutes)); - while (elem) { - min = GPOINTER_TO_INT (elem->data); - minutes[min] = 1; - elem = elem->next; - } - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - if (minutes[occ->minute]) - g_array_append_vals (new_occs, occ, 1); - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - - -/* If the BYSECOND rule is specified it expands each occurrence in occs, by - using each of the seconds in the bysecond list. */ -static GArray* -cal_obj_bysecond_expand (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - GList *elem; - gint len, i; - - /* If BYSECOND has not been specified, or the array is empty, just - return the array. */ - if (!recur->bysecond || occs->len == 0) - return occs; - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - - elem = recur->bysecond; - while (elem) { - occ->second = GPOINTER_TO_INT (elem->data); - g_array_append_vals (new_occs, occ, 1); - elem = elem->next; - } - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - -/* If the BYSECOND rule is specified it filters out all occurrences in occs - which do not match one of the seconds in the bysecond list. */ -static GArray* -cal_obj_bysecond_filter (Recurrence *recur, - GArray *occs) -{ - GArray *new_occs; - CalObjTime *occ; - guint8 seconds[61]; - gint sec, len, i; - GList *elem; - - /* If BYSECOND has not been specified, or the array is empty, just - return the array. */ - elem = recur->bysecond; - if (!elem || occs->len == 0) - return occs; - - /* Create an array of seconds from byseconds for fast lookup. */ - memset (&seconds, 0, sizeof (seconds)); - while (elem) { - sec = GPOINTER_TO_INT (elem->data); - seconds[sec] = 1; - elem = elem->next; - } - - new_occs = g_array_new (FALSE, FALSE, sizeof (CalObjTime)); - - len = occs->len; - for (i = 0; i < len; i++) { - occ = &g_array_index (occs, CalObjTime, i); - if (seconds[occ->second]) - g_array_append_vals (new_occs, occ, 1); - } - - g_array_free (occs, TRUE); - - return new_occs; -} - - - -static void -cal_obj_time_add_days (CalObjTime *cotime, - gint days) -{ - guint day, days_in_month; - - /* We use a guint to avoid overflow on the guint8. */ - day = (guint) cotime->day; - day += days; - - for (;;) { - days_in_month = time_days_in_month (cotime->year, - cotime->month); - if (day <= days_in_month) - break; - - cotime->month++; - if (cotime->month >= 12) { - cotime->year++; - cotime->month = 0; - } - - day -= days_in_month; - } - - cotime->day = (guint8) day; -} diff --git a/calendar/cal-util/cal-recur.h b/calendar/cal-util/cal-recur.h deleted file mode 100644 index 340b897417..0000000000 --- a/calendar/cal-util/cal-recur.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Evolution calendar recurrence rule functions - * - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Damon Chaplin <damon@helixcode.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef CAL_RECURL_H -#define CAL_RECUR_H - -#include <libgnome/gnome-defs.h> -#include <glib.h> - -BEGIN_GNOME_DECLS - - -/* FIXME: I've put modified versions of RecurType and Recurrence here, since - the ones in calobj.h don't support all of iCalendar. Hopefully Seth will - update those soon and these can be removed. */ - -enum RecurType { - RECUR_YEARLY, - RECUR_MONTHLY, - RECUR_WEEKLY, - RECUR_DAILY, - RECUR_HOURLY, - RECUR_MINUTELY, - RECUR_SECONDLY, -}; - -typedef struct { - enum RecurType type; - - int interval; - - int weekday; - - int month_pos; - - int month_day; - - - /* For BYMONTH modifier. A list of GINT_TO_POINTERs, 0-11. */ - GList *bymonth; - - - /* For BYHOUR modifier. A list of GINT_TO_POINTERs, 0-23. */ - GList *byhour; - - /* For BYMINUTE modifier. A list of GINT_TO_POINTERs, 0-59. */ - GList *byminute; - - /* For BYSECOND modifier. A list of GINT_TO_POINTERs, 0-60. */ - GList *bysecond; - -} Recurrence; - - - -/* This is what we use to represent a date & time. */ -typedef struct _CalObjTime CalObjTime; -struct _CalObjTime { - guint16 year; - guint8 month; /* 0 - 11 */ - guint8 day; /* 1 - 31 */ - guint8 hour; /* 0 - 23 */ - guint8 minute; /* 0 - 59 */ - guint8 second; /* 0 - 59 (maybe 60 for leap second) */ -}; - - - -/* Returns an unsorted array of time_t's resulting from expanding the - recurrence within the given interval. Each iCalendar event can have any - number of recurrence rules specifying occurrences of the event, as well as - any number of recurrence rules specifying exceptions. */ -GArray* -cal_obj_expand_recurrence (CalObjTime *event_start, - CalObjTime *event_end, - Recurrence *recur, - CalObjTime *interval_start, - CalObjTime *interval_end); - -END_GNOME_DECLS - -#endif diff --git a/calendar/cal-util/cal-util.c b/calendar/cal-util/cal-util.c deleted file mode 100644 index 40c4fe5bfe..0000000000 --- a/calendar/cal-util/cal-util.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Evolution calendar utilities and types - * - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Federico Mena-Quintero <federico@helixcode.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <stdlib.h> -#include "cal-util.h" -#include "libversit/vcc.h" - - - -/** - * cal_obj_instance_list_free: - * @list: List of #CalObjInstance structures. - * - * Frees a list of #CalObjInstance structures. - **/ -void -cal_obj_instance_list_free (GList *list) -{ - CalObjInstance *i; - GList *l; - - for (l = list; l; l = l->next) { - i = l->data; - - g_assert (i != NULL); - g_assert (i->uid != NULL); - - g_free (i->uid); - g_free (i); - } - - g_list_free (list); -} - -/** - * cal_alarm_instance_list_free: - * @list: List of #CalAlarmInstance structures. - * - * Frees a list of #CalAlarmInstance structures. - **/ -void -cal_alarm_instance_list_free (GList *list) -{ - CalAlarmInstance *i; - GList *l; - - for (l = list; l; l = l->next) { - i = l->data; - - g_assert (i != NULL); - g_assert (i->uid != NULL); - - g_free (i->uid); - g_free (i); - } - - g_list_free (list); -} - -/** - * cal_obj_uid_list_free: - * @list: List of strings with unique identifiers. - * - * Frees a list of unique identifiers for calendar objects. - **/ -void -cal_obj_uid_list_free (GList *list) -{ - GList *l; - - for (l = list; l; l = l->next) { - char *uid; - - uid = l->data; - - g_assert (uid != NULL); - g_free (uid); - } - - g_list_free (list); -} diff --git a/calendar/cal-util/cal-util.h b/calendar/cal-util/cal-util.h deleted file mode 100644 index b222ea8cba..0000000000 --- a/calendar/cal-util/cal-util.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Evolution calendar utilities and types - * - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Federico Mena-Quintero <federico@helixcode.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef CAL_UTIL_H -#define CAL_UTIL_H - -#include <libgnome/gnome-defs.h> -#include <time.h> -#include <glib.h> -#include <cal-util/calobj.h> - -BEGIN_GNOME_DECLS - - - -/* Instance of a calendar object. This can be an actual occurrence, a - * recurrence, or an alarm trigger of a `real' calendar object. - */ -typedef struct { - char *uid; /* UID of the object */ - time_t start; /* Start time of instance */ - time_t end; /* End time of instance */ -} CalObjInstance; - -void cal_obj_instance_list_free (GList *list); - -/* Instance of an alarm trigger */ -typedef struct { - char *uid; /* UID of object */ - enum AlarmType type; /* Type of alarm */ - time_t trigger; /* Alarm trigger time */ - time_t occur; /* Occurrence time */ -} CalAlarmInstance; - -void cal_alarm_instance_list_free (GList *list); - -/* Used for multiple UID queries */ -typedef enum { - CALOBJ_TYPE_EVENT = 1 << 0, - CALOBJ_TYPE_TODO = 1 << 1, - CALOBJ_TYPE_JOURNAL = 1 << 2, - CALOBJ_TYPE_OTHER = 1 << 3, - CALOBJ_TYPE_ANY = 0x0f -} CalObjType; - -void cal_obj_uid_list_free (GList *list); - -END_GNOME_DECLS - -#endif diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c deleted file mode 100644 index d2c47fbc65..0000000000 --- a/calendar/cal-util/calobj.c +++ /dev/null @@ -1,1810 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Calendar objects implementations. - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (quartic@gimp.org) - */ -#include <config.h> -#include <string.h> -#include <glib.h> -#include <ctype.h> -#include <unistd.h> -#include "calobj.h" -#include "timeutil.h" -#include "libversit/vcc.h" - - - -/* VCalendar product ID */ -#define PRODID "-//Helix Code//NONSGML Evolution Calendar//EN" - -static gint compare_exdates (gconstpointer a, gconstpointer b); -static void ical_object_normalize_summary (iCalObject *ico); - - - -char * -ical_gen_uid (void) -{ - static char *hostname; - time_t t = time (NULL); - static int serial; - - if (!hostname){ - char buffer [128]; - - if ((gethostname (buffer, sizeof (buffer)-1) == 0) && - (buffer [0] != 0)) - hostname = g_strdup (buffer); - else - hostname = g_strdup ("localhost"); - } - - return g_strdup_printf ( - "%s-%d-%d-%d-%d@%s", - isodate_from_time_t (t), - getpid (), - getgid (), - getppid (), - serial++, - hostname); -} - -iCalObject * -ical_object_new (void) -{ - iCalObject *ico; - - ico = g_new0 (iCalObject, 1); - - ico->seq = -1; - ico->dtstamp = time (NULL); - ico->uid = ical_gen_uid (); - - ico->pilot_id = 0; - ico->pilot_status = ICAL_PILOT_SYNC_MOD; - - ico->ref_count = 1; - - return ico; -} - -iCalObject * -ical_new (char *comment, char *organizer, char *summary) -{ - iCalObject *ico; - - ico = ical_object_new (); - - ico->comment = g_strdup (comment); - ico->organizer = g_new0 (iCalPerson, 1); - ico->organizer->addr = g_strdup (organizer); - ico->summary = g_strdup (summary); - ico->class = g_strdup ("PUBLIC"); - ico->status = g_strdup ("NEEDS ACTION"); - - ico->dalarm.type = ALARM_DISPLAY; - ico->palarm.type = ALARM_PROGRAM; - ico->malarm.type = ALARM_MAIL; - ico->aalarm.type = ALARM_AUDIO; - - ical_object_normalize_summary (ico); - - return ico; -} - - -void -ical_object_ref (iCalObject *ico) -{ - ico->ref_count++; -} - - -void -ical_object_unref (iCalObject *ico) -{ - ico->ref_count--; - if (ico->ref_count == 0) - ical_object_destroy (ico); -} - - -static void -my_free (gpointer data, gpointer user_dat_ignored) -{ - g_free (data); -} - -static void -list_free (GList *list) -{ - g_list_foreach (list, my_free, 0); - g_list_free (list); -} - -#define free_if_defined(x) if (x){ g_free (x); x = 0; } -#define lfree_if_defined(x) if (x){ list_free (x); x = 0; } -void -ical_object_destroy (iCalObject *ico) -{ - /* Regular strings */ - free_if_defined (ico->comment); - free_if_defined (ico->organizer); - free_if_defined (ico->summary); - free_if_defined (ico->uid); - free_if_defined (ico->status); - free_if_defined (ico->class); - free_if_defined (ico->url); - free_if_defined (ico->recur); - - /* Lists */ - lfree_if_defined (ico->exdate); - lfree_if_defined (ico->categories); - lfree_if_defined (ico->resources); - lfree_if_defined (ico->related); - lfree_if_defined (ico->attach); - - /* Alarms */ - g_free (ico->dalarm.data); - g_free (ico->palarm.data); - g_free (ico->malarm.data); - g_free (ico->aalarm.data); - - g_free (ico); -} - -/* This resets any recurrence rules of the iCalObject. */ -void -ical_object_reset_recurrence (iCalObject *ico) -{ - free_if_defined (ico->recur); - lfree_if_defined (ico->exdate); -} - -static GList * -set_list (char *str) -{ - GList *list = 0; - char *s; - - for (s = strtok (str, ";"); s; s = strtok (NULL, ";")) - list = g_list_prepend (list, g_strdup (s)); - - return list; -} - -static GList * -set_date_list (char *str) -{ - GList *list = 0; - char *s; - - for (s = strtok (str, ";,"); s; s = strtok (NULL, ";,")){ - time_t *t = g_new (time_t, 1); - - while (*s && isspace (*s)) - s++; - *t = time_from_isodate (s); - list = g_list_prepend (list, t); - } - return list; -} - -void -ical_object_add_exdate (iCalObject *o, time_t t) -{ - time_t *pt = g_new (time_t, 1); - - *pt = t; - o->exdate = g_list_prepend (o->exdate, pt); -} - -static void -ignore_space(char **str) -{ - while (**str && isspace (**str)) - (*str)++; -} - -static void -skip_numbers (char **str) -{ - while (**str){ - ignore_space (str); - if (!isdigit (**str)) - return; - while (**str && isdigit (**str)) - (*str)++; - } -} - -static void -weekdaylist (iCalObject *o, char **str) -{ - int i; - struct { - char first_letter, second_letter; - int index; - } days [] = { - { 'S', 'U', 0 }, - { 'M', 'O', 1 }, - { 'T', 'U', 2 }, - { 'W', 'E', 3 }, - { 'T', 'H', 4 }, - { 'F', 'R', 5 }, - { 'S', 'A', 6 } - }; - - ignore_space (str); - do { - for (i = 0; i < 7; i++){ - if (**str == days [i].first_letter && *(*str+1) == days [i].second_letter){ - o->recur->weekday |= 1 << i; - *str += 2; - if (**str == ' ') - (*str)++; - } - } - } while (isalpha (**str)); - - if (o->recur->weekday == 0){ - struct tm tm = *localtime (&o->dtstart); - - o->recur->weekday = 1 << tm.tm_wday; - } -} - -static void -weekdaynum (iCalObject *o, char **str) -{ - int i; - struct { - char first_letter, second_letter; - int index; - } days [] = { - { 'S', 'U', 0 }, - { 'M', 'O', 1 }, - { 'T', 'U', 2 }, - { 'W', 'E', 3 }, - { 'T', 'H', 4 }, - { 'F', 'R', 5 }, - { 'S', 'A', 6 } - }; - - ignore_space (str); - do { - for (i = 0; i < 7; i++){ - if (**str == days [i].first_letter && *(*str+1) == days [i].second_letter){ - o->recur->weekday = i; - *str += 2; - if (**str == ' ') - (*str)++; - } - } - } while (isalpha (**str)); -} - -static void -ocurrencelist (iCalObject *o, char **str) -{ - char *p; - - ignore_space (str); - p = *str; - if (!isdigit (*p)) - return; - - if (!(*p >= '1' && *p <= '5')) - return; - - if (!(*(p+1) == '+' || *(p+1) == '-')) - return; - - o->recur->u.month_pos = (*p-'0') * (*(p+1) == '+' ? 1 : -1); - *str += 2; -} - -#if 0 - -static void -daynumber (iCalObject *o, char **str) -{ - int val = 0; - char *p = *str; - - ignore_space (str); - if (strcmp (p, "LD")){ - o->recur->u.month_day = DAY_LASTDAY; - *str += 2; - return; - } - - if (!(isdigit (*p))) - return; - - while (**str && isdigit (**str)){ - val = val * 10 + (**str - '0'); - (*str)++; - } - - if (**str == '+') - (*str)++; - - if (**str == '-') - val *= -1; - o->recur->u.month_day = val; -} - -#endif - -static void -daynumberlist (iCalObject *o, char **str) -{ - int first = 0; - int val = 0; - - ignore_space (str); - - while (**str){ - if (!isdigit (**str)) - return; - while (**str && isdigit (**str)){ - val = 10 * val + (**str - '0'); - (*str)++; - } - if (!first){ - /* - * Some broken applications set this to zero - */ - if (val == 0){ - struct tm day = *localtime (&o->dtstart); - - val = day.tm_mday; - } - o->recur->u.month_day = val; - first = 1; - val = 0; - } - } -} - -static void -load_recur_weekly (iCalObject *o, char **str) -{ - weekdaylist (o, str); -} - -static void -load_recur_monthly_pos (iCalObject *o, char **str) -{ - ocurrencelist (o, str); - weekdaynum (o, str); -} - -static void -load_recur_monthly_day (iCalObject *o, char **str) -{ - daynumberlist (o, str); -} - -static void -load_recur_yearly_month (iCalObject *o, char **str) -{ - /* Skip as we do not support multiple months and we do expect - * the dtstart to agree with the value on this field - */ - skip_numbers (str); -} - -static void -load_recur_yearly_day (iCalObject *o, char **str) -{ - /* Skip as we do not support multiple days and we do expect - * the dtstart to agree with the value on this field - * - * FIXME: we should support every-n-years - */ - skip_numbers (str); -} - -static void -duration (iCalObject *o, char **str) -{ - unsigned int duration = 0; - - ignore_space (str); - if (**str != '#') - return; - (*str)++; - while (**str && isdigit (**str)){ - duration = duration * 10 + (**str - '0'); - (*str)++; - } - o->recur->duration = duration; -} - -static void -enddate (iCalObject *o, char **str) -{ - ignore_space (str); - if (isdigit (**str)){ - o->recur->_enddate = time_from_isodate (*str); - *str += 16; - } -} - -static int -load_recurrence (iCalObject *o, char *str) -{ - enum RecurType type; - int interval = 0; - - type = -1; - switch (*str++){ - case 'D': - type = RECUR_DAILY; - break; - - case 'W': - type = RECUR_WEEKLY; - break; - - case 'M': - if (*str == 'P') - type = RECUR_MONTHLY_BY_POS; - else if (*str == 'D') - type = RECUR_MONTHLY_BY_DAY; - str++; - break; - - case 'Y': - if (*str == 'M') - type = RECUR_YEARLY_BY_MONTH; - else if (*str == 'D') - type = RECUR_YEARLY_BY_DAY; - str++; - break; - } - if (type == -1) - return 0; - - o->recur = g_new0 (Recurrence, 1); - o->recur->type = type; - ignore_space (&str); - - /* Get the interval */ - for (;*str && isdigit (*str);str++) - interval = interval * 10 + (*str-'0'); - - if (interval == 0) - interval = 1; - - o->recur->interval = interval; - - /* this is the default per the spec */ - o->recur->duration = 2; - - ignore_space (&str); - - switch (type){ - case RECUR_DAILY: - break; - case RECUR_WEEKLY: - load_recur_weekly (o, &str); - break; - case RECUR_MONTHLY_BY_POS: - load_recur_monthly_pos (o, &str); - break; - case RECUR_MONTHLY_BY_DAY: - load_recur_monthly_day (o, &str); - break; - case RECUR_YEARLY_BY_MONTH: - load_recur_yearly_month (o, &str); - break; - case RECUR_YEARLY_BY_DAY: - load_recur_yearly_day (o, &str); - break; - default: - g_warning ("Unimplemented recurrence type %d", (int) type); - break; - } - duration (o, &str); - enddate (o, &str); - - /* Compute the enddate */ - if (o->recur->_enddate == 0){ - if (o->recur->duration != 0){ - ical_object_compute_end (o); - } else - o->recur->enddate = 0; - } else { - o->recur->enddate = o->recur->_enddate; - } - return 1; -} - -#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop) -#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj)) -#define has(obj,prop) (vo = isAPropertyOf (obj, prop)) - -/* - * FIXME: This is loosing precission. Enhanec the thresholds - */ -#define HOURS(n) (n*(60*60)) - -static void -setup_alarm_at (iCalObject *ico, CalendarAlarm *alarm, char *iso_time, VObject *vo) -{ - time_t alarm_time = time_from_isodate (iso_time); - time_t base = ico->dtstart; - int d = difftime (base, alarm_time); - VObject *a; - char *the_str; - - alarm->enabled = 1; - if (d > HOURS (2)){ - if (d > HOURS (48)){ - alarm->count = d / HOURS (24); - alarm->units = ALARM_DAYS; - } else { - alarm->count = d / (60*60); - alarm->units = ALARM_HOURS; - } - } else { - alarm->count = d / 60; - alarm->units = ALARM_MINUTES; - } - - if ((a = is_a_prop_of (vo, VCSnoozeTimeProp))){ - alarm->snooze_secs = isodiff_to_secs (str_val (a)); - free (the_str); - } - - if ((a = is_a_prop_of (vo, VCRepeatCountProp))){ - alarm->snooze_repeat = atoi (str_val (a)); - free (the_str); - } -} - -/* - * Duplicates an iCalObject. Implementation is a grand hack. - * If you need the new ICalObject to have a new uid, free the current one, - * and call ical_gen_uid() to generate a new one. - */ -iCalObject * -ical_object_duplicate (iCalObject *o) -{ - VObject *vo; - iCalObject *new; - - vo = ical_object_to_vobject (o); - switch (o->type){ - case ICAL_EVENT: - new = ical_object_create_from_vobject (vo, VCEventProp); - break; - case ICAL_TODO: - new = ical_object_create_from_vobject (vo, VCTodoProp); - break; - default: - new = NULL; - } - - cleanVObject (vo); - return new; -} - -/* FIXME: we need to load the recurrence properties */ -iCalObject * -ical_object_create_from_vobject (VObject *o, const char *object_name) -{ - time_t now = time (NULL); - iCalObject *ical; - VObject *vo, *a; - VObjectIterator i; - char *the_str; - - ical = g_new0 (iCalObject, 1); - - if (strcmp (object_name, VCEventProp) == 0) - ical->type = ICAL_EVENT; - else if (strcmp (object_name, VCTodoProp) == 0) - ical->type = ICAL_TODO; - else { - g_free (ical); - return 0; - } - - ical->ref_count = 1; - - /* uid */ - if (has (o, VCUniqueStringProp)){ - ical->uid = g_strdup (str_val (vo)); - free (the_str); - } else { - ical->uid = ical_gen_uid (); - } - - /* seq */ - if (has (o, VCSequenceProp)){ - ical->seq = atoi (str_val (vo)); - free (the_str); - } else - ical->seq = 0; - - /* dtstart */ - if (has (o, VCDTstartProp)){ - ical->dtstart = time_from_isodate (str_val (vo)); - free (the_str); - } else - ical->dtstart = 0; - - /* dtend */ - ical->dtend = 0; /* default value */ - if (ical->type == ICAL_EVENT){ - if (has (o, VCDTendProp)){ - ical->dtend = time_from_isodate (str_val (vo)); - free (the_str); - } - } else if (ical->type == ICAL_TODO){ - if (has (o, VCDueProp)){ - ical->dtend = time_from_isodate (str_val (vo)); - free (the_str); - } - } - - /* dcreated */ - if (has (o, VCDCreatedProp)){ - ical->created = time_from_isodate (str_val (vo)); - free (the_str); - } - - /* completed */ - if (has (o, VCCompletedProp)){ - ical->completed = time_from_isodate (str_val (vo)); - free (the_str); - } - - /* last_mod */ - if (has (o, VCLastModifiedProp)){ - ical->last_mod = time_from_isodate (str_val (vo)); - free (the_str); - } else - ical->last_mod = now; - - /* exdate */ - if (has (o, VCExpDateProp)){ - ical->exdate = set_date_list (str_val (vo)); - free (the_str); - } - - /* description/comment */ - if (has (o, VCDescriptionProp)){ - ical->comment = g_strdup (str_val (vo)); - free (the_str); - } - - /* summary */ - if (has (o, VCSummaryProp)){ - ical->summary = g_strdup (str_val (vo)); - free (the_str); - - /* Convert any CR/LF/CRLF sequences in the summary field to - spaces so we just have a one-line field. */ - ical_object_normalize_summary (ical); - } else - ical->summary = g_strdup (""); - - /* status */ - if (has (o, VCStatusProp)){ - ical->status = g_strdup (str_val (vo)); - free (the_str); - } else - ical->status = g_strdup ("NEEDS ACTION"); - - if (has (o, VCClassProp)){ - ical->class = g_strdup (str_val (vo)); - free (the_str); - } else - ical->class = g_strdup ("PUBLIC"); - - /* categories */ - if (has (o, VCCategoriesProp)){ - ical->categories = set_list (str_val (vo)); - free (the_str); - } - - /* resources */ - if (has (o, VCResourcesProp)){ - ical->resources = set_list (str_val (vo)); - free (the_str); - } - - /* priority */ - if (has (o, VCPriorityProp)){ - ical->priority = atoi (str_val (vo)); - free (the_str); - } - - /* tranparency */ - if (has (o, VCTranspProp)){ - ical->transp = atoi (str_val (vo)) ? ICAL_TRANSPARENT : ICAL_OPAQUE; - free (the_str); - } - - /* Organizer */ - if (has (o, VCOrgNameProp)){ - ical->organizer = g_new0 (iCalPerson, 1); - ical->organizer->addr = g_strdup (str_val (vo)); - free (the_str); - } - - /* related */ - if (has (o, VCRelatedToProp)){ - char *str; - char *s; - iCalRelation *rel; - str = str_val (vo); - for (s = strtok (str, ";"); s; s = strtok (NULL, ";")) { - rel = g_new0 (iCalRelation, 1); - rel->uid = g_strdup (s); - rel->reltype = g_strdup ("PARENT"); - ical->related = g_list_prepend (ical->related, rel); - } - free (the_str); - } - - /* attach */ - initPropIterator (&i, o); - while (moreIteration (&i)){ - vo = nextVObject (&i); - if (strcmp (vObjectName (vo), VCAttachProp) == 0){ - ical->attach = g_list_prepend (ical->attach, g_strdup (str_val (vo))); - free (the_str); - } - } - - /* url */ - if (has (o, VCURLProp)){ - ical->url = g_strdup (str_val (vo)); - free (the_str); - } - - /* dalarm */ - ical->dalarm.type = ALARM_DISPLAY; - ical->dalarm.enabled = 0; - if (has (o, VCDAlarmProp)){ - if ((a = is_a_prop_of (vo, VCRunTimeProp))){ - setup_alarm_at (ical, &ical->dalarm, str_val (a), vo); - free (the_str); - } - } - - /* aalarm */ - ical->aalarm.type = ALARM_AUDIO; - ical->aalarm.enabled = 0; - if (has (o, VCAAlarmProp)){ - if ((a = is_a_prop_of (vo, VCRunTimeProp))){ - setup_alarm_at (ical, &ical->aalarm, str_val (a), vo); - free (the_str); - } - } - - /* palarm */ - ical->palarm.type = ALARM_PROGRAM; - ical->palarm.enabled = 0; - if (has (o, VCPAlarmProp)){ - ical->palarm.type = ALARM_PROGRAM; - if ((a = is_a_prop_of (vo, VCRunTimeProp))){ - setup_alarm_at (ical, &ical->palarm, str_val (a), vo); - free (the_str); - - if ((a = is_a_prop_of (vo, VCProcedureNameProp))){ - ical->palarm.data = g_strdup (str_val (a)); - free (the_str); - } else - ical->palarm.data = g_strdup (""); - } - } - - /* malarm */ - ical->malarm.type = ALARM_MAIL; - ical->malarm.enabled = 0; - if (has (o, VCMAlarmProp)){ - ical->malarm.type = ALARM_MAIL; - if ((a = is_a_prop_of (vo, VCRunTimeProp))){ - setup_alarm_at (ical, &ical->malarm, str_val (a), vo); - free (the_str); - - if ((a = is_a_prop_of (vo, VCEmailAddressProp))){ - ical->malarm.data = g_strdup (str_val (a)); - free (the_str); - } else - ical->malarm.data = g_strdup (""); - } - } - - /* rrule */ - if (has (o, VCRRuleProp)){ - if (!load_recurrence (ical, str_val (vo))) { - ical_object_destroy (ical); - return NULL; - } - free (the_str); - } - - /* - * Pilot - */ - if (has (o, XPilotIdProp)){ - ical->pilot_id = atoi (str_val (vo)); - free (the_str); - } else - ical->pilot_id = 0; - - if (has (o, XPilotStatusProp)){ - ical->pilot_status = atoi (str_val (vo)); - free (the_str); - } else - ical->pilot_status = ICAL_PILOT_SYNC_MOD; - - return ical; -} - -static char * -to_str (int num) -{ - static char buf [40]; - - sprintf (buf, "%d", num); - return buf; -} - -/* - * stores a GList in the property. - */ -static void -store_list (VObject *o, char *prop, GList *values) -{ - GList *l; - int len; - char *result, *p; - - for (len = 0, l = values; l; l = l->next) - len += strlen (l->data) + 1; - - result = g_malloc (len); - - for (p = result, l = values; l; l = l->next) { - int len = strlen (l->data); - - strcpy (p, l->data); - - if (l->next) { - p [len] = ';'; - p += len+1; - } else - p += len; - } - - *p = 0; - - addPropValue (o, prop, result); - g_free (result); -} - -static void -store_rel_list (VObject *o, char *prop, GList *values) -{ - GList *l; - int len; - char *result, *p; - - for (len = 0, l = values; l; l = l->next) - len += strlen (((iCalRelation*)(l->data))->uid) + 1; - - result = g_malloc (len); - - for (p = result, l = values; l; l = l->next) { - int len = strlen (((iCalRelation*)(l->data))->uid); - - strcpy (p, ((iCalRelation*)(l->data))->uid); - - if (l->next) { - p [len] = ';'; - p += len+1; - } else - p += len; - } - - *p = 0; - - addPropValue (o, prop, result); - g_free (result); -} - -static void -store_date_list (VObject *o, char *prop, GList *values) -{ - GList *l; - int size, len; - char *s, *p; - - size = g_list_length (values); - s = p = g_malloc ((size * 17 + 1) * sizeof (char)); - - for (l = values; l; l = l->next){ - strcpy (s, isodate_from_time_t (*(time_t *)l->data)); - len = strlen (s); - s [len] = ','; - s += len + 1; - } - s--; - *s = 0; - addPropValue (o, prop, p); - g_free (p); -} - -static char *recur_type_name [] = { "D", "W", "MP", "MD", "YM", "YD" }; -static char *recur_day_list [] = { "SU", "MO", "TU","WE", "TH", "FR", "SA" }; -static char *alarm_names [] = { VCMAlarmProp, VCPAlarmProp, VCDAlarmProp, VCAAlarmProp }; - -static VObject * -save_alarm (VObject *o, CalendarAlarm *alarm, iCalObject *ical) -{ - VObject *alarm_object; - struct tm tm; - time_t alarm_time; - - if (!alarm->enabled) - return NULL; - tm = *localtime (&ical->dtstart); - switch (alarm->units){ - case ALARM_MINUTES: - tm.tm_min -= alarm->count; - break; - - case ALARM_HOURS: - tm.tm_hour -= alarm->count; - break; - - case ALARM_DAYS: - tm.tm_mday -= alarm->count; - break; - } - - alarm_time = mktime (&tm); - alarm_object = addProp (o, alarm_names [alarm->type]); - addPropValue (alarm_object, VCRunTimeProp, isodate_from_time_t (alarm_time)); - - if (alarm->snooze_secs) - addPropValue (alarm_object, VCSnoozeTimeProp, isodiff_from_secs (alarm->snooze_secs)); - else - addPropValue (alarm_object, VCSnoozeTimeProp, ""); - - if (alarm->snooze_repeat){ - char buf [20]; - - sprintf (buf, "%d", alarm->snooze_repeat); - addPropValue (alarm_object, VCRepeatCountProp, buf); - } else - addPropValue (alarm_object, VCRepeatCountProp, ""); - return alarm_object; -} - -VObject * -ical_object_to_vobject (iCalObject *ical) -{ - VObject *o, *alarm, *s; - GList *l; - - if (ical->type == ICAL_EVENT) - o = newVObject (VCEventProp); - else - o = newVObject (VCTodoProp); - - /* uid */ - if (ical->uid) - addPropValue (o, VCUniqueStringProp, ical->uid); - - /* seq */ - addPropValue (o, VCSequenceProp, to_str (ical->seq)); - - /* dtstart */ - addPropValue (o, VCDTstartProp, isodate_from_time_t (ical->dtstart)); - - /* dtend */ - if (ical->type == ICAL_EVENT){ - addPropValue (o, VCDTendProp, isodate_from_time_t (ical->dtend)); - } else if (ical->type == ICAL_TODO){ - addPropValue (o, VCDueProp, isodate_from_time_t (ical->dtend)); - } - - /* dcreated */ - addPropValue (o, VCDCreatedProp, isodate_from_time_t (ical->created)); - - /* completed */ - if (ical->completed) - addPropValue (o, VCDTendProp, isodate_from_time_t (ical->completed)); - - /* last_mod */ - addPropValue (o, VCLastModifiedProp, isodate_from_time_t (ical->last_mod)); - - /* exdate */ - if (ical->exdate) - store_date_list (o, VCExpDateProp, ical->exdate); - - /* description/comment */ - if (ical->comment && strlen (ical->comment)){ - s = addPropValue (o, VCDescriptionProp, ical->comment); - if (strchr (ical->comment, '\n')) - addProp (s, VCQuotedPrintableProp); - } - - /* summary */ - if (strlen (ical->summary)){ - s = addPropValue (o, VCSummaryProp, ical->summary); - if (strchr (ical->summary, '\n')) - addProp (s, VCQuotedPrintableProp); - } - - /* status */ - addPropValue (o, VCStatusProp, ical->status); - - /* class */ - addPropValue (o, VCClassProp, ical->class); - - /* categories */ - if (ical->categories) - store_list (o, VCCategoriesProp, ical->categories); - - /* resources */ - if (ical->resources) - store_list (o, VCCategoriesProp, ical->resources); - - /* priority */ - addPropValue (o, VCPriorityProp, to_str (ical->priority)); - - /* transparency */ - addPropValue (o, VCTranspProp, to_str (ical->transp)); - - /* Owner/organizer */ - if (ical->organizer && ical->organizer->addr) - addPropValue (o, VCOrgNameProp, ical->organizer->addr); - - /* related */ - if (ical->related) - store_rel_list (o, VCRelatedToProp, ical->related); - - /* attach */ - for (l = ical->attach; l; l = l->next) - addPropValue (o, VCAttachProp, l->data); - - /* url */ - if (ical->url) - addPropValue (o, VCURLProp, ical->url); - - if (ical->recur){ - char result [256]; - char buffer [80]; - int i; - - sprintf (result, "%s%d ", recur_type_name [ical->recur->type], ical->recur->interval); - switch (ical->recur->type){ - case RECUR_DAILY: - break; - - case RECUR_WEEKLY: - for (i = 0; i < 7; i++){ - if (ical->recur->weekday & (1 << i)){ - sprintf (buffer, "%s ", recur_day_list [i]); - strcat (result, buffer); - } - } - break; - - case RECUR_MONTHLY_BY_POS: { - int nega = ical->recur->u.month_pos < 0; - - sprintf (buffer, "%d%s ", nega ? -ical->recur->u.month_pos : ical->recur->u.month_pos, - nega ? "-" : "+"); - strcat (result, buffer); - /* the gui is set up for a single day, not a set here in this case */ - sprintf (buffer, "%s ", recur_day_list [ical->recur->weekday]); - strcat (result, buffer); - } - break; - - case RECUR_MONTHLY_BY_DAY: - sprintf (buffer, "%d ", ical->recur->u.month_pos); - strcat (result, buffer); - break; - - case RECUR_YEARLY_BY_MONTH: - break; - - case RECUR_YEARLY_BY_DAY: - break; - } - if (ical->recur->_enddate == 0) - sprintf (buffer, "#%d ",ical->recur->duration); - else - sprintf (buffer, "%s ", isodate_from_time_t (ical->recur->_enddate)); - strcat (result, buffer); - addPropValue (o, VCRRuleProp, result); - } - - save_alarm (o, &ical->aalarm, ical); - save_alarm (o, &ical->dalarm, ical); - - if ((alarm = save_alarm (o, &ical->palarm, ical))) - addPropValue (alarm, VCProcedureNameProp, ical->palarm.data); - if ((alarm = save_alarm (o, &ical->malarm, ical))) - addPropValue (alarm, VCEmailAddressProp, ical->malarm.data); - - /* Pilot */ - { - char buffer [20]; - - sprintf (buffer, "%d", ical->pilot_id); - addPropValue (o, XPilotIdProp, buffer); - sprintf (buffer, "%d", ical->pilot_status); - addPropValue (o, XPilotStatusProp, buffer); - } - - return o; -} - -void -ical_foreach (GList *events, calendarfn fn, void *closure) -{ - for (; events; events = events->next){ - iCalObject *ical = events->data; - - (*fn) (ical, ical->dtstart, ical->dtend, closure); - } -} - -static int -is_date_in_list (GList *list, struct tm *date) -{ - struct tm tm; - - for (; list; list = list->next){ - time_t *timep = list->data; - - tm = *localtime (timep); - if (date->tm_mday == tm.tm_mday && - date->tm_mon == tm.tm_mon && - date->tm_year == tm.tm_year){ - return 1; - } - } - return 0; -} - -/* Generates an event instance based on the reference time */ -static gboolean -generate (iCalObject *ico, time_t reference, calendarfn cb, void *closure) -{ - time_t offset; - struct tm tm_start, ref; - time_t start, end; - - offset = ico->dtend - ico->dtstart; - - tm_start = *localtime (&ico->dtstart); - ref = *localtime (&reference); - - tm_start.tm_mday = ref.tm_mday; - tm_start.tm_mon = ref.tm_mon; - tm_start.tm_year = ref.tm_year; - - start = mktime (&tm_start); - if (start == -1) { - g_message ("generate(): Produced invalid start date!"); - return FALSE; - } - - end = start + offset; - -#if 0 - /* FIXME: I think this is not needed, since we are offsetting by full day values, - * and the times should remain the same --- if you have a daily appointment - * at 18:00, it is always at 18:00 even during daylight savings. - * - * However, what should happen on the exact change-of-savings day with - * appointments in the early morning hours? - */ - - if (ref.tm_isdst > tm_start.tm_isdst) { - tm_start.tm_hour--; - tm_end.tm_hour--; - } else if (ref.tm_isdst < tm_start.tm_isdst) { - tm_start.tm_hour++; - tm_end.tm_hour++; - } -#endif - - if (ico->exdate && is_date_in_list (ico->exdate, &tm_start)) - return TRUE; - - return (*cb) (ico, start, end, closure); -} - -int -ical_object_get_first_weekday (int weekday_mask) -{ - int i; - - for (i = 0; i < 7; i++) - if (weekday_mask & (1 << i)) - return i; - - return -1; -} - -#define time_in_range(t, a, b) ((t >= a) && (b ? (t < b) : 1)) -#define recur_in_range(t, r) (r->enddate ? (t < r->enddate) : 1) - -/* - * Generate every possible event. Invokes the callback routine for - * every occurrence of the event in the [START, END] time interval. - * - * If END is zero, the event is generated forever. - * The callback routine is expected to return 0 when no further event - * generation is requested. - */ -void -ical_object_generate_events (iCalObject *ico, time_t start, time_t end, calendarfn cb, void *closure) -{ - time_t current; - int first_week_day; - - /* If there is no recurrence, just check ranges */ - - if (!ico->recur) { - if ((end && (ico->dtstart < end) && (ico->dtend > start)) - || ((end == 0) && (ico->dtend > start))) { - /* The new calendar views expect the times to not be - clipped, so they can show that it continues past - the end of the viewable area. */ -#if 0 - time_t ev_s, ev_e; - - /* Clip range */ - - ev_s = MAX (ico->dtstart, start); - ev_e = MIN (ico->dtend, end); - - (* cb) (ico, ev_s, ev_e, closure); -#else - (* cb) (ico, ico->dtstart, ico->dtend, closure); -#endif - } - return; - } - - /* The event has a recurrence rule -- check that we will generate at least one instance */ - - if (end != 0) { - if (ico->dtstart > end) - return; - - if (!IS_INFINITE (ico->recur) && (ico->recur->enddate < start)) - return; - } - - /* Generate the instances */ - - current = ico->dtstart; - - switch (ico->recur->type) { - case RECUR_DAILY: - do { - if (time_in_range (current, start, end) && recur_in_range (current, ico->recur)) - if (!generate (ico, current, cb, closure)) - return; - - /* Advance */ - - current = time_add_day (current, ico->recur->interval); - - if (current == -1) { - g_warning ("RECUR_DAILY: time_add_day() returned invalid time"); - return; - } - } while ((current < end) || (end == 0)); - - break; - - case RECUR_WEEKLY: - do { - struct tm tm; - - tm = *localtime (¤t); - - if (time_in_range (current, start, end) && recur_in_range (current, ico->recur)) { - /* Weekdays to recur on are specified as a bitmask */ - if (ico->recur->weekday & (1 << tm.tm_wday)) { - if (!generate (ico, current, cb, closure)) - return; - } - } - - /* Advance by day for scanning the week or by interval at week end */ - - if (tm.tm_wday == 6) - current = time_add_day (current, (ico->recur->interval - 1) * 7 + 1); - else - current = time_add_day (current, 1); - - if (current == -1) { - g_warning ("RECUR_WEEKLY: time_add_day() returned invalid time\n"); - return; - } - } while (current < end || (end == 0)); - - break; - - case RECUR_MONTHLY_BY_POS: - /* FIXME: We only deal with positives now */ - if (ico->recur->u.month_pos < 0) { - g_warning ("RECUR_MONTHLY_BY_POS does not support negative positions yet"); - return; - } - - if (ico->recur->u.month_pos == 0) - return; - - first_week_day = /* ical_object_get_first_weekday (ico->recur->weekday); */ - ico->recur->weekday; /* the i/f only lets you choose a single day of the week! */ - - /* This should not happen, but take it into account */ - if (first_week_day == -1) { - g_warning ("ical_object_get_first_weekday() returned -1"); - return; - } - - do { - struct tm tm; - time_t t; - int week_day_start; - - tm = *localtime (¤t); - tm.tm_mday = 1; - t = mktime (&tm); - tm = *localtime (&t); - week_day_start = tm.tm_wday; - - tm.tm_mday = (7 * (ico->recur->u.month_pos - ((week_day_start <= first_week_day ) ? 1 : 0)) - - (week_day_start - first_week_day) + 1); - if( tm.tm_mday > 31 ) - { - tm.tm_mday = 1; - tm.tm_mon += ico->recur->interval; - current = mktime (&tm); - continue; - } - - switch( tm.tm_mon ) - { - case 3: - case 5: - case 8: - case 10: - if( tm.tm_mday > 30 ) - { - tm.tm_mday = 1; - tm.tm_mon += ico->recur->interval; - current = mktime (&tm); - continue; - } - break; - case 1: - if( ((tm.tm_year+1900)%4) == 0 - && ((tm.tm_year+1900)%400) != 100 - && ((tm.tm_year+1900)%400) != 200 - && ((tm.tm_year+1900)%400) != 300 ) - { - - if( tm.tm_mday > 29 ) - { - tm.tm_mday = 1; - tm.tm_mon += ico->recur->interval; - current = mktime (&tm); - continue; - } - } - else - { - if( tm.tm_mday > 28 ) - { - tm.tm_mday = 1; - tm.tm_mon += ico->recur->interval; - current = mktime (&tm); - continue; - } - } - break; - } - - t = mktime (&tm); - - if (time_in_range (t, start, end) && recur_in_range (current, ico->recur)) - if (!generate (ico, t, cb, closure)) - return; - - /* Advance by the appropriate number of months */ - - current = mktime (&tm); - - tm.tm_mday = 1; - tm.tm_mon += ico->recur->interval; - current = mktime (&tm); - - if (current == -1) { - g_warning ("RECUR_MONTHLY_BY_DAY: mktime error\n"); - return; - } - } while ((current < end) || (end == 0)); - - break; - - case RECUR_MONTHLY_BY_DAY: - do { - struct tm tm; - time_t t; - int p; - - tm = *localtime (¤t); - - p = tm.tm_mday; - tm.tm_mday = ico->recur->u.month_day; - t = mktime (&tm); - if (time_in_range (t, start, end) && recur_in_range (current, ico->recur)) - if (!generate (ico, t, cb, closure)) - return; - - /* Advance by the appropriate number of months */ - - tm.tm_mday = p; - tm.tm_mon += ico->recur->interval; - current = mktime (&tm); - - if (current == -1) { - g_warning ("RECUR_MONTHLY_BY_DAY: mktime error\n"); - return; - } - } while (current < end || (end == 0)); - - break; - - case RECUR_YEARLY_BY_MONTH: - case RECUR_YEARLY_BY_DAY: - do { - if (time_in_range (current, start, end) && recur_in_range (current, ico->recur)) - if (!generate (ico, current, cb, closure)) - return; - - /* Advance */ - - current = time_add_year (current, ico->recur->interval); - } while (current < end || (end == 0)); - - break; - - default: - g_assert_not_reached (); - } -} - -static int -duration_callback (iCalObject *ico, time_t start, time_t end, void *closure) -{ - int *count = closure; - struct tm tm; - - tm = *localtime (&start); - - (*count)++; - if (ico->recur->duration == *count) { - ico->recur->enddate = time_day_end (end); - return 0; - } - return 1; -} - -/* Computes ico->recur->enddate from ico->recur->duration */ -void -ical_object_compute_end (iCalObject *ico) -{ - int count = 0; - - g_return_if_fail (ico->recur != NULL); - - ico->recur->_enddate = 0; - ico->recur->enddate = 0; - ical_object_generate_events (ico, ico->dtstart, 0, duration_callback, &count); -} - -int -alarm_compute_offset (CalendarAlarm *a) -{ - if (!a->enabled) - return -1; - switch (a->units){ - case ALARM_MINUTES: - a->offset = a->count * 60; - break; - case ALARM_HOURS: - a->offset = a->count * 3600; - break; - case ALARM_DAYS: - a->offset = a->count * 24 * 3600; - } - return a->offset; -} - -/** - * ical_object_find_in_string: - * @uid: Unique identifier of the sought object. - * @vcalobj: String representation of a complete calendar object. - * @ico: The resulting #iCalObject is stored here. - * - * Parses a complete vCalendar object string and tries to find the calendar - * object that matches the specified @uid. If found, it stores the resulting - * #iCalObject in the @ico parameter. - * - * Return value: A result code depending on whether the parse and search were - * successful. - **/ -CalObjFindStatus -ical_object_find_in_string (const char *uid, const char *vcalobj, iCalObject **ico) -{ - VObject *vcal; - VObjectIterator i; - CalObjFindStatus status; - - g_return_val_if_fail (uid != NULL, CAL_OBJ_FIND_SYNTAX_ERROR); - g_return_val_if_fail (vcalobj != NULL, CAL_OBJ_FIND_SYNTAX_ERROR); - g_return_val_if_fail (ico != NULL, CAL_OBJ_FIND_SYNTAX_ERROR); - - *ico = NULL; - status = CAL_OBJ_FIND_NOT_FOUND; - - vcal = Parse_MIME (vcalobj, strlen (vcalobj)); - - if (!vcal) - return CAL_OBJ_FIND_SYNTAX_ERROR; - - initPropIterator (&i, vcal); - - while (moreIteration (&i)) { - VObject *vobj; - VObject *uid_prop; - char *the_str; - - vobj = nextVObject (&i); - - uid_prop = isAPropertyOf (vobj, VCUniqueStringProp); - if (!uid_prop) - continue; - - /* str_val() sets the_str to the string representation of the - * property. - */ - str_val (uid_prop); - - if (strcmp (the_str, uid) == 0) { - const char *object_name; - - object_name = vObjectName (vobj); - *ico = ical_object_create_from_vobject (vobj, object_name); - - if (*ico) - status = CAL_OBJ_FIND_SUCCESS; - } - - free (the_str); - - if (status == CAL_OBJ_FIND_SUCCESS) - break; - } - - cleanVObject (vcal); - cleanStrTbl (); - - return status; -} - -/* Creates a VObject with the base information of a calendar */ -static VObject * -get_calendar_base_vobject (void) -{ - VObject *vobj; - time_t now; - struct tm tm; - - /* We call localtime for the side effect of setting tzname */ - - now = time (NULL); - tm = *localtime (&now); - - vobj = newVObject (VCCalProp); - - addPropValue (vobj, VCProdIdProp, PRODID); - -#if defined (HAVE_TM_ZONE) - addPropValue (vobj, VCTimeZoneProp, tm.tm_zone); -#elif defined (HAVE_TZNAME) - addPropValue (vobj, VCTimeZoneProp, tzname[0]); -#endif - - /* Per the vCalendar spec, this must be "1.0" */ - addPropValue (vobj, VCVersionProp, "1.0"); - - return vobj; -} - -/** - * ical_object_to_string: - * @ico: A calendar object. - * - * Converts a vCalendar object to its string representation. It is wrapped - * inside a complete VCALENDAR object because other auxiliary information such - * as timezones may appear there. - * - * Return value: String representation of the object. - **/ -char * -ical_object_to_string (iCalObject *ico) -{ - VObject *vcalobj, *vobj; - char *buf, *gbuf; - - vcalobj = get_calendar_base_vobject (); - vobj = ical_object_to_vobject (ico); - addVObjectProp (vcalobj, vobj); - - buf = writeMemVObject (NULL, NULL, vcalobj); - - cleanVObject (vcalobj); - cleanStrTbl (); - - /* We have to g_strdup() it because libversit uses malloc()/realloc(), - * and we want clients to be able to use g_free(). Sigh. - */ - gbuf = g_strdup (buf); - free (buf); - - return gbuf; -} - - -/** - * ical_object_compare_dates: - * @ico1: A calendar event. - * @ico2: A calendar event to compare with @ico1. - * - * Returns TRUE if the dates of both objects match, including any recurrence - * rules. Both calendar objects must have a type of ICAL_EVENT. - * - * Return value: TRUE if both calendar objects have the same dates. - **/ -gboolean -ical_object_compare_dates (iCalObject *ico1, - iCalObject *ico2) -{ - Recurrence *recur1, *recur2; - gint num_exdates; - GList *elem1, *elem2; - time_t *time1, *time2; - - g_return_val_if_fail (ico1 != NULL, FALSE); - g_return_val_if_fail (ico2 != NULL, FALSE); - g_return_val_if_fail (ico1->type == ICAL_EVENT, FALSE); - g_return_val_if_fail (ico2->type == ICAL_EVENT, FALSE); - - /* First check the base dates. */ - if (ico1->dtstart != ico2->dtstart - || ico1->dtend != ico2->dtend) - return FALSE; - - recur1 = ico1->recur; - recur2 = ico2->recur; - - /* If the event doesn't recur, we already know it matches. */ - if (!recur1 && !recur2) - return TRUE; - - /* Check that both recur. */ - if (!(recur1 && recur2)) - return FALSE; - - /* Now we need to see if the recurrence rules are the same. */ - if (recur1->type != recur2->type - || recur1->interval != recur2->interval - || recur1->enddate != recur2->enddate - || recur1->weekday != recur2->weekday - || recur1->duration != recur2->duration - || recur1->_enddate != recur2->_enddate - || recur1->__count != recur2->__count) - return FALSE; - - switch (recur1->type) { - case RECUR_MONTHLY_BY_POS: - if (recur1->u.month_pos != recur2->u.month_pos) - return FALSE; - break; - case RECUR_MONTHLY_BY_DAY: - if (recur1->u.month_day != recur2->u.month_day) - return FALSE; - break; - default: - break; - } - - /* Now check if the excluded dates match. */ - num_exdates = g_list_length (ico1->exdate); - if (g_list_length (ico2->exdate) != num_exdates) - return FALSE; - if (num_exdates == 0) - return TRUE; - - ico1->exdate = g_list_sort (ico1->exdate, compare_exdates); - ico2->exdate = g_list_sort (ico2->exdate, compare_exdates); - - elem1 = ico1->exdate; - elem2 = ico2->exdate; - while (elem1) { - time1 = (time_t*) elem1->data; - time2 = (time_t*) elem2->data; - - if (*time1 != *time2) - return FALSE; - - elem1 = elem1->next; - elem2 = elem2->next; - } - - return TRUE; -} - - -static gint -compare_exdates (gconstpointer a, gconstpointer b) -{ - const time_t *ca = a, *cb = b; - time_t diff = *ca - *cb; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - - -/* Converts any CR/LF sequences in the summary field to spaces so we just - have a one-line field. The iCalObjects summary field is changed. */ -static void -ical_object_normalize_summary (iCalObject *ico) -{ - gchar *src, *dest, ch; - gboolean just_output_space = FALSE; - - src = dest = ico->summary; - while ((ch = *src++)) { - if (ch == '\n' || ch == '\r') { - /* We only output 1 space for each sequence of CR & LF - characters. */ - if (!just_output_space) { - *dest++ = ' '; - just_output_space = TRUE; - } - } else { - *dest++ = ch; - just_output_space = FALSE; - } - } - *dest = '\0'; -} diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h deleted file mode 100644 index cf5483a228..0000000000 --- a/calendar/cal-util/calobj.h +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Internal representation of a Calendar object. This is modeled after the - * iCalendar/vCalendar specificiation - * - * Authors: Miguel de Icaza (miguel@gnu.org) - * Federico Mena (quartic@gimp.org). - */ -#ifndef CALOBJ_H -#define CALOBJ_H - -#include <libgnome/libgnome.h> -#include "libversit/vcc.h" - -BEGIN_GNOME_DECLS - -enum AlarmType { - ALARM_MAIL, - ALARM_PROGRAM, - ALARM_DISPLAY, - ALARM_AUDIO -}; - -enum AlarmUnit { - ALARM_MINUTES, - ALARM_HOURS, - ALARM_DAYS -}; - -typedef struct { - enum AlarmType type; - int enabled; - int count; - enum AlarmUnit units; - char *data; /* not used for iCalendar alarms */ - - /* the following pointers are used for iCalendar alarms */ - - char *attach; /* AUDIO, EMAIL, PROC */ - char *desc; /* DISPLAY, EMAIL, PROC */ - char *summary; /* EMAIL */ - char *attendee; /* EMAIL */ - - /* Does not get saved, internally used */ - time_t offset; - time_t trigger; - - int snooze_secs; - int snooze_repeat; - - /* Widgets */ - void *w_count; /* A GtkEntry */ - void *w_enabled; /* A GtkChecButton */ - void *w_timesel; /* A GtkMenu */ - void *w_entry; /* A GnomeEntryFile/GtkEntry for PROGRAM/MAIL */ - void *w_label; -} CalendarAlarm; - -/* Calendar object type */ -typedef enum { - ICAL_EVENT, - ICAL_TODO, - ICAL_JOURNAL, - ICAL_FBREQUEST, - ICAL_FBREPLY, - ICAL_BUSYTIME, - ICAL_TIMEZONE -} iCalType; - -/* For keys that might contain binary or text/binary */ -typedef struct { - char *data; - int len; -} iCalValue; - -typedef enum { - ICAL_PILOT_SYNC_NONE = 0, - ICAL_PILOT_SYNC_MOD = 1, - ICAL_PILOT_SYNC_DEL = 3 -} iCalPilotState; - -typedef struct { - int valid; /* true if the Geography was specified */ - double latitude; - double longitude; -} iCalGeo; - -typedef enum { - ICAL_OPAQUE, - ICAL_TRANSPARENT -} iCalTransp; - -typedef struct { - char *uid; - char *reltype; -} iCalRelation; - -typedef char NotYet; - -enum RecurType { - RECUR_DAILY, - RECUR_WEEKLY, - RECUR_MONTHLY_BY_POS, - RECUR_MONTHLY_BY_DAY, - RECUR_YEARLY_BY_MONTH, - RECUR_YEARLY_BY_DAY, -}; - -#define DAY_LASTDAY 10000 - -typedef struct { - enum RecurType type; - - int interval; - - /* Used for recur computation */ - time_t enddate; /* If the value is zero, it is an infinite event - * otherwise, it is either the _enddate value (if - * this is what got specified) or it is our computed - * ending date (computed from the duration item). - */ - - int weekday; - - union { - int month_pos; - int month_day; - } u; - - int duration; - time_t _enddate; /* As found on the vCalendar file */ - int __count; -} Recurrence; - -/* - NOTE: iCalPerson is used for various property values which specify - people (e.g. ATTENDEE, ORGANIZER, etc. Not all fields are valid - under RFC 2445 for all property values, but iCalPerson can store - them anyway. Enforcing the RFC is a job for the parser. -*/ - -typedef struct { - char *addr; - char *name; - char *role; - char *partstat; - gboolean rsvp; - char *cutype; /* calendar user type */ - GList *member; /* group memberships */ - GList *deleg_to; - GList *deleg_from; - char *sent_by; - char *directory; - GList *altrep; /* list of char* URI's */ -} iCalPerson; - -#define IS_INFINITE(r) (r->duration == 0) - -/* Flags to indicate what has changed in an object */ -typedef enum { - CHANGE_NEW = 1 << 0, /* new object */ - CHANGE_SUMMARY = 1 << 1, /* summary */ - CHANGE_DATES = 1 << 2, /* dtstart / dtend */ - CHANGE_ALL = CHANGE_SUMMARY | CHANGE_DATES -} CalObjectChange; - -/* - * This describes an iCalendar object, note that we never store durations, instead we - * always compute the end time computed from the start + duration. - */ -typedef struct { - iCalType type; - - GList *attach; /* type: one or more URIs or binary data */ - GList *attendee; /* type: CAL-ADDRESS (list of iCalPerson) */ - GList *categories; /* type: one or more TEXT */ - char *class; - - char *comment; /* we collapse one or more TEXTs into one */ - time_t completed; - time_t created; - GList *contact; /* type: one or more TEXT */ - char *desc; - time_t dtstamp; - time_t dtstart; - time_t dtend; /* also duedate for todo's */ - gboolean date_only; /* set if the start/end times were - specified using dates, not times (internal use, not stored to disk) */ - GList *exdate; /* type: one or more time_t's */ - GList *exrule; /* type: one or more RECUR */ - iCalGeo geo; - time_t last_mod; - char *location; - iCalPerson *organizer; - int percent; - int priority; - char *rstatus; /* request status for freebusy */ - GList *related; /* type: one or more TEXT */ - GList *resources; /* type: one or more TEXT */ - GList *rdate; /* type: one or more recurrence date */ - GList *rrule; /* type: one or more recurrence rules */ - int seq; - char *status; - char *summary; - iCalTransp transp; - char *uid; - char *url; - time_t recurid; - - CalendarAlarm dalarm; - CalendarAlarm aalarm; - CalendarAlarm palarm; - CalendarAlarm malarm; - - GList *alarms; - - Recurrence *recur; - - int new; - void *user_data; /* Generic data pointer */ - - /* Pilot */ - iCalPilotState pilot_status; /* Status information */ - guint32 pilot_id; /* Pilot ID */ - - guint ref_count; -} iCalObject; - -/* The callback for the recurrence generator */ -typedef int (*calendarfn) (iCalObject *, time_t, time_t, void *); - -iCalObject *ical_new (char *comment, char *organizer, char *summary); -iCalObject *ical_object_new (void); - -/* iCalObjects are created with a refcount of 1. When it drops to 0 it is - destroyed with ical_object_destroy(). To maintain backwards compatability - ical_object_destroy() can still be used, though code which uses it should - not be mixed with code that uses refcounts. */ -void ical_object_ref (iCalObject *ico); -void ical_object_unref (iCalObject *ico); - -void ical_object_destroy (iCalObject *ico); - -iCalObject *ical_object_create_from_vobject (VObject *obj, const char *object_name); -VObject *ical_object_to_vobject (iCalObject *ical); -iCalObject *ical_object_duplicate (iCalObject *o); -void ical_foreach (GList *events, calendarfn fn, void *closure); -void ical_object_generate_events (iCalObject *ico, time_t start, time_t end, calendarfn cb, void *closure); -void ical_object_add_exdate (iCalObject *o, time_t t); - -/* Computes the enddate field of the recurrence based on the duration */ -void ical_object_compute_end (iCalObject *ico); - -typedef enum { - CAL_OBJ_FIND_SUCCESS, - CAL_OBJ_FIND_SYNTAX_ERROR, - CAL_OBJ_FIND_NOT_FOUND -} CalObjFindStatus; - -CalObjFindStatus ical_object_find_in_string (const char *uid, const char *vcalobj, iCalObject **ico); - -char *ical_object_to_string (iCalObject *ico); - - -/* Returns the first toggled day in a weekday mask -- we do this because we do not support multiple - * days on a monthly-by-pos recurrence. If no days are toggled, it returns -1. - */ -int ical_object_get_first_weekday (int weekday_mask); - -/* Returns the number of seconds configured to trigger the alarm in advance to an event */ -int alarm_compute_offset (CalendarAlarm *a); - - -/* Returns TRUE if the dates of both objects match, including any recurrence - rules. */ -gboolean ical_object_compare_dates (iCalObject *ico1, iCalObject *ico2); - -/* Generates a new uid for a calendar object. Should be g_free'd eventually. */ -char *ical_gen_uid (void); - -/* This resets any recurrence rules of the iCalObject. */ -void ical_object_reset_recurrence (iCalObject *ico); - - -END_GNOME_DECLS - -#endif - diff --git a/calendar/cal-util/icalendar-save.c b/calendar/cal-util/icalendar-save.c deleted file mode 100644 index 8fae9a02f5..0000000000 --- a/calendar/cal-util/icalendar-save.c +++ /dev/null @@ -1,509 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#include <config.h> -#include <unistd.h> -#include <sys/stat.h> -#include "icalendar-save.h" - - -static void unparse_person (iCalPerson *person, icalproperty *person_prop); -static struct icaltimetype timet_to_icaltime (time_t tt); -static icalproperty *unparse_related (iCalRelation *rel); -static icalcomponent *unparse_alarm (CalendarAlarm *alarm); - - -icalcomponent* -icalcomponent_create_from_ical_object (iCalObject *ical) -{ - icalcomponent_kind kind; - icalcomponent *comp; - icalproperty *prop; - - switch (ical->type) { - case ICAL_EVENT: kind = ICAL_VEVENT_COMPONENT; break; - case ICAL_TODO: kind = ICAL_VTODO_COMPONENT; break; - case ICAL_JOURNAL: kind = ICAL_VJOURNAL_COMPONENT; break; - case ICAL_FBREQUEST: kind = ICAL_VFREEBUSY_COMPONENT; break; - case ICAL_TIMEZONE: kind = ICAL_VTIMEZONE_COMPONENT; break; - default: - kind = ICAL_NO_COMPONENT; break; - } - - comp = icalcomponent_new (kind); - - /*** calscale ***/ - prop = icalproperty_new_calscale ("GREGORIAN"); - icalcomponent_add_property (comp, prop); - - /*** catagories ***/ - if (ical->categories) { - /* ical->categories is a GList of (char *) */ - GList *cur; - for (cur = ical->categories; cur; cur = cur->next) { - prop = icalproperty_new_categories ((char *) cur); - icalcomponent_add_property (comp, prop); - } - } - - /*** class ***/ - if (ical->class) { - prop = icalproperty_new_class (ical->class); - icalcomponent_add_property (comp, prop); - } - - /*** comment ***/ - if (ical->comment) { - prop = icalproperty_new_comment (ical->comment); - icalcomponent_add_property (comp, prop); - } - - /*** description ***/ - if (ical->desc) { - prop = icalproperty_new_description (ical->desc); - icalcomponent_add_property (comp, prop); - } - - /*** geo ***/ - if (ical->geo.valid) { - struct icalgeotype v; - v.lat = ical->geo.latitude; - v.lon = ical->geo.longitude; - prop = icalproperty_new_geo (v); - icalcomponent_add_property (comp, prop); - } - - /*** location ***/ - if (ical->location) { - prop = icalproperty_new_location (ical->location); - icalcomponent_add_property (comp, prop); - } - - /*** percentcomplete ***/ - prop = icalproperty_new_percentcomplete (ical->percent); - icalcomponent_add_property (comp, prop); - - /*** priority ***/ - if (ical->priority) { - prop = icalproperty_new_priority (ical->priority); - icalcomponent_add_property (comp, prop); - } - - /*** resources ***/ - if (ical->resources) { - /* ical->resources is a GList of (char *) */ - GList *cur; - for (cur = ical->resources; cur; cur = cur->next) { - prop = icalproperty_new_resources ((char *) cur); - icalcomponent_add_property (comp, prop); - } - } - - /*** status ***/ - if (ical->status) { - prop = icalproperty_new_status (ical->status); - icalcomponent_add_property (comp, prop); - } - - /*** summary ***/ - if (ical->summary) { - prop = icalproperty_new_summary (ical->summary); - icalcomponent_add_property (comp, prop); - } - - /*** completed ***/ - if (ical->completed) { - struct icaltimetype ictime; - ictime = timet_to_icaltime (ical->completed); - prop = icalproperty_new_completed (ictime); - icalcomponent_add_property (comp, prop); - } - - /*** dtend ***/ /*** due ***/ - if (ical->dtend) { - /* FIXME: We should handle timezone specifiers */ - struct icaltimetype ictime; - ictime = timet_to_icaltime (ical->dtend); - if (ical->type == ICAL_TODO) - prop = icalproperty_new_due (ictime); - else - prop = icalproperty_new_dtend (ictime); - if (ical->date_only) { - icalparameter *param; - param = icalparameter_new (ICAL_VALUE_PARAMETER); - icalparameter_set_value (param, ICAL_VALUE_DATE); - icalproperty_add_parameter (prop, param); - } - icalcomponent_add_property (comp, prop); - } - - /*** dtstart ***/ - if (ical->dtstart) { - /* FIXME: We should handle timezone specifiers */ - struct icaltimetype ictime; - ictime = timet_to_icaltime (ical->dtstart); - prop = icalproperty_new_dtstart (ictime); - if (ical->date_only) { - icalparameter *param; - param = icalparameter_new (ICAL_VALUE_PARAMETER); - icalparameter_set_value (param, ICAL_VALUE_DATE); - icalproperty_add_parameter (prop, param); - } - icalcomponent_add_property (comp, prop); - } - - /*** duration ***/ - { - /* FIX ME */ - } - - /*** freebusy ***/ - { - /* FIX ME */ - } - - /*** transp ***/ - { - if (ical->transp == ICAL_TRANSP_PROPERTY) - prop = icalproperty_new_transp ("TRANSPARENT"); - else - prop = icalproperty_new_transp ("OPAQUE"); - icalcomponent_add_property (comp, prop); - } - - /* - ICAL_TZID_PROPERTY: - ICAL_TZNAME_PROPERTY: - ICAL_TZOFFSETFROM_PROPERTY: - ICAL_TZOFFSETTO_PROPERTY: - ICAL_TZURL_PROPERTY: - */ - - /*** attendee ***/ - if (ical->attendee) { - /* a list of (iCalPerson *) */ - GList *cur; - for (cur = ical->attendee; cur; cur = cur->next) { - iCalPerson *person = (iCalPerson *) cur->data; - prop = icalproperty_new_attendee (person->addr); - unparse_person (person, prop); - icalcomponent_add_property (comp, prop); - } - } - - /*** contact ***/ - if (ical->contact) { - /* a list of (iCalPerson *) */ - GList *cur; - for (cur = ical->contact; cur; cur = cur->next) { - iCalPerson *person = (iCalPerson *) cur->data; - prop = icalproperty_new_contact (person->addr); - unparse_person (person, prop); - icalcomponent_add_property (comp, prop); - } - } - - /*** organizer ***/ - if (ical->organizer) { - prop = icalproperty_new_organizer (ical->organizer->addr); - unparse_person (ical->organizer, prop); - icalcomponent_add_property (comp, prop); - } - - /*** recurrenceid ***/ - if (ical->recurid) { - struct icaltimetype ictime; - ictime = timet_to_icaltime (ical->recurid); - prop = icalproperty_new_recurrenceid (ictime); - } - - /*** relatedto ***/ - - if (ical->related) { - /* a list of (iCalPerson *) */ - GList *cur; - for (cur = ical->related; cur; cur = cur->next) { - iCalRelation *related = (iCalRelation *) cur->data; - prop = unparse_related (related); - icalcomponent_add_property (comp, prop); - } - } - - - /*** url ***/ - if (ical->url) { - prop = icalproperty_new_url (ical->url); - icalcomponent_add_property (comp, prop); - } - - /*** uid ***/ - if (ical->uid) { - prop = icalproperty_new_uid (ical->uid); - icalcomponent_add_property (comp, prop); - } - - /*** exdate ***/ - if (ical->exdate) { - struct icaltimetype v; - GList *cur; - for (cur = ical->exdate; cur; cur = cur->next) { - time_t t = (time_t) cur->data; - v = timet_to_icaltime (t); - prop = icalproperty_new_exdate (v); - icalcomponent_add_property (comp, prop); - } - } - - /*** created ***/ - if (ical->created) { - struct icaltimetype v; - v = timet_to_icaltime (ical->created); - prop = icalproperty_new_created (v); - icalcomponent_add_property (comp, prop); - } - - /*** dtstamp ***/ - if (ical->dtstamp) { - struct icaltimetype v; - v = timet_to_icaltime (ical->dtstamp); - prop = icalproperty_new_created (v); - icalcomponent_add_property (comp, prop); - } - - /*** lastmodified ***/ - if (ical->last_mod) { - struct icaltimetype v; - v = timet_to_icaltime (ical->last_mod); - prop = icalproperty_new_created (v); - icalcomponent_add_property (comp, prop); - } - - /*** sequence ***/ - if (ical->seq) { - prop = icalproperty_new_sequence (ical->seq); - icalcomponent_add_property (comp, prop); - } - - /*** requeststatus ***/ - if (ical->rstatus) { - prop = icalproperty_new_requeststatus (ical->rstatus); - icalcomponent_add_property (comp, prop); - } - - /* if there is a VALARM subcomponent, add it here */ - - if (ical->alarms) { - GList *cur; - for (cur = ical->alarms; cur; cur = cur->next) { - CalendarAlarm *alarm = (CalendarAlarm *) cur->data; - icalcomponent *subcomp = unparse_alarm (alarm); - icalcomponent_add_component (comp, subcomp); - } - } - - return comp; -} - - -/* FIX ME -- same as icaltimetype_from_timet in icaltypes.c */ -static -struct icaltimetype timet_to_icaltime (time_t tt) -{ - struct tm *t; - struct icaltimetype i; - - t = gmtime (&tt); - - /*return tt - (i->is_utc ? timezone : 0); */ - i.is_utc = 0; - - i.year = t->tm_year + 1900; - i.month = t->tm_mon + 1; - i.day = t->tm_mday; - - if (t->tm_hour == 0 && t->tm_min == 0 && t->tm_sec == 0) { - i.is_date = 1; - i.hour = 0; - i.minute = 0; - i.second = 0; - } else { - i.is_date = 0; - i.hour = t->tm_hour; - i.minute = t->tm_min; - i.second = t->tm_sec; - } - - return i; -} - - -/* fills in "person_prop" with information from "person" */ - -static -void unparse_person (iCalPerson *person, icalproperty *person_prop) -{ - icalparameter *param; - GList *cur; - - /* convert iCalPerson to an icalproperty */ - - if (person->name) { - param = icalparameter_new_cn (person->name); - icalproperty_add_parameter (person_prop, param); - } - - if (g_strcasecmp (person->role, "CHAIR") == 0) - param = icalparameter_new_role (ICAL_ROLE_CHAIR); - else if (g_strcasecmp (person->role, "REQPARTICIPANT") == 0) - param = icalparameter_new_role (ICAL_ROLE_REQPARTICIPANT); - else if (g_strcasecmp (person->role, "OPTPARTICIPANT") == 0) - param = icalparameter_new_role (ICAL_ROLE_OPTPARTICIPANT); - else if (g_strcasecmp (person->role, "NONPARTICIPANT") == 0) - param = icalparameter_new_role (ICAL_ROLE_NONPARTICIPANT); - else - param = icalparameter_new_role (ICAL_ROLE_XNAME); - icalproperty_add_parameter (person_prop, param); - - if (g_strcasecmp (person->partstat, "NEEDSACTION") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_NEEDSACTION); - else if (g_strcasecmp (person->partstat, "ACCEPTED") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_ACCEPTED); - else if (g_strcasecmp (person->partstat, "DECLINED") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_DECLINED); - else if (g_strcasecmp (person->partstat, "TENTATIVE") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_TENTATIVE); - else if (g_strcasecmp (person->partstat, "DELEGATED") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_DELEGATED); - else if (g_strcasecmp (person->partstat, "COMPLETED") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_COMPLETED); - else if (g_strcasecmp (person->partstat, "INPROCESS") == 0) - param = icalparameter_new_partstat (ICAL_PARTSTAT_INPROCESS); - else /* FIX ME, NEEDSACTION instead? */ - param = icalparameter_new_partstat (ICAL_PARTSTAT_XNAME); - icalproperty_add_parameter (person_prop, param); - - if (person->rsvp != FALSE) { - param = icalparameter_new_rsvp (TRUE); - icalproperty_add_parameter (person_prop, param); - } - - if (g_strcasecmp (person->cutype, "INDIVIDUAL") == 0) - param = icalparameter_new_cutype (ICAL_CUTYPE_INDIVIDUAL); - else if (g_strcasecmp (person->cutype, "GROUP") == 0) - param = icalparameter_new_cutype (ICAL_CUTYPE_GROUP); - else if (g_strcasecmp (person->cutype, "RESOURCE") == 0) - param = icalparameter_new_cutype (ICAL_CUTYPE_RESOURCE); - else if (g_strcasecmp (person->cutype, "ROOM") == 0) - param = icalparameter_new_cutype (ICAL_CUTYPE_ROOM); - else /* FIX ME, INDIVIDUAL instead? */ - param = icalparameter_new_cutype (ICAL_CUTYPE_UNKNOWN); - icalproperty_add_parameter (person_prop, param); - - /* person->member is a list of ICAL_MEMBER_PARAMETER */ - for (cur = person->member; cur; cur = cur->next) { - gchar *member = (gchar *) cur->data; - param = icalparameter_new_member (member); - icalproperty_add_parameter (person_prop, param); - } - - /* person->deleg_to is a list of ICAL_DELEGATEDTO_PARAMETER */ - for (cur = person->deleg_to; cur; cur = cur->next) { - gchar *deleg_to = (gchar *) cur->data; - param = icalparameter_new_delegatedto (deleg_to); - icalproperty_add_parameter (person_prop, param); - } - - /* ret->deleg_from is a list of ICAL_DELEGATEDFROM_PARAMETER */ - for (cur = person->deleg_from; cur; cur = cur->next) { - gchar *deleg_from = (gchar *) cur->data; - param = icalparameter_new_delegatedfrom (deleg_from); - icalproperty_add_parameter (person_prop, param); - } - - if (person->sent_by) { - param = icalparameter_new_sentby (person->sent_by); - icalproperty_add_parameter (person_prop, param); - } - - /* ret->deleg_to is a list of ICAL_DIR_PARAMETER */ - /* FIX ME ... */ -} - - -static -icalproperty *unparse_related (iCalRelation *rel) -{ - icalproperty *prop; - - prop = icalproperty_new_relatedto (rel->reltype); - - icalproperty_set_relatedto (prop, rel->uid); - - /* FIX ME RELTYPE_XNAME ? */ - - return prop; -} - - -static -icalcomponent *unparse_alarm (CalendarAlarm *alarm) -{ - icalcomponent *comp = icalcomponent_new (ICAL_VALARM_COMPONENT); - icalproperty *prop; - - prop = NULL; - switch (alarm->type){ - case ALARM_AUDIO: - prop = icalproperty_new_action ("AUDIO"); - break; - case ALARM_DISPLAY: - prop = icalproperty_new_action ("DISPLAY"); - break; - case ALARM_MAIL: - prop = icalproperty_new_action ("EMAIL"); - break; - case ALARM_PROGRAM: - prop = icalproperty_new_action ("PROCEDURE"); - break; - default: - g_warning ("Unsupported alarm type!"); - break; - } - if (prop) - icalcomponent_add_property (comp, prop); - - if (alarm->snooze_repeat) - prop = icalproperty_new_repeat (alarm->snooze_repeat); - - if (alarm->snooze_secs) { - struct icaldurationtype dur; - dur = icaldurationtype_from_timet (alarm->snooze_secs); - prop = icalproperty_new_duration (dur); - icalcomponent_add_property (comp, prop); - } - - if (alarm->attach) { - struct icalattachtype *attach; - attach = icalattachtype_new (); - icalattachtype_set_url (attach, alarm->attach); - prop = icalproperty_new_attach (*attach); - icalattachtype_free (attach); - icalcomponent_add_property (comp, prop); - } - - if (alarm->desc) { - prop = icalproperty_new_description (alarm->desc); - icalcomponent_add_property (comp, prop); - } - - if (alarm->summary) { - prop = icalproperty_new_summary (alarm->summary); - icalcomponent_add_property (comp, prop); - } - - if (alarm->attendee) { - icalproperty_new_attendee (alarm->attendee); - icalcomponent_add_property (comp, prop); - } - - return comp; -} diff --git a/calendar/cal-util/icalendar-save.h b/calendar/cal-util/icalendar-save.h deleted file mode 100644 index 1e0ab59e70..0000000000 --- a/calendar/cal-util/icalendar-save.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ICALENDAR_SAVE_H -#define ICALENDAR_SAVE_H - -#include <ical.h> -#include <cal-util/calobj.h> - - - -icalcomponent *icalcomponent_create_from_ical_object (iCalObject *ical); - - - -#endif diff --git a/calendar/cal-util/icalendar-test.c b/calendar/cal-util/icalendar-test.c deleted file mode 100644 index 921e109a2c..0000000000 --- a/calendar/cal-util/icalendar-test.c +++ /dev/null @@ -1,146 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#include <sys/stat.h> -#include <stdlib.h> -#include <unistd.h> - -#include <config.h> -#include <gtk/gtksignal.h> -#include <cal-util/calobj.h> -#include "libversit/vcc.h" - -#include "icalendar-save.h" -#include "icalendar.h" - - -static icalcomponent* -icalendar_parse_file (char* fname) -{ - FILE* fp; - icalcomponent* comp = NULL; - gchar* str; - struct stat st; - int n; - - fp = fopen (fname, "r"); - if (!fp) { - g_warning ("Cannot open open calendar file."); - return NULL; - } - - stat (fname, &st); - - str = g_malloc (st.st_size + 2); - - n = fread ((gchar*) str, 1, st.st_size, fp); - if (n != st.st_size) { - g_warning ("Read error."); - } - str[n] = '\0'; - - fclose (fp); - - comp = icalparser_parse_string (str); - g_free (str); - - return comp; -} - - -static GList * -icalendar_calendar_load (GList *icals, char *fname) -{ - icalcomponent *comp; - icalcomponent *subcomp; - iCalObject *ical; - - comp = icalendar_parse_file (fname); - subcomp = icalcomponent_get_first_component (comp, - ICAL_ANY_COMPONENT); - while (subcomp) { - ical = ical_object_create_from_icalcomponent (subcomp); - if (ical->type != ICAL_EVENT && - ical->type != ICAL_TODO && - ical->type != ICAL_JOURNAL) { - g_warning ("Skipping unsupported iCalendar component"); - } else { - printf ("prepending %p\n", ical); - icals = g_list_prepend (icals, ical); - } - subcomp = icalcomponent_get_next_component (comp, - ICAL_ANY_COMPONENT); - } - - return icals; -} - - - - -static void -icalendar_calendar_save (GList *icals, char *fname) -{ - GList *cur; - icalcomponent *top = icalcomponent_new (ICAL_VCALENDAR_COMPONENT); - char *out_cal_string; - - for (cur=icals; cur; cur=cur->next) { - iCalObject *ical = (iCalObject *) cur->data; - icalcomponent *comp; - comp = icalcomponent_create_from_ical_object (ical); - icalcomponent_add_component (top, comp); - } - - out_cal_string = icalcomponent_as_ical_string (top); - - printf ("---------------------------------------------------------\n"); - printf ("%s", out_cal_string); -} - - - -int main (int argc, char *argv[]) -{ - GList *icals = NULL; - int i; - long int n0, n1; - struct icaldurationtype dt; - - - /* test icaldurationtype_from_timet */ - srandom (time (0)); - - for (i=0; i<10; i++) { - n0 = random () % ((60 * 60 * 24 * 7) * 4); - dt = icaldurationtype_from_timet (n0); - n1 = icaldurationtype_as_timet (dt); - - printf ("%ld -> (%d %d %d %d %d) -> %ld\n", - n0, - dt.weeks, dt.days, dt.hours, dt.minutes, dt.seconds, - n1); - if (n0 != n1) abort (); - } - - /*****************/ - /* test conversion of icalcomponents to and from iCalObjects */ - /*****************/ - - /* load an ical file */ - - if (argc < 2) { - printf ("give ical file as argument.\n"); - return 1; - } - - icals = icalendar_calendar_load (icals, argv[ 1 ]); - - printf ("loaded %d ical components\n", g_list_length (icals)); - - - /* save it back out */ - - icalendar_calendar_save (icals, "out.ical"); - - return 0; -} diff --git a/calendar/cal-util/icalendar.c b/calendar/cal-util/icalendar.c deleted file mode 100644 index eedb732617..0000000000 --- a/calendar/cal-util/icalendar.c +++ /dev/null @@ -1,674 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * icalendar server for gnomecal - * - * This module interfaces between libical and the gnomecal internal - * representation - * - * Copyright (C) 1999 The Free Software Foundation - * Authors: - * Russell Steinthal (rms39@columbia.edu) - * - */ - -#include <config.h> -#include <unistd.h> -#include <sys/stat.h> -#include "icalendar.h" - -static time_t icaltime_to_timet (struct icaltimetype* i); -static CalendarAlarm* parse_alarm (icalproperty *prop); -static iCalPerson* parse_person (icalproperty *prop, gchar *value); -static iCalRelation* parse_related (icalproperty *prop); - -/* Duplicate a string without memory leaks */ -static gchar* copy_str (gchar** store, gchar* src) -{ - if (*store) - g_free (*store); - return (*store = g_strdup (src)); -} - -static GList* -copy_to_list (GList** store, gchar* src) -{ - *store = g_list_prepend (*store, g_strdup (src)); - return *store; -} - - -iCalObject * -ical_object_create_from_icalcomponent (icalcomponent* comp) -{ - iCalObject *ical = NULL; - iCalPerson *person; - icalcomponent *subcomp; - icalproperty *prop; - icalparameter *param; - struct icaltimetype ictime; - time_t *pt; - CalendarAlarm *alarm = NULL; - icalcomponent_kind compType; - struct icalgeotype geo; - struct icalperiodtype period; - - gboolean root = FALSE; - gboolean attachment = FALSE; - - char *tmpStr; /* this is a library-owned string */ - - ical = g_new0 (iCalObject, 1); - - compType = icalcomponent_isa (comp); - - switch (compType) { - case ICAL_XROOT_COMPONENT: - root = TRUE; - break; - case ICAL_XATTACH_COMPONENT: - attachment = TRUE; - break; - case ICAL_VEVENT_COMPONENT: - ical->type = ICAL_EVENT; - break; - case ICAL_VTODO_COMPONENT: - ical->type = ICAL_TODO; - break; - case ICAL_VJOURNAL_COMPONENT: - ical->type = ICAL_JOURNAL; - break; - case ICAL_VCALENDAR_COMPONENT: - /* FIXME: what does this mean? */ - break; - case ICAL_VFREEBUSY_COMPONENT: - ical->type = ICAL_FBREQUEST; - /* NOTE: This is not conclusive- you need to analyze - properties to determine whether this is an - FBREQUEST or an FBREPLY */ - break; - case ICAL_VTIMEZONE_COMPONENT: - ical->type = ICAL_TIMEZONE; - break; - case ICAL_VALARM_COMPONENT: - case ICAL_XAUDIOALARM_COMPONENT: - case ICAL_XDISPLAYALARM_COMPONENT: - case ICAL_XEMAILALARM_COMPONENT: - case ICAL_XPROCEDUREALARM_COMPONENT: - /* this should not be reached, since this loop should - only be processing first level components */ - break; - case ICAL_XSTANDARD_COMPONENT: - /* FIXME: what does this mean? */ - break; - case ICAL_XDAYLIGHT_COMPONENT: - /* FIXME: what does this mean? */ - break; - case ICAL_X_COMPONENT: - /* FIXME: what does this mean? */ - break; - case ICAL_VSCHEDULE_COMPONENT: - /* FIXME: what does this mean? */ - break; - case ICAL_XLICINVALID_COMPONENT: - /* FIXME: what does this mean? */ - break; - case ICAL_NO_COMPONENT: - case ICAL_ANY_COMPONENT: - /* should not occur */ - break; - case ICAL_VQUERY_COMPONENT: - case ICAL_VCAR_COMPONENT: - case ICAL_VCOMMAND_COMPONENT: - /* FIXME: what does this mean? */ - break; - } - - prop = icalcomponent_get_first_property (comp, ICAL_ANY_PROPERTY); - while (prop) { - switch (icalproperty_isa (prop)) { - case ICAL_CALSCALE_PROPERTY: - if (g_strcasecmp (icalproperty_get_calscale (prop), - "GREGORIAN")) - g_warning ("Unknown calendar format."); - break; - case ICAL_METHOD_PROPERTY: - /* FIXME: implement something here */ - break; - case ICAL_ATTACH_PROPERTY: - /* FIXME: not yet implemented */ - break; - case ICAL_CATEGORIES_PROPERTY: - copy_to_list (&ical->categories, - icalproperty_get_categories (prop)); - break; - case ICAL_CLASS_PROPERTY: - copy_str (&ical->class, icalproperty_get_class (prop)); - break; - case ICAL_COMMENT_PROPERTY: - /*tmpStr = icalproperty_get_comment (prop);*/ - tmpStr = g_strconcat (icalproperty_get_comment (prop), - ical->comment, - NULL); - if (ical->comment) - g_free (ical->comment); - ical->comment = tmpStr; - break; - case ICAL_DESCRIPTION_PROPERTY: - copy_str (&ical->desc, - icalproperty_get_description (prop)); - break; - case ICAL_GEO_PROPERTY: - geo = icalproperty_get_geo (prop); - ical->geo.latitude = geo.lat; - ical->geo.longitude = geo.lon; - ical->geo.valid = TRUE; - break; - case ICAL_LOCATION_PROPERTY: - copy_str (&ical->location, - icalproperty_get_location (prop)); - break; - case ICAL_PERCENTCOMPLETE_PROPERTY: - ical->percent = icalproperty_get_percentcomplete (prop); - break; - case ICAL_PRIORITY_PROPERTY: - ical->priority = icalproperty_get_priority (prop); - if (ical->priority < 0 || ical->priority > 9) - g_warning ("Priority out-of-range (see RFC2445)"); - break; - case ICAL_RESOURCES_PROPERTY: - copy_to_list (&ical->resources, - icalproperty_get_resources (prop)); - break; - case ICAL_STATUS_PROPERTY: - copy_str (&ical->status, - icalproperty_get_status (prop)); - break; - case ICAL_SUMMARY_PROPERTY: - copy_str (&ical->summary, - icalproperty_get_summary (prop)); - break; - case ICAL_COMPLETED_PROPERTY: - ictime = icalproperty_get_completed (prop); - ical->completed = icaltime_to_timet (&ictime); - break; - case ICAL_DTEND_PROPERTY: - ictime = icalproperty_get_dtend (prop); - ical->dtend = icaltime_to_timet (&ictime); - param = icalproperty_get_first_parameter (prop, - ICAL_VALUE_PARAMETER); - if (param) - ical->date_only = (icalparameter_get_value (param) == ICAL_VALUE_DATE); - /* FIXME: We should handle timezone specifiers */ - break; - case ICAL_DUE_PROPERTY: - ictime = icalproperty_get_due (prop); - ical->dtend = icaltime_to_timet (&ictime); - param = icalproperty_get_first_parameter (prop, - ICAL_VALUE_PARAMETER); - ical->date_only = (icalparameter_get_value (param) == - ICAL_VALUE_DATE); - /* FIXME: We should handle timezone specifiers */ - break; - case ICAL_DTSTART_PROPERTY: - ictime = icalproperty_get_dtstart (prop); - ical->dtstart = icaltime_to_timet (&ictime); - param = icalproperty_get_first_parameter (prop, - ICAL_VALUE_PARAMETER); - if (param) - ical->date_only = (icalparameter_get_value (param) == ICAL_VALUE_DATE); - /* FIXME: We should handle timezone specifiers */ - break; - case ICAL_DURATION_PROPERTY: - /* FIXME: I don't see the necessary libical function */ - break; - case ICAL_FREEBUSY_PROPERTY: - period = icalproperty_get_freebusy (prop); - ical->dtstart = icaltime_to_timet (&(period.start)); - /* FIXME: period.end is specified as being relative - to start, so this may not be correct */ - ical->dtend = icaltime_to_timet (&(period.end)); - break; - case ICAL_TRANSP_PROPERTY: - tmpStr = icalproperty_get_transp (prop); - /* do not i18n the following string constant! */ - if (!g_strcasecmp (tmpStr, "TRANSPARENT")) - ical->transp = ICAL_TRANSPARENT; - else - ical->transp = ICAL_OPAQUE; - break; - case ICAL_TZID_PROPERTY: - case ICAL_TZNAME_PROPERTY: - case ICAL_TZOFFSETFROM_PROPERTY: - case ICAL_TZOFFSETTO_PROPERTY: - case ICAL_TZURL_PROPERTY: - /* no implementation for now */ - break; - case ICAL_ATTENDEE_PROPERTY: - tmpStr = icalproperty_get_attendee (prop); - person = parse_person (prop, tmpStr); - ical->attendee = g_list_prepend (ical->attendee, - person); - break; - case ICAL_CONTACT_PROPERTY: - tmpStr = icalproperty_get_contact (prop); - person = parse_person (prop, tmpStr); - ical->contact = g_list_prepend (ical->contact, person); - break; - case ICAL_ORGANIZER_PROPERTY: - tmpStr = icalproperty_get_organizer (prop); - person = parse_person (prop, tmpStr); - if (ical->organizer) - g_free (ical->organizer); - ical->organizer = person; - break; - case ICAL_RECURRENCEID_PROPERTY: - ictime = icalproperty_get_recurrenceid (prop); - ical->recurid = icaltime_to_timet (&ictime); - /* FIXME: Range parameter not implemented */ - break; - case ICAL_RELATEDTO_PROPERTY: - ical->related = g_list_prepend (ical->related, - parse_related (prop)); - break; - case ICAL_URL_PROPERTY: - copy_str (&ical->url, - icalproperty_get_url (prop)); - break; - case ICAL_UID_PROPERTY: - copy_str (&ical->uid, - icalproperty_get_uid (prop)); - break; - case ICAL_EXDATE_PROPERTY: - /* FIXME: This does not appear to parse - multiple exdate values in one property, as - allowed by the RFC; needs a libical fix */ - ictime = icalproperty_get_exdate (prop); - pt = g_new0 (time_t, 1); - *pt = icaltime_to_timet (&ictime); - ical->exdate = g_list_prepend (ical->exdate, pt); - break; - case ICAL_EXRULE_PROPERTY: - case ICAL_RDATE_PROPERTY: - case ICAL_RRULE_PROPERTY: - /* FIXME: need recursion processing */ - break; - case ICAL_ACTION_PROPERTY: - case ICAL_REPEAT_PROPERTY: - case ICAL_TRIGGER_PROPERTY: - /* should only occur in VALARM's, handled below */ - g_assert_not_reached(); - break; - case ICAL_CREATED_PROPERTY: - ictime = icalproperty_get_created (prop); - ical->created = icaltime_to_timet (&ictime); - break; - case ICAL_DTSTAMP_PROPERTY: - ictime = icalproperty_get_dtstamp (prop); - ical->dtstamp = icaltime_to_timet (&ictime); - break; - case ICAL_LASTMODIFIED_PROPERTY: - ictime = icalproperty_get_lastmodified (prop); - ical->last_mod = icaltime_to_timet (&ictime); - break; - case ICAL_SEQUENCE_PROPERTY: - ical->seq = icalproperty_get_sequence (prop); - break; - case ICAL_REQUESTSTATUS_PROPERTY: - copy_str (&ical->rstatus, - icalproperty_get_requeststatus (prop)); - break; - case ICAL_X_PROPERTY: - g_warning ("Unsupported X-property: %s", - icalproperty_as_ical_string (prop)); - break; - case ICAL_XLICERROR_PROPERTY: - g_warning ("Unsupported property: %s", - icalproperty_get_xlicerror (prop)); - break; - case ICAL_PRODID_PROPERTY: - case ICAL_VERSION_PROPERTY: - /* nothing to do for this property */ - break; - default: - g_warning ("Unsupported property: %s", icalproperty_as_ical_string -(prop)); - break; - - } - - prop = icalcomponent_get_next_property (comp, - ICAL_ANY_PROPERTY); - } - - /* now parse subcomponents --- should only be VALARM's */ - subcomp = icalcomponent_get_first_component (comp, - ICAL_ANY_COMPONENT); - while (subcomp) { - compType = icalcomponent_isa (subcomp); - switch (compType) { - case ICAL_VALARM_COMPONENT: - alarm = parse_alarm (subcomp); - if (alarm) - ical->alarms = g_list_prepend (ical->alarms, - alarm); - break; - default: - g_warning ("Only nested VALARM components are supported."); - } - - subcomp = icalcomponent_get_next_component (comp, - ICAL_ANY_COMPONENT); - } - - return ical; -} - - -static time_t icaltime_to_timet (struct icaltimetype* i) -{ - struct tm t; - time_t ret; - - t.tm_year = i->year - 1900; - t.tm_mon = i->month - 1; - t.tm_mday = i->day; - if (!i->is_date) { - t.tm_hour = i->hour; - t.tm_min = i->minute; - t.tm_sec = i->second; - } else { - t.tm_hour = 0; - t.tm_min = 0; - t.tm_sec = 0; - } - - ret = mktime(&t); - - if (i->is_utc) { -#ifdef HAVE_TIMEZONE - extern long timezone; - ret -= timezone; -#else - struct tm *tmp; - time_t tod = time(NULL); - tmp = localtime (&tod); - ret += tmp->tm_gmtoff; -#endif - } - - return ret; -} - -static iCalPerson* -parse_person (icalproperty* prop, gchar* value) -{ - icalparameter* param; - icalparameter_role role; - icalparameter_partstat partstat; - icalparameter_cutype cutype; - - iCalPerson* ret; - - ret = g_new0 (iCalPerson, 1); - - ret->addr = g_strdup (value); - - param = icalproperty_get_first_parameter (prop, - ICAL_CN_PARAMETER); - if (param) - ret->name = g_strdup (icalparameter_get_cn (param)); - else - ret->name = NULL; - - - param = icalproperty_get_first_parameter (prop, - ICAL_ROLE_PARAMETER); - if (param) { - role = icalparameter_get_role (param); - switch (role) { - case ICAL_ROLE_CHAIR: - ret->role = g_strdup ("CHAIR"); - break; - case ICAL_ROLE_REQPARTICIPANT: - ret->role = g_strdup ("REQPARTICIPANT"); - break; - case ICAL_ROLE_OPTPARTICIPANT: - ret->role = g_strdup ("OPTPARTICIPANT"); - break; - case ICAL_ROLE_NONPARTICIPANT: - ret->role = g_strdup ("NONPARTICIPANT"); - break; - case ICAL_ROLE_XNAME: - default: - ret->role = g_strdup ("UNKNOWN"); - break; - } - } else - ret->role = g_strdup ("REQPARTICIPANT"); - - param = icalproperty_get_first_parameter (prop, ICAL_PARTSTAT_PARAMETER); - if (param) { - partstat = icalparameter_get_partstat (param); - switch (partstat) { - case ICAL_PARTSTAT_NEEDSACTION: - ret->partstat = g_strdup ("NEEDSACTION"); - break; - case ICAL_PARTSTAT_ACCEPTED: - ret->partstat = g_strdup ("ACCEPTED"); - break; - case ICAL_PARTSTAT_DECLINED: - ret->partstat = g_strdup ("DECLINED"); - break; - case ICAL_PARTSTAT_TENTATIVE: - ret->partstat = g_strdup ("TENTATIVE"); - break; - case ICAL_PARTSTAT_DELEGATED: - ret->partstat = g_strdup ("DELEGATED"); - break; - case ICAL_PARTSTAT_COMPLETED: - ret->partstat = g_strdup ("COMPLETED"); - break; - case ICAL_PARTSTAT_INPROCESS: - ret->partstat = g_strdup ("INPROCESS"); - break; - case ICAL_PARTSTAT_XNAME: - ret->partstat = g_strdup (icalparameter_get_xvalue (param)); - break; - default: - ret->partstat = g_strdup ("UNKNOWN"); - break; - } - } else - ret->partstat = g_strdup ("NEEDSACTION"); - - param = icalproperty_get_first_parameter (prop, ICAL_RSVP_PARAMETER); - if (param) - ret->rsvp = icalparameter_get_rsvp (param); - else - ret->rsvp = FALSE; - - param = icalproperty_get_first_parameter (prop, ICAL_CUTYPE_PARAMETER -); - if (param) { - cutype = icalparameter_get_cutype (param); - switch (cutype) { - case ICAL_CUTYPE_INDIVIDUAL: - ret->cutype = g_strdup ("INDIVIDUAL"); - break; - case ICAL_CUTYPE_GROUP: - ret->cutype = g_strdup ("GROUP"); - break; - case ICAL_CUTYPE_RESOURCE: - ret->cutype = g_strdup ("RESOURCE"); - break; - case ICAL_CUTYPE_ROOM: - ret->cutype = g_strdup ("ROOM"); - break; - case ICAL_CUTYPE_UNKNOWN: - case ICAL_CUTYPE_XNAME: - default: - ret->cutype = g_strdup ("UNKNOWN"); - break; - } - } else - ret->cutype = g_strdup ("INDIVIDUAL"); - - param = icalproperty_get_first_parameter (prop, ICAL_MEMBER_PARAMETER -); - while (param) { - copy_to_list (&ret->member, icalparameter_get_member (param)); - param = icalproperty_get_next_parameter (prop, - ICAL_MEMBER_PARAMETER); - } - - param = icalproperty_get_first_parameter (prop, ICAL_DELEGATEDTO_PARAMETER); - while (param) { - copy_to_list (&ret->deleg_to, - icalparameter_get_delegatedto (param)); - param = icalproperty_get_next_parameter (prop, - ICAL_DELEGATEDTO_PARAMETER); - } - - param = icalproperty_get_first_parameter (prop, ICAL_DELEGATEDFROM_PARAMETER); - while (param) { - copy_to_list (&ret->deleg_from, - icalparameter_get_delegatedfrom (param)); - param = icalproperty_get_next_parameter (prop, - ICAL_DELEGATEDFROM_PARAMETER); - } - - param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER); - if (param) - copy_str (&ret->sent_by, icalparameter_get_sentby (param)); - else - ret->sent_by = NULL; - - param = icalproperty_get_first_parameter (prop, ICAL_DIR_PARAMETER); - while (param) { - copy_to_list (&ret->deleg_to, - icalparameter_get_delegatedto (param)); - param = icalproperty_get_next_parameter (prop, - ICAL_DIR_PARAMETER); - } - - return ret; -} - -static iCalRelation* -parse_related (icalproperty* prop) -{ - iCalRelation* rel; - icalparameter* param; - icalparameter_reltype type; - - rel = g_new0 (iCalRelation, 1); - rel->uid = g_strdup (icalproperty_get_relatedto (prop)); - - param = icalproperty_get_first_parameter (prop, - ICAL_RELTYPE_PARAMETER); - if (param) { - type = icalparameter_get_reltype (param); - switch (type) { - case ICAL_RELTYPE_PARENT: - rel->reltype = g_strdup ("PARENT"); - break; - case ICAL_RELTYPE_CHILD: - rel->reltype = g_strdup ("CHILD"); - break; - case ICAL_RELTYPE_SIBLING: - rel->reltype = g_strdup ("SIBLING"); - break; - case ICAL_RELTYPE_XNAME: - rel->reltype = g_strdup (icalparameter_get_xvalue (param)); - break; - default: - rel->reltype = g_strdup ("UNKNOWN"); - break; - } - } else - rel->reltype = g_strdup ("PARENT"); - - return rel; -} - -#ifdef TEST - -int main(int argc, char* argv[]) -{ - icalcomponent* comp; - comp = icalendar_parse_file (argv[1]); - printf ("%s\n", icalcomponent_as_ical_string (comp)); - return 0; -} - -#endif - - -static CalendarAlarm* -parse_alarm (icalcomponent* comp) -{ - CalendarAlarm *alarm; - icalproperty *prop; - char *tmpStr; - struct icaldurationtype dur; - struct icalattachtype attach; - - g_return_val_if_fail (comp != NULL, NULL); - - alarm = g_new0 (CalendarAlarm, 1); - - prop = icalcomponent_get_first_property (comp, ICAL_ANY_PROPERTY); - while (prop) { - switch (icalproperty_isa (prop)) { - case ICAL_ACTION_PROPERTY: - tmpStr = icalproperty_get_action (prop); - if (!g_strcasecmp (tmpStr, "AUDIO")) - alarm->type = ALARM_AUDIO; - else if (!g_strcasecmp (tmpStr, "DISPLAY")) - alarm->type = ALARM_DISPLAY; - else if (!g_strcasecmp (tmpStr, "EMAIL")) - alarm->type = ALARM_MAIL; - else if (!g_strcasecmp (tmpStr, "PROCEDURE")) - alarm->type = ALARM_PROGRAM; - else - g_warning ("Unsupported alarm type!"); - break; - case ICAL_TRIGGER_PROPERTY: - /* FIXME: waiting on proper libical support */ - break; - case ICAL_REPEAT_PROPERTY: - alarm->snooze_repeat = icalproperty_get_repeat (prop); - break; - case ICAL_DURATION_PROPERTY: - dur = icalproperty_get_duration (prop); - alarm->snooze_secs = icaldurationtype_as_timet (dur); - break; - case ICAL_ATTACH_PROPERTY: - attach = icalproperty_get_attach (prop); - copy_str (&alarm->attach, - icalattachtype_get_url (&attach)); - break; - case ICAL_DESCRIPTION_PROPERTY: - copy_str (&alarm->desc, - icalproperty_get_description (prop)); - break; - case ICAL_SUMMARY_PROPERTY: - copy_str (&alarm->summary, - icalproperty_get_summary (prop)); - break; - case ICAL_ATTENDEE_PROPERTY: - copy_str (&alarm->attendee, - icalproperty_get_attendee (prop)); - break; - default: - g_warning ("Unsupported alarm property: %s", - icalproperty_as_ical_string (prop)); - break; - } - - prop = icalcomponent_get_next_property (comp, - ICAL_ANY_PROPERTY); - } - - return alarm; -} diff --git a/calendar/cal-util/icalendar.h b/calendar/cal-util/icalendar.h deleted file mode 100644 index 2a22fbab71..0000000000 --- a/calendar/cal-util/icalendar.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ICALENDAR_H -#define ICALENDAR_H - -#include <ical.h> -#include <cal-util/calobj.h> - - - -iCalObject *ical_object_create_from_icalcomponent (icalcomponent* comp); - - - -#endif diff --git a/calendar/cal-util/timeutil.c b/calendar/cal-util/timeutil.c deleted file mode 100644 index f887a8df37..0000000000 --- a/calendar/cal-util/timeutil.c +++ /dev/null @@ -1,557 +0,0 @@ -/* Miscellaneous time-related utilities - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <federico@nuclecu.unam.mx> - * Miguel de Icaza <miguel@nuclecu.unam.mx> - */ - -#include <libgnome/libgnome.h> -#include <string.h> -#include "timeutil.h" - -#define digit_at(x,y) (x [y] - '0') - -time_t -time_from_isodate (char *str) -{ - struct tm my_tm; - time_t t; - - if (strlen (str) < 14) - return -1; - - my_tm.tm_year = (digit_at (str, 0) * 1000 + digit_at (str, 1) * 100 + - digit_at (str, 2) * 10 + digit_at (str, 3)) - 1900; - - my_tm.tm_mon = digit_at (str, 4) * 10 + digit_at (str, 5) - 1; - my_tm.tm_mday = digit_at (str, 6) * 10 + digit_at (str, 7); - my_tm.tm_hour = digit_at (str, 9) * 10 + digit_at (str, 10); - my_tm.tm_min = digit_at (str, 11) * 10 + digit_at (str, 12); - my_tm.tm_sec = digit_at (str, 13) * 10 + digit_at (str, 14); - my_tm.tm_isdst = -1; - - t = mktime (&my_tm); - - if (str [15] == 'Z') -#if defined(HAVE_TM_GMTOFF) - t -= my_tm.tm_gmtoff -#elsif defined(HAVE_TIMEZONE) - t -= timezone -#endif - ; - - return t; -} - -void -print_time_t (time_t t) -{ - struct tm *tm = localtime (&t); - - printf ("TIEMPO: %d/%d/%d %d:%d:%d\n", - tm->tm_mon+1, tm->tm_mday, tm->tm_year, - tm->tm_hour, tm->tm_min, tm->tm_sec); -} - -int -get_time_t_hour (time_t t) -{ - struct tm *tm; - - tm = localtime (&t); - return tm->tm_hour; -} - -char * -isodate_from_time_t (time_t t) -{ - struct tm *tm; - static char isotime [40]; - - tm = localtime (&t); - strftime (isotime, sizeof (isotime)-1, "%Y%m%dT%H%M%S", tm); - return isotime; -} - -time_t -time_from_start_duration (time_t start, char *duration) -{ - printf ("Not yet implemented\n"); - return 0; -} - -char * -format_simple_hour (int hour, int use_am_pm) -{ - static char buf[256]; - - /* I don't know whether this is the best way to internationalize it. - * Does any language use different conventions? - Federico - */ - - if (use_am_pm) - g_snprintf (buf, sizeof(buf), "%d%s", - (hour == 0) ? 12 : (hour > 12) ? (hour - 12) : hour, - (hour < 12) ? _("am") : _("pm")); - else - g_snprintf (buf, sizeof(buf), "%02d%s", hour, _("h")); - - return buf; - -} - -time_t -time_add_minutes (time_t time, int minutes) -{ - struct tm *tm = localtime (&time); - time_t new_time; - - tm->tm_min += minutes; - if ((new_time = mktime (tm)) == -1){ - g_message ("time_add_minutes(): mktime() could not handle " - "adding %d minutes with\n", minutes); - print_time_t (time); - return time; - } - return new_time; -} - -/* Adds a day onto the time, using local time. - Note that if clocks go forward due to daylight savings time, there are - some non-existent local times, so the hour may be changed to make it a - valid time. This also means that it may not be wise to keep calling - time_add_day() to step through a certain period - if the hour gets changed - to make it valid time, any further calls to time_add_day() will also return - this hour, which may not be what you want. */ -time_t -time_add_day (time_t time, int days) -{ - struct tm *tm = localtime (&time); - time_t new_time; -#if 0 - int dst_flag = tm->tm_isdst; -#endif - - tm->tm_mday += days; - - if ((new_time = mktime (tm)) == -1){ - g_message ("time_add_day(): mktime() could not handling adding %d days with\n", - days); - print_time_t (time); - return time; - } - -#if 0 - /* I don't know what this is for. See also time_day_begin() and - time_day_end(). - Damon. */ - if (dst_flag > tm->tm_isdst){ - tm->tm_hour++; - new_time += 3600; - } else if (dst_flag < tm->tm_isdst){ - tm->tm_hour--; - new_time -= 3600; - } -#endif - - return new_time; -} - -time_t -time_add_week (time_t time, int weeks) -{ - return time_add_day (time, weeks * 7); -} - -time_t -time_add_month (time_t time, int months) -{ - struct tm *tm = localtime (&time); - time_t new_time; - int mday; - - mday = tm->tm_mday; - - tm->tm_mon += months; - tm->tm_isdst = -1; - if ((new_time = mktime (tm)) == -1){ - g_message ("time_add_month(): mktime() could not handling adding %d months with\n", - months); - print_time_t (time); - return time; - } - tm = localtime (&new_time); - if (tm->tm_mday < mday){ - tm->tm_mon--; - tm->tm_mday = time_days_in_month (tm->tm_year+1900, tm->tm_mon); - return new_time = mktime (tm); - } - else - return new_time; -} - -time_t -time_add_year (time_t time, int years) -{ - struct tm *tm = localtime (&time); - time_t new_time; - - tm->tm_year += years; - if ((new_time = mktime (tm)) == -1){ - g_message ("time_add_year(): mktime() could not handling adding %d years with\n", - years); - print_time_t (time); - return time; - } - return new_time; -} - -time_t -time_day_hour (time_t t, int hour) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = hour; - tm.tm_min = 0; - tm.tm_sec = 0; - - return mktime (&tm); -} - -/* Number of days in a month, for normal and leap years */ -static const int days_in_month[2][12] = { - { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; - -/* Returns whether the specified year is a leap year */ -static int -is_leap_year (int year) -{ - if (year <= 1752) - return !(year % 4); - else - return (!(year % 4) && (year % 100)) || !(year % 400); -} - -int -time_days_in_month (int year, int month) -{ - g_return_val_if_fail (year >= 1900, 0); - g_return_val_if_fail ((month >= 0) && (month < 12), 0); - - return days_in_month [is_leap_year (year)][month]; -} - -time_t -time_from_day (int year, int month, int day) -{ - struct tm tm; - - memset (&tm, 0, sizeof (tm)); - tm.tm_year = year - 1900; - tm.tm_mon = month; - tm.tm_mday = day; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_year_begin (time_t t) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mon = 0; - tm.tm_mday = 1; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_year_end (time_t t) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mon = 0; - tm.tm_mday = 1; - tm.tm_year++; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_month_begin (time_t t) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday = 1; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_month_end (time_t t) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday = 1; - tm.tm_mon++; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_week_begin (time_t t) -{ - struct tm tm; - - /* FIXME: make it take week_starts_on_monday into account */ - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday -= tm.tm_wday; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_week_end (time_t t) -{ - struct tm tm; - - /* FIXME: make it take week_starts_on_monday into account */ - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday += 7 - tm.tm_wday; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -/* Returns the start of the day, according to the local time. */ -time_t -time_day_begin (time_t t) -{ -#if 1 - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_isdst = -1; - - return mktime (&tm); - -#else - /* This is the original code which sometimes produces a time of 1:00. - I don't understand why it looked at the tm_isdst flags at all. - - Damon. */ - - struct tm tm; - time_t temp = t - 43200; - int dstflag, dstflag2; - - tm = *localtime(&temp); /* one day */ - dstflag = tm.tm_isdst; - - tm = *localtime (&t); - dstflag2 = tm.tm_isdst; - - if (dstflag < dstflag2) - tm.tm_hour = 1; - else - tm.tm_hour = 0; - - tm.tm_min = 0; - tm.tm_sec = 0; - - temp = mktime(&tm); - if (dstflag > dstflag2){ - temp += 3600; - } - - return temp; -#endif -} - -/* Returns the end of the day, according to the local time. */ -time_t -time_day_end (time_t t) -{ -#if 1 - struct tm tm; - - tm = *localtime (&t); - tm.tm_mday++; - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_isdst = -1; - - return mktime (&tm); - -#else - /* This is the original code which has more problems than - time_day_begin(). - Damon. */ - - struct tm tm; - time_t temp; - int dstflag, dstflag2; - - t += 10800; - temp = t - 86400; - - tm = *localtime(&temp); /* one day */ - dstflag = tm.tm_isdst; - - tm = *localtime (&t); - dstflag2 = tm.tm_isdst; - - if (dstflag < dstflag2) - tm.tm_hour = 23; - else { - tm.tm_mday++; - tm.tm_hour = 0; - } - tm.tm_min = 0; - tm.tm_sec = 0; - - temp = mktime(&tm); - if(dstflag > dstflag2) { - } - return temp; -#endif -} - -static char * -pcat (char *dest, int num, char key) -{ - int c; - - c = sprintf (dest, "%d%c", num, key); - return dest + c; -} - -/* Converts secs into the ISO difftime representation */ -char * -isodiff_from_secs (int secs) -{ - static char buffer [60], *p; - int years, months, weeks, days, hours, minutes; - - years = months = weeks = days = hours = minutes = 0; - - years = secs / (365 * 86400); - secs %= (365 * 86400); - months = secs / (30 * 86400); - secs %= (30 * 86400); - weeks = secs / (7 * 86400); - secs %= (7 * 86400); - days = secs / 86400; - secs %= 86400; - hours = secs / 3600; - secs %= 3600; - minutes = secs / 60; - secs %= 60; - - strcpy (buffer, "P"); - p = buffer + 1; - if (years) - p = pcat (p, years, 'Y'); - if (months) - p = pcat (p, months, 'M'); - if (weeks) - p = pcat (p, weeks, 'W'); - if (days) - p = pcat (p, days, 'D'); - if (hours || minutes || secs){ - *p++ = 'T'; - if (hours) - p = pcat (p, hours, 'H'); - if (minutes) - p = pcat (p, minutes, 'M'); - if (secs) - p = pcat (p, secs, 'S'); - } - - return buffer; -} - -int -isodiff_to_secs (char *str) -{ - int value, time; - int years, months, weeks, days, hours, minutes, seconds; - - value = years = months = weeks = days = hours = minutes = time = seconds = 0; - if (*str != 'P') - return 0; - - str++; - while (*str){ - switch (*str){ - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - value = value * 10 + (*str - '0'); - break; - case 'Y': - years = value; value = 0; - break; - case 'M': - if (time) - minutes = value; - else - months = value; - value = 0; - break; - case 'W': - weeks = value; value = 0; - break; - case 'D': - days = value; value = 0; - break; - case 'T': - value = 0; time = 1; - break; - case 'H': - hours = value; value = 0; - break; - case 'S': - seconds = value; value = 0; - break; - } - str++; - } - return seconds + (minutes * 60) + (hours * 3600) + - (days * 86400) + (weeks * 7 * 86400) + - (months * 30 * 86400) + (years * 365 * 86400); -} diff --git a/calendar/cal-util/timeutil.h b/calendar/cal-util/timeutil.h deleted file mode 100644 index 407213d7f8..0000000000 --- a/calendar/cal-util/timeutil.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Miscellaneous time-related utilities - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <federico@nuclecu.unam.mx> - * Miguel de Icaza <miguel@nuclecu.unam.mx> - */ - -#ifndef TIMEUTIL_H -#define TIMEUTIL_H - - -#include <time.h> - - -time_t time_from_isodate (char *str); -time_t time_from_start_duration (time_t start, char *duration); -char *isodate_from_time_t (time_t t); -int get_time_t_hour (time_t t); -int isodiff_to_secs (char *str); -char *isodiff_from_secs (int secs); - -time_t time_add_minutes (time_t time, int minutes); -time_t time_add_day (time_t time, int days); -time_t time_add_week (time_t time, int weeks); -time_t time_add_month (time_t time, int months); -time_t time_add_year (time_t time, int years); - - -/* Returns pointer to a statically-allocated buffer with a string of the form - * 3am, 4am, 12pm, 08h, 17h, etc. - * The string is internationalized, hopefully correctly. - */ -char *format_simple_hour (int hour, int use_am_pm); - -/* Returns the number of days in the specified month. Years are full years (starting from year 1). - * Months are in [0, 11]. - */ -int time_days_in_month (int year, int month); - -/* Converts the specified date to a time_t at the start of the specified day. Years are full years - * (starting from year 1). Months are in [0, 11]. Days are 1-based. - */ -time_t time_from_day (int year, int month, int day); - -time_t time_day_hour (time_t t, int hour); - -/* For the functions below, time ranges are considered to contain the start time, but not the end - * time. - */ - -/* These two functions take a time value and return the beginning or end of the corresponding year, - * respectively. - */ -time_t time_year_begin (time_t t); -time_t time_year_end (time_t t); - -/* These two functions take a time value and return the beginning or end of the corresponding month, - * respectively. - */ -time_t time_month_begin (time_t t); -time_t time_month_end (time_t t); - -/* These functions take a time value and return the beginning or end of the corresponding week, - * respectively. This takes into account the global week_starts_on_monday flag. - */ -time_t time_week_begin (time_t t); -time_t time_week_end (time_t t); - -/* These two functions take a time value and return the beginning or end of the corresponding day, - * respectively. - */ -time_t time_day_begin (time_t t); -time_t time_day_end (time_t t); - - -time_t parse_date (char *str); -void print_time_t (time_t t); - - -#endif |