diff options
author | Damon Chaplin <damon@ximian.com> | 2001-10-23 08:23:42 +0800 |
---|---|---|
committer | Damon Chaplin <damon@src.gnome.org> | 2001-10-23 08:23:42 +0800 |
commit | 04bda8ad1e0cb676d711dbf0f22ff9f4fb615891 (patch) | |
tree | 7f1ff1303c52e9b48a0006c500b204902b9d77c5 /calendar/cal-client | |
parent | 68de308a89a844dcc579e1d9f24d7813d645c956 (diff) | |
download | gsoc2013-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/cal-client')
-rw-r--r-- | calendar/cal-client/cal-client.c | 131 | ||||
-rw-r--r-- | calendar/cal-client/cal-client.h | 6 |
2 files changed, 136 insertions, 1 deletions
diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index f8ce2ff71b..79bfae2b1a 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -63,6 +63,10 @@ struct _CalClientPrivate { /* A cache of timezones retrieved from the server, to avoid getting them repeatedly for each get_object() call. */ GHashTable *timezones; + + /* The default timezone to use to resolve DATE and floating DATE-TIME + values. */ + icaltimezone *default_zone; }; @@ -215,6 +219,7 @@ cal_client_init (CalClient *client) priv->uri = NULL; priv->factories = NULL; priv->timezones = g_hash_table_new (g_str_hash, g_str_equal); + priv->default_zone = icaltimezone_get_utc_timezone (); /* create the WombatClient */ priv->w_client = wombat_client_new ( @@ -1714,7 +1719,8 @@ cal_client_generate_instances (CalClient *client, CalObjType type, comp = l->data; cal_recur_generate_instances (comp, start, end, add_instance, &instances, - cal_client_resolve_tzid_cb, client); + cal_client_resolve_tzid_cb, client, + priv->default_zone); gtk_object_unref (GTK_OBJECT (comp)); } @@ -2285,3 +2291,126 @@ cal_client_get_query (CalClient *client, const char *sexp) return cal_query_new (priv->cal, sexp); } + + +/* This ensures that the given timezone is on the server. We use this to pass + the default timezone to the server, so it can resolve DATE and floating + DATE-TIME values into specific times. (Most of our IDL interface uses + time_t values to pass specific times from the server to the client.) */ +static gboolean +cal_client_ensure_timezone_on_server (CalClient *client, icaltimezone *zone) +{ + CalClientPrivate *priv; + char *tzid, *obj_string; + icaltimezone *tmp_zone; + GString *vcal_string; + gboolean retval = FALSE; + icalcomponent *vtimezone_comp; + char *vtimezone_as_string; + CORBA_Environment ev; + + priv = client->priv; + + /* If the zone is NULL or UTC we don't need to do anything. */ + if (!zone) + return TRUE; + + tzid = icaltimezone_get_tzid (zone); + + if (!strcmp (tzid, "UTC")) + return TRUE; + + /* See if we already have it in the cache. If we do, it must be on + the server already. */ + tmp_zone = g_hash_table_lookup (priv->timezones, tzid); + if (tmp_zone) + return TRUE; + + /* Now we have to send it to the server, in case it doesn't already + have it. */ + + vcal_string = g_string_new (NULL); + g_string_append (vcal_string, + "BEGIN:VCALENDAR\n" + "PRODID:-//Ximian//NONSGML Evolution Calendar//EN\n" + "VERSION:2.0\n"); + + /* Convert the timezone to a string and add it. */ + vtimezone_comp = icaltimezone_get_component (zone); + if (!vtimezone_comp) { + g_string_free (vcal_string, TRUE); + return FALSE; + } + + /* We don't need to free this string as libical owns it. */ + vtimezone_as_string = icalcomponent_as_ical_string (vtimezone_comp); + g_string_append (vcal_string, vtimezone_as_string); + + g_string_append (vcal_string, "END:VCALENDAR\n"); + + obj_string = vcal_string->str; + g_string_free (vcal_string, FALSE); + + CORBA_exception_init (&ev); + GNOME_Evolution_Calendar_Cal_updateObjects (priv->cal, obj_string, &ev); + g_free (obj_string); + + if (BONOBO_USER_EX (&ev, ex_GNOME_Evolution_Calendar_Cal_InvalidObject)) + goto out; + else if (BONOBO_EX (&ev)) { + g_message ("cal_client_ensure_timezone_on_server(): could not add the timezone to the server"); + goto out; + } + + retval = TRUE; + + out: + CORBA_exception_free (&ev); + return retval; +} + + +gboolean +cal_client_set_default_timezone (CalClient *client, icaltimezone *zone) +{ + CalClientPrivate *priv; + gboolean retval = FALSE; + CORBA_Environment ev; + const char *tzid; + + g_return_val_if_fail (client != NULL, FALSE); + g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); + g_return_val_if_fail (zone != NULL, FALSE); + + priv = client->priv; + + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, + FALSE); + + /* Make sure the server has the VTIMEZONE data. */ + if (!cal_client_ensure_timezone_on_server (client, zone)) + return FALSE; + + /* Now set the default timezone on the server. */ + CORBA_exception_init (&ev); + tzid = icaltimezone_get_tzid (zone); + GNOME_Evolution_Calendar_Cal_setDefaultTimezone (priv->cal, + (char *) tzid, &ev); + + if (BONOBO_USER_EX (&ev, ex_GNOME_Evolution_Calendar_Cal_NotFound)) + goto out; + else if (BONOBO_EX (&ev)) { + g_message ("cal_client_set_default_timezone(): could not set the default timezone"); + goto out; + } + + retval = TRUE; + + priv->default_zone = zone; + + out: + + CORBA_exception_free (&ev); + return retval; +} + diff --git a/calendar/cal-client/cal-client.h b/calendar/cal-client/cal-client.h index 10614ef83f..36ff410fe1 100644 --- a/calendar/cal-client/cal-client.h +++ b/calendar/cal-client/cal-client.h @@ -108,6 +108,12 @@ CalClient *cal_client_new (void); void cal_client_set_auth_func (CalClient *client, CalClientAuthFunc func, gpointer data); +/* Sets the default timezone to use to resolve DATE and floating DATE-TIME + values. This will typically be from the user's timezone setting. Call this + before using any other functions. It will pass the default timezone on to + the server. Returns TRUE on success. */ +gboolean cal_client_set_default_timezone (CalClient *client, icaltimezone *zone); + gboolean cal_client_open_calendar (CalClient *client, const char *str_uri, gboolean only_if_exists); GList *cal_client_uri_list (CalClient *client, CalMode mode); |