aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util/cal-component.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@helixcode.com>2000-07-19 08:26:37 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2000-07-19 08:26:37 +0800
commit0557f1946751d9fc7f4c894fa46b7fd791db0c73 (patch)
tree85c3a2fb12bc7643421d4aba971d86c55807aebd /calendar/cal-util/cal-component.c
parent647d16e85b27fda1143b79b34252519c8b249a84 (diff)
downloadgsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.tar
gsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.tar.gz
gsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.tar.bz2
gsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.tar.lz
gsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.tar.xz
gsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.tar.zst
gsoc2013-evolution-0557f1946751d9fc7f4c894fa46b7fd791db0c73.zip
Free the icalcomponent if this is an unattached alarm.
2000-07-18 Federico Mena Quintero <federico@helixcode.com> * cal-util/cal-component.c (cal_component_alarm_free): Free the icalcomponent if this is an unattached alarm. (scan_alarm_property): Handle the TRIGGER property. (cal_component_alarm_get_trigger): Ditto. Royal pain. (cal_component_alarm_set_trigger): Ditto. Less pain. svn path=/trunk/; revision=4216
Diffstat (limited to 'calendar/cal-util/cal-component.c')
-rw-r--r--calendar/cal-util/cal-component.c147
1 files changed, 146 insertions, 1 deletions
diff --git a/calendar/cal-util/cal-component.c b/calendar/cal-util/cal-component.c
index 2ff980a0f6..0d5b829520 100644
--- a/calendar/cal-util/cal-component.c
+++ b/calendar/cal-util/cal-component.c
@@ -95,6 +95,7 @@ struct _CalComponentAlarm {
/* Properties */
icalproperty *action;
+ icalproperty *trigger;
};
@@ -2059,6 +2060,10 @@ scan_alarm_property (CalComponentAlarm *alarm, icalproperty *prop)
alarm->action = prop;
break;
+ case ICAL_TRIGGER_PROPERTY:
+ alarm->trigger = prop;
+ break;
+
default:
break;
}
@@ -2125,8 +2130,14 @@ cal_component_alarm_free (CalComponentAlarm *alarm)
{
g_return_if_fail (alarm != NULL);
- alarm->parent = NULL;
+ g_assert (alarm->icalcomp != NULL);
+
+ if (icalcomponent_get_parent (alarm->icalcomp) != NULL)
+ icalcomponent_free (alarm->icalcomp);
+
alarm->icalcomp = NULL;
+
+ alarm->parent = NULL;
alarm->action = NULL;
g_free (alarm);
@@ -2147,6 +2158,8 @@ cal_component_alarm_get_action (CalComponentAlarm *alarm, CalComponentAlarmActio
g_return_if_fail (alarm != NULL);
g_return_if_fail (action != NULL);
+ g_assert (alarm->icalcomp != NULL);
+
if (!alarm->action) {
*action = CAL_COMPONENT_ALARM_NONE;
return;
@@ -2182,6 +2195,8 @@ cal_component_alarm_set_action (CalComponentAlarm *alarm, CalComponentAlarmActio
g_return_if_fail (action != CAL_COMPONENT_ALARM_NONE);
g_return_if_fail (action != CAL_COMPONENT_ALARM_UNKNOWN);
+ g_assert (alarm->icalcomp != NULL);
+
switch (action) {
case CAL_COMPONENT_ALARM_AUDIO:
str = "AUDIO";
@@ -2211,3 +2226,133 @@ cal_component_alarm_set_action (CalComponentAlarm *alarm, CalComponentAlarmActio
icalcomponent_add_property (alarm->icalcomp, alarm->action);
}
}
+
+/**
+ * cal_component_alarm_get_trigger:
+ * @alarm: An alarm.
+ * @trigger: Return value for the trigger time.
+ *
+ * Queries the trigger time for an alarm.
+ **/
+void
+cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrigger **trigger)
+{
+ icalparameter *param;
+ union icaltriggertype t;
+
+ g_return_if_fail (alarm != NULL);
+ g_return_if_fail (trigger != NULL);
+
+ g_assert (alarm->icalcomp != NULL);
+
+ if (!alarm->trigger) {
+ *trigger = NULL;
+ return;
+ }
+
+ *trigger = g_new (CalComponentAlarmTrigger, 1);
+
+ /* Get trigger type */
+
+ param = icalproperty_get_first_parameter (alarm->trigger, ICAL_VALUE_PARAMETER);
+
+ if (param) {
+ icalparameter_value value;
+
+ value = icalparameter_get_value (param);
+
+ switch (value) {
+ case ICAL_VALUE_DURATION:
+ (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_RELATIVE;
+ break;
+
+ case ICAL_VALUE_DATETIME:
+ (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE;
+ break;
+
+ default:
+ g_message ("cal_component_alarm_get_trigger(): Unknown value for trigger "
+ "value %d; using RELATIVE", value);
+
+ (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_RELATIVE;
+ break;
+ }
+ } else
+ (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_RELATIVE;
+
+ /* Get trigger value and the RELATED parameter */
+
+ t = icalproperty_get_trigger (alarm->trigger);
+
+ switch ((*trigger)->type) {
+ case CAL_COMPONENT_ALARM_TRIGGER_RELATIVE:
+ (*trigger)->u.relative.duration = t.duration;
+
+ param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER);
+ if (param) {
+ icalparameter_related rel;
+
+ rel = icalparameter_get_related (param);
+
+ switch (rel) {
+ case ICAL_RELATED_START:
+ (*trigger)->u.relative.related =
+ CAL_COMPONENT_ALARM_TRIGGER_RELATED_START;
+ break;
+
+ case ICAL_RELATED_END:
+ (*trigger)->u.relative.related =
+ CAL_COMPONENT_ALARM_TRIGGER_RELATED_END;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+ } else
+ (*trigger)->u.relative.related = CAL_COMPONENT_ALARM_TRIGGER_RELATED_START;
+
+ break;
+
+ case CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE:
+ (*trigger)->u.absolute = t.time;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+void
+cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrigger *trigger)
+{
+ union icaltriggertype t;
+
+ g_return_if_fail (alarm != NULL);
+ g_return_if_fail (trigger != NULL);
+
+ g_assert (alarm->icalcomp != NULL);
+
+ /* Set the value */
+
+ switch (trigger->type) {
+ case CAL_COMPONENT_ALARM_TRIGGER_RELATIVE:
+ t.duration = trigger->u.relative.duration;
+ break;
+
+ case CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE:
+ t.time = trigger->u.absolute;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ if (alarm->trigger)
+ icalproperty_set_trigger (alarm->trigger, t);
+ else {
+ alarm->trigger = icalproperty_new_trigger (t);
+ icalcomponent_add_property (alarm->icalcomp, alarm->trigger);
+ }
+
+ /* Set the parameters */
+}