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