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 "iCalPerson.h"
25 @implementation iCalPerson
28 return [super version] + 0 /* v0 */;
31 NSAssert2([super version] == 0,
32 @"invalid superclass (%@) version %i !",
33 NSStringFromClass([self superclass]), [super version]);
38 [self->email release];
40 [self->partStat release];
48 - (id)copyWithZone:(NSZone *)_zone {
51 new = [super copyWithZone:_zone];
53 new->cn = [self->cn copyWithZone:_zone];
54 new->email = [self->email copyWithZone:_zone];
55 new->rsvp = [self->rsvp copyWithZone:_zone];
56 new->partStat = [self->partStat copyWithZone:_zone];
57 new->role = [self->role copyWithZone:_zone];
58 new->xuid = [self->xuid copyWithZone:_zone];
65 - (void)setCn:(NSString *)_s {
66 ASSIGNCOPY(self->cn, _s);
71 - (NSString *)cnWithoutQuotes {
72 /* remove quotes around a CN */
76 if ([_cn length] <= 2)
78 if ([_cn characterAtIndex:0] != '"')
80 if (![_cn hasSuffix:@"\""])
83 return [_cn substringWithRange:NSMakeRange(1, [_cn length] - 2)];
86 - (void)setEmail:(NSString *)_s {
87 ASSIGNCOPY(self->email, _s);
93 - (NSString *)rfc822Email {
97 _email = [self email];
98 idx = NSMaxRange([_email rangeOfString:@":"]);
100 if ((idx > 0) && ([_email length] > idx))
101 return [_email substringFromIndex:idx];
106 - (void)setRsvp:(NSString *)_s {
107 ASSIGNCOPY(self->rsvp, _s);
113 - (void)setXuid:(NSString *)_s {
114 ASSIGNCOPY(self->xuid, _s);
120 - (void)setRole:(NSString *)_s {
121 ASSIGNCOPY(self->role, _s);
127 - (void)setPartStat:(NSString *)_s {
128 ASSIGNCOPY(self->partStat, _s);
130 - (NSString *)partStat {
131 return self->partStat;
133 - (NSString *)partStatWithDefault {
140 return @"NEEDS-ACTION";
143 - (void)setParticipationStatus:(iCalPersonPartStat)_status {
147 case iCalPersonPartStatAccepted:
150 case iCalPersonPartStatDeclined:
153 case iCalPersonPartStatTentative:
156 case iCalPersonPartStatDelegated:
159 case iCalPersonPartStatCompleted:
162 case iCalPersonPartStatInProcess:
163 stat = @"IN-PROCESS";
165 case iCalPersonPartStatExperimental:
166 case iCalPersonPartStatOther:
167 [NSException raise:NSInternalInconsistencyException
168 format:@"Attempt to set meaningless "
169 @"participationStatus (%d)!", _status];
170 stat = nil; /* keep compiler happy */
173 stat = @"NEEDS-ACTION";
176 [self setPartStat:stat];
179 - (iCalPersonPartStat)participationStatus {
182 stat = [[self partStat] uppercaseString];
183 if (![stat isNotNull] || [stat isEqualToString:@"NEEDS-ACTION"])
184 return iCalPersonPartStatNeedsAction;
185 else if ([stat isEqualToString:@"ACCEPTED"])
186 return iCalPersonPartStatAccepted;
187 else if ([stat isEqualToString:@"DECLINED"])
188 return iCalPersonPartStatDeclined;
189 else if ([stat isEqualToString:@"TENTATIVE"])
190 return iCalPersonPartStatTentative;
191 else if ([stat isEqualToString:@"DELEGATED"])
192 return iCalPersonPartStatDelegated;
193 else if ([stat isEqualToString:@"COMPLETED"])
194 return iCalPersonPartStatCompleted;
195 else if ([stat isEqualToString:@"IN-PROCESS"])
196 return iCalPersonPartStatInProcess;
197 else if ([stat hasPrefix:@"X-"])
198 return iCalPersonPartStatExperimental;
199 return iCalPersonPartStatOther;
207 return [[self email] hash];
211 - (BOOL)isEqual:(id)_other {
214 if([_other class] != self->isa)
216 if([_other hash] != [self hash])
218 return [self isEqualToPerson:_other];
221 - (BOOL)isEqualToPerson:(iCalPerson *)_other {
222 if(![self hasSameEmailAddress:_other])
224 if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
226 if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
228 if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
230 if(!IS_EQUAL([self role], [_other role], isEqualToString:))
232 if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
237 - (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
238 return IS_EQUAL([[self email] lowercaseString],
239 [[_other email] lowercaseString],
245 - (NSString *)description {
248 ms = [NSMutableString stringWithCapacity:128];
249 [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
251 if (self->cn) [ms appendFormat:@" cn=%@", self->cn];
252 if (self->email) [ms appendFormat:@" email=%@", self->email];
253 if (self->role) [ms appendFormat:@" role=%@", self->role];
254 if (self->xuid) [ms appendFormat:@" uid=%@", self->xuid];
255 if (self->partStat) [ms appendFormat:@" status=%@", self->partStat];
256 if (self->rsvp) [ms appendFormat:@" rsvp=%@", self->rsvp];
258 [ms appendString:@">"];
262 @end /* iCalPerson */