author | zautrix <zautrix> | 2004-09-19 09:00:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-19 09:00:55 (UTC) |
commit | 787181d34f0d195ad72c9cf6aedbc317b6dd713e (patch) (unidiff) | |
tree | ac49d2b1d7887f96f3834458071b89e77b59218b /kabc/addressbook.cpp | |
parent | f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (diff) | |
download | kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.zip kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.gz kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.bz2 |
more AB sync
-rw-r--r-- | kabc/addressbook.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ec9f893..46a9cf4 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -340,15 +340,20 @@ bool AddressBook::load() | |||
340 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 340 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
341 | ok = false; | 341 | ok = false; |
342 | } | 342 | } |
343 | 343 | ||
344 | // mark all addressees as unchanged | 344 | // mark all addressees as unchanged |
345 | Addressee::List::Iterator addrIt; | 345 | Addressee::List::Iterator addrIt; |
346 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) | 346 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
347 | (*addrIt).setChanged( false ); | 347 | (*addrIt).setChanged( false ); |
348 | 348 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | |
349 | if ( !id.isEmpty() ) { | ||
350 | //qDebug("setId aa %s ", id.latin1()); | ||
351 | (*addrIt).setIDStr(id ); | ||
352 | } | ||
353 | } | ||
349 | blockLSEchange = true; | 354 | blockLSEchange = true; |
350 | return ok; | 355 | return ok; |
351 | } | 356 | } |
352 | 357 | ||
353 | bool AddressBook::save( Ticket *ticket ) | 358 | bool AddressBook::save( Ticket *ticket ) |
354 | { | 359 | { |
@@ -363,13 +368,18 @@ bool AddressBook::save( Ticket *ticket ) | |||
363 | } | 368 | } |
364 | bool AddressBook::saveAB() | 369 | bool AddressBook::saveAB() |
365 | { | 370 | { |
366 | bool ok = true; | 371 | bool ok = true; |
367 | 372 | ||
368 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
369 | 374 | Iterator ait; | |
375 | for ( ait = begin(); ait != end(); ++ait ) { | ||
376 | if ( !(*ait).IDStr().isEmpty() ) { | ||
377 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | ||
378 | } | ||
379 | } | ||
370 | KRES::Manager<Resource>::ActiveIterator it; | 380 | KRES::Manager<Resource>::ActiveIterator it; |
371 | KRES::Manager<Resource> *manager = d->mManager; | 381 | KRES::Manager<Resource> *manager = d->mManager; |
372 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 382 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
373 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 383 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
374 | Ticket *ticket = requestSaveTicket( *it ); | 384 | Ticket *ticket = requestSaveTicket( *it ); |
375 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 385 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
@@ -447,14 +457,16 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
447 | return 0; | 457 | return 0; |
448 | } | 458 | } |
449 | 459 | ||
450 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 460 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
451 | { | 461 | { |
452 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 462 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
463 | //qDebug("block insert "); | ||
453 | return; | 464 | return; |
454 | } | 465 | } |
466 | //qDebug("inserting.... %s ",a.uid().latin1() ); | ||
455 | bool found = false; | 467 | bool found = false; |
456 | Addressee::List::Iterator it; | 468 | Addressee::List::Iterator it; |
457 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 469 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
458 | if ( a.uid() == (*it).uid() ) { | 470 | if ( a.uid() == (*it).uid() ) { |
459 | 471 | ||
460 | bool changed = false; | 472 | bool changed = false; |
@@ -477,13 +489,13 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | |||
477 | } | 489 | } |
478 | (*it).setChanged( true ); | 490 | (*it).setChanged( true ); |
479 | } | 491 | } |
480 | 492 | ||
481 | found = true; | 493 | found = true; |
482 | } else { | 494 | } else { |
483 | if ( (*it).uid() == QString("last-syncAddressee-") ) { | 495 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
484 | QString name = (*it).uid().mid( 19 ); | 496 | QString name = (*it).uid().mid( 19 ); |
485 | Addressee b = a; | 497 | Addressee b = a; |
486 | QString id = b.getID( name ); | 498 | QString id = b.getID( name ); |
487 | if ( ! id.isEmpty() ) { | 499 | if ( ! id.isEmpty() ) { |
488 | QString des = (*it).note(); | 500 | QString des = (*it).note(); |
489 | int startN; | 501 | int startN; |
@@ -513,13 +525,13 @@ void AddressBook::removeAddressee( const Addressee &a ) | |||
513 | bool found = false; | 525 | bool found = false; |
514 | for ( it = begin(); it != end(); ++it ) { | 526 | for ( it = begin(); it != end(); ++it ) { |
515 | if ( a.uid() == (*it).uid() ) { | 527 | if ( a.uid() == (*it).uid() ) { |
516 | found = true; | 528 | found = true; |
517 | it2 = it; | 529 | it2 = it; |
518 | } else { | 530 | } else { |
519 | if ( (*it).uid() == QString("last-syncAddressee-") ) { | 531 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
520 | QString name = (*it).uid().mid( 19 ); | 532 | QString name = (*it).uid().mid( 19 ); |
521 | Addressee b = a; | 533 | Addressee b = a; |
522 | QString id = b.getID( name ); | 534 | QString id = b.getID( name ); |
523 | if ( ! id.isEmpty() ) { | 535 | if ( ! id.isEmpty() ) { |
524 | QString des = (*it).note(); | 536 | QString des = (*it).note(); |
525 | if( des.find( id ) < 0 ) { | 537 | if( des.find( id ) < 0 ) { |
@@ -542,18 +554,23 @@ void AddressBook::removeDeletedAddressees() | |||
542 | deleteRemovedAddressees(); | 554 | deleteRemovedAddressees(); |
543 | Iterator it = begin(); | 555 | Iterator it = begin(); |
544 | Iterator it2 ; | 556 | Iterator it2 ; |
545 | QDateTime dt ( QDate( 2004,1,1) ); | 557 | QDateTime dt ( QDate( 2004,1,1) ); |
546 | while ( it != end() ) { | 558 | while ( it != end() ) { |
547 | (*it).setRevision( dt ); | 559 | (*it).setRevision( dt ); |
548 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 560 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
561 | (*it).setIDStr(""); | ||
562 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | ||
549 | it2 = it; | 563 | it2 = it; |
564 | //qDebug("removing %s ",(*it).uid().latin1() ); | ||
550 | ++it; | 565 | ++it; |
551 | removeAddressee( it2 ); | 566 | removeAddressee( it2 ); |
552 | } else | 567 | } else { |
568 | //qDebug("skipping %s ",(*it).uid().latin1() ); | ||
553 | ++it; | 569 | ++it; |
570 | } | ||
554 | } | 571 | } |
555 | deleteRemovedAddressees(); | 572 | deleteRemovedAddressees(); |
556 | } | 573 | } |
557 | 574 | ||
558 | void AddressBook::removeAddressee( const Iterator &it ) | 575 | void AddressBook::removeAddressee( const Iterator &it ) |
559 | { | 576 | { |