summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file/resourcefile.cpp
Side-by-side diff
Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefile.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index fa6bc49..17263ae 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -44,24 +44,25 @@ $Id$
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include "formatfactory.h"
#include "resource.h"
#include "resourcefileconfig.h"
#include "stdaddressbook.h"
#include "resourcefile.h"
#include "syncprefwidget.h"
+//#define ALLOW_LOCKING
using namespace KABC;
extern "C"
#ifdef _WIN32_
__declspec(dllexport)
#else
{
#endif
//US void *init_kabc_file()
void *init_microkabc_file()
@@ -138,29 +139,30 @@ void ResourceFile::writeConfig( KConfig *config )
config->writeEntry( "FileFormat", mFormatName );
// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
}
Ticket *ResourceFile::requestSaveTicket()
{
kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
if ( !addressBook() ) return 0;
+#ifdef ALLOW_LOCKING
if ( !lock( mFileName ) ) {
- kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '"
- << mFileName << "'" << endl;
+ qDebug("unablt to lock file ");
return 0;
}
+#endif
return createTicket( this );
}
bool ResourceFile::doOpen()
{
QFile file( mFileName );
if ( !file.exists() ) {
// try to create the file
bool ok = file.open( IO_WriteOnly );
if ( ok )
@@ -237,31 +239,34 @@ bool ResourceFile::save( Ticket *ticket )
ok = true;
}
else {
}
if ( !ok )
addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
mDirWatch.startScan();
delete ticket;
+#ifdef ALLOW_LOCKING
unlock( mFileName );
+#endif
return ok;
}
bool ResourceFile::lock( const QString &fileName )
{
+#ifdef ALLOW_LOCKING
QString fn = 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);
QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
@@ -286,39 +291,46 @@ bool ResourceFile::lock( const QString &fileName )
#ifndef _WIN32_
result = ::link( QFile::encodeName( mLockUniqueName ),
QFile::encodeName( lockName ) );
#endif
if ( result == 0 ) {
addressBook()->emitAddressBookLocked();
return true;
}
// TODO: check stat
return false;
+#else
+ return true;
+#endif
}
void ResourceFile::unlock( const QString &fileName )
{
+#ifdef ALLOW_LOCKING
QString fn = 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);
QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
QFile::remove( lockName );
QFile::remove( mLockUniqueName );
addressBook()->emitAddressBookUnlocked();
+#else
+ return;
+#endif
}
void ResourceFile::setFileName( const QString &fileName )
{
mDirWatch.stopScan();
mDirWatch.removeFile( mFileName );
mFileName = fileName;
mDirWatch.addFile( mFileName );
mDirWatch.startScan();