summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-30 22:02:19 (UTC)
committer ulf69 <ulf69>2004-06-30 22:02:19 (UTC)
commit570dc8214a4b43ca89e71901f48deea2b53492bb (patch) (side-by-side diff)
treed3eb25840e1e0e29541c0005ed7950b84557c34c
parent2de4aeb0272fa7d96a55332196a11e52b2f27539 (diff)
downloadkdepimpi-570dc8214a4b43ca89e71901f48deea2b53492bb.zip
kdepimpi-570dc8214a4b43ca89e71901f48deea2b53492bb.tar.gz
kdepimpi-570dc8214a4b43ca89e71901f48deea2b53492bb.tar.bz2
implemented loading of opie resources
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/opie/kabc_opieE.pro24
-rw-r--r--kabc/plugins/opie/resourceopie.cpp117
-rw-r--r--kabc/plugins/opie/resourceopie.h9
-rw-r--r--kabc/plugins/opie/resourceopieconfig.cpp9
4 files changed, 113 insertions, 46 deletions
diff --git a/kabc/plugins/opie/kabc_opieE.pro b/kabc/plugins/opie/kabc_opieE.pro
index 7341ca8..f3e2ac4 100644
--- a/kabc/plugins/opie/kabc_opieE.pro
+++ b/kabc/plugins/opie/kabc_opieE.pro
@@ -1,21 +1,31 @@
TEMPLATE = lib
-CONFIG += qt warn_on release
+CONFIG += qt warn_on
#release debug
-
TARGET = microkabc_opie
-INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat
+
+INCLUDEPATH += ../.. ../../converter/opie ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include
+
+
OBJECTS_DIR = obj/$(PLATFORM)
-MOC_DIR = moc
+MOC_DIR = moc/$(PLATFORM)
DESTDIR = $(QPEDIR)/lib
-LIBS += -lmicrokde -lmicrokabc
+LIBS += -lmicrokde
+LIBS += -lmicrokabc
LIBS += -L$(QPEDIR)/lib
+LIBS += -lopie
+LIBS += -lqpe
+LIBS += -lqte
+LIBS += -lmicrokabc_opieconverter
+#LIBS += -L../../lib/$(PLATFORM)
+
INTERFACES = \
HEADERS = \
resourceopie.h \
- resourceopieconfig.h
+ resourceopieconfig.h \
SOURCES = \
resourceopie.cpp \
- resourceopieconfig.cpp
+ resourceopieconfig.cpp \
+
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 47e22b4..f992301 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -20,96 +20,108 @@
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <qdir.h>
#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>
//US #include "formatfactory.h"
+//US #include <qpe/qpeapplication.h>
+
+#include <opie/ocontactaccess.h>
#include "resource.h"
#include "resourceopieconfig.h"
#include "stdaddressbook.h"
+#include "opieconverter.h"
+
#include "resourceopie.h"
using namespace KABC;
extern "C"
{
-//US void *init_kabc_file()
void *init_microkabc_opie()
{
return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>();
}
}
ResourceOpie::ResourceOpie( const KConfig *config )
- : Resource( config )
+ : Resource( config ), mConverter (0)
{
- QString fileName;
+ QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
KConfig *cfg = (KConfig *)config;
if ( cfg ) {
- fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() );
-// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() );
- } else {
- fileName = StdAddressBook::fileName();
-// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() );
+ fileName = cfg->readEntry( "FileName", fileName );
+
}
+// qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() );
+
init( fileName );
}
ResourceOpie::ResourceOpie( const QString &fileName )
: Resource( 0 )
{
-// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
+// qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1());
init( fileName );
}
void ResourceOpie::init( const QString &fileName )
{
/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
*/
+ //US opie addressbook is always readonly
+ setReadOnly( true );
setFileName( fileName );
+
}
ResourceOpie::~ResourceOpie()
{
+ if (mConverter != 0)
+ delete mConverter;
}
void ResourceOpie::writeConfig( KConfig *config )
{
+ //US opie addressbook is always readonly
+ setReadOnly( true );
+
Resource::writeConfig( config );
config->writeEntry( "FileName", mFileName );
// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
}
Ticket *ResourceOpie::requestSaveTicket()
{
kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl;
@@ -117,24 +129,26 @@ Ticket *ResourceOpie::requestSaveTicket()
if ( !lock( mFileName ) ) {
kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '"
<< mFileName << "'" << endl;
return 0;
}
return createTicket( this );
}
bool ResourceOpie::doOpen()
{
+// qDebug("ResourceOpie::doOpen() %s", mFileName.latin1());
+/*US
QFile file( mFileName );
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;
@@ -142,96 +156,137 @@ bool ResourceOpie::doOpen()
if ( file.size() == 0 ) {
file.close();
return true;
}
//US bool ok = mFormat->checkFormat( &file );
bool ok = true;
file.close();
return ok;
}
+*/
+ qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1());
+ return true;
}
void ResourceOpie::doClose()
{
+// qDebug("ResourceOpie::doClose() %s", mFileName.latin1());
}
bool ResourceOpie::load()
{
+// qDebug("ResourceOpie::load() %s", mFileName.latin1());
kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl;
-
- QFile file( mFileName );
- if ( !file.open( IO_ReadOnly ) ) {
- addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
+
+ OContactAccess* access = new OContactAccess("KDEPim/Pi", mFileName, 0l, false);
+
+ if ( !access ) {
+ qDebug("Unable to load file() %s", mFileName.latin1());
+ addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) );
return false;
}
+
+ access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
+
+ if (mConverter == 0)
+ mConverter = new OpieConverter();
-// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
+
+ OContactAccess::List::Iterator it;
+ OContactAccess::List allList = access->allRecords();
+ bool res = false;
+ for ( it = allList.begin(); it != allList.end(); ++it )
+ {
+ OContact c = (*it);
+
+ KABC::Addressee addressee;
+
+ res = mConverter->opieToAddressee( c, addressee );
+
+ if ( !addressee.isEmpty() && res )
+ {
+ addressee.setResource( this );
+ addressBook()->insertAddressee( addressee );
+ }
+
+// qDebug("found %s", c.fullName().latin1());
+ }
+
+ delete access;
- //US return mFormat->loadAll( addressBook(), this, &file );
return true;
}
bool ResourceOpie::save( Ticket *ticket )
{
-// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
+ qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1());
+/*US
+
+ qDebug("ResourceOpie::save %s", mFileName.latin1());
kdDebug(5700) << "ResourceOpie::save()" << endl;
// 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
//US ToDo: write backupfile
QFile info;
info.setName( mFileName );
bool ok = info.open( IO_WriteOnly );
if ( ok ) {
//US 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("ResourceOpie::save has to be changed");
+*/
return true;
+
}
bool ResourceOpie::lock( const QString &fileName )
{
+ qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1());
+
+/*US
+// qDebug("ResourceOpie::lock() %s", fileName.latin1());
kdDebug(5700) << "ResourceOpie::lock()" << endl;
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" );
kdDebug(5700) << "-- lock name: " << lockName << endl;
@@ -254,92 +309,86 @@ bool ResourceOpie::lock( const QString &fileName )
// Create lock file
int result = ::link( QFile::encodeName( mLockUniqueName ),
QFile::encodeName( lockName ) );
if ( result == 0 ) {
addressBook()->emitAddressBookLocked();
return true;
}
// TODO: check stat
return false;
+*/
+
+ return true;
}
void ResourceOpie::unlock( const QString &fileName )
{
+ qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1());
+/*US
+// qDebug("ResourceOpie::unlock() %s", fileName.latin1());
+
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();
+*/
}
void ResourceOpie::setFileName( const QString &fileName )
{
/*US ToDo: no synchronization so far. Has to be changed in the future
mDirWatch.stopScan();
mDirWatch.removeFile( mFileName );
*/
mFileName = fileName;
/*US ToDo: no synchronization so far. Has to be changed in the future
mDirWatch.addFile( mFileName );
mDirWatch.startScan();
*/
//US simulate KDirWatch event
fileChanged();
}
QString ResourceOpie::fileName() const
{
return mFileName;
}
-/*US
-void ResourceOpie::setFormat( const QString &format )
-{
- mFormatName = format;
- delete mFormat;
-
- FormatFactory *factory = FormatFactory::self();
- mFormat = factory->format( mFormatName );
-}
-
-QString ResourceOpie::format() const
-{
- return mFormatName;
-}
-*/
-
void ResourceOpie::fileChanged()
{
// There is a small theoretical chance that KDirWatch calls us before
// we are fully constructed
if (!addressBook())
return;
load();
addressBook()->emitAddressBookChanged();
}
void ResourceOpie::removeAddressee( const Addressee &addr )
{
/*US
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 ResourceOpie::cleanUp()
{
+// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1());
+
unlock( mFileName );
}
//US #include "resourceopie.moc"
diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h
index d21272a..9db9485 100644
--- a/kabc/plugins/opie/resourceopie.h
+++ b/kabc/plugins/opie/resourceopie.h
@@ -27,32 +27,33 @@ $Id$
#ifndef KABC_RESOURCEOPIE_H
#define KABC_RESOURCEOPIE_H
#include <kconfig.h>
#include <kdirwatch.h>
#include <sys/types.h>
#include "resource.h"
-class QTimer;
-class FormatPlugin;
+
+//class QTimer;
+//class FormatPlugin;
namespace KABC {
//US class FormatPlugin;
class ResourceConfigWidget;
-
+class OpieConverter;
/**
@internal
*/
class ResourceOpie : public Resource
{
Q_OBJECT
public:
/**
Constructor.
@@ -128,22 +129,24 @@ public:
virtual void cleanUp();
protected slots:
void fileChanged();
protected:
void init( const QString &fileName );
bool lock( const QString &fileName );
void unlock( const QString &fileName );
private:
+ OpieConverter* mConverter;
+
QString mFileName;
QString mLockUniqueName;
KDirWatch mDirWatch;
};
}
#endif
diff --git a/kabc/plugins/opie/resourceopieconfig.cpp b/kabc/plugins/opie/resourceopieconfig.cpp
index b92cfa1..f4cc4f9 100644
--- a/kabc/plugins/opie/resourceopieconfig.cpp
+++ b/kabc/plugins/opie/resourceopieconfig.cpp
@@ -26,27 +26,30 @@ $Id$
*/
#include <qlabel.h>
#include <qlayout.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kdialog.h>
#include <unistd.h>
+#include <qdir.h>
#include <qfile.h>
#include "resourceopie.h"
-#include "stdaddressbook.h"
+//US #include <qpe/qpeapplication.h>
+
+//US #include "stdaddressbook.h"
#include "resourceopieconfig.h"
using namespace KABC;
ResourceOpieConfig::ResourceOpieConfig( QWidget* parent, const char* name )
: ConfigWidget( parent, name )
{
//qDebug("ResourceFileConfig::ResourceFileConfig");
QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0,
KDialog::spacingHint() );
@@ -72,36 +75,38 @@ void ResourceOpieConfig::setEditMode( bool value )
void ResourceOpieConfig::loadSettings( KRES::Resource *res )
{
//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
ResourceOpie *resource = (ResourceOpie*)( res );
if ( !resource ) {
kdDebug(5700) << "ResourceOpieConfig::loadSettings(): cast failed" << endl;
return;
}
mFileNameEdit->setURL( resource->fileName() );
if ( mFileNameEdit->url().isEmpty() )
- mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
+ mFileNameEdit->setURL( QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml" );
}
void ResourceOpieConfig::saveSettings( KRES::Resource *res )
{
//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
ResourceOpie *resource = (ResourceOpie*)( res );
if ( !resource ) {
kdDebug(5700) << "ResourceOpieConfig::saveSettings(): cast failed" << endl;
return;
}
resource->setFileName( mFileNameEdit->url() );
}
void ResourceOpieConfig::checkFilePermissions( const QString& fileName )
{
// If file exist but is not writeable...
+/*US
if ( access( QFile::encodeName( fileName ), F_OK ) == 0 )
emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
+*/
}
//US #include "resourceopieconfig.moc"