Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
Downloader Class Reference

Class managing the download of large files from a repository in the background. More...

#include <downloader.h>

Inheritance diagram for Downloader:
Inheritance graph
Collaboration diagram for Downloader:
Collaboration graph

Signals

void signalNoInternetConnection (QVariant forced)
 
void signalDownloading (QVariant downloading)
 
void signalProgress (QVariant filesRemaining, QVariant percent)
 
void signalNewFileDownloaded (QString localpath)
 
void signalAllFilesDownloaded ()
 

Public Member Functions

 Downloader (QString url, QObject *parent=0)
 Constructor, resetting the member variables. More...
 
virtual ~Downloader ()
 
void start (bool forced)
 Start the downloading process in the background. More...
 
void stop ()
 Stop downloading. More...
 
bool isDownloading ()
 
QStringList getPathsOfDownloadedFiles ()
 Get a list of paths of all downloaded files. More...
 
void setVerbosity (int verbosity)
 Set the verbosity level of the class-specific messages. More...
 
int getVerbosity ()
 Get the actual verbosity level. More...
 

Private Slots

void downloadIndexFile ()
 Download index file. More...
 
void indexFileDownloadFinished (QNetworkReply *pReply)
 Private slot: Index file downloaded. More...
 
void initiateDownloadOfNextFile ()
 Private slot: Initiate download of next file. More...
 
void checkWhetherFileExistsAndDownload ()
 Private slot: Start downloading if necessary. More...
 
void downloadProgress (qint64 bytesReceived, qint64 bytesTotal)
 Private slot: Download a data chunk and report progress. More...
 
void downloadComplete (QNetworkReply *pReply)
 Private slot: Download completed. More...
 
void finalize ()
 Finalize download. More...
 

Private Member Functions

QString fullPath (const QString &path, const QString &file) const
 Helper function: Construct a full path out of a path and a file name. More...
 
bool isConnectedToInternet ()
 Check internet connection. More...
 

Private Attributes

QString mLocalPath
 Local path of the file to be downloaded. More...
 
QString mRemotePath
 Remote path of the file to be downloaded. More...
 
QString mIndexFileName
 Name of the remote index file. More...
 
QNetworkAccessManager mNetworkManager
 Instance of the Qt network access manager. More...
 
QStringList mIndexOfFiles
 The content of the index file as a QStringList. More...
 
QNetworkReply * pNetworkReply
 Pointer to the network reply structure. More...
 
QFile mFile
 File to be written. More...
 
bool mIsWaitingForConnection
 Flag indicating waiting status. More...
 
bool mForcedDownload
 Flag for forced download. More...
 
bool mIsDownloading
 Flag indicating active download. More...
 

Detailed Description

Class managing the download of large files from a repository in the background.

This module download files from a remote location (http server) to the local applicaition directory. The files that are downloaded are listed in an index file (index.txt) on the server. The downloading process is singal-slot-driven and is carried out silently in the background.

Definition at line 48 of file downloader.h.

Constructor & Destructor Documentation

Downloader::Downloader ( QString  url,
QObject *  parent = 0 
)
explicit

Constructor, resetting the member variables.

Parameters
url: String containing the http address (URL) from where the files are downloaded.
parent: Optional parent object

Definition at line 48 of file downloader.cpp.

Here is the call graph for this function:

virtual Downloader::~Downloader ( )
inlinevirtual

Definition at line 54 of file downloader.h.

Here is the call graph for this function:

Member Function Documentation

void Downloader::checkWhetherFileExistsAndDownload ( )
privateslot

Private slot: Start downloading if necessary.

This function first reads the header of the remote file without downloading it, extracting the remote file size and the remote date of last modification. If this size differs from the size of the local file of if the remote file was modified more recently than the local file was created, a new download is initiated.

Definition at line 381 of file downloader.cpp.

Here is the call graph for this function:

void Downloader::downloadComplete ( QNetworkReply *  pReply)
privateslot

Private slot: Download completed.

: This slot is triggered by the network manager after complete download of the file. The slot disconnects itself and copies the last chunk of data to the temporary file and closes it. The temporary file is then renamed to the true filename. Finally the slot finalize() is called

Parameters
pReply: Network reply emitted by the network manager

Definition at line 501 of file downloader.cpp.

Here is the call graph for this function:

void Downloader::downloadIndexFile ( )
privateslot

Download index file.

The function first checks whether the local app data storage and an internet connection are available. If so, it sends a request to the NetworkManager to download the index file. Otherwise it will check again in a minute.

Definition at line 179 of file downloader.cpp.

Here is the call graph for this function:

void Downloader::downloadProgress ( qint64  bytesReceived,
qint64  bytesTotal 
)
privateslot

Private slot: Download a data chunk and report progress.

