[evolution-ews] evolution-ews: fix timezone issue on copying from calendars



commit ff2f4340c2da8f2b7e49f5e9a91bc006e711c5cc
Author: James Bottomley <JBottomley Parallels com>
Date:   Sun Aug 7 09:20:18 2011 -0500

    evolution-ews: fix timezone issue on copying from calendars
    
    Currently, when you copy between calendars, it's hit or miss whether
    the appointment copies to the correct time.  The issue is whether the
    icaltimezone gets resolved or not.  Invariably, if the tzid is
    non-standard, it doesn't.
    
    The fix is to always resolve the tzid to a vtimezone component in the
    current calendar and append that to the icalcomponent.  The fix
    depends on the fact that the resolution of the tzid is in the current
    calendar, which depends on fixing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655843
    
    Signed-off-by: James Bottomley <JBottomley Parallels com>

 src/calendar/e-cal-backend-ews.c |   44 ++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index ee4e4f4..2ce4c80 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -1450,6 +1450,33 @@ ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 	g_free(create_data);
 }
 
+struct TzidCbData {
+	icalcomponent *comp;
+	ECalBackendEws *cbews;
+};
+
+static void tzid_cb(icalparameter *param, void *data)
+{
+	struct TzidCbData *cbd = data;
+	const gchar *tzid;
+	icaltimezone *zone;
+	icalcomponent *new_comp;
+
+	tzid = icalparameter_get_tzid (param);
+	if (!tzid)
+		return;
+
+	zone = resolve_tzid(tzid, cbd->cbews);
+	if (!zone)
+		return;
+
+	new_comp = icaltimezone_get_component(zone);
+	if (!new_comp)
+		return;
+
+	icalcomponent_add_component(cbd->comp, new_comp);
+}
+
 static void
 e_cal_backend_ews_create_object(ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *calobj)
 {
@@ -1463,6 +1490,7 @@ e_cal_backend_ews_create_object(ECalBackend *backend, EDataCal *cal, EServerMeth
 	GError *error = NULL;
 	GCancellable *cancellable = NULL;
 	const char *send_meeting_invitations;
+	struct TzidCbData cbd;
 
 	/* sanity check */
 	e_data_cal_error_if_fail(E_IS_CAL_BACKEND_EWS(backend), InvalidArg);
@@ -1480,7 +1508,12 @@ e_cal_backend_ews_create_object(ECalBackend *backend, EDataCal *cal, EServerMeth
 	}
 
 	/* parse ical data */
-	icalcomp = icalparser_parse_string(calobj);
+	comp =  e_cal_component_new_from_string (calobj);
+	if (comp == NULL) {
+		g_propagate_error (&error, EDC_ERROR (InvalidObject));
+		return;
+	}
+	icalcomp = e_cal_component_get_icalcomponent(comp);
 
 	/* make sure data was parsed properly */
 	if (!icalcomp) {
@@ -1495,10 +1528,13 @@ e_cal_backend_ews_create_object(ECalBackend *backend, EDataCal *cal, EServerMeth
 		goto exit;
 	}
 
-	/* prepare new calender component */
-	comp = e_cal_component_new();
-	e_cal_component_set_icalcomponent(comp, icalcomp);
+	/* pick all the tzids out of the component and resolve
+	 * them using the vtimezones in the current calendar */
+	cbd.cbews = cbews;
+	cbd.comp = icalcomp;
+	icalcomponent_foreach_tzid(icalcomp, tzid_cb, &cbd);
 
+	/* prepare new calender component */
 	current = icaltime_current_time_with_zone(icaltimezone_get_utc_timezone());
 	e_cal_component_set_created(comp, &current);
 	e_cal_component_set_last_modified(comp, &current);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]