2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
24 #import <Foundation/NSURL.h>
25 #import <Foundation/NSValue.h>
27 #import "NSCalendarDate+NGCards.h"
30 #import "iCalDateTime.h"
31 #import "iCalEntityObject.h"
32 #import "iCalPerson.h"
34 @interface iCalEntityObject (PrivateAPI)
35 - (NSArray *)_filteredAttendeesThinkingOfPersons:(BOOL)_persons;
38 @implementation iCalEntityObject
40 - (Class) classForTag: (NSString *) classTag
44 if ([classTag isEqualToString: @"ATTENDEE"]
45 || [classTag isEqualToString: @"ORGANIZER"])
46 tagClass = [iCalPerson class];
47 else if ([classTag isEqualToString: @"VALARM"])
48 tagClass = [iCalAlarm class];
49 else if ([classTag isEqualToString: @"SUMMARY"]
50 || [classTag isEqualToString: @"UID"]
51 || [classTag isEqualToString: @"COMMENT"]
52 || [classTag isEqualToString: @"DESCRIPTION"]
53 || [classTag isEqualToString: @"CLASS"]
54 || [classTag isEqualToString: @"STATUS"]
55 || [classTag isEqualToString: @"SEQUENCE"]
56 || [classTag isEqualToString: @"URL"]
57 || [classTag isEqualToString: @"PRIORITY"]
58 || [classTag isEqualToString: @"CATEGORIES"]
59 || [classTag isEqualToString: @"LOCATION"])
60 tagClass = [CardElement class];
61 else if ([classTag isEqualToString: @"DTSTAMP"]
62 || [classTag isEqualToString: @"DTSTART"]
63 || [classTag isEqualToString: @"CREATED"]
64 || [classTag isEqualToString: @"LAST-MODIFIED"])
65 tagClass = [iCalDateTime class];
67 tagClass = [super classForTag: classTag];
74 - (void) setUid: (NSString *) _uid
76 [[self uniqueChildWithTag: @"uid"] setValue: 0 to: _uid];
81 return [[self uniqueChildWithTag: @"uid"] value: 0];
84 - (void) setSummary: (NSString *) _value
86 [[self uniqueChildWithTag: @"summary"] setValue: 0 to: _value];
89 - (NSString *) summary
91 return [[self uniqueChildWithTag: @"summary"] value: 0];
94 - (void) setLocation: (NSString *) _value
96 [[self uniqueChildWithTag: @"location"] setValue: 0 to: _value];
99 - (NSString *) location
101 return [[self uniqueChildWithTag: @"location"] value: 0];
104 - (void) setComment: (NSString *) _value
106 [[self uniqueChildWithTag: @"description"] setValue: 0 to: _value];
109 - (NSString *) comment
111 return [[self uniqueChildWithTag: @"description"] value: 0];
114 - (void) setAccessClass: (NSString *) _value
116 [[self uniqueChildWithTag: @"class"] setValue: 0 to: _value];
119 - (NSString *) accessClass
121 return [[self uniqueChildWithTag: @"class"] value: 0];
124 - (iCalAccessClass) symbolicAccessClass
126 iCalAccessClass symbolicAccessClass;
127 NSString *accessClass;
129 accessClass = [[self accessClass] uppercaseString];
130 if ([accessClass isEqualToString: @"PRIVATE"])
131 symbolicAccessClass = iCalAccessPrivate;
132 else if ([accessClass isEqualToString: @"CONFIDENTIAL"])
133 symbolicAccessClass = iCalAccessConfidential;
135 symbolicAccessClass = iCalAccessPublic;
137 return symbolicAccessClass;
142 return ([self symbolicAccessClass] == iCalAccessPublic);
145 - (void) setPriority: (NSString *) _value
147 [[self uniqueChildWithTag: @"priority"] setValue: 0 to: _value];
150 - (NSString *) priority
152 return [[self uniqueChildWithTag: @"priority"] value: 0];
155 - (void) setCategories: (NSString *) _value
157 [[self uniqueChildWithTag: @"categories"] setValue: 0 to: _value];
160 - (NSString *) categories
162 return [[self uniqueChildWithTag: @"categories"] value: 0];
165 - (void) setUserComment: (NSString *) _value
167 [[self uniqueChildWithTag: @"usercomment"] setValue: 0 to: _value];
170 - (NSString *) userComment
172 return [[self uniqueChildWithTag: @"usercomment"] value: 0];
175 - (void) setStatus: (NSString *) _value
177 [[self uniqueChildWithTag: @"status"] setValue: 0 to: _value];
180 - (NSString *) status
182 return [[self uniqueChildWithTag: @"status"] value: 0];
185 - (void) setSequence: (NSNumber *)_value
189 sequence = [NSString stringWithFormat: @"%@", _value];
190 [[self uniqueChildWithTag: @"sequence"] setValue: 0
194 - (NSNumber *) sequence
198 sequence = [[self uniqueChildWithTag: @"sequence"] value: 0];
200 return [NSNumber numberWithInt: [sequence intValue]];
203 - (void) increaseSequence
207 seq = [[self sequence] intValue];
209 [self setSequence: [NSNumber numberWithInt: seq]];
212 - (void) setCreated: (NSCalendarDate *) newCreated
214 [(iCalDateTime *) [self uniqueChildWithTag: @"created"]
215 setDateTime: newCreated];
218 - (NSCalendarDate *) created
220 return [(iCalDateTime *) [self uniqueChildWithTag: @"created"]
224 - (void) setLastModified: (NSCalendarDate *) newLastModified
226 [(iCalDateTime *) [self uniqueChildWithTag: @"last-modified"]
227 setDateTime: newLastModified];
230 - (NSCalendarDate *) lastModified
232 return [(iCalDateTime *) [self uniqueChildWithTag: @"last-modified"]
236 - (void) setTimeStampAsDate: (NSCalendarDate *) newTimeStamp
238 [(iCalDateTime *) [self uniqueChildWithTag: @"dtstamp"]
239 setDateTime: newTimeStamp];
242 - (NSCalendarDate *) timeStampAsDate
244 return [(iCalDateTime *) [self uniqueChildWithTag: @"dtstamp"]
248 - (void) setStartDate: (NSCalendarDate *) newStartDate
250 [(iCalDateTime *) [self uniqueChildWithTag: @"dtstart"]
251 setDateTime: newStartDate];
254 - (NSCalendarDate *) startDate
256 return [(iCalDateTime *) [self uniqueChildWithTag: @"dtstart"]
260 - (BOOL) hasStartDate
262 return ([[self childrenWithTag: @"dtstart"] count] > 0);
265 - (void) setOrganizer: (iCalPerson *) _organizer
267 [_organizer setTag: @"organizer"];
268 [self setUniqueChild: _organizer];
271 - (iCalPerson *) organizer
273 return (iCalPerson *) [self uniqueChildWithTag: @"organizer"];
276 - (void) removeAllAttendees
278 [children removeObjectsInArray: [self attendees]];
281 - (void) addToAttendees: (iCalPerson *) _person
283 [_person setTag: @"attendee"];
284 [self addChild: _person];
287 - (void) setAttendees: (NSArray *) attendees
289 [self removeAllAttendees];
290 [self addChildren: attendees];
293 - (NSArray *) attendees
295 return [self childrenWithTag: @"attendee"];
298 - (void) removeAllAlarms
300 [children removeObjectsInArray: [self alarms]];
303 - (void) addToAlarms: (id) _alarm
307 [_alarm setTag: @"valarm"];
308 [self addChild: _alarm];
314 return ([[self childrenWithTag: @"valarm"] count] > 0);
319 return [self childrenWithTag: @"valarm"];
322 - (void) setUrl: (id) _value
326 if ([_value isKindOfClass: [NSString class]])
328 else if ([_value isKindOfClass: [NSURL class]])
329 asString = [_value absoluteString];
333 [[self uniqueChildWithTag: @"url"] setValue: 0 to: asString];
340 stringUrl = [[self uniqueChildWithTag: @"url"] value: 0];
342 return [NSURL URLWithString: stringUrl];
347 - (NSArray *) participants
349 return [self _filteredAttendeesThinkingOfPersons: YES];
352 - (NSArray *) resources
354 return [self _filteredAttendeesThinkingOfPersons: NO];
357 - (NSArray *) _filteredAttendeesThinkingOfPersons: (BOOL) _persons
360 NSMutableArray *filtered;
367 list = [self attendees];
369 filtered = [NSMutableArray arrayWithCapacity: max];
370 for (count = 0; count < max; count++)
372 person = (iCalPerson *) [list objectAtIndex: count];
373 role = [[person role] uppercaseString];
374 if (![role hasPrefix: @"NON-PART"])
375 [filtered addObject: person];
381 list = [self childrenWithTag: @"attendee"
382 andAttribute: @"role"
383 havingValue: @"non-part"];
388 - (BOOL) isOrganizer: (id) _email
390 NSString *organizerMail;
392 organizerMail = [[self organizer] rfc822Email];
394 return [[organizerMail lowercaseString]
395 isEqualToString: [_email lowercaseString]];
398 - (BOOL) isParticipant: (id) _email
402 _email = [_email lowercaseString];
403 partEmails = [[self participants] valueForKey:@"rfc822Email"];
404 partEmails = [partEmails valueForKey: @"lowercaseString"];
405 return [partEmails containsObject:_email];
408 - (iCalPerson *) findParticipantWithEmail: (id) _email
413 _email = [_email lowercaseString];
414 ps = [self participants];
417 for (i = 0; i < count; i++) {
420 p = [ps objectAtIndex:i];
421 if ([[[p rfc822Email] lowercaseString] isEqualToString:_email])
425 return nil; /* not found */
428 @end /* iCalEntityObject */