From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kresources/scalix/shared/Makefile.am | 17 + kresources/scalix/shared/kmailconnection.cpp | 281 +++++++++++++++ kresources/scalix/shared/kmailconnection.h | 117 +++++++ kresources/scalix/shared/resourcescalixbase.cpp | 179 ++++++++++ kresources/scalix/shared/resourcescalixbase.h | 180 ++++++++++ kresources/scalix/shared/scalixbase.cpp | 446 ++++++++++++++++++++++++ kresources/scalix/shared/scalixbase.h | 176 ++++++++++ kresources/scalix/shared/subresource.cpp | 116 ++++++ kresources/scalix/shared/subresource.h | 110 ++++++ 9 files changed, 1622 insertions(+) create mode 100644 kresources/scalix/shared/Makefile.am create mode 100644 kresources/scalix/shared/kmailconnection.cpp create mode 100644 kresources/scalix/shared/kmailconnection.h create mode 100644 kresources/scalix/shared/resourcescalixbase.cpp create mode 100644 kresources/scalix/shared/resourcescalixbase.h create mode 100644 kresources/scalix/shared/scalixbase.cpp create mode 100644 kresources/scalix/shared/scalixbase.h create mode 100644 kresources/scalix/shared/subresource.cpp create mode 100644 kresources/scalix/shared/subresource.h (limited to 'kresources/scalix/shared') diff --git a/kresources/scalix/shared/Makefile.am b/kresources/scalix/shared/Makefile.am new file mode 100644 index 000000000..4aaa9304e --- /dev/null +++ b/kresources/scalix/shared/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/kresources/lib $(all_includes) + +noinst_HEADERS = resourcescalixbase.h scalixbase.h subresource.h + +noinst_LTLIBRARIES = libresourcescalixshared.la + +libresourcescalixshared_la_SOURCES = \ + resourcescalixbase.cpp kmailconnection.cpp scalixbase.cpp \ + subresource.cpp \ + kmailconnection.skel kmailicalIface.stub +libresourcescalixshared_la_METASOURCES = AUTO +libresourcescalixshared_la_LIBADD = $(top_builddir)/libkcal/libkcal.la $(top_builddir)/libkdepim/libkdepim.la ../../lib/libkgroupwaredav.la +libresourcescalixshared_la_LDFLAGS = -no-undefined + +kmailicalIface_DCOPIDLNG = true + +kmailicalIface_DIR = $(top_srcdir)/kmail diff --git a/kresources/scalix/shared/kmailconnection.cpp b/kresources/scalix/shared/kmailconnection.cpp new file mode 100644 index 000000000..af32cd74b --- /dev/null +++ b/kresources/scalix/shared/kmailconnection.cpp @@ -0,0 +1,281 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Bo Thorsen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "kmailconnection.h" +#include "resourcescalixbase.h" + +#include +#include +#include +#include +#include + +#include "kmailicalIface_stub.h" + + +using namespace Scalix; + + +KMailConnection::KMailConnection( ResourceScalixBase* resource, + const QCString& objId ) + : DCOPObject( objId ), mResource( resource ), mKMailIcalIfaceStub( 0 ) +{ + // Make the connection to KMail ready + mDCOPClient = new DCOPClient(); + mDCOPClient->attach(); + mDCOPClient->registerAs( objId, true ); + + kapp->dcopClient()->setNotifications( true ); + connect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString& ) ), + this, SLOT( unregisteredFromDCOP( const QCString& ) ) ); +} + +KMailConnection::~KMailConnection() +{ + kapp->dcopClient()->setNotifications( false ); + delete mKMailIcalIfaceStub; + mKMailIcalIfaceStub = 0; + delete mDCOPClient; + mDCOPClient = 0; +} + +static const QCString dcopObjectId = "KMailICalIface"; +bool KMailConnection::connectToKMail() +{ + if ( !mKMailIcalIfaceStub ) { + QString error; + QCString dcopService; + int result = KDCOPServiceStarter::self()-> + findServiceFor( "DCOP/ResourceBackend/IMAP", QString::null, + QString::null, &error, &dcopService ); + if ( result != 0 ) { + kdError(5650) << "Couldn't connect to the IMAP resource backend\n"; + // TODO: You might want to show "error" (if not empty) here, + // using e.g. KMessageBox + return false; + } + + mKMailIcalIfaceStub = new KMailICalIface_stub( kapp->dcopClient(), + dcopService, dcopObjectId ); + + // Attach to the KMail signals + if ( !connectKMailSignal( "incidenceAdded(QString,QString,Q_UINT32,int,QString)", + "fromKMailAddIncidence(QString,QString,Q_UINT32,int,QString)" ) ) + kdError(5650) << "DCOP connection to incidenceAdded failed" << endl; + if ( !connectKMailSignal( "incidenceDeleted(QString,QString,QString)", + "fromKMailDelIncidence(QString,QString,QString)" ) ) + kdError(5650) << "DCOP connection to incidenceDeleted failed" << endl; + if ( !connectKMailSignal( "signalRefresh(QString,QString)", + "fromKMailRefresh(QString,QString)" ) ) + kdError(5650) << "DCOP connection to signalRefresh failed" << endl; + if ( !connectKMailSignal( "subresourceAdded( QString, QString, QString )", + "fromKMailAddSubresource( QString, QString, QString )" ) ) + kdError(5650) << "DCOP connection to subresourceAdded failed" << endl; + if ( !connectKMailSignal( "subresourceDeleted(QString,QString)", + "fromKMailDelSubresource(QString,QString)" ) ) + kdError(5650) << "DCOP connection to subresourceDeleted failed" << endl; + if ( !connectKMailSignal( "asyncLoadResult(QMap, QString, QString)", + "fromKMailAsyncLoadResult(QMap, QString, QString)" ) ) + kdError(5650) << "DCOP connection to asyncLoadResult failed" << endl; + } + + return ( mKMailIcalIfaceStub != 0 ); +} + +bool KMailConnection::fromKMailAddIncidence( const QString& type, + const QString& folder, + Q_UINT32 sernum, + int format, + const QString& data ) +{ + if ( format != KMailICalIface::StorageXML + && format != KMailICalIface::StorageIcalVcard ) + return false; +// kdDebug(5650) << "KMailConnection::fromKMailAddIncidence( " << type << ", " +// << folder << " ). iCal:\n" << ical << endl; + return mResource->fromKMailAddIncidence( type, folder, sernum, format, data ); +} + +void KMailConnection::fromKMailDelIncidence( const QString& type, + const QString& folder, + const QString& xml ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailDelIncidence( " << type << ", " +// << folder << ", " << uid << " )\n"; + mResource->fromKMailDelIncidence( type, folder, xml ); +} + +void KMailConnection::fromKMailRefresh( const QString& type, const QString& folder ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailRefresh( " << type << ", " +// << folder << " )\n"; + mResource->fromKMailRefresh( type, folder ); +} + +void KMailConnection::fromKMailAddSubresource( const QString& type, + const QString& resource, + const QString& label ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailAddSubresource( " << type << ", " +// << resource << " )\n"; + bool writable = true; + + // TODO: This should be told by KMail right away + if ( connectToKMail() ) + writable = mKMailIcalIfaceStub->isWritableFolder( type, resource ); + + mResource->fromKMailAddSubresource( type, resource, label, writable ); +} + +void KMailConnection::fromKMailDelSubresource( const QString& type, + const QString& resource ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailDelSubresource( " << type << ", " +// << resource << " )\n"; + mResource->fromKMailDelSubresource( type, resource ); +} + +void KMailConnection::fromKMailAsyncLoadResult( const QMap& map, + const QString& type, + const QString& folder ) +{ + mResource->fromKMailAsyncLoadResult( map, type, folder ); +} + +bool KMailConnection::connectKMailSignal( const QCString& signal, + const QCString& method ) +{ + return connectDCOPSignal( "kmail", dcopObjectId, signal, method, false ) + && connectDCOPSignal( "kontact", dcopObjectId, signal, method, false ); +} + +bool KMailConnection::kmailSubresources( QValueList& lst, + const QString& contentsType ) +{ + if ( !connectToKMail() ) + return false; + + lst = mKMailIcalIfaceStub->subresourcesKolab( contentsType ); + return mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailIncidencesCount( int& count, + const QString& mimetype, + const QString& resource ) +{ + if ( !connectToKMail() ) + return false; + + count = mKMailIcalIfaceStub->incidencesKolabCount( mimetype, resource ); + return mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailIncidences( QMap& lst, + const QString& mimetype, + const QString& resource, + int startIndex, + int nbMessages ) +{ + if ( !connectToKMail() ) + return false; + + lst = mKMailIcalIfaceStub->incidencesKolab( mimetype, resource, startIndex, nbMessages ); + return mKMailIcalIfaceStub->ok(); +} + + +bool KMailConnection::kmailGetAttachment( KURL& url, + const QString& resource, + Q_UINT32 sernum, + const QString& filename ) +{ + if ( !connectToKMail() ) + return false; + + url = mKMailIcalIfaceStub->getAttachment( resource, sernum, filename ); + return mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailDeleteIncidence( const QString& resource, + Q_UINT32 sernum ) +{ + return connectToKMail() + && mKMailIcalIfaceStub->deleteIncidenceKolab( resource, sernum ) + && mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailUpdate( const QString& resource, + Q_UINT32& sernum, + const QString& subject, + const QString& plainTextBody, + const QMap& customHeaders, + const QStringList& attachmentURLs, + const QStringList& attachmentMimetypes, + const QStringList& attachmentNames, + const QStringList& deletedAttachments ) +{ + //kdDebug(5006) << kdBacktrace() << endl; + if ( connectToKMail() ) { + sernum = mKMailIcalIfaceStub->update( resource, sernum, subject, plainTextBody, customHeaders, + attachmentURLs, attachmentMimetypes, attachmentNames, + deletedAttachments ); + return sernum && mKMailIcalIfaceStub->ok(); + } else + return false; +} + +bool KMailConnection::kmailStorageFormat( KMailICalIface::StorageFormat& type, + const QString& folder ) +{ + bool ok = connectToKMail(); + type = mKMailIcalIfaceStub->storageFormat( folder ); + return ok && mKMailIcalIfaceStub->ok(); +} + + +bool KMailConnection::kmailTriggerSync( const QString &contentsType ) +{ + bool ok = connectToKMail(); + return ok && mKMailIcalIfaceStub->triggerSync( contentsType ); +} + +void KMailConnection::unregisteredFromDCOP( const QCString& appId ) +{ + if ( mKMailIcalIfaceStub && mKMailIcalIfaceStub->app() == appId ) { + // Delete the stub so that the next time we need to talk to kmail, + // we'll know that we need to start a new one. + delete mKMailIcalIfaceStub; + mKMailIcalIfaceStub = 0; + } +} + +#include "kmailconnection.moc" diff --git a/kresources/scalix/shared/kmailconnection.h b/kresources/scalix/shared/kmailconnection.h new file mode 100644 index 000000000..ea57857a8 --- /dev/null +++ b/kresources/scalix/shared/kmailconnection.h @@ -0,0 +1,117 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Bo Thorsen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef KMAILCONNECTION_H +#define KMAILCONNECTION_H + +#include +#include + +class KURL; +class DCOPClient; +class KMailICalIface_stub; + +namespace Scalix { + +class ResourceScalixBase; + +/** + This class provides the kmail connectivity for IMAP resources. +*/ +class KMailConnection : public QObject, public DCOPObject { + Q_OBJECT + K_DCOP + + // These are the methods called by KMail when the resource changes +k_dcop: + bool fromKMailAddIncidence( const QString& type, const QString& resource, + Q_UINT32 sernum, int format, const QString& xml ); + void fromKMailDelIncidence( const QString& type, const QString& resource, + const QString& xml ); + void fromKMailRefresh( const QString& type, const QString& resource ); + void fromKMailAddSubresource( const QString& type, const QString& resource, const QString& label ); + void fromKMailDelSubresource( const QString& type, const QString& resource ); + void fromKMailAsyncLoadResult( const QMap& map, const QString& type, + const QString& folder ); + +public: + KMailConnection( ResourceScalixBase* resource, const QCString& objId ); + virtual ~KMailConnection(); + + /** + * Do the connection to KMail. + */ + bool connectToKMail(); + + // Call the DCOP methods + bool kmailSubresources( QValueList& lst, + const QString& contentsType ); + bool kmailIncidencesCount( int& count, + const QString& mimetype, + const QString& resource ); + bool kmailIncidences( QMap& lst, const QString& mimetype, + const QString& resource, + int startIndex, + int nbMessages ); + + bool kmailGetAttachment( KURL& url, const QString& resource, Q_UINT32 sernum, + const QString& filename ); + bool kmailDeleteIncidence( const QString& resource, Q_UINT32 sernum ); + bool kmailUpdate( const QString& resource, + Q_UINT32& sernum, + const QString& subject, + const QString& plainTextBody, + const QMap& customHeaders, + const QStringList& attachmentURLs, + const QStringList& attachmentMimetypes, + const QStringList& attachmentNames, + const QStringList& deletedAttachments ); + + bool kmailStorageFormat( KMailICalIface::StorageFormat& type, const QString& folder); + + bool kmailTriggerSync( const QString& contentsType ); + +private slots: + virtual void unregisteredFromDCOP( const QCString& ); + +private: + /** Connect a signal from KMail to a local slot. */ + bool connectKMailSignal( const QCString&, const QCString& ); + + ResourceScalixBase* mResource; + DCOPClient* mDCOPClient; + KMailICalIface_stub* mKMailIcalIfaceStub; +}; + +} + +#endif // KMAILCONNECTION_H diff --git a/kresources/scalix/shared/resourcescalixbase.cpp b/kresources/scalix/shared/resourcescalixbase.cpp new file mode 100644 index 000000000..e91e58787 --- /dev/null +++ b/kresources/scalix/shared/resourcescalixbase.cpp @@ -0,0 +1,179 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Bo Thorsen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "resourcescalixbase.h" +#include "kmailconnection.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Scalix; + +static unsigned int uniquifier = 0; + +ResourceScalixBase::ResourceScalixBase( const QCString& objId ) + : mSilent( false ) +{ + KGlobal::locale()->insertCatalogue( "kres_scalix" ); + KGlobal::locale()->insertCatalogue( "libkcal" ); + QString uniqueObjId = QString( objId ) + QString::number( uniquifier++ ); + mConnection = new KMailConnection( this, uniqueObjId.utf8() ); +} + +ResourceScalixBase::~ResourceScalixBase() +{ + delete mConnection; +} + + +bool ResourceScalixBase::kmailSubresources( QValueList& lst, + const QString& contentsType ) const +{ + return mConnection->kmailSubresources( lst, contentsType ); +} + +bool ResourceScalixBase::kmailTriggerSync( const QString& contentsType ) const +{ + return mConnection->kmailTriggerSync( contentsType ); +} + + +bool ResourceScalixBase::kmailIncidencesCount( int &count, + const QString& mimetype, + const QString& resource ) const +{ + return mConnection->kmailIncidencesCount( count, mimetype, resource ); +} + +bool ResourceScalixBase::kmailIncidences( QMap& lst, + const QString& mimetype, + const QString& resource, + int startIndex, + int nbMessages ) const +{ + return mConnection->kmailIncidences( lst, mimetype, resource, startIndex, nbMessages ); +} + +bool ResourceScalixBase::kmailGetAttachment( KURL& url, const QString& resource, + Q_UINT32 sernum, + const QString& filename ) const +{ + return mConnection->kmailGetAttachment( url, resource, sernum, filename ); +} + +bool ResourceScalixBase::kmailDeleteIncidence( const QString& resource, + Q_UINT32 sernum ) +{ + return mSilent || mConnection->kmailDeleteIncidence( resource, sernum ); +} + +bool ResourceScalixBase::kmailUpdate( const QString& resource, + Q_UINT32& sernum, + const QString& xml, + const QString& mimetype, + const QString& subject, + const CustomHeaderMap& _customHeaders, + const QStringList& _attachmentURLs, + const QStringList& _attachmentMimetypes, + const QStringList& _attachmentNames, + const QStringList& deletedAttachments ) +{ + if ( mSilent ) + return true; + + QString subj = subject; + if ( subj.isEmpty() ) + subj = i18n("Internal kolab data: Do not delete this mail."); + + // ical style, simply put the data inline + return mConnection->kmailUpdate( resource, sernum, subj, xml, _customHeaders, + _attachmentURLs, _attachmentMimetypes, _attachmentNames, deletedAttachments ); +} + +QString ResourceScalixBase::configFile( const QString& type ) const +{ + return locateLocal( "config", + QString( "kresources/scalix/%1rc" ).arg( type ) ); +} + +bool ResourceScalixBase::connectToKMail() const +{ + return mConnection->connectToKMail(); +} + +QString ResourceScalixBase::findWritableResource( const ResourceMap& resources ) +{ + // I have to use the label (shown in the dialog) as key here. But given how the + // label is made up, it should be unique. If it's not, well the dialog would suck anyway... + QMap possible; + QStringList labels; + ResourceMap::ConstIterator it; + for ( it = resources.begin(); it != resources.end(); ++it ) { + if ( it.data().writable() && it.data().active() ) { + // Writable and active possibility + possible[ it.data().label() ] = it.key(); + } + } + + if ( possible.isEmpty() ) { // None found!! + kdWarning(5650) << "No writable resource found!" << endl; + KMessageBox::error( 0, i18n( "No writable resource was found, saving will not be possible. Reconfigure KMail first." ) ); + return QString::null; + } + if ( possible.count() == 1 ) + // Just one found + return possible.begin().data(); // yes this is the subresource key, i.e. location + + // Several found, ask the user + QString chosenLabel = KPIM::FolderSelectDialog::getItem( i18n( "Select Resource Folder" ), + i18n( "You have more than one writable resource folder. " + "Please select the one you want to write to." ), + possible.keys() ); + if ( chosenLabel.isEmpty() ) // cancelled + return QString::null; + return possible[chosenLabel]; +} + +KMailICalIface::StorageFormat ResourceScalixBase::kmailStorageFormat( const QString &folder ) const +{ + KMailICalIface::StorageFormat format = (KMailICalIface::StorageFormat) 3; + mConnection->kmailStorageFormat( format, folder ); + return format; +} diff --git a/kresources/scalix/shared/resourcescalixbase.h b/kresources/scalix/shared/resourcescalixbase.h new file mode 100644 index 000000000..3c32c1dfd --- /dev/null +++ b/kresources/scalix/shared/resourcescalixbase.h @@ -0,0 +1,180 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Bo Thorsen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef RESOURCESCALIXBASE_H +#define RESOURCESCALIXBASE_H + +#include +#include +#include + +#include "subresource.h" +#include + +class QCString; +class KURL; + +namespace Scalix { + +class KMailConnection; + +/** + This class provides the kmail connectivity for IMAP resources. + + The main methods are: + + fromKMail...() : calls made _by_ KMail to add/delete data representation in the resource. + + kmail...() : calls _into_ KMail made by the resource. + + e.g. fromKMailAddIncidence() is called by KMail + when a new iCard is there after an IMAP sync. + + By calling fromKMailAddIncidence() KMail notifies + the resource about the new incidence, so in the + addressbook a new address will appear like magic. + + e.g. kmailAddIncidence() is called by the resource when + iCard must be stored by KMail because the user has added + an address in the addressbook. + + By calling kmailAddIncidence() the resource causes + KMail to store the new address in the (IMAP) folder. +*/ +class ResourceScalixBase { +public: + ResourceScalixBase( const QCString& objId ); + virtual ~ResourceScalixBase(); + + // These are the methods called by KMail when the resource changes + virtual bool fromKMailAddIncidence( const QString& type, + const QString& resource, + Q_UINT32 sernum, + int format, + const QString& data ) = 0; + virtual void fromKMailDelIncidence( const QString& type, + const QString& resource, + const QString& xml ) = 0; + virtual void fromKMailRefresh( const QString& type, + const QString& resource ) = 0; + virtual void fromKMailAddSubresource( const QString& type, + const QString& resource, + const QString& label, + bool writable ) = 0; + virtual void fromKMailDelSubresource( const QString& type, + const QString& resource ) = 0; + + virtual void fromKMailAsyncLoadResult( const QMap& map, + const QString& type, + const QString& folder ) = 0; +protected: + /// Do the connection to KMail. + bool connectToKMail() const; + + // These are the KMail dcop function connections. The docs here say + // "Get", which here means that the first argument is the return arg + + /// List all folders with a certain contentsType. Returns a QMap with + /// resourcename/writable pairs + bool kmailSubresources( QValueList& lst, + const QString& contentsType ) const; + + /// Get the number of messages in this folder. + /// Used to iterate over kmailIncidences by chunks + bool kmailIncidencesCount( int& count, const QString& mimetype, + const QString& resource ) const; + + /// Get the mimetype attachments from a chunk of messages from this folder. + /// Returns a QMap with serialNumber/attachment pairs. + bool kmailIncidences( QMap& lst, const QString& mimetype, + const QString& resource, + int startIndex, + int nbMessages ) const; + + bool kmailTriggerSync( const QString& contentType ) const; + +public: // for Contact + /// Get an attachment from a mail. Returns a URL to it. This can + /// be called by the resource after obtaining the incidence. + /// The resource must delete the temp file. + bool kmailGetAttachment( KURL& url, const QString& resource, + Q_UINT32 sernum, + const QString& filename ) const; + +protected: + /// Delete an incidence. + bool kmailDeleteIncidence( const QString& resource, Q_UINT32 sernum ); + + KMailICalIface::StorageFormat kmailStorageFormat( const QString& folder ) const; + + typedef QMap CustomHeaderMap; + + /// Update an incidence. The list of attachments are URLs. + /// The parameter sernum is updated with the right KMail serial number + bool kmailUpdate( const QString& resource, Q_UINT32& sernum, + const QString& xml, + const QString& mimetype, + const QString& subject, + const CustomHeaderMap& customHeaders = CustomHeaderMap(), + const QStringList& attachmentURLs = QStringList(), + const QStringList& attachmentMimetypes = QStringList(), + const QStringList& attachmentNames = QStringList(), + const QStringList& deletedAttachments = QStringList() ); + + /// Get the full path of the config file. + QString configFile( const QString& type ) const; + + /// If only one of these is writable, return that. Otherwise return null. + QString findWritableResource( const ResourceMap& resources ); + + bool mSilent; + + /** + * This is used to store a mapping from the XML UID to the KMail + * serial number of the mail it's stored in. That provides a quick way + * to access the storage in KMail. + */ + UidMap mUidMap; + + /// This is used to distinguish operations triggered by the user, + /// from operations triggered by KMail + QStringList mUidsPendingAdding; + QStringList mUidsPendingDeletion; + QStringList mUidsPendingUpdate; + +private: + mutable KMailConnection* mConnection; +}; + +} + +#endif // RESOURCEKOLABBASE_H diff --git a/kresources/scalix/shared/scalixbase.cpp b/kresources/scalix/shared/scalixbase.cpp new file mode 100644 index 000000000..ab38500e2 --- /dev/null +++ b/kresources/scalix/shared/scalixbase.cpp @@ -0,0 +1,446 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Bo Thorsen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "scalixbase.h" + +#include +#include +#include +#include +#include + +using namespace Scalix; + + +ScalixBase::ScalixBase( const QString& tz ) + : mCreationDate( QDateTime::currentDateTime() ), + mLastModified( QDateTime::currentDateTime() ), + mSensitivity( Public ), mTimeZoneId( tz ), + mHasPilotSyncId( false ), mHasPilotSyncStatus( false ) +{ +} + +ScalixBase::~ScalixBase() +{ +} + +void ScalixBase::setFields( const KCal::Incidence* incidence ) +{ + // So far unhandled KCal::IncidenceBase fields: + // mPilotID, mSyncStatus, mFloats + + setUid( incidence->uid() ); + setBody( incidence->description() ); + setCategories( incidence->categoriesStr() ); + setCreationDate( localToUTC( incidence->created() ) ); + setLastModified( localToUTC( incidence->lastModified() ) ); + setSensitivity( static_cast( incidence->secrecy() ) ); + // TODO: Attachments +} + +void ScalixBase::saveTo( KCal::Incidence* incidence ) const +{ + incidence->setUid( uid() ); + incidence->setDescription( body() ); + incidence->setCategories( categories() ); + incidence->setCreated( utcToLocal( creationDate() ) ); + incidence->setLastModified( utcToLocal( lastModified() ) ); + incidence->setSecrecy( sensitivity() ); + // TODO: Attachments +} + +void ScalixBase::setFields( const KABC::Addressee* addressee ) +{ + // An addressee does not have a creation date, so somehow we should + // make one, if this is a new entry + + setUid( addressee->uid() ); + setBody( addressee->note() ); + setCategories( addressee->categories().join( "," ) ); + + // Set creation-time and last-modification-time + const QString creationString = addressee->custom( "KOLAB", "CreationDate" ); + kdDebug(5006) << "Creation time string: " << creationString << endl; + QDateTime creationDate; + if ( creationString.isEmpty() ) { + creationDate = QDateTime::currentDateTime(); + kdDebug(5006) << "Creation date set to current time\n"; + } + else { + creationDate = stringToDateTime( creationString ); + kdDebug(5006) << "Creation date loaded\n"; + } + QDateTime modified = addressee->revision(); + if ( !modified.isValid() ) + modified = QDateTime::currentDateTime(); + setLastModified( modified ); + if ( modified < creationDate ) { + // It's not possible that the modification date is earlier than creation + creationDate = modified; + kdDebug(5006) << "Creation date set to modification date\n"; + } + setCreationDate( creationDate ); + const QString newCreationDate = dateTimeToString( creationDate ); + if ( creationString != newCreationDate ) { + // We modified the creation date, so store it for future reference + const_cast( addressee ) + ->insertCustom( "KOLAB", "CreationDate", newCreationDate ); + kdDebug(5006) << "Creation date modified. New one: " << newCreationDate << endl; + } + + switch( addressee->secrecy().type() ) { + case KABC::Secrecy::Private: + setSensitivity( Private ); + break; + case KABC::Secrecy::Confidential: + setSensitivity( Confidential ); + break; + default: + setSensitivity( Public ); + } + + // TODO: Attachments +} + +void ScalixBase::saveTo( KABC::Addressee* addressee ) const +{ + addressee->setUid( uid() ); + addressee->setNote( body() ); + addressee->setCategories( QStringList::split( ',', categories() ) ); + addressee->setRevision( lastModified() ); + addressee->insertCustom( "KOLAB", "CreationDate", + dateTimeToString( creationDate() ) ); + + switch( sensitivity() ) { + case Private: + addressee->setSecrecy( KABC::Secrecy( KABC::Secrecy::Private ) ); + break; + case Confidential: + addressee->setSecrecy( KABC::Secrecy( KABC::Secrecy::Confidential ) ); + break; + default: + addressee->setSecrecy( KABC::Secrecy( KABC::Secrecy::Public ) ); + break; + } + + // TODO: Attachments +} + +void ScalixBase::setUid( const QString& uid ) +{ + mUid = uid; +} + +QString ScalixBase::uid() const +{ + return mUid; +} + +void ScalixBase::setBody( const QString& body ) +{ + mBody = body; +} + +QString ScalixBase::body() const +{ + return mBody; +} + +void ScalixBase::setCategories( const QString& categories ) +{ + mCategories = categories; +} + +QString ScalixBase::categories() const +{ + return mCategories; +} + +void ScalixBase::setCreationDate( const QDateTime& date ) +{ + mCreationDate = date; +} + +QDateTime ScalixBase::creationDate() const +{ + return mCreationDate; +} + +void ScalixBase::setLastModified( const QDateTime& date ) +{ + mLastModified = date; +} + +QDateTime ScalixBase::lastModified() const +{ + return mLastModified; +} + +void ScalixBase::setSensitivity( Sensitivity sensitivity ) +{ + mSensitivity = sensitivity; +} + +ScalixBase::Sensitivity ScalixBase::sensitivity() const +{ + return mSensitivity; +} + +void ScalixBase::setPilotSyncId( unsigned long id ) +{ + mHasPilotSyncId = true; + mPilotSyncId = id; +} + +bool ScalixBase::hasPilotSyncId() const +{ + return mHasPilotSyncId; +} + +unsigned long ScalixBase::pilotSyncId() const +{ + return mPilotSyncId; +} + +void ScalixBase::setPilotSyncStatus( int status ) +{ + mHasPilotSyncStatus = true; + mPilotSyncStatus = status; +} + +bool ScalixBase::hasPilotSyncStatus() const +{ + return mHasPilotSyncStatus; +} + +int ScalixBase::pilotSyncStatus() const +{ + return mPilotSyncStatus; +} + +bool ScalixBase::loadEmailAttribute( QDomElement& element, Email& email ) +{ + for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + QDomElement e = n.toElement(); + QString tagName = e.tagName(); + + if ( tagName == "display-name" ) + email.displayName = e.text(); + else if ( tagName == "smtp-address" ) + email.smtpAddress = e.text(); + else + // TODO: Unhandled tag - save for later storage + kdDebug() << "Warning: Unhandled tag " << e.tagName() << endl; + } else + kdDebug() << "Node is not a comment or an element???" << endl; + } + + return true; +} + +void ScalixBase::saveEmailAttribute( QDomElement& element, const Email& email, + const QString& tagName ) const +{ + QDomElement e = element.ownerDocument().createElement( tagName ); + element.appendChild( e ); + writeString( e, "display-name", email.displayName ); + writeString( e, "smtp-address", email.smtpAddress ); +} + +bool ScalixBase::loadAttribute( QDomElement& element ) +{ + QString tagName = element.tagName(); + + if ( tagName == "uid" ) + setUid( element.text() ); + else if ( tagName == "body" ) + setBody( element.text() ); + else if ( tagName == "categories" ) + setCategories( element.text() ); + else if ( tagName == "creation-date" ) + setCreationDate( stringToDateTime( element.text() ) ); + else if ( tagName == "last-modification-date" ) + setLastModified( stringToDateTime( element.text() ) ); + else if ( tagName == "sensitivity" ) + setSensitivity( stringToSensitivity( element.text() ) ); + else if ( tagName == "product-id" ) + return true; // ignore this field + else if ( tagName == "pilot-sync-id" ) + setPilotSyncId( element.text().toULong() ); + else if ( tagName == "pilot-sync-status" ) + setPilotSyncStatus( element.text().toInt() ); + else + return false; + + // Handled here + return true; +} + +bool ScalixBase::saveAttributes( QDomElement& element ) const +{ + writeString( element, "product-id", productID() ); + writeString( element, "uid", uid() ); + writeString( element, "body", body() ); + writeString( element, "categories", categories() ); + writeString( element, "creation-date", dateTimeToString( creationDate() ) ); + writeString( element, "last-modification-date", + dateTimeToString( lastModified() ) ); + writeString( element, "sensitivity", sensitivityToString( sensitivity() ) ); + if ( hasPilotSyncId() ) + writeString( element, "pilot-sync-id", QString::number( pilotSyncId() ) ); + if ( hasPilotSyncStatus() ) + writeString( element, "pilot-sync-status", QString::number( pilotSyncStatus() ) ); + return true; +} + +bool ScalixBase::load( const QString& xml ) +{ + QString errorMsg; + int errorLine, errorColumn; + QDomDocument document; + bool ok = document.setContent( xml, &errorMsg, &errorLine, &errorColumn ); + + if ( !ok ) { + qWarning( "Error loading document: %s, line %d, column %d", + errorMsg.latin1(), errorLine, errorColumn ); + return false; + } + + // XML file loaded into tree. Now parse it + return loadXML( document ); +} + +bool ScalixBase::load( QFile& xml ) +{ + QString errorMsg; + int errorLine, errorColumn; + QDomDocument document; + bool ok = document.setContent( &xml, &errorMsg, &errorLine, &errorColumn ); + + if ( !ok ) { + qWarning( "Error loading document: %s, line %d, column %d", + errorMsg.latin1(), errorLine, errorColumn ); + return false; + } + + // XML file loaded into tree. Now parse it + return loadXML( document ); +} + +QDomDocument ScalixBase::domTree() +{ + QDomDocument document; + + QString p = "version=\"1.0\" encoding=\"UTF-8\""; + document.appendChild(document.createProcessingInstruction( "xml", p ) ); + + return document; +} + + +QString ScalixBase::dateTimeToString( const QDateTime& time ) +{ + return time.toString( Qt::ISODate ) + 'Z'; +} + +QString ScalixBase::dateToString( const QDate& date ) +{ + return date.toString( Qt::ISODate ); +} + +QDateTime ScalixBase::stringToDateTime( const QString& _date ) +{ + QString date( _date ); + if ( date.endsWith( "Z" ) ) + date.truncate( date.length() - 1 ); + return QDateTime::fromString( date, Qt::ISODate ); +} + +QDate ScalixBase::stringToDate( const QString& date ) +{ + return QDate::fromString( date, Qt::ISODate ); +} + +QString ScalixBase::sensitivityToString( Sensitivity s ) +{ + switch( s ) { + case Private: return "private"; + case Confidential: return "confidential"; + case Public: return "public"; + } + + return "What what what???"; +} + +ScalixBase::Sensitivity ScalixBase::stringToSensitivity( const QString& s ) +{ + if ( s == "private" ) + return Private; + if ( s == "confidential" ) + return Confidential; + return Public; +} + +QString ScalixBase::colorToString( const QColor& color ) +{ + // Color is in the format "#RRGGBB" + return color.name(); +} + +QColor ScalixBase::stringToColor( const QString& s ) +{ + return QColor( s ); +} + +void ScalixBase::writeString( QDomElement& element, const QString& tag, + const QString& tagString ) +{ + if ( !tagString.isEmpty() ) { + QDomElement e = element.ownerDocument().createElement( tag ); + QDomText t = element.ownerDocument().createTextNode( tagString ); + e.appendChild( t ); + element.appendChild( e ); + } +} + +QDateTime ScalixBase::localToUTC( const QDateTime& time ) const +{ + return KPimPrefs::localTimeToUtc( time, mTimeZoneId ); +} + +QDateTime ScalixBase::utcToLocal( const QDateTime& time ) const +{ + return KPimPrefs::utcToLocalTime( time, mTimeZoneId ); +} diff --git a/kresources/scalix/shared/scalixbase.h b/kresources/scalix/shared/scalixbase.h new file mode 100644 index 000000000..efed7e27a --- /dev/null +++ b/kresources/scalix/shared/scalixbase.h @@ -0,0 +1,176 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Bo Thorsen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef SCALIXBASE_H +#define SCALIXBASE_H + +#include +#include +#include + +class QFile; + +namespace KCal { + class Incidence; +} + +namespace KABC { + class Addressee; +} + +namespace Scalix { + +class ScalixBase { +public: + struct Email { + public: + Email( const QString& name = QString::null, + const QString& email = QString::null ) + : displayName( name ), smtpAddress( email ) + { + } + + QString displayName; + QString smtpAddress; + }; + + enum Sensitivity { Public = 0, Private = 1, Confidential = 2 }; + + explicit ScalixBase( const QString& timezone = QString::null ); + virtual ~ScalixBase(); + + // Return a string identifying this type + virtual QString type() const = 0; + + virtual void setUid( const QString& uid ); + virtual QString uid() const; + + virtual void setBody( const QString& body ); + virtual QString body() const; + + virtual void setCategories( const QString& categories ); + virtual QString categories() const; + + virtual void setCreationDate( const QDateTime& date ); + virtual QDateTime creationDate() const; + + virtual void setLastModified( const QDateTime& date ); + virtual QDateTime lastModified() const; + + virtual void setSensitivity( Sensitivity sensitivity ); + virtual Sensitivity sensitivity() const; + + virtual void setPilotSyncId( unsigned long id ); + virtual bool hasPilotSyncId() const; + virtual unsigned long pilotSyncId() const; + + virtual void setPilotSyncStatus( int status ); + virtual bool hasPilotSyncStatus() const; + virtual int pilotSyncStatus() const; + + // String - Date conversion methods + static QString dateTimeToString( const QDateTime& time ); + static QString dateToString( const QDate& date ); + static QDateTime stringToDateTime( const QString& time ); + static QDate stringToDate( const QString& date ); + + // String - Sensitivity conversion methods + static QString sensitivityToString( Sensitivity ); + static Sensitivity stringToSensitivity( const QString& ); + + // String - Color conversion methods + static QString colorToString( const QColor& ); + static QColor stringToColor( const QString& ); + + // Load this object by reading the XML file + bool load( const QString& xml ); + bool load( QFile& xml ); + + // Load this QDomDocument + virtual bool loadXML( const QDomDocument& xml ) = 0; + + // Serialize this object to an XML string + virtual QString saveXML() const = 0; + +protected: + /// Read all known fields from this ical incidence + void setFields( const KCal::Incidence* ); + + /// Save all known fields into this ical incidence + void saveTo( KCal::Incidence* ) const; + + /// Read all known fields from this contact + void setFields( const KABC::Addressee* ); + + /// Save all known fields into this contact + void saveTo( KABC::Addressee* ) const; + + // This just makes the initial dom tree with version and doctype + static QDomDocument domTree(); + + bool loadEmailAttribute( QDomElement& element, Email& email ); + + void saveEmailAttribute( QDomElement& element, const Email& email, + const QString& tagName = "email" ) const; + + // Load the attributes of this class + virtual bool loadAttribute( QDomElement& ); + + // Save the attributes of this class + virtual bool saveAttributes( QDomElement& ) const; + + // Return the product ID + virtual QString productID() const = 0; + + // Write a string tag + static void writeString( QDomElement&, const QString&, const QString& ); + + QDateTime localToUTC( const QDateTime& time ) const; + QDateTime utcToLocal( const QDateTime& time ) const; + + QString mUid; + QString mBody; + QString mCategories; + QDateTime mCreationDate; + QDateTime mLastModified; + Sensitivity mSensitivity; + QString mTimeZoneId; + + // KPilot synchronization stuff + bool mHasPilotSyncId, mHasPilotSyncStatus; + unsigned long mPilotSyncId; + int mPilotSyncStatus; +}; + +} + +#endif // SCALIXBASE_H diff --git a/kresources/scalix/shared/subresource.cpp b/kresources/scalix/shared/subresource.cpp new file mode 100644 index 000000000..6653e0f06 --- /dev/null +++ b/kresources/scalix/shared/subresource.cpp @@ -0,0 +1,116 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Klarälvdalens Datakonsult AB + + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "subresource.h" + +using namespace Scalix; + +SubResource::SubResource( bool active, bool writable, const QString& label, + int completionWeight ) + : mActive( active ), mWritable( writable ), mLabel( label ), + mCompletionWeight( completionWeight ) +{ +} + +SubResource::~SubResource() +{ +} + +void SubResource::setActive( bool active ) +{ + mActive = active; +} + +bool SubResource::active() const +{ + return mActive; +} + +void SubResource::setWritable( bool writable ) +{ + mWritable = writable; +} + +bool SubResource::writable() const +{ + return mWritable; +} + +void SubResource::setLabel( const QString& label ) +{ + mLabel = label; +} + +QString SubResource::label() const +{ + return mLabel; +} + +void SubResource::setCompletionWeight( int completionWeight ) +{ + mCompletionWeight = completionWeight; +} + +int SubResource::completionWeight() const +{ + return mCompletionWeight; +} + +StorageReference::StorageReference( const QString& resource, Q_UINT32 sernum ) + : mResource( resource ), mSerialNumber( sernum ) +{ +} + +StorageReference::~StorageReference() +{ +} + +void StorageReference::setResource( const QString& resource ) +{ + mResource = resource; +} + +QString StorageReference::resource() const +{ + return mResource; +} + +void StorageReference::setSerialNumber( Q_UINT32 serialNumber ) +{ + mSerialNumber = serialNumber; +} + +Q_UINT32 StorageReference::serialNumber() const +{ + return mSerialNumber; +} diff --git a/kresources/scalix/shared/subresource.h b/kresources/scalix/shared/subresource.h new file mode 100644 index 000000000..3cfc4429e --- /dev/null +++ b/kresources/scalix/shared/subresource.h @@ -0,0 +1,110 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + Copyright (c) 2004 Klarälvdalens Datakonsult AB + + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef SUBRESOURCE_H +#define SUBRESOURCE_H + +#include +#include + + +namespace Scalix { + +/** + * This class is used to store in a map from resource id to this, providing + * a lookup of the subresource settings. + */ +class SubResource { +public: + // This is just for QMap + SubResource() {} + + SubResource( bool active, bool writable, const QString& label, + int completionWeight = 100 ); + virtual ~SubResource(); + + virtual void setActive( bool active ); + virtual bool active() const; + + virtual void setWritable( bool writable ); + virtual bool writable() const; + + virtual void setLabel( const QString& label ); + virtual QString label() const; + + virtual void setCompletionWeight( int completionWeight ); + virtual int completionWeight() const; + +private: + bool mActive; // Controlled by the applications + bool mWritable; // Set if the KMail folder is writable + QString mLabel; // The GUI name of this resource + + // This is just for the abc plugin. But as long as only this is here, + // it's just as cheap to have it in here as making a d-pointer that + // subclasses could add to. If more are added, then we should refactor + // to a d-pointer instead. + int mCompletionWeight; +}; + +typedef QMap ResourceMap; + +/** + * This class is used to store a mapping from the XML UID to the KMail + * serial number of the mail it's stored in and the resource. That provides + * a quick way to access the storage in KMail. + */ +class StorageReference { +public: + // Just for QMap + StorageReference() {} + + StorageReference( const QString& resource, Q_UINT32 sernum ); + virtual ~StorageReference(); + + virtual void setResource( const QString& resource ); + virtual QString resource() const; + + virtual void setSerialNumber( Q_UINT32 serialNumber ); + virtual Q_UINT32 serialNumber() const; + +private: + QString mResource; + Q_UINT32 mSerialNumber; +}; + +typedef QMap UidMap; + +} + +#endif // SUBRESOURCE_H -- cgit v1.2.1