aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-cal-model.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui/e-cal-model.c')
-rw-r--r--calendar/gui/e-cal-model.c239
1 files changed, 116 insertions, 123 deletions
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index 77f7e622ef..ff48c6bd4d 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -174,46 +174,6 @@ e_cal_model_init (ECalModel *model)
}
static void
-free_comp_data (ECalModelComponent *comp_data)
-{
- g_return_if_fail (comp_data != NULL);
-
- comp_data->client = NULL;
-
- if (comp_data->icalcomp) {
- icalcomponent_free (comp_data->icalcomp);
- comp_data->icalcomp = NULL;
- }
-
- if (comp_data->dtstart) {
- g_free (comp_data->dtstart);
- comp_data->dtstart = NULL;
- }
-
- if (comp_data->dtend) {
- g_free (comp_data->dtend);
- comp_data->dtend = NULL;
- }
-
- if (comp_data->due) {
- g_free (comp_data->due);
- comp_data->due = NULL;
- }
-
- if (comp_data->completed) {
- g_free (comp_data->completed);
- comp_data->completed = NULL;
- }
-
- if (comp_data->color) {
- g_free (comp_data->color);
- comp_data->color = NULL;
- }
-
- g_free (comp_data);
-}
-
-static void
clear_objects_array (ECalModelPrivate *priv)
{
gint i;
@@ -223,7 +183,7 @@ clear_objects_array (ECalModelPrivate *priv)
comp_data = g_ptr_array_index (priv->objects, i);
g_assert (comp_data != NULL);
- free_comp_data (comp_data);
+ e_cal_model_free_component_data (comp_data);
}
@@ -406,11 +366,12 @@ get_dtstart (ECalModel *model, ECalModelComponent *comp_data)
&& e_cal_get_timezone (comp_data->client, icaltime_get_tzid (tt_start), &zone, NULL))
got_zone = TRUE;
- if ((priv->flags & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES) &&
- (e_cal_util_component_has_recurrences (comp_data->icalcomp))) {
- if (got_zone)
+ if (e_cal_model_get_flags (model) & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES) {
+ if (got_zone) {
tt_start = icaltime_from_timet_with_zone (comp_data->instance_start, tt_start.is_date, zone);
- else
+ if (priv->zone)
+ icaltimezone_convert_time (&tt_start, zone, priv->zone);
+ } else
tt_start = icaltime_from_timet (comp_data->instance_start, tt_start.is_date);
}
@@ -758,7 +719,7 @@ ecm_append_row (ETableModel *etm, ETableModel *source, int row)
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (E_IS_TABLE_MODEL (source));
- memset (&comp_data, 0, sizeof (comp_data));
+ memset (&comp_data, 0, sizeof (ECalModelComponent));
comp_data.client = e_cal_model_get_default_client (model);
/* guard against saving before the calendar is open */
@@ -780,7 +741,6 @@ ecm_append_row (ETableModel *etm, ETableModel *source, int row)
model_class->fill_component_from_model (model, &comp_data, source, row);
}
-
if (!e_cal_create_object (comp_data.client, comp_data.icalcomp, NULL, NULL)) {
g_warning (G_STRLOC ": Could not create the object!");
@@ -1314,16 +1274,29 @@ add_instance_cb (ECalComponent *comp, time_t instance_start, time_t instance_end
ECalModelComponent *comp_data;
ECalModelPrivate *priv;
RecurrenceExpansionData *rdata = user_data;
+ struct icaltimetype itt;
priv = rdata->model->priv;
e_table_model_pre_change (E_TABLE_MODEL (rdata->model));
comp_data = g_new0 (ECalModelComponent, 1);
- comp_data->client = g_object_ref (e_cal_view_get_client (rdata->query));
- comp_data->icalcomp = icalcomponent_new_clone (rdata->icalcomp);
- comp_data->instance_start = instance_start;
- comp_data->instance_end = instance_end;
+ comp_data->client = g_object_ref (rdata->client);
+ comp_data->icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
+ if (priv->zone) {
+ itt = icaltime_from_timet_with_zone (instance_start, FALSE, icaltimezone_get_utc_timezone ());
+ icaltimezone_convert_time (&itt, icaltimezone_get_utc_timezone (), priv->zone);
+ comp_data->instance_start = icaltime_as_timet (itt);
+
+ itt = icaltime_from_timet_with_zone (instance_end, FALSE, icaltimezone_get_utc_timezone ());
+ icaltimezone_convert_time (&itt, icaltimezone_get_utc_timezone (), priv->zone);
+ comp_data->instance_end = icaltime_as_timet (itt);
+ } else {
+ comp_data->instance_start = instance_start;
+ comp_data->instance_end = instance_end;
+ }
+ comp_data->dtstart = comp_data->dtend = comp_data->due = comp_data->completed = NULL;
+ comp_data->color = NULL;
g_ptr_array_add (priv->objects, comp_data);
e_table_model_row_inserted (E_TABLE_MODEL (rdata->model), priv->objects->len - 1);
@@ -1332,6 +1305,48 @@ add_instance_cb (ECalComponent *comp, time_t instance_start, time_t instance_end
}
static void
+set_instance_times (ECalModelComponent *comp_data, icaltimezone *zone)
+{
+ struct icaltimetype recur_time, start_time, end_time;
+
+ recur_time = icalcomponent_get_recurrenceid (comp_data->icalcomp);
+ start_time = icalcomponent_get_dtstart (comp_data->icalcomp);
+ end_time = icalcomponent_get_dtend (comp_data->icalcomp);
+
+ if (zone) {
+ if (e_cal_util_component_is_instance (comp_data->icalcomp)) {
+ icaltimezone_convert_time (&recur_time, icaltimezone_get_utc_timezone (), zone);
+ comp_data->instance_start = icaltime_as_timet_with_zone (recur_time, zone);
+
+ comp_data->instance_end = comp_data->instance_start +
+ (icaltime_as_timet_with_zone (end_time, zone) -
+ icaltime_as_timet_with_zone (start_time, zone));
+ } else {
+ icaltimezone_convert_time (&start_time,
+ start_time.zone ? start_time.zone : icaltimezone_get_utc_timezone (),
+ zone);
+ comp_data->instance_start = icaltime_as_timet_with_zone (start_time, zone);
+
+ icaltimezone_convert_time (&end_time,
+ end_time.zone ? end_time.zone : icaltimezone_get_utc_timezone (),
+ zone);
+ comp_data->instance_end = icaltime_as_timet_with_zone (end_time, zone);
+ }
+ } else {
+ if (e_cal_util_component_is_instance (comp_data->icalcomp)) {
+ icaltimezone_convert_time (&recur_time, icaltimezone_get_utc_timezone (), zone);
+ comp_data->instance_start = icaltime_as_timet_with_zone (recur_time, zone);
+ comp_data->instance_end = comp_data->instance_start +
+ (icaltime_as_timet (end_time) -
+ icaltime_as_timet (start_time));
+ } else {
+ comp_data->instance_start = icaltime_as_timet (icalcomponent_get_dtstart (comp_data->icalcomp));
+ comp_data->instance_end = icaltime_as_timet (icalcomponent_get_dtend (comp_data->icalcomp));
+ }
+ }
+}
+
+static void
e_cal_view_objects_added_cb (ECalView *query, GList *objects, gpointer user_data)
{
ECalModel *model = (ECalModel *) user_data;
@@ -1341,8 +1356,7 @@ e_cal_view_objects_added_cb (ECalView *query, GList *objects, gpointer user_data
priv = model->priv;
for (l = objects; l; l = l->next) {
- if ((priv->flags & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES) &&
- e_cal_util_component_has_recurrences (l->data)) {
+ if ((priv->flags & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES)) {
RecurrenceExpansionData rdata;
rdata.client = e_cal_view_get_client (query);
@@ -1361,6 +1375,9 @@ e_cal_view_objects_added_cb (ECalView *query, GList *objects, gpointer user_data
comp_data = g_new0 (ECalModelComponent, 1);
comp_data->client = g_object_ref (e_cal_view_get_client (query));
comp_data->icalcomp = icalcomponent_new_clone (l->data);
+ set_instance_times (comp_data, priv->zone);
+ comp_data->dtstart = comp_data->dtend = comp_data->due = comp_data->completed = NULL;
+ comp_data->color = NULL;
g_ptr_array_add (priv->objects, comp_data);
e_table_model_row_inserted (E_TABLE_MODEL (model), priv->objects->len - 1);
@@ -1379,62 +1396,23 @@ e_cal_view_objects_modified_cb (ECalView *query, GList *objects, gpointer user_d
for (l = objects; l; l = l->next) {
ECalModelComponent *comp_data;
+ GList node;
- if ((priv->flags & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES) &&
- e_cal_util_component_has_recurrences (l->data)) {
- GList node;
-
- /* remove all recurrences and re-add them after generating them */
- while ((comp_data = search_by_uid_and_client (priv, e_cal_view_get_client (query),
- icalcomponent_get_uid (l->data)))) {
- int pos;
+ /* remove all recurrences and re-add them after generating them */
+ while ((comp_data = search_by_uid_and_client (priv, e_cal_view_get_client (query),
+ icalcomponent_get_uid (l->data)))) {
+ int pos;
- pos = get_position_in_array (priv->objects, comp_data);
-
- g_ptr_array_remove (priv->objects, comp_data);
- free_comp_data (comp_data);
-
- e_table_model_row_deleted (E_TABLE_MODEL (model), pos);
- }
-
- node.prev = node.next = NULL;
- node.data = l->data;
- e_cal_view_objects_added_cb (query, &node, model);
- } else {
- e_table_model_pre_change (E_TABLE_MODEL (model));
-
- comp_data = search_by_uid_and_client (priv, e_cal_view_get_client (query),
- icalcomponent_get_uid (l->data));
- if (!comp_data)
- continue;
-
- if (comp_data->icalcomp)
- icalcomponent_free (comp_data->icalcomp);
- if (comp_data->dtstart) {
- g_free (comp_data->dtstart);
- comp_data->dtstart = NULL;
- }
- if (comp_data->dtend) {
- g_free (comp_data->dtend);
- comp_data->dtend = NULL;
- }
- if (comp_data->due) {
- g_free (comp_data->due);
- comp_data->due = NULL;
- }
- if (comp_data->completed) {
- g_free (comp_data->completed);
- comp_data->completed = NULL;
- }
- if (comp_data->color) {
- g_free (comp_data->color);
- comp_data->color = NULL;
- }
-
- comp_data->icalcomp = icalcomponent_new_clone (l->data);
+ pos = get_position_in_array (priv->objects, comp_data);
+ e_table_model_row_deleted (E_TABLE_MODEL (model), pos);
- e_table_model_row_changed (E_TABLE_MODEL (model), get_position_in_array (priv->objects, comp_data));
+ g_ptr_array_remove (priv->objects, comp_data);
+ e_cal_model_free_component_data (comp_data);
}
+
+ node.prev = node.next = NULL;
+ node.data = l->data;
+ e_cal_view_objects_added_cb (query, &node, model);
}
}
@@ -1456,11 +1434,10 @@ e_cal_view_objects_removed_cb (ECalView *query, GList *uids, gpointer user_data)
/* make sure we remove all objects with this UID */
while ((comp_data = search_by_uid_and_client (priv, e_cal_view_get_client (query), l->data))) {
pos = get_position_in_array (priv->objects, comp_data);
-
- g_ptr_array_remove (priv->objects, comp_data);
- free_comp_data (comp_data);
-
e_table_model_row_deleted (E_TABLE_MODEL (model), pos);
+
+ g_ptr_array_remove (priv->objects, comp_data);
+ e_cal_model_free_component_data (comp_data);
}
}
}
@@ -1628,11 +1605,10 @@ remove_client_objects (ECalModel *model, ECalModelClient *client_data)
if (comp_data->client == client_data->client) {
e_table_model_pre_change (E_TABLE_MODEL (model));
-
- g_ptr_array_remove (model->priv->objects, comp_data);
- free_comp_data (comp_data);
-
e_table_model_row_deleted (E_TABLE_MODEL (model), i - 1);
+
+ g_ptr_array_remove (model->priv->objects, comp_data);
+ e_cal_model_free_component_data (comp_data);
}
}
}
@@ -1991,10 +1967,9 @@ copy_ecdv (ECellDateEditValue *ecdv)
{
ECellDateEditValue *new_ecdv;
-
new_ecdv = g_new0 (ECellDateEditValue, 1);
- new_ecdv->tt = ecdv->tt;
- new_ecdv->zone = ecdv->zone;
+ new_ecdv->tt = ecdv ? ecdv->tt : icaltime_null_time ();
+ new_ecdv->zone = ecdv ? ecdv->zone : NULL;
return new_ecdv;
}
@@ -2011,6 +1986,8 @@ e_cal_model_copy_component_data (ECalModelComponent *comp_data)
new_data = g_new0 (ECalModelComponent, 1);
+ new_data->instance_start = comp_data->instance_start;
+ new_data->instance_end = comp_data->instance_end;
if (comp_data->icalcomp)
new_data->icalcomp = icalcomponent_new_clone (comp_data->icalcomp);
if (comp_data->client)
@@ -2023,6 +2000,8 @@ e_cal_model_copy_component_data (ECalModelComponent *comp_data)
new_data->due = copy_ecdv (comp_data->due);
if (comp_data->completed)
new_data->completed = copy_ecdv (comp_data->completed);
+ if (comp_data->color)
+ new_data->color = g_strdup (comp_data->color);
return new_data;
}
@@ -2035,20 +2014,34 @@ e_cal_model_free_component_data (ECalModelComponent *comp_data)
{
g_return_if_fail (comp_data != NULL);
- if (comp_data->client)
+ if (comp_data->client) {
g_object_unref (comp_data->client);
- if (comp_data->icalcomp)
+ comp_data->client = NULL;
+ }
+ if (comp_data->icalcomp) {
icalcomponent_free (comp_data->icalcomp);
- if (comp_data->dtstart)
+ comp_data->icalcomp = NULL;
+ }
+ if (comp_data->dtstart) {
g_free (comp_data->dtstart);
- if (comp_data->dtend)
+ comp_data->dtstart = NULL;
+ }
+ if (comp_data->dtend) {
g_free (comp_data->dtend);
- if (comp_data->due)
+ comp_data->dtend = NULL;
+ }
+ if (comp_data->due) {
g_free (comp_data->due);
- if (comp_data->completed)
+ comp_data->due = NULL;
+ }
+ if (comp_data->completed) {
g_free (comp_data->completed);
- if (comp_data->color)
+ comp_data->completed = NULL;
+ }
+ if (comp_data->color) {
g_free (comp_data->color);
+ comp_data->color = NULL;
+ }
g_free (comp_data);
}