From f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 18 Sep 2004 22:33:39 +0000 Subject: more AB sync --- (limited to 'kabc/addressbook.cpp') diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16e1653..ec9f893 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -234,6 +234,7 @@ 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 "); @@ -345,6 +346,7 @@ bool AddressBook::load() for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) (*addrIt).setChanged( false ); + blockLSEchange = true; return ok; } @@ -447,53 +449,110 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) 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 ) @@ -523,6 +582,7 @@ Addressee AddressBook::findByUid( const QString &uid ) } return Addressee(); } +#if 0 Addressee::List AddressBook::getExternLastSyncAddressees() { Addressee::List results; @@ -530,13 +590,14 @@ Addressee::List AddressBook::getExternLastSyncAddressees() 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; -- cgit v0.9.0.2