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 #include <klocale.h>
00026 
00027 // These for test() method
00028 #include <kio/http.h>
00029 #include <kio/davjob.h>
00030 // #include "libkdepim/resources/resourcemanager.h"
00031 // #include "libkdepim/resources/calendar/resourcecalendar.h"
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 //#include "exchangemonitor.h"
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 //  if ( !mAccount->authenticate( mWindow ) ) return;
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   KRES::Manager<KCal::ResourceCalendar>* manager = new KRES::Manager<KCal::ResourceCalendar>( "calendar" );
00090   KCal::ResourceCalendar* resource = manager->standardResource();
00091 
00092   kdDebug(5800) << "Opening resource " + resource->resourceName() << endl;
00093   bool result = resource->open();
00094   kdDebug() << "Result: " << result << endl;
00095 
00096   resource->subscribeEvents( QDate( 2002, 12, 18 ), QDate( 2002, 12, 19 ) );
00097 */
00098 //  mAccount->tryFindMailbox();
00099 /*
00100   QString query = 
00101   "<propfind xmlns=\"DAV:\" xmlns:h=\"urn:schemas:httpmail:\">\r\n"
00102   "  <allprop/>\r\n"
00103   "</propfind>\r\n";
00104 
00105   KIO::DavJob* job = new KIO::DavJob( url, (int) KIO::DAV_PROPFIND, query, false );
00106   job->addMetaData( "davDepth", "0" );
00107 */
00108 //  ExchangeMonitor* monitor = new ExchangeMonitor( mAccount );
00109 }
00110 
00111 void ExchangeClient::test2()
00112 {
00113   kdDebug() << "Entering test2()" << endl;
00114 }
00115 /*
00116 ExchangeMonitor* ExchangeClient::monitor( int pollMode, const QHostAddress& ownInterface ) 
00117 {
00118   return new ExchangeMonitor( mAccount, pollMode, ownInterface  );
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   // TODO: Remove this busy loop
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   // TODO: Remove this busy loop
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   // TODO: Remove this busy loop
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"
KDE Logo
This file is part of the documentation for libkpimexchange Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 04:48:16 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003