]> err.no Git - sope/blob - sope-ical/NGiCal/iCalPerson.m
bugfixes for cycle calculation, modified implementations with future extensions in...
[sope] / sope-ical / NGiCal / iCalPerson.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "iCalPerson.h"
23 #include "common.h"
24
25 @implementation iCalPerson
26
27 - (void)dealloc {
28   [self->rsvp     release];
29   [self->partStat release];
30   [self->role     release];
31   [self->xuid     release];
32   [self->email release];
33   [self->cn    release];
34   [super dealloc];
35 }
36
37 /* accessors */
38
39 - (void)setCn:(NSString *)_s {
40   ASSIGNCOPY(self->cn, _s);
41 }
42 - (NSString *)cn {
43   return self->cn;
44 }
45 - (NSString *)cnWithoutQuotes {
46   /* remove quotes around a CN */
47   NSString *_cn;
48   
49   _cn = [self cn];
50   if ([_cn length] <= 2)
51     return _cn;
52   if ([_cn characterAtIndex:0] != '"')
53     return _cn;
54   if (![_cn hasSuffix:@"\""])
55     return _cn;
56   
57   return [_cn substringWithRange:NSMakeRange(1, [_cn length] - 2)];
58 }
59
60 - (void)setEmail:(NSString *)_s {
61   ASSIGNCOPY(self->email, _s);
62 }
63 - (NSString *)email {
64   return self->email;
65 }
66
67 - (NSString *)rfc822Email {
68   NSString *_email;
69   unsigned idx;
70
71   _email = [self email];
72   idx    = NSMaxRange([_email rangeOfString:@":"]);
73
74   if ((idx > 0) && ([_email length] > idx))
75     return [_email substringFromIndex:idx];
76
77   return _email;
78 }
79
80 - (void)setRsvp:(NSString *)_s {
81   ASSIGNCOPY(self->rsvp, _s);
82 }
83 - (NSString *)rsvp {
84   return self->rsvp;
85 }
86
87 - (void)setXuid:(NSString *)_s {
88   ASSIGNCOPY(self->xuid, _s);
89 }
90 - (NSString *)xuid {
91   return self->xuid;
92 }
93
94 - (void)setRole:(NSString *)_s {
95   ASSIGNCOPY(self->role, _s);
96 }
97 - (NSString *)role {
98   return self->role;
99 }
100
101 - (void)setPartStat:(NSString *)_s {
102   ASSIGNCOPY(self->partStat, _s);
103 }
104 - (NSString *)partStat {
105   return self->partStat;
106 }
107
108 - (void)setParticipationStatus:(iCalPersonPartStat)_status {
109   NSString *stat;
110
111   switch (_status) {
112     case iCalPersonPartStatAccepted:
113       stat = @"ACCEPTED";
114       break;
115     case iCalPersonPartStatDeclined:
116       stat = @"DECLINED";
117       break;
118     case iCalPersonPartStatTentative:
119       stat = @"TENTATIVE";
120       break;
121     case iCalPersonPartStatDelegated:
122       stat = @"DELEGATED";
123       break;
124     case iCalPersonPartStatCompleted:
125       stat = @"COMPLETED";
126       break;
127     case iCalPersonPartStatInProcess:
128       stat = @"IN-PROCESS";
129       break;
130     case iCalPersonPartStatExperimental:
131     case iCalPersonPartStatOther:
132       [NSException raise:NSInternalInconsistencyException
133                    format:@"Attempt to set meaningless "
134                           @"participationStatus (%d)!", _status];
135       break;
136     default:
137       stat = @"NEEDS-ACTION";
138       break;
139   }
140   [self setPartStat:stat];
141 }
142
143 - (iCalPersonPartStat)participationStatus {
144   NSString *stat;
145   
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;
164 }
165
166
167 /* comparison */
168
169 - (unsigned)hash {
170   if([self email])
171     return [[self email] hash];
172   return [super hash];
173 }
174
175 - (BOOL)isEqual:(id)_other {
176   if(_other == nil)
177     return NO;
178   if([_other class] != self->isa)
179     return NO;
180   if([_other hash] != [self hash])
181     return NO;
182   return [self isEqualToPerson:_other];
183 }
184
185 - (BOOL)isEqualToPerson:(iCalPerson *)_other {
186   if(![self hasSameEmailAddress:_other])
187     return NO;
188   if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
189     return NO;
190   if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
191     return NO;
192   if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
193     return NO;
194   if(!IS_EQUAL([self role], [_other role], isEqualToString:))
195     return NO;
196   if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
197     return NO;
198   return YES;
199 }
200
201 - (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
202   return IS_EQUAL([self email], [_other email], isEqualToString:);
203 }
204
205 /* descriptions */
206
207 - (NSString *)description {
208   NSMutableString *ms;
209
210   ms = [NSMutableString stringWithCapacity:128];
211   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
212
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];
219
220   [ms appendString:@">"];
221   return ms;
222 }
223
224 @end /* iCalPerson */