kabc Library API Documentation

resource.cpp

00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include <kdebug.h> 00022 #include <klocale.h> 00023 00024 #include "resource.h" 00025 00026 using namespace KABC; 00027 00028 Ticket::Ticket( Resource *resource ) 00029 : mResource( resource ) 00030 { 00031 } 00032 00033 Ticket::~Ticket() 00034 { 00035 /* FIXME: avoid cycle deletion 00036 if ( mResource ) 00037 mResource->releaseSaveTicket( this ); 00038 */ 00039 } 00040 00041 Resource *Ticket::resource() 00042 { 00043 return mResource; 00044 } 00045 00046 struct Resource::Iterator::IteratorData 00047 { 00048 Addressee::Map::Iterator mIt; 00049 }; 00050 00051 struct Resource::ConstIterator::ConstIteratorData 00052 { 00053 Addressee::Map::ConstIterator mIt; 00054 }; 00055 00056 Resource::Iterator::Iterator() 00057 { 00058 d = new IteratorData; 00059 } 00060 00061 Resource::Iterator::Iterator( const Resource::Iterator &i ) 00062 { 00063 d = new IteratorData; 00064 d->mIt = i.d->mIt; 00065 } 00066 00067 Resource::Iterator &Resource::Iterator::operator=( const Resource::Iterator &i ) 00068 { 00069 if ( this == &i ) 00070 return *this; 00071 delete d; 00072 00073 d = new IteratorData; 00074 d->mIt = i.d->mIt; 00075 return *this; 00076 } 00077 00078 Resource::Iterator::~Iterator() 00079 { 00080 delete d; 00081 } 00082 00083 const Addressee &Resource::Iterator::operator*() const 00084 { 00085 return d->mIt.data(); 00086 } 00087 00088 Addressee &Resource::Iterator::operator*() 00089 { 00090 return d->mIt.data(); 00091 } 00092 00093 Resource::Iterator &Resource::Iterator::operator++() 00094 { 00095 (d->mIt)++; 00096 return *this; 00097 } 00098 00099 Resource::Iterator &Resource::Iterator::operator++( int ) 00100 { 00101 (d->mIt)++; 00102 return *this; 00103 } 00104 00105 Resource::Iterator &Resource::Iterator::operator--() 00106 { 00107 (d->mIt)--; 00108 return *this; 00109 } 00110 00111 Resource::Iterator &Resource::Iterator::operator--( int ) 00112 { 00113 (d->mIt)--; 00114 return *this; 00115 } 00116 00117 bool Resource::Iterator::operator==( const Iterator &it ) 00118 { 00119 return ( d->mIt == it.d->mIt ); 00120 } 00121 00122 bool Resource::Iterator::operator!=( const Iterator &it ) 00123 { 00124 return ( d->mIt != it.d->mIt ); 00125 } 00126 00127 Resource::ConstIterator::ConstIterator() 00128 { 00129 d = new ConstIteratorData; 00130 } 00131 00132 Resource::ConstIterator::ConstIterator( const Resource::ConstIterator &i ) 00133 { 00134 d = new ConstIteratorData; 00135 d->mIt = i.d->mIt; 00136 } 00137 00138 Resource::ConstIterator::ConstIterator( const Resource::Iterator &i ) 00139 { 00140 d = new ConstIteratorData; 00141 d->mIt = i.d->mIt; 00142 } 00143 00144 Resource::ConstIterator &Resource::ConstIterator::operator=( const Resource::ConstIterator &i ) 00145 { 00146 if ( this == &i ) 00147 return *this; 00148 delete d; 00149 00150 d = new ConstIteratorData; 00151 d->mIt = i.d->mIt; 00152 return *this; 00153 } 00154 00155 Resource::ConstIterator::~ConstIterator() 00156 { 00157 delete d; 00158 } 00159 00160 const Addressee &Resource::ConstIterator::operator*() const 00161 { 00162 return *(d->mIt); 00163 } 00164 00165 Resource::ConstIterator &Resource::ConstIterator::operator++() 00166 { 00167 (d->mIt)++; 00168 return *this; 00169 } 00170 00171 Resource::ConstIterator &Resource::ConstIterator::operator++( int ) 00172 { 00173 (d->mIt)++; 00174 return *this; 00175 } 00176 00177 Resource::ConstIterator &Resource::ConstIterator::operator--() 00178 { 00179 (d->mIt)--; 00180 return *this; 00181 } 00182 00183 Resource::ConstIterator &Resource::ConstIterator::operator--( int ) 00184 { 00185 (d->mIt)--; 00186 return *this; 00187 } 00188 00189 bool Resource::ConstIterator::operator==( const ConstIterator &it ) 00190 { 00191 return ( d->mIt == it.d->mIt ); 00192 } 00193 00194 bool Resource::ConstIterator::operator!=( const ConstIterator &it ) 00195 { 00196 return ( d->mIt != it.d->mIt ); 00197 } 00198 00199 00200 Resource::Resource( const KConfig *config ) 00201 : KRES::Resource( config ), mAddressBook( 0 ) 00202 { 00203 } 00204 00205 Resource::~Resource() 00206 { 00207 } 00208 00209 Resource::Iterator Resource::begin() 00210 { 00211 Iterator it; 00212 it.d->mIt = mAddrMap.begin(); 00213 00214 return it; 00215 } 00216 00217 Resource::ConstIterator Resource::begin() const 00218 { 00219 ConstIterator it; 00220 #if QT_VERSION >= 0x030200 00221 it.d->mIt = mAddrMap.constBegin(); 00222 #else 00223 it.d->mIt = mAddrMap.begin(); 00224 #endif 00225 00226 return it; 00227 } 00228 00229 Resource::Iterator Resource::end() 00230 { 00231 Iterator it; 00232 it.d->mIt = mAddrMap.end(); 00233 00234 return it; 00235 } 00236 00237 Resource::ConstIterator Resource::end() const 00238 { 00239 ConstIterator it; 00240 #if QT_VERSION >= 0x030200 00241 it.d->mIt = mAddrMap.constEnd(); 00242 #else 00243 it.d->mIt = mAddrMap.end(); 00244 #endif 00245 00246 return it; 00247 } 00248 00249 void Resource::writeConfig( KConfig *config ) 00250 { 00251 KRES::Resource::writeConfig( config ); 00252 } 00253 00254 void Resource::setAddressBook( AddressBook *ab ) 00255 { 00256 mAddressBook = ab; 00257 } 00258 00259 AddressBook *Resource::addressBook() 00260 { 00261 return mAddressBook; 00262 } 00263 00264 Ticket *Resource::createTicket( Resource *resource ) 00265 { 00266 return new Ticket( resource ); 00267 } 00268 00269 void Resource::insertAddressee( const Addressee &addr ) 00270 { 00271 mAddrMap.insert( addr.uid(), addr ); 00272 } 00273 00274 void Resource::removeAddressee( const Addressee &addr ) 00275 { 00276 mAddrMap.erase( addr.uid() ); 00277 } 00278 00279 Addressee Resource::findByUid( const QString &uid ) 00280 { 00281 Addressee::Map::ConstIterator it = mAddrMap.find( uid ); 00282 00283 if ( it != mAddrMap.end() ) 00284 return it.data(); 00285 00286 return Addressee(); 00287 } 00288 00289 Addressee::List Resource::findByName( const QString &name ) 00290 { 00291 Addressee::List results; 00292 00293 ConstIterator it; 00294 for ( it = begin(); it != end(); ++it ) { 00295 if ( name == (*it).name() ) 00296 results.append( *it ); 00297 } 00298 00299 return results; 00300 } 00301 00302 Addressee::List Resource::findByEmail( const QString &email ) 00303 { 00304 Addressee::List results; 00305 const QString lowerEmail = email.lower(); 00306 00307 ConstIterator it; 00308 for ( it = begin(); it != end(); ++it ) { 00309 const QStringList mailList = (*it).emails(); 00310 for ( QStringList::ConstIterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 00311 if ( lowerEmail == (*ite).lower() ) 00312 results.append( *it ); 00313 } 00314 } 00315 00316 return results; 00317 } 00318 00319 Addressee::List Resource::findByCategory( const QString &category ) 00320 { 00321 Addressee::List results; 00322 00323 ConstIterator it; 00324 for ( it = begin(); it != end(); ++it ) { 00325 if ( (*it).hasCategory( category) ) { 00326 results.append( *it ); 00327 } 00328 } 00329 00330 return results; 00331 } 00332 00333 void Resource::clear() 00334 { 00335 mAddrMap.clear(); 00336 } 00337 00338 bool Resource::asyncLoad() 00339 { 00340 bool ok = load(); 00341 if ( !ok ) 00342 emit loadingError( this, i18n( "Loading resource '%1' failed!" ) 00343 .arg( resourceName() ) ); 00344 else 00345 emit loadingFinished( this ); 00346 00347 return ok; 00348 } 00349 00350 bool Resource::asyncSave( Ticket *ticket ) { 00351 bool ok = save( ticket ); 00352 if ( !ok ) 00353 emit savingError( this, i18n( "Saving resource '%1' failed!" ) 00354 .arg( resourceName() ) ); 00355 else 00356 emit savingFinished( this ); 00357 00358 return ok; 00359 } 00360 00361 #include "resource.moc"
KDE Logo
This file is part of the documentation for kabc Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 14 00:35:18 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003