• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

kabc

  • sources
  • kde-4.12
  • kdepimlibs
  • kabc
contactgroup.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "contactgroup.h"
23 
24 #include <QtCore/QMap>
25 #include <QtCore/QSharedData>
26 #include <QtCore/QString>
27 #include <QtCore/QUuid>
28 
29 using namespace KABC;
30 
31 class ContactGroup::ContactReference::ContactReferencePrivate : public QSharedData
32 {
33  public:
34  ContactReferencePrivate()
35  : QSharedData()
36  {
37  }
38 
39  ContactReferencePrivate( const ContactReferencePrivate &other )
40  : QSharedData( other )
41  {
42  mUid = other.mUid;
43  mPreferredEmail = other.mPreferredEmail;
44  mCustoms = other.mCustoms;
45  }
46 
47  QString mUid;
48  QString mGid;
49  QString mPreferredEmail;
50  QMap<QString, QString> mCustoms;
51 };
52 
53 ContactGroup::ContactReference::ContactReference()
54  : d( new ContactReferencePrivate )
55 {
56 }
57 
58 ContactGroup::ContactReference::ContactReference( const ContactReference &other )
59  : d( other.d )
60 {
61 }
62 
63 ContactGroup::ContactReference::ContactReference( const QString &uid )
64  : d( new ContactReferencePrivate )
65 {
66  d->mUid = uid;
67 }
68 
69 ContactGroup::ContactReference::~ContactReference()
70 {
71 }
72 
73 void ContactGroup::ContactReference::setUid( const QString &uid )
74 {
75  d->mUid = uid;
76 }
77 
78 QString ContactGroup::ContactReference::uid() const
79 {
80  return d->mUid;
81 }
82 
83 void ContactGroup::ContactReference::setGid( const QString &gid )
84 {
85  d->mGid = gid;
86 }
87 
88 QString ContactGroup::ContactReference::gid() const
89 {
90  return d->mGid;
91 }
92 
93 void ContactGroup::ContactReference::setPreferredEmail( const QString &email )
94 {
95  d->mPreferredEmail = email;
96 }
97 
98 QString ContactGroup::ContactReference::preferredEmail() const
99 {
100  return d->mPreferredEmail;
101 }
102 
103 void ContactGroup::ContactReference::insertCustom( const QString &key, const QString &value )
104 {
105  d->mCustoms.insert( key, value );
106 }
107 
108 void ContactGroup::ContactReference::removeCustom( const QString &key )
109 {
110  d->mCustoms.remove( key );
111 }
112 
113 QString ContactGroup::ContactReference::custom( const QString &key ) const
114 {
115  return d->mCustoms.value( key );
116 }
117 
118 ContactGroup::ContactReference &ContactGroup::ContactReference::operator=(
119  const ContactGroup::ContactReference &other )
120 {
121  if ( this != &other ) {
122  d = other.d;
123  }
124 
125  return *this;
126 }
127 
128 bool ContactGroup::ContactReference::operator==( const ContactReference &other ) const
129 {
130  return d->mUid == other.d->mUid &&
131  d->mPreferredEmail == other.d->mPreferredEmail &&
132  d->mCustoms == other.d->mCustoms;
133 }
134 
135 class ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData
136 {
137  public:
138  ContactGroupReferencePrivate()
139  : QSharedData()
140  {
141  }
142 
143  ContactGroupReferencePrivate( const ContactGroupReferencePrivate &other )
144  : QSharedData( other )
145  {
146  mUid = other.mUid;
147  mCustoms = other.mCustoms;
148  }
149 
150  QString mUid;
151  QMap<QString, QString> mCustoms;
152 };
153 
154 ContactGroup::ContactGroupReference::ContactGroupReference()
155  : d( new ContactGroupReferencePrivate )
156 {
157 }
158 
159 ContactGroup::ContactGroupReference::ContactGroupReference( const ContactGroupReference &other )
160  : d( other.d )
161 {
162 }
163 
164 ContactGroup::ContactGroupReference::ContactGroupReference( const QString &uid )
165  : d( new ContactGroupReferencePrivate )
166 {
167  d->mUid = uid;
168 }
169 
170 ContactGroup::ContactGroupReference::~ContactGroupReference()
171 {
172 }
173 
174 void ContactGroup::ContactGroupReference::setUid( const QString &uid )
175 {
176  d->mUid = uid;
177 }
178 
179 QString ContactGroup::ContactGroupReference::uid() const
180 {
181  return d->mUid;
182 }
183 
184 void ContactGroup::ContactGroupReference::insertCustom( const QString &key, const QString &value )
185 {
186  d->mCustoms.insert( key, value );
187 }
188 
189 void ContactGroup::ContactGroupReference::removeCustom( const QString &key )
190 {
191  d->mCustoms.remove( key );
192 }
193 
194 QString ContactGroup::ContactGroupReference::custom( const QString &key ) const
195 {
196  return d->mCustoms.value( key );
197 }
198 
199 ContactGroup::ContactGroupReference &ContactGroup::ContactGroupReference::operator=(
200  const ContactGroup::ContactGroupReference &other )
201 {
202  if ( this != &other ) {
203  d = other.d;
204  }
205 
206  return *this;
207 }
208 
209 bool ContactGroup::ContactGroupReference::operator==( const ContactGroupReference &other ) const
210 {
211  return d->mUid == other.d->mUid &&
212  d->mCustoms == other.d->mCustoms;
213 }
214 
215 class ContactGroup::Data::DataPrivate : public QSharedData
216 {
217  public:
218  DataPrivate()
219  : QSharedData()
220  {
221  }
222 
223  DataPrivate( const DataPrivate &other )
224  : QSharedData( other )
225  {
226  mName = other.mName;
227  mEmail = other.mEmail;
228  mCustoms = other.mCustoms;
229  }
230 
231  QString mName;
232  QString mEmail;
233  QMap<QString, QString> mCustoms;
234 };
235 
236 ContactGroup::Data::Data()
237  : d( new DataPrivate )
238 {
239 }
240 
241 ContactGroup::Data::Data( const Data &other )
242  : d( other.d )
243 {
244 }
245 
246 ContactGroup::Data::Data( const QString &name, const QString &email )
247  : d( new DataPrivate )
248 {
249  d->mName = name;
250  d->mEmail = email;
251 }
252 
253 ContactGroup::Data::~Data()
254 {
255 }
256 
257 void ContactGroup::Data::setName( const QString &name )
258 {
259  d->mName = name;
260 }
261 
262 QString ContactGroup::Data::name() const
263 {
264  return d->mName;
265 }
266 
267 void ContactGroup::Data::setEmail( const QString &email )
268 {
269  d->mEmail = email;
270 }
271 
272 QString ContactGroup::Data::email() const
273 {
274  return d->mEmail;
275 }
276 
277 void ContactGroup::Data::insertCustom( const QString &key, const QString &value )
278 {
279  d->mCustoms.insert( key, value );
280 }
281 
282 void ContactGroup::Data::removeCustom( const QString &key )
283 {
284  d->mCustoms.remove( key );
285 }
286 
287 QString ContactGroup::Data::custom( const QString &key ) const
288 {
289  return d->mCustoms.value( key );
290 }
291 
292 ContactGroup::Data &ContactGroup::Data::operator=( const ContactGroup::Data &other )
293 {
294  if ( this != &other ) {
295  d = other.d;
296  }
297 
298  return *this;
299 }
300 
301 bool ContactGroup::Data::operator==( const Data &other ) const
302 {
303  return d->mName == other.d->mName &&
304  d->mEmail == other.d->mEmail &&
305  d->mCustoms == other.d->mCustoms;
306 }
307 
308 class ContactGroup::Private : public QSharedData
309 {
310  public:
311  Private()
312  : QSharedData(),
313  mIdentifier( QUuid::createUuid().toString() )
314  {
315  }
316 
317  Private( const Private &other )
318  : QSharedData( other )
319  {
320  mIdentifier = other.mIdentifier;
321  mName = other.mName;
322  mContactReferences = other.mContactReferences;
323  mContactGroupReferences = other.mContactGroupReferences;
324  mDataObjects = other.mDataObjects;
325  }
326 
327  QString mIdentifier;
328  QString mName;
329  ContactGroup::ContactReference::List mContactReferences;
330  ContactGroup::ContactGroupReference::List mContactGroupReferences;
331  ContactGroup::Data::List mDataObjects;
332 };
333 
334 ContactGroup::ContactGroup()
335  : d( new Private )
336 {
337 }
338 
339 ContactGroup::ContactGroup( const ContactGroup &other )
340  : d( other.d )
341 {
342 }
343 
344 ContactGroup::ContactGroup( const QString &name )
345  : d( new Private )
346 {
347  d->mName = name;
348 }
349 
350 ContactGroup::~ContactGroup()
351 {
352 }
353 
354 void ContactGroup::setName( const QString &name )
355 {
356  d->mName = name;
357 }
358 
359 QString ContactGroup::name() const
360 {
361  return d->mName;
362 }
363 
364 void ContactGroup::setId( const QString &id )
365 {
366  d->mIdentifier = id;
367 }
368 
369 QString ContactGroup::id() const
370 {
371  return d->mIdentifier;
372 }
373 
374 unsigned int ContactGroup::count() const
375 {
376  return d->mContactReferences.count() + d->mDataObjects.count();
377 }
378 
379 unsigned int ContactGroup::contactReferenceCount() const
380 {
381  return d->mContactReferences.count();
382 }
383 
384 unsigned int ContactGroup::contactGroupReferenceCount() const
385 {
386  return d->mContactGroupReferences.count();
387 }
388 
389 unsigned int ContactGroup::dataCount() const
390 {
391  return d->mDataObjects.count();
392 }
393 
394 ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index )
395 {
396  Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(),
397  "contactReference()", "index out of range" );
398 
399  return d->mContactReferences[ index ];
400 }
401 
402 const ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index ) const
403 {
404  Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(),
405  "contactReference()", "index out of range" );
406 
407  return d->mContactReferences[ index ];
408 }
409 
410 ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference( unsigned int index )
411 {
412  Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(),
413  "contactGroupReference()", "index out of range" );
414 
415  return d->mContactGroupReferences[ index ];
416 }
417 
418 const ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference(
419  unsigned int index ) const
420 {
421  Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(),
422  "contactGroupReference()", "index out of range" );
423 
424  return d->mContactGroupReferences[ index ];
425 }
426 
427 ContactGroup::Data &ContactGroup::data( unsigned int index )
428 {
429  Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" );
430 
431  return d->mDataObjects[ index ];
432 }
433 
434 const ContactGroup::Data &ContactGroup::data( unsigned int index ) const
435 {
436  Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" );
437 
438  return d->mDataObjects[ index ];
439 }
440 
441 void ContactGroup::append( const ContactReference &reference )
442 {
443  d->mContactReferences.append( reference );
444 }
445 
446 void ContactGroup::append( const ContactGroupReference &reference )
447 {
448  d->mContactGroupReferences.append( reference );
449 }
450 
451 void ContactGroup::append( const Data &data )
452 {
453  d->mDataObjects.append( data );
454 }
455 
456 void ContactGroup::remove( const ContactReference &reference )
457 {
458  d->mContactReferences.removeOne( reference );
459 }
460 
461 void ContactGroup::remove( const ContactGroupReference &reference )
462 {
463  d->mContactGroupReferences.removeOne( reference );
464 }
465 
466 void ContactGroup::remove( const Data &data )
467 {
468  d->mDataObjects.removeOne( data );
469 }
470 
471 void ContactGroup::removeAllContactReferences()
472 {
473  d->mContactReferences.clear();
474 }
475 
476 void ContactGroup::removeAllContactGroupReferences()
477 {
478  d->mContactGroupReferences.clear();
479 }
480 
481 void ContactGroup::removeAllContactData()
482 {
483  d->mDataObjects.clear();
484 }
485 
486 ContactGroup &ContactGroup::operator=( const ContactGroup &other )
487 {
488  if ( this != &other ) {
489  d = other.d;
490  }
491 
492  return *this;
493 }
494 
495 bool ContactGroup::operator==( const ContactGroup &other ) const
496 {
497  return d->mIdentifier == other.d->mIdentifier &&
498  d->mName == other.d->mName &&
499  d->mContactReferences == other.d->mContactReferences &&
500  d->mContactGroupReferences == other.d->mContactGroupReferences &&
501  d->mDataObjects == other.d->mDataObjects;
502 }
503 
504 QString ContactGroup::mimeType()
505 {
506  return QLatin1String( "application/x-vnd.kde.contactgroup" );
507 }
KABC::ContactGroup::ContactReference::operator==
bool operator==(const ContactReference &) const
Definition: contactgroup.cpp:128
KABC::ContactGroup::mimeType
static QString mimeType()
Returns the MIME type used for Contact Groups.
Definition: contactgroup.cpp:504
KABC::ContactGroup::ContactGroupReference::setUid
void setUid(const QString &uid)
Sets the contact group uid of the contact group reference.
Definition: contactgroup.cpp:174
KABC::ContactGroup::setName
void setName(const QString &name)
Sets the i18n'd name of the contact group.
Definition: contactgroup.cpp:354
KABC::ContactGroup::~ContactGroup
~ContactGroup()
Destroys the contact group.
Definition: contactgroup.cpp:350
KABC::ContactGroup::ContactGroupReference::ContactGroupReference
ContactGroupReference()
Creates an empty contact group reference.
Definition: contactgroup.cpp:154
KABC::ContactGroup::Data::List
QList< Data > List
A list of contact data.
Definition: contactgroup.h:243
KABC::ContactGroup::Data::setEmail
void setEmail(const QString &email)
Sets the email address of the contact data object.
Definition: contactgroup.cpp:267
KABC::ContactGroup::Data::operator==
bool operator==(const Data &) const
Definition: contactgroup.cpp:301
KABC::ContactGroup::removeAllContactGroupReferences
void removeAllContactGroupReferences()
Removes all contact group references from the contact group.
Definition: contactgroup.cpp:476
KABC::ContactGroup::ContactReference
This class represents a contact reference.
Definition: contactgroup.h:53
KABC::ContactGroup::ContactReference::preferredEmail
QString preferredEmail() const
Returns the preferred email address, or an empty string if no preferred email address is set...
Definition: contactgroup.cpp:98
KABC::ContactGroup::ContactReference::insertCustom
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
Definition: contactgroup.cpp:103
KABC::ContactGroup::ContactReference::removeCustom
void removeCustom(const QString &key)
Removes the custom entry with the given key.
Definition: contactgroup.cpp:108
KABC::ContactGroup::Data::~Data
~Data()
Destroys the contact data object.
Definition: contactgroup.cpp:253
KABC::ContactGroup::Data::Data
Data()
Creates an empty contact data object.
Definition: contactgroup.cpp:236
KABC::ContactGroup::Data::removeCustom
void removeCustom(const QString &key)
Removes the custom entry with the given key.
Definition: contactgroup.cpp:282
KABC::ContactGroup::ContactGroupReference::uid
QString uid() const
Returns the contact group uid of the contact group reference.
Definition: contactgroup.cpp:179
KABC::ContactGroup::ContactGroupReference::operator=
ContactGroupReference & operator=(const ContactGroupReference &)
Definition: contactgroup.cpp:199
KABC::ContactGroup::ContactGroup
ContactGroup()
Creates an empty contact group.
Definition: contactgroup.cpp:334
KABC::ContactGroup::dataCount
unsigned int dataCount() const
Returns the number of contact data objects in this group.
Definition: contactgroup.cpp:389
KABC::ContactGroup::removeAllContactReferences
void removeAllContactReferences()
Removes all contact references from the contact group.
Definition: contactgroup.cpp:471
KABC::ContactGroup::Data::custom
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...
Definition: contactgroup.cpp:287
KABC::ContactGroup::contactGroupReferenceCount
unsigned int contactGroupReferenceCount() const
Returns the number of group references in this group.
Definition: contactgroup.cpp:384
KABC::ContactGroup::setId
void setId(const QString &id)
Sets the unique id of the contact group.
Definition: contactgroup.cpp:364
KABC::ContactGroup
This class represents a group of contacts.
Definition: contactgroup.h:46
KABC::ContactGroup::ContactReference::setGid
void setGid(const QString &gid)
Sets the contact gid of the contact reference.
Definition: contactgroup.cpp:83
KABC::ContactGroup::Data::name
QString name() const
Returns the name of the contact data object.
Definition: contactgroup.cpp:262
KABC::ContactGroup::contactReferenceCount
unsigned int contactReferenceCount() const
Returns the number of contact references in this group.
Definition: contactgroup.cpp:379
KABC::ContactGroup::data
Data & data(unsigned int index)
Returns the contact data object at the given index.
Definition: contactgroup.cpp:427
KABC::ContactGroup::ContactReference::gid
QString gid() const
Returns the contact GID of the contact reference.
Definition: contactgroup.cpp:88
KABC::ContactGroup::id
QString id() const
Returns the unique id of the contact group.
Definition: contactgroup.cpp:369
KABC::ContactGroup::Data::insertCustom
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
Definition: contactgroup.cpp:277
KABC::ContactGroup::append
void append(const ContactReference &reference)
Appends a new contact reference to the contact group.
Definition: contactgroup.cpp:441
KABC::ContactGroup::ContactReference::ContactReference
ContactReference()
Creates an empty contact reference.
Definition: contactgroup.cpp:53
KABC::ContactGroup::Data::setName
void setName(const QString &name)
Sets the name of the contact data object.
Definition: contactgroup.cpp:257
KABC::ContactGroup::ContactReference::~ContactReference
~ContactReference()
Destroys the contact reference.
Definition: contactgroup.cpp:69
KABC::ContactGroup::ContactGroupReference::operator==
bool operator==(const ContactGroupReference &) const
Definition: contactgroup.cpp:209
KABC::ContactGroup::ContactGroupReference::insertCustom
void insertCustom(const QString &key, const QString &value)
Inserts a custom entry.
Definition: contactgroup.cpp:184
KABC::ContactGroup::ContactReference::operator=
ContactReference & operator=(const ContactReference &)
Definition: contactgroup.cpp:118
KABC::ContactGroup::ContactReference::custom
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...
Definition: contactgroup.cpp:113
KABC::ContactGroup::ContactReference::List
QList< ContactReference > List
A list of contact references.
Definition: contactgroup.h:59
KABC::ContactGroup::ContactGroupReference::List
QList< ContactGroupReference > List
A list of contact group references.
Definition: contactgroup.h:166
KABC::ContactGroup::removeAllContactData
void removeAllContactData()
Removes all contact data from the contact group.
Definition: contactgroup.cpp:481
KABC::ContactGroup::ContactGroupReference::custom
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...
Definition: contactgroup.cpp:194
KABC::ContactGroup::remove
void remove(const ContactReference &reference)
Removes the given contact reference from the contact group.
Definition: contactgroup.cpp:456
KABC::ContactGroup::contactReference
ContactReference & contactReference(unsigned int index)
Returns the contact reference at the given index.
Definition: contactgroup.cpp:394
KABC::ContactGroup::ContactGroupReference::~ContactGroupReference
~ContactGroupReference()
Destroys the contact group reference.
Definition: contactgroup.cpp:170
KABC::ContactGroup::ContactReference::uid
QString uid() const
Returns the contact uid of the contact reference.
Definition: contactgroup.cpp:78
KABC::ContactGroup::ContactReference::setPreferredEmail
void setPreferredEmail(const QString &email)
Sets the preferred email address.
Definition: contactgroup.cpp:93
KABC::ContactGroup::Data::email
QString email() const
Returns the email address of the contact data object.
Definition: contactgroup.cpp:272
KABC::ContactGroup::Data::operator=
Data & operator=(const Data &)
Definition: contactgroup.cpp:292
KABC::ContactGroup::ContactGroupReference
This class represents a contact group reference.
Definition: contactgroup.h:160
KABC::ContactGroup::contactGroupReference
ContactGroupReference & contactGroupReference(unsigned int index)
Returns the contact group reference at the given index.
Definition: contactgroup.cpp:410
KABC::ContactGroup::ContactReference::setUid
void setUid(const QString &uid)
Sets the contact uid of the contact reference.
Definition: contactgroup.cpp:73
KABC::ContactGroup::count
unsigned int count() const
Returns the number of contacts in this group.
Definition: contactgroup.cpp:374
KABC::ContactGroup::name
QString name() const
Returns the i18n'd name of the contact group.
Definition: contactgroup.cpp:359
KABC::ContactGroup::operator==
bool operator==(const ContactGroup &) const
Definition: contactgroup.cpp:495
KABC::ContactGroup::ContactGroupReference::removeCustom
void removeCustom(const QString &key)
Removes the custom entry with the given key.
Definition: contactgroup.cpp:189
KABC::ContactGroup::Data
This class represents a contact data object.
Definition: contactgroup.h:237
KABC::ContactGroup::operator=
ContactGroup & operator=(const ContactGroup &)
Definition: contactgroup.cpp:486
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal