2001-10-22 Damon Chaplin <damon@ximian.com> * idl/evolution-calendar.idl: added setDefaultTimezone() method. * pcs/cal-backend.c (cal_backend_get_default_timezone): (cal_backend_set_default_timezone): new functions to call class methods. * pcs/cal-backend-file.c: lots of changes to handle the default timezone and use it. * pcs/query.c: use the default timezone. * gui/dialogs/task-details-page.c (date_changed_cb): initialized completed_tt. * gui/dialogs/event-page.c: changed it to handle DATE values. The 'All Day Event' checkbox is only set now when the DTSTART and DTEND are DATE values. * gui/dialogs/comp-editor-util.c (comp_editor_free_dates): free the CalComponentDateTime structs as well. * gui/e-tasks.c: set the default timezone on the server. * gui/tag-calendar.c: * gui/gnome-cal.c: * gui/e-week-view.c: * gui/e-day-view.c: updates to handle DATE values. * gui/e-calendar-table.c (date_compare_cb): updated to use the new ECellDateEditValue values, so it now works. (percent_compare_cb): updated to use GPOINTER_TO_INT values. (e_calendar_table_init): use an ECellPercent for the percent field and an ECellDateEditText for the date fields. * gui/comp-util.c (cal_comp_util_compare_event_timezones): return TRUE if the DTSTART or DTEND is a DATE value. We don't want to show the timezone icons for DATE values. * gui/comp-editor-factory.c (resolve_pending_requests): set the default timezone on the server. * gui/calendar-model.c: major changes to support sorting properly. For date and percent fields we now use subclasses of ECellText, so we don't use a char* as the model value. For the percent field we now use a GINT_TO_POINTER. For the date fields we now use a ECellDateEditValue* as the value. * gui/calendar-config.c (calendar_config_configure_e_cell_date_edit): set the timezone and use_24_hour flags of the new ECellDateEditText. * conduits/todo/todo-conduit.c (pre_sync): * conduits/calendar/calendar-conduit.c (pre_sync): set the default timezone on the server. * cal-util/timeutil.c (time_days_in_month): removed debug message. * cal-util/test-recur.c: try to handle timezones in the iCalendar file properly, and updated to pass default timezone. * cal-util/cal-util.c (cal_util_generate_alarms_for_comp): (cal_util_generate_alarms_for_list): added default timezone argument. * cal-util/cal-recur.c: changed many of the functions to take a default timezone, to use to resolve DATE and floating DATE-TIME values. * cal-client/cal-client.c (cal_client_set_default_timezone): new function to set the default timezone. (cal_client_ensure_timezone_on_server): new function to ensure that a given timezone is on the server. * gui/e-cell-date-edit-text.c: new subclass of ECellText to display and edit a date value. * cal-util/cal-recur.c (cal_obj_byday_expand_monthly): changed week_num to -week_num when calculating the weeks to go back from the end of the month for things like BYDAY=-2WE. Fixes bug #11525. (cal_recur_generate_instances_of_rule): only go up to MAX_YEAR (2037). We can't really handle anything past that anyway. (cal_recur_ensure_rule_end_date): initialize cb_date.end_date to 0, so if the RULE doesn't generate COUNT instances we save 0 as the time_t. svn path=/trunk/; revision=13920
163 lines
4.5 KiB
C
163 lines
4.5 KiB
C
/* Evolution calendar - Utilities for manipulating CalComponent objects
|
||
*
|
||
* Copyright (C) 2000 Ximian, Inc.
|
||
* Copyright (C) 2000 Ximian, Inc.
|
||
*
|
||
* Author: Federico Mena-Quintero <federico@ximian.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.
|
||
*/
|
||
|
||
#ifdef HAVE_CONFIG_H
|
||
#include <config.h>
|
||
#endif
|
||
|
||
#include "comp-util.h"
|
||
|
||
|
||
|
||
/**
|
||
* cal_comp_util_add_exdate:
|
||
* @comp: A calendar component object.
|
||
* @itt: Time for the exception.
|
||
*
|
||
* Adds an exception date to the current list of EXDATE properties in a calendar
|
||
* component object.
|
||
**/
|
||
void
|
||
cal_comp_util_add_exdate (CalComponent *comp, time_t t, icaltimezone *zone)
|
||
{
|
||
GSList *list;
|
||
CalComponentDateTime *cdt;
|
||
|
||
g_return_if_fail (comp != NULL);
|
||
g_return_if_fail (IS_CAL_COMPONENT (comp));
|
||
|
||
cal_component_get_exdate_list (comp, &list);
|
||
|
||
cdt = g_new (CalComponentDateTime, 1);
|
||
cdt->value = g_new (struct icaltimetype, 1);
|
||
*cdt->value = icaltime_from_timet_with_zone (t, FALSE, zone);
|
||
cdt->tzid = g_strdup (icaltimezone_get_tzid (zone));
|
||
|
||
list = g_slist_append (list, cdt);
|
||
cal_component_set_exdate_list (comp, list);
|
||
cal_component_free_exdate_list (list);
|
||
}
|
||
|
||
|
||
|
||
/* Returns TRUE if the TZIDs are equivalent, i.e. both NULL or the same. */
|
||
static gboolean
|
||
cal_component_compare_tzid (const char *tzid1, const char *tzid2)
|
||
{
|
||
gboolean retval = TRUE;
|
||
|
||
if (tzid1) {
|
||
if (!tzid2 || strcmp (tzid1, tzid2))
|
||
retval = FALSE;
|
||
} else {
|
||
if (tzid2)
|
||
retval = FALSE;
|
||
}
|
||
|
||
return retval;
|
||
}
|
||
|
||
/**
|
||
* cal_comp_util_compare_event_timezones:
|
||
* @comp: A calendar component object.
|
||
* @client: A #CalClient.
|
||
*
|
||
* Checks if the component uses the given timezone for both the start and
|
||
* the end time, or if the UTC offsets of the start and end times are the same
|
||
* as in the given zone.
|
||
*
|
||
* Returns: TRUE if the component's start and end time are at the same UTC
|
||
* offset in the given timezone.
|
||
**/
|
||
gboolean
|
||
cal_comp_util_compare_event_timezones (CalComponent *comp,
|
||
CalClient *client,
|
||
icaltimezone *zone)
|
||
{
|
||
CalClientGetStatus status;
|
||
CalComponentDateTime start_datetime, end_datetime;
|
||
const char *tzid;
|
||
gboolean retval = FALSE;
|
||
icaltimezone *start_zone, *end_zone;
|
||
int offset1, offset2;
|
||
|
||
tzid = icaltimezone_get_tzid (zone);
|
||
|
||
cal_component_get_dtstart (comp, &start_datetime);
|
||
cal_component_get_dtend (comp, &end_datetime);
|
||
|
||
/* If either the DTSTART or the DTEND is a DATE value, we return TRUE.
|
||
Maybe if one was a DATE-TIME we should check that, but that should
|
||
not happen often. */
|
||
if (start_datetime.value->is_date || end_datetime.value->is_date) {
|
||
retval = TRUE;
|
||
goto out;
|
||
}
|
||
|
||
/* FIXME: DURATION may be used instead. */
|
||
if (cal_component_compare_tzid (tzid, start_datetime.tzid)
|
||
&& cal_component_compare_tzid (tzid, end_datetime.tzid)) {
|
||
/* If both TZIDs are the same as the given zone's TZID, then
|
||
we know the timezones are the same so we return TRUE. */
|
||
retval = TRUE;
|
||
} else {
|
||
/* If the TZIDs differ, we have to compare the UTC offsets
|
||
of the start and end times, using their own timezones and
|
||
the given timezone. */
|
||
status = cal_client_get_timezone (client,
|
||
start_datetime.tzid,
|
||
&start_zone);
|
||
if (status != CAL_CLIENT_GET_SUCCESS)
|
||
goto out;
|
||
|
||
offset1 = icaltimezone_get_utc_offset (start_zone,
|
||
start_datetime.value,
|
||
NULL);
|
||
offset2 = icaltimezone_get_utc_offset (zone,
|
||
start_datetime.value,
|
||
NULL);
|
||
if (offset1 == offset2) {
|
||
status = cal_client_get_timezone (client,
|
||
end_datetime.tzid,
|
||
&end_zone);
|
||
if (status != CAL_CLIENT_GET_SUCCESS)
|
||
goto out;
|
||
|
||
offset1 = icaltimezone_get_utc_offset (end_zone,
|
||
end_datetime.value,
|
||
NULL);
|
||
offset2 = icaltimezone_get_utc_offset (zone,
|
||
end_datetime.value,
|
||
NULL);
|
||
if (offset1 == offset2)
|
||
retval = TRUE;
|
||
}
|
||
}
|
||
|
||
out:
|
||
|
||
cal_component_free_datetime (&start_datetime);
|
||
cal_component_free_datetime (&end_datetime);
|
||
|
||
return retval;
|
||
}
|