From 2ac8cdf48d06894316612acbad96f6421c7fccd7 Mon Sep 17 00:00:00 2001 From: "shaver%mozilla.org" Date: Tue, 23 Nov 2004 23:24:36 +0000 Subject: [PATCH] attendee support --- calendar/base/public/calIICSService.idl | 5 ++ calendar/base/src/calICSService.cpp | 71 ++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/calendar/base/public/calIICSService.idl b/calendar/base/public/calIICSService.idl index 00c7dd81ba7..94d7a8878da 100644 --- a/calendar/base/public/calIICSService.idl +++ b/calendar/base/public/calIICSService.idl @@ -109,6 +109,11 @@ interface calIIcalComponent : nsISupports attribute calIDateTime createdTime; attribute calIDateTime completedTime; attribute calIDateTime lastModified; + + void getAttendees(out PRUint32 count, + [array,size_is(count),retval] out string attendees); + void setAttendees(in PRUint32 count, + [array,size_is(count)] in string attendees); }; [scriptable,uuid(c788a1dc-0929-4029-9a14-e1bc654eafad)] diff --git a/calendar/base/src/calICSService.cpp b/calendar/base/src/calICSService.cpp index 0f9162b77c1..de47110bc34 100644 --- a/calendar/base/src/calICSService.cpp +++ b/calendar/base/src/calICSService.cpp @@ -41,6 +41,7 @@ #include "nsString.h" #include "nsCOMPtr.h" #include "nsComponentManagerUtils.h" +#include "nsCRT.h" #include "calIEvent.h" #include "calBaseCID.h" @@ -106,7 +107,7 @@ protected: return SetProperty(kind, val); } - + void ClearAllProperties(icalproperty_kind kind); icalcomponent *mComponent; nsCOMPtr mParent; @@ -115,13 +116,8 @@ protected: nsresult calIcalComponent::SetProperty(icalproperty_kind kind, icalvalue *val) { - icalproperty *prop = - icalcomponent_get_first_property(mComponent, kind); - if (prop) { - icalcomponent_remove_property(mComponent, prop); - icalproperty_free(prop); - } - prop = icalproperty_new(kind); + ClearAllProperties(kind); + icalproperty *prop = icalproperty_new(kind); if (!prop) { icalvalue_free(val); return NS_ERROR_OUT_OF_MEMORY; @@ -255,6 +251,65 @@ DATE_ATTRIBUTE(LastModified, LASTMODIFIED) DATE_ATTRIBUTE(CreatedTime, CREATED) DATE_ATTRIBUTE(CompletedTime, COMPLETED) +NS_IMETHODIMP +calIcalComponent::GetAttendees(PRUint32 *count, char ***attendees) +{ + char **attlist = nsnull; + PRUint32 attcount = 0; + for (icalproperty *prop = + icalcomponent_get_first_property(mComponent, ICAL_ATTENDEE_PROPERTY); + prop; + prop = icalcomponent_get_next_property(mComponent, ICAL_ATTENDEE_PROPERTY)) { + attcount++; + char **newlist = + NS_STATIC_CAST(char **, + NS_Realloc(attlist, attcount * sizeof(char *))); + if (!newlist) + goto oom; + attlist = newlist; + attlist[attcount - 1] = nsCRT::strdup(icalproperty_get_attendee(prop)); + if (!attlist[attcount - 1]) + goto oom; + } + + *attendees = attlist; + *count = attcount; + return NS_OK; + + oom: + for (PRUint32 i = 0; i < attcount - 1; i++) + NS_Free(attlist[i]); + NS_Free(attlist); + return NS_ERROR_OUT_OF_MEMORY; +} + +void +calIcalComponent::ClearAllProperties(icalproperty_kind kind) +{ + for (icalproperty *prop = + icalcomponent_get_first_property(mComponent, kind), + *next; + prop; + prop = next) { + next = icalcomponent_get_next_property(mComponent, kind); + icalcomponent_remove_property(mComponent, prop); + } +} + +NS_IMETHODIMP +calIcalComponent::SetAttendees(PRUint32 count, const char **attendees) +{ + ClearAllProperties(ICAL_ATTENDEE_PROPERTY); + for (PRUint32 i = 0; i < count; i++) { + icalproperty *prop = icalproperty_new_attendee(attendees[i]); + if (!prop) + return NS_ERROR_OUT_OF_MEMORY; + icalcomponent_add_property(mComponent, prop); + } + + return NS_OK; +} + NS_IMPL_ISUPPORTS1(calICSService, calIICSService) NS_IMETHODIMP