From afa28a62314117555d6b32291188eedd1a576284 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 19 Sep 2004 20:14:28 +0000 Subject: more AB sync --- (limited to 'kabc') diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 3a2dc5f..fda62f1 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -67,6 +67,7 @@ struct Addressee::AddresseeData : public KShared QDateTime revision; QString sortString; QString externalUID; + QString originalExternalUID; KURL url; Secrecy secrecy; Picture logo; @@ -373,6 +374,18 @@ QString Addressee::externalUID() const { return mData->externalUID; } +void Addressee::setOriginalExternalUID( const QString &id ) +{ + if ( id == mData->originalExternalUID ) return; + detach(); + mData->empty = false; + mData->originalExternalUID = id; +} + +QString Addressee::originalExternalUID() const +{ + return mData->originalExternalUID; +} void Addressee::setUid( const QString &id ) { diff --git a/kabc/addressee.h b/kabc/addressee.h index 3ba7777..8baa888 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -114,6 +114,8 @@ class Addressee bool isEmpty() const; void setExternalUID( const QString &id ); QString externalUID() const; + void setOriginalExternalUID( const QString &id ); + QString originalExternalUID() const; void mergeContact( const Addressee& ad ); /** Set unique identifier. diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro index 148da2a..c0aa960 100644 --- a/kabc/plugins/qtopia/qtopiaE.pro +++ b/kabc/plugins/qtopia/qtopiaE.pro @@ -3,7 +3,7 @@ CONFIG += qt warn_on TARGET = microkabc_qtopia -INCLUDEPATH += $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include +INCLUDEPATH += $(KDEPIMDIR) $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include OBJECTS_DIR = obj/$(PLATFORM) MOC_DIR = moc/$(PLATFORM) diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 7d00a3f..de45e63 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -32,6 +32,7 @@ $Id$ #include "qtopiaconverter.h" #include +#include //US #include @@ -75,7 +76,10 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a addr.setAdditionalName( contact.middleName() ); addr.setPrefix( contact.nameTitle() ); addr.setSuffix( contact.suffix() ); + + addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); QString exuid = contact.uid().toString(); + addr.setOriginalExternalUID( exuid ); int ente = exuid.find( "-0000"); if ( exuid.left(1) == "{" ) exuid = exuid.mid(1); @@ -251,6 +255,9 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) { + + + // name contact.setLastName(addr.familyName()); contact.setFirstName(addr.givenName()); diff --git a/kabc/plugins/qtopia/qtopiaconverter.h b/kabc/plugins/qtopia/qtopiaconverter.h index 8f4c698..012a6e2 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.h +++ b/kabc/plugins/qtopia/qtopiaconverter.h @@ -31,6 +31,7 @@ $Id$ #include "addressee.h" #include +#include class Categories; diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 48a9f22..935a1cf 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -52,6 +52,8 @@ $Id$ #include "syncprefwidget.h" #include "resourceqtopia.h" +#include +#include using namespace KABC; extern "C" @@ -189,38 +191,60 @@ bool ResourceQtopia::load() bool ResourceQtopia::save( Ticket *ticket ) { - qDebug("ResourceQtopia::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - - KABC::AddressBook::Iterator it; - bool res; - - for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { - PimContact c; - KABC::Addressee addressee = (*it); - - res = mConverter->addresseeToQtopia( *it, c ); - if (res == true) - { - mAccess->addContact(c); -// if (res == false) -// qDebug("Unable to append Contact %s", c.fullName().latin1()); + qDebug("ResourceQtopia::save: %s", fileName().latin1()); + + mDirWatch.stopScan(); + + KABC::AddressBook::Iterator it; + bool res; + + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + //KABC::Addressee addressee = (*it); + if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + QUuid uid( (*it).originalExternalUID() ); + bool ok; + PimContact c = mAccess->contactForId( uid, &ok ); + res = mConverter->addresseeToQtopia( *it, c ); + if (res == true) { + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { + mAccess->addContact(c); + KABC::Addressee addressee; + mConverter->qtopiaToAddressee( c, addressee ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + addressBook()->insertAddressee( addressee ); + + } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + if ( ok ) + mAccess->removeContact(c); + else + qDebug("Error revoe contact from qtopia "); + } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + if ( ok ) { + mAccess->updateContact(c); + KABC::Addressee addressee; + mConverter->qtopiaToAddressee( c, addressee ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + addressBook()->insertAddressee( addressee ); + } + else + qDebug("Error update contact from qtopia "); + + } + + } else { + qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); + } + } } - else - { - qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); - } - } -// mAccess->addressBookUpdated(); + // mAccess->addressBookUpdated(); - mDirWatch.startScan(); + mDirWatch.startScan(); - delete ticket; - unlock( fileName() ); + delete ticket; + unlock( fileName() ); - return true; + return true; } bool ResourceQtopia::lock( const QString &lockfileName ) -- cgit v0.9.0.2