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 <[email protected]>
5  SPDX-FileCopyrightText: 2010 Casey Link <[email protected]>
6  SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
21 #include "attendee.h"
22 #include "person.h"
23 #include "person_p.h"
24 
25 #include <QDataStream>
26 
27 using namespace KCalendarCore;
28 
33 //@cond PRIVATE
34 class Q_DECL_HIDDEN KCalendarCore::Attendee::Private : public QSharedData
35 {
36 public:
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;
44  PartStat mStatus;
45  mutable QString mUid;
46  QString mDelegate;
47  QString mDelegator;
48  CustomProperties mCustomProperties;
49  QString mName;
50  QString mEmail;
51 private:
52  QString sCuType;
53  CuType mCuType;
54 };
55 //@endcond
56 
57 void KCalendarCore::Attendee::Private::setCuType(Attendee::CuType cuType)
58 {
59  mCuType = cuType;
60  sCuType.clear();
61 }
62 
63 void KCalendarCore::Attendee::Private::setCuType(const QString &cuType)
64 {
65  const QString upper = cuType.toUpper();
66  if (upper == QLatin1String("INDIVIDUAL")) {
67  setCuType(Attendee::Individual);
68  } else if (upper == QLatin1String("GROUP")) {
69  setCuType(Attendee::Group);
70  } else if (upper == QLatin1String("RESOURCE")) {
71  setCuType(Attendee::Resource);
72  } else if (upper == QLatin1String("ROOM")) {
73  setCuType(Attendee::Room);
74  } else {
75  setCuType(Attendee::Unknown);
76  if (upper.startsWith(QLatin1String("X-")) || upper.startsWith(QLatin1String("IANA-"))) {
77  sCuType = upper;
78  }
79  }
80 }
81 
82 Attendee::CuType KCalendarCore::Attendee::Private::cuType() const
83 {
84  return mCuType;
85 }
86 
87 QString KCalendarCore::Attendee::Private::cuTypeStr() const
88 {
89  switch (mCuType) {
91  return QStringLiteral("INDIVIDUAL");
92  case Attendee::Group:
93  return QStringLiteral("GROUP");
94  case Attendee::Resource:
95  return QStringLiteral("RESOURCE");
96  case Attendee::Room:
97  return QStringLiteral("ROOM");
98  case Attendee::Unknown:
99  if (sCuType.isEmpty()) {
100  return QStringLiteral("UNKNOWN");
101  } else {
102  return sCuType;
103  }
104  }
105  return QStringLiteral("UNKNOWN");
106 }
107 
109  : d(new Attendee::Private)
110 {
111 }
112 
113 Attendee::Attendee(const QString &name, const QString &email, bool rsvp,
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 
126 Attendee::Attendee(const Attendee &attendee)
127  : d(attendee.d)
128 {
129 }
130 
131 Attendee::~Attendee() = default;
132 
133 bool 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
142  d->mUid == attendee.d->mUid &&
143  d->mRSVP == attendee.d->mRSVP &&
144  d->mRole == attendee.d->mRole &&
145  d->mStatus == attendee.d->mStatus &&
146  d->mDelegate == attendee.d->mDelegate &&
147  d->mDelegator == attendee.d->mDelegator &&
148  d->cuTypeStr() == attendee.d->cuTypeStr() &&
149  d->mName == attendee.d->mName &&
150  d->mEmail == attendee.d->mEmail;
151 }
152 
154 {
155  return !operator==(attendee);
156 }
157 
159 {
160  // check for self assignment
161  if (&attendee == this) {
162  return *this;
163  }
164 
165  d = attendee.d;
166  return *this;
167 }
168 
169 QString Attendee::name() const
170 {
171  return d->mName;
172 }
173 
175 {
176  if (name.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
177  d->mName = name.mid(7);
178  } else {
179  d->mName = name;
180  }
181 }
182 
184 {
185  return fullNameHelper(d->mName, d->mEmail);
186 }
187 
188 QString Attendee::email() const
189 {
190  return d->mEmail;
191 }
192 
194 {
195  if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
196  d->mEmail = email.mid(7);
197  } else {
198  d->mEmail = email;
199  }
200 }
201 
202 void Attendee::setRSVP(bool r)
203 {
204  d->mRSVP = r;
205 }
206 
207 bool Attendee::RSVP() const
208 {
209  return d->mRSVP;
210 }
211 
213 {
214  d->mStatus = status;
215 }
216 
218 {
219  return d->mStatus;
220 }
221 
223 {
224  d->setCuType(cuType);
225 }
226 
227 void Attendee::setCuType(const QString &cuType)
228 {
229  d->setCuType(cuType);
230 }
231 
233 {
234  return d->cuType();
235 }
236 
238 {
239  return d->cuTypeStr();
240 }
241 
243 {
244  d->mRole = role;
245 }
246 
248 {
249  return d->mRole;
250 }
251 
253 {
254  d->mUid = uid;
255 }
256 
257 QString Attendee::uid() const
258 {
259  /* If Uid is empty, just use the pointer to Attendee (encoded to
260  * string) as Uid. Only thing that matters is that the Uid is unique
261  * insofar IncidenceBase is concerned, and this does that (albeit
262  * not very nicely). If these are ever saved to disk, should use
263  * (considerably more expensive) CalFormat::createUniqueId(). As Uid
264  * is not part of Attendee in iCal std, it's fairly safe bet that
265  * these will never hit disc though so faster generation speed is
266  * more important than actually being forever unique.*/
267  if (d->mUid.isEmpty()) {
268  d->mUid = QString::number((qlonglong)d.constData());
269  }
270 
271  return d->mUid;
272 }
273 
275 {
276  d->mDelegate = delegate;
277 }
278 
280 {
281  return d->mDelegate;
282 }
283 
285 {
286  d->mDelegator = delegator;
287 }
288 
290 {
291  return d->mDelegator;
292 }
293 
294 void Attendee::setCustomProperty(const QByteArray &xname, const QString &xvalue)
295 {
296  d->mCustomProperties.setNonKDECustomProperty(xname, xvalue);
297 }
298 
300 {
301  return d->mCustomProperties;
302 }
303 
305 {
306  return d->mCustomProperties;
307 }
308 
310 {
311  KCalendarCore::Person p(attendee.name(), attendee.email());
312  stream << p;
313  return stream << attendee.d->mRSVP
314  << int(attendee.d->mRole)
315  << int(attendee.d->mStatus)
316  << attendee.d->mUid
317  << attendee.d->mDelegate
318  << attendee.d->mDelegator
319  << attendee.d->cuTypeStr()
320  << attendee.d->mCustomProperties;
321 }
322 
324 {
325  bool RSVP;
328  QString uid;
331  QString cuType;
333  uint role_int;
334  uint status_int;
335 
336  KCalendarCore::Person person;
337  stream >> person;
338  stream >> RSVP
339  >> role_int
340  >> status_int
341  >> uid
342  >> delegate
343  >> delegator
344  >> cuType
345  >> customProperties;
346 
347  role = Attendee::Role(role_int);
348  status = Attendee::PartStat(status_int);
349 
350  attendee = Attendee(person.name(), person.email(), RSVP, status, role, uid);
351  attendee.setDelegate(delegate);
352  attendee.setDelegator(delegator);
353  attendee.setCuType(cuType);
354  attendee.d->mCustomProperties = customProperties;
355  return stream;
356 }
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:825
This file is part of the API for handling calendar data and defines the Attendee class.
QString toUpper() const const
A class to manage custom calendar properties.
QString delegator() const
Returns the delegator.
void setStatus(PartStat status)
Sets the PartStat of the attendee to status.
Definition: attendee.cpp:212
Otherwise not known.
Definition: attendee.h:98
Represents a person, by name and email address.
Definition: person.h:38
~Attendee()
Destroys the attendee.
Represents information related to an attendee of an Calendar Incidence, typically a meeting or task (...
Definition: attendee.h:45
CuType
The different types of a participant.
Definition: attendee.h:93
Attendee()
Create a null Attendee.
Definition: attendee.cpp:108
A group of individuals.
Definition: attendee.h:95
void setCustomProperty(const QByteArray &xname, const QString &xvalue)
Adds a custom property.
Definition: attendee.cpp:294
QString cuTypeStr() const
Returns the CuType of the attendee.
Definition: attendee.cpp:237
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:849
An individual (default)
Definition: attendee.h:94
Role role() const
Returns the Role of the attendee.
Attendee & operator=(const Attendee &attendee)
Sets this attendee equal to attendee.
Definition: attendee.cpp:158
void clear()
This file is part of the API for handling calendar data and defines the Person class.
Role
The different types of participation roles.
Definition: attendee.h:80
QString number(int n, int base)
void setDelegator(const QString &delegator)
Sets the delegator.
Definition: attendee.cpp:284
QString fullName() const
Returns the full name and email address of this attendee.
PartStat
The different types of participant status.
Definition: attendee.h:65
CaseInsensitive
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
void setRSVP(bool rsvp)
Sets the RSVP flag of the attendee to rsvp.
Definition: attendee.cpp:202
bool isNull() const
Returns true if this is a default-constructed Attendee instance.
A room resource.
Definition: attendee.h:97
QString email() const
Returns the email address for this attendee.
void setCuType(CuType cuType)
Sets the CuType of the attendee to cuType.
Definition: attendee.cpp:222
void setDelegate(const QString &delegate)
Sets the delegate.
Definition: attendee.cpp:274
void setUid(const QString &uid)
Sets the UID of the attendee to uid.
Definition: attendee.cpp:252
bool RSVP() const
Returns the attendee RSVP flag.
Definition: attendee.cpp:207
void setRole(Role role)
Sets the Role of the attendee to role.
Definition: attendee.cpp:242
CuType cuType() const
Returns the CuType of the attendee.
void setName(const QString &name)
Sets the name of the attendee to name.
Definition: attendee.cpp:174
void setEmail(const QString &email)
Sets the email address for this attendee to email.
Definition: attendee.cpp:193
QString uid() const
Returns the UID of the attendee.
bool operator!=(const Attendee &attendee) const
Compares this with attendee for inequality.
Definition: attendee.cpp:153
QString mid(int position, int n) const const
QString delegate() const
Returns the delegate.
PartStat status() const
Returns the PartStat of the attendee.
A physical resource.
Definition: attendee.h:96
CustomProperties & customProperties()
Returns a reference to the CustomProperties object.
Definition: attendee.cpp:299
QString name() const
Returns the name of the attendee.
bool operator==(const Attendee &attendee) const
Compares this with attendee for equality.
Definition: attendee.cpp:139
Namespace for all KCalendarCore types.
Definition: alarm.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 27 2021 22:50:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.