-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 @@ -48,9 +48,9 @@ $Id$ #include "resourcesharpdtmconfig.h" -#include "stdaddressbook.h" +#include "resourcesharpdtm.h" -//#include "qtopiaconverter.h" +#include "stdaddressbook.h" -#include "resourcesharpdtm.h" +#include "sharpdtmconverter.h" using namespace KABC; @@ -68,5 +68,5 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) // we can not choose the filename. Therefore use the default to display - QString fileName = SlZDataBase::addressbookFileName(); + QString fileName = SlZDataBase::addressbookFileName(); init( fileName ); } @@ -139,5 +139,5 @@ bool ResourceSharpDTM::doOpen() //US bool ok = mFormat->checkFormat( &file ); bool ok = true; - + file.close(); @@ -145,5 +145,5 @@ bool ResourceSharpDTM::doOpen() } */ - return true; + return true; } @@ -157,7 +157,9 @@ bool ResourceSharpDTM::load() // 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()); @@ -165,31 +167,31 @@ bool ResourceSharpDTM::load() 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 ) { @@ -199,5 +201,5 @@ bool ResourceSharpDTM::load() } } -*/ + delete access; return true; @@ -212,7 +214,7 @@ bool ResourceSharpDTM::save( Ticket *ticket ) // 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 ); @@ -228,5 +230,5 @@ bool ResourceSharpDTM::save( Ticket *ticket ) /*US -//US ToDo: write backupfile +//US ToDo: write backupfile QFile info; info.setName( mFileName ); @@ -234,22 +236,22 @@ bool ResourceSharpDTM::save( Ticket *ticket ) 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; } @@ -264,8 +266,8 @@ bool ResourceSharpDTM::lock( const QString &fileName ) //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; @@ -274,6 +276,6 @@ bool ResourceSharpDTM::lock( const QString &fileName ) 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() ); @@ -306,7 +308,7 @@ void ResourceSharpDTM::unlock( const QString &fileName ) //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 ); @@ -318,5 +320,5 @@ void ResourceSharpDTM::setFileName( const QString &fileName ) mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); - + mFileName = fileName; @@ -337,5 +339,5 @@ void ResourceSharpDTM::fileChanged() 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 ) { |