summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 0838157..20310a0 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -211,52 +211,59 @@ bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
212{ 212{
213 return ( d->mIt != it.d->mIt ); 213 return ( d->mIt != it.d->mIt );
214} 214}
215 215
216 216
217AddressBook::AddressBook() 217AddressBook::AddressBook()
218{ 218{
219 init(0); 219 init(0, "contact");
220} 220}
221 221
222AddressBook::AddressBook( const QString &config ) 222AddressBook::AddressBook( const QString &config )
223{ 223{
224 init(config); 224 init(config, "contact");
225} 225}
226 226
227void AddressBook::init(const QString &config) 227AddressBook::AddressBook( const QString &config, const QString &family )
228{
229 init(config, family);
230
231}
232
233// the default family is "contact"
234void AddressBook::init(const QString &config, const QString &family )
228{ 235{
229 d = new AddressBookData; 236 d = new AddressBookData;
230 if (config != 0) { 237 if (config != 0) {
231 d->mConfig = new KConfig( config ); 238 d->mConfig = new KConfig( config );
232// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 239// qDebug("AddressBook::init 1 config=%s",config.latin1() );
233 } 240 }
234 else { 241 else {
235 d->mConfig = 0; 242 d->mConfig = 0;
236// qDebug("AddressBook::init 1 config=0"); 243// qDebug("AddressBook::init 1 config=0");
237 } 244 }
238 245
239//US d->mErrorHandler = 0; 246//US d->mErrorHandler = 0;
240 d->mManager = new KRES::Manager<Resource>( "contact" ); 247 d->mManager = new KRES::Manager<Resource>( family, false );
241 d->mManager->readConfig( d->mConfig ); 248 d->mManager->readConfig( d->mConfig );
242} 249}
243 250
244AddressBook::~AddressBook() 251AddressBook::~AddressBook()
245{ 252{
246 delete d->mConfig; d->mConfig = 0; 253 delete d->mConfig; d->mConfig = 0;
247 delete d->mManager; d->mManager = 0; 254 delete d->mManager; d->mManager = 0;
248//US delete d->mErrorHandler; d->mErrorHandler = 0; 255//US delete d->mErrorHandler; d->mErrorHandler = 0;
249 delete d; d = 0; 256 delete d; d = 0;
250} 257}
251 258
252bool AddressBook::load() 259bool AddressBook::load()
253{ 260{
254 261
255 262
256 clear(); 263 clear();
257 264
258 KRES::Manager<Resource>::ActiveIterator it; 265 KRES::Manager<Resource>::ActiveIterator it;
259 bool ok = true; 266 bool ok = true;
260 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 267 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
261 if ( !(*it)->load() ) { 268 if ( !(*it)->load() ) {
262 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 269 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
@@ -272,17 +279,17 @@ bool AddressBook::load()
272} 279}
273 280
274bool AddressBook::save( Ticket *ticket ) 281bool AddressBook::save( Ticket *ticket )
275{ 282{
276 kdDebug(5700) << "AddressBook::save()"<< endl; 283 kdDebug(5700) << "AddressBook::save()"<< endl;
277 284
278 if ( ticket->resource() ) { 285 if ( ticket->resource() ) {
279 deleteRemovedAddressees(); 286 deleteRemovedAddressees();
280 287
281 return ticket->resource()->save( ticket ); 288 return ticket->resource()->save( ticket );
282 } 289 }
283 290
284 return false; 291 return false;
285} 292}
286 293
287AddressBook::Iterator AddressBook::begin() 294AddressBook::Iterator AddressBook::begin()
288{ 295{
@@ -351,17 +358,17 @@ void AddressBook::insertAddressee( const Addressee &a )
351 changed = true; 358 changed = true;
352 359
353 (*it) = a; 360 (*it) = a;
354 if ( (*it).resource() == 0 ) 361 if ( (*it).resource() == 0 )
355 (*it).setResource( standardResource() ); 362 (*it).setResource( standardResource() );
356 363
357 if ( changed ) { 364 if ( changed ) {
358 (*it).setRevision( QDateTime::currentDateTime() ); 365 (*it).setRevision( QDateTime::currentDateTime() );
359 (*it).setChanged( true ); 366 (*it).setChanged( true );
360 } 367 }
361 368
362 return; 369 return;
363 } 370 }
364 } 371 }
365 d->mAddressees.append( a ); 372 d->mAddressees.append( a );
366 Addressee& addr = d->mAddressees.last(); 373 Addressee& addr = d->mAddressees.last();
367 if ( addr.resource() == 0 ) 374 if ( addr.resource() == 0 )
@@ -430,17 +437,17 @@ Addressee::List AddressBook::findByName( const QString &name )
430 437
431Addressee::List AddressBook::findByEmail( const QString &email ) 438Addressee::List AddressBook::findByEmail( const QString &email )
432{ 439{
433 Addressee::List results; 440 Addressee::List results;
434 QStringList mailList; 441 QStringList mailList;
435 442
436 Iterator it; 443 Iterator it;
437 for ( it = begin(); it != end(); ++it ) { 444 for ( it = begin(); it != end(); ++it ) {
438 mailList = (*it).emails(); 445 mailList = (*it).emails();
439 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 446 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
440 if ( email == (*ite) ) { 447 if ( email == (*ite) ) {
441 results.append( *it ); 448 results.append( *it );
442 } 449 }
443 } 450 }
444 } 451 }
445 452
446 return results; 453 return results;
@@ -486,25 +493,25 @@ QString AddressBook::identifier()
486 return identifier.join( ":" ); 493 return identifier.join( ":" );
487} 494}
488 495
489Field::List AddressBook::fields( int category ) 496Field::List AddressBook::fields( int category )
490{ 497{
491 if ( d->mAllFields.isEmpty() ) { 498 if ( d->mAllFields.isEmpty() ) {
492 d->mAllFields = Field::allFields(); 499 d->mAllFields = Field::allFields();
493 } 500 }
494 501
495 if ( category == Field::All ) return d->mAllFields; 502 if ( category == Field::All ) return d->mAllFields;
496 503
497 Field::List result; 504 Field::List result;
498 Field::List::ConstIterator it; 505 Field::List::ConstIterator it;
499 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 506 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
500 if ( (*it)->category() & category ) result.append( *it ); 507 if ( (*it)->category() & category ) result.append( *it );
501 } 508 }
502 509
503 return result; 510 return result;
504} 511}
505 512
506bool AddressBook::addCustomField( const QString &label, int category, 513bool AddressBook::addCustomField( const QString &label, int category,
507 const QString &key, const QString &app ) 514 const QString &key, const QString &app )
508{ 515{
509 if ( d->mAllFields.isEmpty() ) { 516 if ( d->mAllFields.isEmpty() ) {
510 d->mAllFields = Field::allFields(); 517 d->mAllFields = Field::allFields();
@@ -536,18 +543,16 @@ QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
536 543
537 s >> ab.d->mAddressees; 544 s >> ab.d->mAddressees;
538 545
539 return s; 546 return s;
540} 547}
541 548
542bool AddressBook::addResource( Resource *resource ) 549bool AddressBook::addResource( Resource *resource )
543{ 550{
544 qDebug("AddressBook::addResource 1");
545
546 if ( !resource->open() ) { 551 if ( !resource->open() ) {
547 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 552 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
548 return false; 553 return false;
549 } 554 }
550 555
551 resource->setAddressBook( this ); 556 resource->setAddressBook( this );
552 557
553 d->mManager->add( resource ); 558 d->mManager->add( resource );
@@ -567,17 +572,17 @@ bool AddressBook::removeResource( Resource *resource )
567 return true; 572 return true;
568} 573}
569 574
570QPtrList<Resource> AddressBook::resources() 575QPtrList<Resource> AddressBook::resources()
571{ 576{
572 QPtrList<Resource> list; 577 QPtrList<Resource> list;
573 578
574// qDebug("AddressBook::resources() 1"); 579// qDebug("AddressBook::resources() 1");
575 580
576 KRES::Manager<Resource>::ActiveIterator it; 581 KRES::Manager<Resource>::ActiveIterator it;
577 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 582 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
578 list.append( *it ); 583 list.append( *it );
579 584
580 return list; 585 return list;
581} 586}
582 587
583/*US 588/*US