KCalendarCore

attendee.cpp
Go to the documentation of this file.
1/*
2 This file is part of the kcalcore library.
3
4 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
5 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
6 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10/**
11 @file
12 This file is part of the API for handling calendar data and
13 defines the Attendee class.
14
15 @brief
16 Represents information related to an attendee of an Calendar Incidence.
17
18 @author Cornelius Schumacher <schumacher@kde.org>
19*/
20
21#include "attendee.h"
22#include "person.h"
23#include "person_p.h"
24
25#include <QDataStream>
26
27using namespace KCalendarCore;
28
29/**
30 Private class that helps to provide binary compatibility between releases.
31 @internal
32*/
33//@cond PRIVATE
34class Q_DECL_HIDDEN KCalendarCore::Attendee::Private : public QSharedData
35{
36public:
37 void setCuType(CuType cuType);
38 void setCuType(const QString &cuType);
39 CuType cuType() const;
40 QString cuTypeStr() const;
41
42 bool mRSVP = false;
43 Role mRole = Attendee::ReqParticipant;
44 PartStat mStatus = Attendee::NeedsAction;
45 mutable QString mUid;
46 QString mDelegate;
47 QString mDelegator;
48 CustomProperties mCustomProperties;
49 QString mName;
50 QString mEmail;
51
52private:
53 QString sCuType;
54 CuType mCuType = Attendee::Individual;
55};
56//@endcond
57
58void KCalendarCore::Attendee::Private::setCuType(Attendee::CuType cuType)
59{
60 mCuType = cuType;
61 sCuType.clear();
62}
63
64void KCalendarCore::Attendee::Private::setCuType(const QString &cuType)
65{
66 const QString upper = cuType.toUpper();
67 if (upper == QLatin1String("INDIVIDUAL")) {
68 setCuType(Attendee::Individual);
69 } else if (upper == QLatin1String("GROUP")) {
70 setCuType(Attendee::Group);
71 } else if (upper == QLatin1String("RESOURCE")) {
72 setCuType(Attendee::Resource);
73 } else if (upper == QLatin1String("ROOM")) {
74 setCuType(Attendee::Room);
75 } else {
76 setCuType(Attendee::Unknown);
77 if (upper.startsWith(QLatin1String("X-")) || upper.startsWith(QLatin1String("IANA-"))) {
78 sCuType = upper;
79 }
80 }
81}
82
83Attendee::CuType KCalendarCore::Attendee::Private::cuType() const
84{
85 return mCuType;
86}
87
88QString KCalendarCore::Attendee::Private::cuTypeStr() const
89{
90 switch (mCuType) {
92 return QStringLiteral("INDIVIDUAL");
93 case Attendee::Group:
94 return QStringLiteral("GROUP");
96 return QStringLiteral("RESOURCE");
97 case Attendee::Room:
98 return QStringLiteral("ROOM");
100 if (sCuType.isEmpty()) {
101 return QStringLiteral("UNKNOWN");
102 } else {
103 return sCuType;
104 }
105 }
106 return QStringLiteral("UNKNOWN");
107}
108
110 : d(new Attendee::Private)
111{
112}
113
114Attendee::Attendee(const QString &name, const QString &email, bool rsvp, Attendee::PartStat status, Attendee::Role role, const QString &uid)
115 : d(new Attendee::Private)
116{
117 setName(name);
118 setEmail(email);
119 d->mRSVP = rsvp;
120 d->mStatus = status;
121 d->mRole = role;
122 d->mUid = uid;
123 d->setCuType(Attendee::Individual);
124}
125
127 : d(attendee.d)
128{
129}
130
131Attendee::~Attendee() = default;
132
133bool Attendee::isNull() const
134{
135 // isNull rather than isEmpty, as user code is actually creating empty but non-null attendees...
136 return d->mName.isNull() && d->mEmail.isNull();
137}
138
140{
141 return d->mUid == attendee.d->mUid && d->mRSVP == attendee.d->mRSVP && d->mRole == attendee.d->mRole && d->mStatus == attendee.d->mStatus
142 && d->mDelegate == attendee.d->mDelegate && d->mDelegator == attendee.d->mDelegator && d->cuTypeStr() == attendee.d->cuTypeStr()
143 && d->mName == attendee.d->mName && d->mEmail == attendee.d->mEmail;
144}
145
147{
148 return !operator==(attendee);
149}
150
152{
153 // check for self assignment
154 if (&attendee == this) {
155 return *this;
156 }
157
158 d = attendee.d;
159 return *this;
160}
161
162QString Attendee::name() const
163{
164 return d->mName;
165}
166
167void Attendee::setName(const QString &name)
168{
169 if (name.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
170 d->mName = name.mid(7);
171 } else {
172 d->mName = name;
173 }
174}
175
176QString Attendee::fullName() const
177{
178 return fullNameHelper(d->mName, d->mEmail);
179}
180
181QString Attendee::email() const
182{
183 return d->mEmail;
184}
185
186void Attendee::setEmail(const QString &email)
187{
188 if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
189 d->mEmail = email.mid(7);
190 } else {
191 d->mEmail = email;
192 }
193}
194
196{
197 d->mRSVP = r;
198}
199
200bool Attendee::RSVP() const
201{
202 return d->mRSVP;
203}
204
206{
207 d->mStatus = status;
208}
209
210Attendee::PartStat Attendee::status() const
211{
212 return d->mStatus;
213}
214
216{
217 d->setCuType(cuType);
218}
219
220void Attendee::setCuType(const QString &cuType)
221{
222 d->setCuType(cuType);
223}
224
225Attendee::CuType Attendee::cuType() const
226{
227 return d->cuType();
228}
229
231{
232 return d->cuTypeStr();
233}
234
236{
237 d->mRole = role;
238}
239
240Attendee::Role Attendee::role() const
241{
242 return d->mRole;
243}
244
245void Attendee::setUid(const QString &uid)
246{
247 d->mUid = uid;
248}
249
250QString Attendee::uid() const
251{
252 /* If Uid is empty, just use the pointer to Attendee (encoded to
253 * string) as Uid. Only thing that matters is that the Uid is unique
254 * insofar IncidenceBase is concerned, and this does that (albeit
255 * not very nicely). If these are ever saved to disk, should use
256 * (considerably more expensive) CalFormat::createUniqueId(). As Uid
257 * is not part of Attendee in iCal std, it's fairly safe bet that
258 * these will never hit disc though so faster generation speed is
259 * more important than actually being forever unique.*/
260 if (d->mUid.isEmpty()) {
261 d->mUid = QString::number((qlonglong)d.constData());
262 }
263
264 return d->mUid;
265}
266
267void Attendee::setDelegate(const QString &delegate)
268{
269 d->mDelegate = delegate;
270}
271
272QString Attendee::delegate() const
273{
274 return d->mDelegate;
275}
276
277void Attendee::setDelegator(const QString &delegator)
278{
279 d->mDelegator = delegator;
280}
281
282QString Attendee::delegator() const
283{
284 return d->mDelegator;
285}
286
287void Attendee::setCustomProperty(const QByteArray &xname, const QString &xvalue)
288{
289 d->mCustomProperties.setNonKDECustomProperty(xname, xvalue);
290}
291
293{
294 return d->mCustomProperties;
295}
296
298{
299 return d->mCustomProperties;
300}
301
303{
304 KCalendarCore::Person p(attendee.name(), attendee.email());
305 stream << p;
306 return stream << attendee.d->mRSVP << int(attendee.d->mRole) << int(attendee.d->mStatus) << attendee.d->mUid << attendee.d->mDelegate
307 << attendee.d->mDelegator << attendee.d->cuTypeStr() << attendee.d->mCustomProperties;
308}
309
311{
312 bool RSVP;
313 Attendee::Role role;
315 QString uid;
316 QString delegate;
317 QString delegator;
318 QString cuType;
319 CustomProperties customProperties;
320 uint role_int;
321 uint status_int;
322
324 stream >> person;
325 stream >> RSVP >> role_int >> status_int >> uid >> delegate >> delegator >> cuType >> customProperties;
326
327 role = Attendee::Role(role_int);
328 status = Attendee::PartStat(status_int);
329
330 attendee = Attendee(person.name(), person.email(), RSVP, status, role, uid);
331 attendee.setDelegate(delegate);
332 attendee.setDelegator(delegator);
333 attendee.setCuType(cuType);
334 attendee.d->mCustomProperties = customProperties;
335 return stream;
336}
337
338#include "moc_attendee.cpp"
This file is part of the API for handling calendar data and defines the Attendee class.
Represents information related to an attendee of an Calendar Incidence, typically a meeting or task (...
Definition attendee.h:45
CustomProperties & customProperties()
Returns a reference to the CustomProperties object.
Definition attendee.cpp:292
void setStatus(PartStat status)
Sets the PartStat of the attendee to status.
Definition attendee.cpp:205
Role
The different types of participation roles.
Definition attendee.h:79
@ ReqParticipant
Participation is required (default)
Definition attendee.h:80
void setDelegator(const QString &delegator)
Sets the delegator.
Definition attendee.cpp:277
void setUid(const QString &uid)
Sets the UID of the attendee to uid.
Definition attendee.cpp:245
bool operator!=(const Attendee &attendee) const
Compares this with attendee for inequality.
Definition attendee.cpp:146
void setName(const QString &name)
Sets the name of the attendee to name.
Definition attendee.cpp:167
bool RSVP() const
Returns the attendee RSVP flag.
Definition attendee.cpp:200
void setRole(Role role)
Sets the Role of the attendee to role.
Definition attendee.cpp:235
void setCuType(CuType cuType)
Sets the CuType of the attendee to cuType.
Definition attendee.cpp:215
PartStat
The different types of participant status.
Definition attendee.h:64
@ NeedsAction
Event, to-do or journal needs action (default)
Definition attendee.h:65
QString cuTypeStr() const
Returns the CuType of the attendee.
Definition attendee.cpp:230
CuType
The different types of a participant.
Definition attendee.h:92
@ Resource
A physical resource.
Definition attendee.h:95
@ Group
A group of individuals.
Definition attendee.h:94
@ Unknown
Otherwise not known.
Definition attendee.h:97
@ Individual
An individual (default)
Definition attendee.h:93
@ Room
A room resource.
Definition attendee.h:96
void setEmail(const QString &email)
Sets the email address for this attendee to email.
Definition attendee.cpp:186
void setDelegate(const QString &delegate)
Sets the delegate.
Definition attendee.cpp:267
void setRSVP(bool rsvp)
Sets the RSVP flag of the attendee to rsvp.
Definition attendee.cpp:195
~Attendee()
Destroys the attendee.
Attendee()
Create a null Attendee.
Definition attendee.cpp:109
void setCustomProperty(const QByteArray &xname, const QString &xvalue)
Adds a custom property.
Definition attendee.cpp:287
Attendee & operator=(const Attendee &attendee)
Sets this attendee equal to attendee.
Definition attendee.cpp:151
bool operator==(const Attendee &attendee) const
Compares this with attendee for equality.
Definition attendee.cpp:139
A class to manage custom calendar properties.
Represents a person, by name and email address.
Definition person.h:38
Q_SCRIPTABLE CaptureState status()
Namespace for all KCalendarCore types.
Definition alarm.h:37
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition alarm.cpp:833
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition alarm.cpp:820
This file is part of the API for handling calendar data and defines the Person class.
void clear()
QString mid(qsizetype position, qsizetype n) const const
QString number(double n, char format, int precision)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString toUpper() const const
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:59:07 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.