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
29 [self->email release];
31 [self->partStat release];
39 - (id)copyWithZone:(NSZone *)_zone {
42 new = [super copyWithZone:_zone];
44 ASSIGNCOPY(new->cn, self->cn);
45 ASSIGNCOPY(new->email, self->email);
46 ASSIGNCOPY(new->rsvp, self->rsvp);
47 ASSIGNCOPY(new->partStat, self->partStat);
48 ASSIGNCOPY(new->role, self->role);
49 ASSIGNCOPY(new->xuid, self->xuid);
56 - (void)setCn:(NSString *)_s {
57 ASSIGNCOPY(self->cn, _s);
62 - (NSString *)cnWithoutQuotes {
63 /* remove quotes around a CN */
67 if ([_cn length] <= 2)
69 if ([_cn characterAtIndex:0] != '"')
71 if (![_cn hasSuffix:@"\""])
74 return [_cn substringWithRange:NSMakeRange(1, [_cn length] - 2)];
77 - (void)setEmail:(NSString *)_s {
78 ASSIGNCOPY(self->email, _s);
84 - (NSString *)rfc822Email {
88 _email = [self email];
89 idx = NSMaxRange([_email rangeOfString:@":"]);
91 if ((idx > 0) && ([_email length] > idx))
92 return [_email substringFromIndex:idx];
97 - (void)setRsvp:(NSString *)_s {
98 ASSIGNCOPY(self->rsvp, _s);
104 - (void)setXuid:(NSString *)_s {
105 ASSIGNCOPY(self->xuid, _s);
111 - (void)setRole:(NSString *)_s {
112 ASSIGNCOPY(self->role, _s);
118 - (void)setPartStat:(NSString *)_s {
119 ASSIGNCOPY(self->partStat, _s);
121 - (NSString *)partStat {
122 return self->partStat;
125 - (void)setParticipationStatus:(iCalPersonPartStat)_status {
129 case iCalPersonPartStatAccepted:
132 case iCalPersonPartStatDeclined:
135 case iCalPersonPartStatTentative:
138 case iCalPersonPartStatDelegated:
141 case iCalPersonPartStatCompleted:
144 case iCalPersonPartStatInProcess:
145 stat = @"IN-PROCESS";
147 case iCalPersonPartStatExperimental:
148 case iCalPersonPartStatOther:
149 [NSException raise:NSInternalInconsistencyException
150 format:@"Attempt to set meaningless "
151 @"participationStatus (%d)!", _status];
152 stat = nil; /* keep compiler happy */
155 stat = @"NEEDS-ACTION";
158 [self setPartStat:stat];
161 - (iCalPersonPartStat)participationStatus {
164 stat = [[self partStat] uppercaseString];
165 if (![stat isNotNull] || [stat isEqualToString:@"NEEDS-ACTION"])
166 return iCalPersonPartStatNeedsAction;
167 else if ([stat isEqualToString:@"ACCEPTED"])
168 return iCalPersonPartStatAccepted;
169 else if ([stat isEqualToString:@"DECLINED"])
170 return iCalPersonPartStatDeclined;
171 else if ([stat isEqualToString:@"TENTATIVE"])
172 return iCalPersonPartStatTentative;
173 else if ([stat isEqualToString:@"DELEGATED"])
174 return iCalPersonPartStatDelegated;
175 else if ([stat isEqualToString:@"COMPLETED"])
176 return iCalPersonPartStatCompleted;
177 else if ([stat isEqualToString:@"IN-PROCESS"])
178 return iCalPersonPartStatInProcess;
179 else if ([stat hasPrefix:@"X-"])
180 return iCalPersonPartStatExperimental;
181 return iCalPersonPartStatOther;
189 return [[self email] hash];
193 - (BOOL)isEqual:(id)_other {
196 if([_other class] != self->isa)
198 if([_other hash] != [self hash])
200 return [self isEqualToPerson:_other];
203 - (BOOL)isEqualToPerson:(iCalPerson *)_other {
204 if(![self hasSameEmailAddress:_other])
206 if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
208 if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
210 if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
212 if(!IS_EQUAL([self role], [_other role], isEqualToString:))
214 if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
219 - (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
220 return IS_EQUAL([[self email] lowercaseString],
221 [[_other email] lowercaseString],
227 - (NSString *)description {
230 ms = [NSMutableString stringWithCapacity:128];
231 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
233 if (self->cn) [ms appendFormat:@" cn=%@", self->cn];
234 if (self->email) [ms appendFormat:@" email=%@", self->email];
235 if (self->role) [ms appendFormat:@" role=%@", self->role];
236 if (self->xuid) [ms appendFormat:@" uid=%@", self->xuid];
237 if (self->partStat) [ms appendFormat:@" status=%@", self->partStat];
238 if (self->rsvp) [ms appendFormat:@" rsvp=%@", self->rsvp];
240 [ms appendString:@">"];
244 @end /* iCalPerson */