1 /* Evolution calendar - iCalendar component object
3 * Copyright (C) 2000 Ximian, Inc.
4 * Copyright (C) 2000 Ximian, Inc.
6 * Author: Federico Mena-Quintero <federico@ximian.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU Lesser General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n-lib.h>
28 #include "e-cal-component.h"
29 #include "e-cal-time-util.h"
38 /* Extension property for alarm components so that we can reference them by UID */
39 #define EVOLUTION_ALARM_UID_PROPERTY "X-EVOLUTION-ALARM-UID"
44 icalparameter *cutype_param;
45 icalparameter *member_param;
46 icalparameter *role_param;
47 icalparameter *partstat_param;
48 icalparameter *rsvp_param;
49 icalparameter *delto_param;
50 icalparameter *delfrom_param;
51 icalparameter *sentby_param;
52 icalparameter *cn_param;
53 icalparameter *language_param;
63 icalparameter *altrep_param;
68 icalparameter *tzid_param;
73 icalparameter *sentby_param;
74 icalparameter *cn_param;
75 icalparameter *language_param;
80 icalparameter *value_param;
84 struct datetime recur_time;
86 icalparameter *range_param;
89 /* Private part of the CalComponent structure */
90 struct _ECalComponentPrivate {
91 /* The icalcomponent we wrap */
92 icalcomponent *icalcomp;
99 GSList *attendee_list;
101 icalproperty *categories;
103 icalproperty *classification;
105 GSList *comment_list; /* list of struct text */
107 icalproperty *completed;
109 GSList *contact_list; /* list of struct text */
111 icalproperty *created;
113 GSList *description_list; /* list of struct text */
115 struct datetime dtstart;
116 struct datetime dtend;
118 icalproperty *dtstamp;
120 /* The DURATION property can be used instead of the VEVENT DTEND or
121 the VTODO DUE dates. We do not use it directly ourselves, but we
122 must be able to handle it from incoming data. If a DTEND or DUE
123 is requested, we convert the DURATION if necessary. If DTEND or
124 DUE is set, we remove any DURATION. */
125 icalproperty *duration;
129 GSList *exdate_list; /* list of struct datetime */
130 GSList *exrule_list; /* list of icalproperty objects */
132 struct organizer organizer;
135 icalproperty *last_modified;
136 icalproperty *percent;
137 icalproperty *priority;
139 struct recur_id recur_id;
141 GSList *rdate_list; /* list of struct period */
143 GSList *rrule_list; /* list of icalproperty objects */
145 icalproperty *sequence;
149 icalparameter *altrep_param;
152 icalproperty *transparency;
154 icalproperty *location;
156 GSList *attachment_list;
160 GHashTable *alarm_uid_hash;
162 /* Whether we should increment the sequence number when piping the
163 * object over the wire.
165 guint need_sequence_inc : 1;
168 /* Private structure for alarms */
169 struct _ECalComponentAlarm {
170 /* Alarm icalcomponent we wrap */
171 icalcomponent *icalcomp;
173 /* Our extension UID property */
178 icalproperty *action;
179 icalproperty *attach; /* FIXME: see scan_alarm_property() below */
183 icalparameter *altrep_param;
186 icalproperty *duration;
187 icalproperty *repeat;
188 icalproperty *trigger;
190 GSList *attendee_list;
195 static void e_cal_component_class_init (ECalComponentClass *klass);
196 static void e_cal_component_init (ECalComponent *comp, ECalComponentClass *klass);
197 static void e_cal_component_finalize (GObject *object);
199 static GObjectClass *parent_class;
204 * e_cal_component_get_type:
206 * Registers the #ECalComponent class if necessary, and returns the type ID
209 * Return value: The type ID of the #ECalComponent class.
212 e_cal_component_get_type (void)
214 static GType e_cal_component_type = 0;
216 if (!e_cal_component_type) {
217 static GTypeInfo info = {
218 sizeof (ECalComponentClass),
219 (GBaseInitFunc) NULL,
220 (GBaseFinalizeFunc) NULL,
221 (GClassInitFunc) e_cal_component_class_init,
223 sizeof (ECalComponent),
225 (GInstanceInitFunc) e_cal_component_init
227 e_cal_component_type = g_type_register_static (G_TYPE_OBJECT, "ECalComponent", &info, 0);
230 return e_cal_component_type;
233 /* Class initialization function for the calendar component object */
235 e_cal_component_class_init (ECalComponentClass *klass)
237 GObjectClass *object_class;
239 object_class = (GObjectClass *) klass;
241 parent_class = g_type_class_peek_parent (klass);
243 object_class->finalize = e_cal_component_finalize;
246 /* Object initialization function for the calendar component object */
248 e_cal_component_init (ECalComponent *comp, ECalComponentClass *klass)
250 ECalComponentPrivate *priv;
252 priv = g_new0 (ECalComponentPrivate, 1);
255 priv->alarm_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
258 /* Does a simple g_free() of the elements of a GSList and then frees the list
259 * itself. Returns NULL.
262 free_slist (GSList *slist)
266 for (l = slist; l; l = l->next)
269 g_slist_free (slist);
273 /* Used from g_hash_table_foreach_remove() to free the alarm UIDs hash table.
274 * We do not need to do anything to individual elements since we were storing
275 * the UID pointers inside the icalproperties themselves.
278 free_alarm_cb (gpointer key, gpointer value, gpointer data)
283 /* Frees the internal icalcomponent only if it does not have a parent. If it
284 * does, it means we don't own it and we shouldn't free it.
287 free_icalcomponent (ECalComponent *comp, gboolean free)
289 ECalComponentPrivate *priv;
297 /* Free the icalcomponent */
299 if (free && icalcomponent_get_parent (priv->icalcomp) == NULL) {
300 icalcomponent_free (priv->icalcomp);
301 priv->icalcomp = NULL;
304 /* Free the mappings */
310 for (l = priv->attachment_list; l != NULL; l = l->next)
312 g_slist_free (priv->attachment_list);
313 priv->attachment_list = NULL;
315 for (l = priv->attendee_list; l != NULL; l = l->next)
317 g_slist_free (priv->attendee_list);
318 priv->attendee_list = NULL;
320 priv->categories = NULL;
322 priv->classification = NULL;
323 priv->comment_list = NULL;
324 priv->completed = NULL;
325 priv->contact_list = NULL;
326 priv->created = NULL;
328 priv->description_list = free_slist (priv->description_list);
330 priv->dtend.prop = NULL;
331 priv->dtend.tzid_param = NULL;
333 priv->dtstamp = NULL;
335 priv->dtstart.prop = NULL;
336 priv->dtstart.tzid_param = NULL;
338 priv->due.prop = NULL;
339 priv->due.tzid_param = NULL;
341 priv->duration = NULL;
343 priv->exdate_list = free_slist (priv->exdate_list);
345 g_slist_free (priv->exrule_list);
346 priv->exrule_list = NULL;
349 priv->last_modified = NULL;
350 priv->percent = NULL;
351 priv->priority = NULL;
353 priv->rdate_list = free_slist (priv->rdate_list);
355 g_slist_free (priv->rrule_list);
356 priv->rrule_list = NULL;
358 priv->sequence = NULL;
360 priv->summary.prop = NULL;
361 priv->summary.altrep_param = NULL;
363 priv->transparency = NULL;
365 priv->location = NULL;
367 /* Free the subcomponents */
369 g_hash_table_foreach_remove (priv->alarm_uid_hash, free_alarm_cb, NULL);
373 priv->need_sequence_inc = FALSE;
376 /* Finalize handler for the calendar component object */
378 e_cal_component_finalize (GObject *object)
381 ECalComponentPrivate *priv;
383 g_return_if_fail (object != NULL);
384 g_return_if_fail (E_IS_CAL_COMPONENT (object));
386 comp = E_CAL_COMPONENT (object);
389 free_icalcomponent (comp, TRUE);
390 g_hash_table_destroy (priv->alarm_uid_hash);
391 priv->alarm_uid_hash = NULL;
396 if (G_OBJECT_CLASS (parent_class)->finalize)
397 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
403 * e_cal_component_gen_uid:
405 * Generates a unique identifier suitable for calendar components.
407 * Return value: A unique identifier string. Every time this function is called
408 * a different string is returned.
411 e_cal_component_gen_uid (void)
414 static char *hostname;
415 time_t t = time (NULL);
420 static char buffer [512];
422 if ((gethostname (buffer, sizeof (buffer) - 1) == 0) &&
426 hostname = "localhost";
428 hostname = g_get_host_name ();
432 iso = isodate_from_time_t (t);
433 ret = g_strdup_printf ("%s-%d-%d-%d-%d@%s",
446 * e_cal_component_new:
448 * Creates a new empty calendar component object. Once created, you should set it from an
449 * existing #icalcomponent structure by using e_cal_component_set_icalcomponent() or with a
450 * new empty component type by using e_cal_component_set_new_vtype().
452 * Return value: A newly-created calendar component object.
455 e_cal_component_new (void)
457 return E_CAL_COMPONENT (g_object_new (E_TYPE_CAL_COMPONENT, NULL));
461 * e_cal_component_new_from_string:
462 * @calobj: A string representation of an iCalendar component.
464 * Creates a new calendar component object from the given iCalendar string.
466 * Return value: A calendar component representing the given iCalendar string on
467 * success, NULL if there was an error.
470 e_cal_component_new_from_string (const char *calobj)
473 icalcomponent *icalcomp;
475 g_return_val_if_fail (calobj != NULL, NULL);
477 icalcomp = icalparser_parse_string (calobj);
481 comp = e_cal_component_new ();
482 if (!e_cal_component_set_icalcomponent (comp, icalcomp)) {
483 icalcomponent_free (icalcomp);
484 g_object_unref (comp);
493 * e_cal_component_clone:
494 * @comp: A calendar component object.
496 * Creates a new calendar component object by copying the information from
499 * Return value: A newly-created calendar component with the same values as the
503 e_cal_component_clone (ECalComponent *comp)
505 ECalComponentPrivate *priv;
506 ECalComponent *new_comp;
507 icalcomponent *new_icalcomp;
509 g_return_val_if_fail (comp != NULL, NULL);
510 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
513 g_return_val_if_fail (priv->need_sequence_inc == FALSE, NULL);
515 new_comp = e_cal_component_new ();
517 if (priv->icalcomp) {
518 new_icalcomp = icalcomponent_new_clone (priv->icalcomp);
519 e_cal_component_set_icalcomponent (new_comp, new_icalcomp);
525 /* Scans an attachment property */
527 scan_attachment (GSList **attachment_list, icalproperty *prop)
529 struct attachment *attachment;
531 attachment = g_new (struct attachment, 1);
532 attachment->prop = prop;
534 attachment->attach = icalproperty_get_attach (prop);
536 *attachment_list = g_slist_append (*attachment_list, attachment);
539 /* Scans an attendee property */
541 scan_attendee (GSList **attendee_list, icalproperty *prop)
543 struct attendee *attendee;
545 attendee = g_new (struct attendee, 1);
546 attendee->prop = prop;
548 attendee->cutype_param = icalproperty_get_first_parameter (prop, ICAL_CUTYPE_PARAMETER);
549 attendee->member_param = icalproperty_get_first_parameter (prop, ICAL_MEMBER_PARAMETER);
550 attendee->role_param = icalproperty_get_first_parameter (prop, ICAL_ROLE_PARAMETER);
551 attendee->partstat_param = icalproperty_get_first_parameter (prop, ICAL_PARTSTAT_PARAMETER);
552 attendee->rsvp_param = icalproperty_get_first_parameter (prop, ICAL_RSVP_PARAMETER);
553 attendee->delto_param = icalproperty_get_first_parameter (prop, ICAL_DELEGATEDTO_PARAMETER);
554 attendee->delfrom_param = icalproperty_get_first_parameter (prop, ICAL_DELEGATEDFROM_PARAMETER);
555 attendee->sentby_param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER);
556 attendee->cn_param = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER);
557 attendee->language_param = icalproperty_get_first_parameter (prop, ICAL_LANGUAGE_PARAMETER);
559 *attendee_list = g_slist_append (*attendee_list, attendee);
562 /* Scans a date/time and timezone pair property */
564 scan_datetime (ECalComponent *comp, struct datetime *datetime, icalproperty *prop)
566 ECalComponentPrivate *priv;
570 datetime->prop = prop;
571 datetime->tzid_param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
574 /* Scans an exception date property */
576 scan_exdate (ECalComponent *comp, icalproperty *prop)
578 ECalComponentPrivate *priv;
583 dt = g_new (struct datetime, 1);
585 dt->tzid_param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
587 priv->exdate_list = g_slist_append (priv->exdate_list, dt);
590 /* Scans and attendee property */
592 scan_organizer (ECalComponent *comp, struct organizer *organizer, icalproperty *prop)
594 organizer->prop = prop;
596 organizer->sentby_param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER);
597 organizer->cn_param = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER);
598 organizer->language_param = icalproperty_get_first_parameter (prop, ICAL_LANGUAGE_PARAMETER);
601 /* Scans an icalperiodtype property */
603 scan_period (ECalComponent *comp, GSList **list, icalproperty *prop)
605 struct period *period;
607 period = g_new (struct period, 1);
609 period->value_param = icalproperty_get_first_parameter (prop, ICAL_VALUE_PARAMETER);
611 *list = g_slist_append (*list, period);
615 /* Scans an icalrecurtype property */
617 scan_recur_id (ECalComponent *comp, struct recur_id *recur_id, icalproperty *prop)
619 scan_datetime (comp, &recur_id->recur_time, prop);
621 recur_id->range_param = icalproperty_get_first_parameter (prop, ICAL_RANGE_PARAMETER);
624 /* Scans an icalrecurtype property */
626 scan_recur (ECalComponent *comp, GSList **list, icalproperty *prop)
628 *list = g_slist_append (*list, prop);
631 /* Scans the summary property */
633 scan_summary (ECalComponent *comp, icalproperty *prop)
635 ECalComponentPrivate *priv;
639 priv->summary.prop = prop;
640 priv->summary.altrep_param = icalproperty_get_first_parameter (prop, ICAL_ALTREP_PARAMETER);
643 /* Scans a text (i.e. text + altrep) property */
645 scan_text (ECalComponent *comp, GSList **text_list, icalproperty *prop)
649 text = g_new (struct text, 1);
651 text->altrep_param = icalproperty_get_first_parameter (prop, ICAL_ALTREP_PARAMETER);
653 *text_list = g_slist_append (*text_list, text);
656 /* Scans an icalproperty and adds its mapping to the component */
658 scan_property (ECalComponent *comp, icalproperty *prop)
660 ECalComponentPrivate *priv;
661 icalproperty_kind kind;
665 kind = icalproperty_isa (prop);
668 case ICAL_STATUS_PROPERTY:
672 case ICAL_ATTACH_PROPERTY:
673 scan_attachment (&priv->attachment_list, prop);
676 case ICAL_ATTENDEE_PROPERTY:
677 scan_attendee (&priv->attendee_list, prop);
680 case ICAL_CATEGORIES_PROPERTY:
681 priv->categories = prop;
684 case ICAL_CLASS_PROPERTY:
685 priv->classification = prop;
688 case ICAL_COMMENT_PROPERTY:
689 scan_text (comp, &priv->comment_list, prop);
692 case ICAL_COMPLETED_PROPERTY:
693 priv->completed = prop;
696 case ICAL_CONTACT_PROPERTY:
697 scan_text (comp, &priv->contact_list, prop);
700 case ICAL_CREATED_PROPERTY:
701 priv->created = prop;
704 case ICAL_DESCRIPTION_PROPERTY:
705 scan_text (comp, &priv->description_list, prop);
708 case ICAL_DTEND_PROPERTY:
709 scan_datetime (comp, &priv->dtend, prop);
712 case ICAL_DTSTAMP_PROPERTY:
713 priv->dtstamp = prop;
716 case ICAL_DTSTART_PROPERTY:
717 scan_datetime (comp, &priv->dtstart, prop);
720 case ICAL_DUE_PROPERTY:
721 scan_datetime (comp, &priv->due, prop);
724 case ICAL_DURATION_PROPERTY:
725 priv->duration = prop;
728 case ICAL_EXDATE_PROPERTY:
729 scan_exdate (comp, prop);
732 case ICAL_EXRULE_PROPERTY:
733 scan_recur (comp, &priv->exrule_list, prop);
736 case ICAL_GEO_PROPERTY:
740 case ICAL_LASTMODIFIED_PROPERTY:
741 priv->last_modified = prop;
744 case ICAL_ORGANIZER_PROPERTY:
745 scan_organizer (comp, &priv->organizer, prop);
748 case ICAL_PERCENTCOMPLETE_PROPERTY:
749 priv->percent = prop;
752 case ICAL_PRIORITY_PROPERTY:
753 priv->priority = prop;
756 case ICAL_RECURRENCEID_PROPERTY:
757 scan_recur_id (comp, &priv->recur_id, prop);
760 case ICAL_RDATE_PROPERTY:
761 scan_period (comp, &priv->rdate_list, prop);
764 case ICAL_RRULE_PROPERTY:
765 scan_recur (comp, &priv->rrule_list, prop);
768 case ICAL_SEQUENCE_PROPERTY:
769 priv->sequence = prop;
772 case ICAL_SUMMARY_PROPERTY:
773 scan_summary (comp, prop);
776 case ICAL_TRANSP_PROPERTY:
777 priv->transparency = prop;
780 case ICAL_UID_PROPERTY:
784 case ICAL_URL_PROPERTY:
788 case ICAL_LOCATION_PROPERTY :
789 priv->location = prop;
797 /* Gets our alarm UID string from a property that is known to contain it */
799 alarm_uid_from_prop (icalproperty *prop)
803 g_assert (icalproperty_isa (prop) == ICAL_X_PROPERTY);
805 xstr = icalproperty_get_x (prop);
806 g_assert (xstr != NULL);
811 /* Sets our alarm UID extension property on an alarm component. Returns a
812 * pointer to the UID string inside the property itself.
815 set_alarm_uid (icalcomponent *alarm, const char *auid)
818 const char *inprop_auid;
820 /* Create the new property */
822 prop = icalproperty_new_x ((char *) auid);
823 icalproperty_set_x_name (prop, EVOLUTION_ALARM_UID_PROPERTY);
825 icalcomponent_add_property (alarm, prop);
827 inprop_auid = alarm_uid_from_prop (prop);
831 /* Removes any alarm UID extension properties from an alarm subcomponent */
833 remove_alarm_uid (icalcomponent *alarm)
840 for (prop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
842 prop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY)) {
845 xname = icalproperty_get_x_name (prop);
846 g_assert (xname != NULL);
848 if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0)
849 list = g_slist_prepend (list, prop);
852 for (l = list; l; l = l->next) {
854 icalcomponent_remove_property (alarm, prop);
855 icalproperty_free (prop);
861 /* Adds an alarm subcomponent to the calendar component's mapping table. The
862 * actual UID with which it gets added may not be the same as the specified one;
863 * this function will change it if the table already had an alarm subcomponent
864 * with the specified UID. Returns the actual UID used.
867 add_alarm (ECalComponent *comp, icalcomponent *alarm, const char *auid)
869 ECalComponentPrivate *priv;
870 icalcomponent *old_alarm;
874 /* First we see if we already have an alarm with the requested UID. In
875 * that case, we need to change the new UID to something else. This
876 * should never happen, but who knows.
879 old_alarm = g_hash_table_lookup (priv->alarm_uid_hash, auid);
880 if (old_alarm != NULL) {
883 g_message ("add_alarm(): Got alarm with duplicated UID `%s', changing it...", auid);
885 remove_alarm_uid (alarm);
887 new_auid = e_cal_component_gen_uid ();
888 auid = set_alarm_uid (alarm, new_auid);
892 g_hash_table_insert (priv->alarm_uid_hash, (char *) auid, alarm);
896 /* Scans an alarm subcomponent, adds an UID extension property to it (so that we
897 * can reference alarms by unique IDs), and adds its mapping to the component. */
899 scan_alarm (ECalComponent *comp, icalcomponent *alarm)
901 ECalComponentPrivate *priv;
908 for (prop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
910 prop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY)) {
913 xname = icalproperty_get_x_name (prop);
914 g_assert (xname != NULL);
916 if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0) {
917 auid = alarm_uid_from_prop (prop);
918 add_alarm (comp, alarm, auid);
923 /* The component has no alarm UID property, so we create one. */
925 new_auid = e_cal_component_gen_uid ();
926 auid = set_alarm_uid (alarm, new_auid);
929 add_alarm (comp, alarm, auid);
932 /* Scans an icalcomponent for its properties so that we can provide
933 * random-access to them. It also builds a hash table of the component's alarm
937 scan_icalcomponent (ECalComponent *comp)
939 ECalComponentPrivate *priv;
945 g_assert (priv->icalcomp != NULL);
947 /* Scan properties */
949 for (prop = icalcomponent_get_first_property (priv->icalcomp, ICAL_ANY_PROPERTY);
951 prop = icalcomponent_get_next_property (priv->icalcomp, ICAL_ANY_PROPERTY))
952 scan_property (comp, prop);
954 /* Scan subcomponents */
956 for (iter = icalcomponent_begin_component (priv->icalcomp, ICAL_VALARM_COMPONENT);
957 icalcompiter_deref (&iter) != NULL;
958 icalcompiter_next (&iter)) {
959 icalcomponent *subcomp;
961 subcomp = icalcompiter_deref (&iter);
962 scan_alarm (comp, subcomp);
966 /* Ensures that the mandatory calendar component properties (uid, dtstamp) do
967 * exist. If they don't exist, it creates them automatically.
970 ensure_mandatory_properties (ECalComponent *comp)
972 ECalComponentPrivate *priv;
975 g_assert (priv->icalcomp != NULL);
980 uid = e_cal_component_gen_uid ();
981 priv->uid = icalproperty_new_uid (uid);
984 icalcomponent_add_property (priv->icalcomp, priv->uid);
987 if (!priv->dtstamp) {
988 struct icaltimetype t;
990 t = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
992 priv->dtstamp = icalproperty_new_dtstamp (t);
993 icalcomponent_add_property (priv->icalcomp, priv->dtstamp);
998 * e_cal_component_set_new_vtype:
999 * @comp: A calendar component object.
1000 * @type: Type of calendar component to create.
1002 * Clears any existing component data from a calendar component object and
1003 * creates a new #icalcomponent of the specified type for it. The only property
1004 * that will be set in the new component will be its unique identifier.
1007 e_cal_component_set_new_vtype (ECalComponent *comp, ECalComponentVType type)
1009 ECalComponentPrivate *priv;
1010 icalcomponent *icalcomp;
1011 icalcomponent_kind kind;
1013 g_return_if_fail (comp != NULL);
1014 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1018 free_icalcomponent (comp, TRUE);
1020 if (type == E_CAL_COMPONENT_NO_TYPE)
1023 /* Figure out the kind and create the icalcomponent */
1026 case E_CAL_COMPONENT_EVENT:
1027 kind = ICAL_VEVENT_COMPONENT;
1030 case E_CAL_COMPONENT_TODO:
1031 kind = ICAL_VTODO_COMPONENT;
1034 case E_CAL_COMPONENT_JOURNAL:
1035 kind = ICAL_VJOURNAL_COMPONENT;
1038 case E_CAL_COMPONENT_FREEBUSY:
1039 kind = ICAL_VFREEBUSY_COMPONENT;
1042 case E_CAL_COMPONENT_TIMEZONE:
1043 kind = ICAL_VTIMEZONE_COMPONENT;
1047 g_assert_not_reached ();
1048 kind = ICAL_NO_COMPONENT;
1051 icalcomp = icalcomponent_new (kind);
1053 g_message ("e_cal_component_set_new_vtype(): Could not create the icalcomponent!");
1057 /* Scan the component to build our mapping table */
1059 priv->icalcomp = icalcomp;
1060 scan_icalcomponent (comp);
1062 /* Add missing stuff */
1064 ensure_mandatory_properties (comp);
1068 * e_cal_component_set_icalcomponent:
1069 * @comp: A calendar component object.
1070 * @icalcomp: An #icalcomponent.
1072 * Sets the contents of a calendar component object from an #icalcomponent
1073 * structure. If the @comp already had an #icalcomponent set into it, it will
1074 * will be freed automatically if the #icalcomponent does not have a parent
1077 * Supported component types are VEVENT, VTODO, VJOURNAL, VFREEBUSY, and VTIMEZONE.
1079 * Return value: TRUE on success, FALSE if @icalcomp is an unsupported component
1083 e_cal_component_set_icalcomponent (ECalComponent *comp, icalcomponent *icalcomp)
1085 ECalComponentPrivate *priv;
1086 icalcomponent_kind kind;
1088 g_return_val_if_fail (comp != NULL, FALSE);
1089 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
1093 if (priv->icalcomp == icalcomp)
1096 free_icalcomponent (comp, TRUE);
1099 priv->icalcomp = NULL;
1103 kind = icalcomponent_isa (icalcomp);
1105 if (!(kind == ICAL_VEVENT_COMPONENT
1106 || kind == ICAL_VTODO_COMPONENT
1107 || kind == ICAL_VJOURNAL_COMPONENT
1108 || kind == ICAL_VFREEBUSY_COMPONENT
1109 || kind == ICAL_VTIMEZONE_COMPONENT))
1112 priv->icalcomp = icalcomp;
1114 scan_icalcomponent (comp);
1115 ensure_mandatory_properties (comp);
1121 * e_cal_component_get_icalcomponent:
1122 * @comp: A calendar component object.
1124 * Queries the #icalcomponent structure that a calendar component object is
1127 * Return value: An #icalcomponent structure, or NULL if the @comp has no
1128 * #icalcomponent set to it.
1131 e_cal_component_get_icalcomponent (ECalComponent *comp)
1133 ECalComponentPrivate *priv;
1135 g_return_val_if_fail (comp != NULL, NULL);
1136 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
1140 return priv->icalcomp;
1144 * e_cal_component_rescan:
1145 * @comp: A calendar component object.
1147 * Rescans the #icalcomponent being wrapped by the given calendar component. This
1148 * would replace any value that was changed in the wrapped #icalcomponent.
1151 e_cal_component_rescan (ECalComponent *comp)
1153 ECalComponentPrivate *priv;
1155 g_return_if_fail (comp != NULL);
1156 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1160 /* Clear everything out */
1161 free_icalcomponent (comp, FALSE);
1164 scan_icalcomponent (comp);
1165 ensure_mandatory_properties (comp);
1169 * e_cal_component_strip_errors:
1170 * @comp: A calendar component object.
1172 * Strips all error messages from the calendar component. Those error messages are
1173 * added to the iCalendar string representation whenever an invalid is used for
1174 * one of its fields.
1177 e_cal_component_strip_errors (ECalComponent *comp)
1179 ECalComponentPrivate *priv;
1181 g_return_if_fail (comp != NULL);
1182 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1186 icalcomponent_strip_errors (priv->icalcomp);
1190 * e_cal_component_get_vtype:
1191 * @comp: A calendar component object.
1193 * Queries the type of a calendar component object.
1195 * Return value: The type of the component, as defined by RFC 2445.
1198 e_cal_component_get_vtype (ECalComponent *comp)
1200 ECalComponentPrivate *priv;
1201 icalcomponent_kind kind;
1203 g_return_val_if_fail (comp != NULL, E_CAL_COMPONENT_NO_TYPE);
1204 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), E_CAL_COMPONENT_NO_TYPE);
1207 g_return_val_if_fail (priv->icalcomp != NULL, E_CAL_COMPONENT_NO_TYPE);
1209 kind = icalcomponent_isa (priv->icalcomp);
1211 case ICAL_VEVENT_COMPONENT:
1212 return E_CAL_COMPONENT_EVENT;
1214 case ICAL_VTODO_COMPONENT:
1215 return E_CAL_COMPONENT_TODO;
1217 case ICAL_VJOURNAL_COMPONENT:
1218 return E_CAL_COMPONENT_JOURNAL;
1220 case ICAL_VFREEBUSY_COMPONENT:
1221 return E_CAL_COMPONENT_FREEBUSY;
1223 case ICAL_VTIMEZONE_COMPONENT:
1224 return E_CAL_COMPONENT_TIMEZONE;
1227 /* We should have been loaded with a supported type! */
1228 g_assert_not_reached ();
1229 return E_CAL_COMPONENT_NO_TYPE;
1234 * e_cal_component_get_as_string:
1235 * @comp: A calendar component.
1237 * Gets the iCalendar string representation of a calendar component. You should
1238 * call e_cal_component_commit_sequence() before this function to ensure that the
1239 * component's sequence number is consistent with the state of the object.
1241 * Return value: String representation of the calendar component according to
1245 e_cal_component_get_as_string (ECalComponent *comp)
1247 ECalComponentPrivate *priv;
1250 g_return_val_if_fail (comp != NULL, NULL);
1251 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
1254 g_return_val_if_fail (priv->icalcomp != NULL, NULL);
1256 /* Ensure that the user has committed the new SEQUENCE */
1257 g_return_val_if_fail (priv->need_sequence_inc == FALSE, NULL);
1259 /* We dup the string; libical owns that memory */
1261 str = icalcomponent_as_ical_string (priv->icalcomp);
1264 buf = g_strdup (str);
1271 /* Used from g_hash_table_foreach(); ensures that an alarm subcomponent
1272 * has the mandatory properties it needs.
1275 ensure_alarm_properties_cb (gpointer key, gpointer value, gpointer data)
1277 ECalComponent *comp;
1278 ECalComponentPrivate *priv;
1279 icalcomponent *alarm;
1281 enum icalproperty_action action;
1286 comp = E_CAL_COMPONENT (data);
1289 prop = icalcomponent_get_first_property (alarm, ICAL_ACTION_PROPERTY);
1293 action = icalproperty_get_action (prop);
1296 case ICAL_ACTION_DISPLAY:
1297 /* Ensure we have a DESCRIPTION property */
1298 prop = icalcomponent_get_first_property (alarm, ICAL_DESCRIPTION_PROPERTY);
1300 if (priv->summary.prop) {
1301 icalproperty *xprop;
1303 xprop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
1305 str = icalproperty_get_x_name (xprop);
1306 if (!strcmp (str, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
1307 icalproperty_set_description (prop, icalproperty_get_summary(priv->summary.prop));
1309 icalcomponent_remove_property (alarm, xprop);
1310 icalproperty_free (xprop);
1314 xprop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY);
1321 if (!priv->summary.prop) {
1322 str = _("Untitled appointment");
1324 /* add the X-EVOLUTION-NEEDS-DESCRIPTION property */
1325 prop = icalproperty_new_x ("1");
1326 icalproperty_set_x_name (prop, "X-EVOLUTION-NEEDS-DESCRIPTION");
1327 icalcomponent_add_property (alarm, prop);
1329 str = icalproperty_get_summary (priv->summary.prop);
1331 prop = icalproperty_new_description (str);
1332 icalcomponent_add_property (alarm, prop);
1338 /* FIXME: add other action types here */
1342 /* Ensures that alarm subcomponents have the mandatory properties they need,
1343 * even when clients may not have set them properly.
1346 ensure_alarm_properties (ECalComponent *comp)
1348 ECalComponentPrivate *priv;
1352 g_hash_table_foreach (priv->alarm_uid_hash, ensure_alarm_properties_cb, comp);
1356 * e_cal_component_commit_sequence:
1357 * @comp: A calendar component object.
1359 * Increments the sequence number property in a calendar component object if it
1360 * needs it. This needs to be done when any of a number of properties listed in
1361 * RFC 2445 change values, such as the start and end dates of a component.
1363 * This function must be called before calling e_cal_component_get_as_string() to
1364 * ensure that the component is fully consistent.
1367 e_cal_component_commit_sequence (ECalComponent *comp)
1369 ECalComponentPrivate *priv;
1371 g_return_if_fail (comp != NULL);
1372 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1375 g_return_if_fail (priv->icalcomp != NULL);
1377 ensure_alarm_properties (comp);
1379 if (!priv->need_sequence_inc)
1382 if (priv->sequence) {
1385 seq = icalproperty_get_sequence (priv->sequence);
1386 icalproperty_set_sequence (priv->sequence, seq + 1);
1388 /* The component had no SEQUENCE property, so assume that the
1389 * default would have been zero. Since it needed incrementing
1390 * anyways, we use a value of 1 here.
1392 priv->sequence = icalproperty_new_sequence (1);
1393 icalcomponent_add_property (priv->icalcomp, priv->sequence);
1396 priv->need_sequence_inc = FALSE;
1400 * e_cal_component_abort_sequence:
1401 * @comp: A calendar component object.
1403 * Aborts the sequence change needed in the given calendar component, which
1404 * means it will not require a sequence commit (via #e_cal_component_commit_sequence)
1405 * even if the changes done require a sequence increment.
1408 e_cal_component_abort_sequence (ECalComponent *comp)
1410 ECalComponentPrivate *priv;
1412 g_return_if_fail (comp != NULL);
1413 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1417 priv->need_sequence_inc = FALSE;
1421 * e_cal_component_get_id:
1422 * @comp: A calendar component object.
1424 * Get the ID of the component as a #ECalComponentId. The return value should
1425 * be freed with e_cal_component_free_id() when you have finished with it.
1427 * Return value: the id of the component
1430 e_cal_component_get_id (ECalComponent *comp)
1432 ECalComponentPrivate *priv;
1433 ECalComponentId *id = NULL;
1435 g_return_val_if_fail (comp != NULL, NULL);
1436 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
1439 g_return_val_if_fail (priv->icalcomp != NULL, NULL);
1441 id = g_new0 (ECalComponentId, 1);
1442 id->uid = g_strdup (icalproperty_get_uid (priv->uid));
1443 id->rid = g_strdup (e_cal_component_get_recurid_as_string (comp));
1449 * e_cal_component_get_uid:
1450 * @comp: A calendar component object.
1451 * @uid: Return value for the UID string.
1453 * Queries the unique identifier of a calendar component object.
1456 e_cal_component_get_uid (ECalComponent *comp, const char **uid)
1458 ECalComponentPrivate *priv;
1460 g_return_if_fail (comp != NULL);
1461 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1462 g_return_if_fail (uid != NULL);
1465 g_return_if_fail (priv->icalcomp != NULL);
1467 /* This MUST exist, since we ensured that it did */
1468 g_assert (priv->uid != NULL);
1470 *uid = icalproperty_get_uid (priv->uid);
1474 * e_cal_component_set_uid:
1475 * @comp: A calendar component object.
1476 * @uid: Unique identifier.
1478 * Sets the unique identifier string of a calendar component object.
1481 e_cal_component_set_uid (ECalComponent *comp, const char *uid)
1483 ECalComponentPrivate *priv;
1485 g_return_if_fail (comp != NULL);
1486 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1487 g_return_if_fail (uid != NULL);
1490 g_return_if_fail (priv->icalcomp != NULL);
1492 /* This MUST exist, since we ensured that it did */
1493 g_assert (priv->uid != NULL);
1495 icalproperty_set_uid (priv->uid, (char *) uid);
1498 /* Gets a text list value */
1500 get_attachment_list (GSList *attachment_list, GSList **al)
1506 if (!attachment_list)
1509 for (l = attachment_list; l; l = l->next) {
1510 struct attachment *attachment;
1515 attachment = l->data;
1516 g_assert (attachment->attach != NULL);
1518 if (icalattach_get_is_url (attachment->attach)) {
1519 /* FIXME : this ref count is screwed up
1520 * These structures are being leaked.
1522 icalattach_ref (attachment->attach);
1523 data = icalattach_get_url (attachment->attach);
1524 buf_size = strlen (data);
1525 buf = g_malloc0 (buf_size+1);
1526 icalvalue_decode_ical_string (data, buf, buf_size);
1530 *al = g_slist_prepend (*al, (char *)buf);
1533 *al = g_slist_reverse (*al);
1538 set_attachment_list (icalcomponent *icalcomp,
1539 GSList **attachment_list,
1544 /* Remove old attachments */
1546 if (*attachment_list) {
1547 for (l = *attachment_list; l; l = l->next) {
1548 struct attachment *attachment;
1550 attachment = l->data;
1551 g_assert (attachment->prop != NULL);
1552 g_assert (attachment->attach != NULL);
1554 icalcomponent_remove_property (icalcomp, attachment->prop);
1555 icalproperty_free (attachment->prop);
1556 g_free (attachment);
1559 g_slist_free (*attachment_list);
1560 *attachment_list = NULL;
1562 /* Add in new attachments */
1564 for (l = al; l; l = l->next) {
1565 struct attachment *attachment;
1569 attachment = g_new0 (struct attachment, 1);
1570 buf_size = 2 * strlen ((char *)l->data);
1571 buf = g_malloc0 (buf_size);
1572 icalvalue_encode_ical_string (l->data, buf, buf_size);
1573 attachment->attach = icalattach_new_from_url ((char *) buf);
1574 attachment->prop = icalproperty_new_attach (attachment->attach);
1575 icalcomponent_add_property (icalcomp, attachment->prop);
1577 *attachment_list = g_slist_prepend (*attachment_list, attachment);
1580 *attachment_list = g_slist_reverse (*attachment_list);
1585 * e_cal_component_get_attachment_list:
1586 * @comp: A calendar component object.
1587 * @attachment_list: Return list of URLS to attachments.
1589 * Queries the attachment properties of the calendar component object. When done,
1590 * the @attachment_list should be freed by calling #g_slist_free.
1593 e_cal_component_get_attachment_list (ECalComponent *comp, GSList **attachment_list)
1595 ECalComponentPrivate *priv;
1597 g_return_if_fail (comp != NULL);
1598 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1599 g_return_if_fail (attachment_list != NULL);
1602 g_return_if_fail (priv->icalcomp != NULL);
1604 get_attachment_list (priv->attachment_list, attachment_list);
1608 * e_cal_component_set_attachment_list:
1609 * @comp: A calendar component object.
1610 * @attachment_list: list of urls to attachment pointers.
1612 * This currently handles only attachments that are urls
1613 * in the file system - not inline binaries.
1615 * Sets the attachments of a calendar component object
1618 e_cal_component_set_attachment_list (ECalComponent *comp, GSList *attachment_list)
1620 ECalComponentPrivate *priv;
1622 g_return_if_fail (comp != NULL);
1623 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1626 g_return_if_fail (priv->icalcomp != NULL);
1628 set_attachment_list (priv->icalcomp, &priv->attachment_list, attachment_list);
1632 * e_cal_component_has_attachments:
1633 * @comp: A calendar component object.
1635 * Queries the component to see if it has attachments.
1637 * Return value: TRUE if there are attachments, FALSE otherwise.
1640 e_cal_component_has_attachments (ECalComponent *comp)
1642 ECalComponentPrivate *priv;
1644 g_return_val_if_fail (comp != NULL, FALSE);
1645 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
1649 if (g_slist_length (priv->attachment_list) > 0)
1656 * e_cal_component_get_num_attachments:
1657 * @comp: A calendar component object.
1659 * Get the number of attachments to this calendar component object.
1661 * Return value: the number of attachments.
1664 e_cal_component_get_num_attachments (ECalComponent *comp)
1666 ECalComponentPrivate *priv;
1668 g_return_val_if_fail (comp != NULL, 0);
1669 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), 0);
1673 return g_slist_length (priv->attachment_list) > 0;
1678 * e_cal_component_get_categories:
1679 * @comp: A calendar component object.
1680 * @categories: Return holder for the categories.
1682 * Queries the categories of the given calendar component. The categories
1683 * are returned in the @categories argument, which, on success, will contain
1684 * a comma-separated list of all categories set in the component.
1687 e_cal_component_get_categories (ECalComponent *comp, const char **categories)
1689 ECalComponentPrivate *priv;
1691 g_return_if_fail (comp != NULL);
1692 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1693 g_return_if_fail (categories != NULL);
1696 g_return_if_fail (priv->icalcomp != NULL);
1698 if (priv->categories)
1699 *categories = icalproperty_get_categories (priv->categories);
1705 * e_cal_component_set_categories:
1706 * @comp: A calendar component object.
1707 * @categories: Comma-separated list of categories.
1709 * Sets the list of categories for a calendar component.
1712 e_cal_component_set_categories (ECalComponent *comp, const char *categories)
1714 ECalComponentPrivate *priv;
1716 g_return_if_fail (comp != NULL);
1717 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1720 g_return_if_fail (priv->icalcomp != NULL);
1722 if (!categories || !(*categories)) {
1723 if (priv->categories) {
1724 icalcomponent_remove_property (priv->icalcomp, priv->categories);
1725 icalproperty_free (priv->categories);
1732 if (priv->categories)
1733 icalproperty_set_categories (priv->categories, (char *) categories);
1735 priv->categories = icalproperty_new_categories ((char *) categories);
1736 icalcomponent_add_property (priv->icalcomp, priv->categories);
1742 * e_cal_component_get_categories_list:
1743 * @comp: A calendar component object.
1744 * @categ_list: Return value for the list of strings, where each string is a
1745 * category. This should be freed using e_cal_component_free_categories_list().
1747 * Queries the list of categories of a calendar component object. Each element
1748 * in the returned categ_list is a string with the corresponding category.
1751 e_cal_component_get_categories_list (ECalComponent *comp, GSList **categ_list)
1753 ECalComponentPrivate *priv;
1754 const char *categories;
1756 const char *cat_start;
1759 g_return_if_fail (comp != NULL);
1760 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1761 g_return_if_fail (categ_list != NULL);
1764 g_return_if_fail (priv->icalcomp != NULL);
1766 if (!priv->categories) {
1771 categories = icalproperty_get_categories (priv->categories);
1772 g_assert (categories != NULL);
1774 cat_start = categories;
1777 for (p = categories; *p; p++)
1779 str = g_strndup (cat_start, p - cat_start);
1780 *categ_list = g_slist_prepend (*categ_list, str);
1785 str = g_strndup (cat_start, p - cat_start);
1786 *categ_list = g_slist_prepend (*categ_list, str);
1788 *categ_list = g_slist_reverse (*categ_list);
1791 /* Creates a comma-delimited string of categories */
1793 stringify_categories (GSList *categ_list)
1799 s = g_string_new (NULL);
1801 for (l = categ_list; l; l = l->next) {
1802 g_string_append (s, l->data);
1804 if (l->next != NULL)
1805 g_string_append (s, ",");
1809 g_string_free (s, FALSE);
1815 * e_cal_component_set_categories_list:
1816 * @comp: A calendar component object.
1817 * @categ_list: List of strings, one for each category.
1819 * Sets the list of categories of a calendar component object.
1822 e_cal_component_set_categories_list (ECalComponent *comp, GSList *categ_list)
1824 ECalComponentPrivate *priv;
1825 char *categories_str;
1827 g_return_if_fail (comp != NULL);
1828 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1831 g_return_if_fail (priv->icalcomp != NULL);
1834 if (priv->categories) {
1835 icalcomponent_remove_property (priv->icalcomp, priv->categories);
1836 icalproperty_free (priv->categories);
1842 /* Create a single string of categories */
1843 categories_str = stringify_categories (categ_list);
1845 /* Set the categories */
1846 priv->categories = icalproperty_new_categories (categories_str);
1847 g_free (categories_str);
1849 icalcomponent_add_property (priv->icalcomp, priv->categories);
1853 * e_cal_component_get_classification:
1854 * @comp: A calendar component object.
1855 * @classif: Return value for the classification.
1857 * Queries the classification of a calendar component object. If the
1858 * classification property is not set on this component, this function returns
1859 * #E_CAL_COMPONENT_CLASS_NONE.
1862 e_cal_component_get_classification (ECalComponent *comp, ECalComponentClassification *classif)
1864 ECalComponentPrivate *priv;
1865 icalproperty_class class;
1867 g_return_if_fail (comp != NULL);
1868 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1869 g_return_if_fail (classif != NULL);
1872 g_return_if_fail (priv->icalcomp != NULL);
1874 if (!priv->classification) {
1875 *classif = E_CAL_COMPONENT_CLASS_NONE;
1879 class = icalproperty_get_class (priv->classification);
1883 case ICAL_CLASS_PUBLIC:
1884 *classif = E_CAL_COMPONENT_CLASS_PUBLIC;
1886 case ICAL_CLASS_PRIVATE:
1887 *classif = E_CAL_COMPONENT_CLASS_PRIVATE;
1889 case ICAL_CLASS_CONFIDENTIAL:
1890 *classif = E_CAL_COMPONENT_CLASS_CONFIDENTIAL;
1893 *classif = E_CAL_COMPONENT_CLASS_UNKNOWN;
1899 * e_cal_component_set_classification:
1900 * @comp: A calendar component object.
1901 * @classif: Classification to use.
1903 * Sets the classification property of a calendar component object. To unset
1904 * the property, specify E_CAL_COMPONENT_CLASS_NONE for @classif.
1907 e_cal_component_set_classification (ECalComponent *comp, ECalComponentClassification classif)
1909 ECalComponentPrivate *priv;
1910 icalproperty_class class;
1912 g_return_if_fail (comp != NULL);
1913 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
1914 g_return_if_fail (classif != E_CAL_COMPONENT_CLASS_UNKNOWN);
1917 g_return_if_fail (priv->icalcomp != NULL);
1919 if (classif == E_CAL_COMPONENT_CLASS_NONE) {
1920 if (priv->classification) {
1921 icalcomponent_remove_property (priv->icalcomp, priv->classification);
1922 icalproperty_free (priv->classification);
1923 priv->classification = NULL;
1930 case E_CAL_COMPONENT_CLASS_PUBLIC:
1931 class = ICAL_CLASS_PUBLIC;
1934 case E_CAL_COMPONENT_CLASS_PRIVATE:
1935 class = ICAL_CLASS_PRIVATE;
1938 case E_CAL_COMPONENT_CLASS_CONFIDENTIAL:
1939 class = ICAL_CLASS_CONFIDENTIAL;
1943 g_assert_not_reached ();
1944 class = ICAL_CLASS_NONE;
1947 if (priv->classification)
1948 icalproperty_set_class (priv->classification, class);
1950 priv->classification = icalproperty_new_class (class);
1951 icalcomponent_add_property (priv->icalcomp, priv->classification);
1955 /* Gets a text list value */
1957 get_text_list (GSList *text_list,
1958 const char *(* get_prop_func) (const icalproperty *prop),
1968 for (l = text_list; l; l = l->next) {
1970 ECalComponentText *t;
1973 g_assert (text->prop != NULL);
1975 t = g_new (ECalComponentText, 1);
1976 t->value = (* get_prop_func) (text->prop);
1978 if (text->altrep_param)
1979 t->altrep = icalparameter_get_altrep (text->altrep_param);
1983 *tl = g_slist_prepend (*tl, t);
1986 *tl = g_slist_reverse (*tl);
1989 /* Sets a text list value */
1991 set_text_list (ECalComponent *comp,
1992 icalproperty *(* new_prop_func) (const char *value),
1996 ECalComponentPrivate *priv;
2001 /* Remove old texts */
2003 for (l = *text_list; l; l = l->next) {
2007 g_assert (text->prop != NULL);
2009 icalcomponent_remove_property (priv->icalcomp, text->prop);
2010 icalproperty_free (text->prop);
2014 g_slist_free (*text_list);
2017 /* Add in new texts */
2019 for (l = tl; l; l = l->next) {
2020 ECalComponentText *t;
2024 g_return_if_fail (t->value != NULL);
2026 text = g_new (struct text, 1);
2028 text->prop = (* new_prop_func) ((char *) t->value);
2029 icalcomponent_add_property (priv->icalcomp, text->prop);
2032 text->altrep_param = icalparameter_new_altrep ((char *) t->altrep);
2033 icalproperty_add_parameter (text->prop, text->altrep_param);
2035 text->altrep_param = NULL;
2037 *text_list = g_slist_prepend (*text_list, text);
2040 *text_list = g_slist_reverse (*text_list);
2044 * e_cal_component_get_comment_list:
2045 * @comp: A calendar component object.
2046 * @text_list: Return value for the comment properties and their parameters, as
2047 * a list of #ECalComponentText structures. This should be freed using the
2048 * e_cal_component_free_text_list() function.
2050 * Queries the comments of a calendar component object. The comment property can
2051 * appear several times inside a calendar component, and so a list of
2052 * #ECalComponentText is returned.
2055 e_cal_component_get_comment_list (ECalComponent *comp, GSList **text_list)
2057 ECalComponentPrivate *priv;
2059 g_return_if_fail (comp != NULL);
2060 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2061 g_return_if_fail (text_list != NULL);
2064 g_return_if_fail (priv->icalcomp != NULL);
2066 get_text_list (priv->comment_list, icalproperty_get_comment, text_list);
2070 * e_cal_component_set_comment_list:
2071 * @comp: A calendar component object.
2072 * @text_list: List of #ECalComponentText structures.
2074 * Sets the comments of a calendar component object. The comment property can
2075 * appear several times inside a calendar component, and so a list of
2076 * #ECalComponentText structures is used.
2079 e_cal_component_set_comment_list (ECalComponent *comp, GSList *text_list)
2081 ECalComponentPrivate *priv;
2083 g_return_if_fail (comp != NULL);
2084 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2087 g_return_if_fail (priv->icalcomp != NULL);
2089 set_text_list (comp, icalproperty_new_comment, &priv->comment_list, text_list);
2093 * e_cal_component_get_contact_list:
2094 * @comp: A calendar component object.
2095 * @text_list: Return value for the contact properties and their parameters, as
2096 * a list of #ECalComponentText structures. This should be freed using the
2097 * e_cal_component_free_text_list() function.
2099 * Queries the contact of a calendar component object. The contact property can
2100 * appear several times inside a calendar component, and so a list of
2101 * #ECalComponentText is returned.
2104 e_cal_component_get_contact_list (ECalComponent *comp, GSList **text_list)
2106 ECalComponentPrivate *priv;
2108 g_return_if_fail (comp != NULL);
2109 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2110 g_return_if_fail (text_list != NULL);
2113 g_return_if_fail (priv->icalcomp != NULL);
2115 get_text_list (priv->contact_list, icalproperty_get_contact, text_list);
2119 * e_cal_component_set_contact_list:
2120 * @comp: A calendar component object.
2121 * @text_list: List of #ECalComponentText structures.
2123 * Sets the contact of a calendar component object. The contact property can
2124 * appear several times inside a calendar component, and so a list of
2125 * #ECalComponentText structures is used.
2128 e_cal_component_set_contact_list (ECalComponent *comp, GSList *text_list)
2130 ECalComponentPrivate *priv;
2132 g_return_if_fail (comp != NULL);
2133 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2136 g_return_if_fail (priv->icalcomp != NULL);
2138 set_text_list (comp, icalproperty_new_contact, &priv->contact_list, text_list);
2141 /* Gets a struct icaltimetype value */
2143 get_icaltimetype (icalproperty *prop,
2144 struct icaltimetype (* get_prop_func) (const icalproperty *prop),
2145 struct icaltimetype **t)
2152 *t = g_new (struct icaltimetype, 1);
2153 **t = (* get_prop_func) (prop);
2156 /* Sets a struct icaltimetype value */
2158 set_icaltimetype (ECalComponent *comp, icalproperty **prop,
2159 icalproperty *(* prop_new_func) (struct icaltimetype v),
2160 void (* prop_set_func) (icalproperty *prop, struct icaltimetype v),
2161 struct icaltimetype *t)
2163 ECalComponentPrivate *priv;
2169 icalcomponent_remove_property (priv->icalcomp, *prop);
2170 icalproperty_free (*prop);
2178 (* prop_set_func) (*prop, *t);
2180 *prop = (* prop_new_func) (*t);
2181 icalcomponent_add_property (priv->icalcomp, *prop);
2186 * e_cal_component_get_completed:
2187 * @comp: A calendar component object.
2188 * @t: Return value for the completion date. This should be freed using the
2189 * e_cal_component_free_icaltimetype() function.
2191 * Queries the date at which a calendar compoment object was completed.
2194 e_cal_component_get_completed (ECalComponent *comp, struct icaltimetype **t)
2196 ECalComponentPrivate *priv;
2198 g_return_if_fail (comp != NULL);
2199 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2200 g_return_if_fail (t != NULL);
2203 g_return_if_fail (priv->icalcomp != NULL);
2205 get_icaltimetype (priv->completed, icalproperty_get_completed, t);
2209 * e_cal_component_set_completed:
2210 * @comp: A calendar component object.
2211 * @t: Value for the completion date.
2213 * Sets the date at which a calendar component object was completed.
2216 e_cal_component_set_completed (ECalComponent *comp, struct icaltimetype *t)
2218 ECalComponentPrivate *priv;
2220 g_return_if_fail (comp != NULL);
2221 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2224 g_return_if_fail (priv->icalcomp != NULL);
2226 set_icaltimetype (comp, &priv->completed,
2227 icalproperty_new_completed,
2228 icalproperty_set_completed,
2234 * e_cal_component_get_created:
2235 * @comp: A calendar component object.
2236 * @t: Return value for the creation date. This should be freed using the
2237 * e_cal_component_free_icaltimetype() function.
2239 * Queries the date in which a calendar component object was created in the
2243 e_cal_component_get_created (ECalComponent *comp, struct icaltimetype **t)
2245 ECalComponentPrivate *priv;
2247 g_return_if_fail (comp != NULL);
2248 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2249 g_return_if_fail (t != NULL);
2252 g_return_if_fail (priv->icalcomp != NULL);
2254 get_icaltimetype (priv->created, icalproperty_get_created, t);
2258 * e_cal_component_set_created:
2259 * @comp: A calendar component object.
2260 * @t: Value for the creation date.
2262 * Sets the date in which a calendar component object is created in the calendar
2263 * store. This should only be used inside a calendar store application, i.e.
2264 * not by calendar user agents.
2267 e_cal_component_set_created (ECalComponent *comp, struct icaltimetype *t)
2269 ECalComponentPrivate *priv;
2271 g_return_if_fail (comp != NULL);
2272 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2275 g_return_if_fail (priv->icalcomp != NULL);
2277 set_icaltimetype (comp, &priv->created,
2278 icalproperty_new_created,
2279 icalproperty_set_created,
2284 * e_cal_component_get_description_list:
2285 * @comp: A calendar component object.
2286 * @text_list: Return value for the description properties and their parameters,
2287 * as a list of #ECalComponentText structures. This should be freed using the
2288 * e_cal_component_free_text_list() function.
2290 * Queries the description of a calendar component object. Journal components
2291 * may have more than one description, and as such this function returns a list
2292 * of #ECalComponentText structures. All other types of components can have at
2293 * most one description.
2296 e_cal_component_get_description_list (ECalComponent *comp, GSList **text_list)
2298 ECalComponentPrivate *priv;
2300 g_return_if_fail (comp != NULL);
2301 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2302 g_return_if_fail (text_list != NULL);
2305 g_return_if_fail (priv->icalcomp != NULL);
2307 get_text_list (priv->description_list, icalproperty_get_description, text_list);
2311 * e_cal_component_set_description_list:
2312 * @comp: A calendar component object.
2313 * @text_list: List of #ECalComponentSummary structures.
2315 * Sets the description of a calendar component object. Journal components may
2316 * have more than one description, and as such this function takes in a list of
2317 * #ECalComponentDescription structures. All other types of components can have
2318 * at most one description.
2321 e_cal_component_set_description_list (ECalComponent *comp, GSList *text_list)
2323 ECalComponentPrivate *priv;
2325 g_return_if_fail (comp != NULL);
2326 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2329 g_return_if_fail (priv->icalcomp != NULL);
2331 set_text_list (comp, icalproperty_new_description, &priv->description_list, text_list);
2334 /* Gets a date/time and timezone pair */
2336 get_datetime (struct datetime *datetime,
2337 struct icaltimetype (* get_prop_func) (const icalproperty *prop),
2338 ECalComponentDateTime *dt)
2340 if (datetime->prop) {
2341 dt->value = g_new (struct icaltimetype, 1);
2342 *dt->value = (* get_prop_func) (datetime->prop);
2346 /* If the icaltimetype has is_utc set, we set "UTC" as the TZID.
2347 This makes the timezone code simpler. */
2348 if (datetime->tzid_param)
2349 dt->tzid = g_strdup (icalparameter_get_tzid (datetime->tzid_param));
2350 else if (dt->value && dt->value->is_utc)
2351 dt->tzid = g_strdup ("UTC");
2356 /* Sets a date/time and timezone pair */
2358 set_datetime (ECalComponent *comp, struct datetime *datetime,
2359 icalproperty *(* prop_new_func) (struct icaltimetype v),
2360 void (* prop_set_func) (icalproperty * prop, struct icaltimetype v),
2361 ECalComponentDateTime *dt)
2363 ECalComponentPrivate *priv;
2367 /* If we are setting the property to NULL (i.e. removing it), then
2368 we remove it if it exists. */
2370 if (datetime->prop) {
2371 icalcomponent_remove_property (priv->icalcomp, datetime->prop);
2372 icalproperty_free (datetime->prop);
2374 datetime->prop = NULL;
2375 datetime->tzid_param = NULL;
2381 g_return_if_fail (dt->value != NULL);
2383 /* If the TZID is set to "UTC", we set the is_utc flag. */
2384 if (dt->tzid && !strcmp (dt->tzid, "UTC"))
2385 dt->value->is_utc = 1;
2387 dt->value->is_utc = 0;
2389 if (datetime->prop) {
2390 (* prop_set_func) (datetime->prop, *dt->value);
2392 datetime->prop = (* prop_new_func) (*dt->value);
2393 icalcomponent_add_property (priv->icalcomp, datetime->prop);
2396 /* If the TZID is set to "UTC", we don't want to save the TZID. */
2397 if (dt->tzid && strcmp (dt->tzid, "UTC")) {
2398 g_assert (datetime->prop != NULL);
2400 if (datetime->tzid_param) {
2401 icalparameter_set_tzid (datetime->tzid_param, (char *) dt->tzid);
2403 datetime->tzid_param = icalparameter_new_tzid ((char *) dt->tzid);
2404 icalproperty_add_parameter (datetime->prop, datetime->tzid_param);
2406 } else if (datetime->tzid_param) {
2407 icalproperty_remove_parameter (datetime->prop, ICAL_TZID_PARAMETER);
2408 datetime->tzid_param = NULL;
2413 /* This tries to get the DTSTART + DURATION for a VEVENT or VTODO. In a
2414 VEVENT this is used for the DTEND if no DTEND exists, In a VTOTO it is
2415 used for the DUE date if DUE doesn't exist. */
2417 e_cal_component_get_start_plus_duration (ECalComponent *comp,
2418 ECalComponentDateTime *dt)
2420 ECalComponentPrivate *priv;
2421 struct icaldurationtype duration;
2425 if (!priv->duration)
2428 /* Get the DTSTART time. */
2429 get_datetime (&priv->dtstart, icalproperty_get_dtstart, dt);
2433 duration = icalproperty_get_duration (priv->duration);
2435 /* The DURATION shouldn't be negative, but just return DTSTART if it
2436 is, i.e. assume it is 0. */
2437 if (duration.is_neg)
2440 /* If DTSTART is a DATE value, then we need to check if the DURATION
2441 includes any hours, minutes or seconds. If it does, we need to
2442 make the DTEND/DUE a DATE-TIME value. */
2443 duration.days += duration.weeks * 7;
2444 if (dt->value->is_date) {
2445 if (duration.hours != 0 || duration.minutes != 0
2446 || duration.seconds != 0) {
2447 dt->value->is_date = 0;
2451 /* Add on the DURATION. */
2452 icaltime_adjust (dt->value, duration.days, duration.hours,
2453 duration.minutes, duration.seconds);
2458 * e_cal_component_get_dtend:
2459 * @comp: A calendar component object.
2460 * @dt: Return value for the date/time end. This should be freed with the
2461 * e_cal_component_free_datetime() function.
2463 * Queries the date/time end of a calendar component object.
2466 e_cal_component_get_dtend (ECalComponent *comp, ECalComponentDateTime *dt)
2468 ECalComponentPrivate *priv;
2470 g_return_if_fail (dt != NULL);
2475 g_return_if_fail (comp != NULL);
2476 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2479 g_return_if_fail (priv->icalcomp != NULL);
2481 get_datetime (&priv->dtend, icalproperty_get_dtend, dt);
2483 /* If we don't have a DTEND property, then we try to get DTSTART
2486 e_cal_component_get_start_plus_duration (comp, dt);
2490 * e_cal_component_set_dtend:
2491 * @comp: A calendar component object.
2492 * @dt: End date/time.
2494 * Sets the date/time end property of a calendar component object.
2497 e_cal_component_set_dtend (ECalComponent *comp, ECalComponentDateTime *dt)
2499 ECalComponentPrivate *priv;
2501 g_return_if_fail (comp != NULL);
2502 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2505 g_return_if_fail (priv->icalcomp != NULL);
2507 set_datetime (comp, &priv->dtend,
2508 icalproperty_new_dtend,
2509 icalproperty_set_dtend,
2512 /* Make sure we remove any existing DURATION property, as it can't be
2513 used with a DTEND. If DTEND is set to NULL, i.e. removed, we also
2514 want to remove any DURATION. */
2515 if (priv->duration) {
2516 icalcomponent_remove_property (priv->icalcomp, priv->duration);
2517 icalproperty_free (priv->duration);
2518 priv->duration = NULL;
2521 priv->need_sequence_inc = TRUE;
2525 * e_cal_component_get_dtstamp:
2526 * @comp: A calendar component object.
2527 * @t: A value for the date/timestamp.
2529 * Queries the date/timestamp property of a calendar component object, which is
2530 * the last time at which the object was modified by a calendar user agent.
2533 e_cal_component_get_dtstamp (ECalComponent *comp, struct icaltimetype *t)
2535 ECalComponentPrivate *priv;
2537 g_return_if_fail (comp != NULL);
2538 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2539 g_return_if_fail (t != NULL);
2542 g_return_if_fail (priv->icalcomp != NULL);
2544 /* This MUST exist, since we ensured that it did */
2545 g_assert (priv->dtstamp != NULL);
2547 *t = icalproperty_get_dtstamp (priv->dtstamp);
2551 * e_cal_component_set_dtstamp:
2552 * @comp: A calendar component object.
2553 * @t: Date/timestamp value.
2555 * Sets the date/timestamp of a calendar component object. This should be
2556 * called whenever a calendar user agent makes a change to a component's
2560 e_cal_component_set_dtstamp (ECalComponent *comp, struct icaltimetype *t)
2562 ECalComponentPrivate *priv;
2564 g_return_if_fail (comp != NULL);
2565 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2566 g_return_if_fail (t != NULL);
2569 g_return_if_fail (priv->icalcomp != NULL);
2571 /* This MUST exist, since we ensured that it did */
2572 g_assert (priv->dtstamp != NULL);
2574 icalproperty_set_dtstamp (priv->dtstamp, *t);
2578 * e_cal_component_get_dtstart:
2579 * @comp: A calendar component object.
2580 * @dt: Return value for the date/time start. This should be freed with the
2581 * e_cal_component_free_datetime() function.
2583 * Queries the date/time start of a calendar component object.
2586 e_cal_component_get_dtstart (ECalComponent *comp, ECalComponentDateTime *dt)
2588 ECalComponentPrivate *priv;
2590 g_return_if_fail (dt != NULL);
2595 g_return_if_fail (comp != NULL);
2596 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2599 g_return_if_fail (priv->icalcomp != NULL);
2601 get_datetime (&priv->dtstart, icalproperty_get_dtstart, dt);
2605 * e_cal_component_set_dtstart:
2606 * @comp: A calendar component object.
2607 * @dt: Start date/time.
2609 * Sets the date/time start property of a calendar component object.
2612 e_cal_component_set_dtstart (ECalComponent *comp, ECalComponentDateTime *dt)
2614 ECalComponentPrivate *priv;
2616 g_return_if_fail (comp != NULL);
2617 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2620 g_return_if_fail (priv->icalcomp != NULL);
2622 set_datetime (comp, &priv->dtstart,
2623 icalproperty_new_dtstart,
2624 icalproperty_set_dtstart,
2627 priv->need_sequence_inc = TRUE;
2631 * e_cal_component_get_due:
2632 * @comp: A calendar component object.
2633 * @dt: Return value for the due date/time. This should be freed with the
2634 * e_cal_component_free_datetime() function.
2636 * Queries the due date/time of a calendar component object.
2639 e_cal_component_get_due (ECalComponent *comp, ECalComponentDateTime *dt)
2641 ECalComponentPrivate *priv;
2643 g_return_if_fail (dt != NULL);
2648 g_return_if_fail (comp != NULL);
2649 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2652 g_return_if_fail (priv->icalcomp != NULL);
2654 get_datetime (&priv->due, icalproperty_get_due, dt);
2656 /* If we don't have a DTEND property, then we try to get DTSTART
2659 e_cal_component_get_start_plus_duration (comp, dt);
2663 * e_cal_component_set_due:
2664 * @comp: A calendar component object.
2665 * @dt: End date/time.
2667 * Sets the due date/time property of a calendar component object.
2670 e_cal_component_set_due (ECalComponent *comp, ECalComponentDateTime *dt)
2672 ECalComponentPrivate *priv;
2674 g_return_if_fail (comp != NULL);
2675 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2678 g_return_if_fail (priv->icalcomp != NULL);
2680 set_datetime (comp, &priv->due,
2681 icalproperty_new_due,
2682 icalproperty_set_due,
2685 /* Make sure we remove any existing DURATION property, as it can't be
2686 used with a DTEND. If DTEND is set to NULL, i.e. removed, we also
2687 want to remove any DURATION. */
2688 if (priv->duration) {
2689 icalcomponent_remove_property (priv->icalcomp, priv->duration);
2690 icalproperty_free (priv->duration);
2691 priv->duration = NULL;
2694 priv->need_sequence_inc = TRUE;
2697 /* Builds a list of ECalComponentPeriod structures based on a list of icalproperties */
2699 get_period_list (GSList *period_list,
2700 struct icaldatetimeperiodtype (* get_prop_func) (const icalproperty *prop),
2710 for (l = period_list; l; l = l->next) {
2711 struct period *period;
2712 ECalComponentPeriod *p;
2713 struct icaldatetimeperiodtype ip;
2716 g_assert (period->prop != NULL);
2718 p = g_new (ECalComponentPeriod, 1);
2720 /* Get value parameter */
2722 if (period->value_param) {
2723 icalparameter_value value_type;
2725 value_type = icalparameter_get_value (period->value_param);
2727 if (value_type == ICAL_VALUE_DATE || value_type == ICAL_VALUE_DATETIME)
2728 p->type = E_CAL_COMPONENT_PERIOD_DATETIME;
2729 else if (value_type == ICAL_VALUE_DURATION)
2730 p->type = E_CAL_COMPONENT_PERIOD_DURATION;
2732 g_message ("get_period_list(): Unknown value for period %d; "
2733 "using DATETIME", value_type);
2734 p->type = E_CAL_COMPONENT_PERIOD_DATETIME;
2737 p->type = E_CAL_COMPONENT_PERIOD_DATETIME;
2739 /* Get start and end/duration */
2741 ip = (* get_prop_func) (period->prop);
2743 p->start = ip.period.start;
2745 if (p->type == E_CAL_COMPONENT_PERIOD_DATETIME)
2746 p->u.end = ip.period.end;
2747 else if (p->type == E_CAL_COMPONENT_PERIOD_DURATION)
2748 p->u.duration = ip.period.duration;
2750 g_assert_not_reached ();
2754 *list = g_slist_prepend (*list, p);
2757 *list = g_slist_reverse (*list);
2760 /* Sets a period list value */
2762 set_period_list (ECalComponent *comp,
2763 icalproperty *(* new_prop_func) (struct icaldatetimeperiodtype period),
2764 GSList **period_list,
2767 ECalComponentPrivate *priv;
2772 /* Remove old periods */
2774 for (l = *period_list; l; l = l->next) {
2775 struct period *period;
2778 g_assert (period->prop != NULL);
2780 icalcomponent_remove_property (priv->icalcomp, period->prop);
2781 icalproperty_free (period->prop);
2785 g_slist_free (*period_list);
2786 *period_list = NULL;
2788 /* Add in new periods */
2790 for (l = pl; l; l = l->next) {
2791 ECalComponentPeriod *p;
2792 struct period *period;
2793 struct icaldatetimeperiodtype ip = {};
2794 icalparameter_value value_type;
2796 g_assert (l->data != NULL);
2799 /* Create libical value */
2801 ip.period.start = p->start;
2803 if (p->type == E_CAL_COMPONENT_PERIOD_DATETIME) {
2804 value_type = ICAL_VALUE_DATETIME;
2805 ip.period.end = p->u.end;
2806 } else if (p->type == E_CAL_COMPONENT_PERIOD_DURATION) {
2807 value_type = ICAL_VALUE_DURATION;
2808 ip.period.duration = p->u.duration;
2810 g_assert_not_reached ();
2814 /* Create property */
2816 period = g_new (struct period, 1);
2818 period->prop = (* new_prop_func) (ip);
2819 period->value_param = icalparameter_new_value (value_type);
2820 icalproperty_add_parameter (period->prop, period->value_param);
2824 *period_list = g_slist_prepend (*period_list, period);
2827 *period_list = g_slist_reverse (*period_list);
2831 * e_cal_component_get_exdate_list:
2832 * @comp: A calendar component object.
2833 * @exdate_list: Return value for the list of exception dates, as a list of
2834 * #ECalComponentDateTime structures. This should be freed using the
2835 * e_cal_component_free_exdate_list() function.
2837 * Queries the list of exception date properties in a calendar component object.
2840 e_cal_component_get_exdate_list (ECalComponent *comp, GSList **exdate_list)
2842 ECalComponentPrivate *priv;
2845 g_return_if_fail (comp != NULL);
2846 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2847 g_return_if_fail (exdate_list != NULL);
2850 g_return_if_fail (priv->icalcomp != NULL);
2852 *exdate_list = NULL;
2854 for (l = priv->exdate_list; l; l = l->next) {
2855 struct datetime *dt;
2856 ECalComponentDateTime *cdt;
2860 cdt = g_new (ECalComponentDateTime, 1);
2861 cdt->value = g_new (struct icaltimetype, 1);
2863 *cdt->value = icalproperty_get_exdate (dt->prop);
2866 cdt->tzid = g_strdup (icalparameter_get_tzid (dt->tzid_param));
2870 *exdate_list = g_slist_prepend (*exdate_list, cdt);
2873 *exdate_list = g_slist_reverse (*exdate_list);
2877 * e_cal_component_set_exdate_list:
2878 * @comp: A calendar component object.
2879 * @exdate_list: List of #ECalComponentDateTime structures.
2881 * Sets the list of exception dates in a calendar component object.
2884 e_cal_component_set_exdate_list (ECalComponent *comp, GSList *exdate_list)
2886 ECalComponentPrivate *priv;
2889 g_return_if_fail (comp != NULL);
2890 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
2893 g_return_if_fail (priv->icalcomp != NULL);
2895 /* Remove old exception dates */
2897 for (l = priv->exdate_list; l; l = l->next) {
2898 struct datetime *dt;
2902 /* Removing the DATE or DATE-TIME property will also remove
2903 any TZID parameter. */
2904 icalcomponent_remove_property (priv->icalcomp, dt->prop);
2905 icalproperty_free (dt->prop);
2909 g_slist_free (priv->exdate_list);
2910 priv->exdate_list = NULL;
2912 /* Add in new exception dates */
2914 for (l = exdate_list; l; l = l->next) {
2915 ECalComponentDateTime *cdt;
2916 struct datetime *dt;
2918 g_assert (l->data != NULL);
2921 g_assert (cdt->value != NULL);
2923 dt = g_new (struct datetime, 1);
2924 dt->prop = icalproperty_new_exdate (*cdt->value);
2927 dt->tzid_param = icalparameter_new_tzid ((char *) cdt->tzid);
2928 icalproperty_add_parameter (dt->prop, dt->tzid_param);
2930 dt->tzid_param = NULL;
2932 icalcomponent_add_property (priv->icalcomp, dt->prop);
2933 priv->exdate_list = g_slist_prepend (priv->exdate_list, dt);
2936 priv->exdate_list = g_slist_reverse (priv->exdate_list);
2938 priv->need_sequence_inc = TRUE;
2942 * e_cal_component_has_exdates:
2943 * @comp: A calendar component object.
2945 * Queries whether a calendar component object has any exception dates defined
2948 * Return value: TRUE if the component has exception dates, FALSE otherwise.
2951 e_cal_component_has_exdates (ECalComponent *comp)
2953 ECalComponentPrivate *priv;
2955 g_return_val_if_fail (comp != NULL, FALSE);
2956 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
2959 g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
2961 return (priv->exdate_list != NULL);
2964 /* Gets a list of recurrence rules */
2966 get_recur_list (GSList *recur_list,
2967 struct icalrecurrencetype (* get_prop_func) (const icalproperty *prop),
2974 for (l = recur_list; l; l = l->next) {
2976 struct icalrecurrencetype *r;
2980 r = g_new (struct icalrecurrencetype, 1);
2981 *r = (* get_prop_func) (prop);
2983 *list = g_slist_prepend (*list, r);
2986 *list = g_slist_reverse (*list);
2989 /* Sets a list of recurrence rules */
2991 set_recur_list (ECalComponent *comp,
2992 icalproperty *(* new_prop_func) (struct icalrecurrencetype recur),
2993 GSList **recur_list,
2996 ECalComponentPrivate *priv;
3001 /* Remove old recurrences */
3003 for (l = *recur_list; l; l = l->next) {
3007 icalcomponent_remove_property (priv->icalcomp, prop);
3008 icalproperty_free (prop);
3011 g_slist_free (*recur_list);
3014 /* Add in new recurrences */
3016 for (l = rl; l; l = l->next) {
3018 struct icalrecurrencetype *recur;
3020 g_assert (l->data != NULL);
3023 prop = (* new_prop_func) (*recur);
3024 icalcomponent_add_property (priv->icalcomp, prop);
3026 *recur_list = g_slist_prepend (*recur_list, prop);
3029 *recur_list = g_slist_reverse (*recur_list);
3033 * e_cal_component_get_exrule_list:
3034 * @comp: A calendar component object.
3035 * @recur_list: List of exception rules as struct #icalrecurrencetype
3036 * structures. This should be freed using the e_cal_component_free_recur_list()
3039 * Queries the list of exception rule properties of a calendar component
3043 e_cal_component_get_exrule_list (ECalComponent *comp, GSList **recur_list)
3045 ECalComponentPrivate *priv;
3047 g_return_if_fail (comp != NULL);
3048 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3049 g_return_if_fail (recur_list != NULL);
3052 g_return_if_fail (priv->icalcomp != NULL);
3054 get_recur_list (priv->exrule_list, icalproperty_get_exrule, recur_list);
3058 * e_cal_component_get_exrule_property_list:
3059 * @comp: A calendar component object.
3060 * @recur_list: Returns a list of exception rule properties.
3062 * Queries the list of exception rule properties of a calendar component object.
3065 e_cal_component_get_exrule_property_list (ECalComponent *comp, GSList **recur_list)
3067 ECalComponentPrivate *priv;
3069 g_return_if_fail (comp != NULL);
3070 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3071 g_return_if_fail (recur_list != NULL);
3074 g_return_if_fail (priv->icalcomp != NULL);
3076 *recur_list = priv->exrule_list;
3080 * e_cal_component_set_exrule_list:
3081 * @comp: A calendar component object.
3082 * @recur_list: List of struct #icalrecurrencetype structures.
3084 * Sets the list of exception rules in a calendar component object.
3087 e_cal_component_set_exrule_list (ECalComponent *comp, GSList *recur_list)
3089 ECalComponentPrivate *priv;
3091 g_return_if_fail (comp != NULL);
3092 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3095 g_return_if_fail (priv->icalcomp != NULL);
3097 set_recur_list (comp, icalproperty_new_exrule, &priv->exrule_list, recur_list);
3099 priv->need_sequence_inc = TRUE;
3103 * e_cal_component_has_exrules:
3104 * @comp: A calendar component object.
3106 * Queries whether a calendar component object has any exception rules defined
3109 * Return value: TRUE if the component has exception rules, FALSE otherwise.
3112 e_cal_component_has_exrules (ECalComponent *comp)
3114 ECalComponentPrivate *priv;
3116 g_return_val_if_fail (comp != NULL, FALSE);
3117 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
3120 g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
3122 return (priv->exrule_list != NULL);
3126 * e_cal_component_has_exceptions:
3127 * @comp: A calendar component object
3129 * Queries whether a calendar component object has any exception dates
3130 * or exception rules.
3132 * Return value: TRUE if the component has exceptions, FALSE otherwise.
3135 e_cal_component_has_exceptions (ECalComponent *comp)
3137 return e_cal_component_has_exdates (comp) || e_cal_component_has_exrules (comp);
3141 * e_cal_component_get_geo:
3142 * @comp: A calendar component object.
3143 * @geo: Return value for the geographic position property. This should be
3144 * freed using the e_cal_component_free_geo() function.
3146 * Gets the geographic position property of a calendar component object.
3149 e_cal_component_get_geo (ECalComponent *comp, struct icalgeotype **geo)
3151 ECalComponentPrivate *priv;
3153 g_return_if_fail (comp != NULL);
3154 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3155 g_return_if_fail (geo != NULL);
3158 g_return_if_fail (priv->icalcomp != NULL);
3161 *geo = g_new (struct icalgeotype, 1);
3162 **geo = icalproperty_get_geo (priv->geo);
3168 * e_cal_component_set_geo:
3169 * @comp: A calendar component object.
3170 * @geo: Value for the geographic position property.
3172 * Sets the geographic position property on a calendar component object.
3175 e_cal_component_set_geo (ECalComponent *comp, struct icalgeotype *geo)
3177 ECalComponentPrivate *priv;
3179 g_return_if_fail (comp != NULL);
3180 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3183 g_return_if_fail (priv->icalcomp != NULL);
3187 icalcomponent_remove_property (priv->icalcomp, priv->geo);
3188 icalproperty_free (priv->geo);
3196 icalproperty_set_geo (priv->geo, *geo);
3198 priv->geo = icalproperty_new_geo (*geo);
3199 icalcomponent_add_property (priv->icalcomp, priv->geo);
3204 * e_cal_component_get_last_modified:
3205 * @comp: A calendar component object.
3206 * @t: Return value for the last modified time value.
3208 * Queries the time at which a calendar component object was last modified in
3209 * the calendar store.
3212 e_cal_component_get_last_modified (ECalComponent *comp, struct icaltimetype **t)
3214 ECalComponentPrivate *priv;
3216 g_return_if_fail (comp != NULL);
3217 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3218 g_return_if_fail (t != NULL);
3221 g_return_if_fail (priv->icalcomp != NULL);
3223 get_icaltimetype (priv->last_modified, icalproperty_get_lastmodified, t);
3227 * e_cal_component_set_last_modified:
3228 * @comp: A calendar component object.
3229 * @t: Value for the last time modified.
3231 * Sets the time at which a calendar component object was last stored in the
3232 * calendar store. This should not be called by plain calendar user agents.
3235 e_cal_component_set_last_modified (ECalComponent *comp, struct icaltimetype *t)
3237 ECalComponentPrivate *priv;
3239 g_return_if_fail (comp != NULL);
3240 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3243 g_return_if_fail (priv->icalcomp != NULL);
3245 set_icaltimetype (comp, &priv->last_modified,
3246 icalproperty_new_lastmodified,
3247 icalproperty_set_lastmodified,
3252 * e_cal_component_get_organizer:
3253 * @comp: A calendar component object
3254 * @organizer: A value for the organizer
3256 * Queries the organizer property of a calendar component object
3259 e_cal_component_get_organizer (ECalComponent *comp, ECalComponentOrganizer *organizer)
3261 ECalComponentPrivate *priv;
3263 g_return_if_fail (comp != NULL);
3264 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3265 g_return_if_fail (organizer != NULL);
3268 g_return_if_fail (priv->icalcomp != NULL);
3270 if (priv->organizer.prop)
3271 organizer->value = icalproperty_get_organizer (priv->organizer.prop);
3273 organizer->value = NULL;
3275 if (priv->organizer.sentby_param)
3276 organizer->sentby = icalparameter_get_sentby (priv->organizer.sentby_param);
3278 organizer->sentby = NULL;
3280 if (priv->organizer.cn_param)
3281 organizer->cn = icalparameter_get_sentby (priv->organizer.cn_param);
3283 organizer->cn = NULL;
3285 if (priv->organizer.language_param)
3286 organizer->language = icalparameter_get_sentby (priv->organizer.language_param);
3288 organizer->language = NULL;
3293 * e_cal_component_set_organizer:
3294 * @comp: A calendar component object.
3295 * @organizer: Value for the organizer property
3297 * Sets the organizer of a calendar component object
3300 e_cal_component_set_organizer (ECalComponent *comp, ECalComponentOrganizer *organizer)
3302 ECalComponentPrivate *priv;
3304 g_return_if_fail (comp != NULL);
3305 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3308 g_return_if_fail (priv->icalcomp != NULL);
3311 if (priv->organizer.prop) {
3312 icalcomponent_remove_property (priv->icalcomp, priv->organizer.prop);
3313 icalproperty_free (priv->organizer.prop);
3315 priv->organizer.prop = NULL;
3316 priv->organizer.sentby_param = NULL;
3317 priv->organizer.cn_param = NULL;
3318 priv->organizer.language_param = NULL;
3324 g_return_if_fail (organizer->value != NULL);
3326 if (priv->organizer.prop)
3327 icalproperty_set_organizer (priv->organizer.prop, (char *) organizer->value);
3329 priv->organizer.prop = icalproperty_new_organizer ((char *) organizer->value);
3330 icalcomponent_add_property (priv->icalcomp, priv->organizer.prop);
3333 if (organizer->sentby) {
3334 g_assert (priv->organizer.prop != NULL);
3336 if (priv->organizer.sentby_param)
3337 icalparameter_set_sentby (priv->organizer.sentby_param,
3338 (char *) organizer->sentby);
3340 priv->organizer.sentby_param = icalparameter_new_sentby (
3341 (char *) organizer->sentby);
3342 icalproperty_add_parameter (priv->organizer.prop,
3343 priv->organizer.sentby_param);
3345 } else if (priv->organizer.sentby_param) {
3346 icalproperty_remove_parameter (priv->organizer.prop, ICAL_SENTBY_PARAMETER);
3347 priv->organizer.sentby_param = NULL;
3350 if (organizer->cn) {
3351 g_assert (priv->organizer.prop != NULL);
3353 if (priv->organizer.cn_param)
3354 icalparameter_set_cn (priv->organizer.cn_param,
3355 (char *) organizer->cn);
3357 priv->organizer.cn_param = icalparameter_new_cn (
3358 (char *) organizer->cn);
3359 icalproperty_add_parameter (priv->organizer.prop,
3360 priv->organizer.cn_param);
3362 } else if (priv->organizer.cn_param) {
3363 icalproperty_remove_parameter (priv->organizer.prop, ICAL_CN_PARAMETER);
3364 priv->organizer.cn_param = NULL;
3367 if (organizer->language) {
3368 g_assert (priv->organizer.prop != NULL);
3370 if (priv->organizer.language_param)
3371 icalparameter_set_language (priv->organizer.language_param,
3372 (char *) organizer->language);
3374 priv->organizer.language_param = icalparameter_new_language (
3375 (char *) organizer->language);
3376 icalproperty_add_parameter (priv->organizer.prop,
3377 priv->organizer.language_param);
3379 } else if (priv->organizer.language_param) {
3380 icalproperty_remove_parameter (priv->organizer.prop, ICAL_LANGUAGE_PARAMETER);
3381 priv->organizer.language_param = NULL;
3389 * e_cal_component_has_organizer:
3390 * @comp: A calendar component object.
3392 * Check whether a calendar component object has an organizer or not.
3394 * Return value: TRUE if there is an organizer, FALSE otherwise.
3397 e_cal_component_has_organizer (ECalComponent *comp)
3399 ECalComponentPrivate *priv;
3401 g_return_val_if_fail (comp != NULL, FALSE);
3402 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
3406 return priv->organizer.prop != NULL;
3410 * e_cal_component_get_percent:
3411 * @comp: A calendar component object.
3412 * @percent: Return value for the percent-complete property. This should be
3413 * freed using the e_cal_component_free_percent() function.
3415 * Queries the percent-complete property of a calendar component object.
3418 e_cal_component_get_percent (ECalComponent *comp, int **percent)
3420 ECalComponentPrivate *priv;
3422 g_return_if_fail (comp != NULL);
3423 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3424 g_return_if_fail (percent != NULL);
3427 g_return_if_fail (priv->icalcomp != NULL);
3429 if (priv->percent) {
3430 *percent = g_new (int, 1);
3431 **percent = icalproperty_get_percentcomplete (priv->percent);
3437 * e_cal_component_set_percent:
3438 * @comp: A calendar component object.
3439 * @percent: Value for the percent-complete property.
3441 * Sets the percent-complete property of a calendar component object.
3444 e_cal_component_set_percent (ECalComponent *comp, int *percent)
3446 ECalComponentPrivate *priv;
3448 g_return_if_fail (comp != NULL);
3449 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3452 g_return_if_fail (priv->icalcomp != NULL);
3455 if (priv->percent) {
3456 icalcomponent_remove_property (priv->icalcomp, priv->percent);
3457 icalproperty_free (priv->percent);
3458 priv->percent = NULL;
3464 g_return_if_fail (*percent >= 0 && *percent <= 100);
3467 icalproperty_set_percentcomplete (priv->percent, *percent);
3469 priv->percent = icalproperty_new_percentcomplete (*percent);
3470 icalcomponent_add_property (priv->icalcomp, priv->percent);
3475 * e_cal_component_get_priority:
3476 * @comp: A calendar component object.
3477 * @priority: Return value for the priority property. This should be freed using
3478 * the e_cal_component_free_priority() function.
3480 * Queries the priority property of a calendar component object.
3483 e_cal_component_get_priority (ECalComponent *comp, int **priority)
3485 ECalComponentPrivate *priv;
3487 g_return_if_fail (comp != NULL);
3488 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3489 g_return_if_fail (priority != NULL);
3492 g_return_if_fail (priv->icalcomp != NULL);
3494 if (priv->priority) {
3495 *priority = g_new (int, 1);
3496 **priority = icalproperty_get_priority (priv->priority);
3502 * e_cal_component_set_priority:
3503 * @comp: A calendar component object.
3504 * @priority: Value for the priority property.
3506 * Sets the priority property of a calendar component object.
3509 e_cal_component_set_priority (ECalComponent *comp, int *priority)
3511 ECalComponentPrivate *priv;
3513 g_return_if_fail (comp != NULL);
3514 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3517 g_return_if_fail (priv->icalcomp != NULL);
3520 if (priv->priority) {
3521 icalcomponent_remove_property (priv->icalcomp, priv->priority);
3522 icalproperty_free (priv->priority);
3523 priv->priority = NULL;
3529 g_return_if_fail (*priority >= 0 && *priority <= 9);
3532 icalproperty_set_priority (priv->priority, *priority);
3534 priv->priority = icalproperty_new_priority (*priority);
3535 icalcomponent_add_property (priv->icalcomp, priv->priority);
3540 * e_cal_component_get_recurid:
3541 * @comp: A calendar component object.
3542 * @recur_id: Return value for the recurrence id property
3544 * Queries the recurrence id property of a calendar component object.
3547 e_cal_component_get_recurid (ECalComponent *comp, ECalComponentRange *recur_id)
3549 ECalComponentPrivate *priv;
3551 g_return_if_fail (comp != NULL);
3552 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3553 g_return_if_fail (recur_id != NULL);
3556 g_return_if_fail (priv->icalcomp != NULL);
3558 get_datetime (&priv->recur_id.recur_time,
3559 icalproperty_get_recurrenceid,
3560 &recur_id->datetime);
3564 * e_cal_component_get_recurid_as_string:
3565 * @comp: A calendar component object.
3567 * Gets the recurrence ID property as a string.
3569 * Return value: the recurrence ID as a string.
3572 e_cal_component_get_recurid_as_string (ECalComponent *comp)
3574 ECalComponentRange range;
3575 struct icaltimetype tt;
3577 if (!e_cal_component_is_instance (comp))
3580 e_cal_component_get_recurid (comp, &range);
3581 if (!range.datetime.value)
3583 tt = *range.datetime.value;
3584 e_cal_component_free_range (&range);
3586 return icaltime_is_valid_time (tt) && !icaltime_is_null_time (tt) ?
3587 icaltime_as_ical_string (tt) : "0";
3591 * e_cal_component_set_recurid:
3592 * @comp: A calendar component object.
3593 * @recur_id: Value for the recurrence id property.
3595 * Sets the recurrence id property of a calendar component object.
3598 e_cal_component_set_recurid (ECalComponent *comp, ECalComponentRange *recur_id)
3600 ECalComponentPrivate *priv;
3602 g_return_if_fail (comp != NULL);
3603 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3606 g_return_if_fail (priv->icalcomp != NULL);
3608 set_datetime (comp, &priv->recur_id.recur_time,
3609 icalproperty_new_recurrenceid,
3610 icalproperty_set_recurrenceid,
3611 recur_id ? &recur_id->datetime : NULL);
3615 * e_cal_component_get_rdate_list:
3616 * @comp: A calendar component object.
3617 * @period_list: Return value for the list of recurrence dates, as a list of
3618 * #ECalComponentPeriod structures. This should be freed using the
3619 * e_cal_component_free_period_list() function.
3621 * Queries the list of recurrence date properties in a calendar component
3625 e_cal_component_get_rdate_list (ECalComponent *comp, GSList **period_list)
3627 ECalComponentPrivate *priv;
3629 g_return_if_fail (comp != NULL);
3630 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3631 g_return_if_fail (period_list != NULL);
3634 g_return_if_fail (priv->icalcomp != NULL);
3636 get_period_list (priv->rdate_list, icalproperty_get_rdate, period_list);
3640 * e_cal_component_set_rdate_list:
3641 * @comp: A calendar component object.
3642 * @period_list: List of #ECalComponentPeriod structures.
3644 * Sets the list of recurrence dates in a calendar component object.
3647 e_cal_component_set_rdate_list (ECalComponent *comp, GSList *period_list)
3649 ECalComponentPrivate *priv;
3651 g_return_if_fail (comp != NULL);
3652 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3655 g_return_if_fail (priv->icalcomp != NULL);
3657 set_period_list (comp, icalproperty_new_rdate, &priv->rdate_list, period_list);
3659 priv->need_sequence_inc = TRUE;
3663 * e_cal_component_has_rdates:
3664 * @comp: A calendar component object.
3666 * Queries whether a calendar component object has any recurrence dates defined
3669 * Return value: TRUE if the component has recurrence dates, FALSE otherwise.
3672 e_cal_component_has_rdates (ECalComponent *comp)
3674 ECalComponentPrivate *priv;
3676 g_return_val_if_fail (comp != NULL, FALSE);
3677 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
3680 g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
3682 return (priv->rdate_list != NULL);
3686 * e_cal_component_get_rrule_list:
3687 * @comp: A calendar component object.
3688 * @recur_list: List of recurrence rules as struct #icalrecurrencetype
3689 * structures. This should be freed using the e_cal_component_free_recur_list()
3692 * Queries the list of recurrence rule properties of a calendar component
3696 e_cal_component_get_rrule_list (ECalComponent *comp, GSList **recur_list)
3698 ECalComponentPrivate *priv;
3700 g_return_if_fail (comp != NULL);
3701 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3702 g_return_if_fail (recur_list != NULL);
3705 g_return_if_fail (priv->icalcomp != NULL);
3707 get_recur_list (priv->rrule_list, icalproperty_get_rrule, recur_list);
3711 * e_cal_component_get_rrule_property_list:
3712 * @comp: A calendar component object.
3713 * @recur_list: Returns a list of recurrence rule properties.
3715 * Queries a list of recurrence rule properties of a calendar component object.
3718 e_cal_component_get_rrule_property_list (ECalComponent *comp, GSList **recur_list)
3720 ECalComponentPrivate *priv;
3722 g_return_if_fail (comp != NULL);
3723 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3724 g_return_if_fail (recur_list != NULL);
3727 g_return_if_fail (priv->icalcomp != NULL);
3729 *recur_list = priv->rrule_list;
3733 * e_cal_component_set_rrule_list:
3734 * @comp: A calendar component object.
3735 * @recur_list: List of struct #icalrecurrencetype structures.
3737 * Sets the list of recurrence rules in a calendar component object.
3740 e_cal_component_set_rrule_list (ECalComponent *comp, GSList *recur_list)
3742 ECalComponentPrivate *priv;
3744 g_return_if_fail (comp != NULL);
3745 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
3748 g_return_if_fail (priv->icalcomp != NULL);
3750 set_recur_list (comp, icalproperty_new_rrule, &priv->rrule_list, recur_list);
3752 priv->need_sequence_inc = TRUE;
3756 * e_cal_component_has_rrules:
3757 * @comp: A calendar component object.
3759 * Queries whether a calendar component object has any recurrence rules defined
3762 * Return value: TRUE if the component has recurrence rules, FALSE otherwise.
3765 e_cal_component_has_rrules (ECalComponent *comp)
3767 ECalComponentPrivate *priv;
3769 g_return_val_if_fail (comp != NULL, FALSE);
3770 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
3773 g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
3775 return (priv->rrule_list != NULL);
3779 * e_cal_component_has_recurrences:
3780 * @comp: A calendar component object
3782 * Queries whether a calendar component object has any recurrence dates or
3785 * Return value: TRUE if the component has recurrences, FALSE otherwise.
3788 e_cal_component_has_recurrences (ECalComponent *comp)
3790 return e_cal_component_has_rdates (comp) || e_cal_component_has_rrules (comp);
3793 /* Counts the elements in the by_xxx fields of an icalrecurrencetype */
3795 count_by_xxx (short *field, int max_elements)
3799 for (i = 0; i < max_elements; i++)
3800 if (field[i] == ICAL_RECURRENCE_ARRAY_MAX)
3807 * e_cal_component_has_simple_recurrence:
3808 * @comp: A calendar component object.
3810 * Checks whether the given calendar component object has simple recurrence
3811 * rules or more complicated ones.
3813 * Return value: TRUE if it has a simple recurrence rule, FALSE otherwise.
3816 e_cal_component_has_simple_recurrence (ECalComponent *comp)
3819 struct icalrecurrencetype *r;
3820 int n_by_second, n_by_minute, n_by_hour;
3821 int n_by_day, n_by_month_day, n_by_year_day;
3822 int n_by_week_no, n_by_month, n_by_set_pos;
3824 gboolean simple = FALSE;
3826 if (!e_cal_component_has_recurrences (comp))
3829 e_cal_component_get_rrule_list (comp, &rrule_list);
3830 len = g_slist_length (rrule_list);
3832 || e_cal_component_has_rdates (comp)
3833 || e_cal_component_has_exrules (comp))
3836 /* Down to one rule, so test that one */
3837 r = rrule_list->data;
3839 /* Any funky frequency? */
3840 if (r->freq == ICAL_SECONDLY_RECURRENCE
3841 || r->freq == ICAL_MINUTELY_RECURRENCE
3842 || r->freq == ICAL_HOURLY_RECURRENCE)
3845 /* Any funky BY_* */
3846 #define N_HAS_BY(field) (count_by_xxx (field, sizeof (field) / sizeof (field[0])))
3848 n_by_second = N_HAS_BY (r->by_second);
3849 n_by_minute = N_HAS_BY (r->by_minute);
3850 n_by_hour = N_HAS_BY (r->by_hour);
3851 n_by_day = N_HAS_BY (r->by_day);
3852 n_by_month_day = N_HAS_BY (r->by_month_day);
3853 n_by_year_day = N_HAS_BY (r->by_year_day);
3854 n_by_week_no = N_HAS_BY (r->by_week_no);
3855 n_by_month = N_HAS_BY (r->by_month);
3856 n_by_set_pos = N_HAS_BY (r->by_set_pos);
3858 if (n_by_second != 0
3864 case ICAL_DAILY_RECURRENCE:
3866 || n_by_month_day != 0
3867 || n_by_year_day != 0
3868 || n_by_week_no != 0
3870 || n_by_set_pos != 0)
3876 case ICAL_WEEKLY_RECURRENCE:
3877 if (n_by_month_day != 0
3878 || n_by_year_day != 0
3879 || n_by_week_no != 0
3881 || n_by_set_pos != 0)
3884 for (i = 0; i < 8 && r->by_day[i] != ICAL_RECURRENCE_ARRAY_MAX; i++) {
3886 pos = icalrecurrencetype_day_position (r->by_day[i]);
3895 case ICAL_MONTHLY_RECURRENCE:
3896 if (n_by_year_day != 0
3897 || n_by_week_no != 0
3899 || n_by_set_pos > 1)
3902 if (n_by_month_day == 1) {
3905 if (n_by_set_pos != 0)
3908 nth = r->by_month_day[0];
3909 if (nth < 1 && nth != -1)
3914 } else if (n_by_day == 1) {
3915 enum icalrecurrencetype_weekday weekday;
3918 /* Outlook 2000 uses BYDAY=TU;BYSETPOS=2, and will not
3919 accept BYDAY=2TU. So we now use the same as Outlook
3922 weekday = icalrecurrencetype_day_day_of_week (r->by_day[0]);
3923 pos = icalrecurrencetype_day_position (r->by_day[0]);
3926 if (n_by_set_pos != 1)
3928 pos = r->by_set_pos[0];
3929 } else if (pos < 0) {
3934 case ICAL_MONDAY_WEEKDAY:
3935 case ICAL_TUESDAY_WEEKDAY:
3936 case ICAL_WEDNESDAY_WEEKDAY:
3937 case ICAL_THURSDAY_WEEKDAY:
3938 case ICAL_FRIDAY_WEEKDAY:
3939 case ICAL_SATURDAY_WEEKDAY:
3940 case ICAL_SUNDAY_WEEKDAY:
3953 case ICAL_YEARLY_RECURRENCE:
3955 || n_by_month_day != 0
3956 || n_by_year_day != 0
3957 || n_by_week_no != 0
3959 || n_by_set_pos != 0)
3970 e_cal_component_free_recur_list (rrule_list);
3976 * e_cal_component_is_instance:
3977 * @comp: A calendar component object.
3979 * Checks whether a calendar component object is an instance of a recurring
3982 * Return value: TRUE if it is an instance, FALSE if not.
3985 e_cal_component_is_instance (ECalComponent *comp)
3987 ECalComponentPrivate *priv;
3989 g_return_val_if_fail (comp != NULL, FALSE);
3990 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
3994 return !(priv->recur_id.recur_time.prop == NULL);
3998 * e_cal_component_get_sequence:
3999 * @comp: A calendar component object.
4000 * @sequence: Return value for the sequence number. This should be freed using
4001 * e_cal_component_free_sequence().
4003 * Queries the sequence number of a calendar component object.
4006 e_cal_component_get_sequence (ECalComponent *comp, int **sequence)
4008 ECalComponentPrivate *priv;
4010 g_return_if_fail (comp != NULL);
4011 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4012 g_return_if_fail (sequence != NULL);
4015 g_return_if_fail (priv->icalcomp != NULL);
4017 if (!priv->sequence) {
4022 *sequence = g_new (int, 1);
4023 **sequence = icalproperty_get_sequence (priv->sequence);
4027 * e_cal_component_set_sequence:
4028 * @comp: A calendar component object.
4029 * @sequence: Sequence number value.
4031 * Sets the sequence number of a calendar component object. Normally this
4032 * function should not be called, since the sequence number is incremented
4033 * automatically at the proper times.
4036 e_cal_component_set_sequence (ECalComponent *comp, int *sequence)
4038 ECalComponentPrivate *priv;
4040 g_return_if_fail (comp != NULL);
4041 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4044 g_return_if_fail (priv->icalcomp != NULL);
4046 priv->need_sequence_inc = FALSE;
4049 if (priv->sequence) {
4050 icalcomponent_remove_property (priv->icalcomp, priv->sequence);
4051 icalproperty_free (priv->sequence);
4052 priv->sequence = NULL;
4059 icalproperty_set_sequence (priv->sequence, *sequence);
4061 priv->sequence = icalproperty_new_sequence (*sequence);
4062 icalcomponent_add_property (priv->icalcomp, priv->sequence);
4067 * e_cal_component_get_status:
4068 * @comp: A calendar component object.
4069 * @status: Return value for the status value. It is set to #ICAL_STATUS_NONE
4070 * if the component has no status property.
4072 * Queries the status property of a calendar component object.
4075 e_cal_component_get_status (ECalComponent *comp, icalproperty_status *status)
4077 ECalComponentPrivate *priv;
4079 g_return_if_fail (comp != NULL);
4080 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4081 g_return_if_fail (status != NULL);
4084 g_return_if_fail (priv->icalcomp != NULL);
4086 if (!priv->status) {
4087 *status = ICAL_STATUS_NONE;
4091 *status = icalproperty_get_status (priv->status);
4095 * e_cal_component_set_status:
4096 * @comp: A calendar component object.
4097 * @status: Status value. You should use #ICAL_STATUS_NONE if you want to unset
4100 * Sets the status property of a calendar component object.
4103 e_cal_component_set_status (ECalComponent *comp, icalproperty_status status)
4105 ECalComponentPrivate *priv;
4107 g_return_if_fail (comp != NULL);
4108 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4111 g_return_if_fail (priv->icalcomp != NULL);
4113 priv->need_sequence_inc = TRUE;
4115 if (status == ICAL_STATUS_NONE) {
4117 icalcomponent_remove_property (priv->icalcomp, priv->status);
4118 icalproperty_free (priv->status);
4119 priv->status = NULL;
4126 icalproperty_set_status (priv->status, status);
4128 priv->status = icalproperty_new_status (status);
4129 icalcomponent_add_property (priv->icalcomp, priv->status);
4134 * e_cal_component_get_summary:
4135 * @comp: A calendar component object.
4136 * @summary: Return value for the summary property and its parameters.
4138 * Queries the summary of a calendar component object.
4141 e_cal_component_get_summary (ECalComponent *comp, ECalComponentText *summary)
4143 ECalComponentPrivate *priv;
4145 g_return_if_fail (comp != NULL);
4146 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4147 g_return_if_fail (summary != NULL);
4150 g_return_if_fail (priv->icalcomp != NULL);
4152 if (priv->summary.prop)
4153 summary->value = icalproperty_get_summary (priv->summary.prop);
4155 summary->value = NULL;
4157 if (priv->summary.altrep_param)
4158 summary->altrep = icalparameter_get_altrep (priv->summary.altrep_param);
4160 summary->altrep = NULL;
4164 const char *old_summary;
4165 const char *new_summary;
4166 } SetAlarmDescriptionData;
4169 set_alarm_description_cb (gpointer key, gpointer value, gpointer user_data)
4171 icalcomponent *alarm;
4172 icalproperty *icalprop, *desc_prop;
4173 SetAlarmDescriptionData *sadd;
4174 gboolean changed = FALSE;
4175 const char *old_summary = NULL;
4180 /* set the new description on the alarm */
4181 desc_prop = icalcomponent_get_first_property (alarm, ICAL_DESCRIPTION_PROPERTY);
4183 old_summary = icalproperty_get_description (desc_prop);
4185 desc_prop = icalproperty_new_description (sadd->new_summary);
4187 /* remove the X-EVOLUTION-NEEDS_DESCRIPTION property */
4188 icalprop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
4192 x_name = icalproperty_get_x_name (icalprop);
4193 if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
4194 icalcomponent_remove_property (alarm, icalprop);
4195 icalproperty_free (icalprop);
4197 icalproperty_set_description (desc_prop, sadd->new_summary);
4202 icalprop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY);
4206 if (!strcmp (old_summary ? old_summary : "", sadd->old_summary ? sadd->old_summary : "")) {
4207 icalproperty_set_description (desc_prop, sadd->new_summary);
4213 * e_cal_component_set_summary:
4214 * @comp: A calendar component object.
4215 * @summary: Summary property and its parameters.
4217 * Sets the summary of a calendar component object.
4220 e_cal_component_set_summary (ECalComponent *comp, ECalComponentText *summary)
4222 ECalComponentPrivate *priv;
4223 SetAlarmDescriptionData sadd;
4225 g_return_if_fail (comp != NULL);
4226 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4229 g_return_if_fail (priv->icalcomp != NULL);
4232 if (priv->summary.prop) {
4233 icalcomponent_remove_property (priv->icalcomp, priv->summary.prop);
4234 icalproperty_free (priv->summary.prop);
4236 priv->summary.prop = NULL;
4237 priv->summary.altrep_param = NULL;
4243 g_return_if_fail (summary->value != NULL);
4245 if (priv->summary.prop) {
4246 sadd.old_summary = icalproperty_get_summary (priv->summary.prop);
4247 icalproperty_set_summary (priv->summary.prop, (char *) summary->value);
4249 sadd.old_summary = NULL;
4250 priv->summary.prop = icalproperty_new_summary ((char *) summary->value);
4251 icalcomponent_add_property (priv->icalcomp, priv->summary.prop);
4254 if (summary->altrep) {
4255 g_assert (priv->summary.prop != NULL);
4257 if (priv->summary.altrep_param)
4258 icalparameter_set_altrep (priv->summary.altrep_param,
4259 (char *) summary->altrep);
4261 priv->summary.altrep_param = icalparameter_new_altrep (
4262 (char *) summary->altrep);
4263 icalproperty_add_parameter (priv->summary.prop,
4264 priv->summary.altrep_param);
4266 } else if (priv->summary.altrep_param) {
4267 icalproperty_remove_parameter (priv->summary.prop, ICAL_ALTREP_PARAMETER);
4268 priv->summary.altrep_param = NULL;
4271 /* look for alarms that need a description */
4272 sadd.new_summary = summary->value;
4273 g_hash_table_foreach (priv->alarm_uid_hash, set_alarm_description_cb, &sadd);
4277 * e_cal_component_get_transparency:
4278 * @comp: A calendar component object.
4279 * @transp: Return value for the time transparency.
4281 * Queries the time transparency of a calendar component object.
4284 e_cal_component_get_transparency (ECalComponent *comp, ECalComponentTransparency *transp)
4286 ECalComponentPrivate *priv;
4287 icalproperty_transp ical_transp;
4289 g_return_if_fail (comp != NULL);
4290 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4291 g_return_if_fail (transp != NULL);
4294 g_return_if_fail (priv->icalcomp != NULL);
4296 if (!priv->transparency) {
4297 *transp = E_CAL_COMPONENT_TRANSP_NONE;
4301 ical_transp = icalproperty_get_transp (priv->transparency);
4303 switch (ical_transp)
4305 case ICAL_TRANSP_TRANSPARENT:
4306 case ICAL_TRANSP_TRANSPARENTNOCONFLICT:
4307 *transp = E_CAL_COMPONENT_TRANSP_TRANSPARENT;
4310 case ICAL_TRANSP_OPAQUE:
4311 case ICAL_TRANSP_OPAQUENOCONFLICT:
4312 *transp = E_CAL_COMPONENT_TRANSP_OPAQUE;
4316 *transp = E_CAL_COMPONENT_TRANSP_UNKNOWN;
4322 * e_cal_component_set_transparency:
4323 * @comp: A calendar component object.
4324 * @transp: Time transparency value.
4326 * Sets the time transparency of a calendar component object.
4329 e_cal_component_set_transparency (ECalComponent *comp, ECalComponentTransparency transp)
4331 ECalComponentPrivate *priv;
4332 icalproperty_transp ical_transp;
4334 g_return_if_fail (comp != NULL);
4335 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4336 g_return_if_fail (transp != E_CAL_COMPONENT_TRANSP_UNKNOWN);
4339 g_return_if_fail (priv->icalcomp != NULL);
4342 if (transp == E_CAL_COMPONENT_TRANSP_NONE) {
4343 if (priv->transparency) {
4344 icalcomponent_remove_property (priv->icalcomp, priv->transparency);
4345 icalproperty_free (priv->transparency);
4346 priv->transparency = NULL;
4353 case E_CAL_COMPONENT_TRANSP_TRANSPARENT:
4354 ical_transp = ICAL_TRANSP_TRANSPARENT;
4357 case E_CAL_COMPONENT_TRANSP_OPAQUE:
4358 ical_transp = ICAL_TRANSP_OPAQUE;
4362 g_assert_not_reached ();
4363 ical_transp = ICAL_TRANSP_NONE;
4366 if (priv->transparency)
4367 icalproperty_set_transp (priv->transparency, ical_transp);
4369 priv->transparency = icalproperty_new_transp (ical_transp);
4370 icalcomponent_add_property (priv->icalcomp, priv->transparency);
4375 * e_cal_component_get_url:
4376 * @comp: A calendar component object.
4377 * @url: Return value for the URL.
4379 * Queries the uniform resource locator property of a calendar component object.
4382 e_cal_component_get_url (ECalComponent *comp, const char **url)
4384 ECalComponentPrivate *priv;
4386 g_return_if_fail (comp != NULL);
4387 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4388 g_return_if_fail (url != NULL);
4391 g_return_if_fail (priv->icalcomp != NULL);
4394 *url = icalproperty_get_url (priv->url);
4400 * e_cal_component_set_url:
4401 * @comp: A calendar component object.
4404 * Sets the uniform resource locator property of a calendar component object.
4407 e_cal_component_set_url (ECalComponent *comp, const char *url)
4409 ECalComponentPrivate *priv;
4411 g_return_if_fail (comp != NULL);
4412 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4415 g_return_if_fail (priv->icalcomp != NULL);
4417 if (!url || !(*url)) {
4419 icalcomponent_remove_property (priv->icalcomp, priv->url);
4420 icalproperty_free (priv->url);
4428 icalproperty_set_url (priv->url, (char *) url);
4430 priv->url = icalproperty_new_url ((char *) url);
4431 icalcomponent_add_property (priv->icalcomp, priv->url);
4435 /* Gets a text list value */
4437 get_attendee_list (GSList *attendee_list, GSList **al)
4446 for (l = attendee_list; l; l = l->next) {
4447 struct attendee *attendee;
4448 ECalComponentAttendee *a;
4451 g_assert (attendee->prop != NULL);
4453 a = g_new0 (ECalComponentAttendee, 1);
4454 a->value = icalproperty_get_attendee (attendee->prop);
4456 if (attendee->member_param)
4457 a->member = icalparameter_get_member (attendee->member_param);
4458 if (attendee->cutype_param)
4459 a->cutype = icalparameter_get_cutype (attendee->cutype_param);
4461 a->cutype = ICAL_CUTYPE_UNKNOWN;
4462 if (attendee->role_param)
4463 a->role = icalparameter_get_role (attendee->role_param);
4465 a->role = ICAL_ROLE_REQPARTICIPANT;
4466 if (attendee->partstat_param)
4467 a->status = icalparameter_get_partstat (attendee->partstat_param);
4469 a->status = ICAL_PARTSTAT_NEEDSACTION;
4470 if (attendee->rsvp_param && icalparameter_get_rsvp (attendee->rsvp_param) == ICAL_RSVP_TRUE)
4474 if (attendee->delfrom_param)
4475 a->delfrom = icalparameter_get_delegatedfrom (attendee->delfrom_param);
4476 if (attendee->delto_param)
4477 a->delto = icalparameter_get_delegatedto (attendee->delto_param);
4478 if (attendee->sentby_param)
4479 a->sentby = icalparameter_get_sentby (attendee->sentby_param);
4480 if (attendee->cn_param)
4481 a->cn = icalparameter_get_cn (attendee->cn_param);
4482 if (attendee->language_param)
4483 a->language = icalparameter_get_language (attendee->language_param);
4485 *al = g_slist_prepend (*al, a);
4488 *al = g_slist_reverse (*al);
4492 /* Sets a text list value */
4494 set_attendee_list (icalcomponent *icalcomp,
4495 GSList **attendee_list,
4500 /* Remove old attendees */
4502 for (l = *attendee_list; l; l = l->next) {
4503 struct attendee *attendee;
4506 g_assert (attendee->prop != NULL);
4508 icalcomponent_remove_property (icalcomp, attendee->prop);
4509 icalproperty_free (attendee->prop);
4513 g_slist_free (*attendee_list);
4514 *attendee_list = NULL;
4516 /* Add in new attendees */
4518 for (l = al; l; l = l->next) {
4519 ECalComponentAttendee *a;
4520 struct attendee *attendee;
4523 g_return_if_fail (a->value != NULL);
4525 attendee = g_new0 (struct attendee, 1);
4527 attendee->prop = icalproperty_new_attendee (a->value);
4528 icalcomponent_add_property (icalcomp, attendee->prop);
4531 attendee->member_param = icalparameter_new_member (a->member);
4532 icalproperty_add_parameter (attendee->prop, attendee->member_param);
4535 attendee->cutype_param = icalparameter_new_cutype (a->cutype);
4536 icalproperty_add_parameter (attendee->prop, attendee->cutype_param);
4538 attendee->role_param = icalparameter_new_role (a->role);
4539 icalproperty_add_parameter (attendee->prop, attendee->role_param);
4541 attendee->partstat_param = icalparameter_new_partstat (a->status);
4542 icalproperty_add_parameter (attendee->prop, attendee->partstat_param);
4545 attendee->rsvp_param = icalparameter_new_rsvp (ICAL_RSVP_TRUE);
4547 attendee->rsvp_param = icalparameter_new_rsvp (ICAL_RSVP_FALSE);
4548 icalproperty_add_parameter (attendee->prop, attendee->rsvp_param);
4551 attendee->delfrom_param = icalparameter_new_delegatedfrom (a->delfrom);
4552 icalproperty_add_parameter (attendee->prop, attendee->delfrom_param);
4555 attendee->delto_param = icalparameter_new_delegatedto (a->delto);
4556 icalproperty_add_parameter (attendee->prop, attendee->delto_param);
4559 attendee->sentby_param = icalparameter_new_sentby (a->sentby);
4560 icalproperty_add_parameter (attendee->prop, attendee->sentby_param);
4563 attendee->cn_param = icalparameter_new_cn (a->cn);
4564 icalproperty_add_parameter (attendee->prop, attendee->cn_param);
4567 attendee->language_param = icalparameter_new_language (a->language);
4568 icalproperty_add_parameter (attendee->prop, attendee->language_param);
4571 *attendee_list = g_slist_prepend (*attendee_list, attendee);
4574 *attendee_list = g_slist_reverse (*attendee_list);
4578 * e_cal_component_get_attendee_list:
4579 * @comp: A calendar component object.
4580 * @attendee_list: Return value for the attendee property.
4581 * This should be freed using the e_cal_component_free_attendee_list ()
4584 * Queries the attendee properties of the calendar component object
4587 e_cal_component_get_attendee_list (ECalComponent *comp, GSList **attendee_list)
4589 ECalComponentPrivate *priv;
4591 g_return_if_fail (comp != NULL);
4592 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4593 g_return_if_fail (attendee_list != NULL);
4596 g_return_if_fail (priv->icalcomp != NULL);
4598 get_attendee_list (priv->attendee_list, attendee_list);
4602 * e_cal_component_set_attendee_list:
4603 * @comp: A calendar component object.
4604 * @attendee_list: Values for attendee properties
4606 * Sets the attendees of a calendar component object
4609 e_cal_component_set_attendee_list (ECalComponent *comp, GSList *attendee_list)
4611 ECalComponentPrivate *priv;
4613 g_return_if_fail (comp != NULL);
4614 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4617 g_return_if_fail (priv->icalcomp != NULL);
4619 set_attendee_list (priv->icalcomp, &priv->attendee_list, attendee_list);
4623 * e_cal_component_has_attendees:
4624 * @comp: A calendar component object.
4626 * Queries a calendar component object for the existence of attendees.
4628 * Return value: TRUE if there are attendees, FALSE if not.
4631 e_cal_component_has_attendees (ECalComponent *comp)
4633 ECalComponentPrivate *priv;
4635 g_return_val_if_fail (comp != NULL, FALSE);
4636 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
4640 if (g_slist_length (priv->attendee_list) > 0)
4647 * e_cal_component_get_location:
4648 * @comp: A calendar component object
4649 * @location: Return value for the location.
4651 * Queries the location property of a calendar component object.
4654 e_cal_component_get_location (ECalComponent *comp, const char **location)
4656 ECalComponentPrivate *priv;
4658 g_return_if_fail (comp != NULL);
4659 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4660 g_return_if_fail (location != NULL);
4663 g_return_if_fail (priv->icalcomp != NULL);
4666 *location = icalproperty_get_location (priv->location);
4672 * e_cal_component_set_location:
4673 * @comp: A calendar component object.
4674 * @location: Location value.
4676 * Sets the location property of a calendar component object.
4679 e_cal_component_set_location (ECalComponent *comp, const char *location)
4681 ECalComponentPrivate *priv;
4683 g_return_if_fail (comp != NULL);
4684 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
4687 g_return_if_fail (priv->icalcomp != NULL);
4689 if (!location || !(*location)) {
4690 if (priv->location) {
4691 icalcomponent_remove_property (priv->icalcomp, priv->location);
4692 icalproperty_free (priv->location);
4693 priv->location = NULL;
4700 icalproperty_set_location (priv->location, (char *) location);
4702 priv->location = icalproperty_new_location ((char *) location);
4703 icalcomponent_add_property (priv->icalcomp, priv->location);
4710 * e_cal_component_free_categories_list:
4711 * @categ_list: List of category strings.
4713 * Frees a list of category strings.
4716 e_cal_component_free_categories_list (GSList *categ_list)
4720 for (l = categ_list; l; l = l->next)
4723 g_slist_free (categ_list);
4727 * e_cal_component_free_datetime:
4728 * @dt: A date/time structure.
4730 * Frees a date/time structure.
4733 e_cal_component_free_datetime (ECalComponentDateTime *dt)
4735 g_return_if_fail (dt != NULL);
4738 g_free ((char*)dt->tzid);
4742 * e_cal_component_free_range:
4743 * @range: A #ECalComponentRange.
4745 * Frees an #ECalComponentRange structure.
4748 e_cal_component_free_range (ECalComponentRange *range)
4750 g_return_if_fail (range != NULL);
4752 e_cal_component_free_datetime (&range->datetime);
4756 * e_cal_component_free_exdate_list:
4757 * @exdate_list: List of #ECalComponentDateTime structures.
4759 * Frees a list of #ECalComponentDateTime structures as returned by the
4760 * e_cal_component_get_exdate_list() function.
4763 e_cal_component_free_exdate_list (GSList *exdate_list)
4767 for (l = exdate_list; l; l = l->next) {
4768 ECalComponentDateTime *cdt;
4770 g_assert (l->data != NULL);
4773 g_assert (cdt->value != NULL);
4774 g_free (cdt->value);
4775 g_free ((char*)cdt->tzid);
4780 g_slist_free (exdate_list);
4784 * e_cal_component_free_geo:
4785 * @geo: An #icalgeotype structure.
4787 * Frees a struct #icalgeotype structure as returned by the calendar component
4791 e_cal_component_free_geo (struct icalgeotype *geo)
4793 g_return_if_fail (geo != NULL);
4799 * e_cal_component_free_icaltimetype:
4800 * @t: An #icaltimetype structure.
4802 * Frees a struct #icaltimetype value as returned by the calendar component
4806 e_cal_component_free_icaltimetype (struct icaltimetype *t)
4808 g_return_if_fail (t != NULL);
4814 * e_cal_component_free_percent:
4815 * @percent: Percent value.
4817 * Frees a percent value as returned by the e_cal_component_get_percent()
4821 e_cal_component_free_percent (int *percent)
4823 g_return_if_fail (percent != NULL);
4829 * e_cal_component_free_priority:
4830 * @priority: Priority value.
4832 * Frees a priority value as returned by the e_cal_component_get_priority()
4836 e_cal_component_free_priority (int *priority)
4838 g_return_if_fail (priority != NULL);
4844 * e_cal_component_free_period_list:
4845 * @period_list: List of #ECalComponentPeriod structures.
4847 * Frees a list of #ECalComponentPeriod structures.
4850 e_cal_component_free_period_list (GSList *period_list)
4854 for (l = period_list; l; l = l->next) {
4855 ECalComponentPeriod *period;
4857 g_assert (l->data != NULL);
4863 g_slist_free (period_list);
4867 * e_cal_component_free_recur_list:
4868 * @recur_list: List of struct #icalrecurrencetype structures.
4870 * Frees a list of struct #icalrecurrencetype structures.
4873 e_cal_component_free_recur_list (GSList *recur_list)
4877 for (l = recur_list; l; l = l->next) {
4878 struct icalrecurrencetype *r;
4880 g_assert (l->data != NULL);
4886 g_slist_free (recur_list);
4890 * e_cal_component_free_sequence:
4891 * @sequence: Sequence number value.
4893 * Frees a sequence number value.
4896 e_cal_component_free_sequence (int *sequence)
4898 g_return_if_fail (sequence != NULL);
4904 * e_cal_component_free_id:
4910 e_cal_component_free_id (ECalComponentId *id)
4912 g_return_if_fail (id != NULL);
4928 * e_cal_component_free_text_list:
4929 * @text_list: List of #ECalComponentText structures.
4931 * Frees a list of #ECalComponentText structures. This function should only be
4932 * used to free lists of text values as returned by the other getter functions
4933 * of #ECalComponent.
4936 e_cal_component_free_text_list (GSList *text_list)
4940 for (l = text_list; l; l = l->next) {
4941 ECalComponentText *text;
4943 g_assert (l->data != NULL);
4946 g_return_if_fail (text != NULL);
4950 g_slist_free (text_list);
4954 * e_cal_component_free_attendee_list:
4955 * @attendee_list: List of attendees.
4957 * Frees a list of #ECalComponentAttendee structures.
4961 e_cal_component_free_attendee_list (GSList *attendee_list)
4965 for (l = attendee_list; l; l = l->next) {
4966 ECalComponentAttendee *attendee;
4968 g_assert (l->data != NULL);
4971 g_return_if_fail (attendee != NULL);
4975 g_slist_free (attendee_list);
4981 * e_cal_component_has_alarms:
4982 * @comp: A calendar component object.
4984 * Checks whether the component has any alarms.
4986 * Return value: TRUE if the component has any alarms.
4989 e_cal_component_has_alarms (ECalComponent *comp)
4991 ECalComponentPrivate *priv;
4993 g_return_val_if_fail (comp != NULL, FALSE);
4994 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
4997 g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
4999 return g_hash_table_size (priv->alarm_uid_hash) != 0;
5003 * e_cal_component_add_alarm:
5004 * @comp: A calendar component.
5007 * Adds an alarm subcomponent to a calendar component. You should have created
5008 * the @alarm by using e_cal_component_alarm_new(); it is invalid to use a
5009 * #ECalComponentAlarm structure that came from e_cal_component_get_alarm(). After
5010 * adding the alarm, the @alarm structure is no longer valid because the
5011 * internal structures may change and you should get rid of it by using
5012 * e_cal_component_alarm_free().
5015 e_cal_component_add_alarm (ECalComponent *comp, ECalComponentAlarm *alarm)
5017 ECalComponentPrivate *priv;
5019 g_return_if_fail (comp != NULL);
5020 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
5021 g_return_if_fail (alarm != NULL);
5025 add_alarm (comp, alarm->icalcomp, icalproperty_get_x (alarm->uid));
5026 icalcomponent_add_component (priv->icalcomp, alarm->icalcomp);
5030 * e_cal_component_remove_alarm:
5031 * @comp: A calendar component.
5032 * @auid: UID of the alarm to remove.
5034 * Removes an alarm subcomponent from a calendar component. If the alarm that
5035 * corresponds to the specified @auid had been fetched with
5036 * e_cal_component_get_alarm(), then those alarm structures will be invalid; you
5037 * should get rid of them with e_cal_component_alarm_free() before using this
5041 e_cal_component_remove_alarm (ECalComponent *comp, const char *auid)
5043 ECalComponentPrivate *priv;
5044 icalcomponent *alarm;
5046 g_return_if_fail (comp != NULL);
5047 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
5048 g_return_if_fail (auid != NULL);
5051 g_return_if_fail (priv->icalcomp != NULL);
5053 alarm = g_hash_table_lookup (priv->alarm_uid_hash, auid);
5057 g_hash_table_remove (priv->alarm_uid_hash, auid);
5058 icalcomponent_remove_component (priv->icalcomp, alarm);
5059 icalcomponent_free (alarm);
5063 for_each_remove_all_alarms (gpointer key, gpointer value, gpointer data)
5065 ECalComponent *comp = E_CAL_COMPONENT (data);
5066 ECalComponentPrivate *priv;
5067 icalcomponent *alarm = value;
5071 icalcomponent_remove_component (priv->icalcomp, alarm);
5072 icalcomponent_free (alarm);
5078 * e_cal_component_remove_all_alarms:
5079 * @comp: A calendar component
5081 * Remove all alarms from the calendar component
5084 e_cal_component_remove_all_alarms (ECalComponent *comp)
5086 ECalComponentPrivate *priv;
5088 g_return_if_fail (comp != NULL);
5089 g_return_if_fail (E_IS_CAL_COMPONENT (comp));
5092 g_return_if_fail (priv->icalcomp != NULL);
5094 g_hash_table_foreach_remove (priv->alarm_uid_hash, for_each_remove_all_alarms, comp);
5098 /* Scans an icalproperty from a calendar component and adds its mapping to our
5099 * own alarm structure.
5102 scan_alarm_property (ECalComponentAlarm *alarm, icalproperty *prop)
5104 icalproperty_kind kind;
5107 kind = icalproperty_isa (prop);
5110 case ICAL_ACTION_PROPERTY:
5111 alarm->action = prop;
5114 case ICAL_ATTACH_PROPERTY:
5115 /* FIXME: mail alarms may have any number of these, not just one */
5116 alarm->attach = prop;
5119 case ICAL_DESCRIPTION_PROPERTY:
5120 alarm->description.prop = prop;
5121 alarm->description.altrep_param = icalproperty_get_first_parameter (
5122 prop, ICAL_ALTREP_PARAMETER);
5125 case ICAL_DURATION_PROPERTY:
5126 alarm->duration = prop;
5129 case ICAL_REPEAT_PROPERTY:
5130 alarm->repeat = prop;
5133 case ICAL_TRIGGER_PROPERTY:
5134 alarm->trigger = prop;
5137 case ICAL_ATTENDEE_PROPERTY:
5138 scan_attendee (&alarm->attendee_list, prop);
5141 case ICAL_X_PROPERTY:
5142 xname = icalproperty_get_x_name (prop);
5143 g_assert (xname != NULL);
5145 if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0)
5155 /* Creates a ECalComponentAlarm from a libical alarm subcomponent */
5156 static ECalComponentAlarm *
5157 make_alarm (icalcomponent *subcomp)
5159 ECalComponentAlarm *alarm;
5162 alarm = g_new (ECalComponentAlarm, 1);
5164 alarm->icalcomp = subcomp;
5167 alarm->action = NULL;
5168 alarm->attach = NULL;
5169 alarm->description.prop = NULL;
5170 alarm->description.altrep_param = NULL;
5171 alarm->duration = NULL;
5172 alarm->repeat = NULL;
5173 alarm->trigger = NULL;
5174 alarm->attendee_list = NULL;
5176 for (prop = icalcomponent_get_first_property (subcomp, ICAL_ANY_PROPERTY);
5178 prop = icalcomponent_get_next_property (subcomp, ICAL_ANY_PROPERTY))
5179 scan_alarm_property (alarm, prop);
5181 g_assert (alarm->uid != NULL);
5187 * e_cal_component_get_alarm_uids:
5188 * @comp: A calendar component.
5190 * Builds a list of the unique identifiers of the alarm subcomponents inside a
5191 * calendar component.
5193 * Return value: List of unique identifiers for alarms. This should be freed
5194 * using cal_obj_uid_list_free().
5197 e_cal_component_get_alarm_uids (ECalComponent *comp)
5199 ECalComponentPrivate *priv;
5203 g_return_val_if_fail (comp != NULL, NULL);
5204 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
5207 g_return_val_if_fail (priv->icalcomp != NULL, NULL);
5210 for (iter = icalcomponent_begin_component (priv->icalcomp, ICAL_VALARM_COMPONENT);
5211 icalcompiter_deref (&iter) != NULL;
5212 icalcompiter_next (&iter)) {
5213 icalcomponent *subcomp;
5216 subcomp = icalcompiter_deref (&iter);
5217 for (prop = icalcomponent_get_first_property (subcomp, ICAL_X_PROPERTY);
5219 prop = icalcomponent_get_next_property (subcomp, ICAL_X_PROPERTY)) {
5222 xname = icalproperty_get_x_name (prop);
5223 g_assert (xname != NULL);
5225 if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0) {
5228 auid = alarm_uid_from_prop (prop);
5229 l = g_list_append (l, g_strdup (auid));
5238 * e_cal_component_get_alarm:
5239 * @comp: A calendar component.
5240 * @auid: Unique identifier for the sought alarm subcomponent.
5242 * Queries a particular alarm subcomponent of a calendar component.
5244 * Return value: The alarm subcomponent that corresponds to the specified @auid,
5245 * or #NULL if no alarm exists with that UID. This should be freed using
5246 * e_cal_component_alarm_free().
5248 ECalComponentAlarm *
5249 e_cal_component_get_alarm (ECalComponent *comp, const char *auid)
5251 ECalComponentPrivate *priv;
5252 icalcomponent *alarm;
5254 g_return_val_if_fail (comp != NULL, NULL);
5255 g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
5258 g_return_val_if_fail (priv->icalcomp != NULL, NULL);
5260 g_return_val_if_fail (auid != NULL, NULL);
5262 alarm = g_hash_table_lookup (priv->alarm_uid_hash, auid);
5265 return make_alarm (alarm);
5271 * e_cal_component_alarms_free:
5272 * @alarms: Component alarms structure.
5274 * Frees a #ECalComponentAlarms structure.
5277 e_cal_component_alarms_free (ECalComponentAlarms *alarms)
5281 g_return_if_fail (alarms != NULL);
5283 g_assert (alarms->comp != NULL);
5284 g_object_unref (G_OBJECT (alarms->comp));
5286 for (l = alarms->alarms; l; l = l->next) {
5287 ECalComponentAlarmInstance *instance;
5290 g_assert (instance != NULL);
5294 g_slist_free (alarms->alarms);
5299 * e_cal_component_alarm_new:
5301 * Create a new alarm object.
5303 * Return value: a new alarm component
5305 ECalComponentAlarm *
5306 e_cal_component_alarm_new (void)
5308 ECalComponentAlarm *alarm;
5311 alarm = g_new (ECalComponentAlarm, 1);
5313 alarm->icalcomp = icalcomponent_new (ICAL_VALARM_COMPONENT);
5315 new_auid = e_cal_component_gen_uid ();
5316 alarm->uid = icalproperty_new_x (new_auid);
5317 icalproperty_set_x_name (alarm->uid, EVOLUTION_ALARM_UID_PROPERTY);
5318 icalcomponent_add_property (alarm->icalcomp, alarm->uid);
5321 alarm->action = NULL;
5322 alarm->attach = NULL;
5323 alarm->description.prop = NULL;
5324 alarm->description.altrep_param = NULL;
5325 alarm->duration = NULL;
5326 alarm->repeat = NULL;
5327 alarm->trigger = NULL;
5328 alarm->attendee_list = NULL;
5334 * e_cal_component_alarm_clone:
5335 * @alarm: An alarm subcomponent.
5337 * Creates a new alarm subcomponent by copying the information from another one.
5339 * Return value: A newly-created alarm subcomponent with the same values as the
5340 * original one. Should be freed with e_cal_component_alarm_free().
5342 ECalComponentAlarm *
5343 e_cal_component_alarm_clone (ECalComponentAlarm *alarm)
5345 icalcomponent *icalcomp;
5347 g_return_val_if_fail (alarm != NULL, NULL);
5349 icalcomp = icalcomponent_new_clone (alarm->icalcomp);
5350 return make_alarm (icalcomp);
5354 * e_cal_component_alarm_free:
5355 * @alarm: A calendar alarm.
5357 * Frees an alarm structure.
5360 e_cal_component_alarm_free (ECalComponentAlarm *alarm)
5364 g_return_if_fail (alarm != NULL);
5366 g_assert (alarm->icalcomp != NULL);
5368 if (icalcomponent_get_parent (alarm->icalcomp) == NULL)
5369 icalcomponent_free (alarm->icalcomp);
5371 alarm->icalcomp = NULL;
5373 alarm->action = NULL;
5374 alarm->attach = NULL;
5375 alarm->description.prop = NULL;
5376 alarm->description.altrep_param = NULL;
5377 alarm->duration = NULL;
5378 alarm->repeat = NULL;
5379 alarm->trigger = NULL;
5381 for (l = alarm->attendee_list; l != NULL; l = l->next)
5383 g_slist_free (alarm->attendee_list);
5384 alarm->attendee_list = NULL;
5390 * e_cal_component_alarm_get_uid:
5391 * @alarm: An alarm subcomponent.
5393 * Queries the unique identifier of an alarm subcomponent.
5395 * Return value: UID of the alarm.
5398 e_cal_component_alarm_get_uid (ECalComponentAlarm *alarm)
5400 g_return_val_if_fail (alarm != NULL, NULL);
5402 return alarm_uid_from_prop (alarm->uid);
5406 * e_cal_component_alarm_get_action:
5408 * @action: Return value for the alarm's action type.
5410 * Queries the action type of an alarm.
5413 e_cal_component_alarm_get_action (ECalComponentAlarm *alarm, ECalComponentAlarmAction *action)
5415 enum icalproperty_action ipa;
5417 g_return_if_fail (alarm != NULL);
5418 g_return_if_fail (action != NULL);
5420 g_assert (alarm->icalcomp != NULL);
5422 if (!alarm->action) {
5423 *action = E_CAL_COMPONENT_ALARM_NONE;
5427 ipa = icalproperty_get_action (alarm->action);
5430 case ICAL_ACTION_AUDIO:
5431 *action = E_CAL_COMPONENT_ALARM_AUDIO;
5434 case ICAL_ACTION_DISPLAY:
5435 *action = E_CAL_COMPONENT_ALARM_DISPLAY;
5438 case ICAL_ACTION_EMAIL:
5439 *action = E_CAL_COMPONENT_ALARM_EMAIL;
5442 case ICAL_ACTION_PROCEDURE:
5443 *action = E_CAL_COMPONENT_ALARM_PROCEDURE;
5446 case ICAL_ACTION_NONE:
5447 *action = E_CAL_COMPONENT_ALARM_NONE;
5451 *action = E_CAL_COMPONENT_ALARM_UNKNOWN;
5456 * e_cal_component_alarm_set_action:
5458 * @action: Action type.
5460 * Sets the action type for an alarm.
5463 e_cal_component_alarm_set_action (ECalComponentAlarm *alarm, ECalComponentAlarmAction action)
5465 enum icalproperty_action ipa;
5467 g_return_if_fail (alarm != NULL);
5468 g_return_if_fail (action != E_CAL_COMPONENT_ALARM_NONE);
5469 g_return_if_fail (action != E_CAL_COMPONENT_ALARM_UNKNOWN);
5471 g_assert (alarm->icalcomp != NULL);
5474 case E_CAL_COMPONENT_ALARM_AUDIO:
5475 ipa = ICAL_ACTION_AUDIO;
5478 case E_CAL_COMPONENT_ALARM_DISPLAY:
5479 ipa = ICAL_ACTION_DISPLAY;
5482 case E_CAL_COMPONENT_ALARM_EMAIL:
5483 ipa = ICAL_ACTION_EMAIL;
5486 case E_CAL_COMPONENT_ALARM_PROCEDURE:
5487 ipa = ICAL_ACTION_PROCEDURE;
5491 g_assert_not_reached ();
5492 ipa = ICAL_ACTION_NONE;
5496 icalproperty_set_action (alarm->action, ipa);
5498 alarm->action = icalproperty_new_action (ipa);
5499 icalcomponent_add_property (alarm->icalcomp, alarm->action);
5504 * e_cal_component_alarm_get_attach:
5506 * @attach: Return value for the attachment; should be freed using icalattach_unref().
5508 * Queries the attachment property of an alarm.
5511 e_cal_component_alarm_get_attach (ECalComponentAlarm *alarm, icalattach **attach)
5513 g_return_if_fail (alarm != NULL);
5514 g_return_if_fail (attach != NULL);
5516 g_assert (alarm->icalcomp != NULL);
5518 if (alarm->attach) {
5519 *attach = icalproperty_get_attach (alarm->attach);
5520 icalattach_ref (*attach);
5526 * e_cal_component_alarm_set_attach:
5528 * @attach: Attachment property or NULL to remove an existing property.
5530 * Sets the attachment property of an alarm.
5533 e_cal_component_alarm_set_attach (ECalComponentAlarm *alarm, icalattach *attach)
5535 g_return_if_fail (alarm != NULL);
5537 g_assert (alarm->icalcomp != NULL);
5539 if (alarm->attach) {
5540 icalcomponent_remove_property (alarm->icalcomp, alarm->attach);
5541 icalproperty_free (alarm->attach);
5542 alarm->attach = NULL;
5546 alarm->attach = icalproperty_new_attach (attach);
5547 icalcomponent_add_property (alarm->icalcomp, alarm->attach);
5552 * e_cal_component_alarm_get_description:
5554 * @description: Return value for the description property and its parameters.
5556 * Queries the description property of an alarm.
5559 e_cal_component_alarm_get_description (ECalComponentAlarm *alarm, ECalComponentText *description)
5561 g_return_if_fail (alarm != NULL);
5562 g_return_if_fail (description != NULL);
5564 g_assert (alarm->icalcomp != NULL);
5566 if (alarm->description.prop)
5567 description->value = icalproperty_get_description (alarm->description.prop);
5569 description->value = NULL;
5571 if (alarm->description.altrep_param)
5572 description->altrep = icalparameter_get_altrep (alarm->description.altrep_param);
5574 description->altrep = NULL;
5578 * e_cal_component_alarm_set_description:
5580 * @description: Description property and its parameters, or NULL for no description.
5582 * Sets the description property of an alarm.
5585 e_cal_component_alarm_set_description (ECalComponentAlarm *alarm, ECalComponentText *description)
5587 g_return_if_fail (alarm != NULL);
5589 g_assert (alarm->icalcomp != NULL);
5591 if (alarm->description.prop) {
5592 icalcomponent_remove_property (alarm->icalcomp, alarm->description.prop);
5593 icalproperty_free (alarm->description.prop);
5595 alarm->description.prop = NULL;
5596 alarm->description.altrep_param = NULL;
5602 g_return_if_fail (description->value != NULL);
5604 alarm->description.prop = icalproperty_new_description (description->value);
5605 icalcomponent_add_property (alarm->icalcomp, alarm->description.prop);
5607 if (description->altrep) {
5608 alarm->description.altrep_param = icalparameter_new_altrep (
5609 (char *) description->altrep);
5610 icalproperty_add_parameter (alarm->description.prop,
5611 alarm->description.altrep_param);
5616 * e_cal_component_alarm_get_repeat:
5618 * @repeat: Return value for the repeat/duration properties.
5620 * Queries the repeat/duration properties of an alarm.
5623 e_cal_component_alarm_get_repeat (ECalComponentAlarm *alarm, ECalComponentAlarmRepeat *repeat)
5625 g_return_if_fail (alarm != NULL);
5626 g_return_if_fail (repeat != NULL);
5628 g_assert (alarm->icalcomp != NULL);
5630 if (!(alarm->repeat && alarm->duration)) {
5631 repeat->repetitions = 0;
5632 memset (&repeat->duration, 0, sizeof (repeat->duration));
5636 repeat->repetitions = icalproperty_get_repeat (alarm->repeat);
5637 repeat->duration = icalproperty_get_duration (alarm->duration);
5641 * e_cal_component_alarm_set_repeat:
5643 * @repeat: Repeat/duration values. To remove any repetitions from the alarm,
5644 * set the @repeat.repetitions to 0.
5646 * Sets the repeat/duration values for an alarm.
5649 e_cal_component_alarm_set_repeat (ECalComponentAlarm *alarm, ECalComponentAlarmRepeat repeat)
5651 g_return_if_fail (alarm != NULL);
5652 g_return_if_fail (repeat.repetitions >= 0);
5654 g_assert (alarm->icalcomp != NULL);
5656 /* Delete old properties */
5658 if (alarm->repeat) {
5659 icalcomponent_remove_property (alarm->icalcomp, alarm->repeat);
5660 icalproperty_free (alarm->repeat);
5661 alarm->repeat = NULL;
5664 if (alarm->duration) {
5665 icalcomponent_remove_property (alarm->icalcomp, alarm->duration);
5666 icalproperty_free (alarm->duration);
5667 alarm->duration = NULL;
5670 /* Set the new properties */
5672 if (repeat.repetitions == 0)
5673 return; /* For zero extra repetitions the properties should not exist */
5675 alarm->repeat = icalproperty_new_repeat (repeat.repetitions);
5676 icalcomponent_add_property (alarm->icalcomp, alarm->repeat);
5678 alarm->duration = icalproperty_new_duration (repeat.duration);
5679 icalcomponent_add_property (alarm->icalcomp, alarm->duration);
5683 * e_cal_component_alarm_get_trigger:
5685 * @trigger: Return value for the trigger time.
5687 * Queries the trigger time for an alarm.
5690 e_cal_component_alarm_get_trigger (ECalComponentAlarm *alarm, ECalComponentAlarmTrigger *trigger)
5692 icalparameter *param;
5693 struct icaltriggertype t;
5696 g_return_if_fail (alarm != NULL);
5697 g_return_if_fail (trigger != NULL);
5699 g_assert (alarm->icalcomp != NULL);
5701 if (!alarm->trigger) {
5702 trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_NONE;
5706 /* Get trigger type */
5708 param = icalproperty_get_first_parameter (alarm->trigger, ICAL_VALUE_PARAMETER);
5710 icalparameter_value value;
5712 value = icalparameter_get_value (param);
5715 case ICAL_VALUE_DURATION:
5719 case ICAL_VALUE_DATETIME:
5724 g_message ("e_cal_component_alarm_get_trigger(): Unknown value for trigger "
5725 "value %d; using RELATIVE", value);
5733 /* Get trigger value and the RELATED parameter */
5735 t = icalproperty_get_trigger (alarm->trigger);
5738 trigger->u.rel_duration = t.duration;
5740 param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER);
5742 icalparameter_related rel;
5744 rel = icalparameter_get_related (param);
5747 case ICAL_RELATED_START:
5748 trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START;
5751 case ICAL_RELATED_END:
5752 trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END;
5756 g_assert_not_reached ();
5759 trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START;
5761 trigger->u.abs_time = t.time;
5762 trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE;
5767 * e_cal_component_alarm_set_trigger:
5769 * @trigger: Trigger time structure.
5771 * Sets the trigger time of an alarm.
5774 e_cal_component_alarm_set_trigger (ECalComponentAlarm *alarm, ECalComponentAlarmTrigger trigger)
5776 struct icaltriggertype t;
5777 icalparameter *param;
5778 icalparameter_value value_type;
5779 icalparameter_related related;
5781 g_return_if_fail (alarm != NULL);
5782 g_return_if_fail (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_NONE);
5784 g_assert (alarm->icalcomp != NULL);
5786 /* Delete old trigger */
5788 if (alarm->trigger) {
5789 icalcomponent_remove_property (alarm->icalcomp, alarm->trigger);
5790 icalproperty_free (alarm->trigger);
5791 alarm->trigger = NULL;
5796 related = ICAL_RELATED_START; /* Keep GCC happy */
5798 t.time = icaltime_null_time ();
5799 t.duration = icaldurationtype_null_duration ();
5800 switch (trigger.type) {
5801 case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START:
5802 t.duration = trigger.u.rel_duration;
5803 value_type = ICAL_VALUE_DURATION;
5804 related = ICAL_RELATED_START;
5807 case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END:
5808 t.duration = trigger.u.rel_duration;
5809 value_type = ICAL_VALUE_DURATION;
5810 related = ICAL_RELATED_END;
5813 case E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE:
5814 t.time = trigger.u.abs_time;
5815 value_type = ICAL_VALUE_DATETIME;
5819 g_assert_not_reached ();
5823 alarm->trigger = icalproperty_new_trigger (t);
5824 icalcomponent_add_property (alarm->icalcomp, alarm->trigger);
5826 /* Value parameters */
5828 param = icalproperty_get_first_parameter (alarm->trigger, ICAL_VALUE_PARAMETER);
5830 icalparameter_set_value (param, value_type);
5832 param = icalparameter_new_value (value_type);
5833 icalproperty_add_parameter (alarm->trigger, param);
5836 /* Related parameter */
5838 if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE) {
5839 param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER);
5842 icalparameter_set_related (param, related);
5844 param = icalparameter_new_related (related);
5845 icalproperty_add_parameter (alarm->trigger, param);
5851 * e_cal_component_alarm_get_attendee_list:
5853 * @attendee_list: Return value for the list of attendees.
5855 * Gets the list of attendees associated with an alarm.
5858 e_cal_component_alarm_get_attendee_list (ECalComponentAlarm *alarm, GSList **attendee_list)
5860 g_return_if_fail (alarm != NULL);
5862 get_attendee_list (alarm->attendee_list, attendee_list);
5866 * e_cal_component_alarm_set_attendee_list:
5868 * @attendee_list: List of attendees.
5870 * Sets the list of attendees for an alarm.
5873 e_cal_component_alarm_set_attendee_list (ECalComponentAlarm *alarm, GSList *attendee_list)
5875 g_return_if_fail (alarm != NULL);
5877 set_attendee_list (alarm->icalcomp, &alarm->attendee_list, attendee_list);
5881 * e_cal_component_alarm_has_attendees:
5884 * Queries an alarm to see if it has attendees associated with it.
5886 * Return value: TRUE if there are attendees in the alarm, FALSE if not.
5889 e_cal_component_alarm_has_attendees (ECalComponentAlarm *alarm)
5892 g_return_val_if_fail (alarm != NULL, FALSE);
5894 if (g_slist_length (alarm->attendee_list) > 0)
5902 * e_cal_component_alarm_get_icalcomponent
5905 * Get the icalcomponent associated with the given #ECalComponentAlarm.
5907 * Returns: the icalcomponent.
5910 e_cal_component_alarm_get_icalcomponent (ECalComponentAlarm *alarm)
5912 g_return_val_if_fail (alarm != NULL, NULL);
5913 return alarm->icalcomp;
5916 /* Returns TRUE if both strings match, i.e. they are both NULL or the
5917 strings are equal. */
5919 e_cal_component_strings_match (const gchar *string1,
5920 const gchar *string2)
5922 if (string1 == NULL || string2 == NULL)
5923 return (string1 == string2) ? TRUE : FALSE;
5925 if (!strcmp (string1, string2))
5933 * e_cal_component_event_dates_match:
5934 * @comp1: A calendar component object.
5935 * @comp2: A calendar component object.
5937 * Checks if the DTSTART and DTEND properties of the 2 components match.
5938 * Note that the events may have different recurrence properties which are not
5939 * taken into account here.
5941 * Returns: TRUE if the DTSTART and DTEND properties of the 2 components match.
5944 e_cal_component_event_dates_match (ECalComponent *comp1,
5945 ECalComponent *comp2)
5947 ECalComponentDateTime comp1_dtstart, comp1_dtend;
5948 ECalComponentDateTime comp2_dtstart, comp2_dtend;
5949 gboolean retval = TRUE;
5951 e_cal_component_get_dtstart (comp1, &comp1_dtstart);
5952 e_cal_component_get_dtend (comp1, &comp1_dtend);
5953 e_cal_component_get_dtstart (comp2, &comp2_dtstart);
5954 e_cal_component_get_dtend (comp2, &comp2_dtend);
5956 /* If either value is NULL they must both be NULL to match. */
5957 if (comp1_dtstart.value == NULL || comp2_dtstart.value == NULL) {
5958 if (comp1_dtstart.value != comp2_dtstart.value) {
5963 if (icaltime_compare (*comp1_dtstart.value,
5964 *comp2_dtstart.value)) {
5970 if (comp1_dtend.value == NULL || comp2_dtend.value == NULL) {
5971 if (comp1_dtend.value != comp2_dtend.value) {
5976 if (icaltime_compare (*comp1_dtend.value,
5977 *comp2_dtend.value)) {
5983 /* Now check the timezones. */
5984 if (!e_cal_component_strings_match (comp1_dtstart.tzid,
5985 comp2_dtstart.tzid)) {
5990 if (!e_cal_component_strings_match (comp1_dtend.tzid,
5991 comp2_dtend.tzid)) {
5997 e_cal_component_free_datetime (&comp1_dtstart);
5998 e_cal_component_free_datetime (&comp1_dtend);
5999 e_cal_component_free_datetime (&comp2_dtstart);
6000 e_cal_component_free_datetime (&comp2_dtend);