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 - (void)setCn:(NSString *)_s {
40 ASSIGNCOPY(self->cn, _s);
45 - (NSString *)cnWithoutQuotes {
46 /* remove quotes around a CN */
50 if ([_cn length] <= 2)
52 if ([_cn characterAtIndex:0] != '"')
54 if (![_cn hasSuffix:@"\""])
57 return [_cn substringWithRange:NSMakeRange(1, [_cn length] - 2)];
60 - (void)setEmail:(NSString *)_s {
61 ASSIGNCOPY(self->email, _s);
67 - (NSString *)rfc822Email {
71 _email = [self email];
72 idx = NSMaxRange([_email rangeOfString:@":"]);
74 if ((idx > 0) && ([_email length] > idx))
75 return [_email substringFromIndex:idx];
80 - (void)setRsvp:(NSString *)_s {
81 ASSIGNCOPY(self->rsvp, _s);
87 - (void)setXuid:(NSString *)_s {
88 ASSIGNCOPY(self->xuid, _s);
94 - (void)setRole:(NSString *)_s {
95 ASSIGNCOPY(self->role, _s);
101 - (void)setPartStat:(NSString *)_s {
102 ASSIGNCOPY(self->partStat, _s);
104 - (NSString *)partStat {
105 return self->partStat;
108 - (void)setParticipationStatus:(iCalPersonPartStat)_status {
112 case iCalPersonPartStatAccepted:
115 case iCalPersonPartStatDeclined:
118 case iCalPersonPartStatTentative:
121 case iCalPersonPartStatDelegated:
124 case iCalPersonPartStatCompleted:
127 case iCalPersonPartStatInProcess:
128 stat = @"IN-PROCESS";
130 case iCalPersonPartStatExperimental:
131 case iCalPersonPartStatOther:
132 [NSException raise:NSInternalInconsistencyException
133 format:@"Attempt to set meaningless "
134 @"participationStatus (%d)!", _status];
135 stat = nil; /* keep compiler happy */
138 stat = @"NEEDS-ACTION";
141 [self setPartStat:stat];
144 - (iCalPersonPartStat)participationStatus {
147 stat = [[self partStat] uppercaseString];
148 if (![stat isNotNull] || [stat isEqualToString:@"NEEDS-ACTION"])
149 return iCalPersonPartStatNeedsAction;
150 else if ([stat isEqualToString:@"ACCEPTED"])
151 return iCalPersonPartStatAccepted;
152 else if ([stat isEqualToString:@"DECLINED"])
153 return iCalPersonPartStatDeclined;
154 else if ([stat isEqualToString:@"TENTATIVE"])
155 return iCalPersonPartStatTentative;
156 else if ([stat isEqualToString:@"DELEGATED"])
157 return iCalPersonPartStatDelegated;
158 else if ([stat isEqualToString:@"COMPLETED"])
159 return iCalPersonPartStatCompleted;
160 else if ([stat isEqualToString:@"IN-PROCESS"])
161 return iCalPersonPartStatInProcess;
162 else if ([stat hasPrefix:@"X-"])
163 return iCalPersonPartStatExperimental;
164 return iCalPersonPartStatOther;
172 return [[self email] hash];
176 - (BOOL)isEqual:(id)_other {
179 if([_other class] != self->isa)
181 if([_other hash] != [self hash])
183 return [self isEqualToPerson:_other];
186 - (BOOL)isEqualToPerson:(iCalPerson *)_other {
187 if(![self hasSameEmailAddress:_other])
189 if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
191 if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
193 if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
195 if(!IS_EQUAL([self role], [_other role], isEqualToString:))
197 if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
202 - (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
203 return IS_EQUAL([[self email] lowercaseString],
204 [[_other email] lowercaseString],
210 - (NSString *)description {
213 ms = [NSMutableString stringWithCapacity:128];
214 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
216 if (self->cn) [ms appendFormat:@" cn=%@", self->cn];
217 if (self->email) [ms appendFormat:@" email=%@", self->email];
218 if (self->role) [ms appendFormat:@" role=%@", self->role];
219 if (self->xuid) [ms appendFormat:@" uid=%@", self->xuid];
220 if (self->partStat) [ms appendFormat:@" status=%@", self->partStat];
221 if (self->rsvp) [ms appendFormat:@" rsvp=%@", self->rsvp];
223 [ms appendString:@">"];
227 @end /* iCalPerson */