-rw-r--r-- | kabc/addressbook.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ad0f702..19c26eb 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -443,403 +443,404 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | |||
443 | } | 443 | } |
444 | vcardnew += vcard.mid( start,vcard.length() ); | 444 | vcardnew += vcard.mid( start,vcard.length() ); |
445 | vcard = ""; | 445 | vcard = ""; |
446 | start = 0; | 446 | start = 0; |
447 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 447 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
448 | int sep = vcardnew.find(":", next); | 448 | int sep = vcardnew.find(":", next); |
449 | vcard +=vcardnew.mid( start, next - start+3); | 449 | vcard +=vcardnew.mid( start, next - start+3); |
450 | start = sep; | 450 | start = sep; |
451 | } | 451 | } |
452 | vcard += vcardnew.mid( start,vcardnew.length() ); | 452 | vcard += vcardnew.mid( start,vcardnew.length() ); |
453 | vcard.replace ( QRegExp(";;;") , "" ); | 453 | vcard.replace ( QRegExp(";;;") , "" ); |
454 | vcard.replace ( QRegExp(";;") , "" ); | 454 | vcard.replace ( QRegExp(";;") , "" ); |
455 | datastream += vcard; | 455 | datastream += vcard; |
456 | 456 | ||
457 | } | 457 | } |
458 | 458 | ||
459 | QFile outFile(fileName); | 459 | QFile outFile(fileName); |
460 | if ( outFile.open(IO_WriteOnly) ) { | 460 | if ( outFile.open(IO_WriteOnly) ) { |
461 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 461 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
462 | QTextStream t( &outFile ); // use a text stream | 462 | QTextStream t( &outFile ); // use a text stream |
463 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 463 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
464 | t <<datastream; | 464 | t <<datastream; |
465 | t << "\r\n\r\n"; | 465 | t << "\r\n\r\n"; |
466 | outFile.close(); | 466 | outFile.close(); |
467 | 467 | ||
468 | } else { | 468 | } else { |
469 | qDebug("Error open temp file "); | 469 | qDebug("Error open temp file "); |
470 | return false; | 470 | return false; |
471 | } | 471 | } |
472 | return true; | 472 | return true; |
473 | 473 | ||
474 | } | 474 | } |
475 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 475 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
476 | { | 476 | { |
477 | 477 | ||
478 | if ( removeOld ) | 478 | if ( removeOld ) |
479 | setUntagged(); | 479 | setUntagged(); |
480 | KABC::Addressee::List list; | 480 | KABC::Addressee::List list; |
481 | QFile file( fileName ); | 481 | QFile file( fileName ); |
482 | file.open( IO_ReadOnly ); | 482 | file.open( IO_ReadOnly ); |
483 | QByteArray rawData = file.readAll(); | 483 | QByteArray rawData = file.readAll(); |
484 | file.close(); | 484 | file.close(); |
485 | QString data; | 485 | QString data; |
486 | if ( replaceLabel ) { | 486 | if ( replaceLabel ) { |
487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
488 | data.replace ( QRegExp("LABEL") , "ADR" ); | 488 | data.replace ( QRegExp("LABEL") , "ADR" ); |
489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
490 | } else | 490 | } else |
491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
492 | KABC::VCardTool tool; | 492 | KABC::VCardTool tool; |
493 | list = tool.parseVCards( data ); | 493 | list = tool.parseVCards( data ); |
494 | KABC::Addressee::List::Iterator it; | 494 | KABC::Addressee::List::Iterator it; |
495 | for ( it = list.begin(); it != list.end(); ++it ) { | 495 | for ( it = list.begin(); it != list.end(); ++it ) { |
496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
497 | if ( !id.isEmpty() ) | 497 | if ( !id.isEmpty() ) |
498 | (*it).setIDStr(id ); | 498 | (*it).setIDStr(id ); |
499 | (*it).setResource( 0 ); | 499 | (*it).setResource( 0 ); |
500 | if ( replaceLabel ) | 500 | if ( replaceLabel ) |
501 | (*it).removeVoice(); | 501 | (*it).removeVoice(); |
502 | if ( removeOld ) | 502 | if ( removeOld ) |
503 | (*it).setTagged( true ); | 503 | (*it).setTagged( true ); |
504 | insertAddressee( (*it), false, true ); | 504 | insertAddressee( (*it), false, true ); |
505 | } | 505 | } |
506 | if ( removeOld ) | 506 | if ( removeOld ) |
507 | removeUntagged(); | 507 | removeUntagged(); |
508 | } | 508 | } |
509 | void AddressBook::setUntagged() | 509 | void AddressBook::setUntagged() |
510 | { | 510 | { |
511 | Iterator ait; | 511 | Iterator ait; |
512 | for ( ait = begin(); ait != end(); ++ait ) { | 512 | for ( ait = begin(); ait != end(); ++ait ) { |
513 | (*ait).setTagged( false ); | 513 | (*ait).setTagged( false ); |
514 | } | 514 | } |
515 | } | 515 | } |
516 | void AddressBook::removeUntagged() | 516 | void AddressBook::removeUntagged() |
517 | { | 517 | { |
518 | Iterator ait; | 518 | Iterator ait; |
519 | bool todelete = false; | 519 | bool todelete = false; |
520 | Iterator todel; | 520 | Iterator todel; |
521 | for ( ait = begin(); ait != end(); ++ait ) { | 521 | for ( ait = begin(); ait != end(); ++ait ) { |
522 | if ( todelete ) | 522 | if ( todelete ) |
523 | removeAddressee( todel ); | 523 | removeAddressee( todel ); |
524 | if (!(*ait).tagged()) { | 524 | if (!(*ait).tagged()) { |
525 | todelete = true; | 525 | todelete = true; |
526 | todel = ait; | 526 | todel = ait; |
527 | } else | 527 | } else |
528 | todelete = false; | 528 | todelete = false; |
529 | } | 529 | } |
530 | if ( todelete ) | 530 | if ( todelete ) |
531 | removeAddressee( todel ); | 531 | removeAddressee( todel ); |
532 | deleteRemovedAddressees(); | 532 | deleteRemovedAddressees(); |
533 | } | 533 | } |
534 | void AddressBook::smplifyAddressees() | 534 | void AddressBook::smplifyAddressees() |
535 | { | 535 | { |
536 | Iterator ait; | 536 | Iterator ait; |
537 | for ( ait = begin(); ait != end(); ++ait ) { | 537 | for ( ait = begin(); ait != end(); ++ait ) { |
538 | (*ait).simplifyEmails(); | 538 | (*ait).simplifyEmails(); |
539 | (*ait).simplifyPhoneNumbers(); | 539 | (*ait).simplifyPhoneNumbers(); |
540 | (*ait).simplifyPhoneNumberTypes(); | 540 | (*ait).simplifyPhoneNumberTypes(); |
541 | (*ait).simplifyAddresses(); | 541 | (*ait).simplifyAddresses(); |
542 | } | 542 | } |
543 | } | 543 | } |
544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
545 | { | 545 | { |
546 | Iterator ait; | 546 | Iterator ait; |
547 | for ( ait = begin(); ait != end(); ++ait ) { | 547 | for ( ait = begin(); ait != end(); ++ait ) { |
548 | QString id = (*ait).IDStr(); | 548 | QString id = (*ait).IDStr(); |
549 | (*ait).setIDStr( ":"); | 549 | (*ait).setIDStr( ":"); |
550 | (*ait).setExternalUID( id ); | 550 | (*ait).setExternalUID( id ); |
551 | (*ait).setOriginalExternalUID( id ); | 551 | (*ait).setOriginalExternalUID( id ); |
552 | if ( isPreSync ) | 552 | if ( isPreSync ) |
553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
554 | else { | 554 | else { |
555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
556 | (*ait).setID( currentSyncDevice,id ); | 556 | (*ait).setID( currentSyncDevice,id ); |
557 | 557 | ||
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
562 | { | 562 | { |
563 | 563 | ||
564 | setUntagged(); | 564 | setUntagged(); |
565 | KABC::Addressee::List list; | 565 | KABC::Addressee::List list; |
566 | QFile file( fileName ); | 566 | QFile file( fileName ); |
567 | file.open( IO_ReadOnly ); | 567 | file.open( IO_ReadOnly ); |
568 | QByteArray rawData = file.readAll(); | 568 | QByteArray rawData = file.readAll(); |
569 | file.close(); | 569 | file.close(); |
570 | QString data; | 570 | QString data; |
571 | 571 | ||
572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
573 | KABC::VCardTool tool; | 573 | KABC::VCardTool tool; |
574 | list = tool.parseVCards( data ); | 574 | list = tool.parseVCards( data ); |
575 | KABC::Addressee::List::Iterator it; | 575 | KABC::Addressee::List::Iterator it; |
576 | for ( it = list.begin(); it != list.end(); ++it ) { | 576 | for ( it = list.begin(); it != list.end(); ++it ) { |
577 | Iterator ait; | 577 | Iterator ait; |
578 | for ( ait = begin(); ait != end(); ++ait ) { | 578 | for ( ait = begin(); ait != end(); ++ait ) { |
579 | if ( !(*ait).tagged() ) { | 579 | if ( !(*ait).tagged() ) { |
580 | if ( (*ait).containsAdr(*it)) { | 580 | if ( (*ait).containsAdr(*it)) { |
581 | (*ait).setTagged(true); | 581 | (*ait).setTagged(true); |
582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
583 | (*it).setIDStr( ":"); | 583 | (*it).setIDStr( ":"); |
584 | (*it).setID( currentSyncDevice,id ); | 584 | (*it).setID( currentSyncDevice,id ); |
585 | (*it).setExternalUID( id ); | 585 | (*it).setExternalUID( id ); |
586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
587 | (*it).setUid( ( (*ait).uid() )); | 587 | (*it).setUid( ( (*ait).uid() )); |
588 | break; | 588 | break; |
589 | } | 589 | } |
590 | } | 590 | } |
591 | 591 | ||
592 | } | 592 | } |
593 | if ( ait == end() ) | 593 | if ( ait == end() ) |
594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
595 | } | 595 | } |
596 | clear(); | 596 | clear(); |
597 | for ( it = list.begin(); it != list.end(); ++it ) { | 597 | for ( it = list.begin(); it != list.end(); ++it ) { |
598 | insertAddressee( (*it) ); | 598 | insertAddressee( (*it) ); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | 601 | ||
602 | bool AddressBook::saveABphone( QString fileName ) | 602 | bool AddressBook::saveABphone( QString fileName ) |
603 | { | 603 | { |
604 | //smplifyAddressees(); | 604 | //smplifyAddressees(); |
605 | qDebug("saveABphone:: saving AB... "); | 605 | qDebug("saveABphone:: saving AB... "); |
606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
607 | return false; | 607 | return false; |
608 | qDebug("saveABphone:: writing to phone... "); | 608 | qDebug("saveABphone:: writing to phone... "); |
609 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 609 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
610 | return false; | 610 | return false; |
611 | } | 611 | } |
612 | qDebug("saveABphone:: re-reading from phone... "); | 612 | qDebug("saveABphone:: re-reading from phone... "); |
613 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 613 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
614 | return false; | 614 | return false; |
615 | } | 615 | } |
616 | return true; | 616 | return true; |
617 | } | 617 | } |
618 | bool AddressBook::saveAB() | 618 | bool AddressBook::saveAB() |
619 | { | 619 | { |
620 | bool ok = true; | 620 | bool ok = true; |
621 | 621 | ||
622 | deleteRemovedAddressees(); | 622 | deleteRemovedAddressees(); |
623 | Iterator ait; | 623 | Iterator ait; |
624 | for ( ait = begin(); ait != end(); ++ait ) { | 624 | for ( ait = begin(); ait != end(); ++ait ) { |
625 | if ( !(*ait).IDStr().isEmpty() ) { | 625 | if ( !(*ait).IDStr().isEmpty() ) { |
626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | KRES::Manager<Resource>::ActiveIterator it; | 629 | KRES::Manager<Resource>::ActiveIterator it; |
630 | KRES::Manager<Resource> *manager = d->mManager; | 630 | KRES::Manager<Resource> *manager = d->mManager; |
631 | qDebug("SaveAB::saving..." ); | 631 | qDebug("SaveAB::saving..." ); |
632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
633 | qDebug("SaveAB::checking resource..." ); | 633 | qDebug("SaveAB::checking resource..." ); |
634 | if ( (*it)->readOnly() ) | 634 | if ( (*it)->readOnly() ) |
635 | qDebug("readonly." ); | 635 | qDebug("resource is readonly." ); |
636 | if ( (*it)->isOpen() ) | 636 | if ( (*it)->isOpen() ) |
637 | qDebug("open" ); | 637 | qDebug("resource is open" ); |
638 | 638 | ||
639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
640 | Ticket *ticket = requestSaveTicket( *it ); | 640 | Ticket *ticket = requestSaveTicket( *it ); |
641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
642 | if ( !ticket ) { | 642 | if ( !ticket ) { |
643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
644 | .arg( (*it)->resourceName() ) ); | 644 | .arg( (*it)->resourceName() ) ); |
645 | return false; | 645 | return false; |
646 | } | 646 | } |
647 | 647 | ||
648 | //if ( !save( ticket ) ) | 648 | //if ( !save( ticket ) ) |
649 | if ( ticket->resource() ) { | 649 | if ( ticket->resource() ) { |
650 | QString name = ticket->resource()->resourceName(); | ||
650 | if ( ! ticket->resource()->save( ticket ) ) | 651 | if ( ! ticket->resource()->save( ticket ) ) |
651 | ok = false; | 652 | ok = false; |
652 | else | 653 | else |
653 | qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() ); | 654 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
654 | 655 | ||
655 | } else | 656 | } else |
656 | ok = false; | 657 | ok = false; |
657 | 658 | ||
658 | } | 659 | } |
659 | } | 660 | } |
660 | return ok; | 661 | return ok; |
661 | } | 662 | } |
662 | 663 | ||
663 | AddressBook::Iterator AddressBook::begin() | 664 | AddressBook::Iterator AddressBook::begin() |
664 | { | 665 | { |
665 | Iterator it = Iterator(); | 666 | Iterator it = Iterator(); |
666 | it.d->mIt = d->mAddressees.begin(); | 667 | it.d->mIt = d->mAddressees.begin(); |
667 | return it; | 668 | return it; |
668 | } | 669 | } |
669 | 670 | ||
670 | AddressBook::ConstIterator AddressBook::begin() const | 671 | AddressBook::ConstIterator AddressBook::begin() const |
671 | { | 672 | { |
672 | ConstIterator it = ConstIterator(); | 673 | ConstIterator it = ConstIterator(); |
673 | it.d->mIt = d->mAddressees.begin(); | 674 | it.d->mIt = d->mAddressees.begin(); |
674 | return it; | 675 | return it; |
675 | } | 676 | } |
676 | 677 | ||
677 | AddressBook::Iterator AddressBook::end() | 678 | AddressBook::Iterator AddressBook::end() |
678 | { | 679 | { |
679 | Iterator it = Iterator(); | 680 | Iterator it = Iterator(); |
680 | it.d->mIt = d->mAddressees.end(); | 681 | it.d->mIt = d->mAddressees.end(); |
681 | return it; | 682 | return it; |
682 | } | 683 | } |
683 | 684 | ||
684 | AddressBook::ConstIterator AddressBook::end() const | 685 | AddressBook::ConstIterator AddressBook::end() const |
685 | { | 686 | { |
686 | ConstIterator it = ConstIterator(); | 687 | ConstIterator it = ConstIterator(); |
687 | it.d->mIt = d->mAddressees.end(); | 688 | it.d->mIt = d->mAddressees.end(); |
688 | return it; | 689 | return it; |
689 | } | 690 | } |
690 | 691 | ||
691 | void AddressBook::clear() | 692 | void AddressBook::clear() |
692 | { | 693 | { |
693 | d->mAddressees.clear(); | 694 | d->mAddressees.clear(); |
694 | } | 695 | } |
695 | 696 | ||
696 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 697 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
697 | { | 698 | { |
698 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 699 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
699 | 700 | ||
700 | if ( !resource ) | 701 | if ( !resource ) |
701 | { | 702 | { |
702 | qDebug("AddressBook::requestSaveTicket no resource" ); | 703 | qDebug("AddressBook::requestSaveTicket no resource" ); |
703 | resource = standardResource(); | 704 | resource = standardResource(); |
704 | } | 705 | } |
705 | 706 | ||
706 | KRES::Manager<Resource>::ActiveIterator it; | 707 | KRES::Manager<Resource>::ActiveIterator it; |
707 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
708 | if ( (*it) == resource ) { | 709 | if ( (*it) == resource ) { |
709 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 710 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
710 | return 0; | 711 | return 0; |
711 | else | 712 | else |
712 | return (*it)->requestSaveTicket(); | 713 | return (*it)->requestSaveTicket(); |
713 | } | 714 | } |
714 | } | 715 | } |
715 | 716 | ||
716 | return 0; | 717 | return 0; |
717 | } | 718 | } |
718 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 719 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
719 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 720 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
720 | { | 721 | { |
721 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 722 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
722 | //qDebug("block insert "); | 723 | //qDebug("block insert "); |
723 | return; | 724 | return; |
724 | } | 725 | } |
725 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 726 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
726 | bool found = false; | 727 | bool found = false; |
727 | Addressee::List::Iterator it; | 728 | Addressee::List::Iterator it; |
728 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 729 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
729 | if ( a.uid() == (*it).uid() ) { | 730 | if ( a.uid() == (*it).uid() ) { |
730 | 731 | ||
731 | bool changed = false; | 732 | bool changed = false; |
732 | Addressee addr = a; | 733 | Addressee addr = a; |
733 | if ( addr != (*it) ) | 734 | if ( addr != (*it) ) |
734 | changed = true; | 735 | changed = true; |
735 | 736 | ||
736 | if ( takeResource ) { | 737 | if ( takeResource ) { |
737 | Resource * res = (*it).resource(); | 738 | Resource * res = (*it).resource(); |
738 | (*it) = a; | 739 | (*it) = a; |
739 | (*it).setResource( res ); | 740 | (*it).setResource( res ); |
740 | } else { | 741 | } else { |
741 | (*it) = a; | 742 | (*it) = a; |
742 | if ( (*it).resource() == 0 ) | 743 | if ( (*it).resource() == 0 ) |
743 | (*it).setResource( standardResource() ); | 744 | (*it).setResource( standardResource() ); |
744 | } | 745 | } |
745 | if ( changed ) { | 746 | if ( changed ) { |
746 | if ( setRev ) { | 747 | if ( setRev ) { |
747 | 748 | ||
748 | // get rid of micro seconds | 749 | // get rid of micro seconds |
749 | QDateTime dt = QDateTime::currentDateTime(); | 750 | QDateTime dt = QDateTime::currentDateTime(); |
750 | QTime t = dt.time(); | 751 | QTime t = dt.time(); |
751 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 752 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
752 | (*it).setRevision( dt ); | 753 | (*it).setRevision( dt ); |
753 | } | 754 | } |
754 | (*it).setChanged( true ); | 755 | (*it).setChanged( true ); |
755 | } | 756 | } |
756 | 757 | ||
757 | found = true; | 758 | found = true; |
758 | } else { | 759 | } else { |
759 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 760 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
760 | QString name = (*it).uid().mid( 19 ); | 761 | QString name = (*it).uid().mid( 19 ); |
761 | Addressee b = a; | 762 | Addressee b = a; |
762 | QString id = b.getID( name ); | 763 | QString id = b.getID( name ); |
763 | if ( ! id.isEmpty() ) { | 764 | if ( ! id.isEmpty() ) { |
764 | QString des = (*it).note(); | 765 | QString des = (*it).note(); |
765 | int startN; | 766 | int startN; |
766 | if( (startN = des.find( id ) ) >= 0 ) { | 767 | if( (startN = des.find( id ) ) >= 0 ) { |
767 | int endN = des.find( ",", startN+1 ); | 768 | int endN = des.find( ",", startN+1 ); |
768 | des = des.left( startN ) + des.mid( endN+1 ); | 769 | des = des.left( startN ) + des.mid( endN+1 ); |
769 | (*it).setNote( des ); | 770 | (*it).setNote( des ); |
770 | } | 771 | } |
771 | } | 772 | } |
772 | } | 773 | } |
773 | } | 774 | } |
774 | } | 775 | } |
775 | if ( found ) | 776 | if ( found ) |
776 | return; | 777 | return; |
777 | d->mAddressees.append( a ); | 778 | d->mAddressees.append( a ); |
778 | Addressee& addr = d->mAddressees.last(); | 779 | Addressee& addr = d->mAddressees.last(); |
779 | if ( addr.resource() == 0 ) | 780 | if ( addr.resource() == 0 ) |
780 | addr.setResource( standardResource() ); | 781 | addr.setResource( standardResource() ); |
781 | 782 | ||
782 | addr.setChanged( true ); | 783 | addr.setChanged( true ); |
783 | } | 784 | } |
784 | 785 | ||
785 | void AddressBook::removeAddressee( const Addressee &a ) | 786 | void AddressBook::removeAddressee( const Addressee &a ) |
786 | { | 787 | { |
787 | Iterator it; | 788 | Iterator it; |
788 | Iterator it2; | 789 | Iterator it2; |
789 | bool found = false; | 790 | bool found = false; |
790 | for ( it = begin(); it != end(); ++it ) { | 791 | for ( it = begin(); it != end(); ++it ) { |
791 | if ( a.uid() == (*it).uid() ) { | 792 | if ( a.uid() == (*it).uid() ) { |
792 | found = true; | 793 | found = true; |
793 | it2 = it; | 794 | it2 = it; |
794 | } else { | 795 | } else { |
795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 796 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
796 | QString name = (*it).uid().mid( 19 ); | 797 | QString name = (*it).uid().mid( 19 ); |
797 | Addressee b = a; | 798 | Addressee b = a; |
798 | QString id = b.getID( name ); | 799 | QString id = b.getID( name ); |
799 | if ( ! id.isEmpty() ) { | 800 | if ( ! id.isEmpty() ) { |
800 | QString des = (*it).note(); | 801 | QString des = (*it).note(); |
801 | if( des.find( id ) < 0 ) { | 802 | if( des.find( id ) < 0 ) { |
802 | des += id + ","; | 803 | des += id + ","; |
803 | (*it).setNote( des ); | 804 | (*it).setNote( des ); |
804 | } | 805 | } |
805 | } | 806 | } |
806 | } | 807 | } |
807 | 808 | ||
808 | } | 809 | } |
809 | } | 810 | } |
810 | 811 | ||
811 | if ( found ) | 812 | if ( found ) |
812 | removeAddressee( it2 ); | 813 | removeAddressee( it2 ); |
813 | 814 | ||
814 | } | 815 | } |
815 | 816 | ||
816 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 817 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
817 | { | 818 | { |
818 | Iterator it = begin(); | 819 | Iterator it = begin(); |
819 | Iterator it2 ; | 820 | Iterator it2 ; |
820 | QDateTime dt ( QDate( 2004,1,1) ); | 821 | QDateTime dt ( QDate( 2004,1,1) ); |
821 | while ( it != end() ) { | 822 | while ( it != end() ) { |
822 | (*it).setRevision( dt ); | 823 | (*it).setRevision( dt ); |
823 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 824 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
824 | (*it).setIDStr(""); | 825 | (*it).setIDStr(""); |
825 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 826 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
826 | it2 = it; | 827 | it2 = it; |
827 | //qDebug("removing %s ",(*it).uid().latin1() ); | 828 | //qDebug("removing %s ",(*it).uid().latin1() ); |
828 | ++it; | 829 | ++it; |
829 | removeAddressee( it2 ); | 830 | removeAddressee( it2 ); |
830 | } else { | 831 | } else { |
831 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 832 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
832 | ++it; | 833 | ++it; |
833 | } | 834 | } |
834 | } | 835 | } |
835 | deleteRemovedAddressees(); | 836 | deleteRemovedAddressees(); |
836 | } | 837 | } |
837 | 838 | ||
838 | void AddressBook::removeAddressee( const Iterator &it ) | 839 | void AddressBook::removeAddressee( const Iterator &it ) |
839 | { | 840 | { |
840 | d->mRemovedAddressees.append( (*it) ); | 841 | d->mRemovedAddressees.append( (*it) ); |
841 | d->mAddressees.remove( it.d->mIt ); | 842 | d->mAddressees.remove( it.d->mIt ); |
842 | } | 843 | } |
843 | 844 | ||
844 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
845 | { | 846 | { |