summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp19
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kaddressbook/kabcore.cpp16
4 files changed, 26 insertions, 13 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 ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index f124dc9..75f8b51 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -246,104 +246,104 @@ class AddressBook : public QObject
246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
247 void emitAddressBookChanged() { emit addressBookChanged( this ); } 247 void emitAddressBookChanged() { emit addressBookChanged( this ); }
248 248
249 /** 249 /**
250 Return list of all Fields known to the address book which are associated 250 Return list of all Fields known to the address book which are associated
251 with the given field category. 251 with the given field category.
252 */ 252 */
253 Field::List fields( int category = Field::All ); 253 Field::List fields( int category = Field::All );
254 254
255 /** 255 /**
256 Add custom field to address book. 256 Add custom field to address book.
257 257
258 @param label User visible label of the field. 258 @param label User visible label of the field.
259 @param category Ored list of field categories. 259 @param category Ored list of field categories.
260 @param key Identifier used as key for reading and writing the field. 260 @param key Identifier used as key for reading and writing the field.
261 @param app String used as application key for reading and writing 261 @param app String used as application key for reading and writing
262 the field. 262 the field.
263 */ 263 */
264 bool addCustomField( const QString &label, int category = Field::All, 264 bool addCustomField( const QString &label, int category = Field::All,
265 const QString &key = QString::null, 265 const QString &key = QString::null,
266 const QString &app = QString::null ); 266 const QString &app = QString::null );
267 267
268 268
269 /** 269 /**
270 Add address book resource. 270 Add address book resource.
271 */ 271 */
272 bool addResource( Resource * ); 272 bool addResource( Resource * );
273 273
274 /** 274 /**
275 Remove address book resource. 275 Remove address book resource.
276 */ 276 */
277 bool removeResource( Resource * ); 277 bool removeResource( Resource * );
278 278
279 /** 279 /**
280 Return pointer list of all resources. 280 Return pointer list of all resources.
281 */ 281 */
282 QPtrList<Resource> resources(); 282 QPtrList<Resource> resources();
283 283
284 /** 284 /**
285 Set the @p ErrorHandler, that is used by @ref error() to 285 Set the @p ErrorHandler, that is used by @ref error() to
286 provide gui-independend error messages. 286 provide gui-independend error messages.
287 */ 287 */
288 void setErrorHandler( ErrorHandler * ); 288 void setErrorHandler( ErrorHandler * );
289 289
290 /** 290 /**
291 Shows gui independend error messages. 291 Shows gui independend error messages.
292 */ 292 */
293 void error( const QString& ); 293 void error( const QString& );
294 294
295 /** 295 /**
296 Query all resources to clean up their lock files 296 Query all resources to clean up their lock files
297 */ 297 */
298 void cleanUp(); 298 void cleanUp();
299 299
300 // sync stuff 300 // sync stuff
301 //Addressee::List getExternLastSyncAddressees(); 301 //Addressee::List getExternLastSyncAddressees();
302 void resetTempSyncStat(); 302 void resetTempSyncStat();
303 QStringList uidList(); 303 QStringList uidList();
304 void removeSyncAddressees( bool removeDeleted = false ); 304 void removeSyncAddressees( bool removeDeleted = false );
305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); 305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
306 Addressee findByExternUid( const QString& uid , const QString& profile ); 306 Addressee findByExternUid( const QString& uid , const QString& profile );
307 bool containsExternalUid( const QString& uid ); 307 bool containsExternalUid( const QString& uid );
308 308
309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); 309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
310 void postExternSync( AddressBook* aBook, const QString& csd ); 310 void postExternSync( AddressBook* aBook, const QString& csd , bool setID );
311 signals: 311 signals:
312 /** 312 /**
313 Emitted, when the address book has changed on disk. 313 Emitted, when the address book has changed on disk.
314 */ 314 */
315 void addressBookChanged( AddressBook * ); 315 void addressBookChanged( AddressBook * );
316 316
317 /** 317 /**
318 Emitted, when the address book has been locked for writing. 318 Emitted, when the address book has been locked for writing.
319 */ 319 */
320 void addressBookLocked( AddressBook * ); 320 void addressBookLocked( AddressBook * );
321 321
322 /** 322 /**
323 Emitted, when the address book has been unlocked. 323 Emitted, when the address book has been unlocked.
324 */ 324 */
325 void addressBookUnlocked( AddressBook * ); 325 void addressBookUnlocked( AddressBook * );
326 326
327 protected: 327 protected:
328 void deleteRemovedAddressees(); 328 void deleteRemovedAddressees();
329 void setStandardResource( Resource * ); 329 void setStandardResource( Resource * );
330 Resource *standardResource(); 330 Resource *standardResource();
331 KRES::Manager<Resource> *resourceManager(); 331 KRES::Manager<Resource> *resourceManager();
332 332
333 void init(const QString &config, const QString &family); 333 void init(const QString &config, const QString &family);
334 334
335 private: 335 private:
336//US QPtrList<Resource> mDummy; // Remove in KDE 4 336//US QPtrList<Resource> mDummy; // Remove in KDE 4
337 337
338 338
339 struct AddressBookData; 339 struct AddressBookData;
340 AddressBookData *d; 340 AddressBookData *d;
341 bool blockLSEchange; 341 bool blockLSEchange;
342}; 342};
343 343
344QDataStream &operator<<( QDataStream &, const AddressBook & ); 344QDataStream &operator<<( QDataStream &, const AddressBook & );
345QDataStream &operator>>( QDataStream &, AddressBook & ); 345QDataStream &operator>>( QDataStream &, AddressBook & );
346 346
347} 347}
348 348
349#endif 349#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index a660a9d..d5a110a 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -205,129 +205,129 @@ ulong Addressee::getCsum4List( const QStringList & attList)
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 if ( mData->url.isValid() ) 235 if ( mData->url.isValid() )
236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
237 KABC::PhoneNumber::List phoneNumbers; 237 KABC::PhoneNumber::List phoneNumbers;
238 KABC::PhoneNumber::List::Iterator phoneIter; 238 KABC::PhoneNumber::List::Iterator phoneIter;
239 239
240 QStringList t; 240 QStringList t;
241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
242 ++phoneIter ) 242 ++phoneIter )
243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
244 t.sort(); 244 t.sort();
245 uint iii; 245 uint iii;
246 for ( iii = 0; iii < t.count(); ++iii) 246 for ( iii = 0; iii < t.count(); ++iii)
247 l.append( t[iii] ); 247 l.append( t[iii] );
248 t = mData->emails; 248 t = mData->emails;
249 t.sort(); 249 t.sort();
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->categories; 252 t = mData->categories;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->custom; 256 t = mData->custom;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 l.append( t[iii] ); 259 l.append( t[iii] );
260 KABC::Address::List::Iterator addressIter; 260 KABC::Address::List::Iterator addressIter;
261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
262 ++addressIter ) { 262 ++addressIter ) {
263 t = (*addressIter).asList(); 263 t = (*addressIter).asList();
264 t.sort(); 264 t.sort();
265 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
266 l.append( t[iii] ); 266 l.append( t[iii] );
267 } 267 }
268 uint cs = getCsum4List(l); 268 uint cs = getCsum4List(l);
269 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 269 //qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
270 setCsum( dev, QString::number (cs )); 270 setCsum( dev, QString::number (cs ));
271} 271}
272 272
273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 273void 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 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 (*it).setNumber( ( *phoneItAD ).number() ); 313 (*it).setNumber( ( *phoneItAD ).number() );
314 break; 314 break;
315 } 315 }
316 } 316 }
317 if ( isSubSet && ! found ) 317 if ( isSubSet && ! found )
318 mData->phoneNumbers.append( *phoneItAD ); 318 mData->phoneNumbers.append( *phoneItAD );
319 } 319 }
320 if ( isSubSet ) { 320 if ( isSubSet ) {
321 // ************* emails; 321 // ************* emails;
322 t = mData->emails; 322 t = mData->emails;
323 tAD = ad.mData->emails; 323 tAD = ad.mData->emails;
324 for ( iii = 0; iii < tAD.count(); ++iii) 324 for ( iii = 0; iii < tAD.count(); ++iii)
325 if ( !t.contains(tAD[iii] ) ) 325 if ( !t.contains(tAD[iii] ) )
326 mData->emails.append( tAD[iii] ); 326 mData->emails.append( tAD[iii] );
327 } 327 }
328 328
329 // ************* categories; 329 // ************* categories;
330 t = mData->categories; 330 t = mData->categories;
331 tAD = ad.mData->categories; 331 tAD = ad.mData->categories;
332 for ( iii = 0; iii < tAD.count(); ++iii) 332 for ( iii = 0; iii < tAD.count(); ++iii)
333 if ( !t.contains(tAD[iii] ) ) 333 if ( !t.contains(tAD[iii] ) )
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index ea87929..b0cb986 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2452,236 +2452,237 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
2452 return 2; 2452 return 2;
2453 return 2; 2453 return 2;
2454 break; 2454 break;
2455 case SYNC_PREF_NEWEST: 2455 case SYNC_PREF_NEWEST:
2456 if ( localMod > remoteMod ) 2456 if ( localMod > remoteMod )
2457 return 1; 2457 return 1;
2458 else 2458 else
2459 return 2; 2459 return 2;
2460 break; 2460 break;
2461 case SYNC_PREF_ASK: 2461 case SYNC_PREF_ASK:
2462 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2462 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2463 if ( lastSync > remoteMod ) 2463 if ( lastSync > remoteMod )
2464 return 1; 2464 return 1;
2465 if ( lastSync > localMod ) 2465 if ( lastSync > localMod )
2466 return 2; 2466 return 2;
2467 localIsNew = localMod >= remoteMod; 2467 localIsNew = localMod >= remoteMod;
2468 //qDebug("conflict! ************************************** "); 2468 //qDebug("conflict! ************************************** ");
2469 { 2469 {
2470 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2470 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2471 result = acd.executeD(localIsNew); 2471 result = acd.executeD(localIsNew);
2472 return result; 2472 return result;
2473 } 2473 }
2474 break; 2474 break;
2475 case SYNC_PREF_FORCE_LOCAL: 2475 case SYNC_PREF_FORCE_LOCAL:
2476 return 1; 2476 return 1;
2477 break; 2477 break;
2478 case SYNC_PREF_FORCE_REMOTE: 2478 case SYNC_PREF_FORCE_REMOTE:
2479 return 2; 2479 return 2;
2480 break; 2480 break;
2481 2481
2482 default: 2482 default:
2483 // SYNC_PREF_TAKE_BOTH not implemented 2483 // SYNC_PREF_TAKE_BOTH not implemented
2484 break; 2484 break;
2485 } 2485 }
2486 return 0; 2486 return 0;
2487} 2487}
2488 2488
2489 2489
2490bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2490bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2491{ 2491{
2492 bool syncOK = true; 2492 bool syncOK = true;
2493 int addedAddressee = 0; 2493 int addedAddressee = 0;
2494 int addedAddresseeR = 0; 2494 int addedAddresseeR = 0;
2495 int deletedAddresseeR = 0; 2495 int deletedAddresseeR = 0;
2496 int deletedAddresseeL = 0; 2496 int deletedAddresseeL = 0;
2497 int changedLocal = 0; 2497 int changedLocal = 0;
2498 int changedRemote = 0; 2498 int changedRemote = 0;
2499 2499
2500 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2500 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2501 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2501 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2502 2502
2503 //QPtrList<Addressee> el = local->rawAddressees(); 2503 //QPtrList<Addressee> el = local->rawAddressees();
2504 Addressee addresseeR; 2504 Addressee addresseeR;
2505 QString uid; 2505 QString uid;
2506 int take; 2506 int take;
2507 Addressee addresseeL; 2507 Addressee addresseeL;
2508 Addressee addresseeRSync; 2508 Addressee addresseeRSync;
2509 Addressee addresseeLSync; 2509 Addressee addresseeLSync;
2510 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2510 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2511 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2511 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2512 bool fullDateRange = false; 2512 bool fullDateRange = false;
2513 local->resetTempSyncStat(); 2513 local->resetTempSyncStat();
2514 mLastAddressbookSync = QDateTime::currentDateTime(); 2514 mLastAddressbookSync = QDateTime::currentDateTime();
2515 if ( syncManager->syncWithDesktop() ) { 2515 if ( syncManager->syncWithDesktop() ) {
2516 remote->removeSyncInfo( QString());//remove all info 2516 // remote->removeSyncInfo( QString());//remove all info
2517 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2517 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2518 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2518 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2519 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2519 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2520 } else { 2520 } else {
2521 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime "); 2521 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
2522 } 2522 }
2523 } 2523 }
2524 QDateTime modifiedCalendar = mLastAddressbookSync; 2524 QDateTime modifiedCalendar = mLastAddressbookSync;
2525 addresseeLSync = getLastSyncAddressee(); 2525 addresseeLSync = getLastSyncAddressee();
2526 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2526 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2527 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2527 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2528 if ( !addresseeR.isEmpty() ) { 2528 if ( !addresseeR.isEmpty() ) {
2529 addresseeRSync = addresseeR; 2529 addresseeRSync = addresseeR;
2530 remote->removeAddressee(addresseeR ); 2530 remote->removeAddressee(addresseeR );
2531 2531
2532 } else { 2532 } else {
2533 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2533 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2534 addresseeRSync = addresseeLSync ; 2534 addresseeRSync = addresseeLSync ;
2535 } else { 2535 } else {
2536 qDebug("FULLDATE 1"); 2536 qDebug("FULLDATE 1");
2537 fullDateRange = true; 2537 fullDateRange = true;
2538 Addressee newAdd; 2538 Addressee newAdd;
2539 addresseeRSync = newAdd; 2539 addresseeRSync = newAdd;
2540 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2540 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2541 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2541 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2542 addresseeRSync.setRevision( mLastAddressbookSync ); 2542 addresseeRSync.setRevision( mLastAddressbookSync );
2543 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2543 addresseeRSync.setCategories( i18n("SyncAddressee") );
2544 } 2544 }
2545 } 2545 }
2546 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2546 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2547 qDebug("FULLDATE 2"); 2547 qDebug("FULLDATE 2");
2548 fullDateRange = true; 2548 fullDateRange = true;
2549 } 2549 }
2550 if ( ! fullDateRange ) { 2550 if ( ! fullDateRange ) {
2551 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2551 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2552 2552
2553 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2553 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2554 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2554 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2555 fullDateRange = true; 2555 fullDateRange = true;
2556 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2556 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2557 } 2557 }
2558 } 2558 }
2559 // fullDateRange = true; // debug only! 2559 // fullDateRange = true; // debug only!
2560 if ( fullDateRange ) 2560 if ( fullDateRange )
2561 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2561 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2562 else 2562 else
2563 mLastAddressbookSync = addresseeLSync.revision(); 2563 mLastAddressbookSync = addresseeLSync.revision();
2564 // for resyncing if own file has changed 2564 // for resyncing if own file has changed
2565 // PENDING fixme later when implemented 2565 // PENDING fixme later when implemented
2566#if 0 2566#if 0
2567 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2567 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2568 mLastAddressbookSync = loadedFileVersion; 2568 mLastAddressbookSync = loadedFileVersion;
2569 qDebug("setting mLastAddressbookSync "); 2569 qDebug("setting mLastAddressbookSync ");
2570 } 2570 }
2571#endif 2571#endif
2572 2572
2573 //qDebug("*************************** "); 2573 //qDebug("*************************** ");
2574 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2574 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2575 QStringList er = remote->uidList(); 2575 QStringList er = remote->uidList();
2576 Addressee inR ;//= er.first(); 2576 Addressee inR ;//= er.first();
2577 Addressee inL; 2577 Addressee inL;
2578 2578
2579 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2579 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2580 2580
2581 int modulo = (er.count()/10)+1; 2581 int modulo = (er.count()/10)+1;
2582 int incCounter = 0; 2582 int incCounter = 0;
2583 while ( incCounter < er.count()) { 2583 while ( incCounter < er.count()) {
2584 if (syncManager->isProgressBarCanceled()) 2584 if (syncManager->isProgressBarCanceled())
2585 return false; 2585 return false;
2586 if ( incCounter % modulo == 0 ) 2586 if ( incCounter % modulo == 0 )
2587 syncManager->showProgressBar(incCounter); 2587 syncManager->showProgressBar(incCounter);
2588 2588
2589 uid = er[ incCounter ]; 2589 uid = er[ incCounter ];
2590 bool skipIncidence = false; 2590 bool skipIncidence = false;
2591 if ( uid.left(19) == QString("last-syncAddressee-") ) 2591 if ( uid.left(19) == QString("last-syncAddressee-") )
2592 skipIncidence = true; 2592 skipIncidence = true;
2593 QString idS,OidS; 2593 QString idS,OidS;
2594 qApp->processEvents(); 2594 qApp->processEvents();
2595 if ( !skipIncidence ) { 2595 if ( !skipIncidence ) {
2596 inL = local->findByUid( uid ); 2596 inL = local->findByUid( uid );
2597 inR = remote->findByUid( uid ); 2597 inR = remote->findByUid( uid );
2598 //inL.setResource( 0 ); 2598 //inL.setResource( 0 );
2599 //inR.setResource( 0 ); 2599 //inR.setResource( 0 );
2600 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2600 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2601 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2601 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2602 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2602 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2603 //qDebug("take %d %s ", take, inL.summary().latin1()); 2603 //qDebug("take %d %s ", take, inL.summary().latin1());
2604 if ( take == 3 ) 2604 if ( take == 3 )
2605 return false; 2605 return false;
2606 if ( take == 1 ) {// take local 2606 if ( take == 1 ) {// take local
2607 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2607 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2608 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2608 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2609 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2609 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2610 local->insertAddressee( inL, false ); 2610 local->insertAddressee( inL, false );
2611 idS = inR.externalUID(); 2611 idS = inR.externalUID();
2612 OidS = inR.originalExternalUID(); 2612 OidS = inR.originalExternalUID();
2613 } 2613 }
2614 else 2614 else
2615 idS = inR.IDStr(); 2615 idS = inR.IDStr();
2616 remote->removeAddressee( inR ); 2616 remote->removeAddressee( inR );
2617 inR = inL; 2617 inR = inL;
2618 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2618 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2619 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2619 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2620 inR.setOriginalExternalUID( OidS ); 2620 inR.setOriginalExternalUID( OidS );
2621 inR.setExternalUID( idS ); 2621 inR.setExternalUID( idS );
2622 if ( syncManager->syncWithDesktop() ) 2622 if ( syncManager->syncWithDesktop() )
2623 inR.setIDStr( "changed" ); 2623 inR.setIDStr("changed" );
2624 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
2624 } else { 2625 } else {
2625 inR.setIDStr( idS ); 2626 inR.setIDStr( idS );
2626 } 2627 }
2627 inR.setResource( 0 ); 2628 inR.setResource( 0 );
2628 remote->insertAddressee( inR , false); 2629 remote->insertAddressee( inR , false);
2629 ++changedRemote; 2630 ++changedRemote;
2630 } else { // take == 2 take remote 2631 } else { // take == 2 take remote
2631 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2632 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2632 if ( inR.revision().date().year() < 2004 ) 2633 if ( inR.revision().date().year() < 2004 )
2633 inR.setRevision( modifiedCalendar ); 2634 inR.setRevision( modifiedCalendar );
2634 } 2635 }
2635 idS = inL.IDStr(); 2636 idS = inL.IDStr();
2636 local->removeAddressee( inL ); 2637 local->removeAddressee( inL );
2637 inL = inR; 2638 inL = inR;
2638 inL.setIDStr( idS ); 2639 inL.setIDStr( idS );
2639 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2640 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2640 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2641 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2641 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2642 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2642 } 2643 }
2643 inL.setResource( 0 ); 2644 inL.setResource( 0 );
2644 local->insertAddressee( inL , false ); 2645 local->insertAddressee( inL , false );
2645 ++changedLocal; 2646 ++changedLocal;
2646 } 2647 }
2647 } 2648 }
2648 } 2649 }
2649 } else { // no conflict 2650 } else { // no conflict
2650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2651 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2651 QString des = addresseeLSync.note(); 2652 QString des = addresseeLSync.note();
2652 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2653 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2653 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2654 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2654 remote->insertAddressee( inR, false ); 2655 remote->insertAddressee( inR, false );
2655 ++deletedAddresseeR; 2656 ++deletedAddresseeR;
2656 } else { 2657 } else {
2657 inR.setRevision( modifiedCalendar ); 2658 inR.setRevision( modifiedCalendar );
2658 remote->insertAddressee( inR, false ); 2659 remote->insertAddressee( inR, false );
2659 inL = inR; 2660 inL = inR;
2660 inL.setResource( 0 ); 2661 inL.setResource( 0 );
2661 local->insertAddressee( inL , false); 2662 local->insertAddressee( inL , false);
2662 ++addedAddressee; 2663 ++addedAddressee;
2663 } 2664 }
2664 } else { 2665 } else {
2665 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2666 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2666 inR.setRevision( modifiedCalendar ); 2667 inR.setRevision( modifiedCalendar );
2667 remote->insertAddressee( inR, false ); 2668 remote->insertAddressee( inR, false );
2668 inR.setResource( 0 ); 2669 inR.setResource( 0 );
2669 local->insertAddressee( inR, false ); 2670 local->insertAddressee( inR, false );
2670 ++addedAddressee; 2671 ++addedAddressee;
2671 } else { 2672 } else {
2672 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2673 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2673 remote->removeAddressee( inR ); 2674 remote->removeAddressee( inR );
2674 ++deletedAddresseeR; 2675 ++deletedAddresseeR;
2675 } 2676 }
2676 } 2677 }
2677 } 2678 }
2678 } 2679 }
2679 ++incCounter; 2680 ++incCounter;
2680 } 2681 }
2681 er.clear(); 2682 er.clear();
2682 QStringList el = local->uidList(); 2683 QStringList el = local->uidList();
2683 modulo = (el.count()/10)+1; 2684 modulo = (el.count()/10)+1;
2684 2685
2685 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2686 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2686 incCounter = 0; 2687 incCounter = 0;
2687 while ( incCounter < el.count()) { 2688 while ( incCounter < el.count()) {
@@ -2751,185 +2752,186 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2751 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2752 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2752 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2753 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2753 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2754 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2754 addresseeRSync.setNote( "" ) ; 2755 addresseeRSync.setNote( "" ) ;
2755 addresseeLSync.setNote( "" ); 2756 addresseeLSync.setNote( "" );
2756 2757
2757 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2758 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2758 remote->insertAddressee( addresseeRSync, false ); 2759 remote->insertAddressee( addresseeRSync, false );
2759 local->insertAddressee( addresseeLSync, false ); 2760 local->insertAddressee( addresseeLSync, false );
2760 QString mes; 2761 QString mes;
2761 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 ); 2762 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 );
2762 if ( syncManager->mShowSyncSummary ) { 2763 if ( syncManager->mShowSyncSummary ) {
2763 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2764 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2764 } 2765 }
2765 qDebug( mes ); 2766 qDebug( mes );
2766 return syncOK; 2767 return syncOK;
2767} 2768}
2768 2769
2769 2770
2770//this is a overwritten callbackmethods from the syncinterface 2771//this is a overwritten callbackmethods from the syncinterface
2771bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2772bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2772{ 2773{
2773 2774
2774 //pending prepare addresseeview for output 2775 //pending prepare addresseeview for output
2775 //pending detect, if remote file has REV field. if not switch to external sync 2776 //pending detect, if remote file has REV field. if not switch to external sync
2776 mGlobalSyncMode = SYNC_MODE_NORMAL; 2777 mGlobalSyncMode = SYNC_MODE_NORMAL;
2777 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2778 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2778 2779
2779 AddressBook abLocal(filename,"syncContact"); 2780 AddressBook abLocal(filename,"syncContact");
2780 bool syncOK = false; 2781 bool syncOK = false;
2781 if ( abLocal.load() ) { 2782 if ( abLocal.load() ) {
2782 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2783 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2783 bool external = false; 2784 bool external = false;
2784 bool isXML = false; 2785 bool isXML = false;
2785 if ( filename.right(4) == ".xml") { 2786 if ( filename.right(4) == ".xml") {
2786 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2787 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2787 isXML = true; 2788 isXML = true;
2788 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2789 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2789 } else { 2790 } else {
2790 external = !manager->mIsKapiFile; 2791 external = !manager->mIsKapiFile;
2791 if ( external ) { 2792 if ( external ) {
2792 qDebug("Setting vcf mode to external "); 2793 qDebug("Setting vcf mode to external ");
2793 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2794 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2794 AddressBook::Iterator it; 2795 AddressBook::Iterator it;
2795 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2796 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2796 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2797 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2797 (*it).computeCsum( mCurrentSyncDevice ); 2798 (*it).computeCsum( mCurrentSyncDevice );
2798 } 2799 }
2799 } 2800 }
2800 } 2801 }
2801 //AddressBook::Iterator it; 2802 //AddressBook::Iterator it;
2802 //QStringList vcards; 2803 //QStringList vcards;
2803 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2804 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2804 // qDebug("Name %s ", (*it).familyName().latin1()); 2805 // qDebug("Name %s ", (*it).familyName().latin1());
2805 //} 2806 //}
2806 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2807 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2807 if ( syncOK ) { 2808 if ( syncOK ) {
2808 if ( syncManager->mWriteBackFile ) 2809 if ( syncManager->mWriteBackFile )
2809 { 2810 {
2810 if ( external ) 2811 if ( external )
2811 abLocal.removeSyncAddressees( !isXML); 2812 abLocal.removeSyncAddressees( !isXML);
2812 qDebug("Saving remote AB "); 2813 qDebug("Saving remote AB ");
2813 if ( ! abLocal.saveAB()) 2814 if ( ! abLocal.saveAB())
2814 qDebug("Error writing back AB to file "); 2815 qDebug("Error writing back AB to file ");
2815 if ( isXML ) { 2816 if ( external ) {
2816 // afterwrite processing 2817 // afterwrite processing
2817 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2818 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
2818 } 2819 }
2819 } 2820 }
2820 } 2821 }
2821 setModified(); 2822 setModified();
2822 2823
2823 } 2824 }
2824 if ( syncOK ) 2825 if ( syncOK )
2825 mViewManager->refreshView(); 2826 mViewManager->refreshView();
2826 return syncOK; 2827 return syncOK;
2827 2828
2828} 2829}
2829void KABCore::removeSyncInfo( QString syncProfile) 2830void KABCore::removeSyncInfo( QString syncProfile)
2830{ 2831{
2831 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 2832 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2832 mAddressBook->removeSyncInfo( syncProfile ); 2833 mAddressBook->removeSyncInfo( syncProfile );
2834 setModified();
2833} 2835}
2834 2836
2835 2837
2836//this is a overwritten callbackmethods from the syncinterface 2838//this is a overwritten callbackmethods from the syncinterface
2837bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2839bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2838{ 2840{
2839 if ( resource == "phone" ) 2841 if ( resource == "phone" )
2840 return syncPhone(); 2842 return syncPhone();
2841 disableBR( true ); 2843 disableBR( true );
2842 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2844 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2843 2845
2844 AddressBook abLocal( resource,"syncContact"); 2846 AddressBook abLocal( resource,"syncContact");
2845 bool syncOK = false; 2847 bool syncOK = false;
2846 if ( abLocal.load() ) { 2848 if ( abLocal.load() ) {
2847 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2849 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2848 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2850 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2849 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2851 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2850 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2852 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2851 if ( syncOK ) { 2853 if ( syncOK ) {
2852 if ( syncManager->mWriteBackFile ) { 2854 if ( syncManager->mWriteBackFile ) {
2853 abLocal.removeSyncAddressees( false ); 2855 abLocal.removeSyncAddressees( false );
2854 abLocal.saveAB(); 2856 abLocal.saveAB();
2855 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2857 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2856 } 2858 }
2857 } 2859 }
2858 setModified(); 2860 setModified();
2859 } 2861 }
2860 if ( syncOK ) 2862 if ( syncOK )
2861 mViewManager->refreshView(); 2863 mViewManager->refreshView();
2862 disableBR( false ); 2864 disableBR( false );
2863 return syncOK; 2865 return syncOK;
2864 2866
2865} 2867}
2866void KABCore::message( QString m ) 2868void KABCore::message( QString m )
2867{ 2869{
2868 topLevelWidget()->setCaption( m ); 2870 topLevelWidget()->setCaption( m );
2869 mMessageTimer->start( 15000, true ); 2871 mMessageTimer->start( 15000, true );
2870} 2872}
2871bool KABCore::syncPhone() 2873bool KABCore::syncPhone()
2872{ 2874{
2873 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2875 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2874 QString fileName = getPhoneFile(); 2876 QString fileName = getPhoneFile();
2875 if ( !PhoneAccess::readFromPhone( fileName) ) { 2877 if ( !PhoneAccess::readFromPhone( fileName) ) {
2876 message(i18n("Phone access failed!")); 2878 message(i18n("Phone access failed!"));
2877 return false; 2879 return false;
2878 } 2880 }
2879 AddressBook abLocal( fileName,"syncContact"); 2881 AddressBook abLocal( fileName,"syncContact");
2880 bool syncOK = false; 2882 bool syncOK = false;
2881 { 2883 {
2882 abLocal.importFromFile( fileName ); 2884 abLocal.importFromFile( fileName );
2883 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2885 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2884 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2886 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2885 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2887 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2886 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2887 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2889 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2888 if ( syncOK ) { 2890 if ( syncOK ) {
2889 if ( syncManager->mWriteBackFile ) { 2891 if ( syncManager->mWriteBackFile ) {
2890 abLocal.removeSyncAddressees( true ); 2892 abLocal.removeSyncAddressees( true );
2891 abLocal.saveABphone( fileName ); 2893 abLocal.saveABphone( fileName );
2892 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2894 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2893 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2895 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2894 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2896 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2895 } 2897 }
2896 } 2898 }
2897 setModified(); 2899 setModified();
2898 } 2900 }
2899 if ( syncOK ) 2901 if ( syncOK )
2900 mViewManager->refreshView(); 2902 mViewManager->refreshView();
2901 return syncOK; 2903 return syncOK;
2902} 2904}
2903void KABCore::getFile( bool success ) 2905void KABCore::getFile( bool success )
2904{ 2906{
2905 if ( ! success ) { 2907 if ( ! success ) {
2906 message( i18n("Error receiving file. Nothing changed!") ); 2908 message( i18n("Error receiving file. Nothing changed!") );
2907 return; 2909 return;
2908 } 2910 }
2909 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2911 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2910 if ( count ) 2912 if ( count )
2911 setModified( true ); 2913 setModified( true );
2912 message( i18n("Pi-Sync successful!") ); 2914 message( i18n("Pi-Sync successful!") );
2913 mViewManager->refreshView(); 2915 mViewManager->refreshView();
2914} 2916}
2915void KABCore::syncFileRequest() 2917void KABCore::syncFileRequest()
2916{ 2918{
2917 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { 2919 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
2918 syncManager->slotSyncMenu( 999 ); 2920 syncManager->slotSyncMenu( 999 );
2919 } 2921 }
2920 mAddressBook->export2File( sentSyncFile() ); 2922 mAddressBook->export2File( sentSyncFile() );
2921} 2923}
2922QString KABCore::sentSyncFile() 2924QString KABCore::sentSyncFile()
2923{ 2925{
2924#ifdef DESKTOP_VERSION 2926#ifdef DESKTOP_VERSION
2925 return locateLocal( "tmp", "copysyncab.vcf" ); 2927 return locateLocal( "tmp", "copysyncab.vcf" );
2926#else 2928#else
2927 return QString( "/tmp/copysyncab.vcf" ); 2929 return QString( "/tmp/copysyncab.vcf" );
2928#endif 2930#endif
2929} 2931}
2930 2932
2931void KABCore::setCaptionBack() 2933void KABCore::setCaptionBack()
2932{ 2934{
2933 mMessageTimer->stop(); 2935 mMessageTimer->stop();
2934 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2936 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2935} 2937}