Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
QgsHttpTransaction Class Reference

HTTP request/response manager that is redirect-aware. More...

#include <qgshttptransaction.h>

List of all members.

Public Slots

void dataStarted (int id)
void dataHeaderReceived (const QHttpResponseHeader &resp)
void dataReceived (const QHttpResponseHeader &resp)
void dataProgress (int done, int total)
void dataFinished (int id, bool error)
void transactionFinished (bool error)
void dataStateChanged (int state)
void networkTimedOut ()
void abort ()
 Aborts the current transaction.

Signals

void setProgress (int done, int total)
 legacy code.
void dataReadProgress (int theProgress)
 Signal for progress update.
void totalSteps (int theTotalSteps)
 Signal for adjusted number of steps.
void statusChanged (QString theStatusQString)
 emit a signal to be caught by qgisapp and display a msg on status bar

Public Member Functions

 QgsHttpTransaction (QString uri, QString proxyHost=QString(), int proxyPort=80, QString proxyUser=QString(), QString proxyPass=QString(), QNetworkProxy::ProxyType proxyType=QNetworkProxy::NoProxy, QString userName=QString(), QString password=QString())
 Constructor.
virtual ~QgsHttpTransaction ()
 Destructor.
void getAsynchronously ()
bool getSynchronously (QByteArray &respondedContent, int redirections=0, const QByteArray *postData=0)
 Gets the response synchronously.
