diff options
Diffstat (limited to 'tderesources/exchange')
-rw-r--r-- | tderesources/exchange/CMakeLists.txt | 40 | ||||
-rw-r--r-- | tderesources/exchange/Makefile.am | 23 | ||||
-rw-r--r-- | tderesources/exchange/dateset.cpp | 280 | ||||
-rw-r--r-- | tderesources/exchange/dateset.h | 87 | ||||
-rw-r--r-- | tderesources/exchange/exchange.desktop | 53 | ||||
-rw-r--r-- | tderesources/exchange/exchange_deprecated.desktop | 48 | ||||
-rw-r--r-- | tderesources/exchange/resourceexchange.cpp | 627 | ||||
-rw-r--r-- | tderesources/exchange/resourceexchange.h | 253 | ||||
-rw-r--r-- | tderesources/exchange/resourceexchangeconfig.cpp | 153 | ||||
-rw-r--r-- | tderesources/exchange/resourceexchangeconfig.h | 67 |
10 files changed, 1631 insertions, 0 deletions
diff --git a/tderesources/exchange/CMakeLists.txt b/tderesources/exchange/CMakeLists.txt new file mode 100644 index 000000000..fc2f9cc3d --- /dev/null +++ b/tderesources/exchange/CMakeLists.txt @@ -0,0 +1,40 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +tde_import( libkpimexchange ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/libtdepim + ${CMAKE_SOURCE_DIR}/libkpimexchange/core + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( FILES exchange.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kcal ) + + +##### resourcecalendarexchange (module) ######### + +tde_add_kpart( resourcecalendarexchange AUTOMOC + SOURCES + resourceexchange.cpp resourceexchangeconfig.cpp dateset.cpp + LINK kpimexchange-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tderesources/exchange/Makefile.am b/tderesources/exchange/Makefile.am new file mode 100644 index 000000000..a9fdf70a6 --- /dev/null +++ b/tderesources/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= -ltderesources \ + $(top_builddir)/libkcal/libkcal.la \ + $(top_builddir)/libkpimexchange/libkpimexchange.la + +servicedir = $(kde_servicesdir)/tderesources/kcal +service_DATA= exchange.desktop + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kres_exchange.pot diff --git a/tderesources/exchange/dateset.cpp b/tderesources/exchange/dateset.cpp new file mode 100644 index 000000000..b26229022 --- /dev/null +++ b/tderesources/exchange/dateset.cpp @@ -0,0 +1,280 @@ +/* + This file is part of libkpimexchange. + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqptrlist.h> +#include <tqdatetime.h> +#include <tqpair.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( TQDate const& date ) +{ + if (mDates->isEmpty()) { + mDates->insert( 0, new TQPair<TQDate,TQDate>( date, date ) ); + return; + } + int i = find( date ); + mDates->insert( i, new TQPair<TQDate,TQDate>( date, date ) ); + tryMerge( i ); + tryMerge( i-1 ); +} + +void DateSet::add( TQDate const& from, TQDate const& to ) +{ + if (mDates->isEmpty()) { + mDates->insert( 0, new TQPair<TQDate,TQDate>( from, to ) ); + return; + } + uint i = find( from ); + kdDebug() << "Adding range at position " << i << endl; + mDates->insert( i, new TQPair<TQDate,TQDate>( from, to ) ); + + do { + } while ( tryMerge( i ) ); + do { + } while ( tryMerge( i-1 ) ); +/* + TQPair<TQDate,TQDate>* item = mDates->at( i ); + + if (to >= item->first) + return; + + if (to.daysTo( item->first ) == 1 ) + item->first = from; + else + mDates->insert( i, new TQPair<TQDate,TQDate>( from, to ) ); +*/ +} + +void DateSet::remove( TQDate const& date ) +{ + if (mDates->isEmpty()) { + return; + } + + uint i = find( date ); + if ( i == mDates->count() ) + return; + + TQPair<TQDate,TQDate>* 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 TQPair<TQDate,TQDate>(item->first, date.addDays( -1 ) ) ); + item->first = date.addDays( 1 ); + } +} + +void DateSet::remove( TQDate const& from, TQDate const& to ) +{ + if (mDates->isEmpty()) { + return; + } + + uint i = find( from ); + if ( i == mDates->count() ) + return; + + while( i < mDates->count() ) { + TQPair<TQDate,TQDate>* 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 TQPair<TQDate,TQDate>( 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( TQDate 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; + + TQPair<TQDate,TQDate>* 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( TQDate const& from, TQDate const& to ) +{ + if (mDates->isEmpty()) { + return false; + } + + uint i = find( from ); + if ( i == mDates->count() ) + return false; + + TQPair<TQDate,TQDate>* 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( TQDate 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; + TQPair<TQDate,TQDate> *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++ ) + { + TQDate start = mDates->at( i )->first; + TQDate end = mDates->at( i )->second; + if (start == end) + kdDebug() << TQString(start.toString()) << endl; + else + kdDebug() << "(" << TQString(start.toString()) << " , " << TQString(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; + + TQPair<TQDate,TQDate>* item1 = mDates->at( i ); + TQPair<TQDate,TQDate>* 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/tderesources/exchange/dateset.h b/tderesources/exchange/dateset.h new file mode 100644 index 000000000..693aa4a31 --- /dev/null +++ b/tderesources/exchange/dateset.h @@ -0,0 +1,87 @@ +/* + This file is part of libkpimexchange. + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqdatetime.h> +#include <tqpair.h> +#include <tqptrlist.h> + +/* +class DateRange { + public: + DateRange() { } + DateRange( TQDate const& from, TQDate const& to ) + : mFrom( from ), mTo( to ) { } + bool operator< ( const DateRange& r ) { return mFrom < r.from(); } + bool contains( TQDate const& d ) { return ( mFrom <= d && d <= mTo ); } + bool contains( TQDate const& from, TQDate const& to ) { return ( mFrom <= from && to <= mTo ); } + + TQDate from() { return mFrom; } + TQDate to() { return mTo; } + + private: + TQDate mFrom; + TQDate mTo; +} +*/ + +class RangeList : public TQPtrList< TQPair<TQDate, TQDate> > { + protected: + virtual int compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2) { + TQPair<TQDate,TQDate> *i1 = static_cast<TQPair<TQDate,TQDate> *> (item1); + TQPair<TQDate,TQDate> *i2 = static_cast<TQPair<TQDate,TQDate> *> (item2); + if ( *i1 < *i2 ) return -1; + if ( *i2 < *i1 ) return 1; + return 0; + } +}; + +class DateSet { + public: + DateSet(); + ~DateSet(); + + void add( TQDate const& date ); + void add( TQDate const& from, TQDate const& to ); + + void remove( TQDate const& date ); + void remove( TQDate const& from, TQDate const& to ); + + bool contains( TQDate const& date ); + // returns true if and only if the whole range is in the set + bool contains( TQDate const& from, TQDate const& to ); + + int find( TQDate const &date ); + void print(); + + protected: + private: + bool tryMerge( int i ); + RangeList *mDates; + + TQDate mOldestDate; + TQDate mNewestDate; +}; + +#endif diff --git a/tderesources/exchange/exchange.desktop b/tderesources/exchange/exchange.desktop new file mode 100644 index 000000000..0ee32090c --- /dev/null +++ b/tderesources/exchange/exchange.desktop @@ -0,0 +1,53 @@ +[Desktop Entry] +Type=Service +X-TDE-Library=resourcecalendarexchange +X-TDE-ResourceFamily=calendar +X-TDE-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[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/tderesources/exchange/exchange_deprecated.desktop b/tderesources/exchange/exchange_deprecated.desktop new file mode 100644 index 000000000..eba22eed2 --- /dev/null +++ b/tderesources/exchange/exchange_deprecated.desktop @@ -0,0 +1,48 @@ +[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[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/tderesources/exchange/resourceexchange.cpp b/tderesources/exchange/resourceexchange.cpp new file mode 100644 index 000000000..16344d015 --- /dev/null +++ b/tderesources/exchange/resourceexchange.cpp @@ -0,0 +1,627 @@ +/* + This file is part of libkpimexchange. + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqdatetime.h> +#include <tqstring.h> +#include <tqptrlist.h> +#include <tqwidgetlist.h> +#include <tqwidget.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 <tderesources/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() + { + TDEGlobal::locale()->insertCatalogue( "kres_exchange" ); + return new ExchangeFactory; + } +} + +class ResourceExchange::EventInfo { +public: + KCal::Event* event; + KURL url; + long updateWatch; +}; + +ResourceExchange::ResourceExchange( const TDEConfig *config ) + : ResourceCalendar( config ), mClient(0), mMonitor(0), mCache(0), mDates(0), + mEventDates(0), mCacheDates(0) +{ + mLock = new KABC::LockNull( true ); + + mTimeZoneId = TQString::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 { + setResourceName( i18n( "Exchange Server" ) ); + mAccount = new ExchangeAccount( "", "", "", "" ); + mCachedSeconds = 600; + } +} + +ResourceExchange::~ResourceExchange() +{ + kdDebug() << "Destructing ResourceExchange" << endl; + + close(); + + delete mAccount; mAccount = 0; +} + +void ResourceExchange::writeConfig( TDEConfig* 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, TQT_SIGNAL( downloadFinished( int, const TQString & ) ), + TQT_SLOT( slotDownloadFinished( int, const TQString & ) ) ); + connect( mClient, TQT_SIGNAL( event( KCal::Event *, const KURL & ) ), + TQT_SLOT( downloadedEvent( KCal::Event *, const KURL & ) ) ); + +#if 0 + kdDebug() << "Creating monitor" << endl; + TQHostAddress ip; + ip.setAddress( mAccount->host() ); + mMonitor = new ExchangeMonitor( mAccount, ExchangeMonitor::CallBack, ip ); + connect( mMonitor, TQT_SIGNAL(notify( const TQValueList<long>& , const TQValueList<KURL>& )), this, TQT_SLOT(slotMonitorNotify( const TQValueList<long>& , const TQValueList<KURL>& )) ); + connect( mMonitor, TQT_SIGNAL(error(int , const TQString&)), this, TQT_SLOT(slotMonitorError(int , const TQString&)) ); + + mMonitor->addWatch( mAccount->calendarURL(), ExchangeMonitor::UpdateNewMember, 1 ); +#endif + + TQWidgetList* widgets = TQApplication::topLevelWidgets(); + if ( !widgets->isEmpty() ) + mClient->setWindow( widgets->first() ); + delete widgets; + + mDates = new DateSet(); + + mEventDates = new TQMap<Event,TQDateTime>(); + mCacheDates = new TQMap<TQDate, TQDateTime>(); + + 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 TQValueList<long>& IDs, const TQValueList<KURL>& urls ) +{ + kdDebug() << "ResourceExchange::slotMonitorNotify()" << endl; + + TQString result; + KPIM::ExchangeMonitor::IDList::ConstIterator it; + for ( it = IDs.begin(); it != IDs.end(); ++it ) { + if ( it == IDs.begin() ) + result += TQString::number( (*it) ); + else + result += "," + TQString::number( (*it) ); + } + kdDebug() << "Got signals for " << result << endl; + TQValueList<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 TQString& moreInfo ) +{ + kdError() << "Ignoring error from Exchange monitor, code=" << errorCode << "; more info: " << moreInfo << endl; +} + + +bool ResourceExchange::addEvent( Event *event ) +{ + return addEvent( event, TQString() ); +} + +bool ResourceExchange::addEvent( Event *event, const TQString &subresource ) +{ + Q_UNUSED( subresource ); //subresources are not supported + + if( !mCache ) return false; + kdDebug() << "ResourceExchange::addEvent" << endl; + + // FIXME: first check of upload finished successfully, only then + // add to cache + mCache->addEvent( event ); + + uploadEvent( event ); +// insertEvent( event ); + + event->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 TQString &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 TQDate &start, const TQDate &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 TQString &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 TQDate &/*start*/, const TQDate &/*end*/ ) +{ + kdDebug() << "ResourceExchange::unsubscribeEvents()" << endl; +} + +bool ResourceExchange::addTodo( Todo *todo ) +{ + return addTodo( todo, TQString() ); +} + +bool ResourceExchange::addTodo( Todo */*todo*/, const TQString &subresource ) +{ + Q_UNUSED( subresource ); //subresources are not supported + // 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 TQString &/*uid*/ ) +{ + // We don't handle todos yet + return 0; +/* if ( !mCache ) + return 0; + else + return mCache->todo( uid );*/ +} + +Todo::List ResourceExchange::rawTodosForDate( const TQDate &/*date*/ ) +{ + Todo::List list; + // We don't handle todos yet +/* if ( mCache ) + list = mCache->rawTodosForDate( date );*/ + return list; +} + +Alarm::List ResourceExchange::alarmsTo( const TQDateTime &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 TQDateTime &from, const TQDateTime &to ) +{ + kdDebug(5800) << "ResourceExchange::alarms(" << from.toString() << " - " << to.toString() << ")\n"; + Alarm::List list; + + TQDate start = from.date(); + TQDate 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 TQDate, this function will look for an eventlist in the dict +// with that date attached - +Event::List ResourceExchange::rawEventsForDate( const TQDate &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 + TQDateTime now = TQDateTime::currentDateTime(); + // kdDebug() << "Now is " << now.toString() << endl; + // kdDebug() << "mDates: " << mDates << endl; + TQDate start = TQDate( qd.year(), qd.month(), 1 ); // First day of month + if ( mDates && ( !mDates->contains( start ) || + (*mCacheDates)[start].secsTo( now ) > mCachedSeconds ) ) { + TQDate 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 " << TQString(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 TQDate &start, const TQDate &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 TQDateTime &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 ) +{ + return addJournal( journal, TQString() ); +} + +bool ResourceExchange::addJournal( Journal */*journal*/, const TQString &subresource ) +{ + Q_UNUSED( subresource ); //subresources are not supported + + // 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 TQDate &/*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 TQString &/*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 TQDate &/*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 TQString &tzid ) +{ + mTimeZoneId = tzid; + if ( mCache ) mCache->setTimeZoneId( tzid ); + if ( mClient ) mClient->setTimeZoneId( tzid ); +} + +#include "resourceexchange.moc" diff --git a/tderesources/exchange/resourceexchange.h b/tderesources/exchange/resourceexchange.h new file mode 100644 index 000000000..9b414dbb7 --- /dev/null +++ b/tderesources/exchange/resourceexchange.h @@ -0,0 +1,253 @@ +/* + This file is part of libkpimexchange. + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqmap.h> +#include <tqdict.h> +#include <tqintdict.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 TDEConfig * ); + virtual ~ResourceExchange(); + + virtual void writeConfig( TDEConfig* 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 TQString &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 TQString &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 TQString &fileName, CalFormat *format = 0 ); + + /** clears out the current calendar, freeing all used memory etc. etc. */ +// void close(); + + /** Add Event to calendar. */ + KDE_DEPRECATED bool addEvent( Event *event ); + bool addEvent( Event *event, const TQString &subresource ); + + /** 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 TQString &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 TQDate& start, const TQDate& 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 TQDate& start, const TQDate& end ); + + /** + Add a todo to the todolist. + */ + KDE_DEPRECATED bool addTodo( Todo *todo ); + bool addTodo( Todo *todo, const TQString &subresource ); + /** + 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 TQString &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 TQDate &date ); + + /** Add a Journal entry to calendar */ + KDE_DEPRECATED bool addJournal( Journal *journal ); + bool addJournal( Journal *journal, const TQString &subresource ); + /** deletes an event from this calendar. */ + virtual bool deleteJournal(Journal *); + /** Return Journals for given date */ + virtual Journal::List journals(const TQDate &); + /** Return Journal with given UID */ + virtual Journal *journal(const TQString &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 TQDate & ); + + /** Return all alarms, which ocur in the given time interval. */ + Alarm::List alarms( const TQDateTime &from, const TQDateTime &to ); + + /** Return all alarms, which ocur before given date. */ + Alarm::List alarmsTo( const TQDateTime &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 TQDate &date, + EventSortField sortField=EventSortUnsorted, + SortDirection sortDirection=SortDirectionAscending ); + + /** + Get unfiltered events for date \a qdt. + */ + Event::List rawEventsForDate( const TQDateTime &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 TQDate &start, const TQDate &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 TQDateTime &from, const TQDateTime &to ); + + /** Append alarms of recurring events in interval to list of alarms. */ +// void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, +// const TQDateTime &from, const TQDateTime &to ); + + bool uploadEvent( Event *event ); + + void setTimeZoneId( const TQString &tzid ); + + protected slots: + void slotMonitorNotify( const TQValueList<long>& IDs, const TQValueList<KURL>& urls); + void slotMonitorError( int errorCode, const TQString& moreInfo ); + void slotDownloadFinished( int result, const TQString& moreinfo ); + void downloadedEvent( KCal::Event*, const KURL& ); + + private: + class EventInfo; + KPIM::ExchangeAccount* mAccount; + KPIM::ExchangeClient* mClient; + KPIM::ExchangeMonitor* mMonitor; + CalendarLocal* mCache; + TQDict<EventInfo> mEventDict; // maps UIDS to EventInfo records + TQIntDict<EventInfo> mWatchDict; // maps Watch IDs to EventInfo records + DateSet* mDates; + TQMap<Event, TQDateTime>* mEventDates; + TQMap<TQDate, TQDateTime>* mCacheDates; + int mCachedSeconds; + bool mAutoMailbox; + TQString mTimeZoneId; + + KABC::Lock *mLock; + + // FIXME: Remove variable, use ResourceCached::changedIncidences() instead. + Incidence::List mChangedIncidences; +}; + +} + +#endif diff --git a/tderesources/exchange/resourceexchangeconfig.cpp b/tderesources/exchange/resourceexchangeconfig.cpp new file mode 100644 index 000000000..36774901b --- /dev/null +++ b/tderesources/exchange/resourceexchangeconfig.cpp @@ -0,0 +1,153 @@ +/* + This file is part of libkpimexchange. + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqlabel.h> +#include <tqlayout.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( TQWidget* parent, const char* name ) + : KRES::ConfigWidget( parent, name ) +{ + resize( 245, 115 ); + TQGridLayout *mainLayout = new TQGridLayout( this, 8, 3 ); + + TQLabel *label = new TQLabel( i18n( "Host:" ), this ); + mHostEdit = new KLineEdit( this ); + mainLayout->addWidget( label, 1, 0 ); + mainLayout->addWidget( mHostEdit, 1, 1 ); + + label = new TQLabel( i18n( "Port:" ), this ); + mPortEdit = new KLineEdit( this ); + mainLayout->addWidget( label, 2, 0 ); + mainLayout->addWidget( mPortEdit, 2, 1 ); + + label = new TQLabel( i18n( "Account:" ), this ); + mAccountEdit = new KLineEdit( this ); + mainLayout->addWidget( label, 3, 0 ); + mainLayout->addWidget( mAccountEdit, 3, 1 ); + + label = new TQLabel( i18n( "Password:" ), this ); + mPasswordEdit = new KLineEdit( this ); + mPasswordEdit->setEchoMode( TQLineEdit::Password ); + mainLayout->addWidget( label, 4, 0 ); + mainLayout->addWidget( mPasswordEdit, 4, 1 ); + + mAutoMailbox = new TQCheckBox( i18n( "Determine mailbox &automatically" ), this ); + mainLayout->addMultiCellWidget( mAutoMailbox, 5, 5, 0, 1 ); + connect( mAutoMailbox, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggleAuto(bool)) ); + + mMailboxEdit = new KLineEdit( this ); + mainLayout->addWidget( new TQLabel( i18n( "Mailbox URL:" ), this ), 6, 0 ); + mainLayout->addWidget( mMailboxEdit, 6, 1 ); + + mTryFindMailbox = new TQPushButton( i18n( "&Find" ), this ); + mainLayout->addWidget( mTryFindMailbox, 6, 2 ); + connect( mTryFindMailbox, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotFindClicked()) ); + + label = new TQLabel( i18n( "Cache timeout:" ), this ); + mCacheEdit = new KIntNumInput( this ); + connect(mCacheEdit, TQT_SIGNAL(valueChanged( int )), TQT_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( TQString() ); + 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 TQString& /*text*/ ) +{ +// if ( mMailboxEqualsUser->isChecked() ) { +// mMailboxEdit->setText( "webdav://" + mHostEdit->text() + "/exchange/" + text ); +// } +} + +void ResourceExchangeConfig::slotFindClicked() +{ + TQString 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/tderesources/exchange/resourceexchangeconfig.h b/tderesources/exchange/resourceexchangeconfig.h new file mode 100644 index 000000000..c008c2ce2 --- /dev/null +++ b/tderesources/exchange/resourceexchangeconfig.h @@ -0,0 +1,67 @@ +/* + This file is part of libkpimexchange. + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 TDEPIM_RESOURCECALENDAREXCHANGECONFIG_H +#define TDEPIM_RESOURCECALENDAREXCHANGECONFIG_H + +#include <tqcheckbox.h> + +#include <kcombobox.h> +#include <kurlrequester.h> +#include <klineedit.h> +#include <knuminput.h> + +#include <tderesources/resource.h> +#include <tderesources/configwidget.h> + +namespace KCal { + +class ResourceExchangeConfig : public KRES::ConfigWidget +{ + Q_OBJECT + + +public: + ResourceExchangeConfig( TQWidget* 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 TQString& text ); + void slotFindClicked(); + void slotCacheEditChanged( int value ); + +private: + KLineEdit* mHostEdit; + KLineEdit* mPortEdit; + KLineEdit* mAccountEdit; + KLineEdit* mPasswordEdit; + TQCheckBox *mAutoMailbox; + KLineEdit* mMailboxEdit; + TQPushButton* mTryFindMailbox; + KIntNumInput* mCacheEdit; +}; + +} +#endif |