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 two for test() method
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   QString query = 
00082   "<propfind xmlns=\"DAV:\" xmlns:h=\"urn:schemas:httpmail:\">\r\n"
00083   "  <prop>\r\n"
00084   "    <h:calendar/>\r\n"
00085   "    <h:contacts/>\r\n"
00086   "    <h:deleteditems/>\r\n"
00087   "    <h:drafts/>\r\n"
00088   "    <h:inbox/>\r\n"
00089   "    <h:journal/>\r\n"
00090   "    <h:notes/>\r\n"
00091   "    <h:outbox/>\r\n"
00092   "    <h:sentitems/>\r\n"
00093   "    <h:tasks/>\r\n"
00094   "    <h:msgfolderroot/>\r\n"
00095   "    <h:sendmsg/>\r\n"
00096   "  </prop>\r\n"
00097   "</propfind>\r\n";
00098 
00099   KIO::DavJob* job = new KIO::DavJob( url, (int) KIO::DAV_PROPFIND, query, false );
00100   job->addMetaData( "davDepth", "0" );
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"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:58 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001