summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp32
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp25
3 files changed, 37 insertions, 23 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 64832f1..86dc7c2 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -597,16 +597,48 @@ 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 ) {
+ 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 ");
+ } 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 );
+ }
+ }
+ }
+}
+
+
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();
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index f40e015..157dc56 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -290,16 +290,19 @@ class AddressBook : public QObject
// sync stuff
//Addressee::List getExternLastSyncAddressees();
void resetTempSyncStat();
QStringList uidList();
void removeDeletedAddressees();
void mergeAB( AddressBook *aBook, const QString& profile );
Addressee findByExternUid( const QString& uid , const QString& profile );
+
+ 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.
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index b3d88de..8f3ca9b 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2923,23 +2923,17 @@ bool KABCore::syncAB(QString filename, int mode)
AddressBook abLocal(filename,"syncContact");
bool syncOK = false;
if ( abLocal.load() ) {
qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
bool external = false;
if ( filename.right(4) == ".xml") {
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
- AddressBook::Iterator it;
- for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
- (*it).setID( mCurrentSyncDevice, (*it).externalUID() );
- (*it).computeCsum( mCurrentSyncDevice );
- }
- abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice );
-
+ abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
} else {
Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
if ( ! lse.isEmpty() ) {
if ( lse.familyName().left(4) == "!E: " )
external = true;
} else {
bool found = false;
QDateTime dt( QDate( 2004,1,1));
@@ -2973,32 +2967,17 @@ bool KABCore::syncAB(QString filename, int mode)
if ( KABPrefs::instance()->mWriteBackFile )
{
if ( external && filename.right(4) != ".xml")
abLocal.removeDeletedAddressees();
qDebug("Saving remote AB ");
abLocal.saveAB();
if ( external && filename.right(4) == ".xml") {
// afterwrite processing
- AddressBook::Iterator it;
- for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
- if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
- (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
- Addressee ad = mAddressBook->findByUid( ( (*it).uid() ));
- if ( ad.isEmpty() ) {
- qDebug("ERROR ad empty ");
- } else {
- (*it).computeCsum( mCurrentSyncDevice );
- if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
- ad.setID( mCurrentSyncDevice, (*it).externalUID() );
- ad.setCsum( mCurrentSyncDevice, (*it).getCsum( mCurrentSyncDevice ) );
- mAddressBook->insertAddressee( ad );
- }
- }
- }
+ abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();