1 | /* |
2 | This file is part of the kcalcore library. |
3 | |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com> |
6 | Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | */ |
23 | /** |
24 | @file |
25 | This file is part of the API for handling calendar data and |
26 | defines the Attendee class. |
27 | |
28 | @brief |
29 | Represents information related to an attendee of an Calendar Incidence. |
30 | |
31 | @author Cornelius Schumacher \<schumacher@kde.org\> |
32 | */ |
33 | |
34 | #include "attendee.h" |
35 | |
36 | #include <QDataStream> |
37 | |
38 | using namespace KCalCore; |
39 | |
40 | /** |
41 | Private class that helps to provide binary compatibility between releases. |
42 | @internal |
43 | */ |
44 | //@cond PRIVATE |
45 | class KCalCore::Attendee::Private |
46 | { |
47 | public: |
48 | void setCuType(CuType cuType); |
49 | void setCuType(const QString &cuType); |
50 | CuType cuType() const; |
51 | QString cuTypeStr() const; |
52 | |
53 | bool mRSVP; |
54 | Role mRole; |
55 | PartStat mStatus; |
56 | QString mUid; |
57 | QString mDelegate; |
58 | QString mDelegator; |
59 | CustomProperties mCustomProperties; |
60 | private: |
61 | QString sCuType; |
62 | CuType mCuType; |
63 | }; |
64 | //@endcond |
65 | |
66 | void KCalCore::Attendee::Private::setCuType(Attendee::CuType cuType) |
67 | { |
68 | mCuType = cuType; |
69 | sCuType.clear(); |
70 | } |
71 | |
72 | void KCalCore::Attendee::Private::setCuType(const QString &cuType) |
73 | { |
74 | const QString upper = cuType.toUpper(); |
75 | if (upper == QLatin1String("INDIVIDUAL" )) { |
76 | setCuType(Attendee::Individual); |
77 | } else if (upper == QLatin1String("GROUP" )) { |
78 | setCuType(Attendee::Group); |
79 | } else if (upper == QLatin1String("RESOURCE" )) { |
80 | setCuType(Attendee::Resource); |
81 | } else if (upper == QLatin1String("ROOM" )) { |
82 | setCuType(Attendee::Room); |
83 | } else { |
84 | setCuType(Attendee::Unknown); |
85 | if (upper.startsWith(QLatin1String("X-" )) || upper.startsWith(QLatin1String("IANA-" ))) { |
86 | sCuType = upper; |
87 | } |
88 | } |
89 | } |
90 | |
91 | Attendee::CuType KCalCore::Attendee::Private::cuType() const |
92 | { |
93 | return mCuType; |
94 | } |
95 | |
96 | QString KCalCore::Attendee::Private::cuTypeStr() const |
97 | { |
98 | switch (mCuType) { |
99 | case Attendee::Individual: |
100 | return QLatin1String("INDIVIDUAL" ); |
101 | case Attendee::Group: |
102 | return QLatin1String("GROUP" ); |
103 | case Attendee::Resource: |
104 | return QLatin1String("RESOURCE" ); |
105 | case Attendee::Room: |
106 | return QLatin1String("ROOM" ); |
107 | case Attendee::Unknown: |
108 | if (sCuType.isEmpty()) { |
109 | return QLatin1String("UNKNOWN" ); |
110 | } else { |
111 | return sCuType; |
112 | } |
113 | } |
114 | return QLatin1String("UNKNOWN" ); |
115 | } |
116 | |
117 | |
118 | |
119 | Attendee::Attendee(const QString &name, const QString &email, bool rsvp, |
120 | Attendee::PartStat status, Attendee::Role role, const QString &uid) |
121 | : d(new Attendee::Private) |
122 | { |
123 | setName(name); |
124 | setEmail(email); |
125 | d->mRSVP = rsvp; |
126 | d->mStatus = status; |
127 | d->mRole = role; |
128 | d->mUid = uid; |
129 | d->setCuType(Attendee::Individual); |
130 | } |
131 | |
132 | Attendee::Attendee(const Attendee &attendee) |
133 | : Person(attendee), |
134 | d(new Attendee::Private(*attendee.d)) |
135 | { |
136 | } |
137 | |
138 | Attendee::~Attendee() |
139 | { |
140 | delete d; |
141 | } |
142 | |
143 | bool KCalCore::Attendee::operator==(const Attendee &attendee) const |
144 | { |
145 | return |
146 | d->mUid == attendee.d->mUid && |
147 | d->mRSVP == attendee.d->mRSVP && |
148 | d->mRole == attendee.d->mRole && |
149 | d->mStatus == attendee.d->mStatus && |
150 | d->mDelegate == attendee.d->mDelegate && |
151 | d->mDelegator == attendee.d->mDelegator && |
152 | d->cuTypeStr() == attendee.d->cuTypeStr() && |
153 | (const Person &)*this == (const Person &)attendee; |
154 | } |
155 | |
156 | bool KCalCore::Attendee::operator!=(const Attendee &attendee) const |
157 | { |
158 | return !operator==(attendee); |
159 | } |
160 | |
161 | Attendee &KCalCore::Attendee::operator=(const Attendee &attendee) |
162 | { |
163 | // check for self assignment |
164 | if (&attendee == this) { |
165 | return *this; |
166 | } |
167 | |
168 | *d = *attendee.d; |
169 | setName(attendee.name()); |
170 | setEmail(attendee.email()); |
171 | return *this; |
172 | } |
173 | |
174 | void Attendee::setRSVP(bool r) |
175 | { |
176 | d->mRSVP = r; |
177 | } |
178 | |
179 | bool Attendee::RSVP() const |
180 | { |
181 | return d->mRSVP; |
182 | } |
183 | |
184 | void Attendee::setStatus(Attendee::PartStat status) |
185 | { |
186 | d->mStatus = status; |
187 | } |
188 | |
189 | Attendee::PartStat Attendee::status() const |
190 | { |
191 | return d->mStatus; |
192 | } |
193 | |
194 | void Attendee::setCuType(Attendee::CuType cuType) |
195 | { |
196 | d->setCuType(cuType); |
197 | } |
198 | |
199 | void Attendee::setCuType(const QString &cuType) |
200 | { |
201 | d->setCuType(cuType); |
202 | } |
203 | |
204 | Attendee::CuType Attendee::cuType() const |
205 | { |
206 | return d->cuType(); |
207 | } |
208 | |
209 | QString Attendee::cuTypeStr() const |
210 | { |
211 | return d->cuTypeStr(); |
212 | } |
213 | |
214 | void Attendee::setRole(Attendee::Role role) |
215 | { |
216 | d->mRole = role; |
217 | } |
218 | |
219 | Attendee::Role Attendee::role() const |
220 | { |
221 | return d->mRole; |
222 | } |
223 | |
224 | void Attendee::setUid(const QString &uid) |
225 | { |
226 | d->mUid = uid; |
227 | } |
228 | |
229 | QString Attendee::uid() const |
230 | { |
231 | return d->mUid; |
232 | } |
233 | |
234 | void Attendee::setDelegate(const QString &delegate) |
235 | { |
236 | d->mDelegate = delegate; |
237 | } |
238 | |
239 | QString Attendee::delegate() const |
240 | { |
241 | return d->mDelegate; |
242 | } |
243 | |
244 | void Attendee::setDelegator(const QString &delegator) |
245 | { |
246 | d->mDelegator = delegator; |
247 | } |
248 | |
249 | QString Attendee::delegator() const |
250 | { |
251 | return d->mDelegator; |
252 | } |
253 | |
254 | void Attendee::setCustomProperty(const QByteArray &xname, const QString &xvalue) |
255 | { |
256 | d->mCustomProperties.setNonKDECustomProperty(xname, xvalue); |
257 | } |
258 | |
259 | CustomProperties &Attendee::customProperties() |
260 | { |
261 | return d->mCustomProperties; |
262 | } |
263 | |
264 | const CustomProperties &Attendee::customProperties() const |
265 | { |
266 | return d->mCustomProperties; |
267 | } |
268 | |
269 | QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Attendee::Ptr &attendee) |
270 | { |
271 | KCalCore::Person::Ptr p(new KCalCore::Person(*((Person *)attendee.data()))); |
272 | stream << p; |
273 | return stream << attendee->d->mRSVP |
274 | << int(attendee->d->mRole) |
275 | << int(attendee->d->mStatus) |
276 | << attendee->d->mUid |
277 | << attendee->d->mDelegate |
278 | << attendee->d->mDelegator |
279 | << attendee->d->cuTypeStr() |
280 | << attendee->d->mCustomProperties; |
281 | } |
282 | |
283 | QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &attendee) |
284 | { |
285 | bool RSVP; |
286 | Attendee::Role role; |
287 | Attendee::PartStat status; |
288 | QString uid; |
289 | QString delegate; |
290 | QString delegator; |
291 | QString cuType; |
292 | CustomProperties customProperties; |
293 | uint role_int; |
294 | uint status_int; |
295 | |
296 | KCalCore::Person::Ptr person(new Person()); |
297 | stream >> person; |
298 | stream >> RSVP |
299 | >> role_int |
300 | >> status_int |
301 | >> uid |
302 | >> delegate |
303 | >> delegator |
304 | >> cuType |
305 | >> customProperties; |
306 | |
307 | role = Attendee::Role(role_int); |
308 | status = Attendee::PartStat(status_int); |
309 | |
310 | Attendee::Ptr att_temp(new KCalCore::Attendee(person->name(), person->email(), |
311 | RSVP, status, role, uid)); |
312 | att_temp->setDelegate(delegate); |
313 | att_temp->setDelegator(delegator); |
314 | att_temp->setCuType(cuType); |
315 | att_temp->d->mCustomProperties = customProperties; |
316 | attendee.swap(att_temp); |
317 | return stream; |
318 | } |
319 | |