Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index dc5932f..4ab7f02 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -50,17 +50,16 @@ $Id$ #include "resourcefileconfig.h" #include "stdaddressbook.h" #define NO_DIRWATCH #include "resourcefile.h" //#define ALLOW_LOCKING - using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif @@ -93,16 +92,19 @@ ResourceFile::ResourceFile( const KConfig *config ) init( fileName, formatName ); } ResourceFile::ResourceFile( const QString &fileName , const QString &formatName ) : Resource( 0 ) { // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); + + + init( fileName, formatName ); } void ResourceFile::init( const QString &fileName, const QString &formatName ) { mFormatName = formatName; FormatFactory *factory = FormatFactory::self(); @@ -113,32 +115,47 @@ void ResourceFile::init( const QString &fileName, const QString &formatName ) mFormat = factory->format( mFormatName ); } #ifndef NO_DIRWATCH connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); #endif + + + QString localKdeDir; + localKdeDir = readEnvPath("LOCALMICROKDEHOME"); + if ( ! localKdeDir.isEmpty() ) { + qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() ); + + + + + } + qDebug("RESOURCE: %s ", fileName.latin1()); + + + setFileName( fileName ); } ResourceFile::~ResourceFile() { delete mFormat; mFormat = 0; } void ResourceFile::writeConfig( KConfig *config ) { config->setGroup( "Resource_" + identifier() ); Resource::writeConfig( config ); - config->writeEntry( "FileName", mFileName ); + config->writeEntry( "FileName", fileName() ); config->writeEntry( "FileFormat", mFormatName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceFile::requestSaveTicket() { @@ -153,18 +170,18 @@ Ticket *ResourceFile::requestSaveTicket() } #endif return createTicket( this ); } bool ResourceFile::doOpen() { - QFile file( mFileName ); - qDebug("ResourceFile::openfile %s ", mFileName.latin1()); + QFile file( fileName() ); + qDebug("ResourceFile::openfile %s ", fileName().latin1()); if ( !file.exists() ) { // try to create the file bool ok = file.open( IO_WriteOnly ); if ( ok ) file.close(); return ok; @@ -186,19 +203,19 @@ bool ResourceFile::doOpen() void ResourceFile::doClose() { } bool ResourceFile::load() { - QFile file( mFileName ); + QFile file( fileName() ); if ( !file.open( IO_ReadOnly ) ) { - addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); + addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) ); return false; } // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); return mFormat->loadAll( addressBook(), this, &file ); } @@ -224,30 +241,30 @@ bool ResourceFile::save( Ticket *ticket ) } */ //US ToDo: write backupfile #ifndef NO_DIRWATCH mDirWatch.stopScan(); #endif QFile info; - info.setName( mFileName ); + info.setName( fileName() ); bool ok = info.open( IO_WriteOnly ); if ( ok ) { mFormat->saveAll( addressBook(), this, &info ); info.close(); ok = true; } else { } if ( !ok ) - addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); + addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) ); #ifndef NO_DIRWATCH mDirWatch.startScan(); #endif delete ticket; #ifdef ALLOW_LOCKING unlock( mFileName ); #endif @@ -329,26 +346,26 @@ void ResourceFile::setFileName( const QString &fileName ) mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); mFileName = fileName; mDirWatch.addFile( mFileName ); mDirWatch.startScan(); #else - mFileName = fileName; + mFileName2 = fileName; #endif //US simulate KDirWatch event //US fileChanged(); } QString ResourceFile::fileName() const { - return mFileName; + return mFileName2; } void ResourceFile::setFormat( const QString &format ) { mFormatName = format; delete mFormat; FormatFactory *factory = FormatFactory::self(); @@ -377,28 +394,28 @@ QString ResourceFile::format() const void ResourceFile::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; - QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); + QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceFile::removeAddressee( const Addressee &addr ) { 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 ResourceFile::cleanUp() { - unlock( mFileName ); + unlock( fileName() ); } //US #include "resourcefile.moc" |