-rw-r--r-- | kabc/addressbook.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index f9e4387..fe59fcb 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -757,404 +757,422 @@ AddressBook::ConstIterator AddressBook::end() const ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.end(); return it; } void AddressBook::clear() { d->mAddressees.clear(); } Ticket *AddressBook::requestSaveTicket( Resource *resource ) { kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; if ( !resource ) { qDebug("AddressBook::requestSaveTicket no resource" ); resource = standardResource(); } KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { if ( (*it)->readOnly() || !(*it)->isOpen() ) return 0; else return (*it)->requestSaveTicket(); } } return 0; } //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) { 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 ) { if ( a.uid() == (*it).uid() ) { bool changed = false; Addressee addr = a; if ( addr != (*it) ) changed = true; if ( takeResource ) { Resource * res = (*it).resource(); (*it) = a; (*it).setResource( res ); } else { (*it) = a; if ( (*it).resource() == 0 ) (*it).setResource( standardResource() ); } if ( changed ) { if ( setRev ) { (*it).setRevision( QDateTime::currentDateTime() ); } (*it).setChanged( true ); } found = true; } 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(); int startN; if( (startN = des.find( id ) ) >= 0 ) { int endN = des.find( ",", startN+1 ); des = des.left( startN ) + des.mid( endN+1 ); (*it).setNote( des ); } } } } } if ( found ) return; d->mAddressees.append( a ); Addressee& addr = d->mAddressees.last(); if ( addr.resource() == 0 ) addr.setResource( standardResource() ); addr.setChanged( true ); } 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::removeSyncAddressees( bool removeDeleted ) { Iterator it = begin(); Iterator it2 ; QDateTime dt ( QDate( 2003,1,1) ); while ( it != end() ) { (*it).setRevision( dt ); if (( *it).IDStr() != "changed" ) { // "changed" is used for tagging changed addressees when syncing with KDE or OL (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr(":"); } 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() ); if ( removeDeleted ) { // we have no postprocessing in the resource, we have to do it here // we have to compute csum for all, because it could be the first sync (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); } ++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 , bool isSubset ) { //qDebug("AddressBook::preExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { (*it).setID( csd, (*it).externalUID() ); (*it).computeCsum( csd ); } mergeAB( aBook ,csd, isSubset ); } +void AddressBook::preOLSync( 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 ); + } + + Addressee ad; + for ( it = begin(); it != end(); ++it ) { + ad = aBook->findByExternUid( (*it).externalUID(), csd ); + if ( !ad.isEmpty() ) { + (*it).mergeOLContact( ad ); + } + } +} void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) { //qDebug("AddressBook::postExternSync "); AddressBook::Iterator it; int foundEmpty = 0; 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 || (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { Addressee ad = aBook->findByUid( ( (*it).uid() )); if ( ad.isEmpty() ) { ++foundEmpty; //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); } else { (*it).setIDStr(":"); if ( setID ) { if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) - ad.setID( csd, (*it).externalUID() ); + ad.setID( csd, (*it).externalUID() );{ + } } else ad.setID( csd, (*it).uid() ); (*it).computeCsum( csd ); ad.setCsum( csd, (*it).getCsum( csd ) ); //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); aBook->insertAddressee( ad , false); } } } if ( foundEmpty ) { qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); } } bool AddressBook::containsExternalUid( const QString& uid ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).externalUID( ) ) return true; } return false; } const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const { ConstIterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).getID( profile ) ) return (*it); } return Addressee(); } void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) { Iterator it; Addressee ad; for ( it = begin(); it != end(); ++it ) { ad = aBook->findByExternUid( (*it).externalUID(), profile ); if ( !ad.isEmpty() ) { (*it).mergeContact( ad ,isSubset); } } #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 ) { results.append( (*it).uid() ); } return results; } Addressee::List AddressBook::allAddressees() { return d->mAddressees; } Addressee::List AddressBook::findByName( const QString &name ) { Addressee::List results; Iterator it; for ( it = begin(); it != end(); ++it ) { if ( name == (*it).realName() ) { results.append( *it ); } } return results; } Addressee::List AddressBook::findByEmail( const QString &email ) { Addressee::List results; QStringList mailList; Iterator it; for ( it = begin(); it != end(); ++it ) { mailList = (*it).emails(); for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { if ( email == (*ite) ) { results.append( *it ); } } } return results; } Addressee::List AddressBook::findByCategory( const QString &category ) { Addressee::List results; Iterator it; for ( it = begin(); it != end(); ++it ) { if ( (*it).hasCategory( category) ) { results.append( *it ); } } return results; } void AddressBook::dump() const { kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; ConstIterator it; for( it = begin(); it != end(); ++it ) { (*it).dump(); } kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; } QString AddressBook::identifier() { QStringList identifier; KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( !(*it)->identifier().isEmpty() ) identifier.append( (*it)->identifier() ); } return identifier.join( ":" ); } Field::List AddressBook::fields( int category ) { if ( d->mAllFields.isEmpty() ) { d->mAllFields = Field::allFields(); } if ( category == Field::All ) return d->mAllFields; Field::List result; Field::List::ConstIterator it; for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { if ( (*it)->category() & category ) result.append( *it ); } return result; } bool AddressBook::addCustomField( const QString &label, int category, const QString &key, const QString &app ) { if ( d->mAllFields.isEmpty() ) { d->mAllFields = Field::allFields(); } //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; QString a = app.isNull() ? KGlobal::getAppName() : app; |