summaryrefslogtreecommitdiffstats
path: root/kresources/kolab/shared
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kresources/kolab/shared
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
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
Diffstat (limited to 'kresources/kolab/shared')
-rw-r--r--kresources/kolab/shared/Makefile.am17
-rw-r--r--kresources/kolab/shared/kmailconnection.cpp317
-rw-r--r--kresources/kolab/shared/kmailconnection.h128
-rw-r--r--kresources/kolab/shared/kolabbase.cpp474
-rw-r--r--kresources/kolab/shared/kolabbase.h177
-rw-r--r--kresources/kolab/shared/resourcekolabbase.cpp255
-rw-r--r--kresources/kolab/shared/resourcekolabbase.h195
-rw-r--r--kresources/kolab/shared/subresource.cpp133
-rw-r--r--kresources/kolab/shared/subresource.h117
9 files changed, 1813 insertions, 0 deletions
diff --git a/kresources/kolab/shared/Makefile.am b/kresources/kolab/shared/Makefile.am
new file mode 100644
index 000000000..f75af8817
--- /dev/null
+++ b/kresources/kolab/shared/Makefile.am
@@ -0,0 +1,17 @@
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/kresources/lib $(all_includes)
+
+noinst_HEADERS = resourcekolabbase.h kolabbase.h subresource.h
+
+noinst_LTLIBRARIES = libresourcekolabshared.la
+
+libresourcekolabshared_la_SOURCES = \
+ resourcekolabbase.cpp kmailconnection.cpp kolabbase.cpp \
+ subresource.cpp \
+ kmailconnection.skel kmailicalIface.stub
+libresourcekolabshared_la_METASOURCES = AUTO
+libresourcekolabshared_la_LIBADD = $(top_builddir)/libkcal/libkcal.la $(top_builddir)/libkdepim/libkdepim.la ../../lib/libkgroupwarebase.la
+libresourcekolabshared_la_LDFLAGS = -no-undefined
+
+kmailicalIface_DCOPIDLNG = true
+
+kmailicalIface_DIR = $(top_srcdir)/kmail
diff --git a/kresources/kolab/shared/kmailconnection.cpp b/kresources/kolab/shared/kmailconnection.cpp
new file mode 100644
index 000000000..6db9f3dab
--- /dev/null
+++ b/kresources/kolab/shared/kmailconnection.cpp
@@ -0,0 +1,317 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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 "resourcekolabbase.h"
+
+#include <kdebug.h>
+#include <dcopclient.h>
+#include <kapplication.h>
+#include <kdcopservicestarter.h>
+#include <klocale.h>
+
+#include "kmailicalIface_stub.h"
+
+
+using namespace Kolab;
+
+
+KMailConnection::KMailConnection( ResourceKolabBase* 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, bool, bool )",
+ "fromKMailAddSubresource( QString, QString, QString, bool, bool )" ) )
+ 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<Q_UINT32, QString>, QString, QString)",
+ "fromKMailAsyncLoadResult(QMap<Q_UINT32, QString>, 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,
+ bool writable,
+ bool alarmRelevant )
+{
+// kdDebug(5650) << "KMailConnection::fromKMailAddSubresource( " << type << ", "
+// << resource << " )\n";
+ mResource->fromKMailAddSubresource( type, resource, label,
+ writable, alarmRelevant );
+}
+
+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<Q_UINT32, QString>& 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<KMailICalIface::SubResource>& 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<Q_UINT32, QString>& 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::kmailAttachmentMimetype( QString & mimeType,
+ const QString & resource,
+ Q_UINT32 sernum,
+ const QString & filename )
+{
+ if ( !connectToKMail() )
+ return false;
+ mimeType = mKMailIcalIfaceStub->attachmentMimetype( resource, sernum, filename );
+ return mKMailIcalIfaceStub->ok();
+}
+
+bool KMailConnection::kmailListAttachments(QStringList &list,
+ const QString & resource, Q_UINT32 sernum)
+{
+ if ( !connectToKMail() )
+ return false;
+
+ list = mKMailIcalIfaceStub->listAttachments( resource, sernum );
+ 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<QCString, QString>& 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::kmailAddSubresource( const QString& resource,
+ const QString& parent,
+ const QString& contentsType )
+{
+ return connectToKMail()
+ && mKMailIcalIfaceStub->addSubresource( resource, parent, contentsType )
+ && mKMailIcalIfaceStub->ok();
+}
+
+bool KMailConnection::kmailRemoveSubresource( const QString& resource )
+{
+ return connectToKMail()
+ && mKMailIcalIfaceStub->removeSubresource( resource )
+ && mKMailIcalIfaceStub->ok();
+}
+
+
+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/kolab/shared/kmailconnection.h b/kresources/kolab/shared/kmailconnection.h
new file mode 100644
index 000000000..cbb69a155
--- /dev/null
+++ b/kresources/kolab/shared/kmailconnection.h
@@ -0,0 +1,128 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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 <dcopobject.h>
+#include <kmail/kmailicalIface.h>
+
+class KURL;
+class DCOPClient;
+class KMailICalIface_stub;
+
+namespace Kolab {
+
+class ResourceKolabBase;
+
+/**
+ 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, bool writable,
+ bool alarmRelevant );
+ void fromKMailDelSubresource( const QString& type, const QString& resource );
+ void fromKMailAsyncLoadResult( const QMap<Q_UINT32, QString>& map, const QString& type,
+ const QString& folder );
+
+public:
+ KMailConnection( ResourceKolabBase* resource, const QCString& objId );
+ virtual ~KMailConnection();
+
+ /**
+ * Do the connection to KMail.
+ */
+ bool connectToKMail();
+
+ // Call the DCOP methods
+ bool kmailSubresources( QValueList<KMailICalIface::SubResource>& lst,
+ const QString& contentsType );
+ bool kmailIncidencesCount( int& count,
+ const QString& mimetype,
+ const QString& resource );
+ bool kmailIncidences( QMap<Q_UINT32, QString>& 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 kmailAttachmentMimetype( QString &mimeType, const QString &resource,
+ Q_UINT32 sernum, const QString &filename );
+ bool kmailListAttachments( QStringList &list, const QString &resource,
+ Q_UINT32 sernum );
+ bool kmailDeleteIncidence( const QString& resource, Q_UINT32 sernum );
+ bool kmailUpdate( const QString& resource,
+ Q_UINT32& sernum,
+ const QString& subject,
+ const QString& plainTextBody,
+ const QMap<QCString, QString>& 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 );
+ bool kmailAddSubresource( const QString& resource,
+ const QString& parent,
+ const QString& contentsType );
+ bool kmailRemoveSubresource( const QString& resource );
+
+private slots:
+ virtual void unregisteredFromDCOP( const QCString& );
+
+private:
+ /** Connect a signal from KMail to a local slot. */
+ bool connectKMailSignal( const QCString&, const QCString& );
+
+ ResourceKolabBase* mResource;
+ DCOPClient* mDCOPClient;
+ KMailICalIface_stub* mKMailIcalIfaceStub;
+};
+
+}
+
+#endif // KMAILCONNECTION_H
diff --git a/kresources/kolab/shared/kolabbase.cpp b/kresources/kolab/shared/kolabbase.cpp
new file mode 100644
index 000000000..44c44ead2
--- /dev/null
+++ b/kresources/kolab/shared/kolabbase.cpp
@@ -0,0 +1,474 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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 "kolabbase.h"
+
+#include <kabc/addressee.h>
+#include <libkcal/journal.h>
+#include <libkdepim/kpimprefs.h>
+#include <kdebug.h>
+#include <qfile.h>
+
+using namespace Kolab;
+
+
+KolabBase::KolabBase( const QString& tz )
+ : mCreationDate( QDateTime::currentDateTime() ),
+ mLastModified( QDateTime::currentDateTime() ),
+ mSensitivity( Public ), mTimeZoneId( tz ),
+ mHasPilotSyncId( false ), mHasPilotSyncStatus( false )
+{
+}
+
+KolabBase::~KolabBase()
+{
+}
+
+void KolabBase::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<Sensitivity>( incidence->secrecy() ) );
+ // TODO: Attachments
+}
+
+void KolabBase::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 KolabBase::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<KABC::Addressee*>( 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 KolabBase::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 KolabBase::setUid( const QString& uid )
+{
+ mUid = uid;
+}
+
+QString KolabBase::uid() const
+{
+ return mUid;
+}
+
+void KolabBase::setBody( const QString& body )
+{
+ mBody = body;
+}
+
+QString KolabBase::body() const
+{
+ return mBody;
+}
+
+void KolabBase::setCategories( const QString& categories )
+{
+ mCategories = categories;
+}
+
+QString KolabBase::categories() const
+{
+ return mCategories;
+}
+
+void KolabBase::setCreationDate( const QDateTime& date )
+{
+ mCreationDate = date;
+}
+
+QDateTime KolabBase::creationDate() const
+{
+ return mCreationDate;
+}
+
+void KolabBase::setLastModified( const QDateTime& date )
+{
+ mLastModified = date;
+}
+
+QDateTime KolabBase::lastModified() const
+{
+ return mLastModified;
+}
+
+void KolabBase::setSensitivity( Sensitivity sensitivity )
+{
+ mSensitivity = sensitivity;
+}
+
+KolabBase::Sensitivity KolabBase::sensitivity() const
+{
+ return mSensitivity;
+}
+
+void KolabBase::setPilotSyncId( unsigned long id )
+{
+ mHasPilotSyncId = true;
+ mPilotSyncId = id;
+}
+
+bool KolabBase::hasPilotSyncId() const
+{
+ return mHasPilotSyncId;
+}
+
+unsigned long KolabBase::pilotSyncId() const
+{
+ return mPilotSyncId;
+}
+
+void KolabBase::setPilotSyncStatus( int status )
+{
+ mHasPilotSyncStatus = true;
+ mPilotSyncStatus = status;
+}
+
+bool KolabBase::hasPilotSyncStatus() const
+{
+ return mHasPilotSyncStatus;
+}
+
+int KolabBase::pilotSyncStatus() const
+{
+ return mPilotSyncStatus;
+}
+
+bool KolabBase::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();
+ const 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 KolabBase::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 KolabBase::loadAttribute( QDomElement& element )
+{
+ const QString tagName = element.tagName();
+ switch ( tagName[0].latin1() ) {
+ case 'u':
+ if ( tagName == "uid" ) {
+ setUid( element.text() );
+ return true;
+ }
+ break;
+ case 'b':
+ if ( tagName == "body" ) {
+ setBody( element.text() );
+ return true;
+ }
+ break;
+ case 'c':
+ if ( tagName == "categories" ) {
+ setCategories( element.text() );
+ return true;
+ }
+ if ( tagName == "creation-date" ) {
+ setCreationDate( stringToDateTime( element.text() ) );
+ return true;
+ }
+ break;
+ case 'l':
+ if ( tagName == "last-modification-date" ) {
+ setLastModified( stringToDateTime( element.text() ) );
+ return true;
+ }
+ break;
+ case 's':
+ if ( tagName == "sensitivity" ) {
+ setSensitivity( stringToSensitivity( element.text() ) );
+ return true;
+ }
+ break;
+ case 'p':
+ if ( tagName == "product-id" )
+ return true; // ignore this field
+ if ( tagName == "pilot-sync-id" ) {
+ setPilotSyncId( element.text().toULong() );
+ return true;
+ }
+ if ( tagName == "pilot-sync-status" ) {
+ setPilotSyncStatus( element.text().toInt() );
+ return true;
+ }
+ break;
+ default:
+ break;
+ }
+ return false;
+}
+
+bool KolabBase::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 KolabBase::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 KolabBase::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 KolabBase::domTree()
+{
+ QDomDocument document;
+
+ QString p = "version=\"1.0\" encoding=\"UTF-8\"";
+ document.appendChild(document.createProcessingInstruction( "xml", p ) );
+
+ return document;
+}
+
+
+QString KolabBase::dateTimeToString( const QDateTime& time )
+{
+ return time.toString( Qt::ISODate ) + 'Z';
+}
+
+QString KolabBase::dateToString( const QDate& date )
+{
+ return date.toString( Qt::ISODate );
+}
+
+QDateTime KolabBase::stringToDateTime( const QString& _date )
+{
+ QString date( _date );
+ if ( date.endsWith( "Z" ) )
+ date.truncate( date.length() - 1 );
+ return QDateTime::fromString( date, Qt::ISODate );
+}
+
+QDate KolabBase::stringToDate( const QString& date )
+{
+ return QDate::fromString( date, Qt::ISODate );
+}
+
+QString KolabBase::sensitivityToString( Sensitivity s )
+{
+ switch( s ) {
+ case Private: return "private";
+ case Confidential: return "confidential";
+ case Public: return "public";
+ }
+
+ return "What what what???";
+}
+
+KolabBase::Sensitivity KolabBase::stringToSensitivity( const QString& s )
+{
+ if ( s == "private" )
+ return Private;
+ if ( s == "confidential" )
+ return Confidential;
+ return Public;
+}
+
+QString KolabBase::colorToString( const QColor& color )
+{
+ // Color is in the format "#RRGGBB"
+ return color.name();
+}
+
+QColor KolabBase::stringToColor( const QString& s )
+{
+ return QColor( s );
+}
+
+void KolabBase::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 KolabBase::localToUTC( const QDateTime& time ) const
+{
+ return KPimPrefs::localTimeToUtc( time, mTimeZoneId );
+}
+
+QDateTime KolabBase::utcToLocal( const QDateTime& time ) const
+{
+ return KPimPrefs::utcToLocalTime( time, mTimeZoneId );
+}
diff --git a/kresources/kolab/shared/kolabbase.h b/kresources/kolab/shared/kolabbase.h
new file mode 100644
index 000000000..053683989
--- /dev/null
+++ b/kresources/kolab/shared/kolabbase.h
@@ -0,0 +1,177 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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 KOLABBASE_H
+#define KOLABBASE_H
+
+#include <qdom.h>
+#include <qdatetime.h>
+#include <qcolor.h>
+
+class QFile;
+
+namespace KCal {
+ class Incidence;
+}
+
+namespace KABC {
+ class Addressee;
+}
+
+namespace Kolab {
+
+class KolabBase {
+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 KolabBase( const QString& timezone = QString::null );
+ virtual ~KolabBase();
+
+ // 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 // KOLABBASE_H
diff --git a/kresources/kolab/shared/resourcekolabbase.cpp b/kresources/kolab/shared/resourcekolabbase.cpp
new file mode 100644
index 000000000..d62a5bb54
--- /dev/null
+++ b/kresources/kolab/shared/resourcekolabbase.cpp
@@ -0,0 +1,255 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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 "resourcekolabbase.h"
+#include "kmailconnection.h"
+
+#include <folderselectdialog.h>
+
+#include <klocale.h>
+#include <kstandarddirs.h>
+#include <kinputdialog.h>
+#include <kurl.h>
+#include <ktempfile.h>
+#include <kmessagebox.h>
+#include <qtextstream.h>
+#include <kdebug.h>
+
+using namespace Kolab;
+
+static unsigned int uniquifier = 0;
+
+ResourceKolabBase::ResourceKolabBase( const QCString& objId )
+ : mSilent( false )
+{
+ KGlobal::locale()->insertCatalogue( "kres_kolab" );
+ KGlobal::locale()->insertCatalogue( "libkcal" );
+ QString uniqueObjId = QString( objId ) + QString::number( uniquifier++ );
+ mConnection = new KMailConnection( this, uniqueObjId.utf8() );
+}
+
+ResourceKolabBase::~ResourceKolabBase()
+{
+ delete mConnection;
+}
+
+
+bool ResourceKolabBase::kmailSubresources( QValueList<KMailICalIface::SubResource>& lst,
+ const QString& contentsType ) const
+{
+ return mConnection->kmailSubresources( lst, contentsType );
+}
+
+bool ResourceKolabBase::kmailTriggerSync( const QString& contentsType ) const
+{
+ return mConnection->kmailTriggerSync( contentsType );
+}
+
+
+bool ResourceKolabBase::kmailIncidencesCount( int &count,
+ const QString& mimetype,
+ const QString& resource ) const
+{
+ return mConnection->kmailIncidencesCount( count, mimetype, resource );
+}
+
+bool ResourceKolabBase::kmailIncidences( QMap<Q_UINT32, QString>& lst,
+ const QString& mimetype,
+ const QString& resource,
+ int startIndex,
+ int nbMessages ) const
+{
+ return mConnection->kmailIncidences( lst, mimetype, resource, startIndex, nbMessages );
+}
+
+bool ResourceKolabBase::kmailGetAttachment( KURL& url, const QString& resource,
+ Q_UINT32 sernum,
+ const QString& filename ) const
+{
+ return mConnection->kmailGetAttachment( url, resource, sernum, filename );
+}
+
+bool ResourceKolabBase::kmailAttachmentMimetype( QString & mimeType, QString & resource,
+ Q_UINT32 sernum, const QString & filename ) const
+{
+ return mConnection->kmailAttachmentMimetype( mimeType, resource, sernum, filename );
+}
+
+bool ResourceKolabBase::kmailListAttachments( QStringList &list,
+ const QString & resource,
+ Q_UINT32 sernum ) const
+{
+ return mConnection->kmailListAttachments( list, resource, sernum );
+}
+
+bool ResourceKolabBase::kmailDeleteIncidence( const QString& resource,
+ Q_UINT32 sernum )
+{
+ return mSilent || mConnection->kmailDeleteIncidence( resource, sernum );
+}
+
+static QString plainTextBody()
+{
+ const char * firstPartTextToTranslate = I18N_NOOP(
+ "This is a Kolab Groupware object.\nTo view this object you"
+ " will need an email client that can understand the Kolab"
+ " Groupware format.\nFor a list of such email clients please"
+ " visit\n%1" );
+ const char * url = "http://www.kolab.org/kolab2-clients.html";
+ QString firstPartTextUntranslated = QString::fromLatin1( firstPartTextToTranslate ).arg( url );
+ QString firstPartText = i18n( firstPartTextToTranslate ).arg( url );
+ if ( firstPartText != firstPartTextUntranslated ) {
+ firstPartText.append("\n\n-----------------------------------------------------\n\n");
+ firstPartText.append( firstPartTextUntranslated );
+ }
+ return firstPartText;
+}
+
+bool ResourceKolabBase::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.");
+
+ if ( mimetype.startsWith( "application/x-vnd.kolab" ) ) {
+
+ // Save the xml file. Will be deleted at the end of this method
+ KTempFile file;
+ file.setAutoDelete( true );
+ QTextStream* stream = file.textStream();
+ stream->setEncoding( QTextStream::UnicodeUTF8 );
+ *stream << xml;
+ file.close();
+
+ // Add the xml file as an attachment
+ QStringList attachmentURLs = _attachmentURLs;
+ QStringList attachmentMimeTypes = _attachmentMimetypes;
+ QStringList attachmentNames = _attachmentNames;
+ KURL url;
+ url.setPath( file.name() );
+ url.setFileEncoding( "UTF-8" );
+ attachmentURLs.prepend( url.url() );
+ attachmentMimeTypes.prepend( mimetype );
+ attachmentNames.prepend( "kolab.xml" );
+
+ CustomHeaderMap customHeaders( _customHeaders );
+ customHeaders.insert( "X-Kolab-Type", mimetype );
+
+ return mConnection->kmailUpdate( resource, sernum, subj, plainTextBody(), customHeaders,
+ attachmentURLs, attachmentMimeTypes, attachmentNames,
+ deletedAttachments );
+ } else {
+ // ical style, simply put the data inline
+ return mConnection->kmailUpdate( resource, sernum, subj, xml, _customHeaders,
+ _attachmentURLs, _attachmentMimetypes, _attachmentNames, deletedAttachments );
+ }
+}
+
+QString ResourceKolabBase::configFile( const QString& type ) const
+{
+ return locateLocal( "config",
+ QString( "kresources/kolab/%1rc" ).arg( type ) );
+}
+
+bool ResourceKolabBase::connectToKMail() const
+{
+ return mConnection->connectToKMail();
+}
+
+bool ResourceKolabBase::kmailAddSubresource( const QString& resource,
+ const QString& parent,
+ const QString& contentsType )
+{
+ return mConnection->kmailAddSubresource( resource, parent, contentsType );
+}
+
+bool ResourceKolabBase::kmailRemoveSubresource( const QString& resource )
+{
+ return mConnection->kmailRemoveSubresource( resource );
+}
+
+QString ResourceKolabBase::findWritableResource( const ResourceMap& resources,
+ const QString& text )
+{
+ // 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<QString, QString> 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
+
+ QString t = text;
+ if ( t.isEmpty() )
+ i18n( "You have more than one writable resource folder. "
+ "Please select the one you want to write to." );
+
+ // Several found, ask the user
+ QString chosenLabel = KPIM::FolderSelectDialog::getItem( i18n( "Select Resource Folder" ),
+ t, possible.keys() );
+ if ( chosenLabel.isEmpty() ) // cancelled
+ return QString::null;
+ return possible[chosenLabel];
+}
+
+KMailICalIface::StorageFormat ResourceKolabBase::kmailStorageFormat( const QString &folder ) const
+{
+ KMailICalIface::StorageFormat format = (KMailICalIface::StorageFormat) 3;
+ mConnection->kmailStorageFormat( format, folder );
+ return format;
+}
diff --git a/kresources/kolab/shared/resourcekolabbase.h b/kresources/kolab/shared/resourcekolabbase.h
new file mode 100644
index 000000000..806220189
--- /dev/null
+++ b/kresources/kolab/shared/resourcekolabbase.h
@@ -0,0 +1,195 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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 RESOURCEKOLABBASE_H
+#define RESOURCEKOLABBASE_H
+
+#include <qstring.h>
+#include <qmap.h>
+#include <qstringlist.h>
+
+#include "subresource.h"
+#include <kmail/kmailicalIface.h>
+
+class QCString;
+class KURL;
+
+namespace Kolab {
+
+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 ResourceKolabBase {
+public:
+ ResourceKolabBase( const QCString& objId );
+ virtual ~ResourceKolabBase();
+
+ // 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,
+ bool alarmRelevant ) = 0;
+ virtual void fromKMailDelSubresource( const QString& type,
+ const QString& resource ) = 0;
+
+ virtual void fromKMailAsyncLoadResult( const QMap<Q_UINT32, QString>& 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<KMailICalIface::SubResource>& 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<Q_UINT32, QString>& 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;
+
+ /** Get the mimetype of the specified attachment. */
+ bool kmailAttachmentMimetype( QString &mimeType, QString &resource,
+ Q_UINT32 sernum, const QString &filename ) const;
+
+ /// List all attachments of a mail.
+ bool kmailListAttachments( QStringList &list, const QString &resource,
+ Q_UINT32 sernum ) const;
+
+protected:
+ /// Delete an incidence.
+ bool kmailDeleteIncidence( const QString& resource, Q_UINT32 sernum );
+
+ KMailICalIface::StorageFormat kmailStorageFormat( const QString& folder ) const;
+
+ typedef QMap<QCString, QString> 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() );
+
+ bool kmailAddSubresource( const QString& resource, const QString& parent,
+ const QString& contentsType );
+ bool kmailRemoveSubresource( const QString& resource );
+
+ /// 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,
+ const QString& text = QString::null );
+
+ 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/kolab/shared/subresource.cpp b/kresources/kolab/shared/subresource.cpp
new file mode 100644
index 000000000..67216913a
--- /dev/null
+++ b/kresources/kolab/shared/subresource.cpp
@@ -0,0 +1,133 @@
+/*
+ This file is part of libkabc and/or kaddressbook.
+ Copyright (c) 2004 Klarälvdalens Datakonsult AB
+ <info@klaralvdalens-datakonsult.se>
+
+ 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 Kolab;
+
+SubResource::SubResource( bool active, bool writable,
+ bool alarmRelevant, const QString& label,
+ int completionWeight )
+ : mActive( active ), mWritable( writable ), mAlarmRelevant( alarmRelevant ),
+ mLabel( label ), mCompletionWeight( completionWeight )
+{
+}
+
+SubResource::SubResource( bool active, bool writable,
+ const QString& label, int completionWeight )
+ : mActive( active ), mWritable( writable ), mAlarmRelevant( false ),
+ mLabel( label ), mCompletionWeight( completionWeight )
+{
+}
+
+SubResource::~SubResource()
+{
+}
+
+void SubResource::setActive( bool active )
+{
+ mActive = active;
+}
+
+bool SubResource::active() const
+{
+ return mActive;
+}
+
+void SubResource::setAlarmRelevant( bool active )
+{
+ mAlarmRelevant = active;
+}
+
+bool SubResource::alarmRelevant() const
+{
+ return mAlarmRelevant;
+}
+
+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/kolab/shared/subresource.h b/kresources/kolab/shared/subresource.h
new file mode 100644
index 000000000..1bdd98cd5
--- /dev/null
+++ b/kresources/kolab/shared/subresource.h
@@ -0,0 +1,117 @@
+/*
+ This file is part of libkabc and/or kaddressbook.
+ Copyright (c) 2004 Klarälvdalens Datakonsult AB
+ <info@klaralvdalens-datakonsult.se>
+
+ 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 <qstring.h>
+#include <qmap.h>
+
+
+namespace Kolab {
+
+/**
+ * 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 );
+
+ SubResource( bool active, bool writable, bool alarmRelevant,
+ 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 setAlarmRelevant( bool active );
+ virtual bool alarmRelevant() 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
+ bool mAlarmRelevant; // Set if the alarms from this resource are of
+ // interest to the user, as per folder acls
+ 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<QString, SubResource> 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<QString, StorageReference> UidMap;
+
+}
+
+#endif // SUBRESOURCE_H