KContacts

contactgroup.cpp
1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2008 Tobias Koenig <tokoe@kde.org>
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
15using namespace KContacts;
16
17class Q_DECL_HIDDEN ContactGroup::ContactReference::ContactReferencePrivate : public QSharedData
18{
19public:
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;
37};
38
40 : d(new ContactReferencePrivate)
41{
42}
43
48
50 : d(new ContactReferencePrivate)
51{
52 d->mUid = uid;
53}
54
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
118class Q_DECL_HIDDEN ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData
119{
120public:
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
146
148 : d(new ContactGroupReferencePrivate)
149{
150 d->mUid = uid;
151}
152
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
196class Q_DECL_HIDDEN ContactGroup::Data::DataPrivate : public QSharedData
197{
198public:
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
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
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
282bool 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
289class Q_DECL_HIDDEN ContactGroup::Private : public QSharedData
290{
291public:
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
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
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
427void 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
442void 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
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}
This class represents a contact group reference.
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.
QString uid() const
Returns the contact group uid of the contact group reference.
void setUid(const QString &uid)
Sets the contact group uid of the contact group reference.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
ContactGroupReference & operator=(const ContactGroupReference &other)
bool operator==(const ContactGroupReference &other) const
ContactGroupReference()
Creates an empty contact group reference.
~ContactGroupReference()
Destroys the contact group reference.
void removeCustom(const QString &key)
Removes the custom entry with the given key.
This class represents a contact reference.
ContactReference()
Creates an empty contact reference.
QString uid() const
Returns the contact uid of the contact reference.
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 setPreferredEmail(const QString &email)
Sets the preferred email address.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
QString gid() const
Returns the contact GID of the contact reference.
bool operator==(const ContactReference &other) const
ContactReference & operator=(const ContactReference &other)
void removeCustom(const QString &key)
Removes the custom entry with the given key.
void setGid(const QString &gid)
Sets the contact gid of the contact reference.
void setUid(const QString &uid)
Sets the contact uid of the contact reference.
QString preferredEmail() const
Returns the preferred email address, or an empty string if no preferred email address is set.
~ContactReference()
Destroys the contact reference.
This class represents a contact data object.
void removeCustom(const QString &key)
Removes the custom entry with the given key.
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.
~Data()
Destroys the contact data object.
QString name() const
Returns the name of the contact data object.
Data()
Creates an empty contact data object.
bool operator==(const Data &other) const
Data & operator=(const Data &other)
void setName(const QString &name)
Sets the name of the contact data object.
void setEmail(const QString &email)
Sets the email address of the contact data object.
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
QString email() const
Returns the email address of the contact data object.
This class represents a group of contacts.
void append(const ContactReference &reference)
Appends a new contact reference to the contact group.
ContactGroupReference & contactGroupReference(int index)
Returns the contact group reference at the given index.
void setName(const QString &name)
Sets the i18n'd name of the contact group.
static QString mimeType()
Returns the MIME type used for Contact Groups.
void removeAllContactGroupReferences()
Removes all contact group references from the contact group.
int contactReferenceCount() const
Returns the number of contact references in this group.
Data & data(int index)
Returns the contact data object at the given index.
QString id() const
Returns the unique id of the contact group.
int contactGroupReferenceCount() const
Returns the number of group references in this group.
void remove(const ContactReference &reference)
Removes the given contact reference from the contact group.
~ContactGroup()
Destroys the contact group.
void removeAllContactReferences()
Removes all contact references from the contact group.
int count() const
Returns the number of contacts in this group.
void removeAllContactData()
Removes all contact data from the contact group.
void setId(const QString &id)
Sets the unique id of the contact group.
ContactGroup()
Creates an empty contact group.
QString name() const
Returns the i18n'd name of the contact group.
bool operator==(const ContactGroup &other) const
ContactReference & contactReference(int index)
Returns the contact reference at the given index.
ContactGroup & operator=(const ContactGroup &other)
int dataCount() const
Returns the number of contact data objects in this group.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.