Port to libecal-2.0

Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/merge_requests/70
This commit is contained in:
Milan Crha
2019-05-17 21:58:55 +02:00
parent 9357db6e23
commit a0cae4356a
19 changed files with 732 additions and 486 deletions
+174 -126
View File
@@ -75,6 +75,10 @@ struct _GcalEvent
gchar *uid;
gboolean has_recurrence;
/* These are cached, because ECalComponent returns newly allocated data for them */
gchar *summary;
gchar *location;
/*
* The description is cached in the class because it
* may come as a GSList of descriptions, in which
@@ -167,12 +171,14 @@ destroy_event_cache_map (void)
static GTimeZone*
get_timezone_from_ical (ECalComponentDateTime *comp)
{
const icaltimezone *zone;
ICalTimezone *zone;
ICalTime *itt;
GTimeZone *tz;
zone = icaltime_get_timezone (*comp->value);
itt = e_cal_component_datetime_get_value (comp);
zone = i_cal_time_get_timezone (itt);
if (comp->value->is_date)
if (i_cal_time_is_date (itt))
{
/*
* When loading an all day event, the timezone must not be taken into account
@@ -181,13 +187,13 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
*/
tz = g_time_zone_new_utc ();
}
else if (comp->tzid)
else if (e_cal_component_datetime_get_tzid (comp))
{
const gchar *real_tzid;
real_tzid = comp->tzid;
real_tzid = e_cal_component_datetime_get_tzid (comp);
if (g_str_has_prefix (comp->tzid, LIBICAL_TZID_PREFIX))
if (g_str_has_prefix (real_tzid, LIBICAL_TZID_PREFIX))
real_tzid += strlen (LIBICAL_TZID_PREFIX);
tz = g_time_zone_new (real_tzid);
@@ -197,8 +203,7 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
g_autofree gchar *tzid = NULL;
gint offset;
offset = icaltimezone_get_utc_offset ((icaltimezone*) icaltime_get_timezone (*comp->value),
comp->value, NULL);
offset = i_cal_timezone_get_utc_offset (zone, itt, NULL);
tzid = format_utc_offset (offset);
tz = g_time_zone_new (tzid);
}
@@ -218,27 +223,32 @@ static ECalComponentDateTime*
build_component_from_datetime (GcalEvent *self,
GDateTime *dt)
{
ECalComponentDateTime *comp_dt;
ICalTime *itt;
gchar *tzid;
if (!dt)
return NULL;
comp_dt = g_new0 (ECalComponentDateTime, 1);
comp_dt->value = gcal_date_time_to_icaltime (dt);
comp_dt->value->is_date = self->all_day;
itt = gcal_date_time_to_icaltime (dt);
if (self->all_day)
{
comp_dt->value->zone = icaltimezone_get_utc_timezone ();
comp_dt->tzid = g_strdup ("UTC");
i_cal_time_set_timezone (itt, i_cal_timezone_get_utc_timezone ());
tzid = g_strdup ("UTC");
}
else
{
comp_dt->value->zone = e_cal_util_get_system_timezone ();
comp_dt->tzid = g_strdup (icaltimezone_get_tzid ((icaltimezone *) comp_dt->value->zone));
ICalTimezone *zone;
zone = e_cal_util_get_system_timezone ();
i_cal_time_set_timezone (itt, zone);
tzid = zone ? g_strdup (i_cal_timezone_get_tzid (zone)) : NULL;
}
return comp_dt;
/* Call it after setting the timezone, because the DATE values do not let set the timezone */
i_cal_time_set_is_date (itt, self->all_day);
return e_cal_component_datetime_new_take (itt, tzid);
}
static void
@@ -254,28 +264,28 @@ gcal_event_update_uid_internal (GcalEvent *self)
/* Clear the previous uid */
g_clear_pointer (&self->uid, g_free);
if (id->rid != NULL)
if (e_cal_component_id_get_rid (id) != NULL)
{
self->uid = g_strdup_printf ("%s:%s:%s",
source_id,
id->uid,
id->rid);
e_cal_component_id_get_uid (id),
e_cal_component_id_get_rid (id));
}
else
{
self->uid = g_strdup_printf ("%s:%s",
source_id,
id->uid);
e_cal_component_id_get_uid (id));
}
e_cal_component_free_id (id);
e_cal_component_id_free (id);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UID]);
}
static void
load_alarms (GcalEvent *self)
{
GList *alarm_uids, *l;
GSList *alarm_uids, *l;
alarm_uids = e_cal_component_get_alarm_uids (self->component);
@@ -298,7 +308,7 @@ load_alarms (GcalEvent *self)
e_cal_component_alarm_free (alarm);
}
cal_obj_uid_list_free (alarm_uids);
g_slist_free_full (alarm_uids, g_free);
}
static void
@@ -307,24 +317,25 @@ gcal_event_set_component_internal (GcalEvent *self,
{
if (g_set_object (&self->component, component))
{
ECalComponentDateTime start;
ECalComponentDateTime end;
icaltimetype date;
ECalComponentDateTime *start;
ECalComponentDateTime *end;
ECalComponentText *text;
ICalTime *date;
GDateTime *date_start;
GTimeZone *zone_start = NULL;
GDateTime *date_end;
GTimeZone *zone_end = NULL;
gboolean start_is_all_day, end_is_all_day;
gchar *description;
gchar *description, *location;
/* Setup start date */
e_cal_component_get_dtstart (component, &start);
start = e_cal_component_get_dtstart (component);
/*
* A NULL start date is invalid. We set something bogus to proceed, and make
* it set a GError and return NULL.
*/
if (!start.value)
if (!start || !e_cal_component_datetime_get_value (start))
{
self->is_valid = FALSE;
g_set_error (&self->initialization_error,
@@ -332,27 +343,31 @@ gcal_event_set_component_internal (GcalEvent *self,
GCAL_EVENT_ERROR_INVALID_START_DATE,
"Event '%s' has an invalid start date", gcal_event_get_uid (self));
start.value = g_new0 (icaltimetype, 1);
*start.value = icaltime_today ();
e_cal_component_datetime_free (start);
start = e_cal_component_datetime_new_take (i_cal_time_new_today (), NULL);
}
GCAL_TRACE_MSG ("Retrieving start timezone");
date = icaltime_normalize (*start.value);
zone_start = get_timezone_from_ical (&start);
date = i_cal_time_normalize (e_cal_component_datetime_get_value (start));
zone_start = get_timezone_from_ical (start);
date_start = g_date_time_new (zone_start,
date.year, date.month, date.day,
date.is_date ? 0 : date.hour,
date.is_date ? 0 : date.minute,
date.is_date ? 0 : date.second);
i_cal_time_get_year (date),
i_cal_time_get_month (date),
i_cal_time_get_day (date),
i_cal_time_is_date (date) ? 0 : i_cal_time_get_hour (date),
i_cal_time_is_date (date) ? 0 : i_cal_time_get_minute (date),
i_cal_time_is_date (date) ? 0 : i_cal_time_get_second (date));
start_is_all_day = gcal_date_time_is_date (date_start);
self->dt_start = date_start;
/* Setup end date */
e_cal_component_get_dtend (component, &end);
g_clear_object (&date);
if(!end.value)
/* Setup end date */
end = e_cal_component_get_dtend (component);
if (!end || !e_cal_component_datetime_get_value (end))
{
self->all_day = TRUE;
}
@@ -360,13 +375,15 @@ gcal_event_set_component_internal (GcalEvent *self,
{
GCAL_TRACE_MSG ("Retrieving end timezone");
date = icaltime_normalize (*end.value);
zone_end = get_timezone_from_ical (&end);
date = i_cal_time_normalize (e_cal_component_datetime_get_value (end));
zone_end = get_timezone_from_ical (end);
date_end = g_date_time_new (zone_end,
date.year, date.month, date.day,
date.is_date ? 0 : date.hour,
date.is_date ? 0 : date.minute,
date.is_date ? 0 : date.second);
i_cal_time_get_year (date),
i_cal_time_get_month (date),
i_cal_time_get_day (date),
i_cal_time_is_date (date) ? 0 : i_cal_time_get_hour (date),
i_cal_time_is_date (date) ? 0 : i_cal_time_get_minute (date),
i_cal_time_is_date (date) ? 0 : i_cal_time_get_second (date));
end_is_all_day = gcal_date_time_is_date (date_end);
self->dt_end = g_date_time_ref (date_end);
@@ -374,9 +391,20 @@ gcal_event_set_component_internal (GcalEvent *self,
/* Setup all day */
self->all_day = start_is_all_day && end_is_all_day;
e_cal_component_free_datetime (&end);
g_clear_object (&date);
}
/* Summary */
text = e_cal_component_get_summary (component);
if (text && e_cal_component_text_get_value (text))
gcal_event_set_summary (self, e_cal_component_text_get_value (text));
else
gcal_event_set_summary (self, "");
/* Location */
location = e_cal_component_get_location (component);
gcal_event_set_location (self, location ? location : "");
/* Setup description */
description = get_desc_from_component (component, "\n\n");
gcal_event_set_description (self, description);
@@ -396,14 +424,15 @@ gcal_event_set_component_internal (GcalEvent *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HAS_RECURRENCE]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RECURRENCE]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPONENT]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCATION]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SUMMARY]);
g_clear_pointer (&zone_start, g_time_zone_unref);
g_clear_pointer (&zone_end, g_time_zone_unref);
g_clear_pointer (&description, g_free);
g_clear_pointer (&location, g_free);
e_cal_component_free_datetime (&start);
e_cal_component_text_free (text);
e_cal_component_datetime_free (start);
e_cal_component_datetime_free (end);
}
}
@@ -449,6 +478,8 @@ gcal_event_finalize (GObject *object)
g_clear_pointer (&self->dt_start, g_date_time_unref);
g_clear_pointer (&self->dt_end, g_date_time_unref);
g_clear_pointer (&self->summary, g_free);
g_clear_pointer (&self->location, g_free);
g_clear_pointer (&self->description, g_free);
g_clear_pointer (&self->alarms, g_hash_table_unref);
g_clear_pointer (&self->uid, g_free);
@@ -937,8 +968,7 @@ gcal_event_set_date_end (GcalEvent *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_END]);
e_cal_component_free_datetime (component_dt);
g_free (component_dt);
e_cal_component_datetime_free (component_dt);
}
}
@@ -986,8 +1016,7 @@ gcal_event_set_date_start (GcalEvent *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_START]);
e_cal_component_free_datetime (component_dt);
g_free (component_dt);
e_cal_component_datetime_free (component_dt);
}
}
@@ -1020,21 +1049,32 @@ gcal_event_set_description (GcalEvent *self,
{
g_return_if_fail (GCAL_IS_EVENT (self));
if (description && !*description)
description = NULL;
if (g_strcmp0 (self->description, description) != 0)
{
ECalComponentText text_component;
GSList list;
g_clear_pointer (&self->description, g_free);
self->description = g_strdup (description);
text_component.value = description;
text_component.altrep = NULL;
if (description)
{
ECalComponentText* text_component;
GSList list;
list.data = &text_component;
list.next = NULL;
text_component = e_cal_component_text_new (description, NULL);
list.data = text_component;
list.next = NULL;
e_cal_component_set_descriptions (self->component, &list);
e_cal_component_text_free (text_component);
}
else
{
e_cal_component_set_descriptions (self->component, NULL);
}
e_cal_component_set_description_list (self->component, &list);
e_cal_component_commit_sequence (self->component);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DESCRIPTION]);
@@ -1085,7 +1125,8 @@ GList*
gcal_event_get_alarms (GcalEvent *self)
{
GHashTable *tmp;
GList *alarm_uids, *alarms, *l;
GSList *alarm_uids, *l;
GList *alarms;
g_return_val_if_fail (GCAL_IS_EVENT (self), NULL);
@@ -1114,7 +1155,7 @@ gcal_event_get_alarms (GcalEvent *self)
}
}
cal_obj_uid_list_free (alarm_uids);
g_slist_free_full (alarm_uids, g_free);
g_hash_table_destroy (tmp);
return alarms;
@@ -1136,9 +1177,10 @@ gcal_event_add_alarm (GcalEvent *self,
guint type,
gboolean has_sound)
{
ECalComponentAlarmTrigger trigger;
ECalComponentAlarmTrigger *trigger;
ECalComponentAlarmAction action;
ECalComponentAlarm *alarm;
ICalDuration *duration;
gchar *alarm_uid;
g_return_if_fail (GCAL_IS_EVENT (self));
@@ -1155,13 +1197,15 @@ gcal_event_add_alarm (GcalEvent *self,
alarm = e_cal_component_alarm_new ();
/* Setup the alarm trigger */
trigger.type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START;
duration = i_cal_duration_new_null_duration ();
i_cal_duration_set_is_neg (duration, TRUE);
i_cal_duration_set_minutes (duration, type);
trigger.u.rel_duration = icaldurationtype_null_duration ();
trigger.u.rel_duration.is_neg = TRUE;
trigger.u.rel_duration.minutes = type;
trigger = e_cal_component_alarm_trigger_new_relative (E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, duration);
e_cal_component_alarm_set_trigger (alarm, trigger);
g_clear_object (&duration);
e_cal_component_alarm_take_trigger (alarm, trigger);
/* Action */
if (has_sound)
@@ -1223,13 +1267,9 @@ gcal_event_remove_alarm (GcalEvent *self,
const gchar*
gcal_event_get_location (GcalEvent *self)
{
const gchar *location;
g_return_val_if_fail (GCAL_IS_EVENT (self), NULL);
e_cal_component_get_location (self->component, &location);
return location ? location : "";
return self->location;
}
/**
@@ -1251,7 +1291,10 @@ gcal_event_set_location (GcalEvent *self,
if (g_strcmp0 (current_location, location) != 0)
{
e_cal_component_set_location (self->component, location);
e_cal_component_set_location (self->component, (location && *location) ? location : NULL);
g_clear_pointer (&self->location, g_free);
self->location = g_strdup (location ? location : "");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCATION]);
}
@@ -1321,13 +1364,9 @@ gcal_event_set_calendar (GcalEvent *self,
const gchar*
gcal_event_get_summary (GcalEvent *self)
{
ECalComponentText summary;
g_return_val_if_fail (GCAL_IS_EVENT (self), NULL);
e_cal_component_get_summary (self->component, &summary);
return summary.value ? summary.value : "";
return self->summary;
}
/**
@@ -1349,14 +1388,18 @@ gcal_event_set_summary (GcalEvent *self,
if (g_strcmp0 (current_summary, summary) != 0)
{
ECalComponentText text_component;
ECalComponentText *text_component;
text_component.value = summary ? summary : "";
text_component.altrep = NULL;
text_component = e_cal_component_text_new (summary ? summary : "", NULL);
e_cal_component_set_summary (self->component, &text_component);
e_cal_component_set_summary (self->component, text_component);
e_cal_component_commit_sequence (self->component);
e_cal_component_text_free (text_component);
g_clear_pointer (&self->summary, g_free);
self->summary = g_strdup (summary ? summary : "");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SUMMARY]);
}
}
@@ -1552,9 +1595,9 @@ gcal_event_set_recurrence (GcalEvent *self,
GcalRecurrence *recur)
{
ECalComponent *comp;
icalcomponent *icalcomp;
icalproperty *prop;
struct icalrecurrencetype *rrule;
ICalComponent *icalcomp;
ICalProperty *prop;
ICalRecurrence *rrule;
g_return_if_fail (GCAL_IS_EVENT (self));
@@ -1566,20 +1609,20 @@ gcal_event_set_recurrence (GcalEvent *self,
g_clear_pointer (&self->recurrence, gcal_recurrence_unref);
self->recurrence = gcal_recurrence_copy (recur);
prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY);
prop = i_cal_component_get_first_property (icalcomp, I_CAL_RRULE_PROPERTY);
if (prop)
{
icalproperty_set_rrule (prop, *rrule);
i_cal_property_set_rrule (prop, rrule);
}
else
{
prop = icalproperty_new_rrule (*rrule);
icalcomponent_add_property (icalcomp, prop);
prop = i_cal_property_new_rrule (rrule);
i_cal_component_add_property (icalcomp, prop);
}
/* Rescan the component for the changes to be detected and registered */
e_cal_component_rescan (comp);
g_clear_object (&rrule);
g_clear_object (&prop);
}
/**
@@ -1619,33 +1662,36 @@ gcal_event_get_original_timezones (GcalEvent *self,
{
g_autoptr (GTimeZone) original_start_tz = NULL;
g_autoptr (GTimeZone) original_end_tz = NULL;
icalcomponent *ical_comp;
icalproperty *property;
ICalComponent *icalcomp;
ICalProperty *property;
g_return_if_fail (GCAL_IS_EVENT (self));
g_assert (self->component != NULL);
ical_comp = e_cal_component_get_icalcomponent (self->component);
icalcomp = e_cal_component_get_icalcomponent (self->component);
for (property = icalcomponent_get_first_property (ical_comp, ICAL_X_PROPERTY);
for (property = i_cal_component_get_first_property (icalcomp, I_CAL_X_PROPERTY);
property;
property = icalcomponent_get_next_property (ical_comp, ICAL_X_PROPERTY))
g_object_unref (property), property = i_cal_component_get_next_property (icalcomp, I_CAL_X_PROPERTY))
{
const gchar *value;
if (original_start_tz && original_end_tz)
break;
if (g_strcmp0 (icalproperty_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-START") == 0)
{
value = icalproperty_get_x (property);
g_object_unref (property);
break;
}
if (g_strcmp0 (i_cal_property_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-START") == 0)
{
value = i_cal_property_get_x (property);
original_start_tz = g_time_zone_new (value);
GCAL_TRACE_MSG ("Found X-GNOME-CALENDAR-ORIGINAL-TZ-START=%s", value);
}
else if (g_strcmp0 (icalproperty_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-END") == 0)
else if (g_strcmp0 (i_cal_property_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-END") == 0)
{
value = icalproperty_get_x (property);
value = i_cal_property_get_x (property);
original_end_tz = g_time_zone_new (value);
GCAL_TRACE_MSG ("Found X-GNOME-CALENDAR-ORIGINAL-TZ-END=%s", value);
@@ -1680,8 +1726,8 @@ gcal_event_get_original_timezones (GcalEvent *self,
void
gcal_event_save_original_timezones (GcalEvent *self)
{
icalcomponent *ical_comp;
icalproperty *property;
ICalComponent *icalcomp;
ICalProperty *property;
GTimeZone *tz;
gboolean has_original_start_tz;
gboolean has_original_end_tz;
@@ -1693,52 +1739,54 @@ gcal_event_save_original_timezones (GcalEvent *self)
has_original_start_tz = FALSE;
has_original_end_tz = FALSE;
ical_comp = e_cal_component_get_icalcomponent (self->component);
icalcomp = e_cal_component_get_icalcomponent (self->component);
for (property = icalcomponent_get_first_property (ical_comp, ICAL_X_PROPERTY);
property;
property = icalcomponent_get_next_property (ical_comp, ICAL_X_PROPERTY))
for (property = i_cal_component_get_first_property (icalcomp, I_CAL_X_PROPERTY);
property && (!has_original_start_tz || !has_original_end_tz);
g_object_unref (property), property = i_cal_component_get_next_property (icalcomp, I_CAL_X_PROPERTY))
{
if (g_strcmp0 (icalproperty_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-START") == 0)
if (g_strcmp0 (i_cal_property_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-START") == 0)
{
tz = g_date_time_get_timezone (self->dt_start);
icalproperty_set_x (property, g_time_zone_get_identifier (tz));
i_cal_property_set_x (property, g_time_zone_get_identifier (tz));
GCAL_TRACE_MSG ("Reusing X-GNOME-CALENDAR-ORIGINAL-TZ-START property with %s", icalproperty_get_x (property));
GCAL_TRACE_MSG ("Reusing X-GNOME-CALENDAR-ORIGINAL-TZ-START property with %s", i_cal_property_get_x (property));
has_original_start_tz = TRUE;
}
else if (g_strcmp0 (icalproperty_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-END") == 0)
else if (g_strcmp0 (i_cal_property_get_x_name (property), "X-GNOME-CALENDAR-ORIGINAL-TZ-END") == 0)
{
tz = g_date_time_get_timezone (self->dt_end);
icalproperty_set_x (property, g_time_zone_get_identifier (tz));
i_cal_property_set_x (property, g_time_zone_get_identifier (tz));
GCAL_TRACE_MSG ("Reusing X-GNOME-CALENDAR-ORIGINAL-TZ-END property with %s", icalproperty_get_x (property));
GCAL_TRACE_MSG ("Reusing X-GNOME-CALENDAR-ORIGINAL-TZ-END property with %s", i_cal_property_get_x (property));
has_original_end_tz = TRUE;
}
}
g_clear_object (&property);
if (!has_original_start_tz)
{
tz = g_date_time_get_timezone (self->dt_start);
property = icalproperty_new_x (g_time_zone_get_identifier (tz));
icalproperty_set_x_name (property, "X-GNOME-CALENDAR-ORIGINAL-TZ-START");
property = i_cal_property_new_x (g_time_zone_get_identifier (tz));
i_cal_property_set_x_name (property, "X-GNOME-CALENDAR-ORIGINAL-TZ-START");
icalcomponent_add_property (ical_comp, property);
GCAL_TRACE_MSG ("Added new X-GNOME-CALENDAR-ORIGINAL-TZ-START property with %s", i_cal_property_get_x (property));
GCAL_TRACE_MSG ("Added new X-GNOME-CALENDAR-ORIGINAL-TZ-START property with %s", icalproperty_get_x (property));
i_cal_component_take_property (icalcomp, property);
}
if (!has_original_end_tz)
{
tz = g_date_time_get_timezone (self->dt_end);
property = icalproperty_new_x (g_time_zone_get_identifier (tz));
icalproperty_set_x_name (property, "X-GNOME-CALENDAR-ORIGINAL-TZ-END");
property = i_cal_property_new_x (g_time_zone_get_identifier (tz));
i_cal_property_set_x_name (property, "X-GNOME-CALENDAR-ORIGINAL-TZ-END");
icalcomponent_add_property (ical_comp, property);
GCAL_TRACE_MSG ("Added new X-GNOME-CALENDAR-ORIGINAL-TZ-END property with %s", i_cal_property_get_x (property));
GCAL_TRACE_MSG ("Added new X-GNOME-CALENDAR-ORIGINAL-TZ-END property with %s", icalproperty_get_x (property));
i_cal_component_take_property (icalcomp, property);
}
GCAL_EXIT;
+16 -11
View File
@@ -1193,7 +1193,7 @@ void
gcal_manager_create_event (GcalManager *self,
GcalEvent *event)
{
icalcomponent *new_event_icalcomp;
ICalComponent *new_event_icalcomp;
ECalComponent *component;
GcalCalendar *calendar;
AsyncOpsData *data;
@@ -1214,6 +1214,7 @@ gcal_manager_create_event (GcalManager *self,
e_cal_client_create_object (gcal_calendar_get_client (calendar),
new_event_icalcomp,
E_CAL_OPERATION_FLAG_NONE,
self->async_ops,
on_event_created,
data);
@@ -1264,6 +1265,7 @@ gcal_manager_update_event (GcalManager *self,
e_cal_client_modify_object (gcal_calendar_get_client (calendar),
e_cal_component_get_icalcomponent (component),
(ECalObjModType) mod,
E_CAL_OPERATION_FLAG_NONE,
NULL,
on_event_updated,
component);
@@ -1298,7 +1300,7 @@ gcal_manager_remove_event (GcalManager *self,
calendar = gcal_event_get_calendar (event);
rid = NULL;
e_cal_component_get_uid (component, &uid);
uid = e_cal_component_get_uid (component);
if (gcal_event_has_recurrence (event))
rid = e_cal_component_get_recurid_as_string (component);
@@ -1307,6 +1309,7 @@ gcal_manager_remove_event (GcalManager *self,
uid,
mod == GCAL_RECURRENCE_MOD_ALL ? NULL : rid,
(ECalObjModType) mod,
E_CAL_OPERATION_FLAG_NONE,
self->async_ops,
on_event_removed,
g_object_ref (event));
@@ -1333,7 +1336,7 @@ gcal_manager_move_event_to_source (GcalManager *self,
{
ECalComponent *ecomponent;
ECalComponent *clone;
icalcomponent *comp;
ICalComponent *comp;
GcalCalendar *calendar;
ECalComponentId *id;
GError *error;
@@ -1355,6 +1358,7 @@ gcal_manager_move_event_to_source (GcalManager *self,
e_cal_client_create_object_sync (gcal_calendar_get_client (calendar),
comp,
E_CAL_OPERATION_FLAG_NONE,
NULL,
NULL,
&error);
@@ -1377,9 +1381,10 @@ gcal_manager_move_event_to_source (GcalManager *self,
id = e_cal_component_get_id (ecomponent);
e_cal_client_remove_object_sync (gcal_calendar_get_client (calendar),
id->uid,
id->rid,
e_cal_component_id_get_uid (id),
e_cal_component_id_get_rid (id),
E_CAL_OBJ_MOD_THIS,
E_CAL_OPERATION_FLAG_NONE,
self->async_ops,
&error);
@@ -1391,7 +1396,7 @@ gcal_manager_move_event_to_source (GcalManager *self,
return;
}
e_cal_component_free_id (id);
e_cal_component_id_free (id);
GCAL_EXIT;
}
@@ -1409,9 +1414,9 @@ gcal_manager_move_event_to_source (GcalManager *self,
* Returns: (nullable)(transfer full)(content-type GcalEvent):a #GList
*/
GList*
gcal_manager_get_events (GcalManager *self,
icaltimetype *start_date,
icaltimetype *end_date)
gcal_manager_get_events (GcalManager *self,
ICalTime *start_date,
ICalTime *end_date)
{
time_t range_start, range_end;
GatherEventData data = {
@@ -1423,8 +1428,8 @@ gcal_manager_get_events (GcalManager *self,
g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL);
range_start = icaltime_as_timet_with_zone (*start_date, e_cal_util_get_system_timezone ());
range_end = icaltime_as_timet_with_zone (*end_date, e_cal_util_get_system_timezone ());
range_start = i_cal_time_as_timet_with_zone (start_date, e_cal_util_get_system_timezone ());
range_end = i_cal_time_as_timet_with_zone (end_date, e_cal_util_get_system_timezone ());
e_cal_data_model_foreach_component (self->e_data_model,
range_start,
+3 -3
View File
@@ -23,7 +23,7 @@
#include "gcal-calendar.h"
#include "gcal-event.h"
#include <libical/icaltime.h>
#include <libecal/libecal.h>
G_BEGIN_DECLS
@@ -88,8 +88,8 @@ void gcal_manager_save_source (GcalManager
ESource *source);
GList* gcal_manager_get_events (GcalManager *self,
icaltimetype *range_start,
icaltimetype *range_end);
ICalTime *range_start,
ICalTime *range_end);
/* GNOME Shell-related functions */
GcalEvent* gcal_manager_get_event_from_shell_search (GcalManager *self,
+70 -49
View File
@@ -160,9 +160,9 @@ GcalRecurrence*
gcal_recurrence_parse_recurrence_rules (ECalComponent *comp)
{
GcalRecurrence *recur;
icalproperty *prop;
icalcomponent *icalcomp;
struct icalrecurrencetype rrule;
ICalProperty *prop;
ICalComponent *icalcomp;
ICalRecurrence *rrule;
if (!e_cal_component_has_recurrences (comp))
return NULL;
@@ -170,26 +170,28 @@ gcal_recurrence_parse_recurrence_rules (ECalComponent *comp)
recur = gcal_recurrence_new ();
icalcomp = e_cal_component_get_icalcomponent (comp);
prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY);
prop = i_cal_component_get_first_property (icalcomp, I_CAL_RRULE_PROPERTY);
g_return_val_if_fail (prop != NULL, NULL);
rrule = icalproperty_get_rrule (prop);
rrule = i_cal_property_get_rrule (prop);
switch (rrule.freq)
g_clear_object (&prop);
switch (i_cal_recurrence_get_freq (rrule))
{
case ICAL_DAILY_RECURRENCE:
case I_CAL_DAILY_RECURRENCE:
recur->frequency = GCAL_RECURRENCE_DAILY;
break;
case ICAL_WEEKLY_RECURRENCE:
case I_CAL_WEEKLY_RECURRENCE:
{
if (rrule.by_day[0] == ICAL_MONDAY_WEEKDAY &&
rrule.by_day[1] == ICAL_TUESDAY_WEEKDAY &&
rrule.by_day[2] == ICAL_WEDNESDAY_WEEKDAY &&
rrule.by_day[3] == ICAL_THURSDAY_WEEKDAY &&
rrule.by_day[4] == ICAL_FRIDAY_WEEKDAY &&
rrule.by_day[5] != ICAL_SATURDAY_WEEKDAY &&
rrule.by_day[6] != ICAL_SUNDAY_WEEKDAY)
if (i_cal_recurrence_get_by_day (rrule, 0) == I_CAL_MONDAY_WEEKDAY &&
i_cal_recurrence_get_by_day (rrule, 1) == I_CAL_TUESDAY_WEEKDAY &&
i_cal_recurrence_get_by_day (rrule, 2) == I_CAL_WEDNESDAY_WEEKDAY &&
i_cal_recurrence_get_by_day (rrule, 3) == I_CAL_THURSDAY_WEEKDAY &&
i_cal_recurrence_get_by_day (rrule, 4) == I_CAL_FRIDAY_WEEKDAY &&
i_cal_recurrence_get_by_day (rrule, 5) != I_CAL_SATURDAY_WEEKDAY &&
i_cal_recurrence_get_by_day (rrule, 6) != I_CAL_SUNDAY_WEEKDAY)
{
recur->frequency = GCAL_RECURRENCE_MON_FRI;
}
@@ -200,11 +202,11 @@ gcal_recurrence_parse_recurrence_rules (ECalComponent *comp)
break;
}
case ICAL_MONTHLY_RECURRENCE:
case I_CAL_MONTHLY_RECURRENCE:
recur->frequency = GCAL_RECURRENCE_MONTHLY;
break;
case ICAL_YEARLY_RECURRENCE:
case I_CAL_YEARLY_RECURRENCE:
recur->frequency = GCAL_RECURRENCE_YEARLY;
break;
@@ -212,21 +214,32 @@ gcal_recurrence_parse_recurrence_rules (ECalComponent *comp)
recur->frequency = GCAL_RECURRENCE_OTHER;
}
if (rrule.count > 0)
if (i_cal_recurrence_get_count (rrule) > 0)
{
recur->limit_type = GCAL_RECURRENCE_COUNT;
recur->limit.count = rrule.count;
}
else if (rrule.until.year != 0)
{
recur->limit_type = GCAL_RECURRENCE_UNTIL;
recur->limit.until = gcal_date_time_from_icaltime (&rrule.until);
recur->limit.count = i_cal_recurrence_get_count (rrule);
}
else
{
recur->limit_type = GCAL_RECURRENCE_FOREVER;
ICalTime *until;
until = i_cal_recurrence_get_until (rrule);
if (i_cal_time_get_year (until) != 0)
{
recur->limit_type = GCAL_RECURRENCE_UNTIL;
recur->limit.until = gcal_date_time_from_icaltime (until);
}
else
{
recur->limit_type = GCAL_RECURRENCE_FOREVER;
}
g_clear_object (&until);
}
g_clear_object (&rrule);
return recur;
}
@@ -236,72 +249,80 @@ gcal_recurrence_parse_recurrence_rules (ECalComponent *comp)
*
* Converts @recur into corresponding rrule.
*
* Returns: (transfer full): a #struct icalrecurrencetype
* Returns: (transfer full): an #ICalRecurrence
*/
struct icalrecurrencetype*
ICalRecurrence*
gcal_recurrence_to_rrule (GcalRecurrence *recur)
{
struct icalrecurrencetype *rrule;
ICalRecurrence *rrule;
if (!recur)
return NULL;
/* Initialize and clear the rrule to get rid of unwanted fields */
rrule = g_new0 (struct icalrecurrencetype, 1);
icalrecurrencetype_clear (rrule);
rrule = i_cal_recurrence_new ();
switch (recur->frequency)
{
case GCAL_RECURRENCE_DAILY:
rrule->freq = ICAL_DAILY_RECURRENCE;
i_cal_recurrence_set_freq (rrule, I_CAL_DAILY_RECURRENCE);
break;
case GCAL_RECURRENCE_WEEKLY:
rrule->freq = ICAL_WEEKLY_RECURRENCE;
i_cal_recurrence_set_freq (rrule, I_CAL_WEEKLY_RECURRENCE);
break;
case GCAL_RECURRENCE_MONTHLY:
rrule->freq = ICAL_MONTHLY_RECURRENCE;
i_cal_recurrence_set_freq (rrule, I_CAL_MONTHLY_RECURRENCE);
break;
case GCAL_RECURRENCE_YEARLY:
rrule->freq = ICAL_YEARLY_RECURRENCE;
i_cal_recurrence_set_freq (rrule, I_CAL_YEARLY_RECURRENCE);
break;
case GCAL_RECURRENCE_NO_REPEAT:
rrule->freq = ICAL_NO_RECURRENCE;
i_cal_recurrence_set_freq (rrule, I_CAL_NO_RECURRENCE);
break;
case GCAL_RECURRENCE_MON_FRI:
{
rrule->freq = ICAL_WEEKLY_RECURRENCE;
rrule->by_day[0] = ICAL_MONDAY_WEEKDAY;
rrule->by_day[1] = ICAL_TUESDAY_WEEKDAY;
rrule->by_day[2] = ICAL_WEDNESDAY_WEEKDAY;
rrule->by_day[3] = ICAL_THURSDAY_WEEKDAY;
rrule->by_day[4] = ICAL_FRIDAY_WEEKDAY;
i_cal_recurrence_set_freq (rrule, I_CAL_WEEKLY_RECURRENCE);
i_cal_recurrence_set_by_day (rrule, 0, I_CAL_MONDAY_WEEKDAY);
i_cal_recurrence_set_by_day (rrule, 1, I_CAL_TUESDAY_WEEKDAY);
i_cal_recurrence_set_by_day (rrule, 2, I_CAL_WEDNESDAY_WEEKDAY);
i_cal_recurrence_set_by_day (rrule, 3, I_CAL_THURSDAY_WEEKDAY);
i_cal_recurrence_set_by_day (rrule, 4, I_CAL_FRIDAY_WEEKDAY);
break;
}
default:
rrule->freq = ICAL_NO_RECURRENCE;
i_cal_recurrence_set_freq (rrule, I_CAL_NO_RECURRENCE);
break;
}
switch (recur->limit_type)
{
case GCAL_RECURRENCE_COUNT:
rrule->count = recur->limit.count;
i_cal_recurrence_set_count (rrule, recur->limit.count);
break;
case GCAL_RECURRENCE_UNTIL:
{
rrule->until.second = g_date_time_get_second (recur->limit.until);
rrule->until.minute = g_date_time_get_minute (recur->limit.until);
rrule->until.hour = g_date_time_get_hour (recur->limit.until);
rrule->until.day = g_date_time_get_day_of_month (recur->limit.until);
rrule->until.month = g_date_time_get_month (recur->limit.until);
rrule->until.year = g_date_time_get_year (recur->limit.until);
ICalTime *until;
until = i_cal_time_new_null_time ();
i_cal_time_set_date (until,
g_date_time_get_year (recur->limit.until),
g_date_time_get_month (recur->limit.until),
g_date_time_get_day_of_month (recur->limit.until));
i_cal_time_set_time (until,
g_date_time_get_hour (recur->limit.until),
g_date_time_get_minute (recur->limit.until),
g_date_time_get_second (recur->limit.until));
i_cal_recurrence_set_until (rrule, until);
g_clear_object (&until);
break;
}
+1 -1
View File
@@ -84,7 +84,7 @@ gboolean gcal_recurrence_is_equal (GcalRecurrence
GcalRecurrence* gcal_recurrence_parse_recurrence_rules (ECalComponent *comp);
struct icalrecurrencetype* gcal_recurrence_to_rrule (GcalRecurrence *recur);
ICalRecurrence* gcal_recurrence_to_rrule (GcalRecurrence *recur);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalRecurrence, gcal_recurrence_unref)