-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 95 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 6 |
3 files changed, 100 insertions, 3 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 @@ -16,64 +16,65 @@ along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> //US #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //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" #include "stdaddressbook.h" #include "sharpdtmconverter.h" //#define ALLOW_LOCKING using namespace KABC; extern "C" { void *init_microkabc_sharpdtm() { return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); } } ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) : Resource( config, syncable ), mConverter (0) { // we can not choose the filename. Therefore use the default to display QString fileName = SlZDataBase::addressbookFileName(); init( fileName ); } ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) : Resource( 0, syncable ) { init( fileName ); @@ -173,93 +174,183 @@ bool ResourceSharpDTM::load() qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); bool res = false; CardId id; for (bool res=mAccess->first(); res == true; res=mAccess->next()) { id = mAccess->cardId(); KABC::Addressee addressee; res = mConverter->sharpToAddressee( id, mAccess, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } 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) { res = mConverter->addresseeToSharp( *it, mAccess, id ); if (res == true) { res = mAccess->finishEditCard(&id); if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); } else { qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); mAccess->cancelEditCard(); } } else { 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; unlock( fileName() ); return true; } bool ResourceSharpDTM::lock( const QString &lockfileName ) { #ifdef ALLOW_LOCKING qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); 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,36 +1,36 @@ 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 LIBS += -lmicrokabc LIBS += -lmicrokdepim LIBS += -lmicroqtcompat LIBS += -lmicrokcal LIBS += -L$(QPEDIR)/lib LIBS += -ljpeg LIBS += -lqpe LIBS += -lqte LIBS += -lzdtm LIBS += -lsl INTERFACES = \ HEADERS = \ resourcesharpdtm.h \ resourcesharpdtmconfig.h \ sharpdtmconverter.h SOURCES = \ resourcesharpdtm.cpp \ resourcesharpdtmconfig.cpp \ sharpdtmconverter.cpp 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 @@ -40,64 +40,70 @@ using namespace SlCategory; SharpDTMConverter::SharpDTMConverter() : catDB(0) { } SharpDTMConverter::~SharpDTMConverter() { deinit(); } bool SharpDTMConverter::init() { catDB = new SlCategory::SlCategories(); if (!catDB) return false; // catDB->load( categoryFileName() ); return true; } void SharpDTMConverter::deinit() { if (catDB) { delete catDB; catDB = 0; } } 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) ); addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); addr.setPrefix( db->readField(ZdbAdrs::Title) ); addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); // email QString emailstr = db->readField(ZdbAdrs::Emails); qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); QStringList emails = QStringList::split(",", emailstr); for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { addr.insertEmail( *it, ((*it) == db->readField(ZdbAdrs::DefaultEmail)) ); } if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); // home if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || (!db->readField(ZdbAdrs::HomeState).isEmpty()) || (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) { Address homeaddress; homeaddress.setType(Address::Home); |