1 #include "Communication.h"
2 #include "ConnectionSettings.h"
3 #include <QAuthenticator>
5 Communication::Communication( const ConnectionSettings &aConnection ) :
9 iConnectionSettings = new ConnectionSettings( aConnection );
11 iHttp = new QHttp( iConnectionSettings->serverUrl().toString(), QHttp::ConnectionModeHttps );
12 iResponse = new QByteArray();
15 SIGNAL( readyRead( const QHttpResponseHeader& ) ),
17 SLOT( processResponse( const QHttpResponseHeader& ) )
20 SIGNAL( requestStarted( int ) ),
22 SLOT( handleRequestStarted( int ) )
25 SIGNAL( requestFinished( int, bool ) ),
27 SLOT( handleResults( int, bool ) )
30 SIGNAL( dataReadProgress( int, int ) ),
32 SLOT( handleReadProgress( int, int ) )
35 SIGNAL( authenticationRequired( const QString&, quint16, QAuthenticator* ) ),
37 SLOT( handleAuthentication( const QString&, quint16, QAuthenticator* ) ) );
39 SIGNAL( sslErrors( const QList<QSslError>& ) ),
41 SLOT( ignoreSslErrors() )/*this, SLOT( notifySsl( const QList<QSslError>& ) )*/
45 Communication::~Communication()
47 delete iConnectionSettings;
52 void Communication::processResponse( const QHttpResponseHeader& aHeader )
54 if ( aHeader.statusCode() == 200 )
56 iResponse->append( iHttp->readAll() );
60 void Communication::handleRequestStarted( int aRequestId )
62 if( aRequestId != 0 && iCurrentRequest != 0 &&
63 aRequestId == iCurrentRequest )
65 emit requestStarted( iCurrentRequest );
69 void Communication::handleResults( int aId, bool /*aError*/ )
71 if( aId == iCurrentRequest )
74 emit requestFinished( aId, iHttp->error() );
78 void Communication::handleAuthentication( const QString& /*aHost*/, quint16 /*aPort*/, QAuthenticator* aAuthenticator )
80 aAuthenticator->setPassword( iConnectionSettings->password() );
81 aAuthenticator->setUser( iConnectionSettings->username() );
83 if( iAuthFailCount > 1 )
89 int Communication::request( const QString &aCommand, const QByteArray &aContent )
91 //TODO: This is just temporarily here to implement multiple request support
94 QHttpRequestHeader header( QString( "POST" ), QString( "/ews/exchange.asmx" ) );
95 header.setValue( "Host", iConnectionSettings->serverUrl().toString() );
96 QString command = aCommand;
97 header.setContentType( command );
101 iCurrentRequest = iHttp->request( header, aContent );
103 return iCurrentRequest;
106 const QByteArray& Communication::response( int /*aRequestId*/ )
111 void Communication::handleReadProgress( int aDone, int aTotal )
113 emit readProgress( iCurrentRequest, aDone, aTotal );