QtlMovie 1.12 (A specialized FFmpeg front-end)
QtlSimpleWebRequest Class Reference

A class which performs one simple HTTP request, expecting a text response (HTML, XML, whatever, but not binary data). More...

Inheritance diagram for QtlSimpleWebRequest:

Signals

void completed (bool success, const QUrl &url, const QString &response, const QString &mimeType)
 Emitted when the request is completed. More...
 

Public Member Functions

 QtlSimpleWebRequest (const QString &url=QString(), QObject *parent=0, QtlLogger *log=0, int maxResponseSize=1000000)
 Constructor. More...
 
virtual ~QtlSimpleWebRequest ()
 Destructor. More...
 
void addCookie (const QString &name, const QString &value)
 Add a cookie for the request. More...
 
bool isCompleted () const
 Check if the request is completed. More...
 
bool isStarted () const
 Check if the request was already started. More...
 
void setUrl (const QString &url)
 Set the URL of the request. More...
 
void start ()
 Start the Web request. More...
 
QUrl url () const
 Get the URL of the request. More...
 

Private Slots

void httpFinished ()
 Invoked when HTTP request completes. More...
 
void httpReadyRead ()
 Invoked when data is available from HTTP. More...
 

Private Member Functions

 QtlSimpleWebRequest () Q_DECL_EQ_DELETE
 
void emitCompleted (const QString &error)
 Emit the completed() signal and delete this instance. More...
 
void startRequest (const QUrl &url)
 Start an HTTP request. More...
 

Private Attributes

bool _completed
 Signal completed() was emitted. More...
 
QString _contentType
 MIME content type. More...
 
QList< QNetworkCookie > _cookies
 List of cookies to get. More...
 
QtlLogger_log
 Message logger. More...
 
const int _maxResponseSize
 Maximum size in bytes of response. More...
 
QNetworkAccessManager _netwManager
 Network manager for all requests. More...
 
QtlNullLogger _nullLog
 Null logger. More...
 
int _redirected
 Number of redirections. More...
 
QNetworkReply * _reply
 HTTP reply. More...
 
bool _started
 The request is started. More...
 
QString _text
 Returned text. More...
 
QUrl _url
 URL to get. More...
 

Detailed Description

A class which performs one simple HTTP request, expecting a text response (HTML, XML, whatever, but not binary data).

Automatically handle proxies and HTTP redirections.

Constructor & Destructor Documentation

◆ QtlSimpleWebRequest() [1/2]

QtlSimpleWebRequest::QtlSimpleWebRequest ( const QString &  url = QString(),
QObject *  parent = 0,
QtlLogger log = 0,
int  maxResponseSize = 1000000 
)

Constructor.

Parameters
[in]urlURL to get. If unspecified, you must call setUrl() before start().
[in]parentOptional parent object.
[in]logOptional message logger.
[in]maxResponseSizeMaximum size in bytes of response (to avoid memory saturation). Default: 1 MB.

◆ ~QtlSimpleWebRequest()

QtlSimpleWebRequest::~QtlSimpleWebRequest ( )
virtual

Destructor.

◆ QtlSimpleWebRequest() [2/2]

QtlSimpleWebRequest::QtlSimpleWebRequest ( )
private

Member Function Documentation

◆ setUrl()

void QtlSimpleWebRequest::setUrl ( const QString &  url)

Set the URL of the request.

Must be called before start(). Ignored otherwise.

Parameters
[in]urlURL of the request.

◆ url()

QUrl QtlSimpleWebRequest::url ( ) const
inline

Get the URL of the request.

Returns
URL of the request.

◆ addCookie()

void QtlSimpleWebRequest::addCookie ( const QString &  name,
const QString &  value 
)

Add a cookie for the request.

Must be called before start(). Ignored otherwise.

Parameters
[in]nameCookie name.
[in]valueCookie value.

◆ start()

void QtlSimpleWebRequest::start ( )

Start the Web request.

The completion will be notified later using the completed() signal. Can be called only once. Subsequent calls are ignored.

◆ isStarted()

bool QtlSimpleWebRequest::isStarted ( ) const
inline

Check if the request was already started.

Returns
True if the request was already started, false otherwise.

◆ isCompleted()

bool QtlSimpleWebRequest::isCompleted ( ) const
inline

Check if the request is completed.

Returns
True if the request is completed, false otherwise.

◆ completed

void QtlSimpleWebRequest::completed ( bool  success,
const QUrl &  url,
const QString &  response,
const QString &  mimeType 
)
signal

Emitted when the request is completed.

Parameters
[in]successTrue on success, false on error (network error for instance).
[in]urlURL of the returned content. May not be the same as the original URL is some redirection occured.
[in]responseIf success is true, contains the text of the response. If status is false, contains an error message.
[in]mimeTypeIf success is true, contains the MIME type of the response. Examples: "text/html", "text/plain", "application/json".

◆ httpReadyRead

void QtlSimpleWebRequest::httpReadyRead ( )
privateslot

Invoked when data is available from HTTP.

◆ httpFinished

void QtlSimpleWebRequest::httpFinished ( )
privateslot

Invoked when HTTP request completes.

◆ startRequest()

void QtlSimpleWebRequest::startRequest ( const QUrl &  url)
private

Start an HTTP request.

Used in original request and all redirections.

Parameters
[in]urlURL to get.

◆ emitCompleted()

void QtlSimpleWebRequest::emitCompleted ( const QString &  error)
private

Emit the completed() signal and delete this instance.

Parameters
[in]errorError message, empty on success.

Member Data Documentation

◆ _nullLog

QtlNullLogger QtlSimpleWebRequest::_nullLog
private

Null logger.

◆ _log

QtlLogger* QtlSimpleWebRequest::_log
private

Message logger.

◆ _started

bool QtlSimpleWebRequest::_started
private

The request is started.

◆ _completed

bool QtlSimpleWebRequest::_completed
private

Signal completed() was emitted.

◆ _url

QUrl QtlSimpleWebRequest::_url
private

URL to get.

◆ _cookies

QList<QNetworkCookie> QtlSimpleWebRequest::_cookies
private

List of cookies to get.

◆ _maxResponseSize

const int QtlSimpleWebRequest::_maxResponseSize
private

Maximum size in bytes of response.

◆ _netwManager

QNetworkAccessManager QtlSimpleWebRequest::_netwManager
private

Network manager for all requests.

◆ _reply

QNetworkReply* QtlSimpleWebRequest::_reply
private

HTTP reply.

◆ _text

QString QtlSimpleWebRequest::_text
private

Returned text.

◆ _contentType

QString QtlSimpleWebRequest::_contentType
private

MIME content type.

◆ _redirected

int QtlSimpleWebRequest::_redirected
private

Number of redirections.


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