summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
authorzautrix <zautrix>2004-10-27 19:44:10 (UTC)
committer zautrix <zautrix>2004-10-27 19:44:10 (UTC)
commitbb82cac85cc196b3f60921ab27e84204036b54b8 (patch) (unidiff)
tree518629480b983b6b85a4cf1e5542f94fe1687e41 /kabc/addressbook.cpp
parent85a0e0d9b1d60805cb4947be1c296c18e73c82b8 (diff)
downloadkdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.zip
kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.tar.gz
kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.tar.bz2
sync fixes
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9b196b5..5774c36 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -813,186 +813,197 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeRes
813 } 813 }
814 } 814 }
815 } 815 }
816 } 816 }
817 if ( found ) 817 if ( found )
818 return; 818 return;
819 d->mAddressees.append( a ); 819 d->mAddressees.append( a );
820 Addressee& addr = d->mAddressees.last(); 820 Addressee& addr = d->mAddressees.last();
821 if ( addr.resource() == 0 ) 821 if ( addr.resource() == 0 )
822 addr.setResource( standardResource() ); 822 addr.setResource( standardResource() );
823 823
824 addr.setChanged( true ); 824 addr.setChanged( true );
825} 825}
826 826
827void AddressBook::removeAddressee( const Addressee &a ) 827void AddressBook::removeAddressee( const Addressee &a )
828{ 828{
829 Iterator it; 829 Iterator it;
830 Iterator it2; 830 Iterator it2;
831 bool found = false; 831 bool found = false;
832 for ( it = begin(); it != end(); ++it ) { 832 for ( it = begin(); it != end(); ++it ) {
833 if ( a.uid() == (*it).uid() ) { 833 if ( a.uid() == (*it).uid() ) {
834 found = true; 834 found = true;
835 it2 = it; 835 it2 = it;
836 } else { 836 } else {
837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
838 QString name = (*it).uid().mid( 19 ); 838 QString name = (*it).uid().mid( 19 );
839 Addressee b = a; 839 Addressee b = a;
840 QString id = b.getID( name ); 840 QString id = b.getID( name );
841 if ( ! id.isEmpty() ) { 841 if ( ! id.isEmpty() ) {
842 QString des = (*it).note(); 842 QString des = (*it).note();
843 if( des.find( id ) < 0 ) { 843 if( des.find( id ) < 0 ) {
844 des += id + ","; 844 des += id + ",";
845 (*it).setNote( des ); 845 (*it).setNote( des );
846 } 846 }
847 } 847 }
848 } 848 }
849 849
850 } 850 }
851 } 851 }
852 852
853 if ( found ) 853 if ( found )
854 removeAddressee( it2 ); 854 removeAddressee( it2 );
855 855
856} 856}
857 857
858void AddressBook::removeSyncAddressees( bool removeDeleted ) 858void AddressBook::removeSyncAddressees( bool removeDeleted )
859{ 859{
860 Iterator it = begin(); 860 Iterator it = begin();
861 Iterator it2 ; 861 Iterator it2 ;
862 QDateTime dt ( QDate( 2004,1,1) ); 862 QDateTime dt ( QDate( 2004,1,1) );
863 while ( it != end() ) { 863 while ( it != end() ) {
864 (*it).setRevision( dt ); 864 (*it).setRevision( dt );
865 if (( *it).IDStr() != "changed" ) { 865 if (( *it).IDStr() != "changed" ) {
866 // "changed" is used for tagging changed addressees when syncing with KDE or OL 866 // "changed" is used for tagging changed addressees when syncing with KDE or OL
867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
868 (*it).setIDStr(""); 868 (*it).setIDStr("");
869 } 869 }
870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
871 it2 = it; 871 it2 = it;
872 //qDebug("removing %s ",(*it).uid().latin1() ); 872 //qDebug("removing %s ",(*it).uid().latin1() );
873 ++it; 873 ++it;
874 removeAddressee( it2 ); 874 removeAddressee( it2 );
875 } else { 875 } else {
876 //qDebug("skipping %s ",(*it).uid().latin1() ); 876 //qDebug("skipping %s ",(*it).uid().latin1() );
877 if ( removeDeleted ) {
878 // 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
880 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
881
882
883 }
877 ++it; 884 ++it;
878 } 885 }
879 } 886 }
880 deleteRemovedAddressees(); 887 deleteRemovedAddressees();
881} 888}
882 889
883void AddressBook::removeAddressee( const Iterator &it ) 890void AddressBook::removeAddressee( const Iterator &it )
884{ 891{
885 d->mRemovedAddressees.append( (*it) ); 892 d->mRemovedAddressees.append( (*it) );
886 d->mAddressees.remove( it.d->mIt ); 893 d->mAddressees.remove( it.d->mIt );
887} 894}
888 895
889AddressBook::Iterator AddressBook::find( const Addressee &a ) 896AddressBook::Iterator AddressBook::find( const Addressee &a )
890{ 897{
891 Iterator it; 898 Iterator it;
892 for ( it = begin(); it != end(); ++it ) { 899 for ( it = begin(); it != end(); ++it ) {
893 if ( a.uid() == (*it).uid() ) { 900 if ( a.uid() == (*it).uid() ) {
894 return it; 901 return it;
895 } 902 }
896 } 903 }
897 return end(); 904 return end();
898} 905}
899 906
900Addressee AddressBook::findByUid( const QString &uid ) 907Addressee AddressBook::findByUid( const QString &uid )
901{ 908{
902 Iterator it; 909 Iterator it;
903 for ( it = begin(); it != end(); ++it ) { 910 for ( it = begin(); it != end(); ++it ) {
904 if ( uid == (*it).uid() ) { 911 if ( uid == (*it).uid() ) {
905 return *it; 912 return *it;
906 } 913 }
907 } 914 }
908 return Addressee(); 915 return Addressee();
909} 916}
910void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 917void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
911{ 918{
912 //qDebug("AddressBook::preExternSync "); 919 //qDebug("AddressBook::preExternSync ");
913 AddressBook::Iterator it; 920 AddressBook::Iterator it;
914 for ( it = begin(); it != end(); ++it ) { 921 for ( it = begin(); it != end(); ++it ) {
915 (*it).setID( csd, (*it).externalUID() ); 922 (*it).setID( csd, (*it).externalUID() );
916 (*it).computeCsum( csd ); 923 (*it).computeCsum( csd );
917 } 924 }
918 mergeAB( aBook ,csd, isSubset ); 925 mergeAB( aBook ,csd, isSubset );
919} 926}
920void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 927void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID)
921{ 928{
922 //qDebug("AddressBook::postExternSync "); 929 //qDebug("AddressBook::postExternSync ");
923 AddressBook::Iterator it; 930 AddressBook::Iterator it;
924 for ( it = begin(); it != end(); ++it ) { 931 for ( it = begin(); it != end(); ++it ) {
925 // qDebug("check uid %s ", (*it).uid().latin1() ); 932 //qDebug("check uid %s ", (*it).uid().latin1() );
926 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 933 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
927 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 934 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
928 Addressee ad = aBook->findByUid( ( (*it).uid() )); 935 Addressee ad = aBook->findByUid( ( (*it).uid() ));
929 if ( ad.isEmpty() ) { 936 if ( ad.isEmpty() ) {
930 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 937 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
931 } else { 938 } else {
939 (*it).setIDStr(":");
932 (*it).computeCsum( csd ); 940 (*it).computeCsum( csd );
933 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 941 if ( setID ) {
934 ad.setID( csd, (*it).externalUID() ); 942 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
943 ad.setID( csd, (*it).externalUID() );
944 } else
945 ad.setID( csd, "_" );
935 ad.setCsum( csd, (*it).getCsum( csd ) ); 946 ad.setCsum( csd, (*it).getCsum( csd ) );
936 aBook->insertAddressee( ad ); 947 aBook->insertAddressee( ad );
937 } 948 }
938 } 949 }
939 } 950 }
940} 951}
941 952
942bool AddressBook::containsExternalUid( const QString& uid ) 953bool AddressBook::containsExternalUid( const QString& uid )
943{ 954{
944 Iterator it; 955 Iterator it;
945 for ( it = begin(); it != end(); ++it ) { 956 for ( it = begin(); it != end(); ++it ) {
946 if ( uid == (*it).externalUID( ) ) 957 if ( uid == (*it).externalUID( ) )
947 return true; 958 return true;
948 } 959 }
949 return false; 960 return false;
950} 961}
951Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 962Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
952{ 963{
953 Iterator it; 964 Iterator it;
954 for ( it = begin(); it != end(); ++it ) { 965 for ( it = begin(); it != end(); ++it ) {
955 if ( uid == (*it).getID( profile ) ) 966 if ( uid == (*it).getID( profile ) )
956 return (*it); 967 return (*it);
957 } 968 }
958 return Addressee(); 969 return Addressee();
959} 970}
960void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 971void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
961{ 972{
962 Iterator it; 973 Iterator it;
963 Addressee ad; 974 Addressee ad;
964 for ( it = begin(); it != end(); ++it ) { 975 for ( it = begin(); it != end(); ++it ) {
965 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 976 ad = aBook->findByExternUid( (*it).externalUID(), profile );
966 if ( !ad.isEmpty() ) { 977 if ( !ad.isEmpty() ) {
967 (*it).mergeContact( ad ,isSubset); 978 (*it).mergeContact( ad ,isSubset);
968 } 979 }
969 } 980 }
970#if 0 981#if 0
971 // test only 982 // test only
972 for ( it = begin(); it != end(); ++it ) { 983 for ( it = begin(); it != end(); ++it ) {
973 984
974 qDebug("uid %s ", (*it).uid().latin1()); 985 qDebug("uid %s ", (*it).uid().latin1());
975 } 986 }
976#endif 987#endif
977} 988}
978 989
979#if 0 990#if 0
980Addressee::List AddressBook::getExternLastSyncAddressees() 991Addressee::List AddressBook::getExternLastSyncAddressees()
981{ 992{
982 Addressee::List results; 993 Addressee::List results;
983 994
984 Iterator it; 995 Iterator it;
985 for ( it = begin(); it != end(); ++it ) { 996 for ( it = begin(); it != end(); ++it ) {
986 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 997 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
987 if ( (*it).familyName().left(4) == "!E: " ) 998 if ( (*it).familyName().left(4) == "!E: " )
988 results.append( *it ); 999 results.append( *it );
989 } 1000 }
990 } 1001 }
991 1002
992 return results; 1003 return results;
993} 1004}
994#endif 1005#endif
995void AddressBook::resetTempSyncStat() 1006void AddressBook::resetTempSyncStat()
996{ 1007{
997 Iterator it; 1008 Iterator it;
998 for ( it = begin(); it != end(); ++it ) { 1009 for ( it = begin(); it != end(); ++it ) {