-rw-r--r-- | kabc/addressbook.cpp | 25 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kabc/addressee.cpp | 6 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 75 |
5 files changed, 95 insertions, 16 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 86dc7c2..17b9ba2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -547,27 +547,26 @@ void AddressBook::removeAddressee( const Addressee &a ) } } if ( found ) removeAddressee( it2 ); } -void AddressBook::removeDeletedAddressees() +void AddressBook::removeSyncAddressees( bool removeDeleted ) { - deleteRemovedAddressees(); Iterator it = begin(); Iterator it2 ; QDateTime dt ( QDate( 2004,1,1) ); while ( it != end() ) { (*it).setRevision( dt ); (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr(""); - if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { + if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { it2 = it; //qDebug("removing %s ",(*it).uid().latin1() ); ++it; removeAddressee( it2 ); } else { //qDebug("skipping %s ",(*it).uid().latin1() ); ++it; } @@ -612,33 +611,42 @@ void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) } mergeAB( aBook ,csd ); } void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) { qDebug("AddressBook::postExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { + qDebug("check uid %s ", (*it).uid().latin1() ); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { Addressee ad = aBook->findByUid( ( (*it).uid() )); if ( ad.isEmpty() ) { - qDebug("ERROR ad empty "); + qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); } else { (*it).computeCsum( csd ); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) ad.setID( csd, (*it).externalUID() ); ad.setCsum( csd, (*it).getCsum( csd ) ); aBook->insertAddressee( ad ); } } } } - +bool AddressBook::containsExternalUid( const QString& uid ) +{ + Iterator it; + for ( it = begin(); it != end(); ++it ) { + if ( uid == (*it).externalUID( ) ) + return true; + } + return false; +} Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).getID( profile ) ) return (*it); } return Addressee(); @@ -648,16 +656,23 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) Iterator it; Addressee ad; for ( it = begin(); it != end(); ++it ) { ad = aBook->findByExternUid( (*it).externalUID(), profile ); if ( !ad.isEmpty() ) { (*it).mergeContact( ad ); } } +#if 0 + // test only + for ( it = begin(); it != end(); ++it ) { + + qDebug("uid %s ", (*it).uid().latin1()); + } +#endif } #if 0 Addressee::List AddressBook::getExternLastSyncAddressees() { Addressee::List results; Iterator it; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 157dc56..8f62f0d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -287,19 +287,20 @@ class AddressBook : public QObject Query all resources to clean up their lock files */ void cleanUp(); // sync stuff //Addressee::List getExternLastSyncAddressees(); void resetTempSyncStat(); QStringList uidList(); - void removeDeletedAddressees(); + void removeSyncAddressees( bool removeDeleted = false ); void mergeAB( AddressBook *aBook, const QString& profile ); Addressee findByExternUid( const QString& uid , const QString& profile ); + bool containsExternalUid( const QString& uid ); void preExternSync( AddressBook* aBook, const QString& csd ); void postExternSync( AddressBook* aBook, const QString& csd ); signals: /** Emitted, when the address book has changed on disk. */ void addressBookChanged( AddressBook * ); diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index fda62f1..e241281 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -90,17 +90,17 @@ struct Addressee::AddresseeData : public KShared Addressee::Addressee() { mData = new AddresseeData; mData->empty = true; mData->changed = false; mData->resource = 0; mData->mExternalId = ":"; - mData->revision = QDateTime ( QDate( 2004,1,1)); + mData->revision = QDateTime ( QDate( 2003,1,1)); mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; } Addressee::~Addressee() { } Addressee::Addressee( const Addressee &a ) @@ -303,16 +303,18 @@ void Addressee::mergeContact( const Addressee& ad ) // pending: // merging phonenumbers // merging addresses // merging emails; // merging categories; // merging custom; // merging keys + qDebug("merge contact %s ", ad.uid().latin1()); + setUid( ad.uid() ); } void Addressee::removeID(const QString &prof) { detach(); mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); } @@ -374,28 +376,30 @@ QString Addressee::externalUID() const { return mData->externalUID; } void Addressee::setOriginalExternalUID( const QString &id ) { if ( id == mData->originalExternalUID ) return; detach(); mData->empty = false; + qDebug("*******Set orig uid %s ", id.latin1()); mData->originalExternalUID = id; } QString Addressee::originalExternalUID() const { return mData->originalExternalUID; } void Addressee::setUid( const QString &id ) { if ( id == mData->uid ) return; detach(); + qDebug("****setuid %s ", id.latin1()); mData->empty = false; mData->uid = id; } QString Addressee::uid() const { if ( mData->uid.isEmpty() ) mData->uid = KApplication::randomString( 10 ); diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index de45e63..430c7b3 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -81,17 +81,17 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a QString exuid = contact.uid().toString(); addr.setOriginalExternalUID( exuid ); int ente = exuid.find( "-0000"); if ( exuid.left(1) == "{" ) exuid = exuid.mid(1); if ( ente > -1 ) exuid = exuid.left( ente-1 ); addr.setExternalUID( exuid ); - //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); + qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); // email QStringList emails = contact.emailList(); for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); } if (!contact.defaultEmail().isEmpty()) diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 935a1cf..1f90fcb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -192,57 +192,116 @@ bool ResourceQtopia::load() bool ResourceQtopia::save( Ticket *ticket ) { qDebug("ResourceQtopia::save: %s", fileName().latin1()); mDirWatch.stopScan(); KABC::AddressBook::Iterator it; bool res; - + KABC::Addressee::List changedAddressees; + QStringList addedUID; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { //KABC::Addressee addressee = (*it); + // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() ); if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { QUuid uid( (*it).originalExternalUID() ); bool ok; PimContact c = mAccess->contactForId( uid, &ok ); + qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() ); res = mConverter->addresseeToQtopia( *it, c ); if (res == true) { if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { - mAccess->addContact(c); + qDebug("skipping adding of contact "); + continue; + PimContact e; + AddressBookAccess Access2; + Access2.addContact(e); + const PimContact* contact; + bool res; + QString uid2, Ouid; + AddressBookIterator itt(Access2); + for (contact=itt.toFirst(); itt.current(); ++itt) + { + contact = itt.current(); + QString exuid = contact->uid().toString(); + Ouid =exuid; + int ente = exuid.find( "-0000"); + if ( exuid.left(1) == "{" ) + exuid = exuid.mid(1); + if ( ente > -1 ) + exuid = exuid.left( ente-1 ); + uid2 = exuid; + qDebug("trying find uid "); + if ( !addressBook()->containsExternalUid( uid2 ) ) { + qDebug("ab not contains "); + if ( !addedUID.contains( uid2 )) { + qDebug("list not contains "); + break; + } + } + + } + if ( !itt.current()) { + qDebug("ERROR uid "); + continue; + } + else + qDebug("ADD uid detected "); + + + QUuid uid3( Ouid); + PimContact d = Access2.contactForId( uid3, &ok ); + if ( ! ok ) { + qDebug("ADD: Error getting new uid "); + } else { + qDebug("NEW UID found "); + PimContact g = mAccess->contactForId( c.uid(), &ok ); KABC::Addressee addressee; - mConverter->qtopiaToAddressee( c, addressee ); + mConverter->qtopiaToAddressee( g, addressee ); + addressee.setUid((*it).uid() ); addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); - addressBook()->insertAddressee( addressee ); + changedAddressees.append( addressee ); + addedUID.append( uid2 ); + } + } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + qDebug("Remove contact "); if ( ok ) mAccess->removeContact(c); else - qDebug("Error revoe contact from qtopia "); + qDebug("Error remove contact from qtopia "); } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { if ( ok ) { + qDebug("Update contact "); mAccess->updateContact(c); + PimContact g = mAccess->contactForId( c.uid(), &ok ); KABC::Addressee addressee; - mConverter->qtopiaToAddressee( c, addressee ); + mConverter->qtopiaToAddressee( g, addressee ); + addressee.setUid((*it).uid() ); addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); - addressBook()->insertAddressee( addressee ); + changedAddressees.append( addressee ); } else qDebug("Error update contact from qtopia "); } } else { qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); } } } - // mAccess->addressBookUpdated(); + KABC::Addressee::List::Iterator it2; + for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) + addressBook()->insertAddressee((*it2)); + + mDirWatch.startScan(); delete ticket; unlock( fileName() ); return true; } |