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 #include "iCalEntityObject.h"
23 #include "iCalPerson.h"
26 @interface iCalEntityObject (PrivateAPI)
27 - (NSArray *)_filteredAttendeesThinkingOfPersons:(BOOL)_persons;
30 @implementation iCalEntityObject
33 return [super version] + 0 /* v0 */;
36 NSAssert2([super version] == 0,
37 @"invalid superclass (%@) version %i !",
38 NSStringFromClass([self superclass]), [super version]);
43 [self->summary release];
44 [self->created release];
45 [self->lastModified release];
46 [self->startDate release];
47 [self->accessClass release];
48 [self->priority release];
49 [self->alarms release];
50 [self->organizer release];
51 [self->attendees release];
52 [self->comment release];
53 [self->sequence release];
54 [self->location release];
55 [self->status release];
56 [self->categories release];
57 [self->userComment release];
63 - (id)copyWithZone:(NSZone *)_zone {
64 iCalEntityObject *new;
66 new = [super copyWithZone:_zone];
68 new->uid = [self->uid copyWithZone:_zone];
69 new->summary = [self->summary copyWithZone:_zone];
70 new->timestamp = self->timestamp;
71 new->created = [self->created copyWithZone:_zone];
72 new->lastModified = [self->lastModified copyWithZone:_zone];
73 new->startDate = [self->startDate copyWithZone:_zone];
74 new->accessClass = [self->accessClass copyWithZone:_zone];
75 new->priority = [self->priority copyWithZone:_zone];
76 new->alarms = [self->alarms copyWithZone:_zone];
77 new->organizer = [self->organizer copyWithZone:_zone];
78 new->attendees = [self->attendees copyWithZone:_zone];
79 new->comment = [self->comment copyWithZone:_zone];
80 new->sequence = [self->sequence copyWithZone:_zone];
81 new->location = [self->location copyWithZone:_zone];
82 new->status = [self->status copyWithZone:_zone];
83 new->categories = [self->categories copyWithZone:_zone];
84 new->userComment = [self->userComment copyWithZone:_zone];
91 - (void)setUid:(NSString *)_value {
92 if (self->uid != _value) {
93 [self->uid autorelease];
94 self->uid = [_value retain];
101 - (void)setSummary:(NSString *)_value {
102 if (self->summary != _value) {
103 [self->summary autorelease];
104 self->summary = [_value retain];
107 - (NSString *)summary {
108 return self->summary;
111 - (void)setLocation:(NSString *)_value {
112 if (self->location != _value) {
113 [self->location autorelease];
114 self->location = [_value retain];
117 - (NSString *)location {
118 return self->location;
121 - (void)setComment:(NSString *)_value {
122 if (self->comment != _value) {
123 [self->comment autorelease];
124 self->comment = [_value retain];
127 - (NSString *)comment {
128 return self->comment;
131 - (void)setAccessClass:(NSString *)_value {
132 if (self->accessClass != _value) {
133 [self->accessClass autorelease];
134 self->accessClass = [_value retain];
137 - (NSString *)accessClass {
138 return self->accessClass;
141 - (void)setPriority:(NSString *)_value {
142 if (self->priority != _value) {
143 [self->priority autorelease];
144 self->priority = [_value retain];
147 - (NSString *)priority {
148 return self->priority;
151 - (void)setCategories:(NSString *)_value {
152 ASSIGN(self->categories, _value);
154 - (NSString *)categories {
155 return self->categories;
158 - (void)setSequence:(NSNumber *)_value {
159 if (![_value isNotNull]) _value = nil;
160 if (self->sequence != _value) {
161 if (_value != nil && ![_value isKindOfClass:[NSNumber class]])
162 _value = [NSNumber numberWithInt:[_value intValue]];
163 [self->sequence autorelease];
164 self->sequence = [_value retain];
167 - (NSNumber *)sequence {
168 return self->sequence;
170 - (void)increaseSequence {
173 seq = [[self sequence] intValue];
175 [self setSequence:[NSNumber numberWithInt:seq]];
178 - (void)setStatus:(NSString *)_value {
179 ASSIGNCOPY(self->status, _value);
181 - (NSString *)status {
182 // eg: STATUS:CONFIRMED
186 - (void)setCreated:(NSCalendarDate *)_value {
187 if (self->created != _value) {
188 [self->created autorelease];
189 self->created = [_value retain];
192 - (NSCalendarDate *)created {
193 return self->created;
195 - (void)setLastModified:(NSCalendarDate *)_value {
196 if (self->lastModified != _value) {
197 [self->lastModified autorelease];
198 self->lastModified = [_value retain];
201 - (NSCalendarDate *)lastModified {
202 return self->lastModified;
205 - (void)setTimeStampAsDate:(NSCalendarDate *)_date {
206 /* TODO: too be completed */
208 - (NSCalendarDate *)timeStampAsDate {
209 return [NSDate dateWithTimeIntervalSince1970:self->timestamp];
212 - (void)setStartDate:(NSCalendarDate *)_date {
213 if (self->startDate != _date) {
214 [self->startDate autorelease];
215 self->startDate = [_date retain];
218 - (NSCalendarDate *)startDate {
219 return self->startDate;
222 - (void)setOrganizer:(iCalPerson *)_organizer {
223 if (self->organizer != _organizer) {
224 [self->organizer autorelease];
225 self->organizer = [_organizer retain];
228 - (iCalPerson *)organizer {
229 return self->organizer;
232 - (void)removeAllAttendees {
233 [self->attendees removeAllObjects];
235 - (void)addToAttendees:(iCalPerson *)_person {
236 if (_person == nil) return;
237 if (self->attendees == nil)
238 self->attendees = [[NSMutableArray alloc] initWithCapacity:4];
239 [self->attendees addObject:_person];
241 - (NSArray *)attendees {
242 return self->attendees;
245 - (void)removeAllAlarms {
246 [self->alarms removeAllObjects];
248 - (void)addToAlarms:(id)_alarm {
249 if (_alarm == nil) return;
250 if (self->alarms == nil)
251 self->alarms = [[NSMutableArray alloc] initWithCapacity:1];
252 [self->alarms addObject:_alarm];
255 return [self->alarms count] > 0 ? YES : NO;
257 - (NSArray *)alarms {
261 - (void)setUserComment:(NSString *)_userComment {
262 ASSIGN(self->userComment, _userComment);
264 - (NSString *)userComment {
265 return self->userComment;
270 - (NSArray *)participants {
271 return [self _filteredAttendeesThinkingOfPersons:YES];
273 - (NSArray *)resources {
274 return [self _filteredAttendeesThinkingOfPersons:NO];
277 - (NSArray *)_filteredAttendeesThinkingOfPersons:(BOOL)_persons {
279 NSMutableArray *filtered;
282 list = [self attendees];
283 count = [list count];
284 filtered = [NSMutableArray arrayWithCapacity:count];
285 for (i = 0; i < count; i++) {
289 p = [list objectAtIndex:i];
292 if (role == nil || ![role hasPrefix:@"NON-PART"])
293 [filtered addObject:p];
296 if ([role hasPrefix:@"NON-PART"])
297 [filtered addObject:p];
303 - (BOOL)isOrganizer:(id)_email {
304 _email = [_email lowercaseString];
305 return [[[[self organizer] rfc822Email] lowercaseString]
306 isEqualToString:_email];
309 - (BOOL)isParticipant:(id)_email {
312 _email = [_email lowercaseString];
313 partEmails = [[self participants] valueForKey:@"rfc822Email"];
314 partEmails = [partEmails valueForKey:@"lowercaseString"];
315 return [partEmails containsObject:_email];
318 - (iCalPerson *)findParticipantWithEmail:(id)_email {
322 _email = [_email lowercaseString];
323 ps = [self participants];
326 for (i = 0; i < count; i++) {
329 p = [ps objectAtIndex:i];
330 if ([[[p rfc822Email] lowercaseString] isEqualToString:_email])
333 return nil; /* not found */
336 @end /* iCalEntityObject */