From 8d96fe16f15f653d0809603ccaecd677e5708d8d Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 18 Dec 2000 23:47:52 +0000 Subject: Alarm instance generation support for the Wombat. 2000-12-18 Federico Mena Quintero Alarm instance generation support for the Wombat. * idl/evolution-calendar.idl (Cal::CalAlarmInstance): Changed to have an alarm UID, the trigger time, and the actual occurrence time. (Cal::CalComponentAlarms): New structure to hold a pair of a component and its alarms that trigger in a particular range of time. (Cal::getAlarmsInRange): Changed to return a CalComponentAlarmsSeq. * cal-util/cal-component.h (CalAlarmInstance): New C-side structure to match the one on the IDL. (CalComponentAlarms): Ditto. (CalAlarmAction): Renamed from CalComponentAlarmAction. (CalAlarmTriggerType): Renamed from CalComponentAlarmTriggerType. Encoded the START and END parameters for the RELATED parameter in this enum, too. Added a NONE value for invalid or missing trigger specifications. (CalComponentAlarmTriggerRelated): Removed. (CalAlarmTrigger): Renamed from CalComponentAlarmTrigger. Renamed the duration/time fields to rel_duration/abs_time, respectively. * cal-util/cal-component.c (cal_component_alarm_get_trigger): Changed to use the new trigger structure. (cal_component_alarm_set_trigger): Likewise. (cal_component_alarm_free_trigger): Removed function. (cal_component_has_alarms): Count the elements in the alarm_uid_hash instead of trying to fetch the first alarm subcomponent. (cal_component_alarms_free): New function to free a CalComponentAlarms structure. (CalComponentAlarmPrivate): Added an uid property pointer. (scan_alarm_property): Scan for the our extension UID property. (cal_component_alarm_get_uid): New function. * pcs/cal-backend.h (CalBackendClass): Changed the signatures of the ::get_alarms_in_range() and ::get_alarms_for_object() methods. * pcs/cal-backend.c (cal_backend_get_alarms_in_range): Changed signature; use the new method. (cal_backend_get_alarms_for_object): Likewise. * pcs/cal-backend-file.c (compute_alarm_range): New spiffy function to compute a range of time for alarm occurrences. (add_alarm_occurrences_cb): New function to add alarms for a particular occurrence of the component. (generate_absolute_triggers): New function to add the absolute alarm triggers. (generate_alarms_for_comp): New function to generate all the alarm instances for a component. (cal_backend_file_get_alarms_in_range): Implemented. * pcs/cal.c (Cal_get_alarms_in_range): Use the new CalBackend API. (Cal_get_alarms_for_object): Likewise. (build_alarm_instance_seq): Removed old function. * cal-util/cal-util.c (cal_alarm_instance_list_free): Removed function. * cal-client/cal-client.c (build_component_alarms_list): New function to demarshal the component alarms sequence. (build_alarm_instance_list): New function to demarshal the alarm instances sequence. (cal_client_get_alarms_in_range): Updated for the new API. (cal_client_get_alarms_for_object): Updated for the new API. * gui/gnome-cal.c: Temporary #ifdef-ing out of alarm-related stuff to make it build. svn path=/trunk/; revision=7076 --- calendar/cal-util/cal-component.c | 190 +++++++++++++++++++++----------------- 1 file changed, 106 insertions(+), 84 deletions(-) (limited to 'calendar/cal-util/cal-component.c') diff --git a/calendar/cal-util/cal-component.c b/calendar/cal-util/cal-component.c index c7a1e6e324..1ece361da7 100644 --- a/calendar/cal-util/cal-component.c +++ b/calendar/cal-util/cal-component.c @@ -118,6 +118,9 @@ struct _CalComponentAlarm { /* Alarm icalcomponent we wrap */ icalcomponent *icalcomp; + /* Our extension UID property */ + icalproperty *uid; + /* Properties */ icalproperty *action; @@ -3433,7 +3436,6 @@ gboolean cal_component_has_alarms (CalComponent *comp) { CalComponentPrivate *priv; - icalcomponent *subcomp; g_return_val_if_fail (comp != NULL, FALSE); g_return_val_if_fail (IS_CAL_COMPONENT (comp), FALSE); @@ -3441,9 +3443,7 @@ cal_component_has_alarms (CalComponent *comp) priv = comp->priv; g_return_val_if_fail (priv->icalcomp != NULL, FALSE); - subcomp = icalcomponent_get_first_component (priv->icalcomp, ICAL_VALARM_COMPONENT); - - return subcomp != NULL ? TRUE : FALSE; + return g_hash_table_size (priv->alarm_uid_hash) != 0; } /* Scans an icalproperty from a calendar component and adds its mapping to our @@ -3453,6 +3453,7 @@ static void scan_alarm_property (CalComponentAlarm *alarm, icalproperty *prop) { icalproperty_kind kind; + const char *xname; kind = icalproperty_isa (prop); @@ -3465,6 +3466,15 @@ scan_alarm_property (CalComponentAlarm *alarm, icalproperty *prop) alarm->trigger = prop; break; + case ICAL_X_PROPERTY: + xname = icalproperty_get_x_name (prop); + g_assert (xname != NULL); + + if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0) + alarm->uid = prop; + + break; + default: break; } @@ -3481,12 +3491,15 @@ make_alarm (CalComponent *comp, icalcomponent *subcomp) alarm->parent = comp; alarm->icalcomp = subcomp; + alarm->uid = NULL; for (prop = icalcomponent_get_first_property (subcomp, ICAL_ANY_PROPERTY); prop; prop = icalcomponent_get_next_property (subcomp, ICAL_ANY_PROPERTY)) scan_alarm_property (alarm, prop); + g_assert (alarm->uid != NULL); + return alarm; } @@ -3588,6 +3601,50 @@ cal_component_alarm_free (CalComponentAlarm *alarm) g_free (alarm); } +/** + * cal_component_alarms_free: + * @alarms: Component alarms structure. + * + * Frees a #CalComponentAlarms structure. + **/ +void +cal_component_alarms_free (CalComponentAlarms *alarms) +{ + GSList *l; + + g_return_if_fail (alarms != NULL); + + g_assert (alarms->comp != NULL); + gtk_object_unref (GTK_OBJECT (alarms->comp)); + + for (l = alarms->alarms; l; l = l->next) { + CalAlarmInstance *instance; + + instance = l->data; + g_assert (instance != NULL); + g_free (instance); + } + + g_free (alarms->alarms); + g_free (alarms); +} + +/** + * cal_component_alarm_get_uid: + * @alarm: An alarm subcomponent. + * + * Queries the unique identifier of an alarm subcomponent. + * + * Return value: UID of the alarm. + **/ +const char * +cal_component_alarm_get_uid (CalComponentAlarm *alarm) +{ + g_return_val_if_fail (alarm != NULL, NULL); + + return alarm_uid_from_prop (alarm->uid); +} + /** * cal_component_alarm_get_action: * @alarm: An alarm. @@ -3596,7 +3653,7 @@ cal_component_alarm_free (CalComponentAlarm *alarm) * Queries the action type of an alarm. **/ void -cal_component_alarm_get_action (CalComponentAlarm *alarm, CalComponentAlarmAction *action) +cal_component_alarm_get_action (CalComponentAlarm *alarm, CalAlarmAction *action) { const char *str; @@ -3606,22 +3663,22 @@ cal_component_alarm_get_action (CalComponentAlarm *alarm, CalComponentAlarmActio g_assert (alarm->icalcomp != NULL); if (!alarm->action) { - *action = CAL_COMPONENT_ALARM_NONE; + *action = CAL_ALARM_NONE; return; } str = icalproperty_get_action (alarm->action); if (strcasecmp (str, "AUDIO") == 0) - *action = CAL_COMPONENT_ALARM_AUDIO; + *action = CAL_ALARM_AUDIO; else if (strcasecmp (str, "DISPLAY") == 0) - *action = CAL_COMPONENT_ALARM_DISPLAY; + *action = CAL_ALARM_DISPLAY; else if (strcasecmp (str, "EMAIL") == 0) - *action = CAL_COMPONENT_ALARM_EMAIL; + *action = CAL_ALARM_EMAIL; else if (strcasecmp (str, "PROCEDURE") == 0) - *action = CAL_COMPONENT_ALARM_PROCEDURE; + *action = CAL_ALARM_PROCEDURE; else - *action = CAL_COMPONENT_ALARM_UNKNOWN; + *action = CAL_ALARM_UNKNOWN; } /** @@ -3632,30 +3689,30 @@ cal_component_alarm_get_action (CalComponentAlarm *alarm, CalComponentAlarmActio * Sets the action type for an alarm. **/ void -cal_component_alarm_set_action (CalComponentAlarm *alarm, CalComponentAlarmAction action) +cal_component_alarm_set_action (CalComponentAlarm *alarm, CalAlarmAction action) { char *str; g_return_if_fail (alarm != NULL); - g_return_if_fail (action != CAL_COMPONENT_ALARM_NONE); - g_return_if_fail (action != CAL_COMPONENT_ALARM_UNKNOWN); + g_return_if_fail (action != CAL_ALARM_NONE); + g_return_if_fail (action != CAL_ALARM_UNKNOWN); g_assert (alarm->icalcomp != NULL); switch (action) { - case CAL_COMPONENT_ALARM_AUDIO: + case CAL_ALARM_AUDIO: str = "AUDIO"; break; - case CAL_COMPONENT_ALARM_DISPLAY: + case CAL_ALARM_DISPLAY: str = "DISPLAY"; break; - case CAL_COMPONENT_ALARM_EMAIL: + case CAL_ALARM_EMAIL: str = "EMAIL"; break; - case CAL_COMPONENT_ALARM_PROCEDURE: + case CAL_ALARM_PROCEDURE: str = "PROCEDURE"; break; @@ -3675,16 +3732,16 @@ cal_component_alarm_set_action (CalComponentAlarm *alarm, CalComponentAlarmActio /** * cal_component_alarm_get_trigger: * @alarm: An alarm. - * @trigger: Return value for the trigger time. This should be freed using the - * cal_component_alarm_free_trigger() function. + * @trigger: Return value for the trigger time. * * Queries the trigger time for an alarm. **/ void -cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrigger **trigger) +cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalAlarmTrigger *trigger) { icalparameter *param; union icaltriggertype t; + gboolean relative; g_return_if_fail (alarm != NULL); g_return_if_fail (trigger != NULL); @@ -3692,16 +3749,13 @@ cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig g_assert (alarm->icalcomp != NULL); if (!alarm->trigger) { - *trigger = NULL; + trigger->type = CAL_ALARM_TRIGGER_NONE; return; } - *trigger = g_new (CalComponentAlarmTrigger, 1); - /* Get trigger type */ param = icalproperty_get_first_parameter (alarm->trigger, ICAL_VALUE_PARAMETER); - if (param) { icalparameter_value value; @@ -3709,30 +3763,29 @@ cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig switch (value) { case ICAL_VALUE_DURATION: - (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_RELATIVE; + relative = TRUE; break; case ICAL_VALUE_DATETIME: - (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE; + relative = FALSE; 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; + relative = TRUE; break; } } else - (*trigger)->type = CAL_COMPONENT_ALARM_TRIGGER_RELATIVE; + relative = TRUE; /* 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; + if (relative) { + trigger->u.rel_duration = t.duration; param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER); if (param) { @@ -3742,29 +3795,21 @@ cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig switch (rel) { case ICAL_RELATED_START: - (*trigger)->u.relative.related = - CAL_COMPONENT_ALARM_TRIGGER_RELATED_START; + trigger->type = CAL_ALARM_TRIGGER_RELATIVE_START; break; case ICAL_RELATED_END: - (*trigger)->u.relative.related = - CAL_COMPONENT_ALARM_TRIGGER_RELATED_END; + trigger->type = CAL_ALARM_TRIGGER_RELATIVE_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 (); + trigger->type = CAL_ALARM_TRIGGER_RELATIVE_START; + } else { + trigger->u.abs_time = t.time; + trigger->type = CAL_ALARM_TRIGGER_ABSOLUTE; } } @@ -3776,7 +3821,7 @@ cal_component_alarm_get_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig * Sets the trigger time of an alarm. **/ void -cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrigger *trigger) +cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalAlarmTrigger trigger) { union icaltriggertype t; icalparameter *param; @@ -3784,7 +3829,7 @@ cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig icalparameter_related related; g_return_if_fail (alarm != NULL); - g_return_if_fail (trigger != NULL); + g_return_if_fail (trigger.type != CAL_ALARM_TRIGGER_NONE); g_assert (alarm->icalcomp != NULL); @@ -3798,32 +3843,23 @@ cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig /* Set the value */ - value_type = ICAL_DURATION_VALUE; /* Keep GCC happy */ - related = ICAL_RELATED_START; /* Ditto */ + related = ICAL_RELATED_START; /* Keep GCC happy */ - switch (trigger->type) { - case CAL_COMPONENT_ALARM_TRIGGER_RELATIVE: - t.duration = trigger->u.relative.duration; + switch (trigger.type) { + case CAL_ALARM_TRIGGER_RELATIVE_START: + t.duration = trigger.u.rel_duration; value_type = ICAL_DURATION_VALUE; + related = ICAL_RELATED_START; + break; - switch (trigger->u.relative.related) { - case CAL_COMPONENT_ALARM_TRIGGER_RELATED_START: - related = ICAL_RELATED_START; - break; - - case CAL_COMPONENT_ALARM_TRIGGER_RELATED_END: - related = ICAL_RELATED_END; - break; - - default: - g_assert_not_reached (); - return; - } - + case CAL_ALARM_TRIGGER_RELATIVE_END: + t.duration = trigger.u.rel_duration; + value_type = ICAL_DURATION_VALUE; + related = ICAL_RELATED_END; break; - case CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE: - t.time = trigger->u.absolute; + case CAL_ALARM_TRIGGER_ABSOLUTE: + t.time = trigger.u.abs_time; value_type = ICAL_DATETIME_VALUE; break; @@ -3847,7 +3883,7 @@ cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig /* Related parameter */ - if (trigger->type == CAL_COMPONENT_ALARM_TRIGGER_RELATIVE) { + if (trigger.type != CAL_ALARM_TRIGGER_ABSOLUTE) { param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER); if (param) @@ -3858,17 +3894,3 @@ cal_component_alarm_set_trigger (CalComponentAlarm *alarm, CalComponentAlarmTrig } } } - -/** - * cal_component_alarm_free_trigger: - * @trigger: A #CalComponentAlarmTrigger structure. - * - * Frees a #CalComponentAlarmTrigger structure. - **/ -void -cal_component_alarm_free_trigger (CalComponentAlarmTrigger *trigger) -{ - g_return_if_fail (trigger != NULL); - - g_free (trigger); -} -- cgit v1.2.3