aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/gui/e-cal-model-calendar.c54
-rw-r--r--calendar/gui/e-cal-model-tasks.c54
-rw-r--r--calendar/gui/e-cal-model.c77
-rw-r--r--calendar/gui/e-cal-model.h7
4 files changed, 72 insertions, 120 deletions
diff --git a/calendar/gui/e-cal-model-calendar.c b/calendar/gui/e-cal-model-calendar.c
index 9f94a601c1..6df5588dae 100644
--- a/calendar/gui/e-cal-model-calendar.c
+++ b/calendar/gui/e-cal-model-calendar.c
@@ -224,55 +224,9 @@ ecmc_value_at (ETableModel *etm, gint col, gint row)
}
static void
-set_dtend (ECalModelComponent *comp_data, gconstpointer value)
+set_dtend (ECalModel* model, ECalModelComponent *comp_data, gconstpointer value)
{
- ECellDateEditValue *dv = (ECellDateEditValue *) value;
- icalproperty *prop;
- icalparameter *param;
- const gchar *tzid;
-
- prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTEND_PROPERTY);
- if (prop)
- param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
- else
- param = NULL;
-
- /* If we are setting the property to NULL (i.e. removing it), then
- we remove it if it exists. */
- if (!dv) {
- if (prop) {
- icalcomponent_remove_property (comp_data->icalcomp, prop);
- icalproperty_free (prop);
- }
-
- return;
- }
-
- /* If the TZID is set to "UTC", we set the is_utc flag. */
- tzid = dv->zone ? icaltimezone_get_tzid (dv->zone) : "UTC";
- if (tzid && !strcmp (tzid, "UTC"))
- dv->tt.is_utc = 1;
- else
- dv->tt.is_utc = 0;
-
- if (prop) {
- icalproperty_set_dtend (prop, dv->tt);
- } else {
- prop = icalproperty_new_dtend (dv->tt);
- icalcomponent_add_property (comp_data->icalcomp, prop);
- }
-
- /* If the TZID is set to "UTC", we don't want to save the TZID. */
- if (tzid && strcmp (tzid, "UTC")) {
- if (param) {
- icalparameter_set_tzid (param, (gchar *) tzid);
- } else {
- param = icalparameter_new_tzid ((gchar *) tzid);
- icalproperty_add_parameter (prop, param);
- }
- } else if (param) {
- icalproperty_remove_parameter (prop, ICAL_TZID_PARAMETER);
- }
+ e_cal_model_update_comp_time (model, comp_data, value, ICAL_DTEND_PROPERTY, icalproperty_set_dtend, icalproperty_new_dtend);
}
static void
@@ -371,7 +325,7 @@ ecmc_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value)
switch (col) {
case E_CAL_MODEL_CALENDAR_FIELD_DTEND :
- set_dtend (comp_data, value);
+ set_dtend ((ECalModel *)model, comp_data, value);
break;
case E_CAL_MODEL_CALENDAR_FIELD_LOCATION :
set_location (comp_data, value);
@@ -559,7 +513,7 @@ ecmc_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
g_return_if_fail (comp_data != NULL);
g_return_if_fail (E_IS_TABLE_MODEL (source_model));
- set_dtend (comp_data,
+ set_dtend (model, comp_data,
e_table_model_value_at (source_model, E_CAL_MODEL_CALENDAR_FIELD_DTEND, row));
set_location (comp_data,
e_table_model_value_at (source_model, E_CAL_MODEL_CALENDAR_FIELD_LOCATION, row));
diff --git a/calendar/gui/e-cal-model-tasks.c b/calendar/gui/e-cal-model-tasks.c
index a56361905f..f189ac27db 100644
--- a/calendar/gui/e-cal-model-tasks.c
+++ b/calendar/gui/e-cal-model-tasks.c
@@ -664,55 +664,9 @@ set_complete (ECalModelComponent *comp_data, gconstpointer value)
}
static void
-set_due (ECalModelComponent *comp_data, gconstpointer value)
+set_due (ECalModel* model, ECalModelComponent *comp_data, gconstpointer value)
{
- ECellDateEditValue *dv = (ECellDateEditValue *) value;
- icalproperty *prop;
- icalparameter *param;
- const gchar *tzid;
-
- prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DUE_PROPERTY);
- if (prop)
- param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
- else
- param = NULL;
-
- /* If we are setting the property to NULL (i.e. removing it), then
- we remove it if it exists. */
- if (!dv) {
- if (prop) {
- icalcomponent_remove_property (comp_data->icalcomp, prop);
- icalproperty_free (prop);
- }
-
- return;
- }
-
- /* If the TZID is set to "UTC", we set the is_utc flag. */
- tzid = dv->zone ? icaltimezone_get_tzid (dv->zone) : "UTC";
- if (tzid && !strcmp (tzid, "UTC"))
- dv->tt.is_utc = 1;
- else
- dv->tt.is_utc = 0;
-
- if (prop) {
- icalproperty_set_due (prop, dv->tt);
- } else {
- prop = icalproperty_new_due (dv->tt);
- icalcomponent_add_property (comp_data->icalcomp, prop);
- }
-
- /* If the TZID is set to "UTC", we don't want to save the TZID. */
- if (tzid && strcmp (tzid, "UTC")) {
- if (param) {
- icalparameter_set_tzid (param, (gchar *) tzid);
- } else {
- param = icalparameter_new_tzid ((gchar *) tzid);
- icalproperty_add_parameter (prop, param);
- }
- } else if (param) {
- icalproperty_remove_parameter (prop, ICAL_TZID_PARAMETER);
- }
+ e_cal_model_update_comp_time (model, comp_data, value, ICAL_DUE_PROPERTY, icalproperty_set_due, icalproperty_new_due);
}
/* FIXME: We need to set the "transient_for" property for the dialog, but the
@@ -929,7 +883,7 @@ ecmt_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value)
set_complete (comp_data, value);
break;
case E_CAL_MODEL_TASKS_FIELD_DUE :
- set_due (comp_data, value);
+ set_due ((ECalModel*) model, comp_data, value);
break;
case E_CAL_MODEL_TASKS_FIELD_GEO :
set_geo (comp_data, value);
@@ -1188,7 +1142,7 @@ ecmt_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
set_status (comp_data, e_table_model_value_at (source_model, E_CAL_MODEL_TASKS_FIELD_STATUS, row));
}
- set_due (comp_data,
+ set_due (model, comp_data,
e_table_model_value_at (source_model, E_CAL_MODEL_TASKS_FIELD_DUE, row));
set_geo (comp_data,
e_table_model_value_at (source_model, E_CAL_MODEL_TASKS_FIELD_GEO, row));
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index ccf2edff82..cf515d55b6 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -834,14 +834,45 @@ set_description (ECalModelComponent *comp_data, const gchar *value)
}
static void
-set_dtstart (ECalModel *model, ECalModelComponent *comp_data, gconstpointer value)
+datetime_to_zone (ECal *client, struct icaltimetype *tt, icaltimezone *tt_zone, const gchar *tzid)
{
- ECellDateEditValue *dv = (ECellDateEditValue *) value;
+ icaltimezone *from, *to;
+ const gchar *tt_tzid = NULL;
+
+ g_return_if_fail (tt != NULL);
+
+ if (tt_zone)
+ tt_tzid = icaltimezone_get_tzid (tt_zone);
+
+ if (tt_tzid == NULL || tzid == NULL ||
+ tt_tzid == tzid || g_str_equal (tt_tzid, tzid))
+ return;
+
+ from = tt_zone;
+ to = icaltimezone_get_builtin_timezone_from_tzid (tzid);
+ if (!to) {
+ /* do not check failure here, maybe the zone is not available there */
+ e_cal_get_timezone (client, tzid, &to, NULL);
+ }
+
+ icaltimezone_convert_time (tt, from, to);
+}
+
+/* updates time in a component, and keeps the timezone used in it, if exists */
+void
+e_cal_model_update_comp_time (ECalModel *model, ECalModelComponent *comp_data, gconstpointer time_value, icalproperty_kind kind, void (*set_func)(icalproperty *prop, struct icaltimetype v), icalproperty * (*new_func)(struct icaltimetype v))
+{
+ ECellDateEditValue *dv = (ECellDateEditValue *) time_value;
icalproperty *prop;
icalparameter *param;
- const gchar *tzid;
+ struct icaltimetype tt;
- prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY);
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (comp_data != NULL);
+ g_return_if_fail (set_func != NULL);
+ g_return_if_fail (new_func != NULL);
+
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, kind);
if (prop)
param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
else
@@ -858,34 +889,40 @@ set_dtstart (ECalModel *model, ECalModelComponent *comp_data, gconstpointer valu
return;
}
- /* If the TZID is set to "UTC", we set the is_utc flag. */
- tzid = dv->zone ? icaltimezone_get_tzid (dv->zone) : "UTC";
- if (tzid && !strcmp (tzid, "UTC"))
- dv->tt.is_utc = 1;
- else
- dv->tt.is_utc = 0;
+ tt = dv->tt;
+ datetime_to_zone (comp_data->client, &tt, e_cal_model_get_timezone (model), param ? icalparameter_get_tzid (param) : NULL);
if (prop) {
- icalproperty_set_dtstart (prop, dv->tt);
+ set_func (prop, tt);
} else {
- prop = icalproperty_new_dtstart (dv->tt);
+ prop = new_func (tt);
icalcomponent_add_property (comp_data->icalcomp, prop);
}
- /* If the TZID is set to "UTC", we don't want to save the TZID. */
- if (tzid && strcmp (tzid, "UTC")) {
- if (param) {
- icalparameter_set_tzid (param, (gchar *) tzid);
+ if (param) {
+ const gchar *tzid = icalparameter_get_tzid (param);
+
+ /* If the TZID is set to "UTC", we don't want to save the TZID. */
+ if (tzid && strcmp (tzid, "UTC")) {
+ if (param) {
+ icalparameter_set_tzid (param, (gchar *) tzid);
+ } else {
+ param = icalparameter_new_tzid ((gchar *) tzid);
+ icalproperty_add_parameter (prop, param);
+ }
} else {
- param = icalparameter_new_tzid ((gchar *) tzid);
- icalproperty_add_parameter (prop, param);
+ icalproperty_remove_parameter (prop, ICAL_TZID_PARAMETER);
}
- } else if (param) {
- icalproperty_remove_parameter (prop, ICAL_TZID_PARAMETER);
}
}
static void
+set_dtstart (ECalModel *model, ECalModelComponent *comp_data, gconstpointer value)
+{
+ e_cal_model_update_comp_time (model, comp_data, value, ICAL_DTSTART_PROPERTY, icalproperty_set_dtstart, icalproperty_new_dtstart);
+}
+
+static void
set_summary (ECalModelComponent *comp_data, const gchar *value)
{
icalproperty *prop;
diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h
index c5fffd3cd6..a59d5e02a5 100644
--- a/calendar/gui/e-cal-model.h
+++ b/calendar/gui/e-cal-model.h
@@ -255,6 +255,13 @@ void e_cal_model_set_default_time_func
ECalModelDefaultTimeFunc func,
gpointer user_data);
+void e_cal_model_update_comp_time (ECalModel *model,
+ ECalModelComponent *comp_data,
+ gconstpointer time_value,
+ icalproperty_kind kind,
+ void (*set_func)(icalproperty *prop, struct icaltimetype v),
+ icalproperty * (*new_func)(struct icaltimetype v));
+
G_END_DECLS
#endif /* E_CAL_MODEL_H */