KContacts

contactgroup.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2008 Tobias Koenig <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "contactgroup.h"
9 
10 #include <QMap>
11 #include <QSharedData>
12 #include <QString>
13 #include <QUuid>
14 
15 using namespace KContacts;
16 
17 class Q_DECL_HIDDEN ContactGroup::ContactReference::ContactReferencePrivate : public QSharedData
18 {
19 public:
20  ContactReferencePrivate()
21  : QSharedData()
22  {
23  }
24 
25  ContactReferencePrivate(const ContactReferencePrivate &other)
26  : QSharedData(other)
27  {
28  mUid = other.mUid;
29  mPreferredEmail = other.mPreferredEmail;
30  mCustoms = other.mCustoms;
31  }
32 
33  QString mUid;
34  QString mGid;
35  QString mPreferredEmail;
36  QMap<QString, QString> mCustoms;
37 };
38 
40  : d(new ContactReferencePrivate)
41 {
42 }
43 
45  : d(other.d)
46 {
47 }
48 
50  : d(new ContactReferencePrivate)
51 {
52  d->mUid = uid;
53 }
54 
56 {
57 }
58 
60 {
61  d->mUid = uid;
62 }
63 
65 {
66  return d->mUid;
67 }
68 
70 {
71  d->mGid = gid;
72 }
73 
75 {
76  return d->mGid;
77 }
78 
80 {
81  d->mPreferredEmail = email;
82 }
83 
85 {
86  return d->mPreferredEmail;
87 }
88 
90 {
91  d->mCustoms.insert(key, value);
92 }
93 
95 {
96  d->mCustoms.remove(key);
97 }
98 
100 {
101  return d->mCustoms.value(key);
102 }
103 
105  const ContactGroup::ContactReference &other)
106 {
107  if (this != &other) {
108  d = other.d;
109  }
110 
111  return *this;
112 }
113 
115 {
116  return d->mUid == other.d->mUid
117  && d->mPreferredEmail == other.d->mPreferredEmail
118  && d->mCustoms == other.d->mCustoms;
119 }
120 
121 class Q_DECL_HIDDEN ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData
122 {
123 public:
124  ContactGroupReferencePrivate()
125  : QSharedData()
126  {
127  }
128 
129  ContactGroupReferencePrivate(const ContactGroupReferencePrivate &other)
130  : QSharedData(other)
131  {
132  mUid = other.mUid;
133  mCustoms = other.mCustoms;
134  }
135 
136  QString mUid;
137  QMap<QString, QString> mCustoms;
138 };
139 
141  : d(new ContactGroupReferencePrivate)
142 {
143 }
144 
146  : d(other.d)
147 {
148 }
149 
151  : d(new ContactGroupReferencePrivate)
152 {
153  d->mUid = uid;
154 }
155 
157 {
158 }
159 
161 {
162  d->mUid = uid;
163 }
164 
166 {
167  return d->mUid;
168 }
169 
171 {
172  d->mCustoms.insert(key, value);
173 }
174 
176 {
177  d->mCustoms.remove(key);
178 }
179 
181 {
182  return d->mCustoms.value(key);
183 }
184 
187 {
188  if (this != &other) {
189  d = other.d;
190  }
191 
192  return *this;
193 }
194 
196 {
197  return d->mUid == other.d->mUid
198  && d->mCustoms == other.d->mCustoms;
199 }
200 
201 class Q_DECL_HIDDEN ContactGroup::Data::DataPrivate : public QSharedData
202 {
203 public:
204  DataPrivate()
205  : QSharedData()
206  {
207  }
208 
209  DataPrivate(const DataPrivate &other)
210  : QSharedData(other)
211  {
212  mName = other.mName;
213  mEmail = other.mEmail;
214  mCustoms = other.mCustoms;
215  }
216 
217  QString mName;
218  QString mEmail;
219  QMap<QString, QString> mCustoms;
220 };
221 
223  : d(new DataPrivate)
224 {
225 }
226 
228  : d(other.d)
229 {
230 }
231 
233  : d(new DataPrivate)
234 {
235  d->mName = name;
236  d->mEmail = email;
237 }
238 
240 {
241 }
242 
244 {
245  d->mName = name;
246 }
247 
249 {
250  return d->mName;
251 }
252 
254 {
255  d->mEmail = email;
256 }
257 
259 {
260  return d->mEmail;
261 }
262 
263 void ContactGroup::Data::insertCustom(const QString &key, const QString &value)
264 {
265  d->mCustoms.insert(key, value);
266 }
267 
269 {
270  d->mCustoms.remove(key);
271 }
272 
274 {
275  return d->mCustoms.value(key);
276 }
277 
279 {
280  if (this != &other) {
281  d = other.d;
282  }
283 
284  return *this;
285 }
286 
287 bool ContactGroup::Data::operator==(const Data &other) const
288 {
289  return d->mName == other.d->mName
290  && d->mEmail == other.d->mEmail
291  && d->mCustoms == other.d->mCustoms;
292 }
293 
294 class Q_DECL_HIDDEN ContactGroup::Private : public QSharedData
295 {
296 public:
297  Private()
298  : QSharedData()
299  , mIdentifier(QUuid::createUuid().toString().mid(1, 36)) //We avoid the curly braces so the string is RFC4122 compliant and can be used as urn
300  {
301  }
302 
303  Private(const Private &other)
304  : QSharedData(other)
305  {
306  mIdentifier = other.mIdentifier;
307  mName = other.mName;
308  mContactReferences = other.mContactReferences;
309  mContactGroupReferences = other.mContactGroupReferences;
310  mDataObjects = other.mDataObjects;
311  }
312 
313  QString mIdentifier;
314  QString mName;
315  ContactGroup::ContactReference::List mContactReferences;
316  ContactGroup::ContactGroupReference::List mContactGroupReferences;
317  ContactGroup::Data::List mDataObjects;
318 };
319 
321  : d(new Private)
322 {
323 }
324 
325 ContactGroup::ContactGroup(const ContactGroup &other)
326  : d(other.d)
327 {
328 }
329 
331  : d(new Private)
332 {
333  d->mName = name;
334 }
335 
337 {
338 }
339 
341 {
342  d->mName = name;
343 }
344 
346 {
347  return d->mName;
348 }
349 
351 {
352  d->mIdentifier = id;
353 }
354 
356 {
357  return d->mIdentifier;
358 }
359 
361 {
362  return d->mContactReferences.count() + d->mDataObjects.count();
363 }
364 
366 {
367  return d->mContactReferences.count();
368 }
369 
371 {
372  return d->mContactGroupReferences.count();
373 }
374 
376 {
377  return d->mDataObjects.count();
378 }
379 
381 {
382  Q_ASSERT_X(index < d->mContactReferences.count(),
383  "contactReference()", "index out of range");
384 
385  return d->mContactReferences[index];
386 }
387 
389 {
390  Q_ASSERT_X(index < d->mContactReferences.count(),
391  "contactReference()", "index out of range");
392 
393  return d->mContactReferences[index];
394 }
395 
397 {
398  Q_ASSERT_X(index < d->mContactGroupReferences.count(),
399  "contactGroupReference()", "index out of range");
400 
401  return d->mContactGroupReferences[index];
402 }
403 
405  int index) const
406 {
407  Q_ASSERT_X(index < d->mContactGroupReferences.count(),
408  "contactGroupReference()", "index out of range");
409 
410  return d->mContactGroupReferences[index];
411 }
412 
414 {
415  Q_ASSERT_X(index < d->mDataObjects.count(), "data()", "index out of range");
416 
417  return d->mDataObjects[index];
418 }
419 
420 const ContactGroup::Data &ContactGroup::data(int index) const
421 {
422  Q_ASSERT_X(index < d->mDataObjects.count(), "data()", "index out of range");
423 
424  return d->mDataObjects[index];
425 }
426 
428 {
429  d->mContactReferences.append(reference);
430 }
431 
433 {
434  d->mContactGroupReferences.append(reference);
435 }
436 
438 {
439  d->mDataObjects.append(data);
440 }
441 
443 {
444  d->mContactReferences.removeOne(reference);
445 }
446 
448 {
449  d->mContactGroupReferences.removeOne(reference);
450 }
451 
453 {
454  d->mDataObjects.removeOne(data);
455 }
456 
458 {
459  d->mContactReferences.clear();
460 }
461 
463 {
464  d->mContactGroupReferences.clear();
465 }
466 
468 {
469  d->mDataObjects.clear();
470 }
471 
472 ContactGroup &ContactGroup::operator=(const ContactGroup &other)
473 {
474  if (this != &other) {
475  d = other.d;
476  }
477 
478  return *this;
479 }
480 
481 bool ContactGroup::operator==(const ContactGroup &other) const
482 {
483  return d->mIdentifier == other.d->mIdentifier
484  && d->mName == other.d->mName
485  && d->mContactReferences == other.d->mContactReferences
486  && d->mContactGroupReferences == other.d->mContactGroupReferences
487  && d->mDataObjects == other.d->mDataObjects;
488 }
489 
491 {
492  return QStringLiteral("application/x-vnd.kde.contactgroup");
493 }
QString uid() const
Returns the contact group uid of the contact group reference.
void setUid(const QString &uid)
Sets the contact uid of the contact reference.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
void setEmail(const QString &email)
Sets the email address of the contact data object.
int contactReferenceCount() const
Returns the number of contact references in this group.
QString id() const
Returns the unique id of the contact group.
void remove(const ContactReference &reference)
Removes the given contact reference from the contact group.
QString name() const
Returns the name of the contact data object.
QString custom(const QString &key) const
Returns the value for the given key, or an empty string if the entry for that key does not exists...
This class represents a group of contacts.
Definition: contactgroup.h:32
void removeAllContactGroupReferences()
Removes all contact group references from the contact group.
ContactGroup()
Creates an empty contact group.
Data()
Creates an empty contact data object.
ContactGroupReference & operator=(const ContactGroupReference &other)
void removeCustom(const QString &key)
Removes the custom entry with the given key.
This class represents a contact group reference.
Definition: contactgroup.h:146
ContactGroupReference & contactGroupReference(int index)
Returns the contact group reference at the given index.
ContactReference & contactReference(int index)
Returns the contact reference at the given index.
~ContactGroupReference()
Destroys the contact group reference.
int contactGroupReferenceCount() const
Returns the number of group references in this group.
QString custom(const QString &key) const
Returns the value for the given key, or an empty string if the entry for that key does not exists...
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
QString gid() const
Returns the contact GID of the contact reference.
ContactReference & operator=(const ContactReference &other)
QString name() const
Returns the i18n&#39;d name of the contact group.
ContactGroup & operator=(const ContactGroup &other)
static QString mimeType()
Returns the MIME type used for Contact Groups.
void setGid(const QString &gid)
Sets the contact gid of the contact reference.
QString preferredEmail() const
Returns the preferred email address, or an empty string if no preferred email address is set...
~Data()
Destroys the contact data object.
bool operator==(const ContactGroupReference &other) const
void setName(const QString &name)
Sets the i18n&#39;d name of the contact group.
QString custom(const QString &key) const
Returns the value for the given key, or an empty string if the entry for that key does not exists...
This class represents a contact reference.
Definition: contactgroup.h:39
bool operator==(const ContactReference &other) const
void setPreferredEmail(const QString &email)
Sets the preferred email address.
void setName(const QString &name)
Sets the name of the contact data object.
void removeAllContactReferences()
Removes all contact references from the contact group.
void setUid(const QString &uid)
Sets the contact group uid of the contact group reference.
~ContactReference()
Destroys the contact reference.
int count() const
Returns the number of contacts in this group.
QString email() const
Returns the email address of the contact data object.
bool operator==(const Data &other) const
ContactGroupReference()
Creates an empty contact group reference.
void removeCustom(const QString &key)
Removes the custom entry with the given key.
This class represents a contact data object.
Definition: contactgroup.h:223
int dataCount() const
Returns the number of contact data objects in this group.
~ContactGroup()
Destroys the contact group.
Data & operator=(const Data &other)
void removeAllContactData()
Removes all contact data from the contact group.
void append(const ContactReference &reference)
Appends a new contact reference to the contact group.
Data & data(int index)
Returns the contact data object at the given index.
ContactReference()
Creates an empty contact reference.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
void removeCustom(const QString &key)
Removes the custom entry with the given key.
QUuid createUuid()
bool operator==(const ContactGroup &other) const
void setId(const QString &id)
Sets the unique id of the contact group.
QString uid() const
Returns the contact uid of the contact reference.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:55:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.