-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 90 |
1 files changed, 46 insertions, 44 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 347d51c..31b99ca 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -46,13 +46,13 @@ $Id$ #include <sl/slzdb.h> #include "resourcesharpdtmconfig.h" -#include "stdaddressbook.h" +#include "resourcesharpdtm.h" -//#include "qtopiaconverter.h" +#include "stdaddressbook.h" -#include "resourcesharpdtm.h" +#include "sharpdtmconverter.h" using namespace KABC; extern "C" { @@ -66,9 +66,9 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) : Resource( config ), mConverter (0) { // we can not choose the filename. Therefore use the default to display - QString fileName = SlZDataBase::addressbookFileName(); + QString fileName = SlZDataBase::addressbookFileName(); init( fileName ); } ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) @@ -137,15 +137,15 @@ bool ResourceSharpDTM::doOpen() } //US bool ok = mFormat->checkFormat( &file ); bool ok = true; - + file.close(); return ok; } */ - return true; + return true; } void ResourceSharpDTM::doClose() { @@ -155,51 +155,53 @@ bool ResourceSharpDTM::load() { kdDebug(5700) << "ResourcSharpDTM::load(): '" << mFileName << "'" << endl; // qDebug("ResourceSharpDTM::load: Try to load file() %s", mFileName.latin1()); - + + // the last parameter in the SlZDataBase constructor means "readonly" SlZDataBase* access = new SlZDataBase(mFileName, - SlZDataBase::addressbookItems()); + SlZDataBase::addressbookItems(), + NULL, true); if ( !access ) { qDebug("Unable to load file() %s", mFileName.latin1()); addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); return false; } - + bool res = false; if (mConverter == 0) { -// mConverter = new QtopiaConverter(); -// res = mConverter->init(); - res = true; + mConverter = new SharpDTMConverter(); + res = mConverter->init(); if ( !res ) { - qDebug("Unable to initialize qtopia converter. Most likely a problem with the category file"); - addressBook()->error( i18n( "Unable to initialize qtopia converter. Most likely a problem with the category file" ) ); + QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); + + qDebug(msg); + addressBook()->error( i18n( msg ) ); delete access; return false; } } - /* - { //create a new scope - AddressBookIterator it(*access); - const PimContact* contact; - - for (contact=it.toFirst(); it.current(); ++it) { - contact = it.current(); - + + { //create a new scope + CardId id; + + for (bool res=access->first(); res == true; res=access->next()) { + id = access->cardId(); + KABC::Addressee addressee; - - res = mConverter->qtopiaToAddressee( (*contact), addressee ); - + + res = mConverter->sharpToAddressee( id, access, addressee ); + if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } } -*/ + delete access; return true; } @@ -210,11 +212,11 @@ bool ResourceSharpDTM::save( Ticket *ticket ) kdDebug(5700) << "ResourceQtopia::save()" << endl; // create backup file QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); - + /*US we use a simpler method to create a backupfile - + (void) KSaveFile::backupFile( mFileName, QString::null ,extension ); KSaveFile saveFile( mFileName ); @@ -226,32 +228,32 @@ bool ResourceSharpDTM::save( Ticket *ticket ) } */ /*US -//US ToDo: write backupfile +//US ToDo: write backupfile QFile info; info.setName( mFileName ); bool ok = info.open( IO_WriteOnly ); if ( ok ) { //US mFormat->saveAll( addressBook(), this, &info ); - + info.close(); ok = true; } else { - + } - + if ( !ok ) addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); - + delete ticket; unlock( mFileName ); - + return ok; qDebug("ResourceQtopia::save has to be changed"); -*/ +*/ return true; } bool ResourceSharpDTM::lock( const QString &fileName ) @@ -262,20 +264,20 @@ bool ResourceSharpDTM::lock( const QString &fileName ) //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp("/"), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); - - KURL url(fn); + + KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); - + kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) return false; QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); - - url = lockUniqueName; + + url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; @@ -304,11 +306,11 @@ void ResourceSharpDTM::unlock( const QString &fileName ) //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp( "/" ), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); //US QString lockName = fn + ".lock"; - KURL url(fn); + KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); - + QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } @@ -316,9 +318,9 @@ void ResourceSharpDTM::unlock( const QString &fileName ) void ResourceSharpDTM::setFileName( const QString &fileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); - + mFileName = fileName; mDirWatch.addFile( mFileName ); mDirWatch.startScan(); @@ -335,9 +337,9 @@ void ResourceSharpDTM::fileChanged() // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; - + QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); |