aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs/cal-backend-file.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@ximian.com>2001-10-23 08:23:42 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-10-23 08:23:42 +0800
commit04bda8ad1e0cb676d711dbf0f22ff9f4fb615891 (patch)
tree7f1ff1303c52e9b48a0006c500b204902b9d77c5 /calendar/pcs/cal-backend-file.c
parent68de308a89a844dcc579e1d9f24d7813d645c956 (diff)
downloadgsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.gz
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.zst
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.zip
added setDefaultTimezone() method.
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
Diffstat (limited to 'calendar/pcs/cal-backend-file.c')
-rw-r--r--calendar/pcs/cal-backend-file.c259
1 files changed, 171 insertions, 88 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index 471dba3fa2..adf323023a 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -79,6 +79,10 @@ struct _CalBackendFilePrivate {
/* Idle handler for saving the calendar when it is dirty */
guint idle_id;
+
+ /* The calendar's default timezone, used for resolving DATE and
+ floating DATE-TIME values. */
+ icaltimezone *default_zone;
};
@@ -118,6 +122,9 @@ static gboolean cal_backend_file_update_objects (CalBackend *backend, const char
static gboolean cal_backend_file_remove_object (CalBackend *backend, const char *uid);
static icaltimezone* cal_backend_file_get_timezone (CalBackend *backend, const char *tzid);
+static icaltimezone* cal_backend_file_get_default_timezone (CalBackend *backend);
+static gboolean cal_backend_file_set_default_timezone (CalBackend *backend,
+ const char *tzid);
static void notify_categories_changed (CalBackendFile *cbfile);
@@ -190,6 +197,8 @@ cal_backend_file_class_init (CalBackendFileClass *class)
backend_class->remove_object = cal_backend_file_remove_object;
backend_class->get_timezone = cal_backend_file_get_timezone;
+ backend_class->get_default_timezone = cal_backend_file_get_default_timezone;
+ backend_class->set_default_timezone = cal_backend_file_set_default_timezone;
}
static Bonobo_ConfigDatabase
@@ -235,6 +244,9 @@ cal_backend_file_init (CalBackendFile *cbfile)
priv->categories = g_hash_table_new (g_str_hash, g_str_equal);
priv->removed_categories = g_hash_table_new (g_str_hash, g_str_equal);
+ /* The timezone defaults to UTC. */
+ priv->default_zone = icaltimezone_get_utc_timezone ();
+
priv->db = load_db ();
gtk_signal_connect (GTK_OBJECT (cbfile), "cal_added",
@@ -1015,7 +1027,7 @@ cal_backend_file_get_timezone_object (CalBackend *backend, const char *tzid)
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
- icaltimezone *icaltz;
+ icaltimezone *zone;
icalcomponent *icalcomp;
char *ical_string;
@@ -1027,11 +1039,11 @@ cal_backend_file_get_timezone_object (CalBackend *backend, const char *tzid)
g_return_val_if_fail (priv->icalcomp != NULL, NULL);
g_assert (priv->comp_uid_hash != NULL);
- icaltz = icalcomponent_get_timezone (priv->icalcomp, tzid);
- if (!icaltz)
+ zone = icalcomponent_get_timezone (priv->icalcomp, tzid);
+ if (!zone)
return NULL;
- icalcomp = icaltimezone_get_component (icaltz);
+ icalcomp = icaltimezone_get_component (zone);
if (!icalcomp)
return NULL;
@@ -1131,7 +1143,7 @@ add_instance (CalComponent *comp, time_t start, time_t end, gpointer data)
* within a specific time range.
*/
static void
-get_instances_in_range (GHashTable *uid_hash, GList *components, time_t start, time_t end)
+get_instances_in_range (GHashTable *uid_hash, GList *components, time_t start, time_t end, icaltimezone *default_zone)
{
GList *l;
@@ -1147,7 +1159,7 @@ get_instances_in_range (GHashTable *uid_hash, GList *components, time_t start, t
vcalendar_comp = icalcomponent_get_parent (icalcomp);
g_assert (vcalendar_comp != NULL);
- cal_recur_generate_instances (comp, start, end, add_instance, uid_hash, resolve_tzid, vcalendar_comp);
+ cal_recur_generate_instances (comp, start, end, add_instance, uid_hash, resolve_tzid, vcalendar_comp, default_zone);
}
}
@@ -1188,13 +1200,16 @@ cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
if (type & CALOBJ_TYPE_EVENT)
- get_instances_in_range (uid_hash, priv->events, start, end);
+ get_instances_in_range (uid_hash, priv->events, start, end,
+ priv->default_zone);
if (type & CALOBJ_TYPE_TODO)
- get_instances_in_range (uid_hash, priv->todos, start, end);
+ get_instances_in_range (uid_hash, priv->todos, start, end,
+ priv->default_zone);
if (type & CALOBJ_TYPE_JOURNAL)
- get_instances_in_range (uid_hash, priv->journals, start, end);
+ get_instances_in_range (uid_hash, priv->journals, start, end,
+ priv->default_zone);
event_list = NULL;
g_hash_table_foreach (uid_hash, add_uid_to_list, &event_list);
@@ -1232,6 +1247,7 @@ create_user_free_busy (CalBackendFile *cbfile, const char *address, const char *
icalcomponent_set_dtend (vfb, icaltime_from_timet (end, 1));
/* add all objects in the given interval */
+
uids = cal_backend_get_objects_in_range (CAL_BACKEND (cbfile),
CALOBJ_TYPE_ANY, start, end);
for (l = uids; l != NULL; l = l->next) {
@@ -1466,7 +1482,8 @@ cal_backend_file_get_changes (CalBackend *backend, CalObjType type, const char *
/* Get_alarms_in_range handler for the file backend */
static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *
-cal_backend_file_get_alarms_in_range (CalBackend *backend, time_t start, time_t end)
+cal_backend_file_get_alarms_in_range (CalBackend *backend,
+ time_t start, time_t end)
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
@@ -1491,10 +1508,12 @@ cal_backend_file_get_alarms_in_range (CalBackend *backend, time_t start, time_t
n_comp_alarms += cal_util_generate_alarms_for_list (priv->events, start, end,
&comp_alarms, resolve_tzid,
- priv->icalcomp);
+ priv->icalcomp,
+ priv->default_zone);
n_comp_alarms += cal_util_generate_alarms_for_list (priv->todos, start, end,
&comp_alarms, resolve_tzid,
- priv->icalcomp);
+ priv->icalcomp,
+ priv->default_zone);
seq = GNOME_Evolution_Calendar_CalComponentAlarmsSeq__alloc ();
CORBA_sequence_set_release (seq, TRUE);
@@ -1525,7 +1544,8 @@ cal_backend_file_get_alarms_in_range (CalBackend *backend, time_t start, time_t
/* Get_alarms_for_object handler for the file backend */
static GNOME_Evolution_Calendar_CalComponentAlarms *
cal_backend_file_get_alarms_for_object (CalBackend *backend, const char *uid,
- time_t start, time_t end, gboolean *object_found)
+ time_t start, time_t end,
+ gboolean *object_found)
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
@@ -1558,7 +1578,7 @@ cal_backend_file_get_alarms_for_object (CalBackend *backend, const char *uid,
corba_alarms->calobj = CORBA_string_dup (comp_str);
g_free (comp_str);
- alarms = cal_util_generate_alarms_for_comp (comp, start, end, resolve_tzid, priv->icalcomp);
+ alarms = cal_util_generate_alarms_for_comp (comp, start, end, resolve_tzid, priv->icalcomp, priv->default_zone);
if (alarms) {
cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms, alarms->alarms);
cal_component_alarms_free (alarms);
@@ -1632,6 +1652,48 @@ clean_removed_categories (CalBackendFile *cbfile)
NULL);
}
+
+/* Creates a CalComponent for the given icalcomponent and adds it to our
+ cache. Note that the icalcomponent is not added to the toplevel
+ icalcomponent here. That needs to be done elsewhere. It returns the uid
+ of the added component, or NULL if it failed. */
+static const char*
+cal_backend_file_update_object (CalBackendFile *cbfile,
+ icalcomponent *icalcomp)
+{
+ CalComponent *old_comp;
+ CalComponent *comp;
+ const char *comp_uid;
+
+ /* Create a CalComponent wrapper for the icalcomponent. */
+ comp = cal_component_new ();
+ if (!cal_component_set_icalcomponent (comp, icalcomp)) {
+ gtk_object_unref (GTK_OBJECT (comp));
+ return NULL;
+ }
+
+ /* Get the UID, and check it isn't empty. */
+ cal_component_get_uid (comp, &comp_uid);
+ if (!comp_uid || !comp_uid[0]) {
+ gtk_object_unref (GTK_OBJECT (comp));
+ return NULL;
+ }
+
+ /* Remove any old version of the component. */
+ old_comp = lookup_component (cbfile, comp_uid);
+ if (old_comp)
+ remove_component (cbfile, old_comp);
+
+ /* Now add the component to our local cache, but we pass FALSE as
+ the last argument, since the libical component is assumed to have
+ been added already. */
+ add_component (cbfile, comp, FALSE);
+
+ return comp_uid;
+}
+
+
+
/* Update_objects handler for the file backend. */
static gboolean
cal_backend_file_update_objects (CalBackend *backend, const char *calobj)
@@ -1640,10 +1702,10 @@ cal_backend_file_update_objects (CalBackend *backend, const char *calobj)
CalBackendFilePrivate *priv;
icalcomponent *toplevel_comp, *icalcomp = NULL;
icalcomponent_kind kind;
- CalComponent *old_comp;
- CalComponent *comp;
- const char *comp_uid;
int old_n_categories, new_n_categories;
+ icalcomponent *subcomp;
+ gboolean retval = TRUE;
+ GList *comp_uid_list = NULL, *elem;
cbfile = CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
@@ -1661,62 +1723,20 @@ cal_backend_file_update_objects (CalBackend *backend, const char *calobj)
kind = icalcomponent_isa (toplevel_comp);
- if (kind == ICAL_VCALENDAR_COMPONENT) {
- int num_found = 0;
- icalcomponent_kind child_kind;
- icalcomponent *subcomp;
-
- /* We have a VCALENDAR containing the VEVENT/VTODO and the
- related timezone data, so we have to step through it to
- find the actual VEVENT/VTODO component. */
- subcomp = icalcomponent_get_first_component (toplevel_comp,
- ICAL_ANY_COMPONENT);
- while (subcomp) {
- child_kind = icalcomponent_isa (subcomp);
- if (child_kind == ICAL_VEVENT_COMPONENT
- || child_kind == ICAL_VTODO_COMPONENT
- || child_kind == ICAL_VJOURNAL_COMPONENT) {
- icalcomp = subcomp;
- num_found++;
- }
- subcomp = icalcomponent_get_next_component (toplevel_comp,
- ICAL_ANY_COMPONENT);
- }
-
- /* If we didn't find exactly 1 VEVENT/VTODO it is an error. */
- if (num_found != 1) {
- icalcomponent_free (toplevel_comp);
- return FALSE;
- }
-
- } else if (kind == ICAL_VEVENT_COMPONENT
- || kind == ICAL_VTODO_COMPONENT
- || kind == ICAL_VJOURNAL_COMPONENT) {
+ if (kind == ICAL_VEVENT_COMPONENT
+ || kind == ICAL_VTODO_COMPONENT
+ || kind == ICAL_VJOURNAL_COMPONENT) {
+ /* Create a temporary toplevel component and put the VEVENT
+ or VTODO in it, to simplify the code below. */
icalcomp = toplevel_comp;
- } else {
+ toplevel_comp = cal_util_new_top_level ();
+ icalcomponent_add_component (toplevel_comp, icalcomp);
+ } else if (kind != ICAL_VCALENDAR_COMPONENT) {
/* We don't support this type of component */
icalcomponent_free (toplevel_comp);
return FALSE;
}
- comp = cal_component_new ();
- if (!cal_component_set_icalcomponent (comp, icalcomp)) {
- gtk_object_unref (GTK_OBJECT (comp));
- icalcomponent_free (toplevel_comp);
- return FALSE;
- }
-
- /* Get the UID, and check it isn't empty. */
-
- cal_component_get_uid (comp, &comp_uid);
-
- if (!comp_uid || !comp_uid[0]) {
- gtk_object_unref (GTK_OBJECT (comp));
- if (kind == ICAL_VCALENDAR_COMPONENT)
- icalcomponent_free (toplevel_comp);
- return FALSE;
- }
-
/* The list of removed categories must be empty because we are about to
* start a new scanning process.
*/
@@ -1724,32 +1744,54 @@ cal_backend_file_update_objects (CalBackend *backend, const char *calobj)
old_n_categories = g_hash_table_size (priv->categories);
- /* Update the component */
-
- old_comp = lookup_component (cbfile, comp_uid);
-
- if (old_comp)
- remove_component (cbfile, old_comp);
-
- if (kind == ICAL_VCALENDAR_COMPONENT) {
- /* If we have a VCALENDAR component with child VTIMEZONEs and
- the VEVENT/VTODO, we have to merge it into the existing
- VCALENDAR, resolving any conflicting TZIDs. */
- icalcomponent_merge_component (priv->icalcomp, toplevel_comp);
-
- /* Now we add the component to our local cache, but we pass
- FALSE as the last argument, since we have already added
- the libical component when merging above.*/
- add_component (cbfile, comp, FALSE);
- } else {
- add_component (cbfile, comp, TRUE);
+ /* Step throught the VEVENT/VTODOs being added, create CalComponents
+ for them, and add them to our cache. */
+ subcomp = icalcomponent_get_first_component (toplevel_comp,
+ ICAL_ANY_COMPONENT);
+ while (subcomp) {
+ /* We ignore anything except VEVENT, VTODO and VJOURNAL
+ components. */
+ icalcomponent_kind child_kind = icalcomponent_isa (icalcomp);
+ if (child_kind == ICAL_VEVENT_COMPONENT
+ || child_kind == ICAL_VTODO_COMPONENT
+ || child_kind == ICAL_VJOURNAL_COMPONENT) {
+ const char *comp_uid;
+
+ comp_uid = cal_backend_file_update_object (cbfile,
+ icalcomp);
+ if (comp_uid) {
+ /* We add a copy of the UID to a list, so we
+ can emit notification signals later. We do
+ a g_strdup() in case any of the components
+ get removed while we are emitting
+ notification signals. */
+ comp_uid_list = g_list_prepend (comp_uid_list,
+ g_strdup (comp_uid));
+ } else {
+ retval = FALSE;
+ }
+ }
+ subcomp = icalcomponent_get_next_component (toplevel_comp,
+ ICAL_ANY_COMPONENT);
}
+ /* Merge the iCalendar components with our existing VCALENDAR,
+ resolving any conflicting TZIDs. */
+ icalcomponent_merge_component (priv->icalcomp, toplevel_comp);
+
new_n_categories = g_hash_table_size (priv->categories);
mark_dirty (cbfile);
- notify_update (cbfile, comp_uid);
+ /* Now emit notification signals for all of the added components.
+ We do this after adding them all to make sure the calendar is in a
+ stable state before emitting signals. */
+ for (elem = comp_uid_list; elem; elem = elem->next) {
+ char *comp_uid = elem->data;
+ notify_update (cbfile, comp_uid);
+ g_free (comp_uid);
+ }
+ g_list_free (comp_uid_list);
if (old_n_categories != new_n_categories ||
g_hash_table_size (priv->removed_categories) != 0) {
@@ -1757,9 +1799,10 @@ cal_backend_file_update_objects (CalBackend *backend, const char *calobj)
notify_categories_changed (cbfile);
}
- return TRUE;
+ return retval;
}
+
/* Remove_object handler for the file backend */
static gboolean
cal_backend_file_remove_object (CalBackend *backend, const char *uid)
@@ -1816,3 +1859,43 @@ cal_backend_file_get_timezone (CalBackend *backend, const char *tzid)
return icalcomponent_get_timezone (priv->icalcomp, tzid);
}
+
+static icaltimezone*
+cal_backend_file_get_default_timezone (CalBackend *backend)
+{
+ CalBackendFile *cbfile;
+ CalBackendFilePrivate *priv;
+
+ cbfile = CAL_BACKEND_FILE (backend);
+ priv = cbfile->priv;
+
+ g_return_val_if_fail (priv->icalcomp != NULL, NULL);
+
+ return priv->default_zone;
+}
+
+
+static gboolean
+cal_backend_file_set_default_timezone (CalBackend *backend,
+ const char *tzid)
+{
+ CalBackendFile *cbfile;
+ CalBackendFilePrivate *priv;
+ icaltimezone *zone;
+
+ cbfile = CAL_BACKEND_FILE (backend);
+ priv = cbfile->priv;
+
+ g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
+
+ /* Look up the VTIMEZONE in our icalcomponent. */
+ zone = icalcomponent_get_timezone (priv->icalcomp, tzid);
+ if (!zone)
+ return FALSE;
+
+ /* Set the default timezone to it. */
+ priv->default_zone = zone;
+
+ return TRUE;
+}
+