FileDownloader Class
class KDUpdater::FileDownloaderThe FileDownloader class is the base class for file downloaders used in KDUpdater. More...
Header: | #include <FileDownloader> |
Inherits: | QObject |
Inherited By: | KDUpdater::HttpDownloader, KDUpdater::LocalFileDownloader, and KDUpdater::ResourceFileDownloader |
Properties
- autoRemoveDownloadedFile : bool
- scheme : QString
- url : QUrl
Public Functions
FileDownloader(const QString &scheme, QObject *parent = 0) | |
virtual | ~FileDownloader() |
QByteArray | assumedSha1Sum() const |
QAuthenticator | authenticator() const |
virtual bool | canDownload() const = 0 |
virtual KDUpdater::FileDownloader * | clone(QObject *parent = 0) const = 0 |
void | download() |
virtual QString | downloadedFileName() const = 0 |
QString | errorString() const |
bool | followRedirects() const |
qint64 | getBytesReceived() const |
bool | ignoreSslErrors() |
bool | isAutoRemoveDownloadedFile() const |
virtual bool | isDownloaded() const = 0 |
KDUpdater::FileDownloaderProxyFactory * | proxyFactory() const |
QString | scheme() const |
void | setAssumedSha1Sum(const QByteArray &sum) |
void | setAuthenticator(const QAuthenticator &authenticator) |
void | setAutoRemoveDownloadedFile(bool val) |
virtual void | setDownloadedFileName(const QString &name) = 0 |
void | setFollowRedirects(bool val) |
void | setIgnoreSslErrors(bool ignore) |
void | setProxyFactory(KDUpdater::FileDownloaderProxyFactory *factory) |
void | setScheme(const QString &scheme) |
void | setUrl(const QUrl &url) |
QByteArray | sha1Sum() const |
QUrl | url() const |
Public Slots
virtual void | cancelDownload() |
Signals
void | authenticatorChanged(const QAuthenticator &authenticator) |
void | downloadAborted(const QString &errorMessage) |
void | downloadCanceled() |
void | downloadCompleted() |
void | downloadProgress(double progress) |
void | downloadProgress(qint64 bytesReceived, qint64 bytesToReceive) |
void | downloadSpeed(qint64 bytesPerSecond) |
void | downloadStarted() |
void | downloadStatus(const QString &status) |
void | estimatedDownloadTime(int seconds) |
Protected Functions
void | addCheckSumData(const QByteArray &data) |
void | addSample(qint64 sample) |
qint64 | bytesDownloadedBeforeResume() |
void | clearBytesDownloadedBeforeResume() |
int | downloadDeadlineTimerId() const |
int | downloadSpeedTimerId() const |
void | emitDownloadProgress() |
void | emitDownloadSpeed() |
void | emitDownloadStatus() |
void | emitEstimatedDownloadTime() |
bool | isDownloadPaused() |
bool | isDownloadResumed() |
virtual void | onError() = 0 |
virtual void | onSuccess() = 0 |
void | resetCheckSumData() |
void | runDownloadDeadlineTimer() |
void | runDownloadSpeedTimer() |
void | setDownloadAborted(const QString &error) |
void | setDownloadCanceled() |
void | setDownloadCompleted() |
void | setDownloadPaused(bool paused) |
void | setDownloadResumed(bool resumed) |
void | setProgress(qint64 bytesReceived, qint64 bytesToReceive) |
void | stopDownloadDeadlineTimer() |
void | stopDownloadSpeedTimer() |
qint64 | totalBytesDownloadedBeforeResume() |
void | updateBytesDownloadedBeforeResume(qint64 bytes) |
void | updateTotalBytesDownloadedBeforeResume() |
Detailed Description
File downloaders are used by the KDUpdater::Update class to download update files. Each subclass of FileDownloader can download files from a specific category of sources (such as local
, ftp
, http
).
This is an internal class, not a part of the public API. Currently we have the following subclasses of FileDownloader:
- HttpDownloader to download files over FTP, HTTP, or HTTPS if Qt is built with SSL.
- LocalFileDownloader to copy files from the local file system.
- ResourceFileDownloader to download resource files.
Property Documentation
autoRemoveDownloadedFile : bool
This property holds whether the downloaded file should be automatically removed after it is downloaded and the class goes out of scope.
Access functions:
bool | isAutoRemoveDownloadedFile() const |
void | setAutoRemoveDownloadedFile(bool val) |
scheme : QString
This property holds the scheme to use for downloading files.
Access functions:
QString | scheme() const |
void | setScheme(const QString &scheme) |
url : QUrl
This property holds the URL to download files from.
Access functions:
QUrl | url() const |
void | setUrl(const QUrl &url) |
Member Function Documentation
[explicit]
FileDownloader::FileDownloader(const QString &scheme, QObject *parent = 0)
Creates a file downloader with the scheme scheme and parent parent.
[virtual noexcept]
FileDownloader::~FileDownloader()
Destroys the file downloader.
[protected]
void FileDownloader::addCheckSumData(const QByteArray &data)
Adds checksum data.
[protected]
void FileDownloader::addSample(qint64 sample)
Adds sample to the current speed bin.
QByteArray FileDownloader::assumedSha1Sum() const
Returns the assumed SHA-1 checksum of the file to download.
See also setAssumedSha1Sum().
QAuthenticator FileDownloader::authenticator() const
Returns a copy of the authenticator that this FileDownloader object is using to set the username and password for a download request.
See also setAuthenticator().
[signal]
void FileDownloader::authenticatorChanged(const QAuthenticator &authenticator)
This signal is emitted when the authenticator changes to authenticator.
[protected]
qint64 FileDownloader::bytesDownloadedBeforeResume()
Gets the amount of bytes downloaded before download resume.
[pure virtual]
bool FileDownloader::canDownload() const
Returns true
if the file exists and is readable.
[virtual slot]
void FileDownloader::cancelDownload()
Cancels file download.
[protected]
void FileDownloader::clearBytesDownloadedBeforeResume()
Clears the amount of bytes downloaded before download resume.
[pure virtual]
KDUpdater::FileDownloader *FileDownloader::clone(QObject *parent = 0) const
Clones the local file downloader and assigns it the parent parent.
void FileDownloader::download()
Downloads files.
[signal]
void FileDownloader::downloadAborted(const QString &errorMessage)
This signal is emitted when downloading a file is aborted with errorMessage.
See also setDownloadAborted().
[signal]
void FileDownloader::downloadCanceled()
This signal is emitted if downloading a file is canceled.
See also setDownloadCanceled().
[signal]
void FileDownloader::downloadCompleted()
This signal is emitted when downloading a file ends.
See also setDownloadCompleted().
[protected]
int FileDownloader::downloadDeadlineTimerId() const
Returns the download deadline timer ID.
[signal]
void FileDownloader::downloadProgress(double progress)
This signal is emitted with the current download progress.
Note: Signal downloadProgress is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:
connect(fileDownloader, QOverload<double>::of(&FileDownloader::downloadProgress), [=](double progress){ /* ... */ });
[signal]
void FileDownloader::downloadProgress(qint64 bytesReceived, qint64 bytesToReceive)
This signal is emitted with the download progress as the number of received bytes, bytesReceived, and the total size of the file to download, bytesToReceive.
Note: Signal downloadProgress is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:
connect(fileDownloader, QOverload<qint64, qint64>::of(&FileDownloader::downloadProgress), [=](qint64 bytesReceived, qint64 bytesToReceive){ /* ... */ });
[signal]
void FileDownloader::downloadSpeed(qint64 bytesPerSecond)
This signal is emitted with the download speed in bytes per second as bytesPerSecond.
[protected]
int FileDownloader::downloadSpeedTimerId() const
Returns the download speed timer ID.
[signal]
void FileDownloader::downloadStarted()
This signal is emitted when downloading a file starts.
[signal]
void FileDownloader::downloadStatus(const QString &status)
This signal is emitted with textual representation of the current download status in the following format: "100 MiB of 150 MiB - (DAYS) (HOURS) (MINUTES) (SECONDS) remaining".
[pure virtual]
QString FileDownloader::downloadedFileName() const
Returns the file name of the downloaded file.
See also setDownloadedFileName().
[protected]
void FileDownloader::emitDownloadProgress()
Emits dowload progress.
[protected]
void FileDownloader::emitDownloadSpeed()
Calculates the download speed in bytes per second and emits the downloadSpeed() signal.
[protected]
void FileDownloader::emitDownloadStatus()
Builds a textual representation of the download status in the following format: "100 MiB of 150 MiB - (DAYS) (HOURS) (MINUTES) (SECONDS) remaining".
Emits the downloadStatus() signal.
[protected]
void FileDownloader::emitEstimatedDownloadTime()
Emits the estimated download time.
QString FileDownloader::errorString() const
Returns an error message.
[signal]
void FileDownloader::estimatedDownloadTime(int seconds)
This signal is emitted with the estimated download time in seconds.
bool FileDownloader::followRedirects() const
Returns whether redirects should be followed.
See also setFollowRedirects().
qint64 FileDownloader::getBytesReceived() const
Returns the number of received bytes.
bool FileDownloader::ignoreSslErrors()
Returns true
if SSL errors should be ignored.
See also setIgnoreSslErrors().
[protected]
bool FileDownloader::isDownloadPaused()
Returns the download paused state.
[protected]
bool FileDownloader::isDownloadResumed()
Returns the download resumed state.
[pure virtual]
bool FileDownloader::isDownloaded() const
Returns true
if the file is downloaded.
[pure virtual protected]
void FileDownloader::onError()
Closes the destination file if an error occurs during copying and stops the download speed timer.
[pure virtual protected]
void FileDownloader::onSuccess()
Closes the destination file after it has been successfully copied and stops the download speed timer.
KDUpdater::FileDownloaderProxyFactory *FileDownloader::proxyFactory() const
Returns a copy of the proxy factory that this FileDownloader object is using to determine the proxies to be used for requests.
See also setProxyFactory().
[protected]
void FileDownloader::resetCheckSumData()
Resets SHA-1 checksum data of the downloaded file.
[protected]
void FileDownloader::runDownloadDeadlineTimer()
Restarts the download deadline timer.
[protected]
void FileDownloader::runDownloadSpeedTimer()
Starts the download speed timer.
void FileDownloader::setAssumedSha1Sum(const QByteArray &sum)
Sets the assumed SHA-1 checksum of the file to download to sum.
See also assumedSha1Sum().
void FileDownloader::setAuthenticator(const QAuthenticator &authenticator)
Sets the authenticator object for this class to be authenticator. An authenticator is used to pass on the required authentication information. This might only be of use for HTTP or FTP requests. Emits the authenticator changed signal with the new authenticator in use.
See also authenticator().
[protected]
void FileDownloader::setDownloadAborted(const QString &error)
Sets the human readable description of the last error that occurred to error. Emits the downloadStatus() and downloadAborted() signals.
See also downloadAborted().
[protected]
void FileDownloader::setDownloadCanceled()
Emits the downloadCanceled() and downloadStatus() signals.
See also downloadCanceled().
[protected]
void FileDownloader::setDownloadCompleted()
Sets the download status to completed
and displays a status message.
If an assumed SHA-1 checksum is set and the actual calculated checksum does not match it, sets the status to error
. If no SHA-1 is assumed, no check is performed, and status is set to success
.
Emits the downloadCompleted() and downloadStatus() signals on success.
See also downloadCompleted().
[protected]
void FileDownloader::setDownloadPaused(bool paused)
Sets the download into a paused state.
See also isDownloadPaused().
[protected]
void FileDownloader::setDownloadResumed(bool resumed)
Sets the download into a resumed state.
See also isDownloadResumed().
[pure virtual]
void FileDownloader::setDownloadedFileName(const QString &name)
Sets the file name of the downloaded file to name.
See also downloadedFileName().
void FileDownloader::setFollowRedirects(bool val)
Determines that redirects should be followed if val is true
.
See also followRedirects().
void FileDownloader::setIgnoreSslErrors(bool ignore)
Determines that SSL errors should be ignored if ignore is true
.
See also ignoreSslErrors().
[protected]
void FileDownloader::setProgress(qint64 bytesReceived, qint64 bytesToReceive)
Sets the file download progress to the number of received bytes, bytesReceived, and the number of total bytes to receive, bytesToReceive.
void FileDownloader::setProxyFactory(KDUpdater::FileDownloaderProxyFactory *factory)
Sets the proxy factory for this class to be factory. A proxy factory is used to determine a more specific list of proxies to be used for a given request, instead of trying to use the same proxy value for all requests. This might only be of use for HTTP or FTP requests.
See also proxyFactory().
QByteArray FileDownloader::sha1Sum() const
Returns the SHA-1 checksum of the downloaded file.
[protected]
void FileDownloader::stopDownloadDeadlineTimer()
Stops the download deadline timer.
[protected]
void FileDownloader::stopDownloadSpeedTimer()
Stops the download speed timer.
[protected]
qint64 FileDownloader::totalBytesDownloadedBeforeResume()
Gets the total amount of bytes downloaded before download resume.
[protected]
void FileDownloader::updateBytesDownloadedBeforeResume(qint64 bytes)
Updates the amount of bytes downloaded before download resumes.
[protected]
void FileDownloader::updateTotalBytesDownloadedBeforeResume()
Updates the total amount of bytes downloaded before download resume.
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. The Qt Company, Qt and their respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.