]> err.no Git - sope/blob - sope-ical/NGiCal/iCalEntityObject.m
added "url" property to iCalEntityObject
[sope] / sope-ical / NGiCal / iCalEntityObject.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "iCalEntityObject.h"
23 #include "iCalPerson.h"
24 #include "common.h"
25
26 @interface iCalEntityObject (PrivateAPI)
27 - (NSArray *)_filteredAttendeesThinkingOfPersons:(BOOL)_persons;
28 @end
29
30 @implementation iCalEntityObject
31
32 + (int)version {
33   return [super version] + 1 /* v1 */;
34 }
35 + (void)initialize {
36   NSAssert2([super version] == 0,
37             @"invalid superclass (%@) version %i !",
38             NSStringFromClass([self superclass]), [super version]);
39 }
40
41 - (void)dealloc {
42   [self->uid          release];
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];
58   [self->url          release];
59   [super dealloc];
60 }
61
62 /* NSCopying */
63
64 - (id)copyWithZone:(NSZone *)_zone {
65   iCalEntityObject *new;
66
67   new = [super copyWithZone:_zone];
68
69   new->uid          = [self->uid          copyWithZone:_zone];
70   new->summary      = [self->summary      copyWithZone:_zone];
71   new->timestamp    = self->timestamp;
72   new->created      = [self->created      copyWithZone:_zone];
73   new->lastModified = [self->lastModified copyWithZone:_zone];
74   new->startDate    = [self->startDate    copyWithZone:_zone];
75   new->accessClass  = [self->accessClass  copyWithZone:_zone];
76   new->priority     = [self->priority     copyWithZone:_zone];
77   new->alarms       = [self->alarms       copyWithZone:_zone];
78   new->organizer    = [self->organizer    copyWithZone:_zone];
79   new->attendees    = [self->attendees    copyWithZone:_zone];
80   new->comment      = [self->comment      copyWithZone:_zone];
81   new->sequence     = [self->sequence     copyWithZone:_zone];
82   new->location     = [self->location     copyWithZone:_zone];
83   new->status       = [self->status       copyWithZone:_zone];
84   new->categories   = [self->categories   copyWithZone:_zone];
85   new->userComment  = [self->userComment  copyWithZone:_zone];
86   new->url          = [self->url          copyWithZone:_zone];
87
88   return new;
89 }
90
91 /* accessors */
92
93 - (void)setUid:(NSString *)_value {
94   if (self->uid != _value) {
95     [self->uid autorelease];
96     self->uid = [_value retain];
97   }
98 }
99 - (NSString *)uid {
100   return self->uid;
101 }
102
103 - (void)setSummary:(NSString *)_value {
104   if (self->summary != _value) {
105     [self->summary autorelease];
106     self->summary = [_value retain];
107   }
108 }
109 - (NSString *)summary {
110   return self->summary;
111 }
112
113 - (void)setLocation:(NSString *)_value {
114   if (self->location != _value) {
115     [self->location autorelease];
116     self->location = [_value retain];
117   }
118 }
119 - (NSString *)location {
120   return self->location;
121 }
122
123 - (void)setComment:(NSString *)_value {
124   if (self->comment != _value) {
125     [self->comment autorelease];
126     self->comment = [_value retain];
127   }
128 }
129 - (NSString *)comment {
130   return self->comment;
131 }
132
133 - (void)setAccessClass:(NSString *)_value {
134   if (self->accessClass != _value) {
135     [self->accessClass autorelease];
136     self->accessClass = [_value retain];
137   }
138 }
139 - (NSString *)accessClass {
140   return self->accessClass;
141 }
142
143 - (void)setPriority:(NSString *)_value {
144   if (self->priority != _value) {
145     [self->priority autorelease];
146     self->priority = [_value retain];
147   }
148 }
149 - (NSString *)priority {
150   return self->priority;
151 }
152
153 - (void)setCategories:(NSString *)_value {
154   ASSIGN(self->categories, _value);
155 }
156 - (NSString *)categories {
157   return self->categories;
158 }
159
160 - (void)setSequence:(NSNumber *)_value {
161   if (![_value isNotNull]) _value = nil;
162   if (self->sequence != _value) {
163     if (_value != nil && ![_value isKindOfClass:[NSNumber class]])
164       _value = [NSNumber numberWithInt:[_value intValue]];
165     [self->sequence autorelease];
166     self->sequence = [_value retain];
167   }
168 }
169 - (NSNumber *)sequence {
170   return self->sequence;
171 }
172 - (void)increaseSequence {
173   int seq;
174   
175   seq = [[self sequence] intValue];
176   seq += 1;
177   [self setSequence:[NSNumber numberWithInt:seq]];
178 }
179
180 - (void)setStatus:(NSString *)_value {
181   ASSIGNCOPY(self->status, _value);
182 }
183 - (NSString *)status {
184   // eg: STATUS:CONFIRMED
185   return self->status;
186 }
187
188 - (void)setCreated:(NSCalendarDate *)_value {
189   if (self->created != _value) {
190     [self->created autorelease];
191     self->created = [_value retain];
192   }
193 }
194 - (NSCalendarDate *)created {
195   return self->created;
196 }
197 - (void)setLastModified:(NSCalendarDate *)_value {
198   if (self->lastModified != _value) {
199     [self->lastModified autorelease];
200     self->lastModified = [_value retain];
201   }
202 }
203 - (NSCalendarDate *)lastModified {
204   return self->lastModified;
205 }
206
207 - (void)setTimeStampAsDate:(NSCalendarDate *)_date {
208   /* TODO: too be completed */
209 }
210 - (NSCalendarDate *)timeStampAsDate {
211   return [NSDate dateWithTimeIntervalSince1970:self->timestamp];
212 }
213
214 - (void)setStartDate:(NSCalendarDate *)_date {
215   if (self->startDate != _date) {
216     [self->startDate autorelease];
217     self->startDate = [_date retain];
218   }
219 }
220 - (NSCalendarDate *)startDate {
221   return self->startDate;
222 }
223
224 - (void)setOrganizer:(iCalPerson *)_organizer {
225   if (self->organizer != _organizer) {
226     [self->organizer autorelease];
227     self->organizer = [_organizer retain];
228   }
229 }
230 - (iCalPerson *)organizer {
231   return self->organizer;
232 }
233
234 - (void)removeAllAttendees {
235     [self->attendees removeAllObjects];
236 }
237 - (void)addToAttendees:(iCalPerson *)_person {
238   if (_person == nil) return;
239   if (self->attendees == nil)
240     self->attendees = [[NSMutableArray alloc] initWithCapacity:4];
241   [self->attendees addObject:_person];
242 }
243 - (NSArray *)attendees {
244   return self->attendees;
245 }
246
247 - (void)removeAllAlarms {
248     [self->alarms removeAllObjects];
249 }
250 - (void)addToAlarms:(id)_alarm {
251   if (_alarm == nil) return;
252   if (self->alarms == nil)
253     self->alarms = [[NSMutableArray alloc] initWithCapacity:1];
254   [self->alarms addObject:_alarm];
255 }
256 - (BOOL)hasAlarms {
257   return [self->alarms count] > 0 ? YES : NO;
258 }
259 - (NSArray *)alarms {
260   return self->alarms;
261 }
262
263 - (void)setUserComment:(NSString *)_userComment {
264   ASSIGN(self->userComment, _userComment);
265 }
266 - (NSString *)userComment {
267   return self->userComment;
268 }
269
270 - (void)setUrl:(id)_value {
271   if (self->url != _value) {
272     [self->url autorelease];
273     if ([_value isKindOfClass:[NSString class]]) {
274       self->url = [[NSURL alloc] initWithString:_value];
275     }
276     else {
277       self->url = [_value retain];
278     }
279   }
280 }
281 - (NSURL *)url {
282   return self->url;
283 }
284
285 /* stuff */
286
287 - (NSArray *)participants {
288   return [self _filteredAttendeesThinkingOfPersons:YES];
289 }
290 - (NSArray *)resources {
291   return [self _filteredAttendeesThinkingOfPersons:NO];
292 }
293
294 - (NSArray *)_filteredAttendeesThinkingOfPersons:(BOOL)_persons {
295   NSArray        *list;
296   NSMutableArray *filtered;
297   unsigned       i, count;
298   
299   list     = [self attendees];
300   count    = [list count];
301   filtered = [NSMutableArray arrayWithCapacity:count];
302   for (i = 0; i < count; i++) {
303     iCalPerson *p;
304     NSString   *role;
305     
306     p = [list objectAtIndex:i];
307     role = [p role];
308     if (_persons) {
309       if (role == nil || ![role hasPrefix:@"NON-PART"])
310         [filtered addObject:p];
311     }
312     else {
313       if ([role hasPrefix:@"NON-PART"])
314         [filtered addObject:p];
315     }
316   }
317   return filtered;
318 }
319
320 - (BOOL)isOrganizer:(id)_email {
321   _email = [_email lowercaseString];
322   return [[[[self organizer] rfc822Email] lowercaseString]
323                                           isEqualToString:_email];
324 }
325
326 - (BOOL)isParticipant:(id)_email {
327   NSArray *partEmails;
328   
329   _email     = [_email lowercaseString];
330   partEmails = [[self participants] valueForKey:@"rfc822Email"];
331   partEmails = [partEmails valueForKey:@"lowercaseString"];
332   return [partEmails containsObject:_email];
333 }
334
335 - (iCalPerson *)findParticipantWithEmail:(id)_email {
336   NSArray  *ps;
337   unsigned i, count;
338   
339   _email = [_email lowercaseString];
340   ps     = [self participants];
341   count  = [ps count];
342
343   for (i = 0; i < count; i++) {
344     iCalPerson *p;
345     
346     p = [ps objectAtIndex:i];
347     if ([[[p rfc822Email] lowercaseString] isEqualToString:_email])
348       return p;
349   }
350   return nil; /* not found */
351 }
352
353 @end /* iCalEntityObject */