summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
authorzautrix <zautrix>2004-09-18 22:33:39 (UTC)
committer zautrix <zautrix>2004-09-18 22:33:39 (UTC)
commitf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (patch) (side-by-side diff)
treec1a9de8b305200a7cec885764a0afb4beb92dabb /kabc/addressbook.cpp
parent28f894fd2a0dfbd5f09f9e530f359981efe0198c (diff)
downloadkdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.zip
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.gz
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.bz2
more AB sync
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp133
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
@@ -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;