summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/opie/resourceopie.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/opie/resourceopie.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kabc/plugins/opie/resourceopie.cpp39
1 files changed, 6 insertions, 33 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 5559827..9dfd473 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -78,24 +78,25 @@ ResourceOpie::ResourceOpie( const KConfig *config, bool syncable )
78 78
79 init( fileName ); 79 init( fileName );
80} 80}
81 81
82ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) 82ResourceOpie::ResourceOpie( const QString &fileName, bool syncable )
83 : Resource( 0, syncable ) 83 : Resource( 0, syncable )
84{ 84{
85 init( fileName ); 85 init( fileName );
86} 86}
87 87
88void ResourceOpie::init( const QString &fileName ) 88void ResourceOpie::init( const QString &fileName )
89{ 89{
90 qDebug("ResourceOpie::init()");
90 91
91 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 92 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
92 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 93 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
93 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 94 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
94 95
95 setFileName( fileName ); 96 setFileName( fileName );
96} 97}
97 98
98ResourceOpie::~ResourceOpie() 99ResourceOpie::~ResourceOpie()
99{ 100{
100 if (mConverter != 0) 101 if (mConverter != 0)
101 delete mConverter; 102 delete mConverter;
@@ -245,25 +246,29 @@ bool ResourceOpie::lock( const QString &lockfileName )
245{ 246{
246 qDebug("ResourceOpie::lock: %s", fileName().latin1()); 247 qDebug("ResourceOpie::lock: %s", fileName().latin1());
247 248
248 kdDebug(5700) << "ResourceOpie::lock()" << endl; 249 kdDebug(5700) << "ResourceOpie::lock()" << endl;
249 250
250 QString fn = lockfileName; 251 QString fn = lockfileName;
251 252
252 KURL url(fn); 253 KURL url(fn);
253 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 254 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
254 255
255 kdDebug(5700) << "-- lock name: " << lockName << endl; 256 kdDebug(5700) << "-- lock name: " << lockName << endl;
256 257
257 if (QFile::exists( lockName )) return false; 258 if (QFile::exists( lockName ))
259 {
260 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
261 return false;
262 }
258 263
259 QString lockUniqueName; 264 QString lockUniqueName;
260 lockUniqueName = fn + KApplication::randomString( 8 ); 265 lockUniqueName = fn + KApplication::randomString( 8 );
261 266
262 url = lockUniqueName; 267 url = lockUniqueName;
263//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 268//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
264 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 269 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
265 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 270 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
266 271
267 // Create unique file 272 // Create unique file
268 QFile file( mLockUniqueName ); 273 QFile file( mLockUniqueName );
269 file.open( IO_WriteOnly ); 274 file.open( IO_WriteOnly );
@@ -331,45 +336,13 @@ void ResourceOpie::fileChanged()
331void ResourceOpie::removeAddressee( const Addressee &addr ) 336void ResourceOpie::removeAddressee( const Addressee &addr )
332{ 337{
333} 338}
334 339
335void ResourceOpie::cleanUp() 340void ResourceOpie::cleanUp()
336{ 341{
337// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); 342// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1());
338 343
339 unlock( fileName() ); 344 unlock( fileName() );
340} 345}
341 346
342 347
343/**
344 * This method returns the number of elements that are currently in the resource.
345 */
346int ResourceOpie::count() const
347{
348 qDebug("ResourceOpie::count: %x", mAccess);
349
350 if (mAccess != 0)
351 {
352 OContactAccess::List contactList = mAccess->allRecords();
353 return contactList.count();
354 }
355 else
356 return 0;
357}
358
359
360/**
361 * This method removes all elements from the resource!! (Not from the addressbook)
362 */
363bool ResourceOpie::clear()
364{
365 if (mAccess != 0) {
366 mAccess->clear();
367 return true;
368 }
369 else
370 return false;
371}
372
373
374
375//US #include "resourceopie.moc" 348//US #include "resourceopie.moc"