LibrePCB Developers Documentation
FileDownload Class Referencefinal

This class is used to download a file asynchronously in a separate thread. More...

#include <filedownload.h>

+ Inheritance diagram for FileDownload:
+ Collaboration diagram for FileDownload:

Signals

void fileDownloaded (librepcb::FilePath filepath)
 File successfully downloaded signal (emitted right before finished()) More...
 
void zipFileExtracted (librepcb::FilePath directory)
 ZIP file successfully extracted signal (emitted right before finished()) More...
 
- Signals inherited from NetworkRequestBase
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 (emitted right before finished()) More...
 
void succeeded ()
 Request succeeded signal (emitted right before finished()) More...
 
void errored (QString errorMsg)
 Request errored signal (emitted right before finished()) More...
 
void finished (bool success)
 Request finished signal. More...
 

Public Member Functions

 FileDownload ()=delete
 
 FileDownload (const FileDownload &other)=delete
 
 FileDownload (const QUrl &url, const FilePath &dest) noexcept
 Constructor. More...
 
 ~FileDownload () noexcept
 
void setExpectedChecksum (QCryptographicHash::Algorithm algorithm, const QByteArray &checksum) noexcept
 Set the expected checksum of the file to download. More...
 
void setZipExtractionDirectory (const FilePath &dir) noexcept
 Set extraction directory of the ZIP file to download. More...
 
FileDownloadoperator= (const FileDownload &rhs)=delete
 
- Public Member Functions inherited from NetworkRequestBase
 NetworkRequestBase ()=delete
 
 NetworkRequestBase (const NetworkRequestBase &other)=delete
 
 NetworkRequestBase (const QUrl &url, const QByteArray &postData=QByteArray()) noexcept
 
virtual ~NetworkRequestBase () noexcept
 
void setHeaderField (const QByteArray &name, const QByteArray &value) noexcept
 Set a HTTP header field for the network request. More...
 
void setCacheLoadControl (QNetworkRequest::CacheLoadControl value) noexcept
 Set the cache load control attribute. More...
 
void setExpectedReplyContentSize (qint64 bytes) noexcept
 Set the expected size of the requested content. More...
 
void setMinimumCacheTime (int seconds) noexcept
 Set the minimum time the request should be cached. More...
 
NetworkRequestBaseoperator= (const NetworkRequestBase &rhs)=delete
 
virtual void prepareRequest ()=0
 
virtual void finalizeRequest ()=0
 
virtual void emitSuccessfullyFinishedSignals () noexcept=0
 
virtual void fetchNewData (QIODevice &device) noexcept=0
 

Private Member Functions

void prepareRequest () override
 
void finalizeRequest () override
 
void emitSuccessfullyFinishedSignals () noexcept override
 
void fetchNewData (QIODevice &device) noexcept override
 

Private Attributes

FilePath mDestination
 
QScopedPointer< QSaveFile > mFile
 
QCryptographicHash::Algorithm mHashAlgorithm
 
QByteArray mExpectedChecksum
 
FilePath mExtractZipToDir
 

Additional Inherited Members

- Public Slots inherited from NetworkRequestBase
void start () noexcept
 Start downloading the requested content. More...
 
void abort () noexcept
 Abort downloading the requested content. More...
 
- Protected Attributes inherited from NetworkRequestBase
QUrl mUrl
 
QByteArray mPostData
 
qint64 mExpectedContentSize
 
int mMinimumCacheTime
 
QList< QUrl > mRedirectedUrls
 
QNetworkRequest mRequest
 
QScopedPointer< QNetworkReply > mReply
 
bool mStarted
 
bool mAborted
 
bool mErrored
 
bool mFinished
 

Detailed Description

This class is used to download a file asynchronously in a separate thread.

See also
librepcb::NetworkRequestBase, librepcb::DownloadManager

Constructor & Destructor Documentation

◆ FileDownload() [1/3]

FileDownload ( )
delete

◆ FileDownload() [2/3]

FileDownload ( const FileDownload other)
delete

◆ FileDownload() [3/3]

FileDownload ( const QUrl &  url,
const FilePath dest 
)
noexcept

Constructor.

Parameters
urlThe URL to the file to download
destThe path to the destination file (must not exist!)

◆ ~FileDownload()

~FileDownload ( )
noexcept

Member Function Documentation

◆ setExpectedChecksum()

void setExpectedChecksum ( QCryptographicHash::Algorithm  algorithm,
const QByteArray &  checksum 
)
noexcept

Set the expected checksum of the file to download.

If set, the checksum of the downloaded file will be compared with this checksum. If they differ, the file gets removed and an error will be reported.

Parameters
algorithmThe checksum algorithm to be used
checksumThe expected checksum of the file to download

◆ setZipExtractionDirectory()

void setZipExtractionDirectory ( const FilePath dir)
noexcept

Set extraction directory of the ZIP file to download.

If set (and valid), the downloaded file (must be a ZIP!) will be extracted into this directory after downloading it.

Note
The downloaded ZIP file will be removed after extracting it.
Parameters
dirDestination directory (may or may not exist)
+ Here is the caller graph for this function:

◆ operator=()

FileDownload & operator= ( const FileDownload rhs)
delete

◆ fileDownloaded

void fileDownloaded ( librepcb::FilePath  filepath)
signal

File successfully downloaded signal (emitted right before finished())

Note
The parameter type is specified with the full namespace, reason see here: http://stackoverflow.com/questions/21119397/emitting-signals-with-custom-types-does-not-work
+ Here is the caller graph for this function:

◆ zipFileExtracted

void zipFileExtracted ( librepcb::FilePath  directory)
signal

ZIP file successfully extracted signal (emitted right before finished())

Note
The parameter type is specified with the full namespace, reason see here: http://stackoverflow.com/questions/21119397/emitting-signals-with-custom-types-does-not-work
+ Here is the caller graph for this function:

◆ prepareRequest()

void prepareRequest ( )
overrideprivatevirtual

Implements NetworkRequestBase.

+ Here is the call graph for this function:

◆ finalizeRequest()

void finalizeRequest ( )
overrideprivatevirtual

Implements NetworkRequestBase.

+ Here is the call graph for this function:

◆ emitSuccessfullyFinishedSignals()

void emitSuccessfullyFinishedSignals ( )
overrideprivatevirtualnoexcept

Implements NetworkRequestBase.

+ Here is the call graph for this function:

◆ fetchNewData()

void fetchNewData ( QIODevice &  device)
overrideprivatevirtualnoexcept

Implements NetworkRequestBase.

Member Data Documentation

◆ mDestination

FilePath mDestination
private

◆ mFile

QScopedPointer<QSaveFile> mFile
private

◆ mHashAlgorithm

QCryptographicHash::Algorithm mHashAlgorithm
private

◆ mExpectedChecksum

QByteArray mExpectedChecksum
private

◆ mExtractZipToDir

FilePath mExtractZipToDir
private

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