QSimpleUpdater
A simple auto-updater system for Qt applications
Public Slots | Signals | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
Downloader Class Reference

Implements an integrated file downloader with a nice UI. More...

#include <Downloader.h>

Inheritance diagram for Downloader:

Public Slots

void startDownload (const QUrl &url)
 
void setUseCustomInstallProcedures (const bool &custom)
 

Signals

void downloadFinished (const QString &url, const QString &filepath)
 

Public Member Functions

 Downloader (QWidget *parent=0)
 
bool useCustomInstallProcedures () const
 

Private Slots

void openDownload ()
 
void installUpdate ()
 
void cancelDownload ()
 
void onDownloadFinished ()
 
void calculateSizes (qint64 received, qint64 total)
 
void updateProgress (qint64 received, qint64 total)
 
void calculateTimeRemaining (qint64 received, qint64 total)
 

Private Member Functions

qreal round (const qreal &input)
 

Private Attributes

uint m_startTime
 
QString m_filePath
 
Ui::Downloader * m_ui
 
QNetworkReply * m_reply
 
bool m_useCustomProcedures
 
QNetworkAccessManager * m_manager
 

Detailed Description

Implements an integrated file downloader with a nice UI.

Member Function Documentation

void Downloader::calculateSizes ( qint64  received,
qint64  total 
)
privateslot

Calculates the appropiate size units (bytes, KB or MB) for the received data and the total download size. Then, this function proceeds to update the dialog controls/UI.

References round().

Referenced by updateProgress().

void Downloader::calculateTimeRemaining ( qint64  received,
qint64  total 
)
privateslot

Uses two time samples (from the current time and a previous sample) to calculate how many bytes have been downloaded.

Then, this function proceeds to calculate the appropiate units of time (hours, minutes or seconds) and constructs a user-friendly string, which is displayed in the dialog.

Referenced by updateProgress().

void Downloader::cancelDownload ( )
privateslot

Prompts the user if he/she wants to cancel the download and cancels the download if the user agrees to do that.

void Downloader::installUpdate ( )
privateslot

Instructs the OS to open the downloaded file.

Note
If useCustomInstallProcedures() returns true, the function will not instruct the OS to open the downloaded file. You can use the signals fired by the QSimpleUpdater to install the update with your own implementations/code.

References openDownload(), and useCustomInstallProcedures().

Referenced by onDownloadFinished().

void Downloader::onDownloadFinished ( )
privateslot

Writes the downloaded data to a temp. directory and updates the UI controls.

Note
If the function detects that the downloaded data is an HTML file (e.g. a redirection notice from the server), the function will add the *.html extension to the downloaded file. This ensures that the download will be resumed when the OS opens a web-browser with the redirection notice.

References installUpdate().

Referenced by startDownload().

void Downloader::openDownload ( )
privateslot

Opens the downloaded file.

Note
If the downloaded file is not found, then the function will alert the user about the error.

Referenced by installUpdate().

qreal Downloader::round ( const qreal &  input)
private

Rounds the given input to two decimal places

Referenced by calculateSizes().

void Downloader::setUseCustomInstallProcedures ( const bool &  custom)
slot

If the custom parameter is set to true, then the Downloader will not attempt to open the downloaded file.

Use the signals fired by the QSimpleUpdater to implement your own install procedures.

Referenced by Updater::setUseCustomInstallProcedures().

void Downloader::startDownload ( const QUrl &  url)
slot

Begins downloading the file at the given url

References onDownloadFinished(), and updateProgress().

Referenced by Updater::setUpdateAvailable().

void Downloader::updateProgress ( qint64  received,
qint64  total 
)
privateslot

Uses the received and total parameters to get the download progress and update the progressbar value on the dialog.

References calculateSizes(), and calculateTimeRemaining().

Referenced by startDownload().

bool Downloader::useCustomInstallProcedures ( ) const

Returns true if the updater shall not intervene when the download has finished (you can use the QSimpleUpdater signals to know when the download is completed).

Referenced by installUpdate(), and Updater::useCustomInstallProcedures().


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