From 570dc8214a4b43ca89e71901f48deea2b53492bb Mon Sep 17 00:00:00 2001 From: ulf69 Date: Wed, 30 Jun 2004 22:02:19 +0000 Subject: implemented loading of opie resources --- (limited to 'kabc/plugins/opie/resourceopie.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 @@ -29,6 +29,7 @@ $Id$ #include #include +#include #include #include #include @@ -42,17 +43,21 @@ $Id$ #include //US #include "formatfactory.h" +//US #include + +#include #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(); @@ -60,26 +65,25 @@ extern "C" } 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 ); } @@ -91,16 +95,24 @@ void ResourceOpie::init( const QString &fileName ) 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 ); @@ -126,6 +138,8 @@ Ticket *ResourceOpie::requestSaveTicket() bool ResourceOpie::doOpen() { +// qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); +/*US QFile file( mFileName ); if ( !file.exists() ) { @@ -151,36 +165,71 @@ bool ResourceOpie::doOpen() 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 @@ -194,7 +243,7 @@ bool ResourceOpie::save( Ticket *ticket ) ok = saveFile.close(); } */ - +/*US //US ToDo: write backupfile QFile info; info.setName( mFileName ); @@ -218,11 +267,17 @@ bool ResourceOpie::save( Ticket *ticket ) 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; @@ -263,10 +318,17 @@ bool ResourceOpie::lock( const QString &fileName ) // 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( "/" ), "_" ); @@ -278,6 +340,7 @@ void ResourceOpie::unlock( const QString &fileName ) QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); +*/ } void ResourceOpie::setFileName( const QString &fileName ) @@ -302,22 +365,6 @@ 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 @@ -339,6 +386,8 @@ void ResourceOpie::removeAddressee( const Addressee &addr ) void ResourceOpie::cleanUp() { +// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); + unlock( mFileName ); } -- cgit v0.9.0.2