/*
- Copyright (C) 2004 SKYRIX Software AG
+ Copyright (C) 2004-2005 SKYRIX Software AG
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "iCalRenderer.h"
#include "iCalEvent.h"
#include "iCalPerson.h"
+#include "iCalRecurrenceRule.h"
+#include "NSCalendarDate+ICal.h"
#include "common.h"
-@interface NSDate(UsedPrivates)
-- (NSString *)icalString; // declared in NGiCal
-@end
-
@implementation iCalRenderer
static iCalRenderer *renderer = nil;
toString:(NSMutableString *)s
{
[s appendString:@"BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\n"];
- [s appendString:@"PRODID:NGiCal/4.3\r\n"];
+ [s appendFormat:@"PRODID:NGiCal/%i.%i\r\n",
+ SOPE_MAJOR_VERSION, SOPE_MINOR_VERSION];
[s appendString:@"VERSION:2.0\r\n"];
}
- (void)addPostambleForAppointment:(iCalEvent *)_apt
[s appendString:@";"];
}
+ if ((x = [p partStat])) {
+ if ([p participationStatus] != iCalPersonPartStatNeedsAction) {
+ [s appendString:@"PARTSTAT="];
+ [s appendString:[x iCalSafeString]];
+ [s appendString:@";"];
+ }
+ }
+
[s appendString:@"CN=\""];
- if ((x = [p cn])) {
+ if ((x = [p cnWithoutQuotes])) {
[s appendString:[x iCalDQUOTESafeString]];
}
[s appendString:@"\""];
- (void)addVEventForAppointment:(iCalEvent *)event
toString:(NSMutableString *)s
{
+ id tmp;
+
[s appendString:@"BEGIN:VEVENT\r\n"];
[s appendString:@"SUMMARY:"];
[s appendString:[[event location] iCalSafeString]];
[s appendString:@"\r\n"];
}
- [s appendString:@"UID:"];
- [s appendString:[event uid]];
- [s appendString:@"\r\n"];
+
+ if ((tmp = [event uid]) != nil) {
+ [s appendString:@"UID:"];
+ [s appendString:tmp];
+ [s appendString:@"\r\n"];
+ }
[s appendString:@"DTSTART:"];
[s appendString:[[event startDate] icalString]];
[s appendString:@"\r\n"];
}
- [s appendString:@"STATUS:"];
- [s appendString:[event status]];
+ if ((tmp = [event status]) != nil) {
+ [s appendString:@"STATUS:"];
+ [s appendString:tmp];
+ [s appendString:@"\r\n"];
+ }
+
+ if ((tmp = [event transparency]) != nil) {
+ [s appendString:@"TRANSP:"];
+ [s appendString:tmp];
+ [s appendString:@"\r\n"];
+ }
+
+ [s appendString:@"CLASS:"];
+ [s appendString:[event accessClass]];
[s appendString:@"\r\n"];
-
- /* what's all this? */
- [s appendString:@"TRANSP:OPAQUE\r\n"]; /* transparency */
- [s appendString:@"CLASS:PRIVATE\r\n"]; /* classification [like 'top secret'] */
-
+ /* recurrence rules */
+ if ([event hasRecurrenceRules]) {
+ NSArray *rules;
+ unsigned i, count;
+
+ rules = [event recurrenceRules];
+ count = [rules count];
+ for (i = 0; i < count; i++) {
+ iCalRecurrenceRule *rule;
+
+ rule = [rules objectAtIndex:i];
+ [s appendString:@"RRULE:"];
+ [s appendString:[rule iCalRepresentation]];
+ [s appendString:@"\r\n"];
+ }
+ }
+
+ /* exception rules */
+ if ([event hasExceptionRules]) {
+ NSArray *rules;
+ unsigned i, count;
+
+ rules = [event exceptionRules];
+ count = [rules count];
+ for (i = 0; i < count; i++) {
+ iCalRecurrenceRule *rule;
+
+ rule = [rules objectAtIndex:i];
+ [s appendString:@"EXRULE:"];
+ [s appendString:[rule iCalRepresentation]];
+ [s appendString:@"\r\n"];
+ }
+ }
+
+ /* exception dates */
+ if ([event hasExceptionDates]) {
+ NSArray *dates;
+ unsigned i, count;
+
+ dates = [event exceptionDates];
+ count = [dates count];
+ [s appendString:@"EXDATE:"];
+ for (i = 0; i < count; i++) {
+ if (i > 0)
+ [s appendString:@","];
+ [s appendString:[[dates objectAtIndex:i] icalString]];
+ }
+ [s appendString:@"\r\n"];
+ }
+
[self addOrganizer:[event organizer] toString:s];
[self addAttendees:[event attendees] toString:s];
return NO;
if ([[_apt uid] length] == 0) {
- [self logWithFormat:
- @"WARNING: got apt without uid, rejecting iCal generation: %@",
- _apt];
+ [self warnWithFormat:@"got apt without uid, rejecting iCal generation: %@",
+ _apt];
return NO;
}
if ([[[_apt startDate] icalString] length] == 0) {
- [self logWithFormat:
- @"WARNING: got apt without start date, "
- @"rejecting iCal generation: %@",
- _apt];
+ [self warnWithFormat:@"got apt without start date, "
+ @"rejecting iCal generation: %@",
+ _apt];
return NO;
}