summaryrefslogtreecommitdiffstats
path: root/kresources/exchange
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kresources/exchange
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kresources/exchange')
-rw-r--r--kresources/exchange/Makefile.am23
-rw-r--r--kresources/exchange/dateset.cpp280
-rw-r--r--kresources/exchange/dateset.h87
-rw-r--r--kresources/exchange/exchange.desktop54
-rw-r--r--kresources/exchange/exchange_deprecated.desktop49
-rw-r--r--kresources/exchange/resourceexchange.cpp605
-rw-r--r--kresources/exchange/resourceexchange.h248
-rw-r--r--kresources/exchange/resourceexchangeconfig.cpp153
-rw-r--r--kresources/exchange/resourceexchangeconfig.h66
9 files changed, 1565 insertions, 0 deletions
diff --git a/kresources/exchange/Makefile.am b/kresources/exchange/Makefile.am
new file mode 100644
index 00000000..556e3df6
--- /dev/null
+++ b/kresources/exchange/Makefile.am
@@ -0,0 +1,23 @@
+METASOURCES = AUTO
+
+INCLUDES = -I$(top_srcdir)/korganizer/interfaces \
+ -I$(top_srcdir)/interfaces \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/libkpimexchange/core -I$(top_builddir)/libkpimexchange/core \
+ -I$(top_srcdir)/libical/src/libical -I$(top_srcdir)/libical/src/libicalss \
+ -I$(top_builddir)/libical/src/libical -I$(top_builddir)/libical/src/libicalss \
+ $(all_includes)
+
+kde_module_LTLIBRARIES = resourcecalendarexchange.la
+
+resourcecalendarexchange_la_SOURCES = resourceexchange.cpp resourceexchangeconfig.cpp dateset.cpp
+resourcecalendarexchange_la_LDFLAGS= $(all_libraries) -module $(KDE_PLUGIN)
+resourcecalendarexchange_la_LIBADD= -lkresources \
+ $(top_builddir)/libkcal/libkcal.la \
+ $(top_builddir)/libkpimexchange/libkpimexchange.la
+
+servicedir = $(kde_servicesdir)/kresources/kcal
+service_DATA= exchange.desktop
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kres_exchange.pot
diff --git a/kresources/exchange/dateset.cpp b/kresources/exchange/dateset.cpp
new file mode 100644
index 00000000..f7981096
--- /dev/null
+++ b/kresources/exchange/dateset.cpp
@@ -0,0 +1,280 @@
+/*
+ This file is part of libkpimexchange.
+ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ 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.
+*/
+
+// $Id$
+
+#include <qptrlist.h>
+#include <qdatetime.h>
+#include <qpair.h>
+
+#include <kdebug.h>
+
+#include "dateset.h"
+
+DateSet::DateSet()
+{
+ kdDebug() << "Creating DateSet" << endl;
+ // mOldestDate =
+ mDates = new RangeList();
+ mDates->setAutoDelete( true );
+}
+
+DateSet::~DateSet()
+{
+ kdDebug() << "Deleting DateSet" << endl;
+ delete mDates;
+}
+
+void DateSet::add( QDate const& date )
+{
+ if (mDates->isEmpty()) {
+ mDates->insert( 0, new QPair<QDate,QDate>( date, date ) );
+ return;
+ }
+ int i = find( date );
+ mDates->insert( i, new QPair<QDate,QDate>( date, date ) );
+ tryMerge( i );
+ tryMerge( i-1 );
+}
+
+void DateSet::add( QDate const& from, QDate const& to )
+{
+ if (mDates->isEmpty()) {
+ mDates->insert( 0, new QPair<QDate,QDate>( from, to ) );
+ return;
+ }
+ uint i = find( from );
+ kdDebug() << "Adding range at position " << i << endl;
+ mDates->insert( i, new QPair<QDate,QDate>( from, to ) );
+
+ do {
+ } while ( tryMerge( i ) );
+ do {
+ } while ( tryMerge( i-1 ) );
+/*
+ QPair<QDate,QDate>* item = mDates->at( i );
+
+ if (to >= item->first)
+ return;
+
+ if (to.daysTo( item->first ) == 1 )
+ item->first = from;
+ else
+ mDates->insert( i, new QPair<QDate,QDate>( from, to ) );
+*/
+}
+
+void DateSet::remove( QDate const& date )
+{
+ if (mDates->isEmpty()) {
+ return;
+ }
+
+ uint i = find( date );
+ if ( i == mDates->count() )
+ return;
+
+ QPair<QDate,QDate>* item = mDates->at( i );
+ if ( date < item->first )
+ return;
+ if ( date == item->first ) {
+ if ( date == item->second ) {
+ mDates->remove( i );
+ } else {
+ item->first = item->first.addDays( 1 );
+ }
+ return;
+ }
+
+ if ( date == item->second ) {
+ item->second = item->second.addDays( -1 );
+ } else {
+ mDates->insert( i, new QPair<QDate,QDate>(item->first, date.addDays( -1 ) ) );
+ item->first = date.addDays( 1 );
+ }
+}
+
+void DateSet::remove( QDate const& from, QDate const& to )
+{
+ if (mDates->isEmpty()) {
+ return;
+ }
+
+ uint i = find( from );
+ if ( i == mDates->count() )
+ return;
+
+ while( i < mDates->count() ) {
+ QPair<QDate,QDate>* item = mDates->at( i );
+ // Check if we're done: next item is later dan removal period
+ if ( to < item->first )
+ break;
+
+ // Check if entire item should be removed
+ if ( from <= item->first && to >= item->second ) {
+ mDates->remove( i );
+ // Don't skip the next range
+ continue;
+ }
+
+ // Check if we should take a slice out of the middle of the item
+ if ( from > item->first && to < item->second ) {
+ mDates->insert( i, new QPair<QDate,QDate>( item->first, from.addDays( -1 ) ) );
+ item->first = to.addDays( 1 );
+ break; // We're done
+ }
+
+ // Now check if we should take off the beginning of the item
+ if ( from <= item->first ) {
+ item->first = to.addDays( 1 );
+ // Finished
+ break;
+ }
+
+ // Only one possibility left: we should take off the end
+ // of the current range
+ item->second = from.addDays( -1 );
+ i++;
+ }
+}
+
+bool DateSet::contains( QDate const& date )
+{
+ if (mDates->isEmpty()) {
+ return false;
+ }
+
+ uint i = find( date );
+// kdDebug() << "contains looking for " << date.toString() << " at range " << i << endl;
+ if ( i == mDates->count() )
+ return false;
+
+ QPair<QDate,QDate>* item = mDates->at( i );
+ // kdDebug() << "contains looking at range " << item->first.toString() << " -- " << item->second.toString() << endl;
+ return ( item->first <= date );
+}
+
+// returns true if and only if the whole range is in the set
+bool DateSet::contains( QDate const& from, QDate const& to )
+{
+ if (mDates->isEmpty()) {
+ return false;
+ }
+
+ uint i = find( from );
+ if ( i == mDates->count() )
+ return false;
+
+ QPair<QDate,QDate>* item = mDates->at( i );
+
+ return ( from >= item->first && to <= item->second );
+}
+
+// Finds the index in mDates of the range containing date, if it
+// exists. Else, return the index of the range following the date.
+// If mDates is empty, return 0.
+// If date is later than the last item in mDates, return mDates->count()
+
+int DateSet::find( QDate const& date )
+{
+ if ( mDates->isEmpty() )
+ return 0;
+
+ int start = 0;
+ int end = mDates->count();
+ while ( start < end ) {
+ int i = start + (end-start) / 2;
+ // kdDebug() << start << ", " << i << ", " << end << endl;
+ QPair<QDate,QDate> *item = mDates->at( i );
+ if ( item->first <= date && date <= item->second )
+ return i;
+ if ( date > item->second ) {
+ start = i+1;
+ } else { // this means date < item->first
+ end = i;
+ }
+ }
+
+ // kdDebug() << "Found for date " << date.toString() << " range " << end << endl;
+ return end;
+/*
+ // Now either start==end or start+1 == end
+ if ( mDates->at( end )->second < date )
+ return end+1;
+ else if (mDates->at( start )->first > date )
+ return start;
+ else
+ return end;
+*/
+}
+
+void DateSet::print()
+{
+ for( uint i=0; i<mDates->count(); i++ )
+ {
+ QDate start = mDates->at( i )->first;
+ QDate end = mDates->at( i )->second;
+ if (start == end)
+ kdDebug() << start.toString() << endl;
+ else
+ kdDebug() << "(" << start.toString() << " , " << end.toString() << ")" << endl;
+ }
+}
+
+// Try and merge range i with range i+1
+// NOT TRUE preconditions: range i starts before range i+1, but MAY end later!
+// preconditions: range i starts before or in range i+1
+bool DateSet::tryMerge( int i )
+{
+ if ( i < 0 || i+1 >= (int)(mDates->count()) )
+ return false;
+
+ QPair<QDate,QDate>* item1 = mDates->at( i );
+ QPair<QDate,QDate>* item2 = mDates->at( i+1 );
+
+ // First case: item1 starts before or on the same date as item2
+ if ( item1->first <= item2->first ) {
+ // Check for overlap
+ if ( item1->second >= item2->first ||
+ item1->second.daysTo( item2->first ) == 1 ) {
+ kdDebug() << "Merging items " << i << " and " << (i+1) << endl;
+ if (item1->second < item2->second) item1->second = item2->second;
+ mDates->remove( i+1 );
+ return true;
+ }
+ return false;
+ }
+
+ // Second case: item1 starts later than item2 (but at the latest on
+ // the last day of item2, see preconditions!)
+
+ // Check for overlap
+ if ( item1->second >= item2->first ||
+ item1->second.daysTo( item2->first ) == 1 ) {
+ kdDebug() << "Merging items " << i << " and " << (i+1) << endl;
+ if (item1->second < item2->second) item1->second = item2->second;
+ item1->first = item2->first;
+ mDates->remove( i+1 );
+ return true;
+ }
+ return false;
+}
+
+
diff --git a/kresources/exchange/dateset.h b/kresources/exchange/dateset.h
new file mode 100644
index 00000000..5041f0d5
--- /dev/null
+++ b/kresources/exchange/dateset.h
@@ -0,0 +1,87 @@
+/*
+ This file is part of libkpimexchange.
+ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ 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.
+*/
+
+// $Id$
+
+#ifndef _DATESET_H
+#define _DATESET_H
+
+#include <qdatetime.h>
+#include <qpair.h>
+#include <qptrlist.h>
+
+/*
+class DateRange {
+ public:
+ DateRange() { }
+ DateRange( QDate const& from, QDate const& to )
+ : mFrom( from ), mTo( to ) { }
+ bool operator< ( const DateRange& r ) { return mFrom < r.from(); }
+ bool contains( QDate const& d ) { return ( mFrom <= d && d <= mTo ); }
+ bool contains( QDate const& from, QDate const& to ) { return ( mFrom <= from && to <= mTo ); }
+
+ QDate from() { return mFrom; }
+ QDate to() { return mTo; }
+
+ private:
+ QDate mFrom;
+ QDate mTo;
+}
+*/
+
+class RangeList : public QPtrList< QPair<QDate, QDate> > {
+ protected:
+ virtual int compareItems(QPtrCollection::Item item1, QPtrCollection::Item item2) {
+ QPair<QDate,QDate> *i1 = static_cast<QPair<QDate,QDate> *> (item1);
+ QPair<QDate,QDate> *i2 = static_cast<QPair<QDate,QDate> *> (item2);
+ if ( *i1 < *i2 ) return -1;
+ if ( *i2 < *i1 ) return 1;
+ return 0;
+ }
+};
+
+class DateSet {
+ public:
+ DateSet();
+ ~DateSet();
+
+ void add( QDate const& date );
+ void add( QDate const& from, QDate const& to );
+
+ void remove( QDate const& date );
+ void remove( QDate const& from, QDate const& to );
+
+ bool contains( QDate const& date );
+ // returns true if and only if the whole range is in the set
+ bool contains( QDate const& from, QDate const& to );
+
+ int find( QDate const &date );
+ void print();
+
+ protected:
+ private:
+ bool tryMerge( int i );
+ RangeList *mDates;
+
+ QDate mOldestDate;
+ QDate mNewestDate;
+};
+
+#endif
diff --git a/kresources/exchange/exchange.desktop b/kresources/exchange/exchange.desktop
new file mode 100644
index 00000000..9342e3ba
--- /dev/null
+++ b/kresources/exchange/exchange.desktop
@@ -0,0 +1,54 @@
+[Desktop Entry]
+Type=Service
+X-KDE-Library=resourcecalendarexchange
+X-KDE-ResourceFamily=calendar
+X-KDE-ResourceType=exchange
+ServiceTypes=KResources/Plugin
+Name=Exchange 2000 Server
+Name[af]=Exchange 2000 Bediener
+Name[be]=Сэрвэр Exchange 2000
+Name[bg]=Сървър Exchange 2000
+Name[br]=Servijer Exchange 2000
+Name[ca]=Servidor Exchange 2000
+Name[cs]=Exchange 2000 server
+Name[da]=Exchange 2000 server
+Name[el]=Εξυπηρετητής Exchange2000
+Name[es]=Servidor Exchange 2000
+Name[et]=Exchange 2000 server
+Name[eu]=Exchange 2000 zerbitzaria
+Name[fa]=کارساز Exchange ۲۰۰۰
+Name[fi]=Exchange 2000 -palvelin
+Name[fr]=Serveur Exchange2000
+Name[fy]=Exchange2000-tsjinner
+Name[ga]=Freastalaí Exchange 2000
+Name[gl]=Servidor Exchange 2000
+Name[hu]=Exchange 2000-kiszolgáló
+Name[is]=Exchange 2000 þjónn
+Name[it]=Server Exchange 2000
+Name[ja]=Exchange 2000 サーバ
+Name[ka]=სერვერი Exchange 2000
+Name[kk]=MS Exchange 2000 сервері
+Name[km]=ម៉ាស៊ីន​បម្រើ Exchange ២០០០
+Name[lt]=Exchange 2000 serveris
+Name[mk]=Exchange 2000-сервер
+Name[ms]=Pelayan Exchange 2000
+Name[nb]=Exchange 2000-tjener
+Name[nds]=Exchange2000-Server
+Name[ne]=एक्सचेन्ज 2000 सर्भर
+Name[nl]=Exchange2000-server
+Name[nn]=Exchange 2000-tenar
+Name[pl]=Serwer Exchange 2000
+Name[pt]=Servidor Exchange 2000
+Name[pt_BR]=Servidor Exchange2000
+Name[ru]=Сервер Microsoft Exchange 2000
+Name[sk]=Exchange 2000 server
+Name[sl]=Strežnik Exchange 2000
+Name[sr]=Exchange 2000 сервер
+Name[sr@Latn]=Exchange 2000 server
+Name[sv]=Exchange 2000-server
+Name[ta]=பரிமாற்ற 2000 சேவகன்
+Name[tr]=Exchange 2000 Sunucusu
+Name[uk]=Сервер Exchange 2000
+Name[zh_CN]=Exchange 2000 服务器
+Name[zh_TW]=Exchange 2000 伺服器
+
diff --git a/kresources/exchange/exchange_deprecated.desktop b/kresources/exchange/exchange_deprecated.desktop
new file mode 100644
index 00000000..70ffbc63
--- /dev/null
+++ b/kresources/exchange/exchange_deprecated.desktop
@@ -0,0 +1,49 @@
+[Desktop Entry]
+Hidden=true
+Name=Exchange 2000 Server (deprecated)
+Name[af]=Exchange 2000 Bediener (nie verder ondersteun)
+Name[bg]=Сървър Exchange 2000 (остаряло)
+Name[ca]=Servidor Exchange 2000 (desaconsellat)
+Name[cs]=Exchange 2000 server (zastaralé)
+Name[da]=Exchange 2000 server (forældet)
+Name[de]=Exchange 2000 Server (veraltet)
+Name[el]=Εξυπηρετητής Exchange2000 (ξεπερασμένος)
+Name[es]=Servidor Exchange 2000 (obsoleto)
+Name[et]=Exchange 2000 server (iganenud)
+Name[eu]=Exchange 2000 zerbitzaria (zaharkituta)
+Name[fa]=کارسازExchange ۲۰۰۰ (محکوم)
+Name[fi]=Exchange 2000 -palvelin (vanhentunut)
+Name[fr]=Serveur Exchange2000 (désuet)
+Name[fy]=Exchange 2000-tsjinner (ôfrieden)
+Name[ga]=Freastalaí Exchange 2000 (as dáta)
+Name[gl]=Servidor Exchange 2000 (desaprobado)
+Name[hu]=Exchange 2000-kiszolgáló (elavult)
+Name[is]=Exchange 2000 þjónn (úrelt)
+Name[it]=Server Exchange 2000 (deprecato)
+Name[ja]=Exchange 2000 サーバ (廃止予定)
+Name[ka]=სერვერი Exchange 2000 (მოძველებული)
+Name[kk]=MS Exchange 2000 сервері (ескірген)
+Name[km]=ម៉ាស៊ីន​បម្រើ Exchange ២០០០ (មិន​សូវ​ល្អ)
+Name[lt]=Exchange 2000 serveris (deprecated)
+Name[mk]=Exchange 2000-сервер (застарено)
+Name[ms]=Pelayan Exchange 2000 (tidak disetujui)
+Name[nb]=Exchange 2000-tjener (frarådet)
+Name[nds]=Exchange2000-Server (utlopen Ünnerstütten)
+Name[ne]=एक्सचेन्ज २००० सर्भर (अनुचित ठानिएको)
+Name[nl]=Exchange 2000-server (afgeraden)
+Name[nn]=Exchange 2000-tenar (frårådd)
+Name[pl]=Serwer Exchange 2000 (przestarzałe)
+Name[pt]=Servidor Exchange 2000 (depreciado)
+Name[pt_BR]=Servidor Exchange2000 (versão de compatibilidade)
+Name[ru]=Сервер Microsoft Exchange 2000 (устаревший)
+Name[sk]=Exchange 2000 server (deprecated)
+Name[sl]=Strežnik Exchange 2000 (opuščeno)
+Name[sr]=Exchange 2000 сервер (неодобраван)
+Name[sr@Latn]=Exchange 2000 server (neodobravan)
+Name[sv]=Exchange 2000-server (avråds från)
+Name[ta]=பரிமாற்ற 2000 சேவகன் (மாறுபாடானது)
+Name[tr]=Exchange 2000 Sunucusu
+Name[uk]=Сервер Exchange 2000 (застаріле)
+Name[zh_CN]=Exchange 2000 服务器(不推荐使用)
+Name[zh_TW]=Exchange 2000 伺服器(已廢除)
+
diff --git a/kresources/exchange/resourceexchange.cpp b/kresources/exchange/resourceexchange.cpp
new file mode 100644
index 00000000..35524492
--- /dev/null
+++ b/kresources/exchange/resourceexchange.cpp
@@ -0,0 +1,605 @@
+/*
+ This file is part of libkpimexchange.
+ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ 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.
+*/
+
+#include <stdlib.h>
+
+#include <qdatetime.h>
+#include <qstring.h>
+#include <qptrlist.h>
+#include <qwidgetlist.h>
+#include <qwidget.h>
+
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kstringhandler.h>
+#include <kglobal.h>
+#include <klocale.h>
+
+#include <libkcal/calendarlocal.h>
+#include <libkcal/calendar.h>
+#include <libkcal/journal.h>
+
+#include <kresources/configwidget.h>
+
+#include <kabc/locknull.h>
+
+#include "dateset.h"
+#include "exchangeaccount.h"
+#include "exchangeclient.h"
+#include "exchangemonitor.h"
+
+#include "resourceexchange.h"
+#include "resourceexchangeconfig.h"
+
+
+using namespace KCal;
+using namespace KPIM;
+
+typedef KRES::PluginFactory<ResourceExchange,ResourceExchangeConfig> ExchangeFactory;
+
+// FIXME: Use K_EXPORT_COMPONENT_FACTORY( resourcecalendarexchange, ExchangeFactory ); here
+// Problem: How to insert the catalogue!
+extern "C"
+{
+ void* init_resourcecalendarexchange()
+ {
+ KGlobal::locale()->insertCatalogue( "kres_exchange" );
+ return new ExchangeFactory;
+ }
+}
+
+class ResourceExchange::EventInfo {
+public:
+ KCal::Event* event;
+ KURL url;
+ long updateWatch;
+};
+
+ResourceExchange::ResourceExchange( const KConfig *config )
+ : ResourceCalendar( config ), mClient(0), mMonitor(0), mCache(0), mDates(0),
+ mEventDates(0), mCacheDates(0)
+{
+ mLock = new KABC::LockNull( true );
+
+ mTimeZoneId = QString::fromLatin1( "UTC" );
+
+ kdDebug() << "Creating ResourceExchange" << endl;
+ if (config ) {
+ mAccount = new ExchangeAccount(
+ config->readEntry( "ExchangeHost" ),
+ config->readEntry( "ExchangePort" ),
+ config->readEntry( "ExchangeAccount" ),
+ KStringHandler::obscure( config->readEntry( "ExchangePassword" ) ),
+ config->readEntry( "ExchangeMailbox" ) );
+ mCachedSeconds = config->readNumEntry( "ExchangeCacheTimeout", 600 );
+ mAutoMailbox = config->readBoolEntry( "ExchangeAutoMailbox", true );
+ } else {
+ mAccount = new ExchangeAccount( "", "", "", "" );
+ mCachedSeconds = 600;
+ }
+}
+
+ResourceExchange::~ResourceExchange()
+{
+ kdDebug() << "Destructing ResourceExchange" << endl;
+
+ close();
+
+ delete mAccount; mAccount = 0;
+}
+
+void ResourceExchange::writeConfig( KConfig* config )
+{
+ ResourceCalendar::writeConfig( config );
+ config->writeEntry( "ExchangeHost", mAccount->host() );
+ config->writeEntry( "ExchangePort", mAccount->port() );
+ config->writeEntry( "ExchangeAccount", mAccount->account() );
+ config->writeEntry( "ExchangeMailbox", mAccount->mailbox() );
+ config->writeEntry( "ExchangePassword", KStringHandler::obscure( mAccount->password() ) );
+ config->writeEntry( "ExchangeCacheTimeout", mCachedSeconds );
+ config->writeEntry( "ExchangeAutoMailbox", mAutoMailbox );
+}
+
+bool ResourceExchange::doOpen()
+{
+ kdDebug() << "ResourceExchange::doOpen()" << endl;
+
+ mClient = new ExchangeClient( mAccount, mTimeZoneId );
+ connect( mClient, SIGNAL( downloadFinished( int, const QString & ) ),
+ SLOT( slotDownloadFinished( int, const QString & ) ) );
+ connect( mClient, SIGNAL( event( KCal::Event *, const KURL & ) ),
+ SLOT( downloadedEvent( KCal::Event *, const KURL & ) ) );
+
+#if 0
+ kdDebug() << "Creating monitor" << endl;
+ QHostAddress ip;
+ ip.setAddress( mAccount->host() );
+ mMonitor = new ExchangeMonitor( mAccount, ExchangeMonitor::CallBack, ip );
+ connect( mMonitor, SIGNAL(notify( const QValueList<long>& , const QValueList<KURL>& )), this, SLOT(slotMonitorNotify( const QValueList<long>& , const QValueList<KURL>& )) );
+ connect( mMonitor, SIGNAL(error(int , const QString&)), this, SLOT(slotMonitorError(int , const QString&)) );
+
+ mMonitor->addWatch( mAccount->calendarURL(), ExchangeMonitor::UpdateNewMember, 1 );
+#endif
+
+ QWidgetList* widgets = QApplication::topLevelWidgets();
+ if ( !widgets->isEmpty() )
+ mClient->setWindow( widgets->first() );
+ delete widgets;
+
+ mDates = new DateSet();
+
+ mEventDates = new QMap<Event,QDateTime>();
+ mCacheDates = new QMap<QDate, QDateTime>();
+
+ mCache = new CalendarLocal( mTimeZoneId );
+ // mOldestDate = 0L;
+ // mNewestDate = 0L;
+
+ // FIXME: check if server exists, account is OK, etc.
+ return true;
+}
+
+void ResourceExchange::doClose()
+{
+ kdDebug() << "ResourceExchange::doClose()" << endl;
+
+ // delete mNewestDate;
+ // delete mOldestDate;
+ delete mDates; mDates = 0;
+// delete mMonitor; mMonitor = 0;
+ delete mClient; mClient = 0;
+ delete mEventDates; mEventDates = 0;
+ delete mCacheDates; mCacheDates = 0;
+ if (mCache) {
+ mCache->close();
+ delete mCache; mCache = 0;
+ }
+// setModified( false );
+}
+
+bool ResourceExchange::doLoad()
+{
+ return true;
+}
+
+bool ResourceExchange::doSave()
+{
+ kdDebug() << "ResourceExchange::save() " << mChangedIncidences.count()
+ << endl;
+
+ Incidence::List::Iterator it = mChangedIncidences.begin();
+ while( it != mChangedIncidences.end() ) {
+ if ( (*it)->type() == "Event" ) {
+ if ( uploadEvent( static_cast<Event *>( *it ) ) ) {
+ it = mChangedIncidences.remove( it );
+ } else {
+ kdError() << "ResourceExchange::save(): upload failed." << endl;
+ ++it;
+ }
+ } else {
+ kdError() << "ResourceExchange::save() type not handled: "
+ << (*it)->type() << endl;
+ ++it;
+ }
+ }
+ return true;
+}
+
+KABC::Lock *ResourceExchange::lock()
+{
+ return mLock;
+}
+
+void ResourceExchange::slotMonitorNotify( const QValueList<long>& IDs, const QValueList<KURL>& urls )
+{
+ kdDebug() << "ResourceExchange::slotMonitorNotify()" << endl;
+
+ QString result;
+ KPIM::ExchangeMonitor::IDList::ConstIterator it;
+ for ( it = IDs.begin(); it != IDs.end(); ++it ) {
+ if ( it == IDs.begin() )
+ result += QString::number( (*it) );
+ else
+ result += "," + QString::number( (*it) );
+ }
+ kdDebug() << "Got signals for " << result << endl;
+ QValueList<KURL>::ConstIterator it2;
+ for ( it2 = urls.begin(); it2 != urls.end(); ++it2 ) {
+ kdDebug() << "URL: " << (*it2).prettyURL() << endl;
+ }
+
+ /* Now find out what happened:
+ * One or more of the following:
+ * 1. Event added in period that we think we have cached
+ * 2. Event deleted that we have in cache
+ * 3. Event modified that we have in cache
+ * 4. Something else happened that isn't relevant to us
+ * Update cache, then notify whoever's watching us
+ * We may be able to find (1) and (3) by looking at the
+ * DAV:getlastmodified property
+ * (2) is trickier: we might have to resort to checking
+ * all uids in the cache
+ * Or: put monitors on every event in the cache, so that
+ * we know when one gets deleted or modified
+ * Only look for new events using the global monitor
+ */
+}
+
+void ResourceExchange::slotMonitorError( int errorCode, const QString& moreInfo )
+{
+ kdError() << "Ignoring error from Exchange monitor, code=" << errorCode << "; more info: " << moreInfo << endl;
+}
+
+
+bool ResourceExchange::addEvent(Event *anEvent)
+{
+ if( !mCache ) return false;
+ kdDebug() << "ResourceExchange::addEvent" << endl;
+
+ // FIXME: first check of upload finished successfully, only then
+ // add to cache
+ mCache->addEvent( anEvent );
+
+ uploadEvent( anEvent );
+// insertEvent(anEvent);
+
+ anEvent->registerObserver( this );
+// setModified( true );
+
+ return true;
+}
+
+bool ResourceExchange::uploadEvent( Event *event )
+{
+ mClient->uploadSynchronous( event );
+ return true;
+}
+
+bool ResourceExchange::deleteEvent(Event *event)
+{
+ if ( !mCache ) return false;
+ kdDebug(5800) << "ResourceExchange::deleteEvent" << endl;
+
+ mClient->removeSynchronous( event );
+
+ // This also frees the event
+ return mCache->deleteEvent( event );
+
+// setModified( true );
+}
+
+void ResourceExchange::changeIncidence( Incidence *incidence )
+{
+ kdDebug() << "ResourceExchange::changeIncidence(): "
+ << incidence->summary() << endl;
+
+ if ( mChangedIncidences.find( incidence ) == mChangedIncidences.end() ) {
+ mChangedIncidences.append( incidence );
+ }
+}
+
+Event *ResourceExchange::event( const QString &uid )
+{
+ kdDebug(5800) << "ResourceExchange::event(): " << uid << endl;
+
+ // FIXME: Look in exchange server for uid!
+ Event *event = 0;
+ if ( mCache )
+ event = mCache->event( uid );
+ return event;
+}
+
+void ResourceExchange::subscribeEvents( const QDate &start, const QDate &end )
+{
+ kdDebug(5800) << "ResourceExchange::subscribeEvents()" << endl;
+ // FIXME: possible race condition if several subscribe events are run close
+ // to each other
+ mClient->download( start, end, false );
+}
+
+void ResourceExchange::downloadedEvent( KCal::Event *event, const KURL &url )
+{
+ kdDebug() << "Downloaded event: " << event->summary() << " from url "
+ << url.prettyURL() << endl;
+ // FIXME: add watches to the monitor for these events
+ // KURL url =
+ // mMonitor->addWatch( url, KPIM::ExchangeMonitor::Update, 0 );
+// emit eventsAdded( events );
+}
+
+void ResourceExchange::slotDownloadFinished( int result,
+ const QString &moreinfo )
+{
+ kdDebug() << "ResourceExchange::downloadFinished" << endl;
+
+ if ( result != KPIM::ExchangeClient::ResultOK ) {
+ // Do something useful with the error report
+ kdError() << "ResourceExchange::slotDownloadFinished(): error " << result
+ << ": " << moreinfo << endl;
+ }
+}
+
+void ResourceExchange::unsubscribeEvents( const QDate &/*start*/, const QDate &/*end*/ )
+{
+ kdDebug() << "ResourceExchange::unsubscribeEvents()" << endl;
+}
+
+bool ResourceExchange::addTodo(Todo */*todo*/)
+{
+ // This resource doesn't handle todos yet!
+ return false;
+/* if( !mCache)
+ return false;
+ mCache->addTodo( todo );
+
+ todo->registerObserver( this );
+
+// setModified( true );
+
+ return true;*/
+}
+
+bool ResourceExchange::deleteTodo(Todo */*todo*/)
+{
+ // We don't handle todos yet
+// if( !mCache )
+ return false;
+// mCache->deleteTodo( todo );
+
+// setModified( true );
+}
+
+Todo::List ResourceExchange::rawTodos( TodoSortField /*sortField*/, SortDirection /*sortDirection*/ )
+{
+ // We don't handle todos yet
+ return Todo::List();
+/* Todo::List list;
+ if ( mCache )
+ list = mCache->rawTodos( sortField, sortDirection );
+ return list;*/
+}
+
+Todo *ResourceExchange::todo( const QString &/*uid*/ )
+{
+ // We don't handle todos yet
+ return 0;
+/* if ( !mCache )
+ return 0;
+ else
+ return mCache->todo( uid );*/
+}
+
+Todo::List ResourceExchange::rawTodosForDate( const QDate &/*date*/ )
+{
+ Todo::List list;
+ // We don't handle todos yet
+/* if ( mCache )
+ list = mCache->rawTodosForDate( date );*/
+ return list;
+}
+
+Alarm::List ResourceExchange::alarmsTo( const QDateTime &to )
+{
+ Alarm::List list;
+ if ( mCache )
+ list = mCache->alarmsTo( to );
+ return list;
+}
+
+/* Invoked by korgac when checking alarms. Always updates the cache. */
+Alarm::List ResourceExchange::alarms( const QDateTime &from, const QDateTime &to )
+{
+ kdDebug(5800) << "ResourceExchange::alarms(" << from.toString() << " - " << to.toString() << ")\n";
+ Alarm::List list;
+
+ QDate start = from.date();
+ QDate end = to.date();
+
+ if ( mCache ) {
+
+ /* Clear the cache */
+ Event::List oldEvents = mCache->rawEvents( start, end, false );
+
+ Event::List::ConstIterator it;
+ for( it = oldEvents.begin(); it != oldEvents.end(); ++it ) {
+ mCache->deleteEvent( *it );
+ }
+
+ /* Fetch events */
+ mClient->downloadSynchronous( mCache, start, end, false );
+
+ list = mCache->alarms( from, to );
+ }
+ return list;
+}
+
+/****************************** PROTECTED METHODS ****************************/
+
+// after changes are made to an event, this should be called.
+void ResourceExchange::incidenceUpdated( IncidenceBase *incidence )
+{
+ Event* event = dynamic_cast<Event *>( incidence );
+ if ( event ) {
+ kdDebug() << "Event updated, resubmit to server..." << endl;
+ uploadEvent( event );
+ }
+// setModified( true );
+}
+
+// this function will take a VEvent and insert it into the event
+// dictionary for the ResourceExchange. If there is no list of events for that
+// particular location in the dictionary, a new one will be created.
+/*
+void ResourceExchange::insertEvent(const Event *anEvent)
+{
+ kdDebug() << "ResourceExchange::insertEvent" << endl;
+
+}
+*/
+// taking a QDate, this function will look for an eventlist in the dict
+// with that date attached -
+Event::List ResourceExchange::rawEventsForDate( const QDate &qd,
+ EventSortField sortField,
+ SortDirection sortDirection )
+{
+ if (!mCache) return Event::List();
+ // If the events for this date are not in the cache, or if they are old,
+ // get them again
+ QDateTime now = QDateTime::currentDateTime();
+ // kdDebug() << "Now is " << now.toString() << endl;
+ // kdDebug() << "mDates: " << mDates << endl;
+ QDate start = QDate( qd.year(), qd.month(), 1 ); // First day of month
+ if ( mDates && ( !mDates->contains( start ) ||
+ (*mCacheDates)[start].secsTo( now ) > mCachedSeconds ) ) {
+ QDate end = start.addMonths( 1 ).addDays( -1 ); // Last day of month
+ // Get events that occur in this period from the cache
+ Event::List oldEvents = mCache->rawEvents( start, end, false );
+ // And remove them all
+ Event::List::ConstIterator it;
+ for( it = oldEvents.begin(); it != oldEvents.end(); ++it ) {
+ mCache->deleteEvent( *it );
+ }
+
+ // FIXME: This is needed for the hack below:
+ Event::List eventsBefore = mCache->rawEvents();
+
+ kdDebug() << "Reading events for month of " << start.toString() << endl;
+ mClient->downloadSynchronous( mCache, start, end, true ); // Show progress dialog
+
+ // FIXME: This is a terrible hack! We need to install the observer for
+ // newly downloaded events.However, downloading is done by
+ // mClient->downloadSynchronous, where we don't have the pointer to this
+ // available... On the other hand, here we don't really know which events
+ // are really new.
+ Event::List eventsAfter = mCache->rawEvents();
+ for ( it = eventsAfter.begin(); it != eventsAfter.end(); ++it ) {
+ if ( eventsBefore.find( *it ) == eventsBefore.end() ) {
+ // it's a new event downloaded by downloadSynchronous -> install observer
+ (*it)->registerObserver( this );
+ }
+ }
+
+ mDates->add( start );
+ mCacheDates->insert( start, now );
+ }
+
+ // Events are safely in the cache now, return them from cache
+ Event::List events;
+ if ( mCache )
+ events = mCache->rawEventsForDate( qd, sortField, sortDirection );
+ // kdDebug() << "Found " << events.count() << " events." << endl;
+ return events;
+}
+
+
+Event::List ResourceExchange::rawEvents( const QDate &start, const QDate &end,
+ bool inclusive )
+{
+ kdDebug() << "ResourceExchange::rawEvents(start,end,inclusive)" << endl;
+ if (!mCache) return Event::List();
+ return mCache->rawEvents( start, end, inclusive );
+}
+
+Event::List ResourceExchange::rawEventsForDate(const QDateTime &qdt)
+{
+ kdDebug() << "ResourceExchange::rawEventsForDate(qdt)" << endl;
+ return rawEventsForDate( qdt.date() );
+}
+
+Event::List ResourceExchange::rawEvents( EventSortField sortField, SortDirection sortDirection )
+{
+ kdDebug() << "ResourceExchange::rawEvents()" << endl;
+ if (!mCache) return Event::List();
+ return mCache->rawEvents( sortField, sortDirection );
+}
+
+bool ResourceExchange::addJournal(Journal */*journal*/)
+{
+ // This resource doesn't handle journals yet
+ return false;
+/* kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
+ if (mCache) {
+ mCache->addJournal( journal );
+
+ journal->registerObserver( this );
+
+// setModified( true );
+ }
+
+ return true;*/
+}
+
+bool ResourceExchange::deleteJournal(Journal */*journal*/)
+{
+ // Wedon't handle journals yet
+// if( !mCache )
+ return false;
+// mCache->deleteJournal( journal );
+
+// setModified( true );
+}
+
+Journal::List ResourceExchange::journals(const QDate &/*date*/)
+{
+ // We don't handle journals yet
+ return Journal::List();
+/* Journal::List list;
+ if ( mCache )
+ list = mCache->journals( date );
+ return list;*/
+}
+
+Journal *ResourceExchange::journal(const QString &/*uid*/)
+{
+ // We don't handle journals yet
+ return 0;
+/* if( !mCache )
+ return 0;
+ return mCache->journal( uid );*/
+}
+
+Journal::List ResourceExchange::rawJournals( JournalSortField /*sortField*/, SortDirection /*sortDirection*/ )
+{
+ // We don't handle journals yet
+ return Journal::List();
+/* Journal::List list;
+ if ( mCache )
+ list = mCache->rawJournals( sortField, sortDirection );
+ return list;*/
+}
+
+Journal::List ResourceExchange::rawJournalsForDate( const QDate &/*date*/ )
+{
+ // We don't handle journals yet
+ return Journal::List();
+/* Journal::List list;
+ if ( mCache )
+ list = mCache->rawJournalsForDate( date );
+ return list;*/
+}
+
+void ResourceExchange::setTimeZoneId( const QString &tzid )
+{
+ mTimeZoneId = tzid;
+ if ( mCache ) mCache->setTimeZoneId( tzid );
+ if ( mClient ) mClient->setTimeZoneId( tzid );
+}
+
+#include "resourceexchange.moc"
diff --git a/kresources/exchange/resourceexchange.h b/kresources/exchange/resourceexchange.h
new file mode 100644
index 00000000..721e3666
--- /dev/null
+++ b/kresources/exchange/resourceexchange.h
@@ -0,0 +1,248 @@
+/*
+ This file is part of libkpimexchange.
+ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ 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.
+*/
+#ifndef KPIM_EXCHANGECALENDAR_H
+#define KPIM_EXCHANGECALENDAR_H
+
+#include <qmap.h>
+#include <qdict.h>
+#include <qintdict.h>
+
+#include <libkcal/calendar.h>
+#include <libkcal/calendarlocal.h>
+#include <libkcal/resourcecalendar.h>
+
+#include "exchangemonitor.h"
+
+class DateSet;
+
+namespace KPIM {
+class ExchangeAccount;
+class ExchangeClient;
+}
+
+namespace KCal {
+class Event;
+class CalFormat;
+
+/**
+ This class provides a calendar stored on a Microsoft Exchange 2000 server
+*/
+// FIXME: Use ResourceCached
+class ResourceExchange : public ResourceCalendar, public IncidenceBase::Observer
+{
+ Q_OBJECT
+
+ public:
+ ResourceExchange( const KConfig * );
+ virtual ~ResourceExchange();
+
+ virtual void writeConfig( KConfig* config );
+
+ KABC::Lock *lock();
+
+ /** constructs a new calendar, with variables initialized to sane values. */
+// ExchangeCalendar( KPIM::ExchangeAccount* account );
+ /** constructs a new calendar, with variables initialized to sane values. */
+// ExchangeCalendar( KPIM::ExchangeAccount* account, const QString &timeZoneId );
+// virtual ~ExchangeCalendar();
+
+ /**
+ Semantics not yet defined. Should the Exchange calendar be wiped clean?
+ Should the disk calendar be copied to the Exchange calendar?
+ At the moment, does nothing.
+ @return true, if successful, false on error.
+ @param fileName the name of the calendar on disk.
+ */
+// bool load( const QString &fileName );
+ /**
+ Writes out the calendar to disk in the specified \a format.
+ ExchangeCalendar takes ownership of the CalFormat object.
+ @return true, if successful, false on error.
+ @param fileName the name of the file
+ */
+// bool save( const QString &fileName, CalFormat *format = 0 );
+
+ /** clears out the current calendar, freeing all used memory etc. etc. */
+// void close();
+
+ /** Add Event to calendar. */
+ bool addEvent(Event *anEvent);
+ /** deletes an event from this calendar. */
+ bool deleteEvent(Event *);
+
+ // Isn't called anymore.
+ void changeIncidence( Incidence * );
+
+ /**
+ Retrieves an event on the basis of the unique string ID.
+ */
+ Event *event(const QString &UniqueStr);
+ /**
+ Return filtered list of all events in calendar.
+ */
+// Event::List events();
+ /**
+ Return unfiltered list of all events in calendar.
+ Use with care, since this causes a LOT of network activity
+ */
+ Event::List rawEvents();
+
+ virtual void subscribeEvents( const QDate& start, const QDate& end );
+
+ /**
+ Stop receiving event signals for the given period (inclusive). After this call,
+ the calendar resource will no longer send eventsAdded, eventsModified or
+ eventsDeleted signals for events falling completely in this period. The resource
+ MAY delete the Events objects. The application MUST NOT dereference pointers
+ to the relevant Events after this call.
+ */
+ virtual void unsubscribeEvents( const QDate& start, const QDate& end );
+
+ /**
+ Add a todo to the todolist.
+ */
+ bool addTodo( Todo *todo );
+ /**
+ Remove a todo from the todolist.
+ */
+ bool deleteTodo( Todo * );
+ /**
+ Searches todolist for an event with this unique string identifier,
+ returns a pointer or null.
+ */
+ Todo *todo( const QString &uid );
+ /**
+ Return list of all todos.
+ */
+ Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
+ /**
+ Returns list of todos due on the specified date.
+ */
+ Todo::List rawTodosForDate( const QDate &date );
+
+ /** Add a Journal entry to calendar */
+ virtual bool addJournal(Journal *);
+ /** deletes an event from this calendar. */
+ virtual bool deleteJournal(Journal *);
+ /** Return Journals for given date */
+ virtual Journal::List journals(const QDate &);
+ /** Return Journal with given UID */
+ virtual Journal *journal(const QString &UID);
+ /** Return list of all Journals stored in calendar */
+ Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
+ /** Return journals for the given date. */
+ Journal::List rawJournalsForDate( const QDate & );
+
+ /** Return all alarms, which ocur in the given time interval. */
+ Alarm::List alarms( const QDateTime &from, const QDateTime &to );
+
+ /** Return all alarms, which ocur before given date. */
+ Alarm::List alarmsTo( const QDateTime &to );
+
+ friend class ResourceExchangeConfig;
+
+ protected:
+ /**
+ Prepare the calendar for use. Load the calendar from disk,
+ open connections to the calendaring server, whatever.
+ Must be called before other methods can be called.
+ */
+ virtual bool doOpen();
+
+ /** clears out the current calendar, freeing all used memory etc. etc. */
+ virtual void doClose();
+
+ virtual bool doLoad();
+ virtual bool doSave();
+
+ public:
+ /**
+ Builds and then returns a list of all events that match for the
+ date specified. useful for dayView, etc. etc.
+ */
+ Event::List rawEventsForDate(
+ const QDate &date,
+ EventSortField sortField=EventSortUnsorted,
+ SortDirection sortDirection=SortDirectionAscending );
+
+ /**
+ Get unfiltered events for date \a qdt.
+ */
+ Event::List rawEventsForDate( const QDateTime &qdt );
+ /**
+ Get unfiltered events in a range of dates. If inclusive is set to true,
+ only events are returned, which are completely included in the range.
+ */
+ Event::List rawEvents( const QDate &start, const QDate &end,
+ bool inclusive = false );
+ /**
+ Get unfiltered events in sorted order.
+ */
+ Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
+
+ protected:
+ /** Notification function of IncidenceBase::Observer. */
+ void incidenceUpdated( IncidenceBase *i );
+
+ /** inserts an event into its "proper place" in the calendar. */
+// void insertEvent(const Event *anEvent);
+
+ /** Append alarms of incidence in interval to list of alarms. */
+// void appendAlarms( Alarm::List &alarms, Incidence *incidence,
+// const QDateTime &from, const QDateTime &to );
+
+ /** Append alarms of recurring events in interval to list of alarms. */
+// void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
+// const QDateTime &from, const QDateTime &to );
+
+ bool uploadEvent( Event *event );
+
+ void setTimeZoneId( const QString &tzid );
+
+ protected slots:
+ void slotMonitorNotify( const QValueList<long>& IDs, const QValueList<KURL>& urls);
+ void slotMonitorError( int errorCode, const QString& moreInfo );
+ void slotDownloadFinished( int result, const QString& moreinfo );
+ void downloadedEvent( KCal::Event*, const KURL& );
+
+ private:
+ class EventInfo;
+ KPIM::ExchangeAccount* mAccount;
+ KPIM::ExchangeClient* mClient;
+ KPIM::ExchangeMonitor* mMonitor;
+ CalendarLocal* mCache;
+ QDict<EventInfo> mEventDict; // maps UIDS to EventInfo records
+ QIntDict<EventInfo> mWatchDict; // maps Watch IDs to EventInfo records
+ DateSet* mDates;
+ QMap<Event, QDateTime>* mEventDates;
+ QMap<QDate, QDateTime>* mCacheDates;
+ int mCachedSeconds;
+ bool mAutoMailbox;
+ QString mTimeZoneId;
+
+ KABC::Lock *mLock;
+
+ // FIXME: Remove variable, use ResourceCached::changedIncidences() instead.
+ Incidence::List mChangedIncidences;
+};
+
+}
+
+#endif
diff --git a/kresources/exchange/resourceexchangeconfig.cpp b/kresources/exchange/resourceexchangeconfig.cpp
new file mode 100644
index 00000000..e2277fa0
--- /dev/null
+++ b/kresources/exchange/resourceexchangeconfig.cpp
@@ -0,0 +1,153 @@
+/*
+ This file is part of libkpimexchange.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ 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.
+*/
+
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+#include <kstandarddirs.h>
+#include <kmessagebox.h>
+
+#include "exchangeaccount.h"
+#include "resourceexchangeconfig.h"
+#include "resourceexchange.h"
+
+using namespace KCal;
+
+ResourceExchangeConfig::ResourceExchangeConfig( QWidget* parent, const char* name )
+ : KRES::ConfigWidget( parent, name )
+{
+ resize( 245, 115 );
+ QGridLayout *mainLayout = new QGridLayout( this, 8, 3 );
+
+ QLabel *label = new QLabel( i18n( "Host:" ), this );
+ mHostEdit = new KLineEdit( this );
+ mainLayout->addWidget( label, 1, 0 );
+ mainLayout->addWidget( mHostEdit, 1, 1 );
+
+ label = new QLabel( i18n( "Port:" ), this );
+ mPortEdit = new KLineEdit( this );
+ mainLayout->addWidget( label, 2, 0 );
+ mainLayout->addWidget( mPortEdit, 2, 1 );
+
+ label = new QLabel( i18n( "Account:" ), this );
+ mAccountEdit = new KLineEdit( this );
+ mainLayout->addWidget( label, 3, 0 );
+ mainLayout->addWidget( mAccountEdit, 3, 1 );
+
+ label = new QLabel( i18n( "Password:" ), this );
+ mPasswordEdit = new KLineEdit( this );
+ mPasswordEdit->setEchoMode( QLineEdit::Password );
+ mainLayout->addWidget( label, 4, 0 );
+ mainLayout->addWidget( mPasswordEdit, 4, 1 );
+
+ mAutoMailbox = new QCheckBox( i18n( "Determine mailbox &automatically" ), this );
+ mainLayout->addMultiCellWidget( mAutoMailbox, 5, 5, 0, 1 );
+ connect( mAutoMailbox, SIGNAL(toggled(bool)), this, SLOT(slotToggleAuto(bool)) );
+
+ mMailboxEdit = new KLineEdit( this );
+ mainLayout->addWidget( new QLabel( i18n( "Mailbox URL:" ), this ), 6, 0 );
+ mainLayout->addWidget( mMailboxEdit, 6, 1 );
+
+ mTryFindMailbox = new QPushButton( i18n( "&Find" ), this );
+ mainLayout->addWidget( mTryFindMailbox, 6, 2 );
+ connect( mTryFindMailbox, SIGNAL(clicked()), this, SLOT(slotFindClicked()) );
+
+ label = new QLabel( i18n( "Cache timeout:" ), this );
+ mCacheEdit = new KIntNumInput( this );
+ connect(mCacheEdit, SIGNAL(valueChanged( int )), SLOT(slotCacheEditChanged( int )));
+ mCacheEdit->setMinValue( 0 );
+ mainLayout->addWidget( label, 7, 0 );
+ mainLayout->addWidget( mCacheEdit, 7, 1 );
+}
+
+void ResourceExchangeConfig::loadSettings( KRES::Resource *resource )
+{
+ ResourceExchange* res = dynamic_cast<ResourceExchange*>( resource );
+ if (res) {
+ mHostEdit->setText( res->mAccount->host() );
+ mPortEdit->setText( res->mAccount->port() );
+ mAccountEdit->setText( res->mAccount->account() );
+ mPasswordEdit->setText( res->mAccount->password() );
+ mAutoMailbox->setChecked( res->mAutoMailbox );
+ mMailboxEdit->setText( res->mAccount->mailbox() );
+ mCacheEdit->setValue( res->mCachedSeconds );
+ } else
+ kdDebug(5700) << "ERROR: ResourceExchangeConfig::loadSettings(): no ResourceExchange, cast failed" << endl;
+}
+
+void ResourceExchangeConfig::saveSettings( KRES::Resource *resource )
+{
+ kdDebug() << "Saving settings to resource " << resource->resourceName() << endl;
+ ResourceExchange* res = dynamic_cast<ResourceExchange*>( resource );
+ if (res) {
+ if ( mAutoMailbox->isChecked() ) {
+ mMailboxEdit->setText( QString::null );
+ slotFindClicked();
+ if ( mMailboxEdit->text().isNull() ) {
+ kdWarning() << "Could not find Exchange mailbox URL, incomplete settings!" << endl;
+ }
+ }
+ res->mAutoMailbox = mAutoMailbox->isChecked();
+
+ res->mAccount->setHost(mHostEdit->text());
+ res->mAccount->setPort(mPortEdit->text());
+ res->mAccount->setAccount(mAccountEdit->text());
+ res->mAccount->setPassword(mPasswordEdit->text());
+ res->mAccount->setMailbox( mMailboxEdit->text() );
+ res->mCachedSeconds = mCacheEdit->value();
+ } else
+ kdDebug(5700) << "ERROR: ResourceExchangeConfig::saveSettings(): no ResourceExchange, cast failed" << endl;
+}
+
+void ResourceExchangeConfig::slotToggleAuto( bool on )
+{
+ mMailboxEdit->setEnabled( ! on );
+// mTryFindMailbox->setEnabled( ! on );
+}
+
+void ResourceExchangeConfig::slotUserChanged( const QString& /*text*/ )
+{
+// if ( mMailboxEqualsUser->isChecked() ) {
+// mMailboxEdit->setText( "webdav://" + mHostEdit->text() + "/exchange/" + text );
+// }
+}
+
+void ResourceExchangeConfig::slotFindClicked()
+{
+ QString mailbox = KPIM::ExchangeAccount::tryFindMailbox(
+ mHostEdit->text(), mPortEdit->text(),
+ mAccountEdit->text(), mPasswordEdit->text() );
+
+ if ( mailbox.isNull() ) {
+ KMessageBox::sorry( this, i18n( "Could not determine mailbox URL, please check your account settings." ) );
+ } else {
+ mMailboxEdit->setText( mailbox );
+ }
+}
+
+void ResourceExchangeConfig::slotCacheEditChanged( int value )
+{
+ mCacheEdit->setSuffix( i18n(" second", " seconds", value) );
+}
+
+#include "resourceexchangeconfig.moc"
diff --git a/kresources/exchange/resourceexchangeconfig.h b/kresources/exchange/resourceexchangeconfig.h
new file mode 100644
index 00000000..59adf02b
--- /dev/null
+++ b/kresources/exchange/resourceexchangeconfig.h
@@ -0,0 +1,66 @@
+/*
+ This file is part of libkpimexchange.
+ Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
+ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ 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.
+*/
+
+#ifndef KDEPIM_RESOURCECALENDAREXCHANGECONFIG_H
+#define KDEPIM_RESOURCECALENDAREXCHANGECONFIG_H
+
+#include <qcheckbox.h>
+
+#include <kcombobox.h>
+#include <kurlrequester.h>
+#include <klineedit.h>
+#include <knuminput.h>
+
+#include <kresources/resource.h>
+#include <kresources/configwidget.h>
+
+namespace KCal {
+
+class ResourceExchangeConfig : public KRES::ConfigWidget
+{
+ Q_OBJECT
+
+public:
+ ResourceExchangeConfig( QWidget* parent = 0, const char* name = 0 );
+
+public slots:
+ virtual void loadSettings( KRES::Resource *resource);
+ virtual void saveSettings( KRES::Resource *resource );
+
+protected slots:
+ void slotToggleAuto( bool on );
+ void slotUserChanged( const QString& text );
+ void slotFindClicked();
+ void slotCacheEditChanged( int value );
+
+private:
+ KLineEdit* mHostEdit;
+ KLineEdit* mPortEdit;
+ KLineEdit* mAccountEdit;
+ KLineEdit* mPasswordEdit;
+ QCheckBox *mAutoMailbox;
+ KLineEdit* mMailboxEdit;
+ QPushButton* mTryFindMailbox;
+ KIntNumInput* mCacheEdit;
+};
+
+}
+#endif