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 {
106  if (this != &other) {
107  d = other.d;
108  }
109 
110  return *this;
111 }
112 
114 {
115  return d->mUid == other.d->mUid && d->mPreferredEmail == other.d->mPreferredEmail && d->mCustoms == other.d->mCustoms;
116 }
117 
118 class Q_DECL_HIDDEN ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData
119 {
120 public:
121  ContactGroupReferencePrivate()
122  : QSharedData()
123  {
124  }
125 
126  ContactGroupReferencePrivate(const ContactGroupReferencePrivate &other)
127  : QSharedData(other)
128  {
129  mUid = other.mUid;
130  mCustoms = other.mCustoms;
131  }
132 
133  QString mUid;
134  QMap<QString, QString> mCustoms;
135 };
136 
138  : d(new ContactGroupReferencePrivate)
139 {
140 }
141 
143  : d(other.d)
144 {
145 }
146 
148  : d(new ContactGroupReferencePrivate)
149 {
150  d->mUid = uid;
151 }
152 
154 {
155 }
156 
158 {
159  d->mUid = uid;
160 }
161 
163 {
164  return d->mUid;
165 }
166 
168 {
169  d->mCustoms.insert(key, value);
170 }
171 
173 {
174  d->mCustoms.remove(key);
175 }
176 
178 {
179  return d->mCustoms.value(key);
180 }
181 
183 {
184  if (this != &other) {
185  d = other.d;
186  }
187 
188  return *this;
189 }
190 
192 {
193  return d->mUid == other.d->mUid && d->mCustoms == other.d->mCustoms;
194 }
195 
196 class Q_DECL_HIDDEN ContactGroup::Data::DataPrivate : public QSharedData
197 {
198 public:
199  DataPrivate()
200  : QSharedData()
201  {
202  }
203 
204  DataPrivate(const DataPrivate &other)
205  : QSharedData(other)
206  {
207  mName = other.mName;
208  mEmail = other.mEmail;
209  mCustoms = other.mCustoms;
210  }
211 
212  QString mName;
213  QString mEmail;
214  QMap<QString, QString> mCustoms;
215 };
216 
218  : d(new DataPrivate)
219 {
220 }
221 
223  : d(other.d)
224 {
225 }
226 
228  : d(new DataPrivate)
229 {
230  d->mName = name;
231  d->mEmail = email;
232 }
233 
235 {
236 }
237 
239 {
240  d->mName = name;
241 }
242 
244 {
245  return d->mName;
246 }
247 
249 {
250  d->mEmail = email;
251 }
252 
254 {
255  return d->mEmail;
256 }
257 
258 void ContactGroup::Data::insertCustom(const QString &key, const QString &value)
259 {
260  d->mCustoms.insert(key, value);
261 }
262 
264 {
265  d->mCustoms.remove(key);
266 }
267 
269 {
270  return d->mCustoms.value(key);
271 }
272 
274 {
275  if (this != &other) {
276  d = other.d;
277  }
278 
279  return *this;
280 }
281 
282 bool ContactGroup::Data::operator==(const Data &other) const
283 {
284  return d->mName == other.d->mName //
285  && d->mEmail == other.d->mEmail //
286  && d->mCustoms == other.d->mCustoms;
287 }
288 
289 class Q_DECL_HIDDEN ContactGroup::Private : public QSharedData
290 {
291 public:
292  Private()
293  : QSharedData()
294  , mIdentifier(QUuid::createUuid().toString().mid(1, 36)) // We avoid the curly braces so the string is RFC4122 compliant and can be used as urn
295  {
296  }
297 
298  Private(const Private &other)
299  : QSharedData(other)
300  {
301  mIdentifier = other.mIdentifier;
302  mName = other.mName;
303  mContactReferences = other.mContactReferences;
304  mContactGroupReferences = other.mContactGroupReferences;
305  mDataObjects = other.mDataObjects;
306  }
307 
308  QString mIdentifier;
309  QString mName;
310  ContactGroup::ContactReference::List mContactReferences;
311  ContactGroup::ContactGroupReference::List mContactGroupReferences;
312  ContactGroup::Data::List mDataObjects;
313 };
314 
316  : d(new Private)
317 {
318 }
319 
321  : d(other.d)
322 {
323 }
324 
326  : d(new Private)
327 {
328  d->mName = name;
329 }
330 
332 {
333 }
334 
336 {
337  d->mName = name;
338 }
339 
341 {
342  return d->mName;
343 }
344 
346 {
347  d->mIdentifier = id;
348 }
349 
351 {
352  return d->mIdentifier;
353 }
354 
356 {
357  return d->mContactReferences.count() + d->mDataObjects.count();
358 }
359 
361 {
362  return d->mContactReferences.count();
363 }
364 
366 {
367  return d->mContactGroupReferences.count();
368 }
369 
371 {
372  return d->mDataObjects.count();
373 }
374 
376 {
377  Q_ASSERT_X(index < d->mContactReferences.count(), "contactReference()", "index out of range");
378 
379  return d->mContactReferences[index];
380 }
381 
383 {
384  Q_ASSERT_X(index < d->mContactReferences.count(), "contactReference()", "index out of range");
385 
386  return d->mContactReferences[index];
387 }
388 
390 {
391  Q_ASSERT_X(index < d->mContactGroupReferences.count(), "contactGroupReference()", "index out of range");
392 
393  return d->mContactGroupReferences[index];
394 }
395 
397 {
398  Q_ASSERT_X(index < d->mContactGroupReferences.count(), "contactGroupReference()", "index out of range");
399 
400  return d->mContactGroupReferences[index];
401 }
402 
404 {
405  Q_ASSERT_X(index < d->mDataObjects.count(), "data()", "index out of range");
406 
407  return d->mDataObjects[index];
408 }
409 
410 const ContactGroup::Data &ContactGroup::data(int index) const
411 {
412  Q_ASSERT_X(index < d->mDataObjects.count(), "data()", "index out of range");
413 
414  return d->mDataObjects[index];
415 }
416 
418 {
419  d->mContactReferences.append(reference);
420 }
421 
423 {
424  d->mContactGroupReferences.append(reference);
425 }
426 
427 void ContactGroup::append(const Data &data)
428 {
429  d->mDataObjects.append(data);
430 }
431 
433 {
434  d->mContactReferences.removeOne(reference);
435 }
436 
438 {
439  d->mContactGroupReferences.removeOne(reference);
440 }
441 
442 void ContactGroup::remove(const Data &data)
443 {
444  d->mDataObjects.removeOne(data);
445 }
446 
448 {
449  d->mContactReferences.clear();
450 }
451 
453 {
454  d->mContactGroupReferences.clear();
455 }
456 
458 {
459  d->mDataObjects.clear();
460 }
461 
463 {
464  if (this != &other) {
465  d = other.d;
466  }
467 
468  return *this;
469 }
470 
471 bool ContactGroup::operator==(const ContactGroup &other) const
472 {
473  return d->mIdentifier == other.d->mIdentifier //
474  && d->mName == other.d->mName //
475  && d->mContactReferences == other.d->mContactReferences //
476  && d->mContactGroupReferences == other.d->mContactGroupReferences //
477  && d->mDataObjects == other.d->mDataObjects;
478 }
479 
481 {
482  return QStringLiteral("application/x-vnd.kde.contactgroup");
483 }
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.
~ContactReference()
Destroys the contact reference.
ContactGroup()
Creates an empty contact group.
ContactGroup & operator=(const ContactGroup &other)
int contactReferenceCount() const
Returns the number of contact 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.
int dataCount() const
Returns the number of contact data objects in this group.
QString name() const
Returns the name of the contact data object.
bool operator==(const Data &other) const
~Data()
Destroys the contact data object.
This class represents a contact group reference.
Definition: contactgroup.h:146
ContactReference()
Creates an empty contact reference.
void setPreferredEmail(const QString &email)
Sets the preferred email address.
Data & operator=(const Data &other)
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 removeCustom(const QString &key)
Removes the custom entry with the given key.
void append(const ContactReference &reference)
Appends a new contact reference to the contact group.
void removeAllContactReferences()
Removes all contact references from the contact group.
~ContactGroupReference()
Destroys the contact group reference.
void removeCustom(const QString &key)
Removes the custom entry with the given key.
void setEmail(const QString &email)
Sets the email address of the contact data object.
ContactGroupReference & operator=(const ContactGroupReference &other)
void setUid(const QString &uid)
Sets the contact uid of the contact reference.
bool operator==(const ContactGroup &other) const
void remove(const ContactReference &reference)
Removes the given contact reference from the contact group.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
QString uid() const
Returns the contact uid of the contact reference.
int contactGroupReferenceCount() const
Returns the number of group references in this group.
~ContactGroup()
Destroys the contact group.
void removeAllContactData()
Removes all contact data from the contact group.
Data()
Creates an empty contact data object.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
static QString mimeType()
Returns the MIME type used for Contact Groups.
Data & data(int index)
Returns the contact data object at the given index.
ContactReference & contactReference(int index)
Returns the contact reference at the given index.
ContactReference & operator=(const ContactReference &other)
QString gid() const
Returns the contact GID of the contact reference.
This class represents a contact reference.
Definition: contactgroup.h:39
This class represents a group of contacts.
Definition: contactgroup.h:33
ContactGroupReference()
Creates an empty contact group reference.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
QString name() const
Returns the i18n'd name of the contact group.
void setGid(const QString &gid)
Sets the contact gid of the contact reference.
QString id() const
Returns the unique id of the contact group.
int count() const
Returns the number of contacts in this group.
ContactGroupReference & contactGroupReference(int index)
Returns the contact group reference at the given index.
void setUid(const QString &uid)
Sets the contact group uid of the contact group reference.
QString preferredEmail() const
Returns the preferred email address, or an empty string if no preferred email address is set.
void setId(const QString &id)
Sets the unique id of the contact group.
void setName(const QString &name)
Sets the i18n'd name of the contact group.
void removeAllContactGroupReferences()
Removes all contact group references from the contact group.
QString uid() const
Returns the contact group uid of the contact group reference.
bool operator==(const ContactReference &other) const
void setName(const QString &name)
Sets the name of the contact data object.
This class represents a contact data object.
Definition: contactgroup.h:223
void removeCustom(const QString &key)
Removes the custom entry with the given key.
bool operator==(const ContactGroupReference &other) const
QString email() const
Returns the email address of the contact data object.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 04:09:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.