LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NetworkRequestBase Class Referenceabstract

Base class for network requests which are processed in the network access manager. More...

#include <networkrequestbase.h>

+ Inheritance diagram for NetworkRequestBase:
+ Collaboration diagram for NetworkRequestBase:

Public Slots

void start () noexcept
 Start downloading the requested content. More...
 
void abort () noexcept
 Abort downloading the requested content. More...
 

Signals

void startRequested ()
 Internal signal, don't use it from outside. More...
 
void progressState (QString state)
 Reply progress / state changed signal. More...
 
void progressPercent (int percent)
 Reply content download progress signal (simple) More...
 
void progress (qint64 bytesReceived, qint64 bytesTotal, int percent)
 Reply content download progress signal (extended) More...
 
void aborted ()
 Request aborted signal (emited right before finished()) More...
 
void succeeded ()
 Request succeeded signal (emited right before finished()) More...
 
void errored (QString errorMsg)
 Request errored signal (emited right before finished()) More...
 
void finished (bool success)
 Request finished signal. More...
 

Public Member Functions

 NetworkRequestBase ()=delete
 
 NetworkRequestBase (const NetworkRequestBase &other)=delete
 
 NetworkRequestBase (const QUrl &url) noexcept
 
virtual ~NetworkRequestBase () noexcept
 
void setHeaderField (const QByteArray &name, const QByteArray &value) noexcept
 Set a HTTP header field for the network request. More...
 
void setExpectedReplyContentSize (qint64 bytes) noexcept
 Set the expected size of the requested content. More...
 
NetworkRequestBaseoperator= (const NetworkRequestBase &rhs)=delete
 
virtual void prepareRequest ()=0
 
virtual void finalizeRequest ()=0
 
virtual void emitSuccessfullyFinishedSignals () noexcept=0
 
virtual void fetchNewData () noexcept=0
 

Protected Attributes

QUrl mUrl
 
qint64 mExpectedContentSize
 
QList< QUrl > mRedirectedUrls
 
QNetworkRequest mRequest
 
QScopedPointer< QNetworkReply > mReply
 
bool mStarted
 
bool mAborted
 
bool mErrored
 
bool mFinished
 

Private Member Functions

void executeRequest () noexcept
 
void replyReadyReadSlot () noexcept
 
void replyErrorSlot (QNetworkReply::NetworkError code) noexcept
 
void replySslErrorsSlot (const QList< QSslError > &errors) noexcept
 
void replyDownloadProgressSlot (qint64 bytesReceived, qint64 bytesTotal) noexcept
 
void replyFinishedSlot () noexcept
 
void finalize (const QString &errorMsg=QString()) noexcept
 

Static Private Member Functions

static QString formatFileSize (qint64 bytes) noexcept
 

Detailed Description

Base class for network requests which are processed in the network access manager.

This class lets you execute a network request without blocking the main application thread. After creating an object derived from NetworkRequestBase, you can connect to signals of that class to track the progress of the request. Then you need to call start() to start the request processing.

Note
You need to ensure that an instance of librepcb::NetworkAccessManager exists while starting a new network request. Otherwise the request will fail. Read the documentation of librepcb::NetworkAccessManager for more information.
See Also
librepcb::NetworkAccessManager
Author
ubruhin
Date
2016-09-12

Constructor & Destructor Documentation

NetworkRequestBase ( )
delete
NetworkRequestBase ( const NetworkRequestBase other)
delete
NetworkRequestBase ( const QUrl &  url)
noexcept

+ Here is the call graph for this function:

~NetworkRequestBase ( )
virtualnoexcept

+ Here is the call graph for this function:

Member Function Documentation

void setHeaderField ( const QByteArray &  name,
const QByteArray &  value 
)
noexcept

Set a HTTP header field for the network request.

Parameters
nameHeader field name
valueHeader field value

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void setExpectedReplyContentSize ( qint64  bytes)
noexcept

Set the expected size of the requested content.

If set, this size will be used to calculate the download progress in percent in case that there is no "Content-Length" attribute in the received HTTP header.

Parameters
bytesExpected content size of the reply in bytes

+ Here is the call graph for this function:

NetworkRequestBase& operator= ( const NetworkRequestBase rhs)
delete
void start ( )
slotnoexcept

Start downloading the requested content.

Warning
It is not save to access this object after calling this method! The object will be moved to another thread and will be deleted after an error occurs or the request succeeds. Any further access to the pointer which you have received from the constructor is unsave and could cause an application crash.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void abort ( )
slotnoexcept

Abort downloading the requested content.

Warning
Because calling this method makes only sense after calling start(), but which is unsave as described in start(), this method must only be used indirectly with the signals/slots concept of Qt (Qt automatically disconnects the callers signal from this slot as soon as this object gets destroyed, so the connection is always safe).

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void startRequested ( )
signal

Internal signal, don't use it from outside.

+ Here is the caller graph for this function:

void progressState ( QString  state)
signal

Reply progress / state changed signal.

This signal shows which actions are executed. Or in other words, it shows the current state of the request processing.

Parameters
actionShort description about the current action/state

+ Here is the caller graph for this function:

void progressPercent ( int  percent)
signal

Reply content download progress signal (simple)

Parameters
percent(Estimated) progress in percent (0..100)

+ Here is the caller graph for this function:

void progress ( qint64  bytesReceived,
qint64  bytesTotal,
int  percent 
)
signal

Reply content download progress signal (extended)

Parameters
bytesReceivedCount of bytes received
bytesTotalCount of total bytes (-1 if unknown)
percent(Estimated) progress in percent (0..100)
void aborted ( )
signal

Request aborted signal (emited right before finished())

+ Here is the caller graph for this function:

void succeeded ( )
signal

Request succeeded signal (emited right before finished())

+ Here is the caller graph for this function:

void errored ( QString  errorMsg)
signal

Request errored signal (emited right before finished())

Parameters
errorMsgAn error message

+ Here is the caller graph for this function:

void finished ( bool  success)
signal

Request finished signal.

This signal is emited right after aborted(), succeeded() or errored().

Parameters
successTrue if succeeded, false if aborted or errored
virtual void prepareRequest ( )
pure virtual

Implemented in FileDownload, and NetworkRequest.

+ Here is the caller graph for this function:

virtual void finalizeRequest ( )
pure virtual

Implemented in FileDownload, and NetworkRequest.

+ Here is the caller graph for this function:

virtual void emitSuccessfullyFinishedSignals ( )
pure virtualnoexcept

Implemented in FileDownload, and NetworkRequest.

virtual void fetchNewData ( )
pure virtualnoexcept

Implemented in FileDownload, and NetworkRequest.

+ Here is the caller graph for this function:

void executeRequest ( )
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replyReadyReadSlot ( )
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replyErrorSlot ( QNetworkReply::NetworkError  code)
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replySslErrorsSlot ( const QList< QSslError > &  errors)
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replyDownloadProgressSlot ( qint64  bytesReceived,
qint64  bytesTotal 
)
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replyFinishedSlot ( )
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void finalize ( const QString &  errorMsg = QString())
privatenoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString formatFileSize ( qint64  bytes)
staticprivatenoexcept

Member Data Documentation

QUrl mUrl
protected
qint64 mExpectedContentSize
protected
QList<QUrl> mRedirectedUrls
protected
QNetworkRequest mRequest
protected
QScopedPointer<QNetworkReply> mReply
protected
bool mStarted
protected
bool mAborted
protected
bool mErrored
protected
bool mFinished
protected

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