summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-02 18:33:07 (UTC)
committer ulf69 <ulf69>2004-08-02 18:33:07 (UTC)
commit60a6886f06be31ec690df34dc8e3b8931c2d3bd7 (patch) (side-by-side diff)
treec4c7c15cfd3753a3342806a11fb8f5c20bb4f923
parent863c4c3678e59ef125c08c00e9532ded5b540f67 (diff)
downloadkdepimpi-60a6886f06be31ec690df34dc8e3b8931c2d3bd7.zip
kdepimpi-60a6886f06be31ec690df34dc8e3b8931c2d3bd7.tar.gz
kdepimpi-60a6886f06be31ec690df34dc8e3b8931c2d3bd7.tar.bz2
added support for syncable resources
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp35
-rw-r--r--kabc/addressbook.h30
-rw-r--r--kabc/kabc.pro4
-rw-r--r--kabc/kabcE.pro7
-rw-r--r--kabc/resource.cpp63
-rw-r--r--kabc/resource.h66
6 files changed, 161 insertions, 44 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 0838157..20310a0 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -215,17 +215,24 @@ bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
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 );
@@ -234,11 +241,11 @@ void AddressBook::init(const QString &config)
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()
@@ -250,9 +257,9 @@ AddressBook::~AddressBook()
}
bool AddressBook::load()
{
-
+
clear();
KRES::Manager<Resource>::ActiveIterator it;
@@ -276,9 +283,9 @@ bool AddressBook::save( Ticket *ticket )
kdDebug(5700) << "AddressBook::save()"<< endl;
if ( ticket->resource() ) {
deleteRemovedAddressees();
-
+
return ticket->resource()->save( ticket );
}
return false;
@@ -355,9 +362,9 @@ void AddressBook::insertAddressee( const Addressee &a )
(*it).setResource( standardResource() );
if ( changed ) {
(*it).setRevision( QDateTime::currentDateTime() );
- (*it).setChanged( true );
+ (*it).setChanged( true );
}
return;
}
@@ -434,9 +441,9 @@ Addressee::List AddressBook::findByEmail( const QString &email )
QStringList mailList;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
- mailList = (*it).emails();
+ mailList = (*it).emails();
for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
if ( email == (*ite) ) {
results.append( *it );
}
@@ -490,17 +497,17 @@ Field::List AddressBook::fields( int category )
{
if ( d->mAllFields.isEmpty() ) {
d->mAllFields = Field::allFields();
}
-
+
if ( category == Field::All ) return d->mAllFields;
-
+
Field::List result;
Field::List::ConstIterator it;
for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
if ( (*it)->category() & category ) result.append( *it );
}
-
+
return result;
}
bool AddressBook::addCustomField( const QString &label, int category,
@@ -540,10 +547,8 @@ QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
}
bool AddressBook::addResource( Resource *resource )
{
- qDebug("AddressBook::addResource 1");
-
if ( !resource->open() ) {
kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
return false;
}
@@ -571,9 +576,9 @@ QPtrList<Resource> AddressBook::resources()
{
QPtrList<Resource> list;
// qDebug("AddressBook::resources() 1");
-
+
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
list.append( *it );
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 3a8e028..f89d7da 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -43,9 +43,9 @@ class Resource;
class Ticket;
/**
@short Address Book
-
+
This class provides access to a collection of address book entries.
*/
class AddressBook : public QObject
{
@@ -57,9 +57,9 @@ class AddressBook : public QObject
public:
/**
@short Address Book Iterator
-
+
This class provides an iterator for address book entries.
*/
class Iterator
{
@@ -84,18 +84,18 @@ class AddressBook : public QObject
};
/**
@short Address Book Const Iterator
-
+
This class provides a const iterator for address book entries.
*/
class ConstIterator
{
public:
ConstIterator();
ConstIterator( const ConstIterator & );
~ConstIterator();
-
+
ConstIterator &operator=( const ConstIterator & );
const Addressee &operator*() const;
const Addressee* operator->() const;
ConstIterator &operator++();
@@ -107,37 +107,38 @@ class AddressBook : public QObject
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();
/**
Save address book. The address book is saved to the file, the Ticket
object has been requested for by @ref requestSaveTicket().
-
+
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
@@ -164,9 +165,9 @@ class AddressBook : public QObject
/**
Removes all entries from address book.
*/
void clear();
-
+
/**
Insert an Addressee object into address book. If an object with the same
unique id already exists in the address book it it replaced by the new
one. If not the new object is appended to the address book.
@@ -242,9 +243,9 @@ class AddressBook : public QObject
Field::List fields( int category = Field::All );
/**
Add custom field to address book.
-
+
@param label User visible label of the field.
@param category Ored list of field categories.
@param key Identifier used as key for reading and writing the field.
@param app String used as application key for reading and writing
@@ -253,9 +254,9 @@ class AddressBook : public QObject
bool addCustomField( const QString &label, int category = Field::All,
const QString &key = QString::null,
const QString &app = QString::null );
-
+
/**
Add address book resource.
*/
bool addResource( Resource * );
@@ -307,14 +308,13 @@ class AddressBook : public QObject
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;
};
diff --git a/kabc/kabc.pro b/kabc/kabc.pro
index a8cd695..10b092c 100644
--- a/kabc/kabc.pro
+++ b/kabc/kabc.pro
@@ -6,9 +6,9 @@ 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
@@ -47,8 +47,9 @@ formats/vcardformatplugin2.h \
secrecy.h \
sound.h \
addressbook.h \
timezone.h \
+ tmpaddressbook.h \
addressee.h \
addresseedialog.h \
vcardconverter.h \
vcard21parser.h \
@@ -156,8 +157,9 @@ formatfactory.cpp \
secrecy.cpp \
sound.cpp \
addressbook.cpp \
timezone.cpp \
+ tmpaddressbook.cpp \
addressee.cpp \
addresseelist.cpp \
addresseedialog.cpp \
vcardconverter.cpp \
diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro
index bc1c0ed..598d4fc 100644
--- a/kabc/kabcE.pro
+++ b/kabc/kabcE.pro
@@ -2,13 +2,14 @@ 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
@@ -35,9 +36,11 @@ HEADERS = \
resource.h \
secrecy.h \
sound.h \
stdaddressbook.h \
+ syncprefwidget.h \
timezone.h \
+ tmpaddressbook.h \
vcardconverter.h \
vcard21parser.h \
vcardformatimpl.h \
vcardformatplugin.h \
@@ -137,9 +140,11 @@ SOURCES = \
resource.cpp \
secrecy.cpp \
sound.cpp \
stdaddressbook.cpp \
+ syncprefwidget.cpp \
timezone.cpp \
+ tmpaddressbook.cpp \
vcardconverter.cpp \
vcard21parser.cpp \
vcardformatimpl.cpp \
vcardformatplugin.cpp \
diff --git a/kabc/resource.cpp b/kabc/resource.cpp
index 9a1a5f8..9632a3f 100644
--- a/kabc/resource.cpp
+++ b/kabc/resource.cpp
@@ -26,26 +26,40 @@ $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;
}
@@ -92,4 +106,49 @@ void Resource::removeAddressee( const Addressee& )
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
@@ -29,15 +29,18 @@ $Id$
#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
@@ -45,24 +48,30 @@ class Ticket
friend class Resource;
public:
Resource *resource() { return mResource; }
- private:
+ 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.
*/
@@ -87,19 +96,15 @@ public:
* 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();
@@ -116,19 +121,60 @@ public:
* 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