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=( 00108 const ContactGroup::ContactReference &other ) 00109 { 00110 if ( this != &other ) { 00111 d = other.d; 00112 } 00113 00114 return *this; 00115 } 00116 00117 bool ContactGroup::ContactReference::operator==( const ContactReference &other ) const 00118 { 00119 return d->mUid == other.d->mUid && 00120 d->mPreferredEmail == other.d->mPreferredEmail && 00121 d->mCustoms == other.d->mCustoms; 00122 } 00123 00124 class ContactGroup::ContactGroupReference::ContactGroupReferencePrivate : public QSharedData 00125 { 00126 public: 00127 ContactGroupReferencePrivate() 00128 : QSharedData() 00129 { 00130 } 00131 00132 ContactGroupReferencePrivate( const ContactGroupReferencePrivate &other ) 00133 : QSharedData( other ) 00134 { 00135 mUid = other.mUid; 00136 mCustoms = other.mCustoms; 00137 } 00138 00139 QString mUid; 00140 QMap<QString, QString> mCustoms; 00141 }; 00142 00143 ContactGroup::ContactGroupReference::ContactGroupReference() 00144 : d( new ContactGroupReferencePrivate ) 00145 { 00146 } 00147 00148 ContactGroup::ContactGroupReference::ContactGroupReference( const ContactGroupReference &other ) 00149 : d( other.d ) 00150 { 00151 } 00152 00153 ContactGroup::ContactGroupReference::ContactGroupReference( const QString &uid ) 00154 : d( new ContactGroupReferencePrivate ) 00155 { 00156 d->mUid = uid; 00157 } 00158 00159 ContactGroup::ContactGroupReference::~ContactGroupReference() 00160 { 00161 } 00162 00163 void ContactGroup::ContactGroupReference::setUid( const QString &uid ) 00164 { 00165 d->mUid = uid; 00166 } 00167 00168 QString ContactGroup::ContactGroupReference::uid() const 00169 { 00170 return d->mUid; 00171 } 00172 00173 void ContactGroup::ContactGroupReference::insertCustom( const QString &key, const QString &value ) 00174 { 00175 d->mCustoms.insert( key, value ); 00176 } 00177 00178 void ContactGroup::ContactGroupReference::removeCustom( const QString &key ) 00179 { 00180 d->mCustoms.remove( key ); 00181 } 00182 00183 QString ContactGroup::ContactGroupReference::custom( const QString &key ) const 00184 { 00185 return d->mCustoms.value( key ); 00186 } 00187 00188 ContactGroup::ContactGroupReference &ContactGroup::ContactGroupReference::operator=( 00189 const ContactGroup::ContactGroupReference &other ) 00190 { 00191 if ( this != &other ) { 00192 d = other.d; 00193 } 00194 00195 return *this; 00196 } 00197 00198 bool ContactGroup::ContactGroupReference::operator==( const ContactGroupReference &other ) const 00199 { 00200 return d->mUid == other.d->mUid && 00201 d->mCustoms == other.d->mCustoms; 00202 } 00203 00204 class ContactGroup::Data::DataPrivate : public QSharedData 00205 { 00206 public: 00207 DataPrivate() 00208 : QSharedData() 00209 { 00210 } 00211 00212 DataPrivate( const DataPrivate &other ) 00213 : QSharedData( other ) 00214 { 00215 mName = other.mName; 00216 mEmail = other.mEmail; 00217 mCustoms = other.mCustoms; 00218 } 00219 00220 QString mName; 00221 QString mEmail; 00222 QMap<QString, QString> mCustoms; 00223 }; 00224 00225 ContactGroup::Data::Data() 00226 : d( new DataPrivate ) 00227 { 00228 } 00229 00230 ContactGroup::Data::Data( const Data &other ) 00231 : d( other.d ) 00232 { 00233 } 00234 00235 ContactGroup::Data::Data( const QString &name, const QString &email ) 00236 : d( new DataPrivate ) 00237 { 00238 d->mName = name; 00239 d->mEmail = email; 00240 } 00241 00242 ContactGroup::Data::~Data() 00243 { 00244 } 00245 00246 void ContactGroup::Data::setName( const QString &name ) 00247 { 00248 d->mName = name; 00249 } 00250 00251 QString ContactGroup::Data::name() const 00252 { 00253 return d->mName; 00254 } 00255 00256 void ContactGroup::Data::setEmail( const QString &email ) 00257 { 00258 d->mEmail = email; 00259 } 00260 00261 QString ContactGroup::Data::email() const 00262 { 00263 return d->mEmail; 00264 } 00265 00266 void ContactGroup::Data::insertCustom( const QString &key, const QString &value ) 00267 { 00268 d->mCustoms.insert( key, value ); 00269 } 00270 00271 void ContactGroup::Data::removeCustom( const QString &key ) 00272 { 00273 d->mCustoms.remove( key ); 00274 } 00275 00276 QString ContactGroup::Data::custom( const QString &key ) const 00277 { 00278 return d->mCustoms.value( key ); 00279 } 00280 00281 ContactGroup::Data &ContactGroup::Data::operator=( const ContactGroup::Data &other ) 00282 { 00283 if ( this != &other ) { 00284 d = other.d; 00285 } 00286 00287 return *this; 00288 } 00289 00290 bool ContactGroup::Data::operator==( const Data &other ) const 00291 { 00292 return d->mName == other.d->mName && 00293 d->mEmail == other.d->mEmail && 00294 d->mCustoms == other.d->mCustoms; 00295 } 00296 00297 class ContactGroup::Private : public QSharedData 00298 { 00299 public: 00300 Private() 00301 : QSharedData(), 00302 mIdentifier( QUuid::createUuid().toString() ) 00303 { 00304 } 00305 00306 Private( const Private &other ) 00307 : QSharedData( other ) 00308 { 00309 mIdentifier = other.mIdentifier; 00310 mName = other.mName; 00311 mContactReferences = other.mContactReferences; 00312 mContactGroupReferences = other.mContactGroupReferences; 00313 mDataObjects = other.mDataObjects; 00314 } 00315 00316 QString mIdentifier; 00317 QString mName; 00318 ContactGroup::ContactReference::List mContactReferences; 00319 ContactGroup::ContactGroupReference::List mContactGroupReferences; 00320 ContactGroup::Data::List mDataObjects; 00321 }; 00322 00323 ContactGroup::ContactGroup() 00324 : d( new Private ) 00325 { 00326 } 00327 00328 ContactGroup::ContactGroup( const ContactGroup &other ) 00329 : d( other.d ) 00330 { 00331 } 00332 00333 ContactGroup::ContactGroup( const QString &name ) 00334 : d( new Private ) 00335 { 00336 d->mName = name; 00337 } 00338 00339 ContactGroup::~ContactGroup() 00340 { 00341 } 00342 00343 void ContactGroup::setName( const QString &name ) 00344 { 00345 d->mName = name; 00346 } 00347 00348 QString ContactGroup::name() const 00349 { 00350 return d->mName; 00351 } 00352 00353 void ContactGroup::setId( const QString &id ) 00354 { 00355 d->mIdentifier = id; 00356 } 00357 00358 QString ContactGroup::id() const 00359 { 00360 return d->mIdentifier; 00361 } 00362 00363 unsigned int ContactGroup::count() const 00364 { 00365 return d->mContactReferences.count() + d->mDataObjects.count(); 00366 } 00367 00368 unsigned int ContactGroup::contactReferenceCount() const 00369 { 00370 return d->mContactReferences.count(); 00371 } 00372 00373 unsigned int ContactGroup::contactGroupReferenceCount() const 00374 { 00375 return d->mContactGroupReferences.count(); 00376 } 00377 00378 unsigned int ContactGroup::dataCount() const 00379 { 00380 return d->mDataObjects.count(); 00381 } 00382 00383 ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index ) 00384 { 00385 Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(), 00386 "contactReference()", "index out of range" ); 00387 00388 return d->mContactReferences[ index ]; 00389 } 00390 00391 const ContactGroup::ContactReference &ContactGroup::contactReference( unsigned int index ) const 00392 { 00393 Q_ASSERT_X( index < (unsigned int)d->mContactReferences.count(), 00394 "contactReference()", "index out of range" ); 00395 00396 return d->mContactReferences[ index ]; 00397 } 00398 00399 ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference( unsigned int index ) 00400 { 00401 Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(), 00402 "contactGroupReference()", "index out of range" ); 00403 00404 return d->mContactGroupReferences[ index ]; 00405 } 00406 00407 const ContactGroup::ContactGroupReference &ContactGroup::contactGroupReference( 00408 unsigned int index ) const 00409 { 00410 Q_ASSERT_X( index < (unsigned int)d->mContactGroupReferences.count(), 00411 "contactGroupReference()", "index out of range" ); 00412 00413 return d->mContactGroupReferences[ index ]; 00414 } 00415 00416 ContactGroup::Data &ContactGroup::data( unsigned int index ) 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 const ContactGroup::Data &ContactGroup::data( unsigned int index ) const 00424 { 00425 Q_ASSERT_X( index < (unsigned int)d->mDataObjects.count(), "data()", "index out of range" ); 00426 00427 return d->mDataObjects[ index ]; 00428 } 00429 00430 void ContactGroup::append( const ContactReference &reference ) 00431 { 00432 d->mContactReferences.append( reference ); 00433 } 00434 00435 void ContactGroup::append( const ContactGroupReference &reference ) 00436 { 00437 d->mContactGroupReferences.append( reference ); 00438 } 00439 00440 void ContactGroup::append( const Data &data ) 00441 { 00442 d->mDataObjects.append( data ); 00443 } 00444 00445 void ContactGroup::remove( const ContactReference &reference ) 00446 { 00447 d->mContactReferences.removeOne( reference ); 00448 } 00449 00450 void ContactGroup::remove( const ContactGroupReference &reference ) 00451 { 00452 d->mContactGroupReferences.removeOne( reference ); 00453 } 00454 00455 void ContactGroup::remove( const Data &data ) 00456 { 00457 d->mDataObjects.removeOne( data ); 00458 } 00459 00460 void ContactGroup::removeAllContactReferences() 00461 { 00462 d->mContactReferences.clear(); 00463 } 00464 00465 void ContactGroup::removeAllContactGroupReferences() 00466 { 00467 d->mContactGroupReferences.clear(); 00468 } 00469 00470 void ContactGroup::removeAllContactData() 00471 { 00472 d->mDataObjects.clear(); 00473 } 00474 00475 ContactGroup &ContactGroup::operator=( const ContactGroup &other ) 00476 { 00477 if ( this != &other ) { 00478 d = other.d; 00479 } 00480 00481 return *this; 00482 } 00483 00484 bool ContactGroup::operator==( const ContactGroup &other ) const 00485 { 00486 return d->mIdentifier == other.d->mIdentifier && 00487 d->mName == other.d->mName && 00488 d->mContactReferences == other.d->mContactReferences && 00489 d->mContactGroupReferences == other.d->mContactGroupReferences && 00490 d->mDataObjects == other.d->mDataObjects; 00491 } 00492 00493 QString ContactGroup::mimeType() 00494 { 00495 return QLatin1String( "application/x-vnd.kde.contactgroup" ); 00496 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:10:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:10:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.