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
34 [self->summary release];
35 [self->created release];
36 [self->lastModified release];
37 [self->startDate release];
38 [self->accessClass release];
39 [self->priority release];
40 [self->alarms release];
41 [self->organizer release];
42 [self->attendees release];
43 [self->comment release];
44 [self->sequence release];
45 [self->location release];
46 [self->status release];
47 [self->categories release];
48 [self->userComment release];
54 - (id)copyWithZone:(NSZone *)_zone {
55 iCalEntityObject *new;
57 new = [super copyWithZone:_zone];
59 ASSIGNCOPY(new->uid, self->uid);
60 ASSIGNCOPY(new->summary, self->summary);
61 new->timestamp = self->timestamp;
62 ASSIGNCOPY(new->created, self->created);
63 ASSIGNCOPY(new->lastModified, self->lastModified);
64 ASSIGNCOPY(new->startDate, self->startDate);
65 ASSIGNCOPY(new->accessClass, self->accessClass);
66 ASSIGNCOPY(new->priority, self->priority);
67 ASSIGNCOPY(new->alarms, self->alarms);
68 ASSIGNCOPY(new->organizer, self->organizer);
69 ASSIGNCOPY(new->attendees, self->attendees);
70 ASSIGNCOPY(new->comment, self->comment);
71 ASSIGNCOPY(new->sequence, self->sequence);
72 ASSIGNCOPY(new->location, self->location);
73 ASSIGNCOPY(new->status, self->status);
74 ASSIGNCOPY(new->categories, self->categories);
75 ASSIGNCOPY(new->userComment, self->userComment);
82 - (void)setUid:(NSString *)_value {
83 if (self->uid != _value) {
84 [self->uid autorelease];
85 self->uid = [_value retain];
92 - (void)setSummary:(NSString *)_value {
93 if (self->summary != _value) {
94 [self->summary autorelease];
95 self->summary = [_value retain];
98 - (NSString *)summary {
102 - (void)setLocation:(NSString *)_value {
103 if (self->location != _value) {
104 [self->location autorelease];
105 self->location = [_value retain];
108 - (NSString *)location {
109 return self->location;
112 - (void)setComment:(NSString *)_value {
113 if (self->comment != _value) {
114 [self->comment autorelease];
115 self->comment = [_value retain];
118 - (NSString *)comment {
119 return self->comment;
122 - (void)setAccessClass:(NSString *)_value {
123 if (self->accessClass != _value) {
124 [self->accessClass autorelease];
125 self->accessClass = [_value retain];
128 - (NSString *)accessClass {
129 return self->accessClass;
132 - (void)setPriority:(NSString *)_value {
133 if (self->priority != _value) {
134 [self->priority autorelease];
135 self->priority = [_value retain];
138 - (NSString *)priority {
139 return self->priority;
142 - (void)setCategories:(NSString *)_value {
143 ASSIGN(self->categories, _value);
145 - (NSString *)categories {
146 return self->categories;
149 - (void)setSequence:(NSNumber *)_value {
150 if (![_value isNotNull]) _value = nil;
151 if (self->sequence != _value) {
152 if (_value != nil && ![_value isKindOfClass:[NSNumber class]])
153 _value = [NSNumber numberWithInt:[_value intValue]];
154 [self->sequence autorelease];
155 self->sequence = [_value retain];
158 - (NSNumber *)sequence {
159 return self->sequence;
161 - (void)increaseSequence {
164 seq = [[self sequence] intValue];
166 [self setSequence:[NSNumber numberWithInt:seq]];
169 - (void)setStatus:(NSString *)_value {
170 ASSIGNCOPY(self->status, _value);
172 - (NSString *)status {
173 // eg: STATUS:CONFIRMED
177 - (void)setCreated:(NSCalendarDate *)_value {
178 if (self->created != _value) {
179 [self->created autorelease];
180 self->created = [_value retain];
183 - (NSCalendarDate *)created {
184 return self->created;
186 - (void)setLastModified:(NSCalendarDate *)_value {
187 if (self->lastModified != _value) {
188 [self->lastModified autorelease];
189 self->lastModified = [_value retain];
192 - (NSCalendarDate *)lastModified {
193 return self->lastModified;
196 - (void)setTimeStampAsDate:(NSCalendarDate *)_date {
197 /* TODO: too be completed */
199 - (NSCalendarDate *)timeStampAsDate {
200 return [NSDate dateWithTimeIntervalSince1970:self->timestamp];
203 - (void)setStartDate:(NSCalendarDate *)_date {
204 if (self->startDate != _date) {
205 [self->startDate autorelease];
206 self->startDate = [_date retain];
209 - (NSCalendarDate *)startDate {
210 return self->startDate;
213 - (void)setOrganizer:(iCalPerson *)_organizer {
214 if (self->organizer != _organizer) {
215 [self->organizer autorelease];
216 self->organizer = [_organizer retain];
219 - (iCalPerson *)organizer {
220 return self->organizer;
223 - (void)removeAllAttendees {
224 [self->attendees removeAllObjects];
226 - (void)addToAttendees:(iCalPerson *)_person {
227 if (_person == nil) return;
228 if (self->attendees == nil)
229 self->attendees = [[NSMutableArray alloc] initWithCapacity:4];
230 [self->attendees addObject:_person];
232 - (NSArray *)attendees {
233 return self->attendees;
236 - (void)removeAllAlarms {
237 [self->alarms removeAllObjects];
239 - (void)addToAlarms:(id)_alarm {
240 if (_alarm == nil) return;
241 if (self->alarms == nil)
242 self->alarms = [[NSMutableArray alloc] initWithCapacity:1];
243 [self->alarms addObject:_alarm];
246 return [self->alarms count] > 0 ? YES : NO;
248 - (NSArray *)alarms {
252 - (void)setUserComment:(NSString *)_userComment {
253 ASSIGN(self->userComment, _userComment);
255 - (NSString *)userComment {
256 return self->userComment;
261 - (NSArray *)participants {
262 return [self _filteredAttendeesThinkingOfPersons:YES];
264 - (NSArray *)resources {
265 return [self _filteredAttendeesThinkingOfPersons:NO];
268 - (NSArray *)_filteredAttendeesThinkingOfPersons:(BOOL)_persons {
270 NSMutableArray *filtered;
273 list = [self attendees];
274 count = [list count];
275 filtered = [NSMutableArray arrayWithCapacity:count];
276 for (i = 0; i < count; i++) {
280 p = [list objectAtIndex:i];
283 if (role == nil || ![role hasPrefix:@"NON-PART"])
284 [filtered addObject:p];
287 if ([role hasPrefix:@"NON-PART"])
288 [filtered addObject:p];
294 - (BOOL)isOrganizer:(id)_email {
295 _email = [_email lowercaseString];
296 return [[[[self organizer] rfc822Email] lowercaseString]
297 isEqualToString:_email];
300 - (BOOL)isParticipant:(id)_email {
303 _email = [_email lowercaseString];
304 partEmails = [[self participants] valueForKey:@"rfc822Email"];
305 partEmails = [partEmails valueForKey:@"lowercaseString"];
306 return [partEmails containsObject:_email];
309 - (iCalPerson *)findParticipantWithEmail:(id)_email {
313 _email = [_email lowercaseString];
314 ps = [self participants];
317 for (i = 0; i < count; i++) {
320 p = [ps objectAtIndex:i];
321 if ([[[p rfc822Email] lowercaseString] isEqualToString:_email])
324 return nil; /* not found */
327 @end /* iCalEntityObject */