summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-10-11 10:09:39 (UTC)
committer zautrix <zautrix>2004-10-11 10:09:39 (UTC)
commitd3759373291c08d2cde93d85a76d190dc8a33830 (patch) (unidiff)
treeccc808fbdcd2ef0f38747fa459b2c605948f49a5 /kabc
parent504f6b2a8732d980a88234cdef0a80c201b9c4da (diff)
downloadkdepimpi-d3759373291c08d2cde93d85a76d190dc8a33830.zip
kdepimpi-d3759373291c08d2cde93d85a76d190dc8a33830.tar.gz
kdepimpi-d3759373291c08d2cde93d85a76d190dc8a33830.tar.bz2
crash fix in saveAB
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp7
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
@@ -539,211 +539,212 @@ void AddressBook::smplifyAddressees()
539 (*ait).simplifyPhoneNumbers(); 539 (*ait).simplifyPhoneNumbers();
540 (*ait).simplifyPhoneNumberTypes(); 540 (*ait).simplifyPhoneNumberTypes();
541 (*ait).simplifyAddresses(); 541 (*ait).simplifyAddresses();
542 } 542 }
543} 543}
544void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 544void 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}
561void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 561void 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
602bool AddressBook::saveABphone( QString fileName ) 602bool 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}
618bool AddressBook::saveAB() 618bool 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
663AddressBook::Iterator AddressBook::begin() 664AddressBook::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
670AddressBook::ConstIterator AddressBook::begin() const 671AddressBook::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
677AddressBook::Iterator AddressBook::end() 678AddressBook::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
684AddressBook::ConstIterator AddressBook::end() const 685AddressBook::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
691void AddressBook::clear() 692void AddressBook::clear()
692{ 693{
693 d->mAddressees.clear(); 694 d->mAddressees.clear();
694} 695}
695 696
696Ticket *AddressBook::requestSaveTicket( Resource *resource ) 697Ticket *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);
719void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 720void 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();