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

kabc

  • 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 mPreferredEmail;
49  QMap<QString, QString> mCustoms;
50 };
51 
52 ContactGroup::ContactReference::ContactReference()
53  : d( new ContactReferencePrivate )
54 {
55 }
56 
57 ContactGroup::ContactReference::ContactReference( const ContactReference &other )
58  : d( other.d )
59 {
60 }
61 
62 ContactGroup::ContactReference::ContactReference( const QString &uid )
63  : d( new ContactReferencePrivate )
64 {
65  d->mUid = uid;
66 }
67 
68 ContactGroup::ContactReference::~ContactReference()
69 {
70 }
71 
72 void ContactGroup::ContactReference::setUid( const QString &uid )
73 {
74  d->mUid = uid;
75 }
76 
77 QString ContactGroup::ContactReference::uid() const
78 {
79  return d->mUid;
80 }
81 
82 void ContactGroup::ContactReference::setPreferredEmail( const QString &email )
83 {
84  d->mPreferredEmail = email;
85 }
86 
87 QString ContactGroup::ContactReference::preferredEmail() const
88 {
89  return d->mPreferredEmail;
90 }
91 
92 void ContactGroup::ContactReference::insertCustom( const QString &key, const QString &value )
93 {
94  d->mCustoms.insert( key, value );
95 }
96 
97 void ContactGroup::ContactReference::removeCustom( const QString &key )
98 {
99  d->mCustoms.remove( key );
100 }
101 
102 QString ContactGroup::ContactReference::custom( const QString &key ) const
103 {
104  return d->mCustoms.value( key );
105 }
106 
107 ContactGroup::ContactReference &ContactGroup::ContactReference::operator=(
108  const ContactGroup::ContactReference &other )
109 {
110  if ( this != &other ) {
111  d = other.d;
112  }
113 
114  return *this;
115 }
116 
117 bool ContactGroup::ContactReference::operator==( const ContactReference &other ) const
118 {
119  return d->mUid == other.d->mUid &&
120  d->mPreferredEmail == other.d->mPreferredEmail &&
121  d->mCustoms == other.d->mCustoms;
122 }
123 
124 class ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData
125 {
126  public:
127  ContactGroupReferencePrivate()
128  : QSharedData()
129  {
130  }
131 
132  ContactGroupReferencePrivate( const ContactGroupReferencePrivate &other )
133  : QSharedData( other )
134  {
135  mUid = other.mUid;
136  mCustoms = other.mCustoms;
137  }
138 
139  QString mUid;
140  QMap<QString, QString> mCustoms;
141 };
142 
143 ContactGroup::ContactGroupReference::ContactGroupReference()
144  : d( new ContactGroupReferencePrivate )
145 {
146 }
147 
148 ContactGroup::ContactGroupReference::ContactGroupReference( const ContactGroupReference &other )
149  : d( other.d )
150 {
151 }
152 
153 ContactGroup::ContactGroupReference::ContactGroupReference( const QString &uid )
154  : d( new ContactGroupReferencePrivate )
155 {
156  d->mUid = uid;
157 }
158 
159 ContactGroup::ContactGroupReference::~ContactGroupReference()
160 {
161 }
162 
163 void ContactGroup::ContactGroupReference::setUid( const QString &uid )
164 {
165  d->mUid = uid;
166 }
167 
168 QString ContactGroup::ContactGroupReference::uid() const
169 {
170  return d->mUid;
171 }
172 
173 void ContactGroup::ContactGroupReference::insertCustom( const QString &key, const QString &value )
174 {
175  d->mCustoms.insert( key, value );
176 }
177 
178 void ContactGroup::ContactGroupReference::removeCustom( const QString &key )
179 {
180  d->mCustoms.remove( key );
181 }
182 
183 QString ContactGroup::ContactGroupReference::custom( const QString &key ) const
184 {
185  return d->mCustoms.value( key );
186 }
187 
188 ContactGroup::ContactGroupReference &ContactGroup::ContactGroupReference::operator=(
189  const ContactGroup::ContactGroupReference &other )
190 {
191  if ( this != &other ) {
192  d = other.d;
193  }
194 
195  return *this;
196 }
197 
198 bool ContactGroup::ContactGroupReference::operator==( const ContactGroupReference &other ) const
199 {
200  return d->mUid == other.d->mUid &&
201  d->mCustoms == other.d->mCustoms;
202 }
203 
204 class ContactGroup::Data::DataPrivate : public QSharedData
205 {
206  public:
207  DataPrivate()
208  : QSharedData()
209  {
210  }
211 
212  DataPrivate( const DataPrivate &other )
213  : QSharedData( other )
214  {
215  mName = other.mName;
216  mEmail = other.mEmail;
217  mCustoms = other.mCustoms;
218  }
219 
220  QString mName;
221  QString mEmail;
222  QMap<QString, QString> mCustoms;
223 };
224 
225 ContactGroup::Data::Data()
226  : d( new DataPrivate )
227 {
228 }
229 
230 ContactGroup::Data::Data( const Data &other )
231  : d( other.d )
232 {
233 }
234 
235 ContactGroup::Data::Data( const QString &name, const QString &email )
236  : d( new DataPrivate )
237 {
238  d->mName = name;
239  d->mEmail = email;
240 }
241 
242 ContactGroup::Data::~Data()
243 {
244 }
245 
246 void ContactGroup::Data::setName( const QString &name )
247 {
248  d->mName = name;
249 }
250 
251 QString ContactGroup::Data::name() const
252 {
253  return d->mName;
254 }
255 
256 void ContactGroup::Data::setEmail( const QString &email )
257 {
258  d->mEmail = email;
259 }
260 
261 QString ContactGroup::Data::email() const
262 {
263  return d->mEmail;
264 }
265 
266 void ContactGroup::Data::insertCustom( const QString &key, const QString &value )
267 {
268  d->mCustoms.insert( key, value );
269 }
270 
271 void ContactGroup::Data::removeCustom( const QString &key )
272 {
273  d->mCustoms.remove( key );
274 }
275 
276 QString ContactGroup::Data::custom( const QString &key ) const
277 {
278  return d->mCustoms.value( key );
279 }
280 
281 ContactGroup::Data &ContactGroup::Data::operator=( const ContactGroup::Data &other )
282 {
283  if ( this != &other ) {
284  d = other.d;
285  }
286 
287  return *this;
288 }
289 
290 bool ContactGroup::Data::operator==( const Data &other ) const
291 {
292  return d->mName == other.d->mName &&
293  d->mEmail == other.d->mEmail &&
294  d->mCustoms == other.d->mCustoms;
295 }
296 
297 class ContactGroup::Private : public QSharedData
298 {
299  public:
300  Private()
301  : QSharedData(),
302  mIdentifier( QUuid::createUuid().toString() )
303  {
304  }
305 
306  Private( const Private &other )
307  : QSharedData( other )
308  {
309  mIdentifier = other.mIdentifier;
310  mName = other.mName;
311  mContactReferences = other.mContactReferences;
312  mContactGroupReferences = other.mContactGroupReferences;
313  mDataObjects = other.mDataObjects;
314  }
315 
316  QString mIdentifier;
317  QString mName;
318  ContactGroup::ContactReference::List mContactReferences;
319  ContactGroup::ContactGroupReference::List mContactGroupReferences;
320  ContactGroup::Data::List mDataObjects;
321 };
322 
323 ContactGroup::ContactGroup()
324  : d( new Private )
325 {
326 }
327 
328 ContactGroup::ContactGroup( const ContactGroup &other )
329  : d( other.d )
330 {
331 }
332 
333 ContactGroup::ContactGroup( const QString &name )
334  : d( new Private )
335 {
336  d->mName = name;
337 }
338 
339 ContactGroup::~ContactGroup()
340 {
341 }
342 
343 void ContactGroup::setName( const QString &name )
344 {
345  d->mName = name;
346 }
347 
348 QString ContactGroup::name() const
349 {
350  return d->mName;
351 }
352 
353 void ContactGroup::setId( const QString &id )
354 {
355  d->mIdentifier = id;
356 }
357 
358 QString ContactGroup::id() const
359 {
360  return d->mIdentifier;
361 }
362 
363 unsigned int ContactGroup::count() const
364 {
365  return d->mContactReferences.count() + d->mDataObjects.count();
366 }
367 
368 unsigned int ContactGroup::contactReferenceCount() const
369 {
370  return d->mContactReferences.count();
371 }
372 
373 unsigned int ContactGroup::contactGroupReferenceCount() const
374 {
375  return d->mContactGroupReferences.count();
376 }
377 
378 unsigned int ContactGroup::dataCount() const
379 {
380  return d->mDataObjects.count();
381 }
382 
383 ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index )
384 {
385  Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(),
386  "contactReference()", "index out of range" );
387 
388  return d->mContactReferences[ index ];
389 }
390 
391 const ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index ) const
392 {
393  Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(),
394  "contactReference()", "index out of range" );
395 
396  return d->mContactReferences[ index ];
397 }
398 
399 ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference( unsigned int index )
400 {
401  Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(),
402  "contactGroupReference()", "index out of range" );
403 
404  return d->mContactGroupReferences[ index ];
405 }
406 
407 const ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference(
408  unsigned int index ) const
409 {
410  Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(),
411  "contactGroupReference()", "index out of range" );
412 
413  return d->mContactGroupReferences[ index ];
414 }
415 
416 ContactGroup::Data &ContactGroup::data( unsigned int index )
417 {
418  Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" );
419 
420  return d->mDataObjects[ index ];
421 }
422 
423 const ContactGroup::Data &ContactGroup::data( unsigned int index ) const
424 {
425  Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" );
426 
427  return d->mDataObjects[ index ];
428 }
429 
430 void ContactGroup::append( const ContactReference &reference )
431 {
432  d->mContactReferences.append( reference );
433 }
434 
435 void ContactGroup::append( const ContactGroupReference &reference )
436 {
437  d->mContactGroupReferences.append( reference );
438 }
439 
440 void ContactGroup::append( const Data &data )
441 {
442  d->mDataObjects.append( data );
443 }
444 
445 void ContactGroup::remove( const ContactReference &reference )
446 {
447  d->mContactReferences.removeOne( reference );
448 }
449 
450 void ContactGroup::remove( const ContactGroupReference &reference )
451 {
452  d->mContactGroupReferences.removeOne( reference );
453 }
454 
455 void ContactGroup::remove( const Data &data )
456 {
457  d->mDataObjects.removeOne( data );
458 }
459 
460 void ContactGroup::removeAllContactReferences()
461 {
462  d->mContactReferences.clear();
463 }
464 
465 void ContactGroup::removeAllContactGroupReferences()
466 {
467  d->mContactGroupReferences.clear();
468 }
469 
470 void ContactGroup::removeAllContactData()
471 {
472  d->mDataObjects.clear();
473 }
474 
475 ContactGroup &ContactGroup::operator=( const ContactGroup &other )
476 {
477  if ( this != &other ) {
478  d = other.d;
479  }
480 
481  return *this;
482 }
483 
484 bool ContactGroup::operator==( const ContactGroup &other ) const
485 {
486  return d->mIdentifier == other.d->mIdentifier &&
487  d->mName == other.d->mName &&
488  d->mContactReferences == other.d->mContactReferences &&
489  d->mContactGroupReferences == other.d->mContactGroupReferences &&
490  d->mDataObjects == other.d->mDataObjects;
491 }
492 
493 QString ContactGroup::mimeType()
494 {
495  return QLatin1String( "application/x-vnd.kde.contactgroup" );
496 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:29:40 by doxygen 1.8.3.1 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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