aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog8
-rw-r--r--calendar/cal-util/cal-component.c147
-rw-r--r--calendar/cal-util/cal-component.h27
3 files changed, 181 insertions, 1 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index b7a7dcea40..8cdae01224 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
2000-07-17 Federico Mena Quintero <federico@helixcode.com>
* cal-client/cal-client.c (cal_client_get_object): Fixed inline
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 */
+}
diff --git a/calendar/cal-util/cal-component.h b/calendar/cal-util/cal-component.h
index d226940586..664599f9f6 100644
--- a/calendar/cal-util/cal-component.h
+++ b/calendar/cal-util/cal-component.h
@@ -182,6 +182,29 @@ typedef enum {
CAL_COMPONENT_ALARM_UNKNOWN
} CalComponentAlarmAction;
+typedef enum {
+ CAL_COMPONENT_ALARM_TRIGGER_RELATIVE,
+ CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE
+} CalComponentAlarmTriggerType;
+
+typedef enum {
+ CAL_COMPONENT_ALARM_TRIGGER_RELATED_START,
+ CAL_COMPONENT_ALARM_TRIGGER_RELATED_END
+} CalComponentAlarmTriggerRelated;
+
+typedef struct {
+ CalComponentAlarmTriggerType type;
+
+ union {
+ struct {
+ struct icaldurationtype duration;
+ CalComponentAlarmTriggerRelated related;
+ } relative;
+
+ struct icaltimetype absolute;
+ } u;
+} CalComponentAlarmTrigger;
+
CalComponentAlarm *cal_component_get_first_alarm (CalComponent *comp);
CalComponentAlarm *cal_component_get_next_alarm (CalComponent *comp);
@@ -190,6 +213,10 @@ void cal_component_alarm_free (CalComponentAlarm *alarm);
void cal_component_alarm_get_action (CalComponentAlarm *alarm, CalComponentAlarmAction *action);
void cal_component_alarm_set_action (CalComponentAlarm *alarm, CalComponentAlarmAction action);
+void cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrigger **trigger);
+void cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrigger *trigger);
+void cal_component_alarm_free_trigger (CalComponentAlarmTrigger *trigger);
+
END_GNOME_DECLS