summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file
Side-by-side diff
Diffstat (limited to 'kabc/plugins/file') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/file.pro2
-rw-r--r--kabc/plugins/file/fileE.pro2
-rw-r--r--kabc/plugins/file/resourcefile.cpp74
-rw-r--r--kabc/plugins/file/resourcefile.h8
4 files changed, 44 insertions, 42 deletions
diff --git a/kabc/plugins/file/file.pro b/kabc/plugins/file/file.pro
index 32555a2..154ef2a 100644
--- a/kabc/plugins/file/file.pro
+++ b/kabc/plugins/file/file.pro
@@ -1,12 +1,12 @@
TEMPLATE = lib
CONFIG += qt warn_on release
#release debug
TARGET = microkabc_file
-INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat
+INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat
DESTDIR = ../../../bin
#LIBS += -lmicrokde -lmicrokabc
#LIBS += -L$(QPEDIR)/lib
INTERFACES = \
diff --git a/kabc/plugins/file/fileE.pro b/kabc/plugins/file/fileE.pro
index d19a26d..3015806 100644
--- a/kabc/plugins/file/fileE.pro
+++ b/kabc/plugins/file/fileE.pro
@@ -1,12 +1,12 @@
TEMPLATE = lib
CONFIG += qt warn_on release
#release debug
TARGET = microkabc_file
-INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat
+INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat
OBJECTS_DIR = obj/$(PLATFORM)
MOC_DIR = moc/$(PLATFORM)
DESTDIR = $(QPEDIR)/lib
LIBS += -lmicrokde -lmicrokabc
LIBS += -L$(QPEDIR)/lib
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 1d3acec..361b36b 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -48,33 +48,35 @@ $Id$
#include "resource.h"
#include "resourcefileconfig.h"
#include "stdaddressbook.h"
#include "resourcefile.h"
+#include "syncwidget.h"
+
using namespace KABC;
extern "C"
#ifdef _WIN32_
-__declspec(dllexport)
+__declspec(dllexport)
#else
{
#endif
//US void *init_kabc_file()
void *init_microkabc_file()
{
- return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
+ return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, KRES::SyncWidget>();
}
#ifndef _WIN32_
}
#endif
-ResourceFile::ResourceFile( const KConfig *config )
- : Resource( config ) , mFormat( 0 )
+ResourceFile::ResourceFile( const KConfig *config, bool syncable )
+ : Resource( config, syncable ) , mFormat( 0 )
{
QString fileName, formatName;
KConfig *cfg = (KConfig *)config;
if ( cfg ) {
fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() );
@@ -86,15 +88,15 @@ ResourceFile::ResourceFile( const KConfig *config )
// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() );
}
init( fileName, formatName );
}
-ResourceFile::ResourceFile( const QString &fileName,
+ResourceFile::ResourceFile( const QString &fileName, bool syncable ,
const QString &formatName )
- : Resource( 0 )
+ : 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 )
@@ -136,20 +138,20 @@ ResourceFile::~ResourceFile()
mFormat = 0;
}
void ResourceFile::writeConfig( KConfig *config )
{
- config->setGroup( "Resource_" + identifier() );
+ 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()
{
kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
@@ -194,94 +196,94 @@ bool ResourceFile::doOpen()
void ResourceFile::doClose()
{
}
bool ResourceFile::load()
{
-
+
QFile file( mFileName );
if ( !file.open( IO_ReadOnly ) ) {
addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
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
+//US ToDo: write backupfile
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 ) );
-
+
delete ticket;
unlock( mFileName );
-
+
return ok;
qDebug("ResourceFile::save has to be changed");
return true;
}
bool ResourceFile::lock( const QString &fileName )
{
-
+
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);
+
+ KURL url(fn);
QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
-
-
+
+
if (QFile::exists( lockName )) return false;
QString lockUniqueName;
lockUniqueName = fn + KApplication::randomString( 8 );
-
- url = lockUniqueName;
+
+ url = lockUniqueName;
//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
// Create unique file
QFile file( mLockUniqueName );
@@ -308,32 +310,32 @@ void ResourceFile::unlock( const QString &fileName )
{
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);
+ KURL url(fn);
QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
-
+
QFile::remove( lockName );
QFile::remove( mLockUniqueName );
addressBook()->emitAddressBookUnlocked();
}
void ResourceFile::setFileName( const QString &fileName )
{
mDirWatch.stopScan();
mDirWatch.removeFile( mFileName );
-
+
mFileName = fileName;
-
+
mDirWatch.addFile( mFileName );
mDirWatch.startScan();
-//US simulate KDirWatch event
+//US simulate KDirWatch event
//US fileChanged();
}
QString ResourceFile::fileName() const
{
return mFileName;
@@ -343,26 +345,26 @@ void ResourceFile::setFormat( const QString &format )
{
mFormatName = format;
delete mFormat;
FormatFactory *factory = FormatFactory::self();
mFormat = factory->format( mFormatName );
-/*US
+/*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;
}
@@ -370,14 +372,14 @@ 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 ) );
if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
load();
addressBook()->emitAddressBookChanged();
}
}
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h
index 4522d78..0a3027c 100644
--- a/kabc/plugins/file/resourcefile.h
+++ b/kabc/plugins/file/resourcefile.h
@@ -55,18 +55,18 @@ public:
/**
Constructor.
@param cfg The config object where custom resource settings are stored.
*/
- ResourceFile( const KConfig *cfg );
+ ResourceFile( const KConfig *cfg, bool syncable );
/**
Construct file resource on file @arg fileName using format @arg formatName.
*/
- ResourceFile( const QString &fileName, const QString &formatName = "vcard" );
+ ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" );
/**
* Destructor.
*/
~ResourceFile();
@@ -82,13 +82,13 @@ public:
virtual bool doOpen();
/**
* Closes the file again.
*/
virtual void doClose();
-
+
/**
* Requests a save ticket, that is used by @ref save()
*/
virtual Ticket *requestSaveTicket();
/**
@@ -150,13 +150,13 @@ private:
QString mFileName;
QString mFormatName;
FormatPlugin *mFormat;
QString mLockUniqueName;
-
+
KDirWatch mDirWatch;
};
}
#endif