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/ChangeLog | 17 +++++++++++++ calendar/cal-util/cal-util.c | 55 +++++++++++++++++++++++++++++++++++++++++ calendar/cal-util/cal-util.h | 2 ++ calendar/gui/e-calendar-table.c | 3 +++ calendar/gui/e-day-view.c | 32 +++++++++++++++++++++--- calendar/gui/e-week-view.c | 32 +++++++++++++++++++++--- 6 files changed, 133 insertions(+), 8 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index a5c17eecac..f28aa74e6c 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,20 @@ +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. + 2002-07-26 JP Rosevear * gui/comp-editor-factory.c (impl_editExisting): focus the editor 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 diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index f8f5e1568b..f775b68f1a 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -834,6 +834,9 @@ copy_row_cb (int model_row, gpointer data) if (!comp) return; + /* add timezones to the VCALENDAR component */ + cal_util_add_timezones_from_component (cal_table->tmp_vcal, comp); + /* add the new component to the VCALENDAR component */ comp_str = cal_component_get_as_string (comp); child = icalparser_parse_string (comp_str); diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index 378de58323..c73b969731 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -2769,6 +2769,8 @@ e_day_view_copy_clipboard (EDayView *day_view) { EDayViewEvent *event; char *comp_str; + icalcomponent *vcal_comp; + icalcomponent *new_icalcomp; g_return_if_fail (E_IS_DAY_VIEW (day_view)); @@ -2776,11 +2778,21 @@ e_day_view_copy_clipboard (EDayView *day_view) if (event == NULL) return; - comp_str = cal_component_get_as_string (event->comp); + /* create top-level VCALENDAR component and add VTIMEZONE's */ + vcal_comp = cal_util_new_top_level (); + cal_util_add_timezones_from_component (vcal_comp, event->comp); + + new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); + icalcomponent_add_component (vcal_comp, new_icalcomp); + + comp_str = icalcomponent_as_ical_string (vcal_comp); if (day_view->clipboard_selection != NULL) g_free (day_view->clipboard_selection); - day_view->clipboard_selection = comp_str; + day_view->clipboard_selection = g_strdup (comp_str); gtk_selection_owner_set (day_view->invisible, clipboard_atom, GDK_CURRENT_TIME); + + /* free memory */ + icalcomponent_free (vcal_comp); } void @@ -4133,6 +4145,8 @@ e_day_view_on_copy (GtkWidget *widget, gpointer data) EDayView *day_view; EDayViewEvent *event; char *comp_str; + icalcomponent *vcal_comp; + icalcomponent *new_icalcomp; day_view = E_DAY_VIEW (data); @@ -4140,12 +4154,22 @@ e_day_view_on_copy (GtkWidget *widget, gpointer data) if (event == NULL) return; - comp_str = cal_component_get_as_string (event->comp); + /* create top-level VCALENDAR component and add VTIMEZONE's */ + vcal_comp = cal_util_new_top_level (); + cal_util_add_timezones_from_component (vcal_comp, event->comp); + + new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); + icalcomponent_add_component (vcal_comp, new_icalcomp); + + comp_str = icalcomponent_as_ical_string (vcal_comp); if (day_view->clipboard_selection) g_free (day_view->clipboard_selection); - day_view->clipboard_selection = comp_str; + day_view->clipboard_selection = g_strdup (comp_str); gtk_selection_owner_set (day_view->invisible, clipboard_atom, GDK_CURRENT_TIME); + + /* free memory */ + icalcomponent_free (vcal_comp); } static void diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c index 1f6768c4cb..69533969d4 100644 --- a/calendar/gui/e-week-view.c +++ b/calendar/gui/e-week-view.c @@ -1865,6 +1865,8 @@ e_week_view_copy_clipboard (EWeekView *week_view) { EWeekViewEvent *event; char *comp_str; + icalcomponent *vcal_comp; + icalcomponent *new_icalcomp; g_return_if_fail (E_IS_WEEK_VIEW (week_view)); @@ -1873,11 +1875,21 @@ e_week_view_copy_clipboard (EWeekView *week_view) if (event == NULL) return; - comp_str = cal_component_get_as_string (event->comp); + /* create top-level VCALENDAR component and add VTIMEZONE's */ + vcal_comp = cal_util_new_top_level (); + cal_util_add_timezones_from_component (vcal_comp, event->comp); + + new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); + icalcomponent_add_component (vcal_comp, new_icalcomp); + + comp_str = icalcomponent_as_ical_string (vcal_comp); if (week_view->clipboard_selection != NULL) g_free (week_view->clipboard_selection); - week_view->clipboard_selection = comp_str; + week_view->clipboard_selection = g_strdup (comp_str); gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME); + + /* free memory */ + icalcomponent_free (vcal_comp); } void @@ -3994,6 +4006,8 @@ e_week_view_on_copy (GtkWidget *widget, gpointer data) EWeekView *week_view; EWeekViewEvent *event; char *comp_str; + icalcomponent *vcal_comp; + icalcomponent *new_icalcomp; week_view = E_WEEK_VIEW (data); @@ -4003,12 +4017,22 @@ e_week_view_on_copy (GtkWidget *widget, gpointer data) event = &g_array_index (week_view->events, EWeekViewEvent, week_view->popup_event_num); - comp_str = cal_component_get_as_string (event->comp); + /* create top-level VCALENDAR component and add VTIMEZONE's */ + vcal_comp = cal_util_new_top_level (); + cal_util_add_timezones_from_component (vcal_comp, event->comp); + + new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); + icalcomponent_add_component (vcal_comp, new_icalcomp); + + comp_str = icalcomponent_as_ical_string (vcal_comp); if (week_view->clipboard_selection) g_free (week_view->clipboard_selection); - week_view->clipboard_selection = comp_str; + week_view->clipboard_selection = g_strdup (comp_str); gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME); + + /* free memory */ + icalcomponent_free (vcal_comp); } static void -- cgit v1.2.3