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