From e40b1868be45996f361fce9c1ea30dacd03306b2 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Fri, 26 Jul 2002 16:32:33 +0000 Subject: new function for adding VTIMEZONE components to a VCALENDAR component. 2002-07-26 Rodrigo Moya * cal-util/cal-util.[ch] (cal_util_add_timezones_from_component): new function for adding VTIMEZONE components to a VCALENDAR component. * gui/e-calendar-table.c (copy_row_cb): added VTIMEZONE components to resulting VCALENDAR top-level component. * gui/e-week-view.c (e_week_view_copy_clipboard): copy to the clipboard a top-level VCALENDAR component, with all the needed VTIMEZONE components. (e_week_view_on_copy): likewise. * gui/e-day-view.c (e_day_view_copy_clipboard): likewise. (e_day_view_on_copy): likewise. svn path=/trunk/; revision=17604 --- calendar/cal-util/cal-util.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ calendar/cal-util/cal-util.h | 2 ++ 2 files changed, 57 insertions(+) (limited to 'calendar/cal-util') diff --git a/calendar/cal-util/cal-util.c b/calendar/cal-util/cal-util.c index 8ba1ff7d63..d4a86e1a8f 100644 --- a/calendar/cal-util/cal-util.c +++ b/calendar/cal-util/cal-util.c @@ -558,3 +558,58 @@ cal_util_expand_uri (char *uri, gboolean tasks) return file_uri; } + +/* callback for icalcomponent_foreach_tzid */ +typedef struct { + icalcomponent *vcal_comp; + CalComponent *comp; +} ForeachTzidData; + +static void +add_timezone_cb (icalparameter *param, void *data) +{ + icaltimezone *tz; + const char *tzid; + icalcomponent *vtz_comp; + ForeachTzidData *f_data = (ForeachTzidData *) data; + + tzid = icalparameter_get_tzid (param); + if (!tzid) + return; + + tz = icalcomponent_get_timezone (f_data->vcal_comp, tzid); + if (tz) + return; + + tz = icalcomponent_get_timezone (cal_component_get_icalcomponent (f_data->comp), + tzid); + if (!tz) { + tz = icaltimezone_get_builtin_timezone_from_tzid (tzid); + if (!tz) + return; + } + + vtz_comp = icaltimezone_get_component (tz); + if (!vtz_comp) + return; + + icalcomponent_add_component (f_data->vcal_comp, + icalcomponent_new_clone (vtz_comp)); +} + +/* Adds VTIMEZONE components to a VCALENDAR for all tzid's + * in the given CalComponent. */ +void +cal_util_add_timezones_from_component (icalcomponent *vcal_comp, + CalComponent *comp) +{ + ForeachTzidData f_data; + + g_return_if_fail (vcal_comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + f_data.vcal_comp = vcal_comp; + f_data.comp = comp; + icalcomponent_foreach_tzid (cal_component_get_icalcomponent (comp), + add_timezone_cb, &f_data); +} diff --git a/calendar/cal-util/cal-util.h b/calendar/cal-util/cal-util.h index d4ccfb5388..e1afc1c3a0 100644 --- a/calendar/cal-util/cal-util.h +++ b/calendar/cal-util/cal-util.h @@ -85,6 +85,8 @@ int cal_util_priority_from_string (const char *string); char *cal_util_expand_uri (char *uri, gboolean tasks); +void cal_util_add_timezones_from_component (icalcomponent *vcal_comp, + CalComponent *comp); END_GNOME_DECLS -- cgit v1.2.3