summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 6194d6d..4c4ae09 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -309,895 +309,889 @@ void AddressBook::init(const QString &config, const QString &family )
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() && (*it).resource()->includeInSync() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 if ( !(*it).IDStr().isEmpty() ) {
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
398 } 398 }
399 KABC::VCardConverter converter; 399 KABC::VCardConverter converter;
400 QString vcard; 400 QString vcard;
401 //Resource *resource() const; 401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version ); 402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n"; 403 t << vcard << "\r\n";
404 } 404 }
405 } 405 }
406 t << "\r\n\r\n"; 406 t << "\r\n\r\n";
407 outFile.close(); 407 outFile.close();
408} 408}
409// if QStringList uids is empty, all are exported 409// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 411{
412 KABC::VCardConverter converter; 412 KABC::VCardConverter converter;
413 QString datastream; 413 QString datastream;
414 Iterator it; 414 Iterator it;
415 bool all = uids.isEmpty(); 415 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count(); 513 return list.count();
514} 514}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
516{ 516{
517 Iterator ait; 517 Iterator ait;
518 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
519 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
521 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
522 } else 522 } else
523 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
524 } else 524 } else
525 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
526 } 526 }
527} 527}
528void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
529{ 529{
530 Iterator ait; 530 Iterator ait;
531 bool todelete = false; 531 bool todelete = false;
532 Iterator todel; 532 Iterator todel;
533 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
534 if ( todelete ) 534 if ( todelete )
535 removeAddressee( todel ); 535 removeAddressee( todel );
536 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
537 todelete = true; 537 todelete = true;
538 todel = ait; 538 todel = ait;
539 } else 539 } else
540 todelete = false; 540 todelete = false;
541 } 541 }
542 if ( todelete ) 542 if ( todelete )
543 removeAddressee( todel ); 543 removeAddressee( todel );
544 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
545} 545}
546void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
547{ 547{
548 Iterator ait; 548 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
554 } 554 }
555} 555}
556void AddressBook::removeSyncInfo( QString syncProfile) 556void AddressBook::removeSyncInfo( QString syncProfile)
557{ 557{
558 Iterator ait; 558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile ); 560 (*ait).removeID( syncProfile );
561 } 561 }
562 if ( syncProfile.isEmpty() ) { 562 if ( syncProfile.isEmpty() ) {
563 Iterator it = begin(); 563 Iterator it = begin();
564 Iterator it2 ; 564 Iterator it2 ;
565 QDateTime dt ( QDate( 2004,1,1) );
566 while ( it != end() ) { 565 while ( it != end() ) {
567 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 566 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
568 it2 = it; 567 it2 = it;
569 //qDebug("removing %s ",(*it).uid().latin1() ); 568 //qDebug("removing %s ",(*it).uid().latin1() );
570 ++it; 569 ++it;
571 removeAddressee( it2 ); 570 removeAddressee( it2 );
572 } else { 571 } else {
573 //qDebug("skipping %s ",(*it).uid().latin1() ); 572 //qDebug("skipping %s ",(*it).uid().latin1() );
574 ++it; 573 ++it;
575 } 574 }
576 } 575 }
577 } else { 576 } else {
578 Addressee lse; 577 Addressee lse;
579 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 578 lse = findByUid( "last-syncAddressee-"+ syncProfile );
580 if ( ! lse.isEmpty() ) 579 if ( ! lse.isEmpty() )
581 removeAddressee( lse ); 580 removeAddressee( lse );
582 } 581 }
583 582
584} 583}
585void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 584void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
586{ 585{
587 Iterator ait; 586 Iterator ait;
588 for ( ait = begin(); ait != end(); ++ait ) { 587 for ( ait = begin(); ait != end(); ++ait ) {
589 QString id = (*ait).IDStr(); 588 QString id = (*ait).IDStr();
590 (*ait).setIDStr( ":"); 589 (*ait).setIDStr( ":");
591 (*ait).setExternalUID( id ); 590 (*ait).setExternalUID( id );
592 (*ait).setOriginalExternalUID( id ); 591 (*ait).setOriginalExternalUID( id );
593 if ( isPreSync ) 592 if ( isPreSync )
594 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 593 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
595 else { 594 else {
596 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 595 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
597 (*ait).setID( currentSyncDevice,id ); 596 (*ait).setID( currentSyncDevice,id );
598 597
599 } 598 }
600 } 599 }
601} 600}
602void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 601void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
603{ 602{
604 603
605 setUntagged(); 604 setUntagged();
606 KABC::Addressee::List list; 605 KABC::Addressee::List list;
607 QFile file( fileName ); 606 QFile file( fileName );
608 file.open( IO_ReadOnly ); 607 file.open( IO_ReadOnly );
609 QByteArray rawData = file.readAll(); 608 QByteArray rawData = file.readAll();
610 file.close(); 609 file.close();
611 QString data; 610 QString data;
612 611
613 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 612 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
614 KABC::VCardTool tool; 613 KABC::VCardTool tool;
615 list = tool.parseVCards( data ); 614 list = tool.parseVCards( data );
616 KABC::Addressee::List::Iterator it; 615 KABC::Addressee::List::Iterator it;
617 for ( it = list.begin(); it != list.end(); ++it ) { 616 for ( it = list.begin(); it != list.end(); ++it ) {
618 Iterator ait; 617 Iterator ait;
619 for ( ait = begin(); ait != end(); ++ait ) { 618 for ( ait = begin(); ait != end(); ++ait ) {
620 if ( !(*ait).tagged() ) { 619 if ( !(*ait).tagged() ) {
621 if ( (*ait).containsAdr(*it)) { 620 if ( (*ait).containsAdr(*it)) {
622 (*ait).setTagged(true); 621 (*ait).setTagged(true);
623 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 622 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
624 (*it).setIDStr( ":"); 623 (*it).setIDStr( ":");
625 (*it).setID( currentSyncDevice,id ); 624 (*it).setID( currentSyncDevice,id );
626 (*it).setExternalUID( id ); 625 (*it).setExternalUID( id );
627 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 626 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
628 (*it).setUid( ( (*ait).uid() )); 627 (*it).setUid( ( (*ait).uid() ));
629 break; 628 break;
630 } 629 }
631 } 630 }
632 631
633 } 632 }
634 if ( ait == end() ) 633 if ( ait == end() )
635 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 634 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
636 } 635 }
637 clear(); 636 clear();
638 for ( it = list.begin(); it != list.end(); ++it ) { 637 for ( it = list.begin(); it != list.end(); ++it ) {
639 insertAddressee( (*it) ); 638 insertAddressee( (*it) );
640 } 639 }
641} 640}
642 641
643bool AddressBook::saveABphone( QString fileName ) 642bool AddressBook::saveABphone( QString fileName )
644{ 643{
645 //smplifyAddressees(); 644 //smplifyAddressees();
646 qDebug("saveABphone:: saving AB... "); 645 qDebug("saveABphone:: saving AB... ");
647 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 646 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
648 return false; 647 return false;
649 qDebug("saveABphone:: writing to phone... "); 648 qDebug("saveABphone:: writing to phone... ");
650 if ( !PhoneAccess::writeToPhone( fileName) ) { 649 if ( !PhoneAccess::writeToPhone( fileName) ) {
651 return false; 650 return false;
652 } 651 }
653 qDebug("saveABphone:: re-reading from phone... "); 652 qDebug("saveABphone:: re-reading from phone... ");
654 if ( !PhoneAccess::readFromPhone( fileName) ) { 653 if ( !PhoneAccess::readFromPhone( fileName) ) {
655 return false; 654 return false;
656 } 655 }
657 return true; 656 return true;
658} 657}
659bool AddressBook::saveAB() 658bool AddressBook::saveAB()
660{ 659{
661 bool ok = true; 660 bool ok = true;
662 661
663 deleteRemovedAddressees(); 662 deleteRemovedAddressees();
664 Iterator ait; 663 Iterator ait;
665 for ( ait = begin(); ait != end(); ++ait ) { 664 for ( ait = begin(); ait != end(); ++ait ) {
666 if ( !(*ait).IDStr().isEmpty() ) { 665 if ( !(*ait).IDStr().isEmpty() ) {
667 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 666 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
668 } 667 }
669 } 668 }
670 KRES::Manager<Resource>::ActiveIterator it; 669 KRES::Manager<Resource>::ActiveIterator it;
671 KRES::Manager<Resource> *manager = d->mManager; 670 KRES::Manager<Resource> *manager = d->mManager;
672 qDebug("SaveAB::saving..." ); 671 qDebug("SaveAB::saving..." );
673 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 672 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
674 qDebug("SaveAB::checking resource..." ); 673 qDebug("SaveAB::checking resource..." );
675 if ( (*it)->readOnly() ) 674 if ( (*it)->readOnly() )
676 qDebug("resource is readonly." ); 675 qDebug("resource is readonly." );
677 if ( (*it)->isOpen() ) 676 if ( (*it)->isOpen() )
678 qDebug("resource is open" ); 677 qDebug("resource is open" );
679 678
680 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 679 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
681 Ticket *ticket = requestSaveTicket( *it ); 680 Ticket *ticket = requestSaveTicket( *it );
682 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 681 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
683 if ( !ticket ) { 682 if ( !ticket ) {
684 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 683 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
685 .arg( (*it)->resourceName() ) ); 684 .arg( (*it)->resourceName() ) );
686 return false; 685 return false;
687 } 686 }
688 687
689 //if ( !save( ticket ) ) 688 //if ( !save( ticket ) )
690 if ( ticket->resource() ) { 689 if ( ticket->resource() ) {
691 QString name = ticket->resource()->resourceName(); 690 QString name = ticket->resource()->resourceName();
692 if ( ! ticket->resource()->save( ticket ) ) 691 if ( ! ticket->resource()->save( ticket ) )
693 ok = false; 692 ok = false;
694 else 693 else
695 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 694 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
696 695
697 } else 696 } else
698 ok = false; 697 ok = false;
699 698
700 } 699 }
701 } 700 }
702 return ok; 701 return ok;
703} 702}
704 703
705AddressBook::Iterator AddressBook::begin() 704AddressBook::Iterator AddressBook::begin()
706{ 705{
707 Iterator it = Iterator(); 706 Iterator it = Iterator();
708 it.d->mIt = d->mAddressees.begin(); 707 it.d->mIt = d->mAddressees.begin();
709 return it; 708 return it;
710} 709}
711 710
712AddressBook::ConstIterator AddressBook::begin() const 711AddressBook::ConstIterator AddressBook::begin() const
713{ 712{
714 ConstIterator it = ConstIterator(); 713 ConstIterator it = ConstIterator();
715 it.d->mIt = d->mAddressees.begin(); 714 it.d->mIt = d->mAddressees.begin();
716 return it; 715 return it;
717} 716}
718 717
719AddressBook::Iterator AddressBook::end() 718AddressBook::Iterator AddressBook::end()
720{ 719{
721 Iterator it = Iterator(); 720 Iterator it = Iterator();
722 it.d->mIt = d->mAddressees.end(); 721 it.d->mIt = d->mAddressees.end();
723 return it; 722 return it;
724} 723}
725 724
726AddressBook::ConstIterator AddressBook::end() const 725AddressBook::ConstIterator AddressBook::end() const
727{ 726{
728 ConstIterator it = ConstIterator(); 727 ConstIterator it = ConstIterator();
729 it.d->mIt = d->mAddressees.end(); 728 it.d->mIt = d->mAddressees.end();
730 return it; 729 return it;
731} 730}
732 731
733void AddressBook::clear() 732void AddressBook::clear()
734{ 733{
735 d->mAddressees.clear(); 734 d->mAddressees.clear();
736} 735}
737 736
738Ticket *AddressBook::requestSaveTicket( Resource *resource ) 737Ticket *AddressBook::requestSaveTicket( Resource *resource )
739{ 738{
740 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 739 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
741 740
742 if ( !resource ) 741 if ( !resource )
743 { 742 {
744 qDebug("AddressBook::requestSaveTicket no resource" ); 743 qDebug("AddressBook::requestSaveTicket no resource" );
745 resource = standardResource(); 744 resource = standardResource();
746 } 745 }
747 746
748 KRES::Manager<Resource>::ActiveIterator it; 747 KRES::Manager<Resource>::ActiveIterator it;
749 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 748 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
750 if ( (*it) == resource ) { 749 if ( (*it) == resource ) {
751 if ( (*it)->readOnly() || !(*it)->isOpen() ) 750 if ( (*it)->readOnly() || !(*it)->isOpen() )
752 return 0; 751 return 0;
753 else 752 else
754 return (*it)->requestSaveTicket(); 753 return (*it)->requestSaveTicket();
755 } 754 }
756 } 755 }
757 756
758 return 0; 757 return 0;
759} 758}
760//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 759//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
761void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 760void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
762{ 761{
763 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 762 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
764 //qDebug("block insert "); 763 //qDebug("block insert ");
765 return; 764 return;
766 } 765 }
767 //qDebug("inserting.... %s ",a.uid().latin1() ); 766 //qDebug("inserting.... %s ",a.uid().latin1() );
768 bool found = false; 767 bool found = false;
769 Addressee::List::Iterator it; 768 Addressee::List::Iterator it;
770 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 769 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
771 if ( a.uid() == (*it).uid() ) { 770 if ( a.uid() == (*it).uid() ) {
772 771
773 bool changed = false; 772 bool changed = false;
774 Addressee addr = a; 773 Addressee addr = a;
775 if ( addr != (*it) ) 774 if ( addr != (*it) )
776 changed = true; 775 changed = true;
777 776
778 if ( takeResource ) { 777 if ( takeResource ) {
779 Resource * res = (*it).resource(); 778 Resource * res = (*it).resource();
780 (*it) = a; 779 (*it) = a;
781 (*it).setResource( res ); 780 (*it).setResource( res );
782 } else { 781 } else {
783 (*it) = a; 782 (*it) = a;
784 if ( (*it).resource() == 0 ) 783 if ( (*it).resource() == 0 )
785 (*it).setResource( standardResource() ); 784 (*it).setResource( standardResource() );
786 } 785 }
787 if ( changed ) { 786 if ( changed ) {
788 if ( setRev ) { 787 if ( setRev ) {
789 788 (*it).setRevision( QDateTime::currentDateTime() );
790 // get rid of micro seconds
791 QDateTime dt = QDateTime::currentDateTime();
792 QTime t = dt.time();
793 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
794 (*it).setRevision( dt );
795 } 789 }
796 (*it).setChanged( true ); 790 (*it).setChanged( true );
797 } 791 }
798 792
799 found = true; 793 found = true;
800 } else { 794 } else {
801 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
802 QString name = (*it).uid().mid( 19 ); 796 QString name = (*it).uid().mid( 19 );
803 Addressee b = a; 797 Addressee b = a;
804 QString id = b.getID( name ); 798 QString id = b.getID( name );
805 if ( ! id.isEmpty() ) { 799 if ( ! id.isEmpty() ) {
806 QString des = (*it).note(); 800 QString des = (*it).note();
807 int startN; 801 int startN;
808 if( (startN = des.find( id ) ) >= 0 ) { 802 if( (startN = des.find( id ) ) >= 0 ) {
809 int endN = des.find( ",", startN+1 ); 803 int endN = des.find( ",", startN+1 );
810 des = des.left( startN ) + des.mid( endN+1 ); 804 des = des.left( startN ) + des.mid( endN+1 );
811 (*it).setNote( des ); 805 (*it).setNote( des );
812 } 806 }
813 } 807 }
814 } 808 }
815 } 809 }
816 } 810 }
817 if ( found ) 811 if ( found )
818 return; 812 return;
813
819 d->mAddressees.append( a ); 814 d->mAddressees.append( a );
820 Addressee& addr = d->mAddressees.last(); 815 Addressee& addr = d->mAddressees.last();
821 if ( addr.resource() == 0 ) 816 if ( addr.resource() == 0 )
822 addr.setResource( standardResource() ); 817 addr.setResource( standardResource() );
823
824 addr.setChanged( true ); 818 addr.setChanged( true );
825} 819}
826 820
827void AddressBook::removeAddressee( const Addressee &a ) 821void AddressBook::removeAddressee( const Addressee &a )
828{ 822{
829 Iterator it; 823 Iterator it;
830 Iterator it2; 824 Iterator it2;
831 bool found = false; 825 bool found = false;
832 for ( it = begin(); it != end(); ++it ) { 826 for ( it = begin(); it != end(); ++it ) {
833 if ( a.uid() == (*it).uid() ) { 827 if ( a.uid() == (*it).uid() ) {
834 found = true; 828 found = true;
835 it2 = it; 829 it2 = it;
836 } else { 830 } else {
837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 831 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
838 QString name = (*it).uid().mid( 19 ); 832 QString name = (*it).uid().mid( 19 );
839 Addressee b = a; 833 Addressee b = a;
840 QString id = b.getID( name ); 834 QString id = b.getID( name );
841 if ( ! id.isEmpty() ) { 835 if ( ! id.isEmpty() ) {
842 QString des = (*it).note(); 836 QString des = (*it).note();
843 if( des.find( id ) < 0 ) { 837 if( des.find( id ) < 0 ) {
844 des += id + ","; 838 des += id + ",";
845 (*it).setNote( des ); 839 (*it).setNote( des );
846 } 840 }
847 } 841 }
848 } 842 }
849 843
850 } 844 }
851 } 845 }
852 846
853 if ( found ) 847 if ( found )
854 removeAddressee( it2 ); 848 removeAddressee( it2 );
855 849
856} 850}
857 851
858void AddressBook::removeSyncAddressees( bool removeDeleted ) 852void AddressBook::removeSyncAddressees( bool removeDeleted )
859{ 853{
860 Iterator it = begin(); 854 Iterator it = begin();
861 Iterator it2 ; 855 Iterator it2 ;
862 QDateTime dt ( QDate( 2004,1,1) ); 856 QDateTime dt ( QDate( 2003,1,1) );
863 while ( it != end() ) { 857 while ( it != end() ) {
864 (*it).setRevision( dt ); 858 (*it).setRevision( dt );
865 if (( *it).IDStr() != "changed" ) { 859 if (( *it).IDStr() != "changed" ) {
866 // "changed" is used for tagging changed addressees when syncing with KDE or OL 860 // "changed" is used for tagging changed addressees when syncing with KDE or OL
867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 861 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
868 (*it).setIDStr(""); 862 (*it).setIDStr(":");
869 } 863 }
870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 864 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
871 it2 = it; 865 it2 = it;
872 //qDebug("removing %s ",(*it).uid().latin1() ); 866 //qDebug("removing %s ",(*it).uid().latin1() );
873 ++it; 867 ++it;
874 removeAddressee( it2 ); 868 removeAddressee( it2 );
875 } else { 869 } else {
876 //qDebug("skipping %s ",(*it).uid().latin1() ); 870 //qDebug("skipping %s ",(*it).uid().latin1() );
877 if ( removeDeleted ) { 871 if ( removeDeleted ) {
878 // we have no postprocessing in the resource, we have to do it here 872 // we have no postprocessing in the resource, we have to do it here
879 // we have to compute csum for all, because it could be the first sync 873 // we have to compute csum for all, because it could be the first sync
880 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 874 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
881
882
883 } 875 }
884 ++it; 876 ++it;
885 } 877 }
886 } 878 }
887 deleteRemovedAddressees(); 879 deleteRemovedAddressees();
888} 880}
889 881
890void AddressBook::removeAddressee( const Iterator &it ) 882void AddressBook::removeAddressee( const Iterator &it )
891{ 883{
892 d->mRemovedAddressees.append( (*it) ); 884 d->mRemovedAddressees.append( (*it) );
893 d->mAddressees.remove( it.d->mIt ); 885 d->mAddressees.remove( it.d->mIt );
894} 886}
895 887
896AddressBook::Iterator AddressBook::find( const Addressee &a ) 888AddressBook::Iterator AddressBook::find( const Addressee &a )
897{ 889{
898 Iterator it; 890 Iterator it;
899 for ( it = begin(); it != end(); ++it ) { 891 for ( it = begin(); it != end(); ++it ) {
900 if ( a.uid() == (*it).uid() ) { 892 if ( a.uid() == (*it).uid() ) {
901 return it; 893 return it;
902 } 894 }
903 } 895 }
904 return end(); 896 return end();
905} 897}
906 898
907Addressee AddressBook::findByUid( const QString &uid ) 899Addressee AddressBook::findByUid( const QString &uid )
908{ 900{
909 Iterator it; 901 Iterator it;
910 for ( it = begin(); it != end(); ++it ) { 902 for ( it = begin(); it != end(); ++it ) {
911 if ( uid == (*it).uid() ) { 903 if ( uid == (*it).uid() ) {
912 return *it; 904 return *it;
913 } 905 }
914 } 906 }
915 return Addressee(); 907 return Addressee();
916} 908}
917void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 909void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
918{ 910{
919 //qDebug("AddressBook::preExternSync "); 911 //qDebug("AddressBook::preExternSync ");
920 AddressBook::Iterator it; 912 AddressBook::Iterator it;
921 for ( it = begin(); it != end(); ++it ) { 913 for ( it = begin(); it != end(); ++it ) {
922 (*it).setID( csd, (*it).externalUID() ); 914 (*it).setID( csd, (*it).externalUID() );
923 (*it).computeCsum( csd ); 915 (*it).computeCsum( csd );
924 } 916 }
925 mergeAB( aBook ,csd, isSubset ); 917 mergeAB( aBook ,csd, isSubset );
926} 918}
927void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) 919void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID)
928{ 920{
929 //qDebug("AddressBook::postExternSync "); 921 //qDebug("AddressBook::postExternSync ");
930 AddressBook::Iterator it; 922 AddressBook::Iterator it;
931 for ( it = begin(); it != end(); ++it ) { 923 for ( it = begin(); it != end(); ++it ) {
932 //qDebug("check uid %s ", (*it).uid().latin1() ); 924 //qDebug("check uid %s ", (*it).uid().latin1() );
933 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 925 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
934 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 926 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ||
927 (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) {
935 Addressee ad = aBook->findByUid( ( (*it).uid() )); 928 Addressee ad = aBook->findByUid( ( (*it).uid() ));
936 if ( ad.isEmpty() ) { 929 if ( ad.isEmpty() ) {
937 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 930 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
938 } else { 931 } else {
939 (*it).setIDStr(":"); 932 (*it).setIDStr(":");
940 (*it).computeCsum( csd );
941 if ( setID ) { 933 if ( setID ) {
942 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 934 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
943 ad.setID( csd, (*it).externalUID() ); 935 ad.setID( csd, (*it).externalUID() );
944 } else 936 } else
945 ad.setID( csd, (*it).uid() ); 937 ad.setID( csd, (*it).uid() );
938 (*it).computeCsum( csd );
946 ad.setCsum( csd, (*it).getCsum( csd ) ); 939 ad.setCsum( csd, (*it).getCsum( csd ) );
947 aBook->insertAddressee( ad ); 940 //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() );
941 aBook->insertAddressee( ad , false);
948 } 942 }
949 } 943 }
950 } 944 }
951} 945}
952 946
953bool AddressBook::containsExternalUid( const QString& uid ) 947bool AddressBook::containsExternalUid( const QString& uid )
954{ 948{
955 Iterator it; 949 Iterator it;
956 for ( it = begin(); it != end(); ++it ) { 950 for ( it = begin(); it != end(); ++it ) {
957 if ( uid == (*it).externalUID( ) ) 951 if ( uid == (*it).externalUID( ) )
958 return true; 952 return true;
959 } 953 }
960 return false; 954 return false;
961} 955}
962Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 956Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
963{ 957{
964 Iterator it; 958 Iterator it;
965 for ( it = begin(); it != end(); ++it ) { 959 for ( it = begin(); it != end(); ++it ) {
966 if ( uid == (*it).getID( profile ) ) 960 if ( uid == (*it).getID( profile ) )
967 return (*it); 961 return (*it);
968 } 962 }
969 return Addressee(); 963 return Addressee();
970} 964}
971void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 965void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
972{ 966{
973 Iterator it; 967 Iterator it;
974 Addressee ad; 968 Addressee ad;
975 for ( it = begin(); it != end(); ++it ) { 969 for ( it = begin(); it != end(); ++it ) {
976 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 970 ad = aBook->findByExternUid( (*it).externalUID(), profile );
977 if ( !ad.isEmpty() ) { 971 if ( !ad.isEmpty() ) {
978 (*it).mergeContact( ad ,isSubset); 972 (*it).mergeContact( ad ,isSubset);
979 } 973 }
980 } 974 }
981#if 0 975#if 0
982 // test only 976 // test only
983 for ( it = begin(); it != end(); ++it ) { 977 for ( it = begin(); it != end(); ++it ) {
984 978
985 qDebug("uid %s ", (*it).uid().latin1()); 979 qDebug("uid %s ", (*it).uid().latin1());
986 } 980 }
987#endif 981#endif
988} 982}
989 983
990#if 0 984#if 0
991Addressee::List AddressBook::getExternLastSyncAddressees() 985Addressee::List AddressBook::getExternLastSyncAddressees()
992{ 986{
993 Addressee::List results; 987 Addressee::List results;
994 988
995 Iterator it; 989 Iterator it;
996 for ( it = begin(); it != end(); ++it ) { 990 for ( it = begin(); it != end(); ++it ) {
997 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 991 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
998 if ( (*it).familyName().left(4) == "!E: " ) 992 if ( (*it).familyName().left(4) == "!E: " )
999 results.append( *it ); 993 results.append( *it );
1000 } 994 }
1001 } 995 }
1002 996
1003 return results; 997 return results;
1004} 998}
1005#endif 999#endif
1006void AddressBook::resetTempSyncStat() 1000void AddressBook::resetTempSyncStat()
1007{ 1001{
1008 Iterator it; 1002 Iterator it;
1009 for ( it = begin(); it != end(); ++it ) { 1003 for ( it = begin(); it != end(); ++it ) {
1010 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 1004 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
1011 } 1005 }
1012 1006
1013} 1007}
1014 1008
1015QStringList AddressBook:: uidList() 1009QStringList AddressBook:: uidList()
1016{ 1010{
1017 QStringList results; 1011 QStringList results;
1018 Iterator it; 1012 Iterator it;
1019 for ( it = begin(); it != end(); ++it ) { 1013 for ( it = begin(); it != end(); ++it ) {
1020 results.append( (*it).uid() ); 1014 results.append( (*it).uid() );
1021 } 1015 }
1022 return results; 1016 return results;
1023} 1017}
1024 1018
1025 1019
1026Addressee::List AddressBook::allAddressees() 1020Addressee::List AddressBook::allAddressees()
1027{ 1021{
1028 return d->mAddressees; 1022 return d->mAddressees;
1029 1023
1030} 1024}
1031 1025
1032Addressee::List AddressBook::findByName( const QString &name ) 1026Addressee::List AddressBook::findByName( const QString &name )
1033{ 1027{
1034 Addressee::List results; 1028 Addressee::List results;
1035 1029
1036 Iterator it; 1030 Iterator it;
1037 for ( it = begin(); it != end(); ++it ) { 1031 for ( it = begin(); it != end(); ++it ) {
1038 if ( name == (*it).realName() ) { 1032 if ( name == (*it).realName() ) {
1039 results.append( *it ); 1033 results.append( *it );
1040 } 1034 }
1041 } 1035 }
1042 1036
1043 return results; 1037 return results;
1044} 1038}
1045 1039
1046Addressee::List AddressBook::findByEmail( const QString &email ) 1040Addressee::List AddressBook::findByEmail( const QString &email )
1047{ 1041{
1048 Addressee::List results; 1042 Addressee::List results;
1049 QStringList mailList; 1043 QStringList mailList;
1050 1044
1051 Iterator it; 1045 Iterator it;
1052 for ( it = begin(); it != end(); ++it ) { 1046 for ( it = begin(); it != end(); ++it ) {
1053 mailList = (*it).emails(); 1047 mailList = (*it).emails();
1054 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1048 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1055 if ( email == (*ite) ) { 1049 if ( email == (*ite) ) {
1056 results.append( *it ); 1050 results.append( *it );
1057 } 1051 }
1058 } 1052 }
1059 } 1053 }
1060 1054
1061 return results; 1055 return results;
1062} 1056}
1063 1057
1064Addressee::List AddressBook::findByCategory( const QString &category ) 1058Addressee::List AddressBook::findByCategory( const QString &category )
1065{ 1059{
1066 Addressee::List results; 1060 Addressee::List results;
1067 1061
1068 Iterator it; 1062 Iterator it;
1069 for ( it = begin(); it != end(); ++it ) { 1063 for ( it = begin(); it != end(); ++it ) {
1070 if ( (*it).hasCategory( category) ) { 1064 if ( (*it).hasCategory( category) ) {
1071 results.append( *it ); 1065 results.append( *it );
1072 } 1066 }
1073 } 1067 }
1074 1068
1075 return results; 1069 return results;
1076} 1070}
1077 1071
1078void AddressBook::dump() const 1072void AddressBook::dump() const
1079{ 1073{
1080 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1074 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1081 1075
1082 ConstIterator it; 1076 ConstIterator it;
1083 for( it = begin(); it != end(); ++it ) { 1077 for( it = begin(); it != end(); ++it ) {
1084 (*it).dump(); 1078 (*it).dump();
1085 } 1079 }
1086 1080
1087 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1081 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1088} 1082}
1089 1083
1090QString AddressBook::identifier() 1084QString AddressBook::identifier()
1091{ 1085{
1092 QStringList identifier; 1086 QStringList identifier;
1093 1087
1094 1088
1095 KRES::Manager<Resource>::ActiveIterator it; 1089 KRES::Manager<Resource>::ActiveIterator it;
1096 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1090 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1097 if ( !(*it)->identifier().isEmpty() ) 1091 if ( !(*it)->identifier().isEmpty() )
1098 identifier.append( (*it)->identifier() ); 1092 identifier.append( (*it)->identifier() );
1099 } 1093 }
1100 1094
1101 return identifier.join( ":" ); 1095 return identifier.join( ":" );
1102} 1096}
1103 1097
1104Field::List AddressBook::fields( int category ) 1098Field::List AddressBook::fields( int category )
1105{ 1099{
1106 if ( d->mAllFields.isEmpty() ) { 1100 if ( d->mAllFields.isEmpty() ) {
1107 d->mAllFields = Field::allFields(); 1101 d->mAllFields = Field::allFields();
1108 } 1102 }
1109 1103
1110 if ( category == Field::All ) return d->mAllFields; 1104 if ( category == Field::All ) return d->mAllFields;
1111 1105
1112 Field::List result; 1106 Field::List result;
1113 Field::List::ConstIterator it; 1107 Field::List::ConstIterator it;
1114 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1108 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1115 if ( (*it)->category() & category ) result.append( *it ); 1109 if ( (*it)->category() & category ) result.append( *it );
1116 } 1110 }
1117 1111
1118 return result; 1112 return result;
1119} 1113}
1120 1114
1121bool AddressBook::addCustomField( const QString &label, int category, 1115bool AddressBook::addCustomField( const QString &label, int category,
1122 const QString &key, const QString &app ) 1116 const QString &key, const QString &app )
1123{ 1117{
1124 if ( d->mAllFields.isEmpty() ) { 1118 if ( d->mAllFields.isEmpty() ) {
1125 d->mAllFields = Field::allFields(); 1119 d->mAllFields = Field::allFields();
1126 } 1120 }
1127//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1121//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1128 QString a = app.isNull() ? KGlobal::getAppName() : app; 1122 QString a = app.isNull() ? KGlobal::getAppName() : app;
1129 1123
1130 QString k = key.isNull() ? label : key; 1124 QString k = key.isNull() ? label : key;
1131 1125
1132 Field *field = Field::createCustomField( label, category, k, a ); 1126 Field *field = Field::createCustomField( label, category, k, a );
1133 1127
1134 if ( !field ) return false; 1128 if ( !field ) return false;
1135 1129
1136 d->mAllFields.append( field ); 1130 d->mAllFields.append( field );
1137 1131
1138 return true; 1132 return true;
1139} 1133}
1140 1134
1141QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1135QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1142{ 1136{
1143 if (!ab.d) return s; 1137 if (!ab.d) return s;
1144 1138
1145 return s << ab.d->mAddressees; 1139 return s << ab.d->mAddressees;
1146} 1140}
1147 1141
1148QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1142QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1149{ 1143{
1150 if (!ab.d) return s; 1144 if (!ab.d) return s;
1151 1145
1152 s >> ab.d->mAddressees; 1146 s >> ab.d->mAddressees;
1153 1147
1154 return s; 1148 return s;
1155} 1149}
1156 1150
1157bool AddressBook::addResource( Resource *resource ) 1151bool AddressBook::addResource( Resource *resource )
1158{ 1152{
1159 if ( !resource->open() ) { 1153 if ( !resource->open() ) {
1160 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1154 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1161 return false; 1155 return false;
1162 } 1156 }
1163 1157
1164 resource->setAddressBook( this ); 1158 resource->setAddressBook( this );
1165 1159
1166 d->mManager->add( resource ); 1160 d->mManager->add( resource );
1167 return true; 1161 return true;
1168} 1162}
1169 1163
1170bool AddressBook::removeResource( Resource *resource ) 1164bool AddressBook::removeResource( Resource *resource )
1171{ 1165{
1172 resource->close(); 1166 resource->close();
1173 1167
1174 if ( resource == standardResource() ) 1168 if ( resource == standardResource() )
1175 d->mManager->setStandardResource( 0 ); 1169 d->mManager->setStandardResource( 0 );
1176 1170
1177 resource->setAddressBook( 0 ); 1171 resource->setAddressBook( 0 );
1178 1172
1179 d->mManager->remove( resource ); 1173 d->mManager->remove( resource );
1180 return true; 1174 return true;
1181} 1175}
1182 1176
1183QPtrList<Resource> AddressBook::resources() 1177QPtrList<Resource> AddressBook::resources()
1184{ 1178{
1185 QPtrList<Resource> list; 1179 QPtrList<Resource> list;
1186 1180
1187// qDebug("AddressBook::resources() 1"); 1181// qDebug("AddressBook::resources() 1");
1188 1182
1189 KRES::Manager<Resource>::ActiveIterator it; 1183 KRES::Manager<Resource>::ActiveIterator it;
1190 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1184 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1191 list.append( *it ); 1185 list.append( *it );
1192 1186
1193 return list; 1187 return list;
1194} 1188}
1195 1189
1196/*US 1190/*US
1197void AddressBook::setErrorHandler( ErrorHandler *handler ) 1191void AddressBook::setErrorHandler( ErrorHandler *handler )
1198{ 1192{
1199 delete d->mErrorHandler; 1193 delete d->mErrorHandler;
1200 d->mErrorHandler = handler; 1194 d->mErrorHandler = handler;
1201} 1195}
1202*/ 1196*/
1203 1197