-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 32 |
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 @@ -68,53 +68,52 @@ ResourceOpie::ResourceOpie( const KConfig *config ) { QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; KConfig *cfg = (KConfig *)config; if ( cfg ) { fileName = cfg->readEntry( "FileName", fileName ); } // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); init( fileName ); } ResourceOpie::ResourceOpie( const QString &fileName ) : Resource( 0 ) { // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); init( fileName ); } void ResourceOpie::init( const QString &fileName ) { -/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); -*/ + //US opie addressbook is always readonly //US setReadOnly( true ); setFileName( fileName ); } ResourceOpie::~ResourceOpie() { if (mConverter != 0) delete mConverter; } void ResourceOpie::writeConfig( KConfig *config ) { Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceOpie::requestSaveTicket() @@ -264,142 +263,127 @@ bool ResourceOpie::save( Ticket *ticket ) info.close(); ok = true; } else { } if ( !ok ) addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); delete ticket; unlock( mFileName ); return ok; qDebug("ResourceOpie::save has to be changed"); */ return true; } bool ResourceOpie::lock( const QString &fileName ) { - qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); - -/*US // qDebug("ResourceOpie::lock() %s", fileName.latin1()); kdDebug(5700) << "ResourceOpie::lock()" << endl; 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" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) return false; QString lockUniqueName; lockUniqueName = fn + 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 = ::link( QFile::encodeName( mLockUniqueName ), + int result = 0; +#ifndef _WIN32_ + result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); - +#endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; -*/ - - return true; } void ResourceOpie::unlock( const QString &fileName ) { - qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1()); -/*US // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); 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(); -*/ } void ResourceOpie::setFileName( const QString &fileName ) { -/*US ToDo: no synchronization so far. Has to be changed in the future mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); -*/ + mFileName = fileName; - -/*US ToDo: no synchronization so far. Has to be changed in the future mDirWatch.addFile( mFileName ); mDirWatch.startScan(); -*/ + //US simulate KDirWatch event - fileChanged(); +//US fileChanged(); } QString ResourceOpie::fileName() const { return mFileName; } void ResourceOpie::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; load(); addressBook()->emitAddressBookChanged(); } void ResourceOpie::removeAddressee( const Addressee &addr ) { -/*US - QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); - QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); - QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); -*/ } void ResourceOpie::cleanUp() { // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); unlock( mFileName ); } //US #include "resourceopie.moc" |