Diffstat (limited to 'kabc/plugins/opie/resourceopie.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 115 |
1 files changed, 82 insertions, 33 deletions
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 @@ -31,2 +31,3 @@ $Id$ +#include <qdir.h> #include <qfile.h> @@ -44,2 +45,5 @@ $Id$ //US #include "formatfactory.h" +//US #include <qpe/qpeapplication.h> + +#include <opie/ocontactaccess.h> @@ -49,2 +53,4 @@ $Id$ +#include "opieconverter.h" + #include "resourceopie.h" @@ -54,3 +60,2 @@ extern "C" { -//US void *init_kabc_file() void *init_microkabc_opie() @@ -62,5 +67,5 @@ extern "C" ResourceOpie::ResourceOpie( const KConfig *config ) - : Resource( config ) + : Resource( config ), mConverter (0) { - QString fileName; + QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; @@ -68,9 +73,8 @@ ResourceOpie::ResourceOpie( const 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 ); @@ -81,3 +85,3 @@ ResourceOpie::ResourceOpie( const QString &fileName ) { -// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); +// qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); init( fileName ); @@ -93,4 +97,7 @@ void ResourceOpie::init( const QString &fileName ) */ + //US opie addressbook is always readonly + setReadOnly( true ); setFileName( fileName ); + } @@ -99,2 +106,4 @@ ResourceOpie::~ResourceOpie() { + if (mConverter != 0) + delete mConverter; } @@ -103,2 +112,5 @@ void ResourceOpie::writeConfig( KConfig *config ) { + //US opie addressbook is always readonly + setReadOnly( true ); + Resource::writeConfig( config ); @@ -128,2 +140,4 @@ bool ResourceOpie::doOpen() { +// qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); +/*US QFile file( mFileName ); @@ -153,2 +167,5 @@ bool ResourceOpie::doOpen() } +*/ + qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); + return true; } @@ -157,2 +174,3 @@ void ResourceOpie::doClose() { +// qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); } @@ -161,7 +179,10 @@ 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; @@ -169,5 +190,30 @@ bool ResourceOpie::load() -// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); + access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available + + if (mConverter == 0) + mConverter = new OpieConverter(); + + + 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; @@ -177,3 +223,6 @@ 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; @@ -182,3 +231,3 @@ bool ResourceOpie::save( Ticket *ticket ) QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); - +*/ /*US we use a simpler method to create a backupfile @@ -196,3 +245,3 @@ bool ResourceOpie::save( Ticket *ticket ) */ - +/*US //US ToDo: write backupfile @@ -220,3 +269,5 @@ bool ResourceOpie::save( Ticket *ticket ) qDebug("ResourceOpie::save has to be changed"); +*/ return true; + } @@ -225,2 +276,6 @@ 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; @@ -265,2 +320,5 @@ bool ResourceOpie::lock( const QString &fileName ) return false; +*/ + + return true; } @@ -269,2 +327,6 @@ 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; @@ -280,2 +342,3 @@ void ResourceOpie::unlock( const QString &fileName ) addressBook()->emitAddressBookUnlocked(); +*/ } @@ -304,18 +367,2 @@ QString ResourceOpie::fileName() const -/*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() @@ -341,2 +388,4 @@ void ResourceOpie::cleanUp() { +// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); + unlock( mFileName ); |