libkpimexchange Library API Documentation

exchangeclient.cpp

00001 /* 00002 This file is part of libkpimexchange 00003 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include <kapplication.h> 00022 #include <kurl.h> 00023 #include <kdebug.h> 00024 #include <kcursor.h> 00025 00026 // These for test() method 00027 #include <kio/http.h> 00028 #include <kio/davjob.h> 00029 // #include "libkdepim/resources/resourcemanager.h" 00030 // #include "libkdepim/resources/calendar/resourcecalendar.h" 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 //#include "exchangemonitor.h" 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 // mAccount->authenticate( mWindow ); 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 KRES::Manager<KCal::ResourceCalendar>* manager = new KRES::Manager<KCal::ResourceCalendar>( "calendar" ); 00088 KCal::ResourceCalendar* resource = manager->standardResource(); 00089 00090 kdDebug(5800) << "Opening resource " + resource->resourceName() << endl; 00091 bool result = resource->open(); 00092 kdDebug() << "Result: " << result << endl; 00093 00094 resource->subscribeEvents( QDate( 2002, 12, 18 ), QDate( 2002, 12, 19 ) ); 00095 */ 00096 // mAccount->tryFindMailbox(); 00097 /* 00098 QString query = 00099 "<propfind xmlns=\"DAV:\" xmlns:h=\"urn:schemas:httpmail:\">\r\n" 00100 " <allprop/>\r\n" 00101 "</propfind>\r\n"; 00102 00103 KIO::DavJob* job = new KIO::DavJob( url, (int) KIO::DAV_PROPFIND, query, false ); 00104 job->addMetaData( "davDepth", "0" ); 00105 */ 00106 // ExchangeMonitor* monitor = new ExchangeMonitor( mAccount ); 00107 } 00108 00109 void ExchangeClient::test2() 00110 { 00111 kdDebug() << "Entering test2()" << endl; 00112 } 00113 /* 00114 ExchangeMonitor* ExchangeClient::monitor( int pollMode, const QHostAddress& ownInterface ) 00115 { 00116 return new ExchangeMonitor( mAccount, pollMode, ownInterface ); 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"
KDE Logo
This file is part of the documentation for libkpimexchange Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:09 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003