author | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
commit | 863c4c3678e59ef125c08c00e9532ded5b540f67 (patch) (side-by-side diff) | |
tree | 449428c45689ffe10ff1ce4caa18f959c4dfe402 | |
parent | 983127ce46c9ff6663d08dedd450da3fe7dd549b (diff) | |
download | kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.zip kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.gz kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.bz2 |
added support for syncprofiles for resources and export/import capabilities
-rw-r--r-- | kabc/plugins/dir/dir.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/dir/dirE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 7 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.h | 2 | ||||
-rw-r--r-- | kabc/plugins/file/file.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/file/fileE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 12 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 4 | ||||
-rw-r--r-- | kabc/plugins/ldap/ldapE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.cpp | 7 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.h | 2 | ||||
-rw-r--r-- | kabc/plugins/opie/opieE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 224 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.h | 36 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 166 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.h | 31 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 35 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.h | 32 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmE.pro | 2 |
20 files changed, 319 insertions, 255 deletions
diff --git a/kabc/plugins/dir/dir.pro b/kabc/plugins/dir/dir.pro index 0555484..a7c1503 100644 --- a/kabc/plugins/dir/dir.pro +++ b/kabc/plugins/dir/dir.pro @@ -5,3 +5,3 @@ CONFIG += qt warn_on release TARGET = microkabc_dir -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 diff --git a/kabc/plugins/dir/dirE.pro b/kabc/plugins/dir/dirE.pro index 729f4ce..9066556 100644 --- a/kabc/plugins/dir/dirE.pro +++ b/kabc/plugins/dir/dirE.pro @@ -5,3 +5,3 @@ CONFIG += qt warn_on release TARGET = microkabc_dir -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) diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 52863d5..d978e61 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp @@ -59,2 +59,3 @@ $Id$ #include "resourcedir.h" +#include "syncwidget.h" @@ -72,3 +73,3 @@ __declspec(dllexport) { - return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); + return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, KRES::SyncWidget>(); } @@ -78,4 +79,4 @@ __declspec(dllexport) -ResourceDir::ResourceDir( const KConfig *config ) - : Resource( config ) +ResourceDir::ResourceDir( const KConfig *config, bool syncable ) + : Resource( config, syncable ) { diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h index 6e35695..c2aedad 100644 --- a/kabc/plugins/dir/resourcedir.h +++ b/kabc/plugins/dir/resourcedir.h @@ -51,3 +51,3 @@ class ResourceDir : public Resource public: - ResourceDir( const KConfig* ); + ResourceDir( const KConfig*, bool syncable ); ~ResourceDir(); 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 @@ -5,3 +5,3 @@ CONFIG += qt warn_on release 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 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 @@ -5,3 +5,3 @@ CONFIG += qt warn_on release 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) 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 @@ -53,2 +53,4 @@ $Id$ #include "resourcefile.h" +#include "syncwidget.h" + @@ -66,3 +68,3 @@ __declspec(dllexport) { - return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); + return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, KRES::SyncWidget>(); } @@ -72,4 +74,4 @@ __declspec(dllexport) -ResourceFile::ResourceFile( const KConfig *config ) - : Resource( config ) , mFormat( 0 ) +ResourceFile::ResourceFile( const KConfig *config, bool syncable ) + : Resource( config, syncable ) , mFormat( 0 ) { @@ -91,5 +93,5 @@ ResourceFile::ResourceFile( const KConfig *config ) -ResourceFile::ResourceFile( const QString &fileName, +ResourceFile::ResourceFile( const QString &fileName, bool syncable , const QString &formatName ) - : Resource( 0 ) + : Resource( 0, syncable ) { 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 @@ -60,3 +60,3 @@ public: */ - ResourceFile( const KConfig *cfg ); + ResourceFile( const KConfig *cfg, bool syncable ); @@ -65,3 +65,3 @@ public: */ - ResourceFile( const QString &fileName, const QString &formatName = "vcard" ); + ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" ); diff --git a/kabc/plugins/ldap/ldapE.pro b/kabc/plugins/ldap/ldapE.pro index f6ca586..2e79fc0 100644 --- a/kabc/plugins/ldap/ldapE.pro +++ b/kabc/plugins/ldap/ldapE.pro @@ -5,3 +5,3 @@ CONFIG += qt warn_on release TARGET = microkabc_ldap -INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include +INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include OBJECTS_DIR = obj/$(PLATFORM) diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp index 55c43af..4b9dede 100644 --- a/kabc/plugins/ldap/resourceldap.cpp +++ b/kabc/plugins/ldap/resourceldap.cpp @@ -38,2 +38,3 @@ $Id$ #include "resourceldapconfig.h" +#include "syncwidget.h" @@ -46,3 +47,3 @@ extern "C" { - return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>(); + return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, KRES::SyncWidget>(); } @@ -53,4 +54,4 @@ void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); -ResourceLDAP::ResourceLDAP( const KConfig *config ) - : Resource( config ), mPort( 389 ), mLdap( 0 ) +ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) + : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) { diff --git a/kabc/plugins/ldap/resourceldap.h b/kabc/plugins/ldap/resourceldap.h index 0625f30..0aad3c1 100644 --- a/kabc/plugins/ldap/resourceldap.h +++ b/kabc/plugins/ldap/resourceldap.h @@ -45,3 +45,3 @@ public: - ResourceLDAP( const KConfig* ); + ResourceLDAP( const KConfig*, bool syncable ); diff --git a/kabc/plugins/opie/opieE.pro b/kabc/plugins/opie/opieE.pro index 8d45c3d..912e596 100644 --- a/kabc/plugins/opie/opieE.pro +++ b/kabc/plugins/opie/opieE.pro @@ -5,3 +5,3 @@ TARGET = microkabc_opie -INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include +INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index aaee801..1222242 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp @@ -52,2 +52,3 @@ $Id$ #include "stdaddressbook.h" +#include "syncwidget.h" @@ -62,3 +63,3 @@ extern "C" { - return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); + return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, KRES::SyncWidget>(); } @@ -66,4 +67,4 @@ extern "C" -ResourceOpie::ResourceOpie( const KConfig *config ) - : Resource( config ), mConverter (0) +ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) + : Resource( config, syncable ), mAccess(0), mConverter (0) { @@ -82,4 +83,4 @@ ResourceOpie::ResourceOpie( const KConfig *config ) -ResourceOpie::ResourceOpie( const QString &fileName ) - : Resource( 0 ) +ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) + : Resource( 0, syncable ) { @@ -105,2 +106,6 @@ ResourceOpie::~ResourceOpie() delete mConverter; + + if(mAccess != 0) + delete mAccess; + } @@ -111,6 +116,3 @@ void ResourceOpie::writeConfig( KConfig *config ) - config->writeEntry( "FileName", mFileName ); - -// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); - + config->writeEntry( "FileName", fileName() ); } @@ -121,7 +123,9 @@ Ticket *ResourceOpie::requestSaveTicket() + qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); + if ( !addressBook() ) return 0; - if ( !lock( mFileName ) ) { + if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" - << mFileName << "'" << endl; + << fileName() << "'" << endl; return 0; @@ -134,31 +138,30 @@ 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(); + qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); - return ok; - } else { - if ( !file.open( IO_ReadWrite ) ) - return false; + OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); + mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); - if ( file.size() == 0 ) { - file.close(); - return true; + if ( !mAccess ) { + qDebug("Unable to load file() %s", fileName().latin1()); + return false; } -//US bool ok = mFormat->checkFormat( &file ); - bool ok = true; + mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available - file.close(); - return ok; + if (mConverter == 0) + { + mConverter = new OpieConverter(); + bool res = mConverter->init(); + if ( !res ) + { + qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); + delete mAccess; + mAccess = 0; + return false; } -*/ - qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); + } + + + return true; @@ -168,40 +171,25 @@ void ResourceOpie::doClose() { -// qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); -} + qDebug("ResourceOpie::doClose: %s", fileName().latin1()); -bool ResourceOpie::load() + if(mAccess) { -// qDebug("ResourceOpie::load() %s", mFileName.latin1()); - kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; - - qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); + delete mAccess; + mAccess = 0; + } + // it seems so, that deletion of access deletes backend as well + //delete backend; - OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); - OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); + return; - 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 - bool res = false; - if (mConverter == 0) - { - mConverter = new OpieConverter(); - res = mConverter->init(); - if ( !res ) +bool ResourceOpie::load() { - qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); - addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) ); - delete access; - return false; - } - } + qDebug("ResourceOpie::load: %s", fileName().latin1()); + bool res = false; OContactAccess::List::Iterator it; - OContactAccess::List allList = access->allRecords(); + OContactAccess::List allList = mAccess->allRecords(); for ( it = allList.begin(); it != allList.end(); ++it ) @@ -220,8 +208,4 @@ bool ResourceOpie::load() -// qDebug("found %s", c.fullName().latin1()); } - delete access; - // it seems so, that deletion of access deletes backend as well - //delete backend; @@ -232,49 +216,31 @@ bool ResourceOpie::save( Ticket *ticket ) { - qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); -/*US + qDebug("ResourceOpie::save: %s", fileName().latin1()); - 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 ); + KABC::AddressBook::Iterator it; + bool res; + + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + OContact c; + KABC::Addressee addressee = (*it); - KSaveFile saveFile( mFileName ); - bool ok = false; - if ( saveFile.status() == 0 && saveFile.file() ) + res = mConverter->addresseeToOpie( *it, c ); + if (res == true) { - mFormat->saveAll( addressBook(), this, saveFile.file() ); - ok = saveFile.close(); + res = mAccess->add(c); + if (res == false) + qDebug("Unable to append Contact %s", c.fullName().latin1()); } -*/ -/*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 + { + qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } - else { - } - if ( !ok ) - addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); + mAccess->save(); delete ticket; - unlock( mFileName ); - - return ok; + unlock( fileName() ); - qDebug("ResourceOpie::save has to be changed"); -*/ return true; @@ -283,4 +249,7 @@ bool ResourceOpie::save( Ticket *ticket ) -bool ResourceOpie::lock( const QString &fileName ) +bool ResourceOpie::lock( const QString &lockfileName ) { + qDebug("ResourceOpie::lock: %s", fileName().latin1()); + + // qDebug("ResourceOpie::lock() %s", fileName.latin1()); @@ -288,3 +257,3 @@ bool ResourceOpie::lock( const QString &fileName ) - QString fn = fileName; + QString fn = lockfileName; @@ -332,3 +301,3 @@ void ResourceOpie::unlock( const QString &fileName ) { -// qDebug("ResourceOpie::unlock() %s", fileName.latin1()); + qDebug("ResourceOpie::unlock() %s", fileName.latin1()); @@ -347,20 +316,14 @@ void ResourceOpie::unlock( const QString &fileName ) -void ResourceOpie::setFileName( const QString &fileName ) +void ResourceOpie::setFileName( const QString &newFileName ) { mDirWatch.stopScan(); - mDirWatch.removeFile( mFileName ); + mDirWatch.removeFile( fileName() ); - mFileName = fileName; + Resource::setFileName( newFileName ); - mDirWatch.addFile( mFileName ); + mDirWatch.addFile( fileName() ); mDirWatch.startScan(); -//US simulate KDirWatch event -//US fileChanged(); } -QString ResourceOpie::fileName() const -{ - return mFileName; -} @@ -373,3 +336,3 @@ void ResourceOpie::fileChanged() - QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); + QString text( i18n( "Opie 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 ) { @@ -391,5 +354,38 @@ void ResourceOpie::cleanUp() - unlock( mFileName ); + unlock( fileName() ); } + +/** + * This method returns the number of elements that are currently in the resource. + */ +int ResourceOpie::count() const +{ + qDebug("ResourceOpie::count: %x", mAccess); + + if (mAccess != 0) + { + OContactAccess::List contactList = mAccess->allRecords(); + return contactList.count(); + } + else + return 0; +} + + +/** + * This method removes all elements from the resource!! (Not from the addressbook) + */ +bool ResourceOpie::clear() +{ + if (mAccess != 0) { + mAccess->clear(); + return true; + } + else + return false; +} + + + //US #include "resourceopie.moc" diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h index 9db9485..ca30fee 100644 --- a/kabc/plugins/opie/resourceopie.h +++ b/kabc/plugins/opie/resourceopie.h @@ -39,4 +39,3 @@ $Id$ -//class QTimer; -//class FormatPlugin; +class OContactAccess; @@ -44,3 +43,2 @@ namespace KABC { -//US class FormatPlugin; class ResourceConfigWidget; @@ -61,3 +59,3 @@ public: */ - ResourceOpie( const KConfig *cfg ); + ResourceOpie( const KConfig *cfg, bool syncable ); @@ -66,3 +64,3 @@ public: */ - ResourceOpie( const QString &fileName ); + ResourceOpie( const QString &fileName, bool syncable ); @@ -108,11 +106,2 @@ public: - /** - * Set name of file to be used for saving. - */ - void setFileName( const QString & ); - - /** - * Return name of file used for loading and saving the address book. - */ - QString fileName() const; @@ -125,2 +114,7 @@ public: /** + * Set name of file to be used for saving. + */ + virtual void setFileName( const QString & ); + + /** * This method is called by an error handler if the application @@ -130,2 +124,13 @@ public: + /** + * This method returns the number of elements that are currently in the resource. + */ + virtual int count() const; + + /** + * This method removes all elements from the resource!! (Not from the addressbook) + */ + virtual bool clear(); + + protected slots: @@ -140,6 +145,5 @@ protected: private: + OContactAccess* mAccess; OpieConverter* mConverter; - QString mFileName; - QString mLockUniqueName; diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro index 56eae87..d956519 100644 --- a/kabc/plugins/qtopia/qtopiaE.pro +++ b/kabc/plugins/qtopia/qtopiaE.pro @@ -5,3 +5,3 @@ TARGET = microkabc_qtopia -INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include +INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 7e10e46..dc88272 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -51,2 +51,3 @@ $Id$ #include "qtopiaconverter.h" +#include "syncwidget.h" @@ -59,3 +60,3 @@ extern "C" { - return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); + return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, KRES::SyncWidget>(); } @@ -63,4 +64,4 @@ extern "C" -ResourceQtopia::ResourceQtopia( const KConfig *config ) - : Resource( config ), mConverter (0) +ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) + : Resource( config, syncable ), mConverter (0) { @@ -72,4 +73,4 @@ ResourceQtopia::ResourceQtopia( const KConfig *config ) -ResourceQtopia::ResourceQtopia( const QString &fileName ) - : Resource( 0 ) +ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) + : Resource( 0, syncable ) { @@ -94,2 +95,4 @@ ResourceQtopia::~ResourceQtopia() + if(mAccess != 0) + delete mAccess; } @@ -107,5 +110,5 @@ Ticket *ResourceQtopia::requestSaveTicket() - if ( !lock( mFileName ) ) { + if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" - << mFileName << "'" << endl; + << fileName() << "'" << endl; return 0; @@ -118,47 +121,8 @@ bool ResourceQtopia::doOpen() { -/*US - QFile file( mFileName ); + qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); - if ( !file.exists() ) { - // try to create the file - bool ok = file.open( IO_WriteOnly ); - if ( ok ) - file.close(); + mAccess = new AddressBookAccess(); - return ok; - } else { - if ( !file.open( IO_ReadWrite ) ) - return false; - - if ( file.size() == 0 ) { - file.close(); - return true; - } - -//US bool ok = mFormat->checkFormat( &file ); - bool ok = true; - - file.close(); - - return ok; - } -*/ - return true; -} - -void ResourceQtopia::doClose() -{ -} - -bool ResourceQtopia::load() -{ - kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl; - -// qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1()); - - AddressBookAccess* access = new AddressBookAccess(); - - if ( !access ) { - qDebug("Unable to load file() %s", mFileName.latin1()); - addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); + if ( !mAccess ) { + qDebug("Unable to load file() %s", fileName().latin1()); return false; @@ -175,4 +139,4 @@ bool ResourceQtopia::load() qDebug(msg); - addressBook()->error( i18n( msg ) ); - delete access; + delete mAccess; + mAccess = 0; return false; @@ -181,7 +145,30 @@ bool ResourceQtopia::load() - { //create a new scope - AddressBookIterator it(*access); + return true; +} + +void ResourceQtopia::doClose() +{ + qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); + + if(mAccess) + { + delete mAccess; + mAccess = 0; + } + // it seems so, that deletion of access deletes backend as well + //delete backend; + + return; +} + +bool ResourceQtopia::load() +{ + qDebug("ResourceQtopia::load: %s", fileName().latin1()); + + AddressBookIterator it(*mAccess); const PimContact* contact; + bool res; - for (contact=it.toFirst(); it.current(); ++it) { + for (contact=it.toFirst(); it.current(); ++it) + { contact = it.current(); @@ -198,5 +185,3 @@ bool ResourceQtopia::load() } - } - delete access; return true; @@ -251,3 +236,8 @@ bool ResourceQtopia::save( Ticket *ticket ) qDebug("ResourceQtopia::save has to be changed"); + + + access->save(); + */ + return true; @@ -314,20 +304,13 @@ void ResourceQtopia::unlock( const QString &fileName ) -void ResourceQtopia::setFileName( const QString &fileName ) +void ResourceQtopia::setFileName( const QString &newFileName ) { mDirWatch.stopScan(); - mDirWatch.removeFile( mFileName ); + mDirWatch.removeFile( fileName() ); - mFileName = fileName; + Resource::setFileName( newFileName ); - mDirWatch.addFile( mFileName ); + mDirWatch.addFile( fileName() ); mDirWatch.startScan(); - -//US simulate KDirWatch event -//US fileChanged(); } -QString ResourceQtopia::fileName() const -{ - return mFileName; -} @@ -340,3 +323,3 @@ void ResourceQtopia::fileChanged() - QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); + QString text( i18n( "Qtopia 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 ) { @@ -353,5 +336,48 @@ void ResourceQtopia::cleanUp() { - unlock( mFileName ); + unlock( fileName() ); +} + + + +/** + * This method returns the number of elements that are currently in the resource. + */ +int ResourceQtopia::count() const +{ + if (mAccess != 0) + { + int counter = 0; + AddressBookIterator it2(*mAccess); + for (it2.toFirst(); it2.current(); ++it2) { + counter++; + } + + return counter; + } + else + return 0; } + +/** + * This method removes all elements from the resource!! (Not from the addressbook) + */ +bool ResourceQtopia::clear() +{ + if (mAccess != 0) + { + AddressBookIterator it2(*mAccess); + for (it2.toFirst(); it2.current(); ++it2) { + mAccess->removeContact(*it2.current()); + } + return true; + } + else + return false; +} + + + + + //US #include "resourceqtopia.moc" diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h index bf9dd45..90ab1f4 100644 --- a/kabc/plugins/qtopia/resourceqtopia.h +++ b/kabc/plugins/qtopia/resourceqtopia.h @@ -38,2 +38,3 @@ $Id$ +class AddressBookAccess; @@ -59,3 +60,3 @@ public: */ - ResourceQtopia( const KConfig *cfg ); + ResourceQtopia( const KConfig *cfg, bool syncable ); @@ -64,3 +65,3 @@ public: */ - ResourceQtopia( const QString &fileName ); + ResourceQtopia( const QString &fileName, bool syncable ); @@ -107,22 +108,27 @@ public: /** + * Remove a addressee from its source. + * This method is mainly called by KABC::AddressBook. + */ + virtual void removeAddressee( const Addressee& addr ); + + /** * Set name of file to be used for saving. */ - void setFileName( const QString & ); + virtual void setFileName( const QString & ); /** - * Return name of file used for loading and saving the address book. + * This method is called by an error handler if the application + * crashed */ - QString fileName() const; + virtual void cleanUp(); /** - * Remove a addressee from its source. - * This method is mainly called by KABC::AddressBook. + * This method returns the number of elements that are currently in the resource. */ - virtual void removeAddressee( const Addressee& addr ); + virtual int count() const; /** - * This method is called by an error handler if the application - * crashed + * This method removes all elements from the resource!! (Not from the addressbook) */ - virtual void cleanUp(); + virtual bool clear(); @@ -138,6 +144,5 @@ protected: private: + AddressBookAccess* mAccess; QtopiaConverter* mConverter; - QString mFileName; - QString mLockUniqueName; diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 31b99ca..7b909de 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -2,3 +2,3 @@ This file is part of libkabc. - Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> + Copyright (c) 2004 Ulf Schenk @@ -64,4 +64,4 @@ extern "C" -ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) - : Resource( config ), mConverter (0) +ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) + : Resource( config, syncable ), mConverter (0) { @@ -73,4 +73,4 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) -ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) - : Resource( 0 ) +ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) + : Resource( 0, syncable ) { @@ -357 +357,26 @@ void ResourceSharpDTM::cleanUp() +/** + * This method returns the number of elements that are currently in the resource. + */ +int ResourceSharpDTM::count() const +{ + if (mAccess != 0) + return mAccess->count(); + else + return 0; +} + + +/** + * This method removes all elements from the resource!! (Not from the addressbook) + */ +bool ResourceSharpDTM::clear() +{ + if (mAccess != 0) + return mAccess->deleteCard(0, SlZDataBase::AllCard ); + else + return false; +} + + + diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h index d2e2a52..f495e9d 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.h +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h @@ -2,3 +2,3 @@ This file is part of libkabc. - Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> + Copyright (c) 2004 Ulf Schenk @@ -58,3 +58,3 @@ public: */ - ResourceSharpDTM( const KConfig *cfg ); + ResourceSharpDTM( const KConfig *cfg, bool syncable ); @@ -63,3 +63,3 @@ public: */ - ResourceSharpDTM( const QString &fileName ); + ResourceSharpDTM( const QString &fileName, bool syncable ); @@ -106,22 +106,28 @@ public: /** + * Remove a addressee from its source. + * This method is mainly called by KABC::AddressBook. + */ + virtual void removeAddressee( const Addressee& addr ); + + /** * Set name of file to be used for saving. */ - void setFileName( const QString & ); + virtual void setFileName( const QString & ); /** - * Return name of file used for loading and saving the address book. + * This method is called by an error handler if the application + * crashed */ - QString fileName() const; + virtual void cleanUp(); /** - * Remove a addressee from its source. - * This method is mainly called by KABC::AddressBook. + * This method returns the number of elements that are currently in the resource. */ - virtual void removeAddressee( const Addressee& addr ); + virtual int count() const; /** - * This method is called by an error handler if the application - * crashed + * This method removes all elements from the resource!! (Not from the addressbook) */ - virtual void cleanUp(); + virtual bool clear(); + @@ -139,4 +145,2 @@ private: - QString mFileName; - QString mLockUniqueName; diff --git a/kabc/plugins/sharpdtm/sharpdtmE.pro b/kabc/plugins/sharpdtm/sharpdtmE.pro index 54ef083..52bc10f 100644 --- a/kabc/plugins/sharpdtm/sharpdtmE.pro +++ b/kabc/plugins/sharpdtm/sharpdtmE.pro @@ -4,3 +4,3 @@ TARGET = microkabc_sharpdtm -INCLUDEPATH += ../.. $(SHARPDTMSDK)/include ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include +INCLUDEPATH += ../.. $(SHARPDTMSDK)/include ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include |