summaryrefslogtreecommitdiffstats
path: root/tderesources/kolab/shared
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-01-26 13:17:50 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-01-26 13:17:50 -0600
commitb363d2579af0a11b77e698aed2e1021c2233b644 (patch)
treef4a47b87354b7a6a3b266c8121bd8ddaeb7accaa /tderesources/kolab/shared
parent61bddfe3a7226b18c68a76124b727c736f431688 (diff)
downloadtdepim-b363d2579af0a11b77e698aed2e1021c2233b644.tar.gz
tdepim-b363d2579af0a11b77e698aed2e1021c2233b644.zip
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tderesources/kolab/shared')
-rw-r--r--tderesources/kolab/shared/CMakeLists.txt30
-rw-r--r--tderesources/kolab/shared/Makefile.am17
-rw-r--r--tderesources/kolab/shared/kmailconnection.cpp339
-rw-r--r--tderesources/kolab/shared/kmailconnection.h129
-rw-r--r--tderesources/kolab/shared/kolabbase.cpp487
-rw-r--r--tderesources/kolab/shared/kolabbase.h177
-rw-r--r--tderesources/kolab/shared/resourcekolabbase.cpp287
-rw-r--r--tderesources/kolab/shared/resourcekolabbase.h205
-rw-r--r--tderesources/kolab/shared/subresource.cpp133
-rw-r--r--tderesources/kolab/shared/subresource.h117
10 files changed, 1921 insertions, 0 deletions
diff --git a/tderesources/kolab/shared/CMakeLists.txt b/tderesources/kolab/shared/CMakeLists.txt
new file mode 100644
index 000000000..1509deb1a
--- /dev/null
+++ b/tderesources/kolab/shared/CMakeLists.txt
@@ -0,0 +1,30 @@
+#################################################
+#
+# (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_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/tderesources/lib
+ ${CMAKE_SOURCE_DIR}/libtdepim
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+
+##### resourcekolabshared (static) ##############
+
+set( KDE3_DCOPIDL_EXECUTABLE ${KDE3_DCOPIDLNG_EXECUTABLE} )
+
+tde_add_library( resourcekolabshared STATIC_PIC AUTOMOC
+ SOURCES
+ resourcekolabbase.cpp kmailconnection.cpp kolabbase.cpp subresource.cpp
+ kmailconnection.skel ${CMAKE_SOURCE_DIR}/kmail/kmailicalIface.stub
+)
diff --git a/tderesources/kolab/shared/Makefile.am b/tderesources/kolab/shared/Makefile.am
new file mode 100644
index 000000000..287620330
--- /dev/null
+++ b/tderesources/kolab/shared/Makefile.am
@@ -0,0 +1,17 @@
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/tderesources/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)/libtdepim/libtdepim.la ../../lib/libkgroupwarebase.la
+libresourcekolabshared_la_LDFLAGS = -no-undefined
+
+kmailicalIface_DCOPIDLNG = true
+
+kmailicalIface_DIR = $(top_srcdir)/kmail
diff --git a/tderesources/kolab/shared/kmailconnection.cpp b/tderesources/kolab/shared/kmailconnection.cpp
new file mode 100644
index 000000000..e82102a34
--- /dev/null
+++ b/tderesources/kolab/shared/kmailconnection.cpp
@@ -0,0 +1,339 @@
+/*
+ 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 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 "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 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 ) {
+ TQCString dcopService;
+
+ // if we are kmail (and probably kontact as well) ourselves, don't try to start us again
+ // this prevents a DCOP deadlock when launching the kmail while kontact is the IMAP backend
+ // provider (and probably vice versa)
+ if ( kapp->instanceName() == "kmail" ) {
+ // someone, probably ourselves, already offers the interface, if not stop here
+ const QCStringList services = kapp->dcopClient()->registeredApplications();
+ for ( uint i = 0; i < services.count(); ++i ) {
+ if ( services[i].find( "anonymous" ) == 0 ) // querying anonymous-XXXXX deadlocks as well, what are those anyway?
+ continue;
+ const QCStringList objs = kapp->dcopClient()->remoteObjects( services[i] );
+ if ( objs.contains( dcopObjectId ) ) {
+ dcopService = services[i];
+ break;
+ }
+ }
+ if ( dcopService.isEmpty() ) {
+ kdError(5650) << k_funcinfo << "Not connecting to KMail to prevent DCOP deadlock" << endl;
+ return false;
+ }
+ } else {
+ TQString error;
+ 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, bool, bool )",
+ "fromKMailAddSubresource( TQString, TQString, TQString, bool, bool )" ) )
+ 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,
+ bool writable,
+ bool alarmRelevant )
+{
+// kdDebug(5650) << "KMailConnection::fromKMailAddSubresource( " << type << ", "
+// << resource << " )\n";
+ mResource->fromKMailAddSubresource( type, resource, label,
+ writable, alarmRelevant );
+}
+
+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::kmailAttachmentMimetype( TQString & mimeType,
+ const TQString & resource,
+ TQ_UINT32 sernum,
+ const TQString & filename )
+{
+ if ( !connectToKMail() )
+ return false;
+ mimeType = mKMailIcalIfaceStub->attachmentMimetype( resource, sernum, filename );
+ return mKMailIcalIfaceStub->ok();
+}
+
+bool KMailConnection::kmailListAttachments(TQStringList &list,
+ const TQString & resource, TQ_UINT32 sernum)
+{
+ if ( !connectToKMail() )
+ return false;
+
+ list = mKMailIcalIfaceStub->listAttachments( resource, sernum );
+ 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::kmailAddSubresource( const TQString& resource,
+ const TQString& parent,
+ const TQString& contentsType )
+{
+ return connectToKMail()
+ && mKMailIcalIfaceStub->addSubresource( resource, parent, contentsType )
+ && mKMailIcalIfaceStub->ok();
+}
+
+bool KMailConnection::kmailRemoveSubresource( const TQString& resource )
+{
+ return connectToKMail()
+ && mKMailIcalIfaceStub->removeSubresource( resource )
+ && mKMailIcalIfaceStub->ok();
+}
+
+
+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/kolab/shared/kmailconnection.h b/tderesources/kolab/shared/kmailconnection.h
new file mode 100644
index 000000000..62003b5f9
--- /dev/null
+++ b/tderesources/kolab/shared/kmailconnection.h
@@ -0,0 +1,129 @@
+/*
+ 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 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 Kolab {
+
+class ResourceKolabBase;
+
+/**
+ 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, bool writable,
+ bool alarmRelevant );
+ void fromKMailDelSubresource( const TQString& type, const TQString& resource );
+ void fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map, const TQString& type,
+ const TQString& folder );
+
+public:
+ KMailConnection( ResourceKolabBase* 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 kmailAttachmentMimetype( TQString &mimeType, const TQString &resource,
+ TQ_UINT32 sernum, const TQString &filename );
+ bool kmailListAttachments( TQStringList &list, const TQString &resource,
+ TQ_UINT32 sernum );
+ 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 );
+ bool kmailAddSubresource( const TQString& resource,
+ const TQString& parent,
+ const TQString& contentsType );
+ bool kmailRemoveSubresource( const TQString& resource );
+
+private slots:
+ virtual void unregisteredFromDCOP( const TQCString& );
+
+private:
+ /** Connect a signal from KMail to a local slot. */
+ bool connectKMailSignal( const TQCString&, const TQCString& );
+
+ ResourceKolabBase* mResource;
+ DCOPClient* mDCOPClient;
+ KMailICalIface_stub* mKMailIcalIfaceStub;
+};
+
+}
+
+#endif // KMAILCONNECTION_H
diff --git a/tderesources/kolab/shared/kolabbase.cpp b/tderesources/kolab/shared/kolabbase.cpp
new file mode 100644
index 000000000..167f2566a
--- /dev/null
+++ b/tderesources/kolab/shared/kolabbase.cpp
@@ -0,0 +1,487 @@
+/*
+ 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 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 "kolabbase.h"
+
+#include <kabc/addressee.h>
+#include <libkcal/journal.h>
+#include <libtdepim/kpimprefs.h>
+#include <libemailfunctions/email.h>
+#include <kdebug.h>
+#include <tqfile.h>
+
+using namespace Kolab;
+
+
+KolabBase::KolabBase( const TQString& tz )
+ : mCreationDate( TQDateTime::currentDateTime() ),
+ mLastModified( TQDateTime::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 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 KolabBase::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 KolabBase::setUid( const TQString& uid )
+{
+ mUid = uid;
+}
+
+TQString KolabBase::uid() const
+{
+ return mUid;
+}
+
+void KolabBase::setBody( const TQString& body )
+{
+ mBody = body;
+}
+
+TQString KolabBase::body() const
+{
+ return mBody;
+}
+
+void KolabBase::setCategories( const TQString& categories )
+{
+ mCategories = categories;
+}
+
+TQString KolabBase::categories() const
+{
+ return mCategories;
+}
+
+void KolabBase::setCreationDate( const TQDateTime& date )
+{
+ mCreationDate = date;
+}
+
+TQDateTime KolabBase::creationDate() const
+{
+ return mCreationDate;
+}
+
+void KolabBase::setLastModified( const TQDateTime& date )
+{
+ mLastModified = date;
+}
+
+TQDateTime 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( 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();
+ const TQString tagName = e.tagName();
+
+ if ( tagName == "display-name" ) {
+ // Quote the text in case it contains commas or other quotable chars.
+ TQString tusername = KPIM::quoteNameIfNecessary( e.text() );
+
+ TQString tname, temail;
+ // ignore the return value because it will always be false since
+ // tusername does not contain "@domain".
+ KPIM::getNameAndMail( tusername, tname, temail );
+ email.displayName = tname;
+ }
+ 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( 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 KolabBase::loadAttribute( TQDomElement& element )
+{
+ const TQString 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( 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 KolabBase::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 KolabBase::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 KolabBase::domTree()
+{
+ TQDomDocument document;
+
+ TQString p = "version=\"1.0\" encoding=\"UTF-8\"";
+ document.appendChild(document.createProcessingInstruction( "xml", p ) );
+
+ return document;
+}
+
+
+TQString KolabBase::dateTimeToString( const TQDateTime& time )
+{
+ return time.toString( Qt::ISODate ) + 'Z';
+}
+
+TQString KolabBase::dateToString( const TQDate& date )
+{
+ return date.toString( Qt::ISODate );
+}
+
+TQDateTime KolabBase::stringToDateTime( const TQString& _date )
+{
+ TQString date( _date );
+ //Deal with data from some clients that always append a Z to dates.
+ if ( date.endsWith( "ZZ" ) )
+ date.truncate( date.length() - 2 );
+ //In TQt3, Qt::ISODate cannot handle a trailing Z for UTC, so remove if found.
+ else if ( date.endsWith( "Z" ) )
+ date.truncate( date.length() - 1 );
+ return TQDateTime::fromString( date, Qt::ISODate );
+}
+
+TQDate KolabBase::stringToDate( const TQString& date )
+{
+ return TQDate::fromString( date, Qt::ISODate );
+}
+
+TQString 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 TQString& s )
+{
+ if ( s == "private" )
+ return Private;
+ if ( s == "confidential" )
+ return Confidential;
+ return Public;
+}
+
+TQString KolabBase::colorToString( const TQColor& color )
+{
+ // Color is in the format "#RRGGBB"
+ return color.name();
+}
+
+TQColor KolabBase::stringToColor( const TQString& s )
+{
+ return TQColor( s );
+}
+
+void KolabBase::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 KolabBase::localToUTC( const TQDateTime& time ) const
+{
+ return KPimPrefs::localTimeToUtc( time, mTimeZoneId );
+}
+
+TQDateTime KolabBase::utcToLocal( const TQDateTime& time ) const
+{
+ return KPimPrefs::utcToLocalTime( time, mTimeZoneId );
+}
diff --git a/tderesources/kolab/shared/kolabbase.h b/tderesources/kolab/shared/kolabbase.h
new file mode 100644
index 000000000..294a7d81b
--- /dev/null
+++ b/tderesources/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 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 KOLABBASE_H
+#define KOLABBASE_H
+
+#include <tqdom.h>
+#include <tqdatetime.h>
+#include <tqcolor.h>
+
+class TQFile;
+
+namespace KCal {
+ class Incidence;
+}
+
+namespace KABC {
+ class Addressee;
+}
+
+namespace Kolab {
+
+class KolabBase {
+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 KolabBase( const TQString& timezone = TQString() );
+ virtual ~KolabBase();
+
+ // 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 // KOLABBASE_H
diff --git a/tderesources/kolab/shared/resourcekolabbase.cpp b/tderesources/kolab/shared/resourcekolabbase.cpp
new file mode 100644
index 000000000..a56538a67
--- /dev/null
+++ b/tderesources/kolab/shared/resourcekolabbase.cpp
@@ -0,0 +1,287 @@
+/*
+ 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 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 "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 <tqtextstream.h>
+#include <kdebug.h>
+
+using namespace Kolab;
+
+static unsigned int uniquifier = 0;
+
+ResourceKolabBase::ResourceKolabBase( const TQCString& objId )
+ : mSilent( false )
+{
+ TDEGlobal::locale()->insertCatalogue( "kres_kolab" );
+ TDEGlobal::locale()->insertCatalogue( "libkcal" );
+ TQString uniqueObjId = TQString( objId ) + TQString::number( uniquifier++ );
+ mConnection = new KMailConnection( this, uniqueObjId.utf8() );
+}
+
+ResourceKolabBase::~ResourceKolabBase()
+{
+ delete mConnection;
+}
+
+
+bool ResourceKolabBase::kmailSubresources( TQValueList<KMailICalIface::SubResource>& lst,
+ const TQString& contentsType ) const
+{
+ return mConnection->kmailSubresources( lst, contentsType );
+}
+
+bool ResourceKolabBase::kmailTriggerSync( const TQString& contentsType ) const
+{
+ return mConnection->kmailTriggerSync( contentsType );
+}
+
+
+bool ResourceKolabBase::kmailIncidencesCount( int &count,
+ const TQString& mimetype,
+ const TQString& resource ) const
+{
+ return mConnection->kmailIncidencesCount( count, mimetype, resource );
+}
+
+bool ResourceKolabBase::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 ResourceKolabBase::kmailGetAttachment( KURL& url, const TQString& resource,
+ TQ_UINT32 sernum,
+ const TQString& filename ) const
+{
+ return mConnection->kmailGetAttachment( url, resource, sernum, filename );
+}
+
+bool ResourceKolabBase::kmailAttachmentMimetype( TQString & mimeType, TQString & resource,
+ TQ_UINT32 sernum, const TQString & filename ) const
+{
+ return mConnection->kmailAttachmentMimetype( mimeType, resource, sernum, filename );
+}
+
+bool ResourceKolabBase::kmailListAttachments( TQStringList &list,
+ const TQString & resource,
+ TQ_UINT32 sernum ) const
+{
+ return mConnection->kmailListAttachments( list, resource, sernum );
+}
+
+bool ResourceKolabBase::kmailDeleteIncidence( const TQString& resource,
+ TQ_UINT32 sernum )
+{
+ return mSilent || mConnection->kmailDeleteIncidence( resource, sernum );
+}
+
+static TQString 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";
+ TQString firstPartTextUntranslated = TQString::fromLatin1( firstPartTextToTranslate ).arg( url );
+ TQString firstPartText = i18n( firstPartTextToTranslate ).arg( url );
+ if ( firstPartText != firstPartTextUntranslated ) {
+ firstPartText.append("\n\n-----------------------------------------------------\n\n");
+ firstPartText.append( firstPartTextUntranslated );
+ }
+ return firstPartText;
+}
+
+bool ResourceKolabBase::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.");
+
+ 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 );
+ TQTextStream* stream = file.textStream();
+ stream->setEncoding( TQTextStream::UnicodeUTF8 );
+ *stream << xml;
+ file.close();
+
+ // Add the xml file as an attachment
+ TQStringList attachmentURLs = _attachmentURLs;
+ TQStringList attachmentMimeTypes = _attachmentMimetypes;
+ TQStringList 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 );
+ }
+}
+
+TQString ResourceKolabBase::configFile( const TQString& type ) const
+{
+ return locateLocal( "config",
+ TQString( "tderesources/kolab/%1rc" ).arg( type ) );
+}
+
+bool ResourceKolabBase::connectToKMail() const
+{
+ return mConnection->connectToKMail();
+}
+
+bool ResourceKolabBase::kmailAddSubresource( const TQString& resource,
+ const TQString& parent,
+ const TQString& contentsType )
+{
+ return mConnection->kmailAddSubresource( resource, parent, contentsType );
+}
+
+bool ResourceKolabBase::kmailRemoveSubresource( const TQString& resource )
+{
+ return mConnection->kmailRemoveSubresource( resource );
+}
+
+TQString ResourceKolabBase::findWritableResource( const ResourceType &type,
+ const ResourceMap& resources,
+ const TQString& text )
+{
+ mErrorCode = NoError;
+
+ // 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;
+
+ TQString errorText;
+ switch( type ) {
+ case Events:
+ errorText = i18n( "You have no writable event folders so saving will not be possible.\n"
+ "Please create or activate at least one writable event folder and try again." );
+ break;
+ case Tasks:
+ errorText = i18n( "You have no writable task folders so saving will not be possible.\n"
+ "Please create or activate at least one writable task folder and try again." );
+ break;
+ case Incidences:
+ errorText = i18n( "You have no writable calendar folder so saving will not be possible.\n"
+ "Please create or activate at least one writable calendar folder and try again." );
+ break;
+ case Notes:
+ errorText = i18n( "You have no writable notes folders so saving will not be possible.\n"
+ "Please create or activate at least one writable notes folder and try again." );
+ break;
+ case Contacts:
+ errorText = i18n( "You have no writable addressbook folder so saving will not be possible.\n"
+ "Please create or activate at least one writable addressbook folder and try again." );
+ break;
+ }
+
+ KMessageBox::error( 0, errorText );
+ mErrorCode = NoWritableFound;
+ return TQString();
+ }
+ if ( possible.count() == 1 )
+ // Just one found
+ return possible.begin().data(); // yes this is the subresource key, i.e. location
+
+ TQString 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
+ TQString chosenLabel = KPIM::FolderSelectDialog::getItem( i18n( "Select Resource Folder" ),
+ t, possible.keys() );
+ if ( chosenLabel.isEmpty() ) {
+ // cancelled
+ mErrorCode = UserCancel;
+ return TQString();
+ }
+ return possible[chosenLabel];
+}
+
+KMailICalIface::StorageFormat ResourceKolabBase::kmailStorageFormat( const TQString &folder ) const
+{
+ KMailICalIface::StorageFormat format = (KMailICalIface::StorageFormat) 3;
+ mConnection->kmailStorageFormat( format, folder );
+ return format;
+}
diff --git a/tderesources/kolab/shared/resourcekolabbase.h b/tderesources/kolab/shared/resourcekolabbase.h
new file mode 100644
index 000000000..f32c151fd
--- /dev/null
+++ b/tderesources/kolab/shared/resourcekolabbase.h
@@ -0,0 +1,205 @@
+/*
+ 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 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 RESOURCEKOLABBASE_H
+#define RESOURCEKOLABBASE_H
+
+#include <tqstring.h>
+#include <tqmap.h>
+#include <tqstringlist.h>
+
+#include "subresource.h"
+#include <kmail/kmailicalIface.h>
+
+class TQCString;
+class KURL;
+
+namespace Kolab {
+
+enum ResourceType { Tasks, Events, Incidences, Contacts, Notes };
+
+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 TQCString& objId );
+ virtual ~ResourceKolabBase();
+
+ // 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,
+ bool alarmRelevant ) = 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;
+
+ /** Get the mimetype of the specified attachment. */
+ bool kmailAttachmentMimetype( TQString &mimeType, TQString &resource,
+ TQ_UINT32 sernum, const TQString &filename ) const;
+
+ /// List all attachments of a mail.
+ bool kmailListAttachments( TQStringList &list, const TQString &resource,
+ TQ_UINT32 sernum ) 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() );
+
+ bool kmailAddSubresource( const TQString& resource, const TQString& parent,
+ const TQString& contentsType );
+ bool kmailRemoveSubresource( const TQString& resource );
+
+ /// 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 ResourceType &type,
+ const ResourceMap& resources,
+ const TQString& text = TQString() );
+
+ enum ErrorCode {
+ NoError,
+ NoWritableFound, /**< No writable resource is available */
+ UserCancel /**< User canceled the operation */
+ };
+ ErrorCode mErrorCode;
+
+ 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/kolab/shared/subresource.cpp b/tderesources/kolab/shared/subresource.cpp
new file mode 100644
index 000000000..7520d275a
--- /dev/null
+++ b/tderesources/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 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 Kolab;
+
+SubResource::SubResource( bool active, bool writable,
+ bool alarmRelevant, const TQString& label,
+ int completionWeight )
+ : mActive( active ), mWritable( writable ), mAlarmRelevant( alarmRelevant ),
+ mLabel( label ), mCompletionWeight( completionWeight )
+{
+}
+
+SubResource::SubResource( bool active, bool writable,
+ const TQString& 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 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/kolab/shared/subresource.h b/tderesources/kolab/shared/subresource.h
new file mode 100644
index 000000000..79104a747
--- /dev/null
+++ b/tderesources/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 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 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 TQMap
+ SubResource() {}
+
+ SubResource( bool active, bool writable, const TQString& label,
+ int completionWeight = 100 );
+
+ SubResource( bool active, bool writable, bool alarmRelevant,
+ 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 setAlarmRelevant( bool active );
+ virtual bool alarmRelevant() 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
+ bool mAlarmRelevant; // Set if the alarms from this resource are of
+ // interest to the user, as per folder acls
+ 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