summaryrefslogtreecommitdiffabout
path: root/kabc
Side-by-side diff
Diffstat (limited to 'kabc') (more/less context) (show whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp17
-rw-r--r--kabc/plugins/dir/resourcedir.h3
-rw-r--r--kabc/plugins/file/resourcefile.cpp20
-rw-r--r--kabc/plugins/file/resourcefile.h3
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
@@ -51,16 +51,17 @@ $Id$
#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"
@@ -108,21 +109,21 @@ ResourceDir::ResourceDir( const KConfig *config, bool syncable )
//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;
}
@@ -203,19 +204,19 @@ bool ResourceDir::load()
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;
@@ -223,18 +224,19 @@ bool ResourceDir::save( Ticket *ticket )
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 )
@@ -296,24 +298,27 @@ void ResourceDir::unlock( const QString &path )
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;
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
@@ -99,17 +99,18 @@ protected slots:
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
@@ -44,22 +44,24 @@ $Id$
#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
@@ -110,21 +112,21 @@ void ResourceFile::init( const QString &fileName, const QString &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;
}
@@ -222,36 +224,37 @@ bool ResourceFile::save( Ticket *ticket )
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;
}
@@ -321,24 +324,27 @@ void ResourceFile::unlock( const QString &fileName )
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;
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
@@ -148,15 +148,16 @@ protected:
private:
QString mFileName;
QString mFormatName;
FormatPlugin *mFormat;
QString mLockUniqueName;
-
+#ifndef NO_DIRWATCH
KDirWatch mDirWatch;
+#endif
};
}
#endif