summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 22:33:39 (UTC)
committer zautrix <zautrix>2004-09-18 22:33:39 (UTC)
commitf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (patch) (unidiff)
treec1a9de8b305200a7cec885764a0afb4beb92dabb
parent28f894fd2a0dfbd5f09f9e530f359981efe0198c (diff)
downloadkdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.zip
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.gz
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.bz2
more AB sync
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/address.cpp13
-rw-r--r--kabc/address.h1
-rw-r--r--kabc/addressbook.cpp75
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp97
-rw-r--r--kabc/addressee.h2
-rw-r--r--kaddressbook/kabcore.cpp34
7 files changed, 214 insertions, 12 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index c820a6c..5ffe511 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -79,24 +79,37 @@ bool Address::isEmpty() const
79 mExtended.isEmpty() && 79 mExtended.isEmpty() &&
80 mStreet.isEmpty() && 80 mStreet.isEmpty() &&
81 mLocality.isEmpty() && 81 mLocality.isEmpty() &&
82 mRegion.isEmpty() && 82 mRegion.isEmpty() &&
83 mPostalCode.isEmpty() && 83 mPostalCode.isEmpty() &&
84 mCountry.isEmpty() && 84 mCountry.isEmpty() &&
85 mLabel.isEmpty() ) { 85 mLabel.isEmpty() ) {
86 return true; 86 return true;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91QStringList Address::asList()
92{
93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result;
103}
91void Address::clear() 104void Address::clear()
92{ 105{
93 *this = Address(); 106 *this = Address();
94} 107}
95 108
96void Address::setId( const QString &id ) 109void Address::setId( const QString &id )
97{ 110{
98 mEmpty = false; 111 mEmpty = false;
99 112
100 mId = id; 113 mId = id;
101} 114}
102 115
diff --git a/kabc/address.h b/kabc/address.h
index ad132a7..6b53c7e 100644
--- a/kabc/address.h
+++ b/kabc/address.h
@@ -98,24 +98,25 @@ class Address
98 bool operator==( const Address & ) const; 98 bool operator==( const Address & ) const;
99 bool operator!=( const Address & ) const; 99 bool operator!=( const Address & ) const;
100 100
101 /** 101 /**
102 Returns true, if the address is empty. 102 Returns true, if the address is empty.
103 */ 103 */
104 bool isEmpty() const; 104 bool isEmpty() const;
105 105
106 /** 106 /**
107 Clears all entries of the address. 107 Clears all entries of the address.
108 */ 108 */
109 void clear(); 109 void clear();
110 QStringList asList();
110 111
111 /** 112 /**
112 Sets the unique id. 113 Sets the unique id.
113 */ 114 */
114 void setId( const QString & ); 115 void setId( const QString & );
115 116
116 /* 117 /*
117 Returns the unique id. 118 Returns the unique id.
118 */ 119 */
119 QString id() const; 120 QString id() const;
120 121
121 /** 122 /**
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16e1653..ec9f893 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -225,24 +225,25 @@ AddressBook::AddressBook( const QString &config )
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false;
237 d = new AddressBookData; 238 d = new AddressBookData;
238 QString fami = family; 239 QString fami = family;
239 qDebug("new ab "); 240 qDebug("new ab ");
240 if (config != 0) { 241 if (config != 0) {
241 qDebug("config != 0 "); 242 qDebug("config != 0 ");
242 if ( family == "syncContact" ) { 243 if ( family == "syncContact" ) {
243 qDebug("creating sync config "); 244 qDebug("creating sync config ");
244 fami = "contact"; 245 fami = "contact";
245 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
246 con->setGroup( "General" ); 247 con->setGroup( "General" );
247 con->writeEntry( "ResourceKeys", QString("sync") ); 248 con->writeEntry( "ResourceKeys", QString("sync") );
248 con->writeEntry( "Standard", QString("sync") ); 249 con->writeEntry( "Standard", QString("sync") );
@@ -336,24 +337,25 @@ bool AddressBook::load()
336 bool ok = true; 337 bool ok = true;
337 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
338 if ( !(*it)->load() ) { 339 if ( !(*it)->load() ) {
339 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
340 ok = false; 341 ok = false;
341 } 342 }
342 343
343 // mark all addressees as unchanged 344 // mark all addressees as unchanged
344 Addressee::List::Iterator addrIt; 345 Addressee::List::Iterator addrIt;
345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
346 (*addrIt).setChanged( false ); 347 (*addrIt).setChanged( false );
347 348
349 blockLSEchange = true;
348 return ok; 350 return ok;
349} 351}
350 352
351bool AddressBook::save( Ticket *ticket ) 353bool AddressBook::save( Ticket *ticket )
352{ 354{
353 kdDebug(5700) << "AddressBook::save()"<< endl; 355 kdDebug(5700) << "AddressBook::save()"<< endl;
354 356
355 if ( ticket->resource() ) { 357 if ( ticket->resource() ) {
356 deleteRemovedAddressees(); 358 deleteRemovedAddressees();
357 return ticket->resource()->save( ticket ); 359 return ticket->resource()->save( ticket );
358 } 360 }
359 361
@@ -438,71 +440,128 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
438 if ( (*it)->readOnly() || !(*it)->isOpen() ) 440 if ( (*it)->readOnly() || !(*it)->isOpen() )
439 return 0; 441 return 0;
440 else 442 else
441 return (*it)->requestSaveTicket(); 443 return (*it)->requestSaveTicket();
442 } 444 }
443 } 445 }
444 446
445 return 0; 447 return 0;
446} 448}
447 449
448void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 450void AddressBook::insertAddressee( const Addressee &a, bool setRev )
449{ 451{
452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
453 return;
454 }
455 bool found = false;
450 Addressee::List::Iterator it; 456 Addressee::List::Iterator it;
451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
452 if ( a.uid() == (*it).uid() ) { 458 if ( a.uid() == (*it).uid() ) {
453 if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 459
454 return;
455 }
456 bool changed = false; 460 bool changed = false;
457 Addressee addr = a; 461 Addressee addr = a;
458 if ( addr != (*it) ) 462 if ( addr != (*it) )
459 changed = true; 463 changed = true;
460 464
461 (*it) = a; 465 (*it) = a;
462 if ( (*it).resource() == 0 ) 466 if ( (*it).resource() == 0 )
463 (*it).setResource( standardResource() ); 467 (*it).setResource( standardResource() );
464 468
465 if ( changed ) { 469 if ( changed ) {
466 if ( setRev ) { 470 if ( setRev ) {
467 471
468 // get rid of micro seconds 472 // get rid of micro seconds
469 QDateTime dt = QDateTime::currentDateTime(); 473 QDateTime dt = QDateTime::currentDateTime();
470 QTime t = dt.time(); 474 QTime t = dt.time();
471 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
472 (*it).setRevision( dt ); 476 (*it).setRevision( dt );
473 } 477 }
474 (*it).setChanged( true ); 478 (*it).setChanged( true );
475 } 479 }
476 480
477 return; 481 found = true;
482 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 );
485 Addressee b = a;
486 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) {
488 QString des = (*it).note();
489 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des );
494 }
478 } 495 }
479 } 496 }
497 }
498 }
499 if ( found )
500 return;
480 d->mAddressees.append( a ); 501 d->mAddressees.append( a );
481 Addressee& addr = d->mAddressees.last(); 502 Addressee& addr = d->mAddressees.last();
482 if ( addr.resource() == 0 ) 503 if ( addr.resource() == 0 )
483 addr.setResource( standardResource() ); 504 addr.setResource( standardResource() );
484 505
485 addr.setChanged( true ); 506 addr.setChanged( true );
486} 507}
487 508
488void AddressBook::removeAddressee( const Addressee &a ) 509void AddressBook::removeAddressee( const Addressee &a )
489{ 510{
490 Iterator it; 511 Iterator it;
512 Iterator it2;
513 bool found = false;
491 for ( it = begin(); it != end(); ++it ) { 514 for ( it = begin(); it != end(); ++it ) {
492 if ( a.uid() == (*it).uid() ) { 515 if ( a.uid() == (*it).uid() ) {
493 removeAddressee( it ); 516 found = true;
494 return; 517 it2 = it;
518 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 );
521 Addressee b = a;
522 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) {
524 QString des = (*it).note();
525 if( des.find( id ) < 0 ) {
526 des += id + ",";
527 (*it).setNote( des );
528 }
495 } 529 }
496 } 530 }
531
532 }
533 }
534
535 if ( found )
536 removeAddressee( it2 );
537
538}
539
540void AddressBook::removeDeletedAddressees()
541{
542 deleteRemovedAddressees();
543 Iterator it = begin();
544 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) {
547 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
549 it2 = it;
550 ++it;
551 removeAddressee( it2 );
552 } else
553 ++it;
554 }
555 deleteRemovedAddressees();
497} 556}
498 557
499void AddressBook::removeAddressee( const Iterator &it ) 558void AddressBook::removeAddressee( const Iterator &it )
500{ 559{
501 d->mRemovedAddressees.append( (*it) ); 560 d->mRemovedAddressees.append( (*it) );
502 d->mAddressees.remove( it.d->mIt ); 561 d->mAddressees.remove( it.d->mIt );
503} 562}
504 563
505AddressBook::Iterator AddressBook::find( const Addressee &a ) 564AddressBook::Iterator AddressBook::find( const Addressee &a )
506{ 565{
507 Iterator it; 566 Iterator it;
508 for ( it = begin(); it != end(); ++it ) { 567 for ( it = begin(); it != end(); ++it ) {
@@ -514,38 +573,40 @@ AddressBook::Iterator AddressBook::find( const Addressee &a )
514} 573}
515 574
516Addressee AddressBook::findByUid( const QString &uid ) 575Addressee AddressBook::findByUid( const QString &uid )
517{ 576{
518 Iterator it; 577 Iterator it;
519 for ( it = begin(); it != end(); ++it ) { 578 for ( it = begin(); it != end(); ++it ) {
520 if ( uid == (*it).uid() ) { 579 if ( uid == (*it).uid() ) {
521 return *it; 580 return *it;
522 } 581 }
523 } 582 }
524 return Addressee(); 583 return Addressee();
525} 584}
585#if 0
526Addressee::List AddressBook::getExternLastSyncAddressees() 586Addressee::List AddressBook::getExternLastSyncAddressees()
527{ 587{
528 Addressee::List results; 588 Addressee::List results;
529 589
530 Iterator it; 590 Iterator it;
531 for ( it = begin(); it != end(); ++it ) { 591 for ( it = begin(); it != end(); ++it ) {
532 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 592 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
533 if ( (*it).familyName().left(3) == "E: " ) 593 if ( (*it).familyName().left(4) == "!E: " )
534 results.append( *it ); 594 results.append( *it );
535 } 595 }
536 } 596 }
537 597
538 return results; 598 return results;
539} 599}
600#endif
540void AddressBook::resetTempSyncStat() 601void AddressBook::resetTempSyncStat()
541{ 602{
542 Iterator it; 603 Iterator it;
543 for ( it = begin(); it != end(); ++it ) { 604 for ( it = begin(); it != end(); ++it ) {
544 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 605 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
545 } 606 }
546 607
547} 608}
548 609
549QStringList AddressBook:: uidList() 610QStringList AddressBook:: uidList()
550{ 611{
551 QStringList results; 612 QStringList results;
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 253de68..2f2678b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -280,27 +280,28 @@ class AddressBook : public QObject
280 280
281 /** 281 /**
282 Shows gui independend error messages. 282 Shows gui independend error messages.
283 */ 283 */
284 void error( const QString& ); 284 void error( const QString& );
285 285
286 /** 286 /**
287 Query all resources to clean up their lock files 287 Query all resources to clean up their lock files
288 */ 288 */
289 void cleanUp(); 289 void cleanUp();
290 290
291 // sync stuff 291 // sync stuff
292 Addressee::List getExternLastSyncAddressees(); 292 //Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList(); 294 QStringList uidList();
295 void removeDeletedAddressees();
295 296
296 297
297 signals: 298 signals:
298 /** 299 /**
299 Emitted, when the address book has changed on disk. 300 Emitted, when the address book has changed on disk.
300 */ 301 */
301 void addressBookChanged( AddressBook * ); 302 void addressBookChanged( AddressBook * );
302 303
303 /** 304 /**
304 Emitted, when the address book has been locked for writing. 305 Emitted, when the address book has been locked for writing.
305 */ 306 */
306 void addressBookLocked( AddressBook * ); 307 void addressBookLocked( AddressBook * );
@@ -315,20 +316,21 @@ class AddressBook : public QObject
315 void setStandardResource( Resource * ); 316 void setStandardResource( Resource * );
316 Resource *standardResource(); 317 Resource *standardResource();
317 KRES::Manager<Resource> *resourceManager(); 318 KRES::Manager<Resource> *resourceManager();
318 319
319 void init(const QString &config, const QString &family); 320 void init(const QString &config, const QString &family);
320 321
321 private: 322 private:
322//US QPtrList<Resource> mDummy; // Remove in KDE 4 323//US QPtrList<Resource> mDummy; // Remove in KDE 4
323 324
324 325
325 struct AddressBookData; 326 struct AddressBookData;
326 AddressBookData *d; 327 AddressBookData *d;
328 bool blockLSEchange;
327}; 329};
328 330
329QDataStream &operator<<( QDataStream &, const AddressBook & ); 331QDataStream &operator<<( QDataStream &, const AddressBook & );
330QDataStream &operator>>( QDataStream &, AddressBook & ); 332QDataStream &operator>>( QDataStream &, AddressBook & );
331 333
332} 334}
333 335
334#endif 336#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7f04d8f..0f5d605 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -165,24 +165,120 @@ bool Addressee::operator==( const Addressee &a ) const
165 return true; 165 return true;
166} 166}
167 167
168bool Addressee::operator!=( const Addressee &a ) const 168bool Addressee::operator!=( const Addressee &a ) const
169{ 169{
170 return !( a == *this ); 170 return !( a == *this );
171} 171}
172 172
173bool Addressee::isEmpty() const 173bool Addressee::isEmpty() const
174{ 174{
175 return mData->empty; 175 return mData->empty;
176} 176}
177ulong Addressee::getCsum4List( const QStringList & attList)
178{
179 int max = attList.count();
180 ulong cSum = 0;
181 int j,k,i;
182 int add;
183 for ( i = 0; i < max ; ++i ) {
184 QString s = attList[i];
185 if ( ! s.isEmpty() ){
186 j = s.length();
187 for ( k = 0; k < j; ++k ) {
188 int mul = k +1;
189 add = s[k].unicode ();
190 if ( k < 16 )
191 mul = mul * mul;
192 int ii = i+1;
193 add = add * mul *ii*ii*ii;
194 cSum += add;
195 }
196 }
197
198 }
199 //QString dump = attList.join(",");
200 //qDebug("csum: %d %s", cSum,dump.latin1());
201
202 return cSum;
203
204}
205void Addressee::computeCsum(const QString &dev)
206{
207 QStringList l;
208 if ( !mData->name.isEmpty() ) l.append(mData->name);
209 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
210 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
211 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
212 if ( !mData->additionalName ) l.append( mData->additionalName );
213 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
214 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
215 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
216 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
217 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
218 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
219 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
220 if ( !mData->title .isEmpty() ) l.append( mData->title );
221 if ( !mData->role.isEmpty() ) l.append( mData->role );
222 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
223 if ( !mData->note.isEmpty() ) l.append( mData->note );
224 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
225 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
226 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
227 // if ( !mData->logo.isEmpty() ) l.append( );
228 //if ( !mData->photo.isEmpty() ) l.append( );
229 //if ( !mData->sound.isEmpty() ) l.append( );
230 //if ( !mData->agent.isEmpty() ) l.append( );
231 //if ( mData->url.isValid() ) l.append( );
232#if 0
233 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
234 if ( !mData->addresses.isEmpty() ) l.append( );
235 //if ( !mData->keys.isEmpty() ) l.append( );
236 if ( !mData->emails.isEmpty() ) l.append( );
237 if ( !mData->categories .isEmpty() ) l.append( );
238 if ( !mData->custom.isEmpty() ) l.append( );
239#endif
240 KABC::PhoneNumber::List phoneNumbers;
241 KABC::PhoneNumber::List::Iterator phoneIter;
242
243 QStringList t;
244 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
245 ++phoneIter )
246 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
247 t.sort();
248 uint iii;
249 for ( iii = 0; iii < t.count(); ++iii)
250 l.append( t[iii] );
251 t = mData->emails;
252 t.sort();
253 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] );
255 t = mData->categories;
256 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] );
259 t = mData->custom;
260 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] );
263 KABC::Address::List::Iterator addressIter;
264 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
265 ++addressIter ) {
266 t = (*addressIter).asList();
267 t.sort();
268 for ( iii = 0; iii < t.count(); ++iii)
269 l.append( t[iii] );
270 }
271 setCsum( dev, QString::number (getCsum4List(l)) );
272}
177void Addressee::removeID(const QString &prof) 273void Addressee::removeID(const QString &prof)
178{ 274{
179 detach(); 275 detach();
180 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 276 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
181 277
182} 278}
183void Addressee::setID( const QString & prof , const QString & id ) 279void Addressee::setID( const QString & prof , const QString & id )
184{ 280{
185 detach(); 281 detach();
186 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 282 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
187} 283}
188void Addressee::setTempSyncStat( int id ) 284void Addressee::setTempSyncStat( int id )
@@ -1445,25 +1541,24 @@ void Addressee::insertCustom( const QString &app, const QString &name,
1445 detach(); 1541 detach();
1446 mData->empty = false; 1542 mData->empty = false;
1447 1543
1448 QString qualifiedName = app + "-" + name + ":"; 1544 QString qualifiedName = app + "-" + name + ":";
1449 1545
1450 QStringList::Iterator it; 1546 QStringList::Iterator it;
1451 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1547 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1452 if ( (*it).startsWith( qualifiedName ) ) { 1548 if ( (*it).startsWith( qualifiedName ) ) {
1453 (*it) = qualifiedName + value; 1549 (*it) = qualifiedName + value;
1454 return; 1550 return;
1455 } 1551 }
1456 } 1552 }
1457
1458 mData->custom.append( qualifiedName + value ); 1553 mData->custom.append( qualifiedName + value );
1459} 1554}
1460 1555
1461void Addressee::removeCustom( const QString &app, const QString &name) 1556void Addressee::removeCustom( const QString &app, const QString &name)
1462{ 1557{
1463 detach(); 1558 detach();
1464 1559
1465 QString qualifiedName = app + "-" + name + ":"; 1560 QString qualifiedName = app + "-" + name + ":";
1466 1561
1467 QStringList::Iterator it; 1562 QStringList::Iterator it;
1468 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1563 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1469 if ( (*it).startsWith( qualifiedName ) ) { 1564 if ( (*it).startsWith( qualifiedName ) ) {
diff --git a/kabc/addressee.h b/kabc/addressee.h
index f098371..0805458 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -97,24 +97,26 @@ class Addressee
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);
110 ulong getCsum4List( const QStringList & attList);
109 /** 111 /**
110 Return, if the address book entry is empty. 112 Return, if the address book entry is empty.
111 */ 113 */
112 bool isEmpty() const; 114 bool isEmpty() const;
113 115
114 /** 116 /**
115 Set unique identifier. 117 Set unique identifier.
116 */ 118 */
117 void setUid( const QString &uid ); 119 void setUid( const QString &uid );
118 /** 120 /**
119 Return unique identifier. 121 Return unique identifier.
120 */ 122 */
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index cc8eb52..8776b53 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2660,26 +2660,26 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2660 int addedAddresseeR = 0; 2660 int addedAddresseeR = 0;
2661 int deletedAddresseeR = 0; 2661 int deletedAddresseeR = 0;
2662 int deletedAddresseeL = 0; 2662 int deletedAddresseeL = 0;
2663 int changedLocal = 0; 2663 int changedLocal = 0;
2664 int changedRemote = 0; 2664 int changedRemote = 0;
2665 //QPtrList<Addressee> el = local->rawAddressees(); 2665 //QPtrList<Addressee> el = local->rawAddressees();
2666 Addressee addresseeR; 2666 Addressee addresseeR;
2667 QString uid; 2667 QString uid;
2668 int take; 2668 int take;
2669 Addressee addresseeL; 2669 Addressee addresseeL;
2670 Addressee addresseeRSync; 2670 Addressee addresseeRSync;
2671 Addressee addresseeLSync; 2671 Addressee addresseeLSync;
2672 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2672 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2673 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2673 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2674 bool fullDateRange = false; 2674 bool fullDateRange = false;
2675 local->resetTempSyncStat(); 2675 local->resetTempSyncStat();
2676 mLastAddressbookSync = QDateTime::currentDateTime(); 2676 mLastAddressbookSync = QDateTime::currentDateTime();
2677 QDateTime modifiedCalendar = mLastAddressbookSync;; 2677 QDateTime modifiedCalendar = mLastAddressbookSync;;
2678 addresseeLSync = getLastSyncAddressee(); 2678 addresseeLSync = getLastSyncAddressee();
2679 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2679 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2680 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2680 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2681 if ( !addresseeR.isEmpty() ) { 2681 if ( !addresseeR.isEmpty() ) {
2682 addresseeRSync = addresseeR; 2682 addresseeRSync = addresseeR;
2683 remote->removeAddressee(addresseeR ); 2683 remote->removeAddressee(addresseeR );
2684 2684
2685 } else { 2685 } else {
@@ -2700,25 +2700,25 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2700 qDebug("FULLDATE 2"); 2700 qDebug("FULLDATE 2");
2701 fullDateRange = true; 2701 fullDateRange = true;
2702 } 2702 }
2703 if ( ! fullDateRange ) { 2703 if ( ! fullDateRange ) {
2704 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2704 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2705 2705
2706 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2706 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2707 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2707 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2708 fullDateRange = true; 2708 fullDateRange = true;
2709 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2709 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2710 } 2710 }
2711 } 2711 }
2712 fullDateRange = true; // debug only! 2712 // fullDateRange = true; // debug only!
2713 if ( fullDateRange ) 2713 if ( fullDateRange )
2714 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2714 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2715 else 2715 else
2716 mLastAddressbookSync = addresseeLSync.revision(); 2716 mLastAddressbookSync = addresseeLSync.revision();
2717 // for resyncing if own file has changed 2717 // for resyncing if own file has changed
2718 // PENDING fixme later when implemented 2718 // PENDING fixme later when implemented
2719#if 0 2719#if 0
2720 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2720 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2721 mLastAddressbookSync = loadedFileVersion; 2721 mLastAddressbookSync = loadedFileVersion;
2722 qDebug("setting mLastAddressbookSync "); 2722 qDebug("setting mLastAddressbookSync ");
2723 } 2723 }
2724#endif 2724#endif
@@ -2909,33 +2909,61 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2909} 2909}
2910 2910
2911bool KABCore::syncAB(QString filename, int mode) 2911bool KABCore::syncAB(QString filename, int mode)
2912{ 2912{
2913 2913
2914 //pending prepare addresseeview for output 2914 //pending prepare addresseeview for output
2915 //pending detect, if remote file has REV field. if not switch to external sync 2915 //pending detect, if remote file has REV field. if not switch to external sync
2916 mGlobalSyncMode = SYNC_MODE_NORMAL; 2916 mGlobalSyncMode = SYNC_MODE_NORMAL;
2917 AddressBook abLocal(filename,"syncContact"); 2917 AddressBook abLocal(filename,"syncContact");
2918 bool syncOK = false; 2918 bool syncOK = false;
2919 if ( abLocal.load() ) { 2919 if ( abLocal.load() ) {
2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2921 bool external = false;
2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2923 if ( ! lse.isEmpty() ) {
2924 if ( lse.familyName().left(4) == "!E: " )
2925 external = true;
2926 } else {
2927 bool found = false;
2928 QDateTime dt( QDate( 2004,1,1));
2921 AddressBook::Iterator it; 2929 AddressBook::Iterator it;
2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2931 if ( (*it).revision() != dt ) {
2932 found = true;
2933 break;
2934 }
2935 }
2936 external = ! found;
2937 }
2938
2939 if ( external ) {
2940 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2941 AddressBook::Iterator it;
2942 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2943 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2944 (*it).computeCsum( mCurrentSyncDevice );
2945 }
2946 }
2947 //AddressBook::Iterator it;
2922 //QStringList vcards; 2948 //QStringList vcards;
2923 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2949 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2924 // qDebug("Name %s ", (*it).familyName().latin1()); 2950 // qDebug("Name %s ", (*it).familyName().latin1());
2925 //} 2951 //}
2926 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2952 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2927 if ( syncOK ) { 2953 if ( syncOK ) {
2928 if ( KABPrefs::instance()->mWriteBackFile ) 2954 if ( KABPrefs::instance()->mWriteBackFile )
2929 { 2955 {
2956 if ( external )
2957 abLocal.removeDeletedAddressees();
2930 qDebug("saving remote AB "); 2958 qDebug("saving remote AB ");
2931 abLocal.saveAB(); 2959 abLocal.saveAB();
2932 } 2960 }
2933 } 2961 }
2934 setModified(); 2962 setModified();
2935 2963
2936 } 2964 }
2937 if ( syncOK ) 2965 if ( syncOK )
2938 mViewManager->refreshView(); 2966 mViewManager->refreshView();
2939 return syncOK; 2967 return syncOK;
2940#if 0 2968#if 0
2941 2969