author | zautrix <zautrix> | 2004-09-15 10:22:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-15 10:22:55 (UTC) |
commit | d4adafe41cf399585b8e35cb600ff35706d55ae0 (patch) (side-by-side diff) | |
tree | 1becc87f6c40390fd73082996d18f71fb5e9c772 /kabc | |
parent | 8889ffd6f6958c3a1d07bafedcc8af5d786a1660 (diff) | |
download | kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.zip kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.tar.gz kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.tar.bz2 |
fixes for desktop version
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 17 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.h | 3 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 20 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 3 |
4 files changed, 28 insertions, 15 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 7d96cb7..e58e4f7 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp @@ -47,24 +47,25 @@ $Id$ #include <kmessagebox.h> #include "addressbook.h" #include "formatfactory.h" #include "resourcedirconfig.h" #include "stdaddressbook.h" //US #include <qdir.h> +#define NO_DIRWATCH #include "resourcedir.h" #include "syncprefwidget.h" //#define ALLOW_LOCKING using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { @@ -104,29 +105,29 @@ ResourceDir::ResourceDir( const KConfig *config, bool syncable ) mFormat = factory->format( mFormatName ); } /*US //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); if (mFormatName == "vcard") mFormat = new VCardFormatPlugin2(); else if (mFormatName == "binary") mFormat = new BinaryFormat(); else qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); */ - +#ifndef NO_DIRWATCH connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); - +#endif setPath( path ); } ResourceDir::~ResourceDir() { delete mFormat; mFormat = 0; } void ResourceDir::writeConfig( KConfig *config ) { config->setGroup( "Resource_" + identifier() ); @@ -199,46 +200,47 @@ bool ResourceDir::load() ok = false; file.close(); } return ok; } bool ResourceDir::save( Ticket *ticket ) { AddressBook::Iterator it; bool ok = true; - +#ifndef NO_DIRWATCH mDirWatch.stopScan(); - +#endif for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { if ( (*it).resource() != this || !(*it).changed() ) continue; QFile file( mPath + "/" + (*it).uid() ); if ( !file.open( IO_WriteOnly ) ) { addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); continue; } mFormat->save( *it, &file ); // mark as unchanged (*it).setChanged( false ); file.close(); } +#ifndef NO_DIRWATCH mDirWatch.startScan(); - +#endif delete ticket; #ifdef ALLOW_LOCKING unlock( mPath ); #endif return ok; } bool ResourceDir::lock( const QString &path ) { #ifdef ALLOW_LOCKING QString p = path; //US change the implementation how the lockfilename is getting created @@ -292,32 +294,35 @@ void ResourceDir::unlock( const QString &path ) QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); ::unlink( QFile::encodeName( lockName ) ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); #else return; #endif } void ResourceDir::setPath( const QString &path ) { +#ifndef NO_DIRWATCH mDirWatch.stopScan(); mDirWatch.removeDir( mPath ); mPath = path; mDirWatch.addDir( mPath, true ); mDirWatch.startScan(); - +#else + mPath = path; +#endif //US simulate KDirWatch event //US pathChanged(); } QString ResourceDir::path() const { return mPath; } void ResourceDir::setFormat( const QString &format ) { diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h index c2aedad..77cd18c 100644 --- a/kabc/plugins/dir/resourcedir.h +++ b/kabc/plugins/dir/resourcedir.h @@ -95,21 +95,22 @@ public: virtual void cleanUp(); protected slots: void pathChanged(); protected: bool lock( const QString &path ); void unlock( const QString &path ); private: FormatPlugin *mFormat; +#ifndef NO_DIRWATCH KDirWatch mDirWatch; - +#endif QString mPath; QString mFormatName; QString mLockUniqueName; }; } #endif diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 17263ae..b8c32d5 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -40,30 +40,32 @@ $Id$ #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include "formatfactory.h" #include "resource.h" #include "resourcefileconfig.h" #include "stdaddressbook.h" - +#define NO_DIRWATCH #include "resourcefile.h" #include "syncprefwidget.h" //#define ALLOW_LOCKING + + using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif //US void *init_kabc_file() void *init_microkabc_file() { @@ -106,29 +108,29 @@ ResourceFile::ResourceFile( const QString &fileName, bool syncable , void ResourceFile::init( const QString &fileName, const QString &formatName ) { mFormatName = formatName; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); if ( !mFormat ) { mFormatName = "vcard"; 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 setFileName( fileName ); } ResourceFile::~ResourceFile() { delete mFormat; mFormat = 0; } void ResourceFile::writeConfig( KConfig *config ) { @@ -218,44 +220,45 @@ bool ResourceFile::save( Ticket *ticket ) ,extension ); KSaveFile saveFile( mFileName ); bool ok = false; if ( saveFile.status() == 0 && saveFile.file() ) { mFormat->saveAll( addressBook(), this, saveFile.file() ); ok = saveFile.close(); } */ //US ToDo: write backupfile +#ifndef NO_DIRWATCH mDirWatch.stopScan(); - +#endif QFile info; info.setName( mFileName ); 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 ) ); - +#ifndef NO_DIRWATCH mDirWatch.startScan(); - +#endif delete ticket; #ifdef ALLOW_LOCKING unlock( mFileName ); #endif return ok; } bool ResourceFile::lock( const QString &fileName ) { #ifdef ALLOW_LOCKING @@ -317,32 +320,35 @@ void ResourceFile::unlock( const QString &fileName ) QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); #else return; #endif } void ResourceFile::setFileName( const QString &fileName ) { +#ifndef NO_DIRWATCH mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); - mFileName = fileName; mDirWatch.addFile( mFileName ); mDirWatch.startScan(); +#else + mFileName = fileName; +#endif //US simulate KDirWatch event //US fileChanged(); } QString ResourceFile::fileName() const { return mFileName; } void ResourceFile::setFormat( const QString &format ) { diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h index 0a3027c..8339340 100644 --- a/kabc/plugins/file/resourcefile.h +++ b/kabc/plugins/file/resourcefile.h @@ -144,19 +144,20 @@ protected: void init( const QString &fileName, const QString &format ); bool lock( const QString &fileName ); void unlock( const QString &fileName ); private: QString mFileName; QString mFormatName; FormatPlugin *mFormat; QString mLockUniqueName; - +#ifndef NO_DIRWATCH KDirWatch mDirWatch; +#endif }; } #endif |