-rw-r--r-- | kabc/addressbook.cpp | 8 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 82 | ||||
-rw-r--r-- | kabc/addressee.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 6 |
5 files changed, 68 insertions, 34 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 19c26eb..8882259 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -834,122 +834,122 @@ void AddressBook::removeSyncAddressees( bool removeDeleted ) | |||
834 | } | 834 | } |
835 | } | 835 | } |
836 | deleteRemovedAddressees(); | 836 | deleteRemovedAddressees(); |
837 | } | 837 | } |
838 | 838 | ||
839 | void AddressBook::removeAddressee( const Iterator &it ) | 839 | void AddressBook::removeAddressee( const Iterator &it ) |
840 | { | 840 | { |
841 | d->mRemovedAddressees.append( (*it) ); | 841 | d->mRemovedAddressees.append( (*it) ); |
842 | d->mAddressees.remove( it.d->mIt ); | 842 | d->mAddressees.remove( it.d->mIt ); |
843 | } | 843 | } |
844 | 844 | ||
845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
846 | { | 846 | { |
847 | Iterator it; | 847 | Iterator it; |
848 | for ( it = begin(); it != end(); ++it ) { | 848 | for ( it = begin(); it != end(); ++it ) { |
849 | if ( a.uid() == (*it).uid() ) { | 849 | if ( a.uid() == (*it).uid() ) { |
850 | return it; | 850 | return it; |
851 | } | 851 | } |
852 | } | 852 | } |
853 | return end(); | 853 | return end(); |
854 | } | 854 | } |
855 | 855 | ||
856 | Addressee AddressBook::findByUid( const QString &uid ) | 856 | Addressee AddressBook::findByUid( const QString &uid ) |
857 | { | 857 | { |
858 | Iterator it; | 858 | Iterator it; |
859 | for ( it = begin(); it != end(); ++it ) { | 859 | for ( it = begin(); it != end(); ++it ) { |
860 | if ( uid == (*it).uid() ) { | 860 | if ( uid == (*it).uid() ) { |
861 | return *it; | 861 | return *it; |
862 | } | 862 | } |
863 | } | 863 | } |
864 | return Addressee(); | 864 | return Addressee(); |
865 | } | 865 | } |
866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
867 | { | 867 | { |
868 | //qDebug("AddressBook::preExternSync "); | 868 | //qDebug("AddressBook::preExternSync "); |
869 | AddressBook::Iterator it; | 869 | AddressBook::Iterator it; |
870 | for ( it = begin(); it != end(); ++it ) { | 870 | for ( it = begin(); it != end(); ++it ) { |
871 | (*it).setID( csd, (*it).externalUID() ); | 871 | (*it).setID( csd, (*it).externalUID() ); |
872 | (*it).computeCsum( csd ); | 872 | (*it).computeCsum( csd ); |
873 | } | 873 | } |
874 | mergeAB( aBook ,csd ); | 874 | mergeAB( aBook ,csd, isSubset ); |
875 | } | 875 | } |
876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
877 | { | 877 | { |
878 | //qDebug("AddressBook::postExternSync "); | 878 | //qDebug("AddressBook::postExternSync "); |
879 | AddressBook::Iterator it; | 879 | AddressBook::Iterator it; |
880 | for ( it = begin(); it != end(); ++it ) { | 880 | for ( it = begin(); it != end(); ++it ) { |
881 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 881 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
885 | if ( ad.isEmpty() ) { | 885 | if ( ad.isEmpty() ) { |
886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
887 | } else { | 887 | } else { |
888 | (*it).computeCsum( csd ); | 888 | (*it).computeCsum( csd ); |
889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
890 | ad.setID( csd, (*it).externalUID() ); | 890 | ad.setID( csd, (*it).externalUID() ); |
891 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 891 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
892 | aBook->insertAddressee( ad ); | 892 | aBook->insertAddressee( ad ); |
893 | } | 893 | } |
894 | } | 894 | } |
895 | } | 895 | } |
896 | } | 896 | } |
897 | 897 | ||
898 | bool AddressBook::containsExternalUid( const QString& uid ) | 898 | bool AddressBook::containsExternalUid( const QString& uid ) |
899 | { | 899 | { |
900 | Iterator it; | 900 | Iterator it; |
901 | for ( it = begin(); it != end(); ++it ) { | 901 | for ( it = begin(); it != end(); ++it ) { |
902 | if ( uid == (*it).externalUID( ) ) | 902 | if ( uid == (*it).externalUID( ) ) |
903 | return true; | 903 | return true; |
904 | } | 904 | } |
905 | return false; | 905 | return false; |
906 | } | 906 | } |
907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
908 | { | 908 | { |
909 | Iterator it; | 909 | Iterator it; |
910 | for ( it = begin(); it != end(); ++it ) { | 910 | for ( it = begin(); it != end(); ++it ) { |
911 | if ( uid == (*it).getID( profile ) ) | 911 | if ( uid == (*it).getID( profile ) ) |
912 | return (*it); | 912 | return (*it); |
913 | } | 913 | } |
914 | return Addressee(); | 914 | return Addressee(); |
915 | } | 915 | } |
916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
917 | { | 917 | { |
918 | Iterator it; | 918 | Iterator it; |
919 | Addressee ad; | 919 | Addressee ad; |
920 | for ( it = begin(); it != end(); ++it ) { | 920 | for ( it = begin(); it != end(); ++it ) { |
921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
922 | if ( !ad.isEmpty() ) { | 922 | if ( !ad.isEmpty() ) { |
923 | (*it).mergeContact( ad ); | 923 | (*it).mergeContact( ad ,isSubset); |
924 | } | 924 | } |
925 | } | 925 | } |
926 | #if 0 | 926 | #if 0 |
927 | // test only | 927 | // test only |
928 | for ( it = begin(); it != end(); ++it ) { | 928 | for ( it = begin(); it != end(); ++it ) { |
929 | 929 | ||
930 | qDebug("uid %s ", (*it).uid().latin1()); | 930 | qDebug("uid %s ", (*it).uid().latin1()); |
931 | } | 931 | } |
932 | #endif | 932 | #endif |
933 | } | 933 | } |
934 | 934 | ||
935 | #if 0 | 935 | #if 0 |
936 | Addressee::List AddressBook::getExternLastSyncAddressees() | 936 | Addressee::List AddressBook::getExternLastSyncAddressees() |
937 | { | 937 | { |
938 | Addressee::List results; | 938 | Addressee::List results; |
939 | 939 | ||
940 | Iterator it; | 940 | Iterator it; |
941 | for ( it = begin(); it != end(); ++it ) { | 941 | for ( it = begin(); it != end(); ++it ) { |
942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
943 | if ( (*it).familyName().left(4) == "!E: " ) | 943 | if ( (*it).familyName().left(4) == "!E: " ) |
944 | results.append( *it ); | 944 | results.append( *it ); |
945 | } | 945 | } |
946 | } | 946 | } |
947 | 947 | ||
948 | return results; | 948 | return results; |
949 | } | 949 | } |
950 | #endif | 950 | #endif |
951 | void AddressBook::resetTempSyncStat() | 951 | void AddressBook::resetTempSyncStat() |
952 | { | 952 | { |
953 | Iterator it; | 953 | Iterator it; |
954 | for ( it = begin(); it != end(); ++it ) { | 954 | for ( it = begin(); it != end(); ++it ) { |
955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index df9048b..a6bf451 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -272,69 +272,69 @@ class AddressBook : public QObject | |||
272 | 272 | ||
273 | /** | 273 | /** |
274 | Remove address book resource. | 274 | Remove address book resource. |
275 | */ | 275 | */ |
276 | bool removeResource( Resource * ); | 276 | bool removeResource( Resource * ); |
277 | 277 | ||
278 | /** | 278 | /** |
279 | Return pointer list of all resources. | 279 | Return pointer list of all resources. |
280 | */ | 280 | */ |
281 | QPtrList<Resource> resources(); | 281 | QPtrList<Resource> resources(); |
282 | 282 | ||
283 | /** | 283 | /** |
284 | Set the @p ErrorHandler, that is used by @ref error() to | 284 | Set the @p ErrorHandler, that is used by @ref error() to |
285 | provide gui-independend error messages. | 285 | provide gui-independend error messages. |
286 | */ | 286 | */ |
287 | void setErrorHandler( ErrorHandler * ); | 287 | void setErrorHandler( ErrorHandler * ); |
288 | 288 | ||
289 | /** | 289 | /** |
290 | Shows gui independend error messages. | 290 | Shows gui independend error messages. |
291 | */ | 291 | */ |
292 | void error( const QString& ); | 292 | void error( const QString& ); |
293 | 293 | ||
294 | /** | 294 | /** |
295 | Query all resources to clean up their lock files | 295 | Query all resources to clean up their lock files |
296 | */ | 296 | */ |
297 | void cleanUp(); | 297 | void cleanUp(); |
298 | 298 | ||
299 | // sync stuff | 299 | // sync stuff |
300 | //Addressee::List getExternLastSyncAddressees(); | 300 | //Addressee::List getExternLastSyncAddressees(); |
301 | void resetTempSyncStat(); | 301 | void resetTempSyncStat(); |
302 | QStringList uidList(); | 302 | QStringList uidList(); |
303 | void removeSyncAddressees( bool removeDeleted = false ); | 303 | void removeSyncAddressees( bool removeDeleted = false ); |
304 | void mergeAB( AddressBook *aBook, const QString& profile ); | 304 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); |
305 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 305 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
306 | bool containsExternalUid( const QString& uid ); | 306 | bool containsExternalUid( const QString& uid ); |
307 | 307 | ||
308 | void preExternSync( AddressBook* aBook, const QString& csd ); | 308 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); |
309 | void postExternSync( AddressBook* aBook, const QString& csd ); | 309 | void postExternSync( AddressBook* aBook, const QString& csd ); |
310 | signals: | 310 | signals: |
311 | /** | 311 | /** |
312 | Emitted, when the address book has changed on disk. | 312 | Emitted, when the address book has changed on disk. |
313 | */ | 313 | */ |
314 | void addressBookChanged( AddressBook * ); | 314 | void addressBookChanged( AddressBook * ); |
315 | 315 | ||
316 | /** | 316 | /** |
317 | Emitted, when the address book has been locked for writing. | 317 | Emitted, when the address book has been locked for writing. |
318 | */ | 318 | */ |
319 | void addressBookLocked( AddressBook * ); | 319 | void addressBookLocked( AddressBook * ); |
320 | 320 | ||
321 | /** | 321 | /** |
322 | Emitted, when the address book has been unlocked. | 322 | Emitted, when the address book has been unlocked. |
323 | */ | 323 | */ |
324 | void addressBookUnlocked( AddressBook * ); | 324 | void addressBookUnlocked( AddressBook * ); |
325 | 325 | ||
326 | protected: | 326 | protected: |
327 | void deleteRemovedAddressees(); | 327 | void deleteRemovedAddressees(); |
328 | void setStandardResource( Resource * ); | 328 | void setStandardResource( Resource * ); |
329 | Resource *standardResource(); | 329 | Resource *standardResource(); |
330 | KRES::Manager<Resource> *resourceManager(); | 330 | KRES::Manager<Resource> *resourceManager(); |
331 | 331 | ||
332 | void init(const QString &config, const QString &family); | 332 | void init(const QString &config, const QString &family); |
333 | 333 | ||
334 | private: | 334 | private: |
335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
336 | 336 | ||
337 | 337 | ||
338 | struct AddressBookData; | 338 | struct AddressBookData; |
339 | AddressBookData *d; | 339 | AddressBookData *d; |
340 | bool blockLSEchange; | 340 | bool blockLSEchange; |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 2aca559..295ee4f 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -270,155 +270,154 @@ void Addressee::computeCsum(const QString &dev) | |||
270 | setCsum( dev, QString::number (cs )); | 270 | setCsum( dev, QString::number (cs )); |
271 | } | 271 | } |
272 | 272 | ||
273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) | 273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) |
274 | { | 274 | { |
275 | 275 | ||
276 | detach(); | 276 | detach(); |
277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
285 | if ( !mData->birthday.isValid() ) | 285 | if ( !mData->birthday.isValid() ) |
286 | if ( ad.mData->birthday.isValid()) | 286 | if ( ad.mData->birthday.isValid()) |
287 | mData->birthday = ad.mData->birthday; | 287 | mData->birthday = ad.mData->birthday; |
288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
299 | QStringList t; | 299 | QStringList t; |
300 | QStringList tAD; | 300 | QStringList tAD; |
301 | uint iii; | 301 | uint iii; |
302 | if ( isSubSet ) { | 302 | |
303 | // ********** phone numbers | 303 | // ********** phone numbers |
304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); | 304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); |
305 | PhoneNumber::List::Iterator phoneItAD; | 305 | PhoneNumber::List::Iterator phoneItAD; |
306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | 306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { |
307 | bool found = false; | 307 | bool found = false; |
308 | PhoneNumber::List::Iterator it; | 308 | PhoneNumber::List::Iterator it; |
309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
310 | if ( ( *phoneItAD ).contains( (*it) ) ) { | 310 | if ( ( *phoneItAD ).contains( (*it) ) ) { |
311 | found = true; | 311 | found = true; |
312 | (*it).setType( ( *phoneItAD ).type() ); | 312 | (*it).setType( ( *phoneItAD ).type() ); |
313 | break; | 313 | break; |
314 | } | ||
315 | } | 314 | } |
316 | if ( ! found ) | ||
317 | mData->phoneNumbers.append( *phoneItAD ); | ||
318 | } | 315 | } |
316 | if ( isSubSet && ! found ) | ||
317 | mData->phoneNumbers.append( *phoneItAD ); | ||
318 | } | ||
319 | if ( isSubSet ) { | ||
319 | // ************* emails; | 320 | // ************* emails; |
320 | t = mData->emails; | 321 | t = mData->emails; |
321 | tAD = ad.mData->emails; | 322 | tAD = ad.mData->emails; |
322 | for ( iii = 0; iii < tAD.count(); ++iii) | 323 | for ( iii = 0; iii < tAD.count(); ++iii) |
323 | if ( !t.contains(tAD[iii] ) ) | 324 | if ( !t.contains(tAD[iii] ) ) |
324 | mData->emails.append( tAD[iii] ); | 325 | mData->emails.append( tAD[iii] ); |
325 | // ************* categories; | ||
326 | t = mData->categories; | ||
327 | tAD = ad.mData->categories; | ||
328 | for ( iii = 0; iii < tAD.count(); ++iii) | ||
329 | if ( !t.contains(tAD[iii] ) ) | ||
330 | mData->categories.append( tAD[iii] ); | ||
331 | |||
332 | |||
333 | } | 326 | } |
334 | 327 | ||
328 | // ************* categories; | ||
329 | t = mData->categories; | ||
330 | tAD = ad.mData->categories; | ||
331 | for ( iii = 0; iii < tAD.count(); ++iii) | ||
332 | if ( !t.contains(tAD[iii] ) ) | ||
333 | mData->categories.append( tAD[iii] ); | ||
335 | QStringList::ConstIterator it; | 334 | QStringList::ConstIterator it; |
336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 335 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
337 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 336 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
338 | bool found = false; | 337 | bool found = false; |
339 | QStringList::ConstIterator itL; | 338 | QStringList::ConstIterator itL; |
340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 339 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
341 | if ( (*itL).startsWith( qualifiedName ) ) { | 340 | if ( (*itL).startsWith( qualifiedName ) ) { |
342 | found = true; | 341 | found = true; |
343 | break; | 342 | break; |
344 | } | 343 | } |
345 | } | 344 | } |
346 | if ( ! found ) { | 345 | if ( ! found ) { |
347 | mData->custom.append( *it ); | 346 | mData->custom.append( *it ); |
348 | } | 347 | } |
349 | } | 348 | } |
350 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 349 | 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; | 350 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
352 | if ( !mData->sound.isIntern() ) { | 351 | if ( !mData->sound.isIntern() ) { |
353 | if ( mData->sound.url().isEmpty() ) { | 352 | if ( mData->sound.url().isEmpty() ) { |
354 | mData->sound = ad.mData->sound; | 353 | mData->sound = ad.mData->sound; |
355 | } | 354 | } |
356 | } | 355 | } |
357 | if ( !mData->agent.isIntern() ) { | 356 | if ( !mData->agent.isIntern() ) { |
358 | if ( mData->agent.url().isEmpty() ) { | 357 | if ( mData->agent.url().isEmpty() ) { |
359 | mData->agent = ad.mData->agent; | 358 | mData->agent = ad.mData->agent; |
360 | } | 359 | } |
361 | } | 360 | } |
362 | { | 361 | { |
363 | Key::List::Iterator itA; | 362 | Key::List::Iterator itA; |
364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 363 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
365 | bool found = false; | 364 | bool found = false; |
366 | Key::List::Iterator it; | 365 | Key::List::Iterator it; |
367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 366 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
368 | if ( (*it) == (*itA)) { | 367 | if ( (*it) == (*itA)) { |
369 | found = true; | 368 | found = true; |
370 | break; | 369 | break; |
371 | 370 | ||
372 | } | 371 | } |
373 | } | 372 | } |
374 | if ( ! found ) { | 373 | if ( ! found ) { |
375 | mData->keys.append( *itA ); | 374 | mData->keys.append( *itA ); |
376 | } | 375 | } |
377 | } | 376 | } |
378 | } | 377 | } |
379 | KABC::Address::List::Iterator addressIterA; | 378 | KABC::Address::List::Iterator addressIterA; |
380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 379 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
381 | bool found = false; | 380 | bool found = false; |
382 | KABC::Address::List::Iterator addressIter; | 381 | KABC::Address::List::Iterator addressIter; |
383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 382 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
384 | ++addressIter ) { | 383 | ++addressIter ) { |
385 | if ( (*addressIter) == (*addressIterA)) { | 384 | if ( (*addressIter) == (*addressIterA)) { |
386 | found = true; | 385 | found = true; |
387 | (*addressIter).setType( (*addressIterA).type() ); | 386 | (*addressIter).setType( (*addressIterA).type() ); |
388 | break; | 387 | break; |
389 | } | 388 | } |
390 | 389 | ||
391 | } | 390 | } |
392 | if ( ! found ) { | 391 | if ( isSubSet && ! found ) { |
393 | mData->addresses.append( *addressIterA ); | 392 | mData->addresses.append( *addressIterA ); |
394 | } | 393 | } |
395 | } | 394 | } |
396 | //qDebug("merge contact %s ", ad.uid().latin1()); | 395 | //qDebug("merge contact %s ", ad.uid().latin1()); |
397 | setUid( ad.uid() ); | 396 | setUid( ad.uid() ); |
398 | setRevision( ad.revision() ); | 397 | setRevision( ad.revision() ); |
399 | } | 398 | } |
400 | 399 | ||
401 | bool Addressee::removeVoice() | 400 | bool Addressee::removeVoice() |
402 | { | 401 | { |
403 | PhoneNumber::List phoneN = phoneNumbers(); | 402 | PhoneNumber::List phoneN = phoneNumbers(); |
404 | PhoneNumber::List::Iterator phoneIt; | 403 | PhoneNumber::List::Iterator phoneIt; |
405 | bool found = false; | 404 | bool found = false; |
406 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 405 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
407 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 406 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
408 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 407 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
409 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 408 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
410 | insertPhoneNumber( (*phoneIt) ); | 409 | insertPhoneNumber( (*phoneIt) ); |
411 | found = true; | 410 | found = true; |
412 | } | 411 | } |
413 | } | 412 | } |
414 | 413 | ||
415 | } | 414 | } |
416 | return found; | 415 | return found; |
417 | } | 416 | } |
418 | 417 | ||
419 | bool Addressee::containsAdr(const Addressee& ad ) | 418 | bool Addressee::containsAdr(const Addressee& ad ) |
420 | { | 419 | { |
421 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 420 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; |
422 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | 421 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; |
423 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | 422 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; |
424 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | 423 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; |
@@ -449,66 +448,101 @@ bool Addressee::containsAdr(const Addressee& ad ) | |||
449 | void Addressee::simplifyAddresses() | 448 | void Addressee::simplifyAddresses() |
450 | { | 449 | { |
451 | int max = 2; | 450 | int max = 2; |
452 | if ( mData->url.isValid() ) | 451 | if ( mData->url.isValid() ) |
453 | max = 1; | 452 | max = 1; |
454 | if ( mData->addresses.count() <= max ) return ; | 453 | if ( mData->addresses.count() <= max ) return ; |
455 | int count = 0; | 454 | int count = 0; |
456 | Address::List list; | 455 | Address::List list; |
457 | Address::List::Iterator it; | 456 | Address::List::Iterator it; |
458 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 457 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
459 | if ( count >= max ) | 458 | if ( count >= max ) |
460 | list.append( *it ); | 459 | list.append( *it ); |
461 | ++count; | 460 | ++count; |
462 | } | 461 | } |
463 | for( it = list.begin(); it != list.end(); ++it ) { | 462 | for( it = list.begin(); it != list.end(); ++it ) { |
464 | removeAddress( (*it) ); | 463 | removeAddress( (*it) ); |
465 | } | 464 | } |
466 | } | 465 | } |
467 | 466 | ||
468 | // removes all emails but the first | 467 | // removes all emails but the first |
469 | // needed by phone sync | 468 | // needed by phone sync |
470 | void Addressee::simplifyEmails() | 469 | void Addressee::simplifyEmails() |
471 | { | 470 | { |
472 | if ( mData->emails.count() == 0 ) return ; | 471 | if ( mData->emails.count() == 0 ) return ; |
473 | QString email = mData->emails.first(); | 472 | QString email = mData->emails.first(); |
474 | detach(); | 473 | detach(); |
475 | mData->emails.clear(); | 474 | mData->emails.clear(); |
476 | mData->emails.append( email ); | 475 | mData->emails.append( email ); |
477 | } | 476 | } |
478 | 477 | ||
479 | void Addressee::simplifyPhoneNumbers() | 478 | void Addressee::simplifyPhoneNumbers() |
480 | { | 479 | { |
480 | int max = 4; | ||
481 | int inList = mData->phoneNumbers.count(); | ||
481 | KABC::PhoneNumber::List removeNumbers; | 482 | KABC::PhoneNumber::List removeNumbers; |
482 | KABC::PhoneNumber::List::Iterator phoneIter; | 483 | KABC::PhoneNumber::List::Iterator phoneIter; |
484 | if ( inList > max ) { | ||
485 | // delete non-preferred numbers | ||
486 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
487 | ++phoneIter ) { | ||
488 | if ( inList > max ) { | ||
489 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | ||
490 | removeNumbers.append( ( *phoneIter ) ); | ||
491 | --inList; | ||
492 | } | ||
493 | } else | ||
494 | break; | ||
495 | } | ||
496 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | ||
497 | ++phoneIter ) { | ||
498 | removePhoneNumber(( *phoneIter )); | ||
499 | } | ||
500 | // delete preferred numbers | ||
501 | if ( inList > max ) { | ||
502 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
503 | ++phoneIter ) { | ||
504 | if ( inList > max ) { | ||
505 | removeNumbers.append( ( *phoneIter ) ); | ||
506 | --inList; | ||
507 | } else | ||
508 | break; | ||
509 | } | ||
510 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | ||
511 | ++phoneIter ) { | ||
512 | removePhoneNumber(( *phoneIter )); | ||
513 | } | ||
514 | } | ||
515 | } | ||
516 | // remove non-numeric characters | ||
483 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 517 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
484 | ++phoneIter ) { | 518 | ++phoneIter ) { |
485 | if ( ! ( *phoneIter ).simplifyNumber() ) | 519 | if ( ! ( *phoneIter ).simplifyNumber() ) |
486 | removeNumbers.append( ( *phoneIter ) ); | 520 | removeNumbers.append( ( *phoneIter ) ); |
487 | } | 521 | } |
488 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 522 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
489 | ++phoneIter ) { | 523 | ++phoneIter ) { |
490 | removePhoneNumber(( *phoneIter )); | 524 | removePhoneNumber(( *phoneIter )); |
491 | } | 525 | } |
492 | } | 526 | } |
493 | void Addressee::simplifyPhoneNumberTypes() | 527 | void Addressee::simplifyPhoneNumberTypes() |
494 | { | 528 | { |
495 | KABC::PhoneNumber::List::Iterator phoneIter; | 529 | KABC::PhoneNumber::List::Iterator phoneIter; |
496 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 530 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
497 | ++phoneIter ) | 531 | ++phoneIter ) |
498 | ( *phoneIter ).simplifyType(); | 532 | ( *phoneIter ).simplifyType(); |
499 | } | 533 | } |
500 | void Addressee::removeID(const QString &prof) | 534 | void Addressee::removeID(const QString &prof) |
501 | { | 535 | { |
502 | detach(); | 536 | detach(); |
503 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 537 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
504 | 538 | ||
505 | } | 539 | } |
506 | void Addressee::setID( const QString & prof , const QString & id ) | 540 | void Addressee::setID( const QString & prof , const QString & id ) |
507 | { | 541 | { |
508 | detach(); | 542 | detach(); |
509 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 543 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
510 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 544 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
511 | } | 545 | } |
512 | void Addressee::setTempSyncStat( int id ) | 546 | void Addressee::setTempSyncStat( int id ) |
513 | { | 547 | { |
514 | if ( mData->mTempSyncStat == id ) return; | 548 | if ( mData->mTempSyncStat == id ) return; |
diff --git a/kabc/addressee.h b/kabc/addressee.h index e7900c6..2c81c1a 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -87,65 +87,65 @@ class Addressee | |||
87 | 87 | ||
88 | /** | 88 | /** |
89 | Construct an empty address book entry. | 89 | Construct an empty address book entry. |
90 | */ | 90 | */ |
91 | Addressee(); | 91 | Addressee(); |
92 | ~Addressee(); | 92 | ~Addressee(); |
93 | 93 | ||
94 | Addressee( const Addressee & ); | 94 | Addressee( const Addressee & ); |
95 | Addressee &operator=( const Addressee & ); | 95 | Addressee &operator=( const Addressee & ); |
96 | 96 | ||
97 | bool operator==( const Addressee & ) const; | 97 | bool operator==( const Addressee & ) const; |
98 | bool operator!=( const Addressee & ) const; | 98 | bool operator!=( const Addressee & ) const; |
99 | // sync stuff | 99 | // sync stuff |
100 | void setTempSyncStat(int id); | 100 | void setTempSyncStat(int id); |
101 | int tempSyncStat() const; | 101 | int tempSyncStat() const; |
102 | void setIDStr( const QString & ); | 102 | void setIDStr( const QString & ); |
103 | QString IDStr() const; | 103 | QString IDStr() const; |
104 | void setID( const QString &, const QString & ); | 104 | void setID( const QString &, const QString & ); |
105 | QString getID( const QString & ); | 105 | QString getID( const QString & ); |
106 | void setCsum( const QString &, const QString & ); | 106 | void setCsum( const QString &, const QString & ); |
107 | QString getCsum( const QString & ); | 107 | QString getCsum( const QString & ); |
108 | void removeID(const QString &); | 108 | void removeID(const QString &); |
109 | void computeCsum(const QString &dev); | 109 | void computeCsum(const QString &dev); |
110 | ulong getCsum4List( const QStringList & attList); | 110 | ulong getCsum4List( const QStringList & attList); |
111 | /** | 111 | /** |
112 | Return, if the address book entry is empty. | 112 | Return, if the address book entry is empty. |
113 | */ | 113 | */ |
114 | bool isEmpty() const; | 114 | bool isEmpty() const; |
115 | void setExternalUID( const QString &id ); | 115 | void setExternalUID( const QString &id ); |
116 | QString externalUID() const; | 116 | QString externalUID() const; |
117 | void setOriginalExternalUID( const QString &id ); | 117 | void setOriginalExternalUID( const QString &id ); |
118 | QString originalExternalUID() const; | 118 | QString originalExternalUID() const; |
119 | void mergeContact( const Addressee& ad, bool isSubSet = false ); | 119 | void mergeContact( const Addressee& ad, bool isSubSet ); |
120 | void simplifyEmails(); | 120 | void simplifyEmails(); |
121 | void simplifyAddresses(); | 121 | void simplifyAddresses(); |
122 | void simplifyPhoneNumbers(); | 122 | void simplifyPhoneNumbers(); |
123 | void simplifyPhoneNumberTypes(); | 123 | void simplifyPhoneNumberTypes(); |
124 | bool removeVoice(); | 124 | bool removeVoice(); |
125 | bool containsAdr(const Addressee& addr ); | 125 | bool containsAdr(const Addressee& addr ); |
126 | 126 | ||
127 | /** | 127 | /** |
128 | Set unique identifier. | 128 | Set unique identifier. |
129 | */ | 129 | */ |
130 | void setUid( const QString &uid ); | 130 | void setUid( const QString &uid ); |
131 | /** | 131 | /** |
132 | Return unique identifier. | 132 | Return unique identifier. |
133 | */ | 133 | */ |
134 | QString uid() const; | 134 | QString uid() const; |
135 | /** | 135 | /** |
136 | Return translated label for uid field. | 136 | Return translated label for uid field. |
137 | */ | 137 | */ |
138 | static QString uidLabel(); | 138 | static QString uidLabel(); |
139 | 139 | ||
140 | /** | 140 | /** |
141 | Set name. | 141 | Set name. |
142 | */ | 142 | */ |
143 | void setName( const QString &name ); | 143 | void setName( const QString &name ); |
144 | /** | 144 | /** |
145 | Return name. | 145 | Return name. |
146 | */ | 146 | */ |
147 | QString name() const; | 147 | QString name() const; |
148 | /** | 148 | /** |
149 | Return translated label for name field. | 149 | Return translated label for name field. |
150 | */ | 150 | */ |
151 | static QString nameLabel(); | 151 | static QString nameLabel(); |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 205dbc8..ea34be2 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2703,162 +2703,162 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2703 | 2703 | ||
2704 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2704 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2705 | remote->insertAddressee( addresseeRSync, false ); | 2705 | remote->insertAddressee( addresseeRSync, false ); |
2706 | local->insertAddressee( addresseeLSync, false ); | 2706 | local->insertAddressee( addresseeLSync, false ); |
2707 | QString mes; | 2707 | QString mes; |
2708 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | 2708 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); |
2709 | if ( syncManager->mShowSyncSummary ) { | 2709 | if ( syncManager->mShowSyncSummary ) { |
2710 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2710 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2711 | } | 2711 | } |
2712 | qDebug( mes ); | 2712 | qDebug( mes ); |
2713 | return syncOK; | 2713 | return syncOK; |
2714 | } | 2714 | } |
2715 | 2715 | ||
2716 | 2716 | ||
2717 | //this is a overwritten callbackmethods from the syncinterface | 2717 | //this is a overwritten callbackmethods from the syncinterface |
2718 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2718 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2719 | { | 2719 | { |
2720 | 2720 | ||
2721 | //pending prepare addresseeview for output | 2721 | //pending prepare addresseeview for output |
2722 | //pending detect, if remote file has REV field. if not switch to external sync | 2722 | //pending detect, if remote file has REV field. if not switch to external sync |
2723 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2723 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2724 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2724 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2725 | 2725 | ||
2726 | AddressBook abLocal(filename,"syncContact"); | 2726 | AddressBook abLocal(filename,"syncContact"); |
2727 | bool syncOK = false; | 2727 | bool syncOK = false; |
2728 | if ( abLocal.load() ) { | 2728 | if ( abLocal.load() ) { |
2729 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2729 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2730 | bool external = false; | 2730 | bool external = false; |
2731 | bool isXML = false; | 2731 | bool isXML = false; |
2732 | if ( filename.right(4) == ".xml") { | 2732 | if ( filename.right(4) == ".xml") { |
2733 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2733 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2734 | isXML = true; | 2734 | isXML = true; |
2735 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2735 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2736 | } else { | 2736 | } else { |
2737 | external = !manager->mIsKapiFile; | 2737 | external = !manager->mIsKapiFile; |
2738 | if ( external ) { | 2738 | if ( external ) { |
2739 | qDebug("Setting vcf mode to external "); | 2739 | qDebug("Setting vcf mode to external "); |
2740 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2740 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2741 | AddressBook::Iterator it; | 2741 | AddressBook::Iterator it; |
2742 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2742 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2743 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2743 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2744 | (*it).computeCsum( mCurrentSyncDevice ); | 2744 | (*it).computeCsum( mCurrentSyncDevice ); |
2745 | } | 2745 | } |
2746 | } | 2746 | } |
2747 | } | 2747 | } |
2748 | //AddressBook::Iterator it; | 2748 | //AddressBook::Iterator it; |
2749 | //QStringList vcards; | 2749 | //QStringList vcards; |
2750 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2750 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2751 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2751 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2752 | //} | 2752 | //} |
2753 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2753 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2754 | if ( syncOK ) { | 2754 | if ( syncOK ) { |
2755 | if ( syncManager->mWriteBackFile ) | 2755 | if ( syncManager->mWriteBackFile ) |
2756 | { | 2756 | { |
2757 | if ( external ) | 2757 | if ( external ) |
2758 | abLocal.removeSyncAddressees( !isXML); | 2758 | abLocal.removeSyncAddressees( !isXML); |
2759 | qDebug("Saving remote AB "); | 2759 | qDebug("Saving remote AB "); |
2760 | if ( ! abLocal.saveAB()) | 2760 | if ( ! abLocal.saveAB()) |
2761 | qDebug("Error writing back AB to file "); | 2761 | qDebug("Error writing back AB to file "); |
2762 | if ( isXML ) { | 2762 | if ( isXML ) { |
2763 | // afterwrite processing | 2763 | // afterwrite processing |
2764 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2764 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2765 | } | 2765 | } |
2766 | } | 2766 | } |
2767 | } | 2767 | } |
2768 | setModified(); | 2768 | setModified(); |
2769 | 2769 | ||
2770 | } | 2770 | } |
2771 | if ( syncOK ) | 2771 | if ( syncOK ) |
2772 | mViewManager->refreshView(); | 2772 | mViewManager->refreshView(); |
2773 | return syncOK; | 2773 | return syncOK; |
2774 | 2774 | ||
2775 | } | 2775 | } |
2776 | 2776 | ||
2777 | 2777 | ||
2778 | //this is a overwritten callbackmethods from the syncinterface | 2778 | //this is a overwritten callbackmethods from the syncinterface |
2779 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2779 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2780 | { | 2780 | { |
2781 | if ( resource == "phone" ) | 2781 | if ( resource == "phone" ) |
2782 | return syncPhone(); | 2782 | return syncPhone(); |
2783 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2783 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2784 | 2784 | ||
2785 | AddressBook abLocal( resource,"syncContact"); | 2785 | AddressBook abLocal( resource,"syncContact"); |
2786 | bool syncOK = false; | 2786 | bool syncOK = false; |
2787 | if ( abLocal.load() ) { | 2787 | if ( abLocal.load() ) { |
2788 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2788 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2789 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2789 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2790 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2790 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
2791 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2791 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2792 | if ( syncOK ) { | 2792 | if ( syncOK ) { |
2793 | if ( syncManager->mWriteBackFile ) { | 2793 | if ( syncManager->mWriteBackFile ) { |
2794 | abLocal.removeSyncAddressees( false ); | 2794 | abLocal.removeSyncAddressees( false ); |
2795 | abLocal.saveAB(); | 2795 | abLocal.saveAB(); |
2796 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2796 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2797 | } | 2797 | } |
2798 | } | 2798 | } |
2799 | setModified(); | 2799 | setModified(); |
2800 | } | 2800 | } |
2801 | if ( syncOK ) | 2801 | if ( syncOK ) |
2802 | mViewManager->refreshView(); | 2802 | mViewManager->refreshView(); |
2803 | return syncOK; | 2803 | return syncOK; |
2804 | 2804 | ||
2805 | } | 2805 | } |
2806 | void KABCore::message( QString m ) | 2806 | void KABCore::message( QString m ) |
2807 | { | 2807 | { |
2808 | 2808 | ||
2809 | topLevelWidget()->setCaption( m ); | 2809 | topLevelWidget()->setCaption( m ); |
2810 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); | 2810 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); |
2811 | } | 2811 | } |
2812 | bool KABCore::syncPhone() | 2812 | bool KABCore::syncPhone() |
2813 | { | 2813 | { |
2814 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2814 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2815 | QString fileName; | 2815 | QString fileName; |
2816 | #ifdef _WIN32_ | 2816 | #ifdef _WIN32_ |
2817 | fileName = locateLocal("tmp", "phonefile.vcf"); | 2817 | fileName = locateLocal("tmp", "phonefile.vcf"); |
2818 | #else | 2818 | #else |
2819 | fileName = "/tmp/phonefile.vcf"; | 2819 | fileName = "/tmp/phonefile.vcf"; |
2820 | #endif | 2820 | #endif |
2821 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 2821 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
2822 | message(i18n("Phone access failed!")); | 2822 | message(i18n("Phone access failed!")); |
2823 | return false; | 2823 | return false; |
2824 | } | 2824 | } |
2825 | AddressBook abLocal( fileName,"syncContact"); | 2825 | AddressBook abLocal( fileName,"syncContact"); |
2826 | bool syncOK = false; | 2826 | bool syncOK = false; |
2827 | { | 2827 | { |
2828 | abLocal.importFromFile( fileName ); | 2828 | abLocal.importFromFile( fileName ); |
2829 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2829 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2830 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2830 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2831 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 2831 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
2832 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2832 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2833 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2833 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2834 | if ( syncOK ) { | 2834 | if ( syncOK ) { |
2835 | if ( syncManager->mWriteBackFile ) { | 2835 | if ( syncManager->mWriteBackFile ) { |
2836 | abLocal.removeSyncAddressees( true ); | 2836 | abLocal.removeSyncAddressees( true ); |
2837 | abLocal.saveABphone( fileName ); | 2837 | abLocal.saveABphone( fileName ); |
2838 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 2838 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
2839 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 2839 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
2840 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2840 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2841 | } | 2841 | } |
2842 | } | 2842 | } |
2843 | setModified(); | 2843 | setModified(); |
2844 | } | 2844 | } |
2845 | if ( syncOK ) | 2845 | if ( syncOK ) |
2846 | mViewManager->refreshView(); | 2846 | mViewManager->refreshView(); |
2847 | return syncOK; | 2847 | return syncOK; |
2848 | } | 2848 | } |
2849 | void KABCore::getFile( bool success ) | 2849 | void KABCore::getFile( bool success ) |
2850 | { | 2850 | { |
2851 | if ( ! success ) { | 2851 | if ( ! success ) { |
2852 | message( i18n("Error receiving file. Nothing changed!") ); | 2852 | message( i18n("Error receiving file. Nothing changed!") ); |
2853 | return; | 2853 | return; |
2854 | } | 2854 | } |
2855 | mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2855 | mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2856 | message( i18n("Pi-Sync successful!") ); | 2856 | message( i18n("Pi-Sync successful!") ); |
2857 | mViewManager->refreshView(); | 2857 | mViewManager->refreshView(); |
2858 | } | 2858 | } |
2859 | void KABCore::syncFileRequest() | 2859 | void KABCore::syncFileRequest() |
2860 | { | 2860 | { |
2861 | mAddressBook->export2File( sentSyncFile() ); | 2861 | mAddressBook->export2File( sentSyncFile() ); |
2862 | } | 2862 | } |
2863 | QString KABCore::sentSyncFile() | 2863 | QString KABCore::sentSyncFile() |
2864 | { | 2864 | { |