JP and Rodrigo, New patch for HEAD attached. Please review it. Thanks! Harry JP Rosevear wrote: On Wed, 2003-11-19 at 06:22, Rodrigo Moya wrote:On Wed, 2003-11-19 at 05:40, Harry Lu wrote:Hi, Per JPR's request, I write this mail to discuss a problem. Here is the problem. The attached Bruins.ics is get from http://www.apple.com/ical/library/. I cut it to 2 events. If I import it into Evolution, since the timezone (US/Eastern) is not included in Evolution's buildin timezone list, though the import is successfu and I can see some black dates from the date calendar at the upper right, I can see nothing from dayview, weekview and month view. I had made a patch based on 1.4 to patch cal_backend_file_update_objects() to change the timezone into local default timezone so that the events can be seen. Rodrigo has approved and I had checked in to 1.4 branch. Now I need to made a patch for HEAD. I think I should patch e_cal_backend_file_create_object() and e_cal_backend_file_modify_object(). Do I need to patch e_cal_backend_file_receive_objects(), too?yes, anytime an event is changed/added, you need to check that. Those 3 functions do what update_objects used to.Is there some way to unify the code for this? Maybe a sanitize_object call or something? -JP |
Index: calendar//ChangeLog =================================================================== RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v retrieving revision 1.24 diff -u -r1.24 ChangeLog --- calendar//ChangeLog 18 Nov 2003 14:57:39 -0000 1.24 +++ calendar//ChangeLog 20 Nov 2003 04:18:59 -0000 @@ -1,3 +1,15 @@ +2003-11-20 Harry Lu <harry lu sun com> + + * backends/file/e-cal-backend-file.c: + (e_cal_backend_file_internal_get_default_timezone): move to the front + to avoid a compile warning. + (e_cal_backend_file_internal_get_timezone): ditto + (sanitize_component): new function. If the component's timezone is not + included in buildin timezone list, convert it to local default timezone. + (e_cal_backend_file_create_object): call sanitize_component. + (e_cal_backend_file_modify_object): ditto. + (e_cal_backend_file_receive_objects): ditto. + 2003-11-18 Rodrigo Moya <rodrigo ximian com> * backends/groupwise/e-gw-connection.h: fixed typo. Index: calendar//backends/file/e-cal-backend-file.c =================================================================== RCS file: /cvs/gnome/evolution-data-server/calendar/backends/file/e-cal-backend-file.c,v retrieving revision 1.3 diff -u -r1.3 e-cal-backend-file.c --- calendar//backends/file/e-cal-backend-file.c 6 Nov 2003 15:50:15 -0000 1.3 +++ calendar//backends/file/e-cal-backend-file.c 20 Nov 2003 04:19:01 -0000 @@ -1485,6 +1485,92 @@ return GNOME_Evolution_Calendar_Success; } +static icaltimezone * +e_cal_backend_file_internal_get_default_timezone (ECalBackend *backend) +{ + ECalBackendFile *cbfile; + ECalBackendFilePrivate *priv; + + cbfile = E_CAL_BACKEND_FILE (backend); + priv = cbfile->priv; + + g_return_val_if_fail (priv->icalcomp != NULL, NULL); + + return priv->default_zone; +} + +static icaltimezone * +e_cal_backend_file_internal_get_timezone (ECalBackend *backend, const char *tzid) +{ + ECalBackendFile *cbfile; + ECalBackendFilePrivate *priv; + icaltimezone *zone; + + cbfile = E_CAL_BACKEND_FILE (backend); + priv = cbfile->priv; + + g_return_val_if_fail (priv->icalcomp != NULL, NULL); + + if (!strcmp (tzid, "UTC")) + zone = icaltimezone_get_utc_timezone (); + else { + zone = icalcomponent_get_timezone (priv->icalcomp, tzid); + if (!zone) + zone = icaltimezone_get_builtin_timezone_from_tzid (tzid); + } + + return zone; +} + +static void +sanitize_component (ECalBackendFile *cbfile, ECalComponent *comp) +{ + ECalComponentDateTime dt; + icaltimezone *zone, *default_zone; + + /* Check dtstart, dtend and due's timezone, and convert it to local + * default timezone if the timezone is not in our builtin timezone + * list */ + e_cal_component_get_dtstart (comp, &dt); + if (dt.value && dt.tzid) { + zone = e_cal_backend_file_internal_get_timezone ((ECalBackend *)cbfile, dt.tzid); + if (!zone) { + default_zone = e_cal_backend_file_internal_get_default_timezone ((ECalBackend *)cbfile); + g_free ((char *)dt.tzid); + dt.tzid = g_strdup (icaltimezone_get_tzid (default_zone)); + e_cal_component_set_dtstart (comp, &dt); + } + } + e_cal_component_free_datetime (&dt); + + e_cal_component_get_dtend (comp, &dt); + if (dt.value && dt.tzid) { + zone = e_cal_backend_file_internal_get_timezone ((ECalBackend *)cbfile, dt.tzid); + if (!zone) { + default_zone = e_cal_backend_file_internal_get_default_timezone ((ECalBackend *)cbfile); + g_free ((char *)dt.tzid); + dt.tzid = g_strdup (icaltimezone_get_tzid (default_zone)); + e_cal_component_set_dtend (comp, &dt); + } + } + e_cal_component_free_datetime (&dt); + + e_cal_component_get_due (comp, &dt); + if (dt.value && dt.tzid) { + zone = e_cal_backend_file_internal_get_timezone ((ECalBackend *)cbfile, dt.tzid); + if (!zone) { + default_zone = e_cal_backend_file_internal_get_default_timezone ((ECalBackend *)cbfile); + g_free ((char *)dt.tzid); + dt.tzid = g_strdup (icaltimezone_get_tzid (default_zone)); + e_cal_component_set_due (comp, &dt); + } + } + e_cal_component_free_datetime (&dt); + e_cal_component_abort_sequence (comp); + +} + + static ECalBackendSyncStatus e_cal_backend_file_create_object (ECalBackendSync *backend, EDataCal *cal, const char *calobj, char **uid) { @@ -1531,6 +1617,9 @@ e_cal_component_set_created (comp, ¤t); e_cal_component_set_last_modified (comp, ¤t); + /* sanitize the component*/ + sanitize_component (cbfile, comp); + /* Add the object */ add_component (cbfile, comp, TRUE); @@ -1592,6 +1681,9 @@ current = icaltime_from_timet (time (NULL), 0); e_cal_component_set_last_modified (comp, ¤t); + /* sanitize the component*/ + sanitize_component (cbfile, comp); + /* handle mod_type */ switch (mod) { case CALOBJ_MOD_THIS : @@ -1853,6 +1945,8 @@ icalproperty_method method; icalcomponent *subcomp; GList *comps, *l; + ECalComponent *comp; + struct icaltimetype current; ECalBackendFileTzidData tzdata; ECalBackendSyncStatus status = GNOME_Evolution_Calendar_Success; @@ -1929,7 +2023,19 @@ /* Now we manipulate the components we care about */ for (l = comps; l; l = l->next) { subcomp = l->data; - + + /* Create the cal component */ + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent (comp, subcomp); + + /* Set the created and last modified times on the component */ + current = icaltime_from_timet (time (NULL), 0); + e_cal_component_set_created (comp, ¤t); + e_cal_component_set_last_modified (comp, ¤t); + + /* sanitize the component*/ + sanitize_component (cbfile, comp); + switch (method) { case ICAL_METHOD_PUBLISH: case ICAL_METHOD_REQUEST: @@ -1981,43 +2087,6 @@ /* FIXME Put in a util routine to send stuff via email */ return GNOME_Evolution_Calendar_Success; -} - -static icaltimezone * -e_cal_backend_file_internal_get_default_timezone (ECalBackend *backend) -{ - ECalBackendFile *cbfile; - ECalBackendFilePrivate *priv; - - cbfile = E_CAL_BACKEND_FILE (backend); - priv = cbfile->priv; - - g_return_val_if_fail (priv->icalcomp != NULL, NULL); - - return priv->default_zone; -} - -static icaltimezone * -e_cal_backend_file_internal_get_timezone (ECalBackend *backend, const char *tzid) -{ - ECalBackendFile *cbfile; - ECalBackendFilePrivate *priv; - icaltimezone *zone; - - cbfile = E_CAL_BACKEND_FILE (backend); - priv = cbfile->priv; - - g_return_val_if_fail (priv->icalcomp != NULL, NULL); - - if (!strcmp (tzid, "UTC")) - zone = icaltimezone_get_utc_timezone (); - else { - zone = icalcomponent_get_timezone (priv->icalcomp, tzid); - if (!zone) - zone = icaltimezone_get_builtin_timezone_from_tzid (tzid); - } - - return zone; } /* Object initialization function for the file backend */