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 */
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 <[email protected]>
19 */
20 
21 #include "attendee.h"
22 #include "person.h"
23 #include "person_p.h"
24 
25 #include <QDataStream>
26 
27 using namespace KCalendarCore;
28 
29 /**
30  Private class that helps to provide binary compatibility between releases.
31  @internal
32 */
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 
52 private:
53  QString sCuType;
54  CuType mCuType;
55 };
56 //@endcond
57 
58 void KCalendarCore::Attendee::Private::setCuType(Attendee::CuType cuType)
59 {
60  mCuType = cuType;
61  sCuType.clear();
62 }
63 
64 void 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 
83 Attendee::CuType KCalendarCore::Attendee::Private::cuType() const
84 {
85  return mCuType;
86 }
87 
88 QString KCalendarCore::Attendee::Private::cuTypeStr() const
89 {
90  switch (mCuType) {
92  return QStringLiteral("INDIVIDUAL");
93  case Attendee::Group:
94  return QStringLiteral("GROUP");
95  case Attendee::Resource:
96  return QStringLiteral("RESOURCE");
97  case Attendee::Room:
98  return QStringLiteral("ROOM");
99  case Attendee::Unknown:
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 
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 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 
162 QString Attendee::name() const
163 {
164  return d->mName;
165 }
166 
168 {
169  if (name.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
170  d->mName = name.mid(7);
171  } else {
172  d->mName = name;
173  }
174 }
175 
177 {
178  return fullNameHelper(d->mName, d->mEmail);
179 }
180 
181 QString Attendee::email() const
182 {
183  return d->mEmail;
184 }
185 
187 {
188  if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
189  d->mEmail = email.mid(7);
190  } else {
191  d->mEmail = email;
192  }
193 }
194 
195 void Attendee::setRSVP(bool r)
196 {
197  d->mRSVP = r;
198 }
199 
200 bool Attendee::RSVP() const
201 {
202  return d->mRSVP;
203 }
204 
206 {
207  d->mStatus = status;
208 }
209 
211 {
212  return d->mStatus;
213 }
214 
216 {
217  d->setCuType(cuType);
218 }
219 
220 void Attendee::setCuType(const QString &cuType)
221 {
222  d->setCuType(cuType);
223 }
224 
226 {
227  return d->cuType();
228 }
229 
231 {
232  return d->cuTypeStr();
233 }
234 
236 {
237  d->mRole = role;
238 }
239 
241 {
242  return d->mRole;
243 }
244 
246 {
247  d->mUid = uid;
248 }
249 
250 QString 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 
268 {
269  d->mDelegate = delegate;
270 }
271 
273 {
274  return d->mDelegate;
275 }
276 
278 {
279  d->mDelegator = delegator;
280 }
281 
283 {
284  return d->mDelegator;
285 }
286 
287 void 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;
315  QString uid;
318  QString cuType;
320  uint role_int;
321  uint status_int;
322 
323  KCalendarCore::Person person;
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 }
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:821
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:205
Otherwise not known.
Definition: attendee.h:97
Represents a person, by name and email address.
Definition: person.h:37
~Attendee()
Destroys the attendee.
Represents information related to an attendee of an Calendar Incidence, typically a meeting or task (...
Definition: attendee.h:44
CuType
The different types of a participant.
Definition: attendee.h:92
Attendee()
Create a null Attendee.
Definition: attendee.cpp:109
A group of individuals.
Definition: attendee.h:94
void setCustomProperty(const QByteArray &xname, const QString &xvalue)
Adds a custom property.
Definition: attendee.cpp:287
QString cuTypeStr() const
Returns the CuType of the attendee.
Definition: attendee.cpp:230
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:834
An individual (default)
Definition: attendee.h:93
Role role() const
Returns the Role of the attendee.
Attendee & operator=(const Attendee &attendee)
Sets this attendee equal to attendee.
Definition: attendee.cpp:151
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:79
QString number(int n, int base)
void setDelegator(const QString &delegator)
Sets the delegator.
Definition: attendee.cpp:277
QString fullName() const
Returns the full name and email address of this attendee.
PartStat
The different types of participant status.
Definition: attendee.h:64
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:195
bool isNull() const
Returns true if this is a default-constructed Attendee instance.
A room resource.
Definition: attendee.h:96
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:215
void setDelegate(const QString &delegate)
Sets the delegate.
Definition: attendee.cpp:267
void setUid(const QString &uid)
Sets the UID of the attendee to uid.
Definition: attendee.cpp:245
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
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:167
void setEmail(const QString &email)
Sets the email address for this attendee to email.
Definition: attendee.cpp:186
QString uid() const
Returns the UID of the attendee.
bool operator!=(const Attendee &attendee) const
Compares this with attendee for inequality.
Definition: attendee.cpp:146
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:95
CustomProperties & customProperties()
Returns a reference to the CustomProperties object.
Definition: attendee.cpp:292
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 Thu Apr 22 2021 22:51:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.