-rw-r--r-- | kabc/addressbook.cpp | 27 | ||||
-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 | 79 |
5 files changed, 98 insertions, 19 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 86dc7c2..17b9ba2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -523,165 +523,180 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev ) void AddressBook::removeAddressee( const Addressee &a ) { Iterator it; Iterator it2; bool found = false; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { found = true; it2 = it; } else { if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { QString name = (*it).uid().mid( 19 ); Addressee b = a; QString id = b.getID( name ); if ( ! id.isEmpty() ) { QString des = (*it).note(); if( des.find( id ) < 0 ) { des += id + ","; (*it).setNote( des ); } } } } } 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 { + } else { //qDebug("skipping %s ",(*it).uid().latin1() ); ++it; } } deleteRemovedAddressees(); } void AddressBook::removeAddressee( const Iterator &it ) { d->mRemovedAddressees.append( (*it) ); d->mAddressees.remove( it.d->mIt ); } AddressBook::Iterator AddressBook::find( const Addressee &a ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { return it; } } return end(); } Addressee AddressBook::findByUid( const QString &uid ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).uid() ) { return *it; } } return Addressee(); } void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) { qDebug("AddressBook::preExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { (*it).setID( csd, (*it).externalUID() ); (*it).computeCsum( 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(); } 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; for ( it = begin(); it != end(); ++it ) { if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { if ( (*it).familyName().left(4) == "!E: " ) results.append( *it ); } } return results; } #endif void AddressBook::resetTempSyncStat() { Iterator it; for ( it = begin(); it != end(); ++it ) { (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); } } QStringList AddressBook:: uidList() { QStringList results; Iterator it; for ( it = begin(); it != end(); ++it ) { diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 157dc56..8f62f0d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -263,67 +263,68 @@ class AddressBook : public QObject bool addResource( Resource * ); /** Remove address book resource. */ bool removeResource( Resource * ); /** Return pointer list of all resources. */ QPtrList<Resource> resources(); /** Set the @p ErrorHandler, that is used by @ref error() to provide gui-independend error messages. */ void setErrorHandler( ErrorHandler * ); /** Shows gui independend error messages. */ void error( const QString& ); /** 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 * ); /** Emitted, when the address book has been locked for writing. */ void addressBookLocked( AddressBook * ); /** Emitted, when the address book has been unlocked. */ void addressBookUnlocked( AddressBook * ); protected: void deleteRemovedAddressees(); void setStandardResource( Resource * ); Resource *standardResource(); KRES::Manager<Resource> *resourceManager(); void init(const QString &config, const QString &family); private: //US QPtrList<Resource> mDummy; // Remove in KDE 4 struct AddressBookData; diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index fda62f1..e241281 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -66,65 +66,65 @@ struct Addressee::AddresseeData : public KShared QString productId; QDateTime revision; QString sortString; QString externalUID; QString originalExternalUID; KURL url; Secrecy secrecy; Picture logo; Picture photo; Sound sound; Agent agent; QString mExternalId; PhoneNumber::List phoneNumbers; Address::List addresses; Key::List keys; QStringList emails; QStringList categories; QStringList custom; int mTempSyncStat; Resource *resource; bool empty :1; bool changed :1; }; 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 ) { mData = a.mData; } Addressee &Addressee::operator=( const Addressee &a ) { mData = a.mData; return (*this); } Addressee Addressee::copy() { Addressee a; *(a.mData) = *mData; return a; } void Addressee::detach() { if ( mData.count() == 1 ) return; *this = copy(); } bool Addressee::operator==( const Addressee &a ) const @@ -279,64 +279,66 @@ void Addressee::mergeContact( const Addressee& ad ) detach(); if ( mData->name.isEmpty() ) mData->name = ad.mData->name; if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; if ( !mData->birthday.isValid() ) if ( ad.mData->birthday.isValid()) mData->birthday = ad.mData->birthday; if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; // 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); } void Addressee::setID( const QString & prof , const QString & id ) { detach(); 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 ) { if ( mData->mTempSyncStat == id ) return; detach(); mData->mTempSyncStat = id; } int Addressee::tempSyncStat() const { return mData->mTempSyncStat; } QString Addressee::getID( const QString & prof) { return KIdManager::getId ( mData->mExternalId, prof ); } void Addressee::setCsum( const QString & prof , const QString & id ) { @@ -350,76 +352,78 @@ QString Addressee::getCsum( const QString & prof) { return KIdManager::getCsum ( mData->mExternalId, prof ); } void Addressee::setIDStr( const QString & s ) { detach(); mData->mExternalId = s; } QString Addressee::IDStr() const { return mData->mExternalId; } void Addressee::setExternalUID( const QString &id ) { if ( id == mData->externalUID ) return; detach(); mData->empty = false; mData->externalUID = id; } 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 ); return mData->uid; } QString Addressee::uidLabel() { return i18n("Unique Identifier"); } void Addressee::setName( const QString &name ) { if ( name == mData->name ) return; detach(); mData->empty = false; mData->name = name; } QString Addressee::name() const { return mData->name; } QString Addressee::nameLabel() { 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 @@ -57,65 +57,65 @@ bool QtopiaConverter::init() catDB->load( categoryFileName() ); return true; } void QtopiaConverter::deinit() { if (catDB) { delete catDB; catDB = 0; } } bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) { // name addr.setFormattedName(contact.fileAs()); addr.setFamilyName( contact.lastName() ); addr.setGivenName( contact.firstName() ); addr.setAdditionalName( contact.middleName() ); addr.setPrefix( contact.nameTitle() ); addr.setSuffix( contact.suffix() ); addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 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()) addr.insertEmail(contact.defaultEmail(), true); // home if ((!contact.homeStreet().isEmpty()) || (!contact.homeCity().isEmpty()) || (!contact.homeState().isEmpty()) || (!contact.homeZip().isEmpty()) || (!contact.homeCountry().isEmpty())) { Address homeaddress; homeaddress.setType(Address::Home); //US homeaddress.setPostOfficeBox( "" ); //US homeaddress.setExtended( "" ); homeaddress.setStreet( contact.homeStreet() ); homeaddress.setLocality( contact.homeCity() ); homeaddress.setRegion( contact.homeState() ); homeaddress.setPostalCode( contact.homeZip() ); homeaddress.setCountry( contact.homeCountry() ); addr.insertAddress( homeaddress ); } if (!contact.homePhone().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 @@ -168,105 +168,164 @@ bool ResourceQtopia::load() qDebug("ResourceQtopia::load: %s", fileName().latin1()); AddressBookIterator it(*mAccess); const PimContact* contact; bool res; for (contact=it.toFirst(); it.current(); ++it) { contact = it.current(); KABC::Addressee addressee; res = mConverter->qtopiaToAddressee( (*contact), addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } 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); - KABC::Addressee addressee; - mConverter->qtopiaToAddressee( c, addressee ); - addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); - addressBook()->insertAddressee( addressee ); + 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( g, addressee ); + addressee.setUid((*it).uid() ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + 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; } bool ResourceQtopia::lock( const QString &lockfileName ) { qDebug("ResourceQtopia::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceQtopia::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; |