summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-07-14 14:58:04 (UTC)
committer ulf69 <ulf69>2004-07-14 14:58:04 (UTC)
commiteff6207dd2b2cbd8624845782b24f00fd6a2b64a (patch) (unidiff)
tree4572aff369f49f1c6dd2d9d88f1016a9e85f176d
parentf2779e5e7742103ce848ab11e6b9fe3661587f0b (diff)
downloadkdepimpi-eff6207dd2b2cbd8624845782b24f00fd6a2b64a.zip
kdepimpi-eff6207dd2b2cbd8624845782b24f00fd6a2b64a.tar.gz
kdepimpi-eff6207dd2b2cbd8624845782b24f00fd6a2b64a.tar.bz2
added support for kdirwatch
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/plugins/opie/resourceopie.cpp32
1 files changed, 8 insertions, 24 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 3a40ea2..1436508 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -80,29 +80,28 @@ ResourceOpie::ResourceOpie( const KConfig *config )
80} 80}
81 81
82ResourceOpie::ResourceOpie( const QString &fileName ) 82ResourceOpie::ResourceOpie( const QString &fileName )
83 : Resource( 0 ) 83 : Resource( 0 )
84{ 84{
85// qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); 85// qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1());
86 init( fileName ); 86 init( fileName );
87} 87}
88 88
89void ResourceOpie::init( const QString &fileName ) 89void ResourceOpie::init( const QString &fileName )
90{ 90{
91 91
92/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
93 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 92 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
94 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 93 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
95 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 94 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
96*/ 95
97 //US opie addressbook is always readonly 96 //US opie addressbook is always readonly
98//US setReadOnly( true ); 97//US setReadOnly( true );
99 98
100 setFileName( fileName ); 99 setFileName( fileName );
101 100
102} 101}
103 102
104ResourceOpie::~ResourceOpie() 103ResourceOpie::~ResourceOpie()
105{ 104{
106 if (mConverter != 0) 105 if (mConverter != 0)
107 delete mConverter; 106 delete mConverter;
108} 107}
@@ -276,27 +275,24 @@ bool ResourceOpie::save( Ticket *ticket )
276 unlock( mFileName ); 275 unlock( mFileName );
277 276
278 return ok; 277 return ok;
279 278
280 qDebug("ResourceOpie::save has to be changed"); 279 qDebug("ResourceOpie::save has to be changed");
281*/ 280*/
282 return true; 281 return true;
283 282
284} 283}
285 284
286bool ResourceOpie::lock( const QString &fileName ) 285bool ResourceOpie::lock( const QString &fileName )
287{ 286{
288 qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1());
289
290/*US
291// qDebug("ResourceOpie::lock() %s", fileName.latin1()); 287// qDebug("ResourceOpie::lock() %s", fileName.latin1());
292 kdDebug(5700) << "ResourceOpie::lock()" << endl; 288 kdDebug(5700) << "ResourceOpie::lock()" << endl;
293 289
294 QString fn = fileName; 290 QString fn = fileName;
295 291
296//US change the implementation how the lockfilename is getting created 292//US change the implementation how the lockfilename is getting created
297//US fn.replace( QRegExp("/"), "_" ); 293//US fn.replace( QRegExp("/"), "_" );
298//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 294//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
299 295
300 KURL url(fn); 296 KURL url(fn);
301 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 297 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
302 298
@@ -309,97 +305,85 @@ bool ResourceOpie::lock( const QString &fileName )
309 305
310 url = lockUniqueName; 306 url = lockUniqueName;
311//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 307//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
312 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 308 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
313 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 309 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
314 310
315 // Create unique file 311 // Create unique file
316 QFile file( mLockUniqueName ); 312 QFile file( mLockUniqueName );
317 file.open( IO_WriteOnly ); 313 file.open( IO_WriteOnly );
318 file.close(); 314 file.close();
319 315
320 // Create lock file 316 // Create lock file
321 int result = ::link( QFile::encodeName( mLockUniqueName ), 317 int result = 0;
318#ifndef _WIN32_
319 result = ::link( QFile::encodeName( mLockUniqueName ),
322 QFile::encodeName( lockName ) ); 320 QFile::encodeName( lockName ) );
323 321#endif
324 if ( result == 0 ) { 322 if ( result == 0 ) {
325 addressBook()->emitAddressBookLocked(); 323 addressBook()->emitAddressBookLocked();
326 return true; 324 return true;
327 } 325 }
328 326
329 // TODO: check stat 327 // TODO: check stat
330 328
331 return false; 329 return false;
332*/
333
334 return true;
335} 330}
336 331
337void ResourceOpie::unlock( const QString &fileName ) 332void ResourceOpie::unlock( const QString &fileName )
338{ 333{
339 qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1());
340/*US
341// qDebug("ResourceOpie::unlock() %s", fileName.latin1()); 334// qDebug("ResourceOpie::unlock() %s", fileName.latin1());
342 335
343 QString fn = fileName; 336 QString fn = fileName;
344//US change the implementation how the lockfilename is getting created 337//US change the implementation how the lockfilename is getting created
345//US fn.replace( QRegExp( "/" ), "_" ); 338//US fn.replace( QRegExp( "/" ), "_" );
346//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 339//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
347//US QString lockName = fn + ".lock"; 340//US QString lockName = fn + ".lock";
348 KURL url(fn); 341 KURL url(fn);
349 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 342 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
350 343
351 QFile::remove( lockName ); 344 QFile::remove( lockName );
352 QFile::remove( mLockUniqueName ); 345 QFile::remove( mLockUniqueName );
353 addressBook()->emitAddressBookUnlocked(); 346 addressBook()->emitAddressBookUnlocked();
354*/
355} 347}
356 348
357void ResourceOpie::setFileName( const QString &fileName ) 349void ResourceOpie::setFileName( const QString &fileName )
358{ 350{
359/*US ToDo: no synchronization so far. Has to be changed in the future
360 mDirWatch.stopScan(); 351 mDirWatch.stopScan();
361 mDirWatch.removeFile( mFileName ); 352 mDirWatch.removeFile( mFileName );
362*/
363 mFileName = fileName;
364 353
354 mFileName = fileName;
365 355
366/*US ToDo: no synchronization so far. Has to be changed in the future
367 mDirWatch.addFile( mFileName ); 356 mDirWatch.addFile( mFileName );
368 mDirWatch.startScan(); 357 mDirWatch.startScan();
369*/ 358
370//US simulate KDirWatch event 359//US simulate KDirWatch event
371 fileChanged(); 360//US fileChanged();
372} 361}
373 362
374QString ResourceOpie::fileName() const 363QString ResourceOpie::fileName() const
375{ 364{
376 return mFileName; 365 return mFileName;
377} 366}
378 367
379void ResourceOpie::fileChanged() 368void ResourceOpie::fileChanged()
380{ 369{
381 // There is a small theoretical chance that KDirWatch calls us before 370 // There is a small theoretical chance that KDirWatch calls us before
382 // we are fully constructed 371 // we are fully constructed
383 if (!addressBook()) 372 if (!addressBook())
384 return; 373 return;
385 load(); 374 load();
386 addressBook()->emitAddressBookChanged(); 375 addressBook()->emitAddressBookChanged();
387} 376}
388 377
389void ResourceOpie::removeAddressee( const Addressee &addr ) 378void ResourceOpie::removeAddressee( const Addressee &addr )
390{ 379{
391/*US
392 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
393 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
394 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
395*/
396} 380}
397 381
398void ResourceOpie::cleanUp() 382void ResourceOpie::cleanUp()
399{ 383{
400// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); 384// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1());
401 385
402 unlock( mFileName ); 386 unlock( mFileName );
403} 387}
404 388
405//US #include "resourceopie.moc" 389//US #include "resourceopie.moc"