00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include <kapplication.h>
00022
#include <kurl.h>
00023
#include <kdebug.h>
00024
#include <kcursor.h>
00025
#include <klocale.h>
00026
00027
00028
#include <kio/http.h>
00029
#include <kio/davjob.h>
00030
00031
00032
00033
00034
#include "exchangeclient.h"
00035
#include "exchangeaccount.h"
00036
#include "exchangeprogress.h"
00037
#include "exchangeupload.h"
00038
#include "exchangedownload.h"
00039
#include "exchangedelete.h"
00040
00041
#include "utils.h"
00042
00043
using namespace KPIM;
00044
00045 ExchangeClient::ExchangeClient( ExchangeAccount *account,
00046
const QString &timeZoneId )
00047 : mWindow( 0 ), mTimeZoneId( timeZoneId )
00048 {
00049 kdDebug() <<
"Creating ExchangeClient...\n";
00050 mAccount = account;
00051
if ( timeZoneId.isNull() ) {
00052 setTimeZoneId(
"UTC" );
00053 }
00054 }
00055
00056 ExchangeClient::~ExchangeClient()
00057 {
00058 kdDebug() <<
"ExchangeClient destructor" << endl;
00059 }
00060
00061
void ExchangeClient::setWindow(
QWidget *window)
00062 {
00063 mWindow = window;
00064 }
00065
00066
QWidget *ExchangeClient::window()
const
00067
{
00068
return mWindow;
00069 }
00070
00071
void ExchangeClient::setTimeZoneId(
const QString& timeZoneId )
00072 {
00073 mTimeZoneId = timeZoneId;
00074 }
00075
00076
QString ExchangeClient::timeZoneId()
00077 {
00078
return mTimeZoneId;
00079 }
00080
00081
void ExchangeClient::test()
00082 {
00083
00084 kdDebug() <<
"Entering test()" << endl;
00085 KURL baseURL = KURL(
"http://mail.tbm.tudelft.nl/janb/Calendar" );
00086 KURL url(
"webdav://mail.tbm.tudelft.nl/exchange/" );
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 }
00110
00111
void ExchangeClient::test2()
00112 {
00113 kdDebug() <<
"Entering test2()" << endl;
00114 }
00115
00116
00117
00118
00119
00120
00121
void ExchangeClient::download( KCal::Calendar *calendar,
const QDate &start,
00122
const QDate &end,
bool showProgress )
00123 {
00124 kdDebug() <<
"ExchangeClient::download1()" << endl;
00125
00126
if ( !mAccount->authenticate( mWindow ) ) {
00127 emit downloadFinished( 0, i18n(
"Authentication error") );
00128
return;
00129 }
00130
00131 ExchangeDownload *worker =
new ExchangeDownload( mAccount, mWindow );
00132 worker->download( calendar, start, end, showProgress );
00133 connect( worker,
00134 SIGNAL( finished( ExchangeDownload *,
int,
const QString & ) ),
00135 SLOT( slotDownloadFinished( ExchangeDownload *,
int,
00136
const QString & ) ) );
00137 }
00138
00139
void ExchangeClient::download(
const QDate &start,
const QDate &end,
00140
bool showProgress )
00141 {
00142 kdDebug() <<
"ExchangeClient::download2()" << endl;
00143
00144
if ( !mAccount->authenticate( mWindow ) ) {
00145 emit downloadFinished( 0, i18n(
"Authentication error") );
00146
return;
00147 }
00148
00149 ExchangeDownload *worker =
new ExchangeDownload( mAccount, mWindow );
00150 worker->download( start, end, showProgress );
00151 connect( worker,
00152 SIGNAL( finished( ExchangeDownload *,
int,
const QString & ) ),
00153 SLOT( slotDownloadFinished( ExchangeDownload *,
int,
00154
const QString & ) ) );
00155 connect( worker, SIGNAL( gotEvent( KCal::Event *,
const KURL & ) ),
00156 SIGNAL( event( KCal::Event *,
const KURL & ) ) );
00157 }
00158
00159
void ExchangeClient::upload( KCal::Event *event )
00160 {
00161 kdDebug() <<
"ExchangeClient::upload()" << endl;
00162
00163
if ( !mAccount->authenticate( mWindow ) ) {
00164 emit uploadFinished( 0, i18n(
"Authentication error") );
00165
return;
00166 }
00167
00168 ExchangeUpload *worker =
new ExchangeUpload( event, mAccount, mTimeZoneId,
00169 mWindow );
00170 connect( worker, SIGNAL( finished( ExchangeUpload *,
int,
const QString & ) ),
00171 SLOT( slotUploadFinished( ExchangeUpload *,
int,
const QString & ) ) );
00172 }
00173
00174
void ExchangeClient::remove( KCal::Event *event )
00175 {
00176
if ( !mAccount->authenticate( mWindow ) ) {
00177 emit removeFinished( 0, i18n(
"Authentication error") );
00178
return;
00179 }
00180
00181 ExchangeDelete *worker =
new ExchangeDelete( event, mAccount, mWindow );
00182 connect( worker, SIGNAL( finished( ExchangeDelete *,
int,
const QString & ) ),
00183 SLOT( slotRemoveFinished( ExchangeDelete *,
int,
const QString & ) ) );
00184 }
00185
00186
void ExchangeClient::slotDownloadFinished( ExchangeDownload *worker,
00187
int result,
const QString &moreInfo )
00188 {
00189 emit downloadFinished( result, moreInfo );
00190 worker->deleteLater();
00191 }
00192
00193
void ExchangeClient::slotDownloadFinished( ExchangeDownload* worker,
int result,
const QString& moreInfo,
QPtrList<KCal::Event>& events )
00194 {
00195 emit downloadFinished( result, moreInfo, events );
00196 worker->deleteLater();
00197 }
00198
00199
void ExchangeClient::slotUploadFinished( ExchangeUpload* worker,
int result,
const QString& moreInfo )
00200 {
00201 kdDebug() <<
"ExchangeClient::slotUploadFinished()" << endl;
00202 emit uploadFinished( result, moreInfo );
00203 worker->deleteLater();
00204 }
00205
00206
void ExchangeClient::slotRemoveFinished( ExchangeDelete* worker,
int result,
const QString& moreInfo )
00207 {
00208 kdDebug() <<
"ExchangeClient::slotRemoveFinished()" << endl;
00209 emit removeFinished( result, moreInfo );
00210 worker->deleteLater();
00211 }
00212
00213
int ExchangeClient::downloadSynchronous( KCal::Calendar *calendar,
00214
const QDate &start,
const QDate &end,
00215
bool showProgress )
00216 {
00217 kdDebug() <<
"ExchangeClient::downloadSynchronous()" << endl;
00218
00219 mClientState = WaitingForResult;
00220 connect(
this, SIGNAL( downloadFinished(
int,
const QString & ) ),
00221 SLOT( slotSyncFinished(
int,
const QString & ) ) );
00222
00223 download( calendar, start, end, showProgress );
00224
00225
00226 QApplication::setOverrideCursor
00227 ( KCursor::waitCursor() );
00228
do {
00229 qApp->processEvents();
00230 }
while ( mClientState == WaitingForResult );
00231 QApplication::restoreOverrideCursor();
00232
00233 disconnect(
this, SIGNAL( downloadFinished(
int,
const QString & ) ),
00234
this, SLOT( slotSyncFinished(
int,
const QString & ) ) );
00235
00236
return mSyncResult;
00237 }
00238
00239
int ExchangeClient::uploadSynchronous( KCal::Event* event )
00240 {
00241 mClientState = WaitingForResult;
00242 connect(
this, SIGNAL( uploadFinished(
int,
const QString & ) ),
00243 SLOT( slotSyncFinished(
int,
const QString & ) ) );
00244
00245 upload( event );
00246
00247
00248 QApplication::setOverrideCursor( KCursor::waitCursor() );
00249
do {
00250 qApp->processEvents();
00251 }
while ( mClientState == WaitingForResult );
00252 QApplication::restoreOverrideCursor();
00253 disconnect(
this, SIGNAL( uploadFinished(
int,
const QString & ) ),
00254
this, SLOT( slotSyncFinished(
int,
const QString & ) ) );
00255
return mSyncResult;
00256 }
00257
00258
int ExchangeClient::removeSynchronous( KCal::Event* event )
00259 {
00260 mClientState = WaitingForResult;
00261 connect(
this, SIGNAL( removeFinished(
int,
const QString & ) ),
00262 SLOT( slotSyncFinished(
int,
const QString & ) ) );
00263
00264 remove( event );
00265
00266
00267 QApplication::setOverrideCursor( KCursor::waitCursor() );
00268
do {
00269 qApp->processEvents();
00270 }
while ( mClientState == WaitingForResult );
00271 QApplication::restoreOverrideCursor();
00272 disconnect(
this, SIGNAL( removeFinished(
int,
const QString & ) ),
00273
this, SLOT( slotSyncFinished(
int,
const QString & ) ) );
00274
return mSyncResult;
00275 }
00276
00277
void ExchangeClient::slotSyncFinished(
int result,
const QString &moreInfo )
00278 {
00279 kdDebug() <<
"Exchangeclient::slotSyncFinished("<<result<<
","<<moreInfo<<
")" << endl;
00280
if ( mClientState == WaitingForResult ) {
00281 mClientState = HaveResult;
00282 mSyncResult = result;
00283 mDetailedErrorString = moreInfo;
00284 }
00285 }
00286
00287
QString ExchangeClient::detailedErrorString()
00288 {
00289
return mDetailedErrorString;
00290 }
00291
00292
#include "exchangeclient.moc"