Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 16 |
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 | |||
@@ -50,12 +50,13 @@ $Id$ | |||
50 | #include "resourcefileconfig.h" | 50 | #include "resourcefileconfig.h" |
51 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
52 | 52 | ||
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | //#define ALLOW_LOCKING | ||
56 | 57 | ||
57 | using namespace KABC; | 58 | using namespace KABC; |
58 | 59 | ||
59 | extern "C" | 60 | extern "C" |
60 | #ifdef _WIN32_ | 61 | #ifdef _WIN32_ |
61 | __declspec(dllexport) | 62 | __declspec(dllexport) |
@@ -144,17 +145,18 @@ void ResourceFile::writeConfig( KConfig *config ) | |||
144 | Ticket *ResourceFile::requestSaveTicket() | 145 | Ticket *ResourceFile::requestSaveTicket() |
145 | { | 146 | { |
146 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 147 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
147 | 148 | ||
148 | if ( !addressBook() ) return 0; | 149 | if ( !addressBook() ) return 0; |
149 | 150 | ||
151 | #ifdef ALLOW_LOCKING | ||
150 | if ( !lock( mFileName ) ) { | 152 | if ( !lock( mFileName ) ) { |
151 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 153 | qDebug("unablt to lock file "); |
152 | << mFileName << "'" << endl; | ||
153 | return 0; | 154 | return 0; |
154 | } | 155 | } |
156 | #endif | ||
155 | return createTicket( this ); | 157 | return createTicket( this ); |
156 | } | 158 | } |
157 | 159 | ||
158 | 160 | ||
159 | bool ResourceFile::doOpen() | 161 | bool ResourceFile::doOpen() |
160 | { | 162 | { |
@@ -243,19 +245,22 @@ bool ResourceFile::save( Ticket *ticket ) | |||
243 | if ( !ok ) | 245 | if ( !ok ) |
244 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 246 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
245 | 247 | ||
246 | mDirWatch.startScan(); | 248 | mDirWatch.startScan(); |
247 | 249 | ||
248 | delete ticket; | 250 | delete ticket; |
251 | #ifdef ALLOW_LOCKING | ||
249 | unlock( mFileName ); | 252 | unlock( mFileName ); |
253 | #endif | ||
250 | 254 | ||
251 | return ok; | 255 | return ok; |
252 | } | 256 | } |
253 | 257 | ||
254 | bool ResourceFile::lock( const QString &fileName ) | 258 | bool ResourceFile::lock( const QString &fileName ) |
255 | { | 259 | { |
260 | #ifdef ALLOW_LOCKING | ||
256 | 261 | ||
257 | 262 | ||
258 | QString fn = fileName; | 263 | QString fn = fileName; |
259 | 264 | ||
260 | //US change the implementation how the lockfilename is getting created | 265 | //US change the implementation how the lockfilename is getting created |
261 | //US fn.replace( QRegExp("/"), "_" ); | 266 | //US fn.replace( QRegExp("/"), "_" ); |
@@ -292,27 +297,34 @@ bool ResourceFile::lock( const QString &fileName ) | |||
292 | return true; | 297 | return true; |
293 | } | 298 | } |
294 | 299 | ||
295 | // TODO: check stat | 300 | // TODO: check stat |
296 | 301 | ||
297 | return false; | 302 | return false; |
303 | #else | ||
304 | return true; | ||
305 | #endif | ||
298 | } | 306 | } |
299 | 307 | ||
300 | void ResourceFile::unlock( const QString &fileName ) | 308 | void ResourceFile::unlock( const QString &fileName ) |
301 | { | 309 | { |
310 | #ifdef ALLOW_LOCKING | ||
302 | QString fn = fileName; | 311 | QString fn = fileName; |
303 | //US change the implementation how the lockfilename is getting created | 312 | //US change the implementation how the lockfilename is getting created |
304 | //US fn.replace( QRegExp( "/" ), "_" ); | 313 | //US fn.replace( QRegExp( "/" ), "_" ); |
305 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
306 | //US QString lockName = fn + ".lock"; | 315 | //US QString lockName = fn + ".lock"; |
307 | KURL url(fn); | 316 | KURL url(fn); |
308 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
309 | 318 | ||
310 | QFile::remove( lockName ); | 319 | QFile::remove( lockName ); |
311 | QFile::remove( mLockUniqueName ); | 320 | QFile::remove( mLockUniqueName ); |
312 | addressBook()->emitAddressBookUnlocked(); | 321 | addressBook()->emitAddressBookUnlocked(); |
322 | #else | ||
323 | return; | ||
324 | #endif | ||
313 | } | 325 | } |
314 | 326 | ||
315 | void ResourceFile::setFileName( const QString &fileName ) | 327 | void ResourceFile::setFileName( const QString &fileName ) |
316 | { | 328 | { |
317 | mDirWatch.stopScan(); | 329 | mDirWatch.stopScan(); |
318 | mDirWatch.removeFile( mFileName ); | 330 | mDirWatch.removeFile( mFileName ); |