QString responseContentType ()
QString errorString ()
 If an operation returns 0 (e.g.
void setCredentials (const QString &username, const QString &password)
 Set the credentials (username and password)
int networkTimeout () const
 Returns the network timeout in msec.
void setNetworkTimeout (int msec)
 Sets the network timeout in milliseconds.

Static Public Member Functions

static bool applyProxySettings (QHttp &http, const QString &url)
 Apply proxy settings from QSettings to a http object.

Private Member Functions

 QgsHttpTransaction ()
 Default constructor is forbidden.

Private Attributes

QHttp * http
 Indicates the associated QHttp object.
int httpid
 Indicates the QHttp ID.
bool httpactive
 Indicates if the transaction is in progress.
QByteArray httpresponse
QString httpresponsecontenttype
QString httpurl
 The original URL requested for this transaction.
QString httphost
 The host being used for this transaction.
QString httpredirecturl
 If not empty, indicates that the QHttp is a redirect to the contents of this variable.
int httpredirections
 Number of http redirections this transaction has been subjected to.
QTimer * mWatchdogTimer
 Indicates the associated QTimer object - used to detect network timeouts.
QString mError
 The error message associated with the last HTTP error.
QString mUserName
 User name.
QString mPassword
 Password.
int mNetworkTimeoutMsec
 Network timeout in milliseconds.

Detailed Description

HTTP request/response manager that is redirect-aware.

This class extends the Qt QHttp concept by being able to recognise and respond to redirection responses (e.g. HTTP code 302)

Definition at line 37 of file qgshttptransaction.h.


Constructor & Destructor Documentation

QgsHttpTransaction::QgsHttpTransaction ( QString  uri,
QString  proxyHost = QString(),
int  proxyPort = 80,
QString  proxyUser = QString(),
QString  proxyPass = QString(),
QNetworkProxy::ProxyType  proxyType = QNetworkProxy::NoProxy,
QString  userName = QString(),
QString  password = QString() 
)

Constructor.

Note:
userName and password added in 1.1

Definition at line 39 of file qgshttptransaction.cpp.

References mNetworkTimeoutMsec.

QgsHttpTransaction::~QgsHttpTransaction ( )
virtual

Destructor.

Definition at line 61 of file qgshttptransaction.cpp.

References QgsDebugMsg.

QgsHttpTransaction::QgsHttpTransaction ( )
private

Default constructor is forbidden.

Definition at line 56 of file qgshttptransaction.cpp.


Member Function Documentation

void QgsHttpTransaction::abort ( )
slot

Aborts the current transaction.

Definition at line 546 of file qgshttptransaction.cpp.

References http.

bool QgsHttpTransaction::applyProxySettings ( QHttp &  http,
const QString &  url 
)
static

Apply proxy settings from QSettings to a http object.

Returns:
true if proxy settings was applied, false else

Definition at line 489 of file qgshttptransaction.cpp.

Referenced by getSynchronously().

void QgsHttpTransaction::dataFinished ( int  id,
bool  error 
)
slot

Definition at line 327 of file qgshttptransaction.cpp.

References http, httpactive, httpresponse, mError, and QgsDebugMsg.

Referenced by getSynchronously().

void QgsHttpTransaction::dataHeaderReceived ( const QHttpResponseHeader &  resp)
slot
void QgsHttpTransaction::dataProgress ( int  done,
int  total 
)
slot
void QgsHttpTransaction::dataReadProgress ( int  theProgress)
signal

Signal for progress update.

Referenced by dataProgress(), and getSynchronously().

void QgsHttpTransaction::dataReceived ( const QHttpResponseHeader &  resp)
slot

Definition at line 284 of file qgshttptransaction.cpp.

References http, and httpresponse.

Referenced by getSynchronously().

void QgsHttpTransaction::dataStarted ( int  id)
slot

Definition at line 247 of file qgshttptransaction.cpp.

References QgsDebugMsg.

Referenced by getSynchronously().

void QgsHttpTransaction::dataStateChanged ( int  state)
slot
QString QgsHttpTransaction::errorString ( )

If an operation returns 0 (e.g.

getSynchronously()), this function returns the text of the error associated with the failure. Interactive users of this provider can then, for example, call a QMessageBox to display the contents.

Definition at line 484 of file qgshttptransaction.cpp.

References mError.

void QgsHttpTransaction::getAsynchronously ( )

Definition at line 72 of file qgshttptransaction.cpp.

bool QgsHttpTransaction::getSynchronously ( QByteArray &  respondedContent,
int  redirections = 0,
const QByteArray *  postData = 0 
)

Gets the response synchronously.

Note that signals will still be emitted while in this function.

    The function returns false if there is an error while getting the response.
    @param[out] respondedContent is replaced with the new content.

    @param[in]  redirections     is used to measure how many http redirections we've been through.
    Clients typically don't need to set this.

    @param postData data to send with the http message. This is only used for HTTP POST. If
    0 then the request is done with HTTP GET.

    @return true in case of success

Definition at line 79 of file qgshttptransaction.cpp.

References applyProxySettings(), dataFinished(), dataHeaderReceived(), dataProgress(), dataReadProgress(), dataReceived(), dataStarted(), dataStateChanged(), getSynchronously(), http, HTTP_PORT_DEFAULT, httpactive, httphost, httpid, httpredirections, httpredirecturl, httpresponse, httpurl, mError, mNetworkTimeoutMsec, mPassword, mUserName, mWatchdogTimer, networkTimedOut(), QgsDebugMsg, setCredentials(), statusChanged(), and transactionFinished().

Referenced by getSynchronously().

void QgsHttpTransaction::networkTimedOut ( )
slot

Definition at line 471 of file qgshttptransaction.cpp.

References httpactive, mError, mNetworkTimeoutMsec, and QgsDebugMsg.

Referenced by getSynchronously().

int QgsHttpTransaction::networkTimeout ( ) const
inline

Returns the network timeout in msec.

Definition at line 100 of file qgshttptransaction.h.

QString QgsHttpTransaction::responseContentType ( )

Definition at line 241 of file qgshttptransaction.cpp.

References httpresponsecontenttype.

void QgsHttpTransaction::setCredentials ( const QString &  username,
const QString &  password 
)

Set the credentials (username and password)

Note:
added in 1.1

Definition at line 67 of file qgshttptransaction.cpp.

References mPassword, and mUserName.

Referenced by getSynchronously().

void QgsHttpTransaction::setNetworkTimeout ( int  msec)
inline

Sets the network timeout in milliseconds.

Definition at line 102 of file qgshttptransaction.h.

void QgsHttpTransaction::setProgress ( int  done,
int  total 
)
signal

legacy code.

This signal is currently not emitted and only kept for API compatibility

void QgsHttpTransaction::statusChanged ( QString  theStatusQString)
signal

emit a signal to be caught by qgisapp and display a msg on status bar

Referenced by dataProgress(), dataStateChanged(), and getSynchronously().

void QgsHttpTransaction::totalSteps ( int  theTotalSteps)
signal

Signal for adjusted number of steps.

Referenced by dataProgress().

void QgsHttpTransaction::transactionFinished ( bool  error)
slot

Definition at line 374 of file qgshttptransaction.cpp.

References http, httpactive, httpresponse, mError, and QgsDebugMsg.

Referenced by getSynchronously().


Member Data Documentation

QHttp* QgsHttpTransaction::http
private

Indicates the associated QHttp object.

Note:
We tried to use this as a plain QHttp object but strange things were happening with the signals - therefore we use the "pointer to" instead.

Definition at line 152 of file qgshttptransaction.h.

Referenced by abort(), dataFinished(), dataReceived(), getSynchronously(), and transactionFinished().

bool QgsHttpTransaction::httpactive
private

Indicates if the transaction is in progress.

Definition at line 162 of file qgshttptransaction.h.

Referenced by dataFinished(), getSynchronously(), networkTimedOut(), and transactionFinished().

QString QgsHttpTransaction::httphost
private

The host being used for this transaction.

Definition at line 182 of file qgshttptransaction.h.

Referenced by dataStateChanged(), and getSynchronously().

int QgsHttpTransaction::httpid
private

Indicates the QHttp ID.

Definition at line 157 of file qgshttptransaction.h.

Referenced by getSynchronously().

int QgsHttpTransaction::httpredirections
private

Number of http redirections this transaction has been subjected to.

TODO: Use this as part of a redirection loop detector

Definition at line 197 of file qgshttptransaction.h.

Referenced by getSynchronously().

QString QgsHttpTransaction::httpredirecturl
private

If not empty, indicates that the QHttp is a redirect to the contents of this variable.

Definition at line 188 of file qgshttptransaction.h.

Referenced by dataHeaderReceived(), and getSynchronously().

QByteArray QgsHttpTransaction::httpresponse
private
QString QgsHttpTransaction::httpresponsecontenttype
private

Definition at line 172 of file qgshttptransaction.h.

Referenced by dataHeaderReceived(), and responseContentType().

QString QgsHttpTransaction::httpurl
private

The original URL requested for this transaction.

Definition at line 177 of file qgshttptransaction.h.

Referenced by dataStateChanged(), and getSynchronously().

QString QgsHttpTransaction::mError
private

The error message associated with the last HTTP error.

Definition at line 207 of file qgshttptransaction.h.

Referenced by dataFinished(), dataHeaderReceived(), errorString(), getSynchronously(), networkTimedOut(), and transactionFinished().

int QgsHttpTransaction::mNetworkTimeoutMsec
private

Network timeout in milliseconds.

Definition at line 220 of file qgshttptransaction.h.

Referenced by dataHeaderReceived(), dataProgress(), dataStateChanged(), getSynchronously(), networkTimedOut(), and QgsHttpTransaction().

QString QgsHttpTransaction::mPassword
private

Password.

Definition at line 217 of file qgshttptransaction.h.

Referenced by getSynchronously(), and setCredentials().

QString QgsHttpTransaction::mUserName
private

User name.

Definition at line 212 of file qgshttptransaction.h.

Referenced by getSynchronously(), and setCredentials().

QTimer* QgsHttpTransaction::mWatchdogTimer
private

Indicates the associated QTimer object - used to detect network timeouts.

Definition at line 202 of file qgshttptransaction.h.

Referenced by dataHeaderReceived(), dataProgress(), dataStateChanged(), and getSynchronously().


The documentation for this class was generated from the following files: