}
- (id)initWithICalString:(NSString *)_iCal {
+ if ([_iCal length] == 0) {
+ [self logWithFormat:@"ERROR: tried to init SOGoAppointment without iCal"];
+ [self release];
+ return nil;
+ }
if ((self = [self init])) {
id root;
/* parse */
- [parser parseFromSource:_iCal];
- root = [[sax rootObject] retain];
- [sax reset];
+ if ([_iCal length] > 0) {
+ [parser parseFromSource:_iCal];
+ root = [[sax rootObject] retain];
+ [sax reset];
+ }
+ else
+ root = nil;
/* fill */
if ([root isKindOfClass:[iCalEvent class]]) {
self->event = root;
}
+ else if ([root isKindOfClass:[NSDictionary class]]) {
+ /* multiple vevents in the calendar */
+ [self logWithFormat:
+ @"ERROR(%s): tried to initialize with multiple records: %@",
+ __PRETTY_FUNCTION__, root];
+ [self release];
+ return nil;
+ }
else {
self->calendar = root;
self->event = [[[self->calendar events] lastObject] retain];
/* TODO: REMOVE THIS HACK ASAP */
- (NSString *)iCalString {
- NSMutableString *s;
- NSArray *persons;
- unsigned i, count;
- iCalPerson *p;
-
- /* assume length of 1K - reasonable ? */
- s = [[NSMutableString alloc] initWithCapacity:1024];
- [s appendString:@"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:"];
- if (self->calendar == nil)
- [s appendString:@"SOGo/0.9"];
- else
- [s appendString:[self->calendar prodId]];
- [s appendString:@"\nVERSION:"];
- if (self->calendar == nil)
- [s appendString:@"2.0"];
- else
- [s appendString:[(iCalCalendar *)self->calendar version]];
- [s appendString:@"\nBEGIN:VEVENT"];
- [s appendString:@"\nSUMMARY:"];
- [s appendString:[self summary]];
- if([self hasLocation]) {
+ NSMutableString *s;
+ NSArray *persons;
+ unsigned i, count;
+ iCalPerson *p;
+
+ /* assume length of 1K - reasonable ? */
+ s = [NSMutableString stringWithCapacity:1024];
+
+ [s appendString:@"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:"];
+ if (self->calendar == nil)
+ [s appendString:@"SOGo/0.9"];
+ else
+ [s appendString:[self->calendar prodId]];
+ [s appendString:@"\nVERSION:"];
+ if (self->calendar == nil)
+ [s appendString:@"2.0"];
+ else
+ [s appendString:[(iCalCalendar *)self->calendar version]];
+ [s appendString:@"\nBEGIN:VEVENT"];
+ [s appendString:@"\nSUMMARY:"];
+ [s appendString:[self summary]];
+ if([self hasLocation]) {
[s appendString:@"\nLOCATION:"];
[s appendString:[self location]];
- }
- [s appendString:@"\nUID:"];
- [s appendString:[self uid]];
- [s appendString:@"\nDTSTART:"];
- [s appendString:[[self startDate] icalString]];
- if([self hasEndDate]) {
+ }
+ [s appendString:@"\nUID:"];
+ [s appendString:[self uid]];
+ [s appendString:@"\nDTSTART:"];
+ [s appendString:[[self startDate] icalString]];
+ if([self hasEndDate]) {
[s appendString:@"\nDTEND:"];
[s appendString:[[self endDate] icalString]];
- }
- if([self hasDuration]) {
+ }
+ if([self hasDuration]) {
[s appendString:@"\nDURATION:"];
[s appendString:[(iCalEvent *)self->event duration]];
- }
- [s appendString:@"\nSTATUS:"];
- [s appendString:[self status]];
+ }
+ [s appendString:@"\nSTATUS:"];
+ [s appendString:[self status]];
- /* what's all this? */
- [s appendString:@"\nTRANSP:OPAQUE"];
- [s appendString:@"\nCLASS:PRIVATE"];
+ /* what's all this? */
+ [s appendString:@"\nTRANSP:OPAQUE"]; /* transparency */
+ [s appendString:@"\nCLASS:PRIVATE"]; /* classification [like 'top secret'] */
- /* organizer */
- p = [self organizer];
- if(p) {
+ /* organizer */
+ p = [self organizer];
+ if(p) {
NSString *x;
[s appendString:@"\nORGANIZER;CN=\""];
[s appendString:@":"]; /* sic! */
[s appendString:x];
}
- }
+ }
- /* attendees */
- persons = [self attendees];
- count = [persons count];
- for(i = 0; i < count; i++) {
+ /* attendees */
+ persons = [self attendees];
+ count = [persons count];
+ for (i = 0; i < count; i++) {
NSString *x;
p = [persons objectAtIndex:i];
[s appendString:@":"]; /* sic! */
[s appendString:x];
}
- }
-
- /* postamble */
- [s appendString:@"\nEND:VEVENT\nEND:VCALENDAR"];
- return [s autorelease];
+ }
+
+ /* postamble */
+ [s appendString:@"\nEND:VEVENT\nEND:VCALENDAR"];
+ return s;
}
- (void)setUid:(NSString *)_value {
- [self->event setUid:_value];
+ [self->event setUid:_value];
}
- (NSString *)uid {
- return [self->event uid];
+ return [self->event uid];
}
- (void)setSummary:(NSString *)_value {
- [self->event setSummary:_value];
+ [self->event setSummary:_value];
}
- (NSString *)summary {
- return [self->event summary];
+ return [self->event summary];
}
- (void)setLocation:(NSString *)_value {