diff options
Diffstat (limited to 'tderesources/scalix/shared')
-rw-r--r-- | tderesources/scalix/shared/CMakeLists.txt | 31 | ||||
-rw-r--r-- | tderesources/scalix/shared/Makefile.am | 17 | ||||
-rw-r--r-- | tderesources/scalix/shared/kmailconnection.cpp | 281 | ||||
-rw-r--r-- | tderesources/scalix/shared/kmailconnection.h | 118 | ||||
-rw-r--r-- | tderesources/scalix/shared/resourcescalixbase.cpp | 179 | ||||
-rw-r--r-- | tderesources/scalix/shared/resourcescalixbase.h | 180 | ||||
-rw-r--r-- | tderesources/scalix/shared/scalixbase.cpp | 446 | ||||
-rw-r--r-- | tderesources/scalix/shared/scalixbase.h | 176 | ||||
-rw-r--r-- | tderesources/scalix/shared/subresource.cpp | 116 | ||||
-rw-r--r-- | tderesources/scalix/shared/subresource.h | 110 |
10 files changed, 1654 insertions, 0 deletions
diff --git a/tderesources/scalix/shared/CMakeLists.txt b/tderesources/scalix/shared/CMakeLists.txt new file mode 100644 index 000000000..28ede16e0 --- /dev/null +++ b/tderesources/scalix/shared/CMakeLists.txt @@ -0,0 +1,31 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/libtdepim + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + + +##### resourcescalixshared (static) ############# + +set( KDE3_DCOPIDL_EXECUTABLE ${KDE3_DCOPIDLNG_EXECUTABLE} ) + +tde_add_library( resourcescalixshared STATIC_PIC AUTOMOC + SOURCES + resourcescalixbase.cpp kmailconnection.cpp scalixbase.cpp + subresource.cpp kmailconnection.skel + ${CMAKE_SOURCE_DIR}/kmail/kmailicalIface.stub +) diff --git a/tderesources/scalix/shared/Makefile.am b/tderesources/scalix/shared/Makefile.am new file mode 100644 index 000000000..44b4dc95e --- /dev/null +++ b/tderesources/scalix/shared/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/tderesources/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)/libtdepim/libtdepim.la ../../lib/libkgroupwaredav.la +libresourcescalixshared_la_LDFLAGS = -no-undefined + +kmailicalIface_DCOPIDLNG = true + +kmailicalIface_DIR = $(top_srcdir)/kmail diff --git a/tderesources/scalix/shared/kmailconnection.cpp b/tderesources/scalix/shared/kmailconnection.cpp new file mode 100644 index 000000000..5a1570480 --- /dev/null +++ b/tderesources/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 <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <kdebug.h> +#include <dcopclient.h> +#include <kapplication.h> +#include <kdcopservicestarter.h> +#include <klocale.h> + +#include "kmailicalIface_stub.h" + + +using namespace Scalix; + + +KMailConnection::KMailConnection( ResourceScalixBase* resource, + const TQCString& 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(), TQT_SIGNAL( applicationRemoved( const TQCString& ) ), + this, TQT_SLOT( unregisteredFromDCOP( const TQCString& ) ) ); +} + +KMailConnection::~KMailConnection() +{ + kapp->dcopClient()->setNotifications( false ); + delete mKMailIcalIfaceStub; + mKMailIcalIfaceStub = 0; + delete mDCOPClient; + mDCOPClient = 0; +} + +static const TQCString dcopObjectId = "KMailICalIface"; +bool KMailConnection::connectToKMail() +{ + if ( !mKMailIcalIfaceStub ) { + TQString error; + TQCString dcopService; + int result = KDCOPServiceStarter::self()-> + findServiceFor( "DCOP/ResourceBackend/IMAP", TQString(), + TQString(), &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(TQString,TQString,TQ_UINT32,int,TQString)", + "fromKMailAddIncidence(TQString,TQString,TQ_UINT32,int,TQString)" ) ) + kdError(5650) << "DCOP connection to incidenceAdded failed" << endl; + if ( !connectKMailSignal( "incidenceDeleted(TQString,TQString,TQString)", + "fromKMailDelIncidence(TQString,TQString,TQString)" ) ) + kdError(5650) << "DCOP connection to incidenceDeleted failed" << endl; + if ( !connectKMailSignal( "signalRefresh(TQString,TQString)", + "fromKMailRefresh(TQString,TQString)" ) ) + kdError(5650) << "DCOP connection to signalRefresh failed" << endl; + if ( !connectKMailSignal( "subresourceAdded( TQString, TQString, TQString )", + "fromKMailAddSubresource( TQString, TQString, TQString )" ) ) + kdError(5650) << "DCOP connection to subresourceAdded failed" << endl; + if ( !connectKMailSignal( "subresourceDeleted(TQString,TQString)", + "fromKMailDelSubresource(TQString,TQString)" ) ) + kdError(5650) << "DCOP connection to subresourceDeleted failed" << endl; + if ( !connectKMailSignal( "asyncLoadResult(TQMap<TQ_UINT32, TQString>, TQString, TQString)", + "fromKMailAsyncLoadResult(TQMap<TQ_UINT32, TQString>, TQString, TQString)" ) ) + kdError(5650) << "DCOP connection to asyncLoadResult failed" << endl; + } + + return ( mKMailIcalIfaceStub != 0 ); +} + +bool KMailConnection::fromKMailAddIncidence( const TQString& type, + const TQString& folder, + TQ_UINT32 sernum, + int format, + const TQString& 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 TQString& type, + const TQString& folder, + const TQString& xml ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailDelIncidence( " << type << ", " +// << folder << ", " << uid << " )\n"; + mResource->fromKMailDelIncidence( type, folder, xml ); +} + +void KMailConnection::fromKMailRefresh( const TQString& type, const TQString& folder ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailRefresh( " << type << ", " +// << folder << " )\n"; + mResource->fromKMailRefresh( type, folder ); +} + +void KMailConnection::fromKMailAddSubresource( const TQString& type, + const TQString& resource, + const TQString& 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 TQString& type, + const TQString& resource ) +{ +// kdDebug(5650) << "KMailConnection::fromKMailDelSubresource( " << type << ", " +// << resource << " )\n"; + mResource->fromKMailDelSubresource( type, resource ); +} + +void KMailConnection::fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map, + const TQString& type, + const TQString& folder ) +{ + mResource->fromKMailAsyncLoadResult( map, type, folder ); +} + +bool KMailConnection::connectKMailSignal( const TQCString& signal, + const TQCString& method ) +{ + return connectDCOPSignal( "kmail", dcopObjectId, signal, method, false ) + && connectDCOPSignal( "kontact", dcopObjectId, signal, method, false ); +} + +bool KMailConnection::kmailSubresources( TQValueList<KMailICalIface::SubResource>& lst, + const TQString& contentsType ) +{ + if ( !connectToKMail() ) + return false; + + lst = mKMailIcalIfaceStub->subresourcesKolab( contentsType ); + return mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailIncidencesCount( int& count, + const TQString& mimetype, + const TQString& resource ) +{ + if ( !connectToKMail() ) + return false; + + count = mKMailIcalIfaceStub->incidencesKolabCount( mimetype, resource ); + return mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailIncidences( TQMap<TQ_UINT32, TQString>& lst, + const TQString& mimetype, + const TQString& 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 TQString& resource, + TQ_UINT32 sernum, + const TQString& filename ) +{ + if ( !connectToKMail() ) + return false; + + url = mKMailIcalIfaceStub->getAttachment( resource, sernum, filename ); + return mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailDeleteIncidence( const TQString& resource, + TQ_UINT32 sernum ) +{ + return connectToKMail() + && mKMailIcalIfaceStub->deleteIncidenceKolab( resource, sernum ) + && mKMailIcalIfaceStub->ok(); +} + +bool KMailConnection::kmailUpdate( const TQString& resource, + TQ_UINT32& sernum, + const TQString& subject, + const TQString& plainTextBody, + const TQMap<TQCString, TQString>& customHeaders, + const TQStringList& attachmentURLs, + const TQStringList& attachmentMimetypes, + const TQStringList& attachmentNames, + const TQStringList& 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 TQString& folder ) +{ + bool ok = connectToKMail(); + type = mKMailIcalIfaceStub->storageFormat( folder ); + return ok && mKMailIcalIfaceStub->ok(); +} + + +bool KMailConnection::kmailTriggerSync( const TQString &contentsType ) +{ + bool ok = connectToKMail(); + return ok && mKMailIcalIfaceStub->triggerSync( contentsType ); +} + +void KMailConnection::unregisteredFromDCOP( const TQCString& 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/tderesources/scalix/shared/kmailconnection.h b/tderesources/scalix/shared/kmailconnection.h new file mode 100644 index 000000000..7fec6274f --- /dev/null +++ b/tderesources/scalix/shared/kmailconnection.h @@ -0,0 +1,118 @@ +/* + This file is part of the scalix resource - based on the kolab resource. + + 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 Scalix { + +class ResourceScalixBase; + +/** + This class provides the kmail connectivity for IMAP resources. +*/ +class KMailConnection : public TQObject, public DCOPObject { + Q_OBJECT +// + K_DCOP + + // These are the methods called by KMail when the resource changes +k_dcop: + bool fromKMailAddIncidence( const TQString& type, const TQString& resource, + TQ_UINT32 sernum, int format, const TQString& xml ); + void fromKMailDelIncidence( const TQString& type, const TQString& resource, + const TQString& xml ); + void fromKMailRefresh( const TQString& type, const TQString& resource ); + void fromKMailAddSubresource( const TQString& type, const TQString& resource, const TQString& label ); + void fromKMailDelSubresource( const TQString& type, const TQString& resource ); + void fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map, const TQString& type, + const TQString& folder ); + +public: + KMailConnection( ResourceScalixBase* resource, const TQCString& objId ); + virtual ~KMailConnection(); + + /** + * Do the connection to KMail. + */ + bool connectToKMail(); + + // Call the DCOP methods + bool kmailSubresources( TQValueList<KMailICalIface::SubResource>& lst, + const TQString& contentsType ); + bool kmailIncidencesCount( int& count, + const TQString& mimetype, + const TQString& resource ); + bool kmailIncidences( TQMap<TQ_UINT32, TQString>& lst, const TQString& mimetype, + const TQString& resource, + int startIndex, + int nbMessages ); + + bool kmailGetAttachment( KURL& url, const TQString& resource, TQ_UINT32 sernum, + const TQString& filename ); + bool kmailDeleteIncidence( const TQString& resource, TQ_UINT32 sernum ); + bool kmailUpdate( const TQString& resource, + TQ_UINT32& sernum, + const TQString& subject, + const TQString& plainTextBody, + const TQMap<TQCString, TQString>& customHeaders, + const TQStringList& attachmentURLs, + const TQStringList& attachmentMimetypes, + const TQStringList& attachmentNames, + const TQStringList& deletedAttachments ); + + bool kmailStorageFormat( KMailICalIface::StorageFormat& type, const TQString& folder); + + bool kmailTriggerSync( const TQString& contentsType ); + +private slots: + virtual void unregisteredFromDCOP( const TQCString& ); + +private: + /** Connect a signal from KMail to a local slot. */ + bool connectKMailSignal( const TQCString&, const TQCString& ); + + ResourceScalixBase* mResource; + DCOPClient* mDCOPClient; + KMailICalIface_stub* mKMailIcalIfaceStub; +}; + +} + +#endif // KMAILCONNECTION_H diff --git a/tderesources/scalix/shared/resourcescalixbase.cpp b/tderesources/scalix/shared/resourcescalixbase.cpp new file mode 100644 index 000000000..1f829a79d --- /dev/null +++ b/tderesources/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 <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <folderselectdialog.h> + +#include <klocale.h> +#include <kstandarddirs.h> +#include <kinputdialog.h> +#include <kurl.h> +#include <ktempfile.h> +#include <kmessagebox.h> +#include <tqtextstream.h> +#include <kdebug.h> + +using namespace Scalix; + +static unsigned int uniquifier = 0; + +ResourceScalixBase::ResourceScalixBase( const TQCString& objId ) + : mSilent( false ) +{ + TDEGlobal::locale()->insertCatalogue( "kres_scalix" ); + TDEGlobal::locale()->insertCatalogue( "libkcal" ); + TQString uniqueObjId = TQString( objId ) + TQString::number( uniquifier++ ); + mConnection = new KMailConnection( this, uniqueObjId.utf8() ); +} + +ResourceScalixBase::~ResourceScalixBase() +{ + delete mConnection; +} + + +bool ResourceScalixBase::kmailSubresources( TQValueList<KMailICalIface::SubResource>& lst, + const TQString& contentsType ) const +{ + return mConnection->kmailSubresources( lst, contentsType ); +} + +bool ResourceScalixBase::kmailTriggerSync( const TQString& contentsType ) const +{ + return mConnection->kmailTriggerSync( contentsType ); +} + + +bool ResourceScalixBase::kmailIncidencesCount( int &count, + const TQString& mimetype, + const TQString& resource ) const +{ + return mConnection->kmailIncidencesCount( count, mimetype, resource ); +} + +bool ResourceScalixBase::kmailIncidences( TQMap<TQ_UINT32, TQString>& lst, + const TQString& mimetype, + const TQString& resource, + int startIndex, + int nbMessages ) const +{ + return mConnection->kmailIncidences( lst, mimetype, resource, startIndex, nbMessages ); +} + +bool ResourceScalixBase::kmailGetAttachment( KURL& url, const TQString& resource, + TQ_UINT32 sernum, + const TQString& filename ) const +{ + return mConnection->kmailGetAttachment( url, resource, sernum, filename ); +} + +bool ResourceScalixBase::kmailDeleteIncidence( const TQString& resource, + TQ_UINT32 sernum ) +{ + return mSilent || mConnection->kmailDeleteIncidence( resource, sernum ); +} + +bool ResourceScalixBase::kmailUpdate( const TQString& resource, + TQ_UINT32& sernum, + const TQString& xml, + const TQString& mimetype, + const TQString& subject, + const CustomHeaderMap& _customHeaders, + const TQStringList& _attachmentURLs, + const TQStringList& _attachmentMimetypes, + const TQStringList& _attachmentNames, + const TQStringList& deletedAttachments ) +{ + if ( mSilent ) + return true; + + TQString 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 ); +} + +TQString ResourceScalixBase::configFile( const TQString& type ) const +{ + return locateLocal( "config", + TQString( "tderesources/scalix/%1rc" ).arg( type ) ); +} + +bool ResourceScalixBase::connectToKMail() const +{ + return mConnection->connectToKMail(); +} + +TQString 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... + TQMap<TQString, TQString> possible; + TQStringList 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 TQString(); + } + 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 + TQString 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 TQString(); + return possible[chosenLabel]; +} + +KMailICalIface::StorageFormat ResourceScalixBase::kmailStorageFormat( const TQString &folder ) const +{ + KMailICalIface::StorageFormat format = (KMailICalIface::StorageFormat) 3; + mConnection->kmailStorageFormat( format, folder ); + return format; +} diff --git a/tderesources/scalix/shared/resourcescalixbase.h b/tderesources/scalix/shared/resourcescalixbase.h new file mode 100644 index 000000000..82c6e471a --- /dev/null +++ b/tderesources/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 <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <tqstring.h> +#include <tqmap.h> +#include <tqstringlist.h> + +#include "subresource.h" +#include <kmail/kmailicalIface.h> + +class TQCString; +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 TQCString& objId ); + virtual ~ResourceScalixBase(); + + // These are the methods called by KMail when the resource changes + virtual bool fromKMailAddIncidence( const TQString& type, + const TQString& resource, + TQ_UINT32 sernum, + int format, + const TQString& data ) = 0; + virtual void fromKMailDelIncidence( const TQString& type, + const TQString& resource, + const TQString& xml ) = 0; + virtual void fromKMailRefresh( const TQString& type, + const TQString& resource ) = 0; + virtual void fromKMailAddSubresource( const TQString& type, + const TQString& resource, + const TQString& label, + bool writable ) = 0; + virtual void fromKMailDelSubresource( const TQString& type, + const TQString& resource ) = 0; + + virtual void fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map, + const TQString& type, + const TQString& 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 TQMap with + /// resourcename/writable pairs + bool kmailSubresources( TQValueList<KMailICalIface::SubResource>& lst, + const TQString& contentsType ) const; + + /// Get the number of messages in this folder. + /// Used to iterate over kmailIncidences by chunks + bool kmailIncidencesCount( int& count, const TQString& mimetype, + const TQString& resource ) const; + + /// Get the mimetype attachments from a chunk of messages from this folder. + /// Returns a TQMap with serialNumber/attachment pairs. + bool kmailIncidences( TQMap<TQ_UINT32, TQString>& lst, const TQString& mimetype, + const TQString& resource, + int startIndex, + int nbMessages ) const; + + bool kmailTriggerSync( const TQString& 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 TQString& resource, + TQ_UINT32 sernum, + const TQString& filename ) const; + +protected: + /// Delete an incidence. + bool kmailDeleteIncidence( const TQString& resource, TQ_UINT32 sernum ); + + KMailICalIface::StorageFormat kmailStorageFormat( const TQString& folder ) const; + + typedef TQMap<TQCString, TQString> CustomHeaderMap; + + /// Update an incidence. The list of attachments are URLs. + /// The parameter sernum is updated with the right KMail serial number + bool kmailUpdate( const TQString& resource, TQ_UINT32& sernum, + const TQString& xml, + const TQString& mimetype, + const TQString& subject, + const CustomHeaderMap& customHeaders = CustomHeaderMap(), + const TQStringList& attachmentURLs = TQStringList(), + const TQStringList& attachmentMimetypes = TQStringList(), + const TQStringList& attachmentNames = TQStringList(), + const TQStringList& deletedAttachments = TQStringList() ); + + /// Get the full path of the config file. + TQString configFile( const TQString& type ) const; + + /// If only one of these is writable, return that. Otherwise return null. + TQString 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 + TQStringList mUidsPendingAdding; + TQStringList mUidsPendingDeletion; + TQStringList mUidsPendingUpdate; + +private: + mutable KMailConnection* mConnection; +}; + +} + +#endif // RESOURCEKOLABBASE_H diff --git a/tderesources/scalix/shared/scalixbase.cpp b/tderesources/scalix/shared/scalixbase.cpp new file mode 100644 index 000000000..d40bdb03f --- /dev/null +++ b/tderesources/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 <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <kabc/addressee.h> +#include <libkcal/journal.h> +#include <libtdepim/kpimprefs.h> +#include <kdebug.h> +#include <tqfile.h> + +using namespace Scalix; + + +ScalixBase::ScalixBase( const TQString& tz ) + : mCreationDate( TQDateTime::currentDateTime() ), + mLastModified( TQDateTime::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<Sensitivity>( 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 TQString creationString = addressee->custom( "KOLAB", "CreationDate" ); + kdDebug(5006) << "Creation time string: " << creationString << endl; + TQDateTime creationDate; + if ( creationString.isEmpty() ) { + creationDate = TQDateTime::currentDateTime(); + kdDebug(5006) << "Creation date set to current time\n"; + } + else { + creationDate = stringToDateTime( creationString ); + kdDebug(5006) << "Creation date loaded\n"; + } + TQDateTime modified = addressee->revision(); + if ( !modified.isValid() ) + modified = TQDateTime::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 TQString 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 ScalixBase::saveTo( KABC::Addressee* addressee ) const +{ + addressee->setUid( uid() ); + addressee->setNote( body() ); + addressee->setCategories( TQStringList::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 TQString& uid ) +{ + mUid = uid; +} + +TQString ScalixBase::uid() const +{ + return mUid; +} + +void ScalixBase::setBody( const TQString& body ) +{ + mBody = body; +} + +TQString ScalixBase::body() const +{ + return mBody; +} + +void ScalixBase::setCategories( const TQString& categories ) +{ + mCategories = categories; +} + +TQString ScalixBase::categories() const +{ + return mCategories; +} + +void ScalixBase::setCreationDate( const TQDateTime& date ) +{ + mCreationDate = date; +} + +TQDateTime ScalixBase::creationDate() const +{ + return mCreationDate; +} + +void ScalixBase::setLastModified( const TQDateTime& date ) +{ + mLastModified = date; +} + +TQDateTime 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( TQDomElement& element, Email& email ) +{ + for ( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + TQString 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( TQDomElement& element, const Email& email, + const TQString& tagName ) const +{ + TQDomElement e = element.ownerDocument().createElement( tagName ); + element.appendChild( e ); + writeString( e, "display-name", email.displayName ); + writeString( e, "smtp-address", email.smtpAddress ); +} + +bool ScalixBase::loadAttribute( TQDomElement& element ) +{ + TQString 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( TQDomElement& 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", TQString::number( pilotSyncId() ) ); + if ( hasPilotSyncStatus() ) + writeString( element, "pilot-sync-status", TQString::number( pilotSyncStatus() ) ); + return true; +} + +bool ScalixBase::load( const TQString& xml ) +{ + TQString errorMsg; + int errorLine, errorColumn; + TQDomDocument document; + bool ok = document.setContent( xml, &errorMsg, &errorLine, &errorColumn ); + + if ( !ok ) { + tqWarning( "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( TQFile& xml ) +{ + TQString errorMsg; + int errorLine, errorColumn; + TQDomDocument document; + bool ok = document.setContent( &xml, &errorMsg, &errorLine, &errorColumn ); + + if ( !ok ) { + tqWarning( "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 ); +} + +TQDomDocument ScalixBase::domTree() +{ + TQDomDocument document; + + TQString p = "version=\"1.0\" encoding=\"UTF-8\""; + document.appendChild(document.createProcessingInstruction( "xml", p ) ); + + return document; +} + + +TQString ScalixBase::dateTimeToString( const TQDateTime& time ) +{ + return time.toString( Qt::ISODate ) + 'Z'; +} + +TQString ScalixBase::dateToString( const TQDate& date ) +{ + return date.toString( Qt::ISODate ); +} + +TQDateTime ScalixBase::stringToDateTime( const TQString& _date ) +{ + TQString date( _date ); + if ( date.endsWith( "Z" ) ) + date.truncate( date.length() - 1 ); + return TQDateTime::fromString( date, Qt::ISODate ); +} + +TQDate ScalixBase::stringToDate( const TQString& date ) +{ + return TQDate::fromString( date, Qt::ISODate ); +} + +TQString 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 TQString& s ) +{ + if ( s == "private" ) + return Private; + if ( s == "confidential" ) + return Confidential; + return Public; +} + +TQString ScalixBase::colorToString( const TQColor& color ) +{ + // Color is in the format "#RRGGBB" + return color.name(); +} + +TQColor ScalixBase::stringToColor( const TQString& s ) +{ + return TQColor( s ); +} + +void ScalixBase::writeString( TQDomElement& element, const TQString& tag, + const TQString& tagString ) +{ + if ( !tagString.isEmpty() ) { + TQDomElement e = element.ownerDocument().createElement( tag ); + TQDomText t = element.ownerDocument().createTextNode( tagString ); + e.appendChild( t ); + element.appendChild( e ); + } +} + +TQDateTime ScalixBase::localToUTC( const TQDateTime& time ) const +{ + return KPimPrefs::localTimeToUtc( time, mTimeZoneId ); +} + +TQDateTime ScalixBase::utcToLocal( const TQDateTime& time ) const +{ + return KPimPrefs::utcToLocalTime( time, mTimeZoneId ); +} diff --git a/tderesources/scalix/shared/scalixbase.h b/tderesources/scalix/shared/scalixbase.h new file mode 100644 index 000000000..7bff80a4b --- /dev/null +++ b/tderesources/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 <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <tqdom.h> +#include <tqdatetime.h> +#include <tqcolor.h> + +class TQFile; + +namespace KCal { + class Incidence; +} + +namespace KABC { + class Addressee; +} + +namespace Scalix { + +class ScalixBase { +public: + struct Email { + public: + Email( const TQString& name = TQString(), + const TQString& email = TQString() ) + : displayName( name ), smtpAddress( email ) + { + } + + TQString displayName; + TQString smtpAddress; + }; + + enum Sensitivity { Public = 0, Private = 1, Confidential = 2 }; + + explicit ScalixBase( const TQString& timezone = TQString() ); + virtual ~ScalixBase(); + + // Return a string identifying this type + virtual TQString type() const = 0; + + virtual void setUid( const TQString& uid ); + virtual TQString uid() const; + + virtual void setBody( const TQString& body ); + virtual TQString body() const; + + virtual void setCategories( const TQString& categories ); + virtual TQString categories() const; + + virtual void setCreationDate( const TQDateTime& date ); + virtual TQDateTime creationDate() const; + + virtual void setLastModified( const TQDateTime& date ); + virtual TQDateTime 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 TQString dateTimeToString( const TQDateTime& time ); + static TQString dateToString( const TQDate& date ); + static TQDateTime stringToDateTime( const TQString& time ); + static TQDate stringToDate( const TQString& date ); + + // String - Sensitivity conversion methods + static TQString sensitivityToString( Sensitivity ); + static Sensitivity stringToSensitivity( const TQString& ); + + // String - Color conversion methods + static TQString colorToString( const TQColor& ); + static TQColor stringToColor( const TQString& ); + + // Load this object by reading the XML file + bool load( const TQString& xml ); + bool load( TQFile& xml ); + + // Load this TQDomDocument + virtual bool loadXML( const TQDomDocument& xml ) = 0; + + // Serialize this object to an XML string + virtual TQString 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 TQDomDocument domTree(); + + bool loadEmailAttribute( TQDomElement& element, Email& email ); + + void saveEmailAttribute( TQDomElement& element, const Email& email, + const TQString& tagName = "email" ) const; + + // Load the attributes of this class + virtual bool loadAttribute( TQDomElement& ); + + // Save the attributes of this class + virtual bool saveAttributes( TQDomElement& ) const; + + // Return the product ID + virtual TQString productID() const = 0; + + // Write a string tag + static void writeString( TQDomElement&, const TQString&, const TQString& ); + + TQDateTime localToUTC( const TQDateTime& time ) const; + TQDateTime utcToLocal( const TQDateTime& time ) const; + + TQString mUid; + TQString mBody; + TQString mCategories; + TQDateTime mCreationDate; + TQDateTime mLastModified; + Sensitivity mSensitivity; + TQString mTimeZoneId; + + // KPilot synchronization stuff + bool mHasPilotSyncId, mHasPilotSyncStatus; + unsigned long mPilotSyncId; + int mPilotSyncStatus; +}; + +} + +#endif // SCALIXBASE_H diff --git a/tderesources/scalix/shared/subresource.cpp b/tderesources/scalix/shared/subresource.cpp new file mode 100644 index 000000000..bd3fdd8aa --- /dev/null +++ b/tderesources/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 + <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 TQString& 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 TQString& label ) +{ + mLabel = label; +} + +TQString SubResource::label() const +{ + return mLabel; +} + +void SubResource::setCompletionWeight( int completionWeight ) +{ + mCompletionWeight = completionWeight; +} + +int SubResource::completionWeight() const +{ + return mCompletionWeight; +} + +StorageReference::StorageReference( const TQString& resource, TQ_UINT32 sernum ) + : mResource( resource ), mSerialNumber( sernum ) +{ +} + +StorageReference::~StorageReference() +{ +} + +void StorageReference::setResource( const TQString& resource ) +{ + mResource = resource; +} + +TQString StorageReference::resource() const +{ + return mResource; +} + +void StorageReference::setSerialNumber( TQ_UINT32 serialNumber ) +{ + mSerialNumber = serialNumber; +} + +TQ_UINT32 StorageReference::serialNumber() const +{ + return mSerialNumber; +} diff --git a/tderesources/scalix/shared/subresource.h b/tderesources/scalix/shared/subresource.h new file mode 100644 index 000000000..3fcb6b03c --- /dev/null +++ b/tderesources/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 + <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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <tqstring.h> +#include <tqmap.h> + + +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 TQMap + SubResource() {} + + SubResource( bool active, bool writable, const TQString& 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 TQString& label ); + virtual TQString 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 + TQString 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 TQMap<TQString, 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 TQMap + StorageReference() {} + + StorageReference( const TQString& resource, TQ_UINT32 sernum ); + virtual ~StorageReference(); + + virtual void setResource( const TQString& resource ); + virtual TQString resource() const; + + virtual void setSerialNumber( TQ_UINT32 serialNumber ); + virtual TQ_UINT32 serialNumber() const; + +private: + TQString mResource; + TQ_UINT32 mSerialNumber; +}; + +typedef TQMap<TQString, StorageReference> UidMap; + +} + +#endif // SUBRESOURCE_H |