summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Side-by-side diff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore 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
@@ -35,48 +35,49 @@ $Id$
#include <qregexp.h>
#include <qtimer.h>
#include <qwidget.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
//US #include <kgenericfactory.h>
#include <kglobal.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kurlrequester.h>
#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
{
#endif
//US void *init_kabc_dir()
void *init_microkabc_dir()
{
return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>();
}
#ifndef _WIN32_
}
#endif
ResourceDir::ResourceDir( const KConfig *config, bool syncable )
@@ -92,53 +93,53 @@ ResourceDir::ResourceDir( const KConfig *config, bool syncable )
mFormatName = cfg->readEntry( "FileFormat", "vcard" );
} else {
path = StdAddressBook::directoryName();
mFormatName = "vcard";
}
FormatFactory *factory = FormatFactory::self();
mFormat = factory->format( mFormatName );
if ( !mFormat ) {
mFormatName = "vcard";
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() );
Resource::writeConfig( config );
config->writeEntry( "FilePath", mPath );
config->writeEntry( "FileFormat", mFormatName );
}
Ticket *ResourceDir::requestSaveTicket()
{
if ( !addressBook() ) return 0;
#ifdef ALLOW_LOCKING
@@ -187,70 +188,71 @@ bool ResourceDir::load()
QStringList::Iterator it;
bool ok = true;
for ( it = files.begin(); it != files.end(); ++it ) {
QFile file( mPath + "/" + (*it) );
if ( !file.open( IO_ReadOnly ) ) {
addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
ok = false;
continue;
}
if ( !mFormat->loadAll( addressBook(), this, &file ) )
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
//US p.replace( QRegExp("/"), "_" );
//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
KURL url(p);
QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
if ( QFile::exists( lockName ) ) return false;
QString lockUniqueName;
lockUniqueName = p + KApplication::randomString( 8 );
url = lockUniqueName;
@@ -280,56 +282,59 @@ bool ResourceDir::lock( const QString &path )
return true;
#endif
}
void ResourceDir::unlock( const QString &path )
{
#ifdef ALLOW_LOCKING
QString p = path;
//US change the implementation how the lockfilename is getting created
//US p.replace( QRegExp( "/" ), "_" );
//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
KURL url(p);
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 )
{
mFormatName = format;
if ( mFormat )
delete mFormat;
FormatFactory *factory = FormatFactory::self();
mFormat = factory->format( mFormatName );
/*US
qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
if (mFormatName == "vcard")
mFormat = new VCardFormatPlugin2();
else if (mFormatName == "binary")
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
@@ -83,33 +83,34 @@ public:
QString format() const;
/**
* Remove a addressee from its source.
* This method is mainly called by KABC::AddressBook.
*/
virtual void removeAddressee( const Addressee& addr );
/**
* This method is called by an error handler if the application
* crashed
*/
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
@@ -28,54 +28,56 @@ $Id$
#include <sys/types.h>
#include <sys/stat.h>
#ifndef _WIN32_
#include <unistd.h>
#endif
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
#include <qtimer.h>
#include <kapplication.h>
#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()
{
return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>();
}
#ifndef _WIN32_
}
#endif
ResourceFile::ResourceFile( const KConfig *config, bool syncable )
: Resource( config, syncable ) , mFormat( 0 )
{
QString fileName, formatName, default_fileName;
if (syncable == true)
@@ -94,53 +96,53 @@ ResourceFile::ResourceFile( const KConfig *config, bool syncable )
init( fileName, formatName );
}
ResourceFile::ResourceFile( const QString &fileName, bool syncable ,
const QString &formatName )
: Resource( 0, syncable )
{
// 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();
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 )
{
config->setGroup( "Resource_" + identifier() );
Resource::writeConfig( config );
config->writeEntry( "FileName", mFileName );
config->writeEntry( "FileFormat", mFormatName );
// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
}
Ticket *ResourceFile::requestSaveTicket()
{
@@ -206,68 +208,69 @@ bool ResourceFile::load()
bool ResourceFile::save( Ticket *ticket )
{
// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
// create backup file
QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
/*US we use a simpler method to create a backupfile
(void) KSaveFile::backupFile( mFileName, QString::null
,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
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" );
@@ -305,56 +308,59 @@ bool ResourceFile::lock( const QString &fileName )
#endif
}
void ResourceFile::unlock( const QString &fileName )
{
#ifdef ALLOW_LOCKING
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();
#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 )
{
mFormatName = format;
delete mFormat;
FormatFactory *factory = FormatFactory::self();
mFormat = factory->format( mFormatName );
/*US
//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
if (mFormatName == "vcard") {
mFormat = new VCardFormatPlugin2();
// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
}
else if (mFormatName == "binary") {
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
@@ -132,31 +132,32 @@ public:
virtual void removeAddressee( const Addressee& addr );
/**
* This method is called by an error handler if the application
* crashed
*/
virtual void cleanUp();
protected slots:
void fileChanged();
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