diff options
Diffstat (limited to 'calendar/cal-util')
-rw-r--r-- | calendar/cal-util/cal-component.c | 163 | ||||
-rw-r--r-- | calendar/cal-util/cal-component.h | 10 |
2 files changed, 156 insertions, 17 deletions
diff --git a/calendar/cal-util/cal-component.c b/calendar/cal-util/cal-component.c index 60e0a1bbd5..ff3bcd6d96 100644 --- a/calendar/cal-util/cal-component.c +++ b/calendar/cal-util/cal-component.c @@ -95,6 +95,9 @@ struct _CalComponentPrivate { icalproperty *transparency; icalproperty *url; + icalproperty *pilot_id; + icalproperty *pilot_status; + /* Whether we should increment the sequence number when piping the * object over the wire. */ @@ -560,6 +563,13 @@ scan_property (CalComponent *comp, icalproperty *prop) priv->url = prop; break; + case ICAL_X_PROPERTY: + if (!strcmp (icalproperty_get_x_name (prop), "X-PILOT-ID")) + priv->pilot_id = prop; + if (!strcmp (icalproperty_get_x_name (prop), "X-PILOT-STATUS")) + priv->pilot_status = prop; + break; + default: break; } @@ -2882,11 +2892,29 @@ cal_component_set_url (CalComponent *comp, const char *url) * Queries the pilot id of a calendar component object, if any. **/ void -cal_component_get_pilot_id (CalComponent *comp, unsigned long *pilot_id) +cal_component_get_pilot_id (CalComponent *comp, unsigned long **pilot_id) { - /* pilot_id maybe should be recordid_t */ - /* FIX ME */ - *pilot_id = 0; + CalComponentPrivate *priv; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + + /* Pilot id might want to be recordid_t */ + if (priv->pilot_id) { + icalvalue *value; + char *text; + + value = icalproperty_get_value (priv->pilot_id); + text = icalvalue_get_text (value); + + *pilot_id = g_new (unsigned long, 1); + **pilot_id = strtoul (text, NULL, 0); + } else { + *pilot_id = NULL; + } } /** @@ -2897,10 +2925,41 @@ cal_component_get_pilot_id (CalComponent *comp, unsigned long *pilot_id) * Sets the pilot id of a clanedar component object. **/ void -cal_component_set_pilot_id (CalComponent *comp, unsigned long pilot_id) +cal_component_set_pilot_id (CalComponent *comp, unsigned long *pilot_id) { + CalComponentPrivate *priv; + icalvalue *value; + char text[256]; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + /* pilot_id maybe should be recordid_t */ - /* FIX ME */ + if (!pilot_id) { + if (priv->pilot_id) { + icalcomponent_remove_property (priv->icalcomp, + priv->pilot_id); + icalproperty_free (priv->pilot_id); + priv->pilot_id = NULL; + } + + return; + } + + /* iCalendar spec does not support unsigned longs directly */ + g_snprintf (text, 256, "%lu", *pilot_id); + value = icalvalue_new_text (text); + + if (!priv->pilot_id) { + priv->pilot_id = icalproperty_new (ICAL_X_PROPERTY); + icalproperty_set_x_name (priv->pilot_id, "X-PILOT-ID"); + icalcomponent_add_property (priv->icalcomp, priv->pilot_id); + } + + icalproperty_set_value (priv->pilot_id, value); } /** @@ -2911,11 +2970,30 @@ cal_component_set_pilot_id (CalComponent *comp, unsigned long pilot_id) * Queries the pilot status of a calendar component object, if any. **/ void -cal_component_get_pilot_status (CalComponent *comp, unsigned long *pilot_status) +cal_component_get_pilot_status (CalComponent *comp, + unsigned long **pilot_status) { - /* FIX ME */ - /* pilot_status should be iCalPilotState ? */ - *pilot_status = 0; + CalComponentPrivate *priv; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + + /* Pilot id might want to be recordid_t */ + if (priv->pilot_status) { + icalvalue *value; + char *text; + + value = icalproperty_get_value (priv->pilot_status); + text = icalvalue_get_text (value); + + *pilot_status = g_new (unsigned long, 1); + **pilot_status = strtoul (text, NULL, 0); + } else { + *pilot_status = NULL; + } } /** @@ -2926,10 +3004,41 @@ cal_component_get_pilot_status (CalComponent *comp, unsigned long *pilot_status) * Sets the pilot id of a clanedar component object. **/ void -cal_component_set_pilot_status (CalComponent *comp, unsigned long pilot_status) +cal_component_set_pilot_status (CalComponent *comp, + unsigned long *pilot_status) { - /* pilot_id maybe should be recordid_t */ - /* FIX ME */ + CalComponentPrivate *priv; + icalvalue *value; + char text[256]; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + + if (!pilot_status) { + if (priv->pilot_status) { + icalcomponent_remove_property (priv->icalcomp, + priv->pilot_status); + icalproperty_free (priv->pilot_status); + priv->pilot_status = NULL; + } + + return; + } + + /* iCalendar spec does not support unsigned longs directly */ + g_snprintf (text, 256, "%lu", *pilot_status); + value = icalvalue_new_text (text); + + if (!priv->pilot_status) { + priv->pilot_status = icalproperty_new (ICAL_X_PROPERTY); + icalproperty_set_x_name (priv->pilot_status, "X-PILOT-STATUS"); + icalcomponent_add_property (priv->icalcomp, priv->pilot_status); + } + + icalproperty_set_value (priv->pilot_status, value); } @@ -3112,6 +3221,34 @@ cal_component_free_sequence (int *sequence) } /** + * cal_component_free_pilot_id: + * @sequence: Sequence number value. + * + * Frees a sequence number value. + **/ +void +cal_component_free_pilot_id (unsigned long *pilot_id) +{ + g_return_if_fail (pilot_id != NULL); + + g_free (pilot_id); +} + +/** + * cal_component_free_pilot_status: + * @sequence: Sequence number value. + * + * Frees a sequence number value. + **/ +void +cal_component_free_pilot_status (unsigned long *pilot_status) +{ + g_return_if_fail (pilot_status != NULL); + + g_free (pilot_status); +} + +/** * cal_component_free_text_list: * @text_list: List of #CalComponentText structures. * diff --git a/calendar/cal-util/cal-component.h b/calendar/cal-util/cal-component.h index 2f9067896b..5fa759748f 100644 --- a/calendar/cal-util/cal-component.h +++ b/calendar/cal-util/cal-component.h @@ -239,11 +239,11 @@ void cal_component_set_transparency (CalComponent *comp, CalComponentTransparenc void cal_component_get_url (CalComponent *comp, const char **url); void cal_component_set_url (CalComponent *comp, const char *url); -void cal_component_get_pilot_id (CalComponent *comp, unsigned long *pilot_id); -void cal_component_set_pilot_id (CalComponent *comp, unsigned long pilot_id); +void cal_component_get_pilot_id (CalComponent *comp, unsigned long **pilot_id); +void cal_component_set_pilot_id (CalComponent *comp, unsigned long *pilot_id); -void cal_component_get_pilot_status (CalComponent *comp, unsigned long *pilot_status); -void cal_component_set_pilot_status (CalComponent *comp, unsigned long pilot_status); +void cal_component_get_pilot_status (CalComponent *comp, unsigned long **pilot_status); +void cal_component_set_pilot_status (CalComponent *comp, unsigned long *pilot_status); /* Functions to free returned values */ @@ -257,6 +257,8 @@ void cal_component_free_priority (int *priority); void cal_component_free_period_list (GSList *period_list); void cal_component_free_recur_list (GSList *recur_list); void cal_component_free_sequence (int *sequence); +void cal_component_free_pilot_id (unsigned long *pilot_status); +void cal_component_free_pilot_status (unsigned long *pilot_status); void cal_component_free_text_list (GSList *text_list); /* Alarms */ |