-rw-r--r-- | kabc/addressbook.cpp | 133 |
1 files changed, 97 insertions, 36 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16e1653..ec9f893 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -231,12 +231,13 @@ AddressBook::AddressBook( const QString &config, const QString &family ) } // the default family is "contact" void AddressBook::init(const QString &config, const QString &family ) { + blockLSEchange = false; d = new AddressBookData; QString fami = family; qDebug("new ab "); if (config != 0) { qDebug("config != 0 "); if ( family == "syncContact" ) { @@ -342,12 +343,13 @@ bool AddressBook::load() // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) (*addrIt).setChanged( false ); + blockLSEchange = true; return ok; } bool AddressBook::save( Ticket *ticket ) { kdDebug(5700) << "AddressBook::save()"<< endl; @@ -444,59 +446,116 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) return 0; } void AddressBook::insertAddressee( const Addressee &a, bool setRev ) { - Addressee::List::Iterator it; - for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { - if ( a.uid() == (*it).uid() ) { - if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { - return; - } - bool changed = false; - Addressee addr = a; - if ( addr != (*it) ) - changed = true; - - (*it) = a; - if ( (*it).resource() == 0 ) - (*it).setResource( standardResource() ); - - if ( changed ) { - if ( setRev ) { + if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { + return; + } + 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; + + (*it) = a; + if ( (*it).resource() == 0 ) + (*it).setResource( standardResource() ); + + if ( changed ) { + if ( setRev ) { - // get rid of micro seconds - QDateTime dt = QDateTime::currentDateTime(); - QTime t = dt.time(); - dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); - (*it).setRevision( dt ); - } - (*it).setChanged( true ); - } - - return; + // get rid of micro seconds + QDateTime dt = QDateTime::currentDateTime(); + QTime t = dt.time(); + dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); + (*it).setRevision( dt ); + } + (*it).setChanged( true ); + } + + found = true; + } else { + if ( (*it).uid() == 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 ); + } + } + } + } } - } - d->mAddressees.append( a ); - Addressee& addr = d->mAddressees.last(); - if ( addr.resource() == 0 ) - addr.setResource( standardResource() ); + if ( found ) + return; + d->mAddressees.append( a ); + Addressee& addr = d->mAddressees.last(); + if ( addr.resource() == 0 ) + addr.setResource( standardResource() ); - addr.setChanged( true ); + 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() ) { - removeAddressee( it ); - return; + found = true; + it2 = it; + } else { + if ( (*it).uid() == 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() +{ + deleteRemovedAddressees(); + Iterator it = begin(); + Iterator it2 ; + QDateTime dt ( QDate( 2004,1,1) ); + while ( it != end() ) { + (*it).setRevision( dt ); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + it2 = it; + ++it; + removeAddressee( it2 ); + } else + ++it; + } + deleteRemovedAddressees(); } void AddressBook::removeAddressee( const Iterator &it ) { d->mRemovedAddressees.append( (*it) ); d->mAddressees.remove( it.d->mIt ); @@ -520,26 +579,28 @@ Addressee AddressBook::findByUid( const QString &uid ) if ( uid == (*it).uid() ) { return *it; } } return Addressee(); } +#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(3) == "E: " ) + 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 ); } |