summaryrefslogtreecommitdiffabout
path: root/kabc
Side-by-side diff
Diffstat (limited to 'kabc') (more/less context) (show whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp93
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmE.pro2
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmconverter.cpp6
3 files changed, 99 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
@@ -42,12 +42,13 @@ $Id$
//US #include <ksavefile.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include <sl/slzdb.h>
+#include <libkdepim/ksyncprofile.h>
#include "resourcesharpdtmconfig.h"
#include "resourcesharpdtm.h"
#include "syncprefwidget.h"
@@ -199,14 +200,101 @@ bool ResourceSharpDTM::save( Ticket *ticket )
qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
mDirWatch.stopScan();
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);
res = mAccess->startEditCard(id);
if (res == true)
{
@@ -224,15 +312,18 @@ bool ResourceSharpDTM::save( Ticket *ticket )
}
}
else
{
qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1());
}
+#endif
}
-
+ KABC::Addressee::List::Iterator it2;
+ for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
+ addressBook()->insertAddressee((*it2));
//US mAccess->save();
mDirWatch.startScan();
delete ticket;
unlock( fileName() );
diff --git a/kabc/plugins/sharpdtm/sharpdtmE.pro b/kabc/plugins/sharpdtm/sharpdtmE.pro
index f335729..b80a1da 100644
--- a/kabc/plugins/sharpdtm/sharpdtmE.pro
+++ b/kabc/plugins/sharpdtm/sharpdtmE.pro
@@ -1,11 +1,11 @@
TEMPLATE = lib
CONFIG += qt warn_on
TARGET = microkabc_sharpdtm
-INCLUDEPATH += $(KDEPIMDIR)/kabc $(SHARPDTMSDK)/include $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include
+INCLUDEPATH += $(KDEPIMDIR) $(KDEPIMDIR)/kabc $(SHARPDTMSDK)/include $(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)
DESTDIR = $(QPEDIR)/lib
LIBS += -lmicrokde
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
index 8f8334e..b065bf3 100644
--- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
+++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
@@ -66,12 +66,18 @@ void SharpDTMConverter::deinit()
}
}
bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr )
{
SlZDataBase* db = (SlZDataBase*)database;
+
+ // for syncing: we need setting of the two fields
+ addr.setExternalUID( QString::number( contact ) );
+ addr.setOriginalExternalUID( QString::number( contact ) );
+
+
// name
qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!");
addr.setFormattedName(db->readField(ZdbAdrs::FileAs));
addr.setFamilyName( db->readField(ZdbAdrs::LastName) );
addr.setGivenName( db->readField(ZdbAdrs::FirstName) );