Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 1d3acec..361b36b 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -52,4 +52,6 @@ $Id$ #include "resourcefile.h" +#include "syncwidget.h" + using namespace KABC; @@ -57,5 +59,5 @@ using namespace KABC; extern "C" #ifdef _WIN32_ -__declspec(dllexport) +__declspec(dllexport) #else { @@ -65,5 +67,5 @@ __declspec(dllexport) void *init_microkabc_file() { - return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); + return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, KRES::SyncWidget>(); } #ifndef _WIN32_ @@ -71,6 +73,6 @@ __declspec(dllexport) #endif -ResourceFile::ResourceFile( const KConfig *config ) - : Resource( config ) , mFormat( 0 ) +ResourceFile::ResourceFile( const KConfig *config, bool syncable ) + : Resource( config, syncable ) , mFormat( 0 ) { QString fileName, formatName; @@ -90,7 +92,7 @@ ResourceFile::ResourceFile( const KConfig *config ) } -ResourceFile::ResourceFile( const QString &fileName, +ResourceFile::ResourceFile( const QString &fileName, bool syncable , const QString &formatName ) - : Resource( 0 ) + : Resource( 0, syncable ) { // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); @@ -140,12 +142,12 @@ void ResourceFile::writeConfig( KConfig *config ) { - config->setGroup( "Resource_" + identifier() ); + config->setGroup( "Resource_" + identifier() ); Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); config->writeEntry( "FileFormat", mFormatName ); - + // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); - + } @@ -198,5 +200,5 @@ void ResourceFile::doClose() bool ResourceFile::load() { - + QFile file( mFileName ); @@ -207,5 +209,5 @@ bool ResourceFile::load() // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); - + return mFormat->loadAll( addressBook(), this, &file ); } @@ -214,11 +216,11 @@ bool ResourceFile::save( Ticket *ticket ) { // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); - + // 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 ); @@ -233,5 +235,5 @@ bool ResourceFile::save( Ticket *ticket ) */ -//US ToDo: write backupfile +//US ToDo: write backupfile QFile info; info.setName( mFileName ); @@ -239,18 +241,18 @@ bool ResourceFile::save( Ticket *ticket ) if ( ok ) { 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; @@ -261,5 +263,5 @@ bool ResourceFile::save( Ticket *ticket ) bool ResourceFile::lock( const QString &fileName ) { - + QString fn = fileName; @@ -268,9 +270,9 @@ bool ResourceFile::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" ); - - + + if (QFile::exists( lockName )) return false; @@ -278,6 +280,6 @@ bool ResourceFile::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() ); @@ -312,7 +314,7 @@ void ResourceFile::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 ); @@ -324,12 +326,12 @@ void ResourceFile::setFileName( const QString &fileName ) mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); - + mFileName = fileName; - + mDirWatch.addFile( mFileName ); mDirWatch.startScan(); -//US simulate KDirWatch event +//US simulate KDirWatch event //US fileChanged(); } @@ -347,5 +349,5 @@ void ResourceFile::setFormat( const QString &format ) FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); -/*US +/*US //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); if (mFormatName == "vcard") { @@ -360,5 +362,5 @@ void ResourceFile::setFormat( const QString &format ) qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); */ - + } @@ -374,6 +376,6 @@ void ResourceFile::fileChanged() if (!addressBook()) return; - - + + QString text( i18n( "File 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 ) { |