This slot is called periodically from the mNetworkManager to report how many bytes have been downloaded. We use this slot for periodically reading the buffer and appending its content to the open local file. This allows one to download large files in the background without the need of excessive memory space

Parameters
bytesReceived: Number of bytes that have already been received
bytesTotal: Total length of the file in bytes

Definition at line 477 of file downloader.cpp.

void Downloader::finalize ( )
privateslot

Finalize download.

This function finalizes the download of a single file, deletes its entry from the mIndexOfFiles, and proceeds with the next file. If not files are left a corresponding signal is emitted and the process terminates.

Definition at line 550 of file downloader.cpp.

Here is the call graph for this function:

QString Downloader::fullPath ( const QString &  path,
const QString &  file 
) const
private

Helper function: Construct a full path out of a path and a file name.

Parameters
path: The path as a QString with or without a slash in the end
file: The bare filename without path and slashes
Returns
: full path as QString

Definition at line 574 of file downloader.cpp.

QStringList Downloader::getPathsOfDownloadedFiles ( )

Get a list of paths of all downloaded files.

Returns
List of paths

Definition at line 319 of file downloader.cpp.

Here is the call graph for this function:

int Log::getVerbosity ( )
inherited

Get the actual verbosity level.

Returns
: Verbosity level (1...4)

Definition at line 118 of file log.cpp.

void Downloader::indexFileDownloadFinished ( QNetworkReply *  pReply)
privateslot

Private slot: Index file downloaded.

The downloaded index file is converted to a QStringList named mIndexOfFiles and the index file is written to the local storage. Finally the slot initiateDownloadOfNextFile() is called.

Parameters
pReply: Pointer to the network reply (derived from QIODevice)

Definition at line 262 of file downloader.cpp.

Here is the call graph for this function:

void Downloader::initiateDownloadOfNextFile ( )
privateslot

Private slot: Initiate download of next file.

This slot starts the download chain for the first entry in the mIndexOfFiles. The first step is to check the file sizes and to see whether the file to be downloaded already exists on the local drive. For this reason the first step is to download only the head (metadata) of the remote file. After downloading the head, the private slot checkWhetherFileExistsAndDownload() is called.

Definition at line 356 of file downloader.cpp.

Here is the call graph for this function:

bool Downloader::isConnectedToInternet ( )
private

Check internet connection.

Returns
True if the device is connected to the internet.

Definition at line 73 of file downloader.cpp.

bool Downloader::isDownloading ( )
inline

Definition at line 58 of file downloader.h.

Here is the call graph for this function:

void Log::setVerbosity ( int  verbosity)
inherited

Set the verbosity level of the class-specific messages.

Parameters
verbosity: Verbosity level (1...4)

Definition at line 107 of file log.cpp.

void Downloader::signalAllFilesDownloaded ( )
signal
void Downloader::signalDownloading ( QVariant  downloading)
signal
void Downloader::signalNewFileDownloaded ( QString  localpath)
signal
void Downloader::signalNoInternetConnection ( QVariant  forced)
signal
void Downloader::signalProgress ( QVariant  filesRemaining,
QVariant  percent 
)
signal
void Downloader::start ( bool  forced)

Start the downloading process in the background.

By calling this function the Downloader starts the chain of signal-slot interactions to carry out the downloading process.

If the parameter 'forced' is true, the function tries to reload the files

Parameters
forced: Reload all files (including the existing ones)

Definition at line 121 of file downloader.cpp.

Here is the call graph for this function:

void Downloader::stop ( )

Stop downloading.

Terminate the network connection, close all files and exit.

Definition at line 237 of file downloader.cpp.

Member Data Documentation

QFile Downloader::mFile
private

File to be written.

Definition at line 89 of file downloader.h.

bool Downloader::mForcedDownload
private

Flag for forced download.

Definition at line 91 of file downloader.h.

QString Downloader::mIndexFileName
private

Name of the remote index file.

Definition at line 85 of file downloader.h.

QStringList Downloader::mIndexOfFiles
private

The content of the index file as a QStringList.

Definition at line 87 of file downloader.h.

bool Downloader::mIsDownloading
private

Flag indicating active download.

Definition at line 92 of file downloader.h.

bool Downloader::mIsWaitingForConnection
private

Flag indicating waiting status.

Definition at line 90 of file downloader.h.

QString Downloader::mLocalPath
private

Local path of the file to be downloaded.

Definition at line 83 of file downloader.h.

QNetworkAccessManager Downloader::mNetworkManager
private

Instance of the Qt network access manager.

Definition at line 86 of file downloader.h.

QString Downloader::mRemotePath
private

Remote path of the file to be downloaded.

Definition at line 84 of file downloader.h.

QNetworkReply* Downloader::pNetworkReply
private

Pointer to the network reply structure.

Definition at line 88 of file downloader.h.


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