-rw-r--r-- | kabc/addressbook.cpp | 31 | ||||
-rw-r--r-- | kabc/addressee.cpp | 19 | ||||
-rw-r--r-- | kabc/addressee.h | 1 | ||||
-rw-r--r-- | kabc/stdaddressbook.cpp | 7 |
4 files changed, 43 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ec9f893..46a9cf4 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -343,9 +343,14 @@ bool AddressBook::load() // mark all addressees as unchanged Addressee::List::Iterator addrIt; - for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) + for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { (*addrIt).setChanged( false ); - + QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); + if ( !id.isEmpty() ) { + //qDebug("setId aa %s ", id.latin1()); + (*addrIt).setIDStr(id ); + } + } blockLSEchange = true; return ok; } @@ -366,7 +371,12 @@ bool AddressBook::saveAB() bool ok = true; deleteRemovedAddressees(); - + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + if ( !(*ait).IDStr().isEmpty() ) { + (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); + } + } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = d->mManager; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { @@ -450,8 +460,10 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) void AddressBook::insertAddressee( const Addressee &a, bool setRev ) { if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { + //qDebug("block insert "); return; } + //qDebug("inserting.... %s ",a.uid().latin1() ); bool found = false; Addressee::List::Iterator it; for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { @@ -480,7 +492,7 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev ) found = true; } else { - if ( (*it).uid() == QString("last-syncAddressee-") ) { + if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { QString name = (*it).uid().mid( 19 ); Addressee b = a; QString id = b.getID( name ); @@ -516,7 +528,7 @@ void AddressBook::removeAddressee( const Addressee &a ) found = true; it2 = it; } else { - if ( (*it).uid() == QString("last-syncAddressee-") ) { + if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { QString name = (*it).uid().mid( 19 ); Addressee b = a; QString id = b.getID( name ); @@ -545,13 +557,18 @@ void AddressBook::removeDeletedAddressees() QDateTime dt ( QDate( 2004,1,1) ); while ( it != end() ) { (*it).setRevision( dt ); - if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); + (*it).setIDStr(""); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { it2 = it; + //qDebug("removing %s ",(*it).uid().latin1() ); ++it; removeAddressee( it2 ); - } else + } else { + //qDebug("skipping %s ",(*it).uid().latin1() ); ++it; } + } deleteRemovedAddressees(); } diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 0f5d605..d6b70c4 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -79,7 +79,7 @@ struct Addressee::AddresseeData : public KShared QStringList emails; QStringList categories; QStringList custom; - + int mTempSyncStat; Resource *resource; bool empty :1; @@ -94,7 +94,7 @@ Addressee::Addressee() mData->resource = 0; mData->mExternalId = ":"; mData->revision = QDateTime ( QDate( 2004,1,1)); - mTempSyncStat = SYNC_TEMPSTATE_INITIAL; + mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; } Addressee::~Addressee() @@ -104,7 +104,6 @@ Addressee::~Addressee() Addressee::Addressee( const Addressee &a ) { mData = a.mData; - mTempSyncStat = SYNC_TEMPSTATE_INITIAL; } Addressee &Addressee::operator=( const Addressee &a ) @@ -268,7 +267,9 @@ void Addressee::computeCsum(const QString &dev) for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); } - setCsum( dev, QString::number (getCsum4List(l)) ); + uint cs = getCsum4List(l); + qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); + setCsum( dev, QString::number (cs )); } void Addressee::removeID(const QString &prof) { @@ -279,15 +280,19 @@ void Addressee::removeID(const QString &prof) void Addressee::setID( const QString & prof , const QString & id ) { detach(); + qDebug("setID1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); + qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); } void Addressee::setTempSyncStat( int id ) { - mTempSyncStat = id; + if ( mData->mTempSyncStat == id ) return; + detach(); + mData->mTempSyncStat = id; } int Addressee::tempSyncStat() const { - return mTempSyncStat; + return mData->mTempSyncStat; } QString Addressee::getID( const QString & prof) @@ -298,7 +303,9 @@ QString Addressee::getID( const QString & prof) void Addressee::setCsum( const QString & prof , const QString & id ) { detach(); + qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); + qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); } QString Addressee::getCsum( const QString & prof) diff --git a/kabc/addressee.h b/kabc/addressee.h index 0805458..bfb0840 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -826,7 +826,6 @@ class Addressee private: Addressee copy(); void detach(); - int mTempSyncStat; struct AddresseeData; mutable KSharedPtr<AddresseeData> mData; diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index ec47a4e..181a09e 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp @@ -165,7 +165,12 @@ bool StdAddressBook::save() AddressBook *ab = self(); ab->deleteRemovedAddressees(); - + Iterator ait; + for ( ait = ab->begin(); ait != ab->end(); ++ait ) { + if ( !(*ait).IDStr().isEmpty() ) { + (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); + } + } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = ab->resourceManager(); for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |