author | zautrix <zautrix> | 2004-10-29 09:03:54 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-29 09:03:54 (UTC) |
commit | 6500d6ebb080f1de58fe676aa0a730d47fcf64f5 (patch) (unidiff) | |
tree | 41841e05bf1e6b88e6e55f42011dce5f6bed85b4 /kabc | |
parent | 41e3625b8c38ff45e70b59416a519d59a5f4d937 (diff) | |
download | kdepimpi-6500d6ebb080f1de58fe676aa0a730d47fcf64f5.zip kdepimpi-6500d6ebb080f1de58fe676aa0a730d47fcf64f5.tar.gz kdepimpi-6500d6ebb080f1de58fe676aa0a730d47fcf64f5.tar.bz2 |
sync fixes
-rw-r--r-- | kabc/addressbook.cpp | 26 | ||||
-rw-r--r-- | kabc/addressee.cpp | 25 |
2 files changed, 29 insertions, 22 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 6194d6d..4c4ae09 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -437,639 +437,633 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | |||
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 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int 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 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void 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 | } |
528 | void AddressBook::removeUntagged() | 528 | void 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 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void 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 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | 556 | void 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 | } |
585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 584 | void 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 | } |
602 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 601 | void 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 | ||
643 | bool AddressBook::saveABphone( QString fileName ) | 642 | bool 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 | } |
659 | bool AddressBook::saveAB() | 658 | bool 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 | ||
705 | AddressBook::Iterator AddressBook::begin() | 704 | AddressBook::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 | ||
712 | AddressBook::ConstIterator AddressBook::begin() const | 711 | AddressBook::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 | ||
719 | AddressBook::Iterator AddressBook::end() | 718 | AddressBook::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 | ||
726 | AddressBook::ConstIterator AddressBook::end() const | 725 | AddressBook::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 | ||
733 | void AddressBook::clear() | 732 | void AddressBook::clear() |
734 | { | 733 | { |
735 | d->mAddressees.clear(); | 734 | d->mAddressees.clear(); |
736 | } | 735 | } |
737 | 736 | ||
738 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 737 | Ticket *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); |
761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 760 | void 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 | ||
827 | void AddressBook::removeAddressee( const Addressee &a ) | 821 | void 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 | ||
858 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 852 | void 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 | ||
890 | void AddressBook::removeAddressee( const Iterator &it ) | 882 | void 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 | ||
896 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 888 | AddressBook::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 | ||
907 | Addressee AddressBook::findByUid( const QString &uid ) | 899 | Addressee 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 | } |
917 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 909 | void 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 | } |
927 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) | 919 | void 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 | ||
953 | bool AddressBook::containsExternalUid( const QString& uid ) | 947 | bool 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 | } |
962 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 956 | Addressee 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 | } |
971 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 965 | void 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 |
991 | Addressee::List AddressBook::getExternLastSyncAddressees() | 985 | Addressee::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 |
1006 | void AddressBook::resetTempSyncStat() | 1000 | void 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 | ||
1015 | QStringList AddressBook:: uidList() | 1009 | QStringList 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 | ||
1026 | Addressee::List AddressBook::allAddressees() | 1020 | Addressee::List AddressBook::allAddressees() |
1027 | { | 1021 | { |
1028 | return d->mAddressees; | 1022 | return d->mAddressees; |
1029 | 1023 | ||
1030 | } | 1024 | } |
1031 | 1025 | ||
1032 | Addressee::List AddressBook::findByName( const QString &name ) | 1026 | Addressee::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 | ||
1046 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1040 | Addressee::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 | ||
1064 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1058 | Addressee::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; |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index d5a110a..3d4992c 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -84,314 +84,324 @@ struct Addressee::AddresseeData : public KShared | |||
84 | QStringList categories; | 84 | QStringList categories; |
85 | QStringList custom; | 85 | QStringList custom; |
86 | int mTempSyncStat; | 86 | int mTempSyncStat; |
87 | Resource *resource; | 87 | Resource *resource; |
88 | 88 | ||
89 | bool empty :1; | 89 | bool empty :1; |
90 | bool changed :1; | 90 | bool changed :1; |
91 | bool tagged :1; | 91 | bool tagged :1; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | Addressee::Addressee() | 94 | Addressee::Addressee() |
95 | { | 95 | { |
96 | mData = new AddresseeData; | 96 | mData = new AddresseeData; |
97 | mData->empty = true; | 97 | mData->empty = true; |
98 | mData->changed = false; | 98 | mData->changed = false; |
99 | mData->resource = 0; | 99 | mData->resource = 0; |
100 | mData->mExternalId = ":"; | 100 | mData->mExternalId = ":"; |
101 | mData->revision = QDateTime ( QDate( 2003,1,1)); | 101 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
103 | } | 103 | } |
104 | 104 | ||
105 | Addressee::~Addressee() | 105 | Addressee::~Addressee() |
106 | { | 106 | { |
107 | } | 107 | } |
108 | 108 | ||
109 | Addressee::Addressee( const Addressee &a ) | 109 | Addressee::Addressee( const Addressee &a ) |
110 | { | 110 | { |
111 | mData = a.mData; | 111 | mData = a.mData; |
112 | } | 112 | } |
113 | 113 | ||
114 | Addressee &Addressee::operator=( const Addressee &a ) | 114 | Addressee &Addressee::operator=( const Addressee &a ) |
115 | { | 115 | { |
116 | mData = a.mData; | 116 | mData = a.mData; |
117 | return (*this); | 117 | return (*this); |
118 | } | 118 | } |
119 | 119 | ||
120 | Addressee Addressee::copy() | 120 | Addressee Addressee::copy() |
121 | { | 121 | { |
122 | Addressee a; | 122 | Addressee a; |
123 | *(a.mData) = *mData; | 123 | *(a.mData) = *mData; |
124 | return a; | 124 | return a; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Addressee::detach() | 127 | void Addressee::detach() |
128 | { | 128 | { |
129 | if ( mData.count() == 1 ) return; | 129 | if ( mData.count() == 1 ) return; |
130 | *this = copy(); | 130 | *this = copy(); |
131 | } | 131 | } |
132 | 132 | ||
133 | bool Addressee::operator==( const Addressee &a ) const | 133 | bool Addressee::operator==( const Addressee &a ) const |
134 | { | 134 | { |
135 | if ( uid() != a.uid() ) return false; | 135 | if ( uid() != a.uid() ) return false; |
136 | if ( mData->name != a.mData->name ) return false; | 136 | if ( mData->name != a.mData->name ) return false; |
137 | if ( mData->formattedName != a.mData->formattedName ) return false; | 137 | if ( mData->formattedName != a.mData->formattedName ) return false; |
138 | if ( mData->familyName != a.mData->familyName ) return false; | 138 | if ( mData->familyName != a.mData->familyName ) return false; |
139 | if ( mData->givenName != a.mData->givenName ) return false; | 139 | if ( mData->givenName != a.mData->givenName ) return false; |
140 | if ( mData->additionalName != a.mData->additionalName ) return false; | 140 | if ( mData->additionalName != a.mData->additionalName ) return false; |
141 | if ( mData->prefix != a.mData->prefix ) return false; | 141 | if ( mData->prefix != a.mData->prefix ) return false; |
142 | if ( mData->suffix != a.mData->suffix ) return false; | 142 | if ( mData->suffix != a.mData->suffix ) return false; |
143 | if ( mData->nickName != a.mData->nickName ) return false; | 143 | if ( mData->nickName != a.mData->nickName ) return false; |
144 | if ( mData->birthday != a.mData->birthday ) return false; | 144 | if ( mData->birthday != a.mData->birthday ) return false; |
145 | if ( mData->mailer != a.mData->mailer ) return false; | 145 | if ( mData->mailer != a.mData->mailer ) return false; |
146 | if ( mData->timeZone != a.mData->timeZone ) return false; | 146 | if ( mData->timeZone != a.mData->timeZone ) return false; |
147 | if ( mData->geo != a.mData->geo ) return false; | 147 | if ( mData->geo != a.mData->geo ) return false; |
148 | if ( mData->title != a.mData->title ) return false; | 148 | if ( mData->title != a.mData->title ) return false; |
149 | if ( mData->role != a.mData->role ) return false; | 149 | if ( mData->role != a.mData->role ) return false; |
150 | if ( mData->organization != a.mData->organization ) return false; | 150 | if ( mData->organization != a.mData->organization ) return false; |
151 | if ( mData->note != a.mData->note ) return false; | 151 | if ( mData->note != a.mData->note ) return false; |
152 | if ( mData->productId != a.mData->productId ) return false; | 152 | if ( mData->productId != a.mData->productId ) return false; |
153 | //if ( mData->revision != a.mData->revision ) return false; | 153 | //if ( mData->revision != a.mData->revision ) return false; |
154 | if ( mData->sortString != a.mData->sortString ) return false; | 154 | if ( mData->sortString != a.mData->sortString ) return false; |
155 | if ( mData->secrecy != a.mData->secrecy ) return false; | 155 | if ( mData->secrecy != a.mData->secrecy ) return false; |
156 | if ( mData->logo != a.mData->logo ) return false; | 156 | if ( mData->logo != a.mData->logo ) return false; |
157 | if ( mData->photo != a.mData->photo ) return false; | 157 | if ( mData->photo != a.mData->photo ) return false; |
158 | if ( mData->sound != a.mData->sound ) return false; | 158 | if ( mData->sound != a.mData->sound ) return false; |
159 | if ( mData->agent != a.mData->agent ) return false; | 159 | if ( mData->agent != a.mData->agent ) return false; |
160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
161 | ( mData->url != a.mData->url ) ) return false; | 161 | ( mData->url != a.mData->url ) ) return false; |
162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
163 | if ( mData->addresses != a.mData->addresses ) return false; | 163 | if ( mData->addresses != a.mData->addresses ) return false; |
164 | if ( mData->keys != a.mData->keys ) return false; | 164 | if ( mData->keys != a.mData->keys ) return false; |
165 | if ( mData->emails != a.mData->emails ) return false; | 165 | if ( mData->emails != a.mData->emails ) return false; |
166 | if ( mData->categories != a.mData->categories ) return false; | 166 | if ( mData->categories != a.mData->categories ) return false; |
167 | if ( mData->custom != a.mData->custom ) return false; | 167 | if ( mData->custom != a.mData->custom ) return false; |
168 | 168 | ||
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool Addressee::operator!=( const Addressee &a ) const | 172 | bool Addressee::operator!=( const Addressee &a ) const |
173 | { | 173 | { |
174 | return !( a == *this ); | 174 | return !( a == *this ); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool Addressee::isEmpty() const | 177 | bool Addressee::isEmpty() const |
178 | { | 178 | { |
179 | return mData->empty; | 179 | return mData->empty; |
180 | } | 180 | } |
181 | ulong Addressee::getCsum4List( const QStringList & attList) | 181 | ulong Addressee::getCsum4List( const QStringList & attList) |
182 | { | 182 | { |
183 | int max = attList.count(); | 183 | int max = attList.count(); |
184 | ulong cSum = 0; | 184 | ulong cSum = 0; |
185 | int j,k,i; | 185 | int j,k,i; |
186 | int add; | 186 | int add; |
187 | for ( i = 0; i < max ; ++i ) { | 187 | for ( i = 0; i < max ; ++i ) { |
188 | QString s = attList[i]; | 188 | QString s = attList[i]; |
189 | if ( ! s.isEmpty() ){ | 189 | if ( ! s.isEmpty() ){ |
190 | j = s.length(); | 190 | j = s.length(); |
191 | for ( k = 0; k < j; ++k ) { | 191 | for ( k = 0; k < j; ++k ) { |
192 | int mul = k +1; | 192 | int mul = k +1; |
193 | add = s[k].unicode (); | 193 | add = s[k].unicode (); |
194 | if ( k < 16 ) | 194 | if ( k < 16 ) |
195 | mul = mul * mul; | 195 | mul = mul * mul; |
196 | int ii = i+1; | 196 | int ii = i+1; |
197 | add = add * mul *ii*ii*ii; | 197 | add = add * mul *ii*ii*ii; |
198 | cSum += add; | 198 | cSum += add; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | } | 202 | } |
203 | //QString dump = attList.join(","); | 203 | //QString dump = attList.join(","); |
204 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 204 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
205 | 205 | ||
206 | return cSum; | 206 | return cSum; |
207 | 207 | ||
208 | } | 208 | } |
209 | void Addressee::computeCsum(const QString &dev) | 209 | void Addressee::computeCsum(const QString &dev) |
210 | { | 210 | { |
211 | QStringList l; | 211 | QStringList l; |
212 | if ( !mData->name.isEmpty() ) l.append(mData->name); | 212 | //if ( !mData->name.isEmpty() ) l.append(mData->name); |
213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 213 | //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
216 | if ( !mData->additionalName ) l.append( mData->additionalName ); | 216 | if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); |
217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
231 | // if ( !mData->logo.isEmpty() ) l.append( ); | 231 | // if ( !mData->logo.isEmpty() ) l.append( ); |
232 | //if ( !mData->photo.isEmpty() ) l.append( ); | 232 | //if ( !mData->photo.isEmpty() ) l.append( ); |
233 | //if ( !mData->sound.isEmpty() ) l.append( ); | 233 | //if ( !mData->sound.isEmpty() ) l.append( ); |
234 | //if ( !mData->agent.isEmpty() ) l.append( ); | 234 | //if ( !mData->agent.isEmpty() ) l.append( ); |
235 | if ( mData->url.isValid() ) | 235 | if ( mData->url.isValid() ) |
236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); | 236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); |
237 | KABC::PhoneNumber::List phoneNumbers; | 237 | KABC::PhoneNumber::List phoneNumbers; |
238 | KABC::PhoneNumber::List::Iterator phoneIter; | 238 | KABC::PhoneNumber::List::Iterator phoneIter; |
239 | 239 | ||
240 | QStringList t; | 240 | QStringList t; |
241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
242 | ++phoneIter ) | 242 | ++phoneIter ) |
243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
244 | t.sort(); | 244 | t.sort(); |
245 | uint iii; | 245 | uint iii; |
246 | for ( iii = 0; iii < t.count(); ++iii) | 246 | for ( iii = 0; iii < t.count(); ++iii) |
247 | l.append( t[iii] ); | 247 | l.append( t[iii] ); |
248 | t = mData->emails; | 248 | t = mData->emails; |
249 | t.sort(); | 249 | t.sort(); |
250 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
251 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
252 | t = mData->categories; | 252 | t = mData->categories; |
253 | t.sort(); | 253 | t.sort(); |
254 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
255 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
256 | t = mData->custom; | 256 | t = mData->custom; |
257 | t.sort(); | 257 | t.sort(); |
258 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
259 | l.append( t[iii] ); | 259 | if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { |
260 | int find = t[iii].find (':')+1; | ||
261 | //qDebug("lennnn %d %d ", find, t[iii].length()); | ||
262 | if ( find < t[iii].length()) | ||
263 | l.append( t[iii] ); | ||
264 | |||
265 | } | ||
260 | KABC::Address::List::Iterator addressIter; | 266 | KABC::Address::List::Iterator addressIter; |
261 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 267 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
262 | ++addressIter ) { | 268 | ++addressIter ) { |
263 | t = (*addressIter).asList(); | 269 | t = (*addressIter).asList(); |
264 | t.sort(); | 270 | t.sort(); |
265 | for ( iii = 0; iii < t.count(); ++iii) | 271 | for ( iii = 0; iii < t.count(); ++iii) |
266 | l.append( t[iii] ); | 272 | l.append( t[iii] ); |
267 | } | 273 | } |
268 | uint cs = getCsum4List(l); | 274 | uint cs = getCsum4List(l); |
269 | //qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 275 | #if 1 |
276 | for ( iii = 0; iii < l.count(); ++iii) | ||
277 | qDebug("%d***%s***",iii,l[iii].latin1()); | ||
278 | qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | ||
279 | #endif | ||
270 | setCsum( dev, QString::number (cs )); | 280 | setCsum( dev, QString::number (cs )); |
271 | } | 281 | } |
272 | 282 | ||
273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) | 283 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) |
274 | { | 284 | { |
275 | 285 | ||
276 | detach(); | 286 | detach(); |
277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 287 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 288 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 289 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 290 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 291 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 292 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 293 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 294 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
285 | if ( !mData->birthday.isValid() ) | 295 | if ( !mData->birthday.isValid() ) |
286 | if ( ad.mData->birthday.isValid()) | 296 | if ( ad.mData->birthday.isValid()) |
287 | mData->birthday = ad.mData->birthday; | 297 | mData->birthday = ad.mData->birthday; |
288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 298 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 299 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 300 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 301 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 302 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 303 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 304 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 305 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 306 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 307 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 308 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
299 | QStringList t; | 309 | QStringList t; |
300 | QStringList tAD; | 310 | QStringList tAD; |
301 | uint iii; | 311 | uint iii; |
302 | 312 | ||
303 | // ********** phone numbers | 313 | // ********** phone numbers |
304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); | 314 | PhoneNumber::List phoneAD = ad.phoneNumbers(); |
305 | PhoneNumber::List::Iterator phoneItAD; | 315 | PhoneNumber::List::Iterator phoneItAD; |
306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | 316 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { |
307 | bool found = false; | 317 | bool found = false; |
308 | PhoneNumber::List::Iterator it; | 318 | PhoneNumber::List::Iterator it; |
309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 319 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
310 | if ( ( *phoneItAD ).contains( (*it) ) ) { | 320 | if ( ( *phoneItAD ).contains( (*it) ) ) { |
311 | found = true; | 321 | found = true; |
312 | (*it).setType( ( *phoneItAD ).type() ); | 322 | (*it).setType( ( *phoneItAD ).type() ); |
313 | (*it).setNumber( ( *phoneItAD ).number() ); | 323 | (*it).setNumber( ( *phoneItAD ).number() ); |
314 | break; | 324 | break; |
315 | } | 325 | } |
316 | } | 326 | } |
317 | if ( isSubSet && ! found ) | 327 | if ( isSubSet && ! found ) |
318 | mData->phoneNumbers.append( *phoneItAD ); | 328 | mData->phoneNumbers.append( *phoneItAD ); |
319 | } | 329 | } |
320 | if ( isSubSet ) { | 330 | if ( isSubSet ) { |
321 | // ************* emails; | 331 | // ************* emails; |
322 | t = mData->emails; | 332 | t = mData->emails; |
323 | tAD = ad.mData->emails; | 333 | tAD = ad.mData->emails; |
324 | for ( iii = 0; iii < tAD.count(); ++iii) | 334 | for ( iii = 0; iii < tAD.count(); ++iii) |
325 | if ( !t.contains(tAD[iii] ) ) | 335 | if ( !t.contains(tAD[iii] ) ) |
326 | mData->emails.append( tAD[iii] ); | 336 | mData->emails.append( tAD[iii] ); |
327 | } | 337 | } |
328 | 338 | ||
329 | // ************* categories; | 339 | // ************* categories; |
330 | t = mData->categories; | 340 | t = mData->categories; |
331 | tAD = ad.mData->categories; | 341 | tAD = ad.mData->categories; |
332 | for ( iii = 0; iii < tAD.count(); ++iii) | 342 | for ( iii = 0; iii < tAD.count(); ++iii) |
333 | if ( !t.contains(tAD[iii] ) ) | 343 | if ( !t.contains(tAD[iii] ) ) |
334 | mData->categories.append( tAD[iii] ); | 344 | mData->categories.append( tAD[iii] ); |
335 | QStringList::ConstIterator it; | 345 | QStringList::ConstIterator it; |
336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 346 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
337 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 347 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
338 | bool found = false; | 348 | bool found = false; |
339 | QStringList::ConstIterator itL; | 349 | QStringList::ConstIterator itL; |
340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 350 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
341 | if ( (*itL).startsWith( qualifiedName ) ) { | 351 | if ( (*itL).startsWith( qualifiedName ) ) { |
342 | found = true; | 352 | found = true; |
343 | break; | 353 | break; |
344 | } | 354 | } |
345 | } | 355 | } |
346 | if ( ! found ) { | 356 | if ( ! found ) { |
347 | mData->custom.append( *it ); | 357 | mData->custom.append( *it ); |
348 | } | 358 | } |
349 | } | 359 | } |
350 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 360 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; |
351 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; | 361 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
352 | if ( !mData->sound.isIntern() ) { | 362 | if ( !mData->sound.isIntern() ) { |
353 | if ( mData->sound.url().isEmpty() ) { | 363 | if ( mData->sound.url().isEmpty() ) { |
354 | mData->sound = ad.mData->sound; | 364 | mData->sound = ad.mData->sound; |
355 | } | 365 | } |
356 | } | 366 | } |
357 | if ( !mData->agent.isIntern() ) { | 367 | if ( !mData->agent.isIntern() ) { |
358 | if ( mData->agent.url().isEmpty() ) { | 368 | if ( mData->agent.url().isEmpty() ) { |
359 | mData->agent = ad.mData->agent; | 369 | mData->agent = ad.mData->agent; |
360 | } | 370 | } |
361 | } | 371 | } |
362 | { | 372 | { |
363 | Key::List::Iterator itA; | 373 | Key::List::Iterator itA; |
364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 374 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
365 | bool found = false; | 375 | bool found = false; |
366 | Key::List::Iterator it; | 376 | Key::List::Iterator it; |
367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 377 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
368 | if ( (*it) == (*itA)) { | 378 | if ( (*it) == (*itA)) { |
369 | found = true; | 379 | found = true; |
370 | break; | 380 | break; |
371 | 381 | ||
372 | } | 382 | } |
373 | } | 383 | } |
374 | if ( ! found ) { | 384 | if ( ! found ) { |
375 | mData->keys.append( *itA ); | 385 | mData->keys.append( *itA ); |
376 | } | 386 | } |
377 | } | 387 | } |
378 | } | 388 | } |
379 | KABC::Address::List::Iterator addressIterA; | 389 | KABC::Address::List::Iterator addressIterA; |
380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 390 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
381 | bool found = false; | 391 | bool found = false; |
382 | KABC::Address::List::Iterator addressIter; | 392 | KABC::Address::List::Iterator addressIter; |
383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 393 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
384 | ++addressIter ) { | 394 | ++addressIter ) { |
385 | if ( (*addressIter) == (*addressIterA)) { | 395 | if ( (*addressIter) == (*addressIterA)) { |
386 | found = true; | 396 | found = true; |
387 | (*addressIter).setType( (*addressIterA).type() ); | 397 | (*addressIter).setType( (*addressIterA).type() ); |
388 | break; | 398 | break; |
389 | } | 399 | } |
390 | 400 | ||
391 | } | 401 | } |
392 | if ( isSubSet && ! found ) { | 402 | if ( isSubSet && ! found ) { |
393 | mData->addresses.append( *addressIterA ); | 403 | mData->addresses.append( *addressIterA ); |
394 | } | 404 | } |
395 | } | 405 | } |
396 | //qDebug("merge contact %s ", ad.uid().latin1()); | 406 | //qDebug("merge contact %s ", ad.uid().latin1()); |
397 | setUid( ad.uid() ); | 407 | setUid( ad.uid() ); |
@@ -986,257 +996,260 @@ TimeZone Addressee::timeZone() const | |||
986 | return mData->timeZone; | 996 | return mData->timeZone; |
987 | } | 997 | } |
988 | 998 | ||
989 | QString Addressee::timeZoneLabel() | 999 | QString Addressee::timeZoneLabel() |
990 | { | 1000 | { |
991 | return i18n("Time Zone"); | 1001 | return i18n("Time Zone"); |
992 | } | 1002 | } |
993 | 1003 | ||
994 | 1004 | ||
995 | void Addressee::setGeo( const Geo &geo ) | 1005 | void Addressee::setGeo( const Geo &geo ) |
996 | { | 1006 | { |
997 | if ( geo == mData->geo ) return; | 1007 | if ( geo == mData->geo ) return; |
998 | detach(); | 1008 | detach(); |
999 | mData->empty = false; | 1009 | mData->empty = false; |
1000 | mData->geo = geo; | 1010 | mData->geo = geo; |
1001 | } | 1011 | } |
1002 | 1012 | ||
1003 | Geo Addressee::geo() const | 1013 | Geo Addressee::geo() const |
1004 | { | 1014 | { |
1005 | return mData->geo; | 1015 | return mData->geo; |
1006 | } | 1016 | } |
1007 | 1017 | ||
1008 | QString Addressee::geoLabel() | 1018 | QString Addressee::geoLabel() |
1009 | { | 1019 | { |
1010 | return i18n("Geographic Position"); | 1020 | return i18n("Geographic Position"); |
1011 | } | 1021 | } |
1012 | 1022 | ||
1013 | 1023 | ||
1014 | void Addressee::setTitle( const QString &title ) | 1024 | void Addressee::setTitle( const QString &title ) |
1015 | { | 1025 | { |
1016 | if ( title == mData->title ) return; | 1026 | if ( title == mData->title ) return; |
1017 | detach(); | 1027 | detach(); |
1018 | mData->empty = false; | 1028 | mData->empty = false; |
1019 | mData->title = title; | 1029 | mData->title = title; |
1020 | } | 1030 | } |
1021 | 1031 | ||
1022 | QString Addressee::title() const | 1032 | QString Addressee::title() const |
1023 | { | 1033 | { |
1024 | return mData->title; | 1034 | return mData->title; |
1025 | } | 1035 | } |
1026 | 1036 | ||
1027 | QString Addressee::titleLabel() | 1037 | QString Addressee::titleLabel() |
1028 | { | 1038 | { |
1029 | return i18n("Title"); | 1039 | return i18n("Title"); |
1030 | } | 1040 | } |
1031 | 1041 | ||
1032 | 1042 | ||
1033 | void Addressee::setRole( const QString &role ) | 1043 | void Addressee::setRole( const QString &role ) |
1034 | { | 1044 | { |
1035 | if ( role == mData->role ) return; | 1045 | if ( role == mData->role ) return; |
1036 | detach(); | 1046 | detach(); |
1037 | mData->empty = false; | 1047 | mData->empty = false; |
1038 | mData->role = role; | 1048 | mData->role = role; |
1039 | } | 1049 | } |
1040 | 1050 | ||
1041 | QString Addressee::role() const | 1051 | QString Addressee::role() const |
1042 | { | 1052 | { |
1043 | return mData->role; | 1053 | return mData->role; |
1044 | } | 1054 | } |
1045 | 1055 | ||
1046 | QString Addressee::roleLabel() | 1056 | QString Addressee::roleLabel() |
1047 | { | 1057 | { |
1048 | return i18n("Role"); | 1058 | return i18n("Role"); |
1049 | } | 1059 | } |
1050 | 1060 | ||
1051 | 1061 | ||
1052 | void Addressee::setOrganization( const QString &organization ) | 1062 | void Addressee::setOrganization( const QString &organization ) |
1053 | { | 1063 | { |
1054 | if ( organization == mData->organization ) return; | 1064 | if ( organization == mData->organization ) return; |
1055 | detach(); | 1065 | detach(); |
1056 | mData->empty = false; | 1066 | mData->empty = false; |
1057 | mData->organization = organization; | 1067 | mData->organization = organization; |
1058 | } | 1068 | } |
1059 | 1069 | ||
1060 | QString Addressee::organization() const | 1070 | QString Addressee::organization() const |
1061 | { | 1071 | { |
1062 | return mData->organization; | 1072 | return mData->organization; |
1063 | } | 1073 | } |
1064 | 1074 | ||
1065 | QString Addressee::organizationLabel() | 1075 | QString Addressee::organizationLabel() |
1066 | { | 1076 | { |
1067 | return i18n("Organization"); | 1077 | return i18n("Organization"); |
1068 | } | 1078 | } |
1069 | 1079 | ||
1070 | 1080 | ||
1071 | void Addressee::setNote( const QString ¬e ) | 1081 | void Addressee::setNote( const QString ¬e ) |
1072 | { | 1082 | { |
1073 | if ( note == mData->note ) return; | 1083 | if ( note == mData->note ) return; |
1074 | detach(); | 1084 | detach(); |
1075 | mData->empty = false; | 1085 | mData->empty = false; |
1076 | mData->note = note; | 1086 | mData->note = note; |
1077 | } | 1087 | } |
1078 | 1088 | ||
1079 | QString Addressee::note() const | 1089 | QString Addressee::note() const |
1080 | { | 1090 | { |
1081 | return mData->note; | 1091 | return mData->note; |
1082 | } | 1092 | } |
1083 | 1093 | ||
1084 | QString Addressee::noteLabel() | 1094 | QString Addressee::noteLabel() |
1085 | { | 1095 | { |
1086 | return i18n("Note"); | 1096 | return i18n("Note"); |
1087 | } | 1097 | } |
1088 | 1098 | ||
1089 | 1099 | ||
1090 | void Addressee::setProductId( const QString &productId ) | 1100 | void Addressee::setProductId( const QString &productId ) |
1091 | { | 1101 | { |
1092 | if ( productId == mData->productId ) return; | 1102 | if ( productId == mData->productId ) return; |
1093 | detach(); | 1103 | detach(); |
1094 | mData->empty = false; | 1104 | mData->empty = false; |
1095 | mData->productId = productId; | 1105 | mData->productId = productId; |
1096 | } | 1106 | } |
1097 | 1107 | ||
1098 | QString Addressee::productId() const | 1108 | QString Addressee::productId() const |
1099 | { | 1109 | { |
1100 | return mData->productId; | 1110 | return mData->productId; |
1101 | } | 1111 | } |
1102 | 1112 | ||
1103 | QString Addressee::productIdLabel() | 1113 | QString Addressee::productIdLabel() |
1104 | { | 1114 | { |
1105 | return i18n("Product Identifier"); | 1115 | return i18n("Product Identifier"); |
1106 | } | 1116 | } |
1107 | 1117 | ||
1108 | 1118 | ||
1109 | void Addressee::setRevision( const QDateTime &revision ) | 1119 | void Addressee::setRevision( const QDateTime &revision ) |
1110 | { | 1120 | { |
1111 | if ( revision == mData->revision ) return; | 1121 | if ( revision == mData->revision ) return; |
1112 | detach(); | 1122 | detach(); |
1113 | mData->empty = false; | 1123 | mData->empty = false; |
1114 | mData->revision = revision; | 1124 | mData->revision = QDateTime( revision.date(), |
1125 | QTime (revision.time().hour(), | ||
1126 | revision.time().minute(), | ||
1127 | revision.time().second())); | ||
1115 | } | 1128 | } |
1116 | 1129 | ||
1117 | QDateTime Addressee::revision() const | 1130 | QDateTime Addressee::revision() const |
1118 | { | 1131 | { |
1119 | return mData->revision; | 1132 | return mData->revision; |
1120 | } | 1133 | } |
1121 | 1134 | ||
1122 | QString Addressee::revisionLabel() | 1135 | QString Addressee::revisionLabel() |
1123 | { | 1136 | { |
1124 | return i18n("Revision Date"); | 1137 | return i18n("Revision Date"); |
1125 | } | 1138 | } |
1126 | 1139 | ||
1127 | 1140 | ||
1128 | void Addressee::setSortString( const QString &sortString ) | 1141 | void Addressee::setSortString( const QString &sortString ) |
1129 | { | 1142 | { |
1130 | if ( sortString == mData->sortString ) return; | 1143 | if ( sortString == mData->sortString ) return; |
1131 | detach(); | 1144 | detach(); |
1132 | mData->empty = false; | 1145 | mData->empty = false; |
1133 | mData->sortString = sortString; | 1146 | mData->sortString = sortString; |
1134 | } | 1147 | } |
1135 | 1148 | ||
1136 | QString Addressee::sortString() const | 1149 | QString Addressee::sortString() const |
1137 | { | 1150 | { |
1138 | return mData->sortString; | 1151 | return mData->sortString; |
1139 | } | 1152 | } |
1140 | 1153 | ||
1141 | QString Addressee::sortStringLabel() | 1154 | QString Addressee::sortStringLabel() |
1142 | { | 1155 | { |
1143 | return i18n("Sort String"); | 1156 | return i18n("Sort String"); |
1144 | } | 1157 | } |
1145 | 1158 | ||
1146 | 1159 | ||
1147 | void Addressee::setUrl( const KURL &url ) | 1160 | void Addressee::setUrl( const KURL &url ) |
1148 | { | 1161 | { |
1149 | if ( url == mData->url ) return; | 1162 | if ( url == mData->url ) return; |
1150 | detach(); | 1163 | detach(); |
1151 | mData->empty = false; | 1164 | mData->empty = false; |
1152 | mData->url = url; | 1165 | mData->url = url; |
1153 | } | 1166 | } |
1154 | 1167 | ||
1155 | KURL Addressee::url() const | 1168 | KURL Addressee::url() const |
1156 | { | 1169 | { |
1157 | return mData->url; | 1170 | return mData->url; |
1158 | } | 1171 | } |
1159 | 1172 | ||
1160 | QString Addressee::urlLabel() | 1173 | QString Addressee::urlLabel() |
1161 | { | 1174 | { |
1162 | return i18n("URL"); | 1175 | return i18n("URL"); |
1163 | } | 1176 | } |
1164 | 1177 | ||
1165 | 1178 | ||
1166 | void Addressee::setSecrecy( const Secrecy &secrecy ) | 1179 | void Addressee::setSecrecy( const Secrecy &secrecy ) |
1167 | { | 1180 | { |
1168 | if ( secrecy == mData->secrecy ) return; | 1181 | if ( secrecy == mData->secrecy ) return; |
1169 | detach(); | 1182 | detach(); |
1170 | mData->empty = false; | 1183 | mData->empty = false; |
1171 | mData->secrecy = secrecy; | 1184 | mData->secrecy = secrecy; |
1172 | } | 1185 | } |
1173 | 1186 | ||
1174 | Secrecy Addressee::secrecy() const | 1187 | Secrecy Addressee::secrecy() const |
1175 | { | 1188 | { |
1176 | return mData->secrecy; | 1189 | return mData->secrecy; |
1177 | } | 1190 | } |
1178 | 1191 | ||
1179 | QString Addressee::secrecyLabel() | 1192 | QString Addressee::secrecyLabel() |
1180 | { | 1193 | { |
1181 | return i18n("Security Class"); | 1194 | return i18n("Security Class"); |
1182 | } | 1195 | } |
1183 | 1196 | ||
1184 | 1197 | ||
1185 | void Addressee::setLogo( const Picture &logo ) | 1198 | void Addressee::setLogo( const Picture &logo ) |
1186 | { | 1199 | { |
1187 | if ( logo == mData->logo ) return; | 1200 | if ( logo == mData->logo ) return; |
1188 | detach(); | 1201 | detach(); |
1189 | mData->empty = false; | 1202 | mData->empty = false; |
1190 | mData->logo = logo; | 1203 | mData->logo = logo; |
1191 | } | 1204 | } |
1192 | 1205 | ||
1193 | Picture Addressee::logo() const | 1206 | Picture Addressee::logo() const |
1194 | { | 1207 | { |
1195 | return mData->logo; | 1208 | return mData->logo; |
1196 | } | 1209 | } |
1197 | 1210 | ||
1198 | QString Addressee::logoLabel() | 1211 | QString Addressee::logoLabel() |
1199 | { | 1212 | { |
1200 | return i18n("Logo"); | 1213 | return i18n("Logo"); |
1201 | } | 1214 | } |
1202 | 1215 | ||
1203 | 1216 | ||
1204 | void Addressee::setPhoto( const Picture &photo ) | 1217 | void Addressee::setPhoto( const Picture &photo ) |
1205 | { | 1218 | { |
1206 | if ( photo == mData->photo ) return; | 1219 | if ( photo == mData->photo ) return; |
1207 | detach(); | 1220 | detach(); |
1208 | mData->empty = false; | 1221 | mData->empty = false; |
1209 | mData->photo = photo; | 1222 | mData->photo = photo; |
1210 | } | 1223 | } |
1211 | 1224 | ||
1212 | Picture Addressee::photo() const | 1225 | Picture Addressee::photo() const |
1213 | { | 1226 | { |
1214 | return mData->photo; | 1227 | return mData->photo; |
1215 | } | 1228 | } |
1216 | 1229 | ||
1217 | QString Addressee::photoLabel() | 1230 | QString Addressee::photoLabel() |
1218 | { | 1231 | { |
1219 | return i18n("Photo"); | 1232 | return i18n("Photo"); |
1220 | } | 1233 | } |
1221 | 1234 | ||
1222 | 1235 | ||
1223 | void Addressee::setSound( const Sound &sound ) | 1236 | void Addressee::setSound( const Sound &sound ) |
1224 | { | 1237 | { |
1225 | if ( sound == mData->sound ) return; | 1238 | if ( sound == mData->sound ) return; |
1226 | detach(); | 1239 | detach(); |
1227 | mData->empty = false; | 1240 | mData->empty = false; |
1228 | mData->sound = sound; | 1241 | mData->sound = sound; |
1229 | } | 1242 | } |
1230 | 1243 | ||
1231 | Sound Addressee::sound() const | 1244 | Sound Addressee::sound() const |
1232 | { | 1245 | { |
1233 | return mData->sound; | 1246 | return mData->sound; |
1234 | } | 1247 | } |
1235 | 1248 | ||
1236 | QString Addressee::soundLabel() | 1249 | QString Addressee::soundLabel() |
1237 | { | 1250 | { |
1238 | return i18n("Sound"); | 1251 | return i18n("Sound"); |
1239 | } | 1252 | } |
1240 | 1253 | ||
1241 | 1254 | ||
1242 | void Addressee::setAgent( const Agent &agent ) | 1255 | void Addressee::setAgent( const Agent &agent ) |