• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kabc

contactgroup.cpp

00001 /*
00002   This file is part of libkabc.
00003   Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public License
00016   along with this library; see the file COPYING.LIB.  If not, write to
00017   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018 
00019   Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "contactgroup.h"
00023 
00024 #include <QtCore/QMap>
00025 #include <QtCore/QSharedData>
00026 #include <QtCore/QString>
00027 #include <QtCore/QUuid>
00028 
00029 using namespace KABC;
00030 
00031 class ContactGroup::ContactReference::ContactReferencePrivate : public QSharedData
00032 {
00033   public:
00034     ContactReferencePrivate()
00035       : QSharedData()
00036     {
00037     }
00038 
00039     ContactReferencePrivate( const ContactReferencePrivate &other )
00040       : QSharedData( other )
00041     {
00042       mUid = other.mUid;
00043       mPreferredEmail = other.mPreferredEmail;
00044       mCustoms = other.mCustoms;
00045     }
00046 
00047     QString mUid;
00048     QString mPreferredEmail;
00049     QMap<QString, QString> mCustoms;
00050 };
00051 
00052 ContactGroup::ContactReference::ContactReference()
00053   : d( new ContactReferencePrivate )
00054 {
00055 }
00056 
00057 ContactGroup::ContactReference::ContactReference( const ContactReference &other )
00058   : d( other.d )
00059 {
00060 }
00061 
00062 ContactGroup::ContactReference::ContactReference( const QString &uid )
00063   : d( new ContactReferencePrivate )
00064 {
00065   d->mUid = uid;
00066 }
00067 
00068 ContactGroup::ContactReference::~ContactReference()
00069 {
00070 }
00071 
00072 void ContactGroup::ContactReference::setUid( const QString &uid )
00073 {
00074   d->mUid = uid;
00075 }
00076 
00077 QString ContactGroup::ContactReference::uid() const
00078 {
00079   return d->mUid;
00080 }
00081 
00082 void ContactGroup::ContactReference::setPreferredEmail( const QString &email )
00083 {
00084   d->mPreferredEmail = email;
00085 }
00086 
00087 QString ContactGroup::ContactReference::preferredEmail() const
00088 {
00089   return d->mPreferredEmail;
00090 }
00091 
00092 void ContactGroup::ContactReference::insertCustom( const QString &key, const QString &value )
00093 {
00094   d->mCustoms.insert( key, value );
00095 }
00096 
00097 void ContactGroup::ContactReference::removeCustom( const QString &key )
00098 {
00099   d->mCustoms.remove( key );
00100 }
00101 
00102 QString ContactGroup::ContactReference::custom( const QString &key ) const
00103 {
00104   return d->mCustoms.value( key );
00105 }
00106 
00107 ContactGroup::ContactReference &ContactGroup::ContactReference::operator=( const ContactGroup::ContactReference &other )
00108 {
00109   if ( this != &other ) {
00110     d = other.d;
00111   }
00112 
00113   return *this;
00114 }
00115 
00116 bool ContactGroup::ContactReference::operator==( const ContactReference &other ) const
00117 {
00118   return d->mUid == other.d->mUid &&
00119     d->mPreferredEmail == other.d->mPreferredEmail &&
00120     d->mCustoms == other.d->mCustoms;
00121 }
00122 
00123 class ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData
00124 {
00125   public:
00126     ContactGroupReferencePrivate()
00127       : QSharedData()
00128     {
00129     }
00130 
00131     ContactGroupReferencePrivate( const ContactGroupReferencePrivate &other )
00132       : QSharedData( other )
00133     {
00134       mUid = other.mUid;
00135       mCustoms = other.mCustoms;
00136     }
00137 
00138     QString mUid;
00139     QMap<QString, QString> mCustoms;
00140 };
00141 
00142 ContactGroup::ContactGroupReference::ContactGroupReference()
00143   : d( new ContactGroupReferencePrivate )
00144 {
00145 }
00146 
00147 ContactGroup::ContactGroupReference::ContactGroupReference( const ContactGroupReference &other )
00148   : d( other.d )
00149 {
00150 }
00151 
00152 ContactGroup::ContactGroupReference::ContactGroupReference( const QString &uid )
00153   : d( new ContactGroupReferencePrivate )
00154 {
00155   d->mUid = uid;
00156 }
00157 
00158 ContactGroup::ContactGroupReference::~ContactGroupReference()
00159 {
00160 }
00161 
00162 void ContactGroup::ContactGroupReference::setUid( const QString &uid )
00163 {
00164   d->mUid = uid;
00165 }
00166 
00167 QString ContactGroup::ContactGroupReference::uid() const
00168 {
00169   return d->mUid;
00170 }
00171 
00172 void ContactGroup::ContactGroupReference::insertCustom( const QString &key, const QString &value )
00173 {
00174   d->mCustoms.insert( key, value );
00175 }
00176 
00177 void ContactGroup::ContactGroupReference::removeCustom( const QString &key )
00178 {
00179   d->mCustoms.remove( key );
00180 }
00181 
00182 QString ContactGroup::ContactGroupReference::custom( const QString &key ) const
00183 {
00184   return d->mCustoms.value( key );
00185 }
00186 
00187 ContactGroup::ContactGroupReference &ContactGroup::ContactGroupReference::operator=( const ContactGroup::ContactGroupReference &other )
00188 {
00189   if ( this != &other ) {
00190     d = other.d;
00191   }
00192 
00193   return *this;
00194 }
00195 
00196 bool ContactGroup::ContactGroupReference::operator==( const ContactGroupReference &other ) const
00197 {
00198   return d->mUid == other.d->mUid &&
00199     d->mCustoms == other.d->mCustoms;
00200 }
00201 
00202 class ContactGroup::Data::DataPrivate : public QSharedData
00203 {
00204   public:
00205     DataPrivate()
00206       : QSharedData()
00207     {
00208     }
00209 
00210     DataPrivate( const DataPrivate &other )
00211       : QSharedData( other )
00212     {
00213       mName = other.mName;
00214       mEmail = other.mEmail;
00215       mCustoms = other.mCustoms;
00216     }
00217 
00218     QString mName;
00219     QString mEmail;
00220     QMap<QString, QString> mCustoms;
00221 };
00222 
00223 ContactGroup::Data::Data()
00224   : d( new DataPrivate )
00225 {
00226 }
00227 
00228 ContactGroup::Data::Data( const Data &other )
00229   : d( other.d )
00230 {
00231 }
00232 
00233 ContactGroup::Data::Data( const QString &name, const QString &email )
00234   : d( new DataPrivate )
00235 {
00236   d->mName = name;
00237   d->mEmail = email;
00238 }
00239 
00240 ContactGroup::Data::~Data()
00241 {
00242 }
00243 
00244 void ContactGroup::Data::setName( const QString &name )
00245 {
00246   d->mName = name;
00247 }
00248 
00249 QString ContactGroup::Data::name() const
00250 {
00251   return d->mName;
00252 }
00253 
00254 void ContactGroup::Data::setEmail( const QString &email )
00255 {
00256   d->mEmail = email;
00257 }
00258 
00259 QString ContactGroup::Data::email() const
00260 {
00261   return d->mEmail;
00262 }
00263 
00264 void ContactGroup::Data::insertCustom( const QString &key, const QString &value )
00265 {
00266   d->mCustoms.insert( key, value );
00267 }
00268 
00269 void ContactGroup::Data::removeCustom( const QString &key )
00270 {
00271   d->mCustoms.remove( key );
00272 }
00273 
00274 QString ContactGroup::Data::custom( const QString &key ) const
00275 {
00276   return d->mCustoms.value( key );
00277 }
00278 
00279 ContactGroup::Data &ContactGroup::Data::operator=( const ContactGroup::Data &other )
00280 {
00281   if ( this != &other ) {
00282     d = other.d;
00283   }
00284 
00285   return *this;
00286 }
00287 
00288 bool ContactGroup::Data::operator==( const Data &other ) const
00289 {
00290   return d->mName == other.d->mName &&
00291     d->mEmail == other.d->mEmail &&
00292     d->mCustoms == other.d->mCustoms;
00293 }
00294 
00295 class ContactGroup::Private : public QSharedData
00296 {
00297   public:
00298     Private()
00299       : QSharedData(),
00300         mIdentifier( QUuid::createUuid().toString() )
00301     {
00302     }
00303 
00304     Private( const Private &other )
00305       : QSharedData( other )
00306     {
00307       mIdentifier = other.mIdentifier;
00308       mName = other.mName;
00309       mContactReferences = other.mContactReferences;
00310       mContactGroupReferences = other.mContactGroupReferences;
00311       mDataObjects = other.mDataObjects;
00312     }
00313 
00314     QString mIdentifier;
00315     QString mName;
00316     ContactGroup::ContactReference::List mContactReferences;
00317     ContactGroup::ContactGroupReference::List mContactGroupReferences;
00318     ContactGroup::Data::List mDataObjects;
00319 };
00320 
00321 ContactGroup::ContactGroup()
00322   : d( new Private )
00323 {
00324 }
00325 
00326 ContactGroup::ContactGroup( const ContactGroup &other )
00327   : d( other.d )
00328 {
00329 }
00330 
00331 ContactGroup::ContactGroup( const QString &name )
00332   : d( new Private )
00333 {
00334   d->mName = name;
00335 }
00336 
00337 ContactGroup::~ContactGroup()
00338 {
00339 }
00340 
00341 void ContactGroup::setName( const QString &name )
00342 {
00343   d->mName = name;
00344 }
00345 
00346 QString ContactGroup::name() const
00347 {
00348   return d->mName;
00349 }
00350 
00351 void ContactGroup::setId( const QString &id )
00352 {
00353   d->mIdentifier = id;
00354 }
00355 
00356 QString ContactGroup::id() const
00357 {
00358   return d->mIdentifier;
00359 }
00360 
00361 unsigned int ContactGroup::count() const
00362 {
00363   return d->mContactReferences.count() + d->mDataObjects.count();
00364 }
00365 
00366 unsigned int ContactGroup::contactReferenceCount() const
00367 {
00368   return d->mContactReferences.count();
00369 }
00370 
00371 unsigned int ContactGroup::contactGroupReferenceCount() const
00372 {
00373   return d->mContactGroupReferences.count();
00374 }
00375 
00376 unsigned int ContactGroup::dataCount() const
00377 {
00378   return d->mDataObjects.count();
00379 }
00380 
00381 ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index )
00382 {
00383   Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(), "contactReference()", "index out of range" );
00384 
00385   return d->mContactReferences[ index ];
00386 }
00387 
00388 const ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index ) const
00389 {
00390   Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(), "contactReference()", "index out of range" );
00391 
00392   return d->mContactReferences[ index ];
00393 }
00394 
00395 ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference( unsigned int index )
00396 {
00397   Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(), "contactGroupReference()", "index out of range" );
00398 
00399   return d->mContactGroupReferences[ index ];
00400 }
00401 
00402 const ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference( unsigned int index ) const
00403 {
00404   Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(), "contactGroupReference()", "index out of range" );
00405 
00406   return d->mContactGroupReferences[ index ];
00407 }
00408 
00409 ContactGroup::Data &ContactGroup::data( unsigned int index )
00410 {
00411   Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" );
00412 
00413   return d->mDataObjects[ index ];
00414 }
00415 
00416 const ContactGroup::Data &ContactGroup::data( unsigned int index ) const
00417 {
00418   Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" );
00419 
00420   return d->mDataObjects[ index ];
00421 }
00422 
00423 void ContactGroup::append( const ContactReference &reference )
00424 {
00425   d->mContactReferences.append( reference );
00426 }
00427 
00428 void ContactGroup::append( const ContactGroupReference &reference )
00429 {
00430   d->mContactGroupReferences.append( reference );
00431 }
00432 
00433 void ContactGroup::append( const Data &data )
00434 {
00435   d->mDataObjects.append( data );
00436 }
00437 
00438 void ContactGroup::remove( const ContactReference &reference )
00439 {
00440   d->mContactReferences.removeOne( reference );
00441 }
00442 
00443 void ContactGroup::remove( const ContactGroupReference &reference )
00444 {
00445   d->mContactGroupReferences.removeOne( reference );
00446 }
00447 
00448 void ContactGroup::remove( const Data &data )
00449 {
00450   d->mDataObjects.removeOne( data );
00451 }
00452 
00453 void ContactGroup::removeAllContactReferences()
00454 {
00455   d->mContactReferences.clear();
00456 }
00457 
00458 void ContactGroup::removeAllContactGroupReferences()
00459 {
00460   d->mContactGroupReferences.clear();
00461 }
00462 
00463 void ContactGroup::removeAllContactData()
00464 {
00465   d->mDataObjects.clear();
00466 }
00467 
00468 ContactGroup &ContactGroup::operator=( const ContactGroup &other )
00469 {
00470   if ( this != &other ) {
00471     d = other.d;
00472   }
00473 
00474   return *this;
00475 }
00476 
00477 bool ContactGroup::operator==( const ContactGroup &other ) const
00478 {
00479   return d->mIdentifier == other.d->mIdentifier &&
00480     d->mName == other.d->mName &&
00481     d->mContactReferences == other.d->mContactReferences &&
00482     d->mContactGroupReferences == other.d->mContactGroupReferences &&
00483     d->mDataObjects == other.d->mDataObjects;
00484 }
00485 
00486 QString ContactGroup::mimeType()
00487 {
00488   return QLatin1String( "application/x-vnd.kde.contactgroup" );
00489 }

kabc

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal