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/file/resourcefile.cpp41
-rw-r--r--kabc/plugins/file/resourcefile.h2
2 files changed, 30 insertions, 13 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
@@ -34,236 +34,253 @@ $Id$
#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"
//#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>();
}
#ifndef _WIN32_
}
#endif
ResourceFile::ResourceFile( const KConfig *config )
: Resource( config ) , mFormat( 0 )
{
QString fileName, formatName, default_fileName;
default_fileName = StdAddressBook::fileName();
KConfig *cfg = (KConfig *)config;
if ( cfg ) {
fileName = cfg->readEntry( "FileName", default_fileName );
formatName = cfg->readEntry( "FileFormat", "vcard" );
} else {
fileName = default_fileName;
formatName = "vcard";
}
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();
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
+
+
+ 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()
{
kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
if ( !addressBook() ) return 0;
#ifdef ALLOW_LOCKING
if ( !lock( mFileName ) ) {
qDebug("unablt to lock file ");
return 0;
}
#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;
} else {
if ( !file.open( IO_ReadWrite ) )
return false;
if ( file.size() == 0 ) {
file.close();
return true;
}
bool ok = mFormat->checkFormat( &file );
file.close();
return ok;
}
}
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 );
}
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 );
+ 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
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" );
@@ -313,92 +330,92 @@ void ResourceFile::unlock( const QString &fileName )
//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;
+ 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();
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") {
mFormat = new BinaryFormat();
// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
}
else
qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
*/
}
QString ResourceFile::format() const
{
return mFormatName;
}
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"
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h
index b4421b2..dd38a9d 100644
--- a/kabc/plugins/file/resourcefile.h
+++ b/kabc/plugins/file/resourcefile.h
@@ -126,38 +126,38 @@ 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 fileChanged();
protected:
void init( const QString &fileName, const QString &format );
bool lock( const QString &fileName );
void unlock( const QString &fileName );
private:
- QString mFileName;
+ QString mFileName2;
QString mFormatName;
FormatPlugin *mFormat;
QString mLockUniqueName;
#ifndef NO_DIRWATCH
KDirWatch mDirWatch;
#endif
};
}
#endif