-rw-r--r-- | kabc/addressbook.cpp | 17 | ||||
-rw-r--r-- | kabc/addressbook.h | 6 | ||||
-rw-r--r-- | kabc/kabc.pro | 4 | ||||
-rw-r--r-- | kabc/kabcE.pro | 7 | ||||
-rw-r--r-- | kabc/resource.cpp | 63 | ||||
-rw-r--r-- | kabc/resource.h | 56 |
6 files changed, 135 insertions, 18 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 0838157..20310a0 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -203,54 +203,61 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) return *this; } bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) { return ( d->mIt == it.d->mIt ); } bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) { return ( d->mIt != it.d->mIt ); } AddressBook::AddressBook() { - init(0); + init(0, "contact"); } AddressBook::AddressBook( const QString &config ) { - init(config); + init(config, "contact"); } -void AddressBook::init(const QString &config) +AddressBook::AddressBook( const QString &config, const QString &family ) +{ + init(config, family); + +} + +// the default family is "contact" +void AddressBook::init(const QString &config, const QString &family ) { d = new AddressBookData; if (config != 0) { d->mConfig = new KConfig( config ); // qDebug("AddressBook::init 1 config=%s",config.latin1() ); } else { d->mConfig = 0; // qDebug("AddressBook::init 1 config=0"); } //US d->mErrorHandler = 0; - d->mManager = new KRES::Manager<Resource>( "contact" ); + d->mManager = new KRES::Manager<Resource>( family, false ); d->mManager->readConfig( d->mConfig ); } AddressBook::~AddressBook() { delete d->mConfig; d->mConfig = 0; delete d->mManager; d->mManager = 0; //US delete d->mErrorHandler; d->mErrorHandler = 0; delete d; d = 0; } bool AddressBook::load() { clear(); @@ -528,34 +535,32 @@ QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) if (!ab.d) return s; return s << ab.d->mAddressees; } QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) { if (!ab.d) return s; s >> ab.d->mAddressees; return s; } bool AddressBook::addResource( Resource *resource ) { - qDebug("AddressBook::addResource 1"); - if ( !resource->open() ) { kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; return false; } resource->setAddressBook( this ); d->mManager->add( resource ); return true; } bool AddressBook::removeResource( Resource *resource ) { resource->close(); if ( resource == standardResource() ) diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 3a8e028..f89d7da 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -103,32 +103,33 @@ class AddressBook : public QObject ConstIterator &operator--(); ConstIterator &operator--(int); bool operator==( const ConstIterator &it ); bool operator!=( const ConstIterator &it ); struct ConstIteratorData; ConstIteratorData *d; }; /** Constructs a address book object. @param format File format class. */ AddressBook(); AddressBook( const QString &config ); + AddressBook( const QString &config, const QString &family ); virtual ~AddressBook(); /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); @@ -295,33 +296,32 @@ class AddressBook : public QObject /** Emitted, when the address book has been locked for writing. */ void addressBookLocked( AddressBook * ); /** Emitted, when the address book has been unlocked. */ void addressBookUnlocked( AddressBook * ); protected: void deleteRemovedAddressees(); void setStandardResource( Resource * ); Resource *standardResource(); KRES::Manager<Resource> *resourceManager(); + void init(const QString &config, const QString &family); + private: //US QPtrList<Resource> mDummy; // Remove in KDE 4 -//US optimization - void init(const QString &config); - struct AddressBookData; AddressBookData *d; }; QDataStream &operator<<( QDataStream &, const AddressBook & ); QDataStream &operator>>( QDataStream &, AddressBook & ); } #endif diff --git a/kabc/kabc.pro b/kabc/kabc.pro index a8cd695..10b092c 100644 --- a/kabc/kabc.pro +++ b/kabc/kabc.pro @@ -1,26 +1,26 @@ TEMPLATE = lib CONFIG += qt warn_on #release debug DESTDIR=../bin TARGET = microkabc include( ../variables.pri ) -INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kio/kfile ../microkde/kio/kio ../qtcompat ../microkde/kdeui +INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim ../qtcompat ../microkde/kdeui #LIBS += -lmicrokde -lldap LIBS += -L$(QPEDIR)/lib DEFINES += KAB_EMBEDDED DESKTOP_VERSION unix : { OBJECTS_DIR = obj/unix MOC_DIR = moc/unix } win32: { DEFINES += _WIN32_ OBJECTS_DIR = obj/win MOC_DIR = moc/win } INTERFACES = \ @@ -35,32 +35,33 @@ HEADERS = \ plugin.h \ address.h \ addresseelist.h \ formatfactory.h \ formatplugin.h \ phonenumber.h \ distributionlist.h \ distributionlistdialog.h \ distributionlisteditor.h \ vcardformatplugin.h \ formats/vcardformatplugin2.h \ picture.h \ secrecy.h \ sound.h \ addressbook.h \ timezone.h \ + tmpaddressbook.h \ addressee.h \ addresseedialog.h \ vcardconverter.h \ vcard21parser.h \ vcardformatimpl.h \ plugins/file/resourcefile.h \ plugins/file/resourcefileconfig.h \ plugins/dir/resourcedir.h \ plugins/dir/resourcedirconfig.h \ vcardparser/vcardline.h \ vcardparser/vcard.h \ vcardparser/vcardtool.h \ vcardparser/vcardparser.h \ vcard/include/VCardAdrParam.h \ vcard/include/VCardAdrValue.h \ vcard/include/VCardAgentParam.h \ @@ -144,32 +145,33 @@ vcardformatplugin.cpp \ formats/vcardformatplugin2.cpp \ formatfactory.cpp \ resource.cpp \ stdaddressbook.cpp \ plugin.cpp \ agent.cpp \ geo.cpp \ key.cpp \ field.cpp \ address.cpp \ phonenumber.cpp \ picture.cpp \ secrecy.cpp \ sound.cpp \ addressbook.cpp \ timezone.cpp \ + tmpaddressbook.cpp \ addressee.cpp \ addresseelist.cpp \ addresseedialog.cpp \ vcardconverter.cpp \ vcard21parser.cpp \ vcardformatimpl.cpp \ plugins/file/resourcefile.cpp \ plugins/file/resourcefileconfig.cpp \ plugins/dir/resourcedir.cpp \ plugins/dir/resourcedirconfig.cpp \ vcardparser/vcardline.cpp \ vcardparser/vcard.cpp \ vcardparser/vcardtool.cpp \ vcardparser/vcardparser.cpp \ vcard/AdrParam.cpp \ vcard/AdrValue.cpp \ diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro index bc1c0ed..598d4fc 100644 --- a/kabc/kabcE.pro +++ b/kabc/kabcE.pro @@ -1,55 +1,58 @@ TEMPLATE = lib CONFIG += qt warn_on TARGET = microkabc -INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../qtcompat $(QPEDIR)/include +INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim ../qtcompat $(QPEDIR)/include OBJECTS_DIR = obj/$(PLATFORM) MOC_DIR = moc/$(PLATFORM) DESTDIR = $(QPEDIR)/lib LIBS += -lmicrokde +LIBS += -lmicrokdepim #LIBS += -lldap LIBS += -L$(QPEDIR)/lib DEFINES += KAB_EMBEDDED INTERFACES = \ HEADERS = \ address.h \ addressbook.h \ addressee.h \ addresseedialog.h \ addresseelist.h \ agent.h \ distributionlist.h \ distributionlistdialog.h \ distributionlisteditor.h \ field.h \ formatfactory.h \ formatplugin.h \ geo.h \ key.h \ phonenumber.h \ picture.h \ plugin.h \ resource.h \ secrecy.h \ sound.h \ stdaddressbook.h \ + syncprefwidget.h \ timezone.h \ + tmpaddressbook.h \ vcardconverter.h \ vcard21parser.h \ vcardformatimpl.h \ vcardformatplugin.h \ vcardparser/vcardline.h \ vcardparser/vcard.h \ vcardparser/vcardtool.h \ vcardparser/vcardparser.h \ vcard/include/VCardAdrParam.h \ vcard/include/VCardAdrValue.h \ vcard/include/VCardAgentParam.h \ vcard/include/VCardContentLine.h \ vcard/include/VCardDateParam.h \ vcard/include/VCardDateValue.h \ vcard/include/VCardEmailParam.h \ vcard/include/VCardGeoValue.h \ @@ -125,33 +128,35 @@ SOURCES = \ addresseelist.cpp \ agent.cpp \ distributionlist.cpp \ distributionlistdialog.cpp \ distributionlisteditor.cpp \ field.cpp \ formatfactory.cpp \ geo.cpp \ key.cpp \ phonenumber.cpp \ picture.cpp \ plugin.cpp \ resource.cpp \ secrecy.cpp \ sound.cpp \ stdaddressbook.cpp \ + syncprefwidget.cpp \ timezone.cpp \ + tmpaddressbook.cpp \ vcardconverter.cpp \ vcard21parser.cpp \ vcardformatimpl.cpp \ vcardformatplugin.cpp \ vcardparser/vcardline.cpp \ vcardparser/vcard.cpp \ vcardparser/vcardtool.cpp \ vcardparser/vcardparser.cpp \ vcard/AdrParam.cpp \ vcard/AdrValue.cpp \ vcard/AgentParam.cpp \ vcard/ContentLine.cpp \ vcard/DateParam.cpp \ vcard/DateValue.cpp \ vcard/EmailParam.cpp \ vcard/Entity.cpp \ diff --git a/kabc/resource.cpp b/kabc/resource.cpp index 9a1a5f8..9632a3f 100644 --- a/kabc/resource.cpp +++ b/kabc/resource.cpp @@ -14,50 +14,64 @@ You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <kdebug.h> +#include <ksyncprofile.h> + #include "resource.h" using namespace KABC; -Resource::Resource( const KConfig *config ) - : KRES::Resource( config ), mAddressBook( 0 ) +Resource::Resource( const KConfig *config, bool syncable ) + : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 ) { + if(syncable == true) { + mSyncProfile = new KSyncProfile( identifier() ); + mSyncProfile->setName(resourceName()); + mSyncProfile->readConfig( (KConfig *)config ); + } } Resource::~Resource() { + if (mSyncProfile != 0) { + delete mSyncProfile; + } } void Resource::writeConfig( KConfig *config ) { KRES::Resource::writeConfig( config ); + + if(mSyncProfile != 0) + mSyncProfile->writeConfig( config ); } + void Resource::setAddressBook( AddressBook *ab ) { mAddressBook = ab; } AddressBook *Resource::addressBook() { return mAddressBook; } bool Resource::doOpen() { return true; } void Resource::doClose() @@ -80,16 +94,61 @@ bool Resource::save( Ticket * ) } Ticket *Resource::createTicket( Resource *resource ) { return new Ticket( resource ); } void Resource::removeAddressee( const Addressee& ) { // do nothing } void Resource::cleanUp() { // do nothing } + +bool Resource::isSyncable() const +{ + return (mSyncProfile != 0); +} + +/** + * This method returns the number of elements that are currently in the resource. + */ +int Resource::count() const +{ + return 0; +} + +/** + * This method removes all elements from the resource!! (Not from the addressbook) + */ +bool Resource::clear() +{ + return false; +} + +QString Resource::fileName() const +{ + return mFileName; +} + +void Resource::setFileName( const QString &fileName ) +{ + mFileName = fileName; +} + +/** + * Set the name of resource.You can override this method, + * but also remember to call Resource::setResourceName(). + */ +void Resource::setResourceName( const QString &name ) +{ + KRES::Resource::setResourceName(name); + if(mSyncProfile != 0) { + mSyncProfile->setName( name ); + } + +} + diff --git a/kabc/resource.h b/kabc/resource.h index c363125..db806a6 100644 --- a/kabc/resource.h +++ b/kabc/resource.h @@ -17,118 +17,164 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_RESOURCE_H #define KABC_RESOURCE_H #include <kresources/resource.h> + #include "addressbook.h" +class KSyncProfile; + namespace KABC { /** * @short Helper class for handling coordinated save of address books. * * This class is used as helper class for saving address book. * @see requestSaveTicket(), save(). */ class Ticket { friend class Resource; public: Resource *resource() { return mResource; } private: Ticket( Resource *resource ) : mResource( resource ) {} Resource *mResource; }; /** * @internal */ class Resource : public KRES::Resource { +private: + /** + * make this constructor private to force everybody to use the other one + */ + Resource( const KConfig *config); + public: /** * Constructor */ - Resource( const KConfig *config ); + Resource( const KConfig *config, bool syncable ); /** * Destructor. */ virtual ~Resource(); /** * Sets the address book of the resource. */ void setAddressBook( AddressBook* ); /** * Returns a pointer to the addressbook. */ AddressBook *addressBook(); /** * Writes the resource specific config to file. */ virtual void writeConfig( KConfig *config ); /** * Open the resource and returns if it was successfully */ virtual bool doOpen(); - /** - * Close the resource and returns if it was successfully - */ - virtual void doClose(); /** * Request a ticket, you have to pass through @ref save() to * allow locking. */ virtual Ticket *requestSaveTicket(); /** * Load all addressees to the addressbook */ virtual bool load(); /** * Save all addressees to the addressbook. * * @param ticket The ticket you get by @ref requestSaveTicket() */ virtual bool save( Ticket *ticket ); /** * Removes a addressee from resource. This method is mainly * used by record-based resources like LDAP or SQL. */ virtual void removeAddressee( const Addressee& addr ); + /** * This method is called by an error handler if the application * crashed */ virtual void cleanUp(); + + /** + * 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(); + + /** + * Set name of file to be used for saving. + */ + virtual void setFileName( const QString & ); + + /** + * Return name of file used for loading and saving the address book. + */ + virtual QString fileName() const; + + + virtual bool isSyncable() const; + + /** + * Set the name of resource.You can override this method, + * but also remember to call Resource::setResourceName(). + */ + virtual void setResourceName( const QString &name ); + + + protected: Ticket *createTicket( Resource * ); + virtual void doClose(); private: AddressBook *mAddressBook; + KSyncProfile *mSyncProfile; + QString mFileName; + }; + } + + + #endif |