Diffstat (limited to 'kabc/plugins/dir/resourcedir.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index fac06a1..7d96cb7 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp @@ -54,16 +54,18 @@ $Id$ #include "stdaddressbook.h" //US #include <qdir.h> #include "resourcedir.h" #include "syncprefwidget.h" +//#define ALLOW_LOCKING + using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif @@ -131,26 +133,27 @@ void ResourceDir::writeConfig( KConfig *config ) Resource::writeConfig( config ); config->writeEntry( "FilePath", mPath ); config->writeEntry( "FileFormat", mFormatName ); } Ticket *ResourceDir::requestSaveTicket() { - kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; + if ( !addressBook() ) return 0; - +#ifdef ALLOW_LOCKING if ( !lock( mPath ) ) { - kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" - << mPath << "'" << endl; + return 0; } +#endif return createTicket( this ); + } bool ResourceDir::doOpen() { QDir dir( mPath ); if ( !dir.exists() ) { // no directory available return dir.mkdir( dir.path() ); @@ -173,18 +176,16 @@ bool ResourceDir::doOpen() } void ResourceDir::doClose() { } bool ResourceDir::load() { - kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; - QDir dir( mPath ); QStringList files = dir.entryList( QDir::Files ); QStringList::Iterator it; bool ok = true; for ( it = files.begin(); it != files.end(); ++it ) { QFile file( mPath + "/" + (*it) ); @@ -200,18 +201,16 @@ bool ResourceDir::load() file.close(); } return ok; } bool ResourceDir::save( Ticket *ticket ) { - kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; - AddressBook::Iterator it; bool ok = true; mDirWatch.stopScan(); for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { if ( (*it).resource() != this || !(*it).changed() ) continue; @@ -227,46 +226,42 @@ bool ResourceDir::save( Ticket *ticket ) // mark as unchanged (*it).setChanged( false ); file.close(); } mDirWatch.startScan(); delete ticket; +#ifdef ALLOW_LOCKING unlock( mPath ); - +#endif return ok; } bool ResourceDir::lock( const QString &path ) { - kdDebug(5700) << "ResourceDir::lock()" << endl; - +#ifdef ALLOW_LOCKING QString p = path; //US change the implementation how the lockfilename is getting created //US p.replace( QRegExp("/"), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); KURL url(p); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); - kdDebug(5700) << "-- lock name: " << lockName << endl; - if ( QFile::exists( lockName ) ) return false; QString lockUniqueName; lockUniqueName = p + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); - kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; - // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ @@ -276,30 +271,37 @@ bool ResourceDir::lock( const QString &path ) if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; +#else + return true; +#endif } void ResourceDir::unlock( const QString &path ) { +#ifdef ALLOW_LOCKING QString p = path; //US change the implementation how the lockfilename is getting created //US p.replace( QRegExp( "/" ), "_" ); //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); KURL url(p); QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); ::unlink( QFile::encodeName( lockName ) ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); +#else + return; +#endif } void ResourceDir::setPath( const QString &path ) { mDirWatch.stopScan(); mDirWatch.removeDir( mPath ); mPath = path; |