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->partStat release];
32 [self->email 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];
137 stat = @"NEEDS-ACTION";
140 [self setPartStat:stat];
143 - (iCalPersonPartStat)participationStatus {
146 stat = [[self partStat] uppercaseString];
147 if (![stat isNotNull] || [stat isEqualToString:@"NEEDS-ACTION"])
148 return iCalPersonPartStatNeedsAction;
149 else if ([stat isEqualToString:@"ACCEPTED"])
150 return iCalPersonPartStatAccepted;
151 else if ([stat isEqualToString:@"DECLINED"])
152 return iCalPersonPartStatDeclined;
153 else if ([stat isEqualToString:@"TENTATIVE"])
154 return iCalPersonPartStatTentative;
155 else if ([stat isEqualToString:@"DELEGATED"])
156 return iCalPersonPartStatDelegated;
157 else if ([stat isEqualToString:@"COMPLETED"])
158 return iCalPersonPartStatCompleted;
159 else if ([stat isEqualToString:@"IN-PROCESS"])
160 return iCalPersonPartStatInProcess;
161 else if ([stat hasPrefix:@"X-"])
162 return iCalPersonPartStatExperimental;
163 return iCalPersonPartStatOther;
171 return [[self email] hash];
175 - (BOOL)isEqual:(id)_other {
178 if([_other class] != self->isa)
180 if([_other hash] != [self hash])
182 return [self isEqualToPerson:_other];
185 - (BOOL)isEqualToPerson:(iCalPerson *)_other {
186 if(![self hasSameEmailAddress:_other])
188 if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
190 if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
192 if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
194 if(!IS_EQUAL([self role], [_other role], isEqualToString:))
196 if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
201 - (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
202 return IS_EQUAL([self email], [_other email], isEqualToString:);
207 - (NSString *)description {
210 ms = [NSMutableString stringWithCapacity:128];
211 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
213 if (self->cn) [ms appendFormat:@" cn=%@", self->cn];
214 if (self->email) [ms appendFormat:@" email=%@", self->email];
215 if (self->role) [ms appendFormat:@" role=%@", self->role];
216 if (self->xuid) [ms appendFormat:@" uid=%@", self->xuid];
217 if (self->partStat) [ms appendFormat:@" status=%@", self->partStat];
218 if (self->rsvp) [ms appendFormat:@" rsvp=%@", self->rsvp];
220 [ms appendString:@">"];
224 @end /* iCalPerson */