author | zautrix <zautrix> | 2004-09-20 18:59:02 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-20 18:59:02 (UTC) |
commit | 138be6cfa921cd8a07fa0b18046d955e7d2dbd6e (patch) (side-by-side diff) | |
tree | 67b8b69e26641f4f048ce19e05b361f5aea6db85 /kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |
parent | 6b6a28919908134ccbb3badcb24c2dcae0d426a5 (diff) | |
download | kdepimpi-138be6cfa921cd8a07fa0b18046d955e7d2dbd6e.zip kdepimpi-138be6cfa921cd8a07fa0b18046d955e7d2dbd6e.tar.gz kdepimpi-138be6cfa921cd8a07fa0b18046d955e7d2dbd6e.tar.bz2 |
more DTM sync
Diffstat (limited to 'kabc/plugins/sharpdtm/resourcesharpdtm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 867bc07..bba5f9a 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -45,6 +45,7 @@ $Id$ #include <sl/slzdb.h> +#include <libkdepim/ksyncprofile.h> #include "resourcesharpdtmconfig.h" #include "resourcesharpdtm.h" @@ -202,8 +203,95 @@ bool ResourceSharpDTM::save( Ticket *ticket ) KABC::AddressBook::Iterator it; bool res; + KABC::Addressee::List changedAddressees; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + + if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + QString uid = (*it).originalExternalUID(); + CardId id ; + bool res; + if ( uid.isEmpty() ) + id = 0; + else + id = uid.toUInt(); + KABC::Addressee addressee = (*it); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { + res = mAccess->startEditCard(id); + if (res == true) + { + res = mConverter->addresseeToSharp( (*it), mAccess, id ); + if (res == true) + { + KABC::Addressee addressee; + qDebug("1NEW id is %d", id); + res = mConverter->sharpToAddressee( id, mAccess, addressee ); + addressee.setUid((*it).uid() ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + changedAddressees.append( addressee ); + res = mAccess->finishEditCard(&id); + qDebug("2NEW id is %d", id); + + if (res == false) + qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); + else { + qDebug("added card success "); + } + } + else + { + qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); + mAccess->cancelEditCard(); + } + } + + } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + res = mAccess->deleteCard(&id); + if ( res ) + qDebug("delete success "); + else + qDebug("delete error "); + + + } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + //changed + res = mAccess->startEditCard(id); + if (res == true) + { + res = mConverter->addresseeToSharp( (*it), mAccess, id ); + if (res == true) + { + KABC::Addressee addressee; + res = mConverter->sharpToAddressee( id, mAccess, addressee ); + addressee.setUid((*it).uid() ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + changedAddressees.append( addressee ); + res = mAccess->finishEditCard(&id); + if (res == false) + qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); + else { + qDebug("change card succes "); + } + } + else + { + qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); + mAccess->cancelEditCard(); + } + } + } + + + + + + + + + } + +#if 0 + // old code CardId id = 0; // 0 means new card KABC::Addressee addressee = (*it); @@ -227,10 +315,13 @@ bool ResourceSharpDTM::save( Ticket *ticket ) { qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); } +#endif } - -//US mAccess->save(); + KABC::Addressee::List::Iterator it2; + for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) + addressBook()->insertAddressee((*it2)); + //US mAccess->save(); mDirWatch.startScan(); delete ticket; |