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 #import <Foundation/NSString.h>
24 #import "iCalPerson.h"
26 @implementation iCalPerson
30 - (void) setCn: (NSString *) _s
32 [self setValue: 0 ofAttribute: @"cn" to: _s];
37 return [self value: 0 ofAttribute: @"cn"];
40 - (NSString *) cnWithoutQuotes
42 /* remove quotes around a CN */
46 if ([_cn length] <= 2)
48 if ([_cn characterAtIndex:0] != '"')
50 if (![_cn hasSuffix:@"\""])
53 return [_cn substringWithRange:NSMakeRange(1, [_cn length] - 2)];
56 - (void) setEmail: (NSString *)_s
59 to: [NSString stringWithFormat: @"MAILTO:%@", _s]];
64 return [self value: 0];
67 - (NSString *) rfc822Email
72 _email = [self email];
73 idx = NSMaxRange([_email rangeOfString:@":"]);
75 if ((idx > 0) && ([_email length] > idx))
76 return [_email substringFromIndex:idx];
81 - (void) setRsvp: (NSString *) _s
83 [self setValue: 0 ofAttribute: @"rsvp" to: _s];
88 return [self value: 0 ofAttribute: @"rsvp"];
91 // - (void)setXuid:(NSString *)_s {
92 // ASSIGNCOPY(self->xuid, _s);
94 // - (NSString *)xuid {
98 - (void)setRole:(NSString *)_s
100 [self setValue: 0 ofAttribute: @"role" to: _s];
105 return [self value: 0 ofAttribute: @"role"];
108 - (void)setPartStat:(NSString *)_s
110 [self setValue: 0 ofAttribute: @"partstat" to: _s];
113 - (NSString *) partStat
115 return [self value: 0 ofAttribute: @"partstat"];
118 - (NSString *) partStatWithDefault
126 return @"NEEDS-ACTION";
129 - (void) setParticipationStatus: (iCalPersonPartStat) _status
134 case iCalPersonPartStatAccepted:
137 case iCalPersonPartStatDeclined:
140 case iCalPersonPartStatTentative:
143 case iCalPersonPartStatDelegated:
146 case iCalPersonPartStatCompleted:
149 case iCalPersonPartStatInProcess:
150 stat = @"IN-PROCESS";
152 case iCalPersonPartStatExperimental:
153 case iCalPersonPartStatOther:
154 // [NSException raise:NSInternalInconsistencyException
155 // format:@"Attempt to set meaningless "
156 // @"participationStatus (%d)!", _status];
157 stat = nil; /* keep compiler happy */
160 stat = @"NEEDS-ACTION";
164 [self setPartStat:stat];
167 - (iCalPersonPartStat)participationStatus {
170 stat = [[self partStat] uppercaseString];
171 if (![stat length] || [stat isEqualToString:@"NEEDS-ACTION"])
172 return iCalPersonPartStatNeedsAction;
173 else if ([stat isEqualToString:@"ACCEPTED"])
174 return iCalPersonPartStatAccepted;
175 else if ([stat isEqualToString:@"DECLINED"])
176 return iCalPersonPartStatDeclined;
177 else if ([stat isEqualToString:@"TENTATIVE"])
178 return iCalPersonPartStatTentative;
179 else if ([stat isEqualToString:@"DELEGATED"])
180 return iCalPersonPartStatDelegated;
181 else if ([stat isEqualToString:@"COMPLETED"])
182 return iCalPersonPartStatCompleted;
183 else if ([stat isEqualToString:@"IN-PROCESS"])
184 return iCalPersonPartStatInProcess;
185 else if ([stat hasPrefix:@"X-"])
186 return iCalPersonPartStatExperimental;
187 return iCalPersonPartStatOther;
195 return [[self email] hash];
199 - (BOOL)isEqual:(id)_other {
202 if([_other class] != self->isa)
204 if([_other hash] != [self hash])
206 return [self isEqualToPerson:_other];
209 - (BOOL)isEqualToPerson:(iCalPerson *)_other {
210 if(![self hasSameEmailAddress:_other])
212 if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
214 if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
216 if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
218 if(!IS_EQUAL([self role], [_other role], isEqualToString:))
220 // if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
225 - (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
226 return IS_EQUAL([[self email] lowercaseString],
227 [[_other email] lowercaseString],
231 @end /* iCalPerson */