|
QGroundControl
Ground Control Station for MAVLink Drones
|
Cached file download with time-based expiration. More...
#include <QGCCachedFileDownload.h>
Inheritance diagram for QGCCachedFileDownload:
Collaboration diagram for QGCCachedFileDownload:Public Slots | |
| bool | download (const QString &url, int maxCacheAgeSec) |
| bool | downloadPreferCache (const QString &url) |
| bool | downloadNoCache (const QString &url) |
| void | cancel () |
| Cancel current download. | |
| void | clearCache () |
| Clear all cached files. | |
| bool | removeFromCache (const QString &url) |
Signals | |
| void | progressChanged (qreal progress) |
| Emitted when download progress changes. | |
| void | runningChanged (bool running) |
| Emitted when running state changes. | |
| void | errorStringChanged (const QString &errorString) |
| Emitted when error string changes. | |
| void | urlChanged (const QUrl &url) |
| Emitted when URL changes. | |
| void | localPathChanged (const QString &localPath) |
| Emitted when local path changes. | |
| void | fromCacheChanged (bool fromCache) |
| Emitted when fromCache state changes. | |
| void | cacheDirectoryChanged (const QString &directory) |
| Emitted when cache directory changes. | |
| void | maxCacheSizeChanged (qint64 bytes) |
| Emitted when max cache size changes. | |
| void | cacheSizeChanged (qint64 bytes) |
| Emitted when cache size changes. | |
| void | finished (bool success, const QString &localPath, const QString &errorMessage, bool fromCache) |
| void | downloadProgress (qint64 bytesReceived, qint64 totalBytes) |
| Emitted during download with byte counts. | |
Public Member Functions | |
| QGCCachedFileDownload (const QString &cacheDirectory, QObject *parent=nullptr) | |
| Current download progress (0.0 to 1.0) | |
| QGCCachedFileDownload (QObject *parent=nullptr) | |
| Construct without cache directory (must call setCacheDirectory before use) | |
| ~QGCCachedFileDownload () override | |
| qreal | progress () const |
| bool | isRunning () const |
| QString | errorString () const |
| QUrl | url () const |
| QString | localPath () const |
| bool | isFromCache () const |
| QString | cacheDirectory () const |
| qint64 | maxCacheSize () const |
| qint64 | cacheSize () const |
| void | setCacheDirectory (const QString &directory) |
| void | setMaxCacheSize (qint64 bytes) |
| Q_INVOKABLE bool | isCached (const QString &url, int maxAgeSec=0) const |
| Q_INVOKABLE QString | cachedPath (const QString &url) const |
| Q_INVOKABLE int | cacheAge (const QString &url) const |
| QGCFileDownload * | fileDownloader () const |
| Get the underlying file downloader (for advanced configuration) | |
| QNetworkDiskCache * | diskCache () const |
| Get the disk cache (for advanced configuration) | |
Cached file download with time-based expiration.
Features:
Cache behavior:
Example C++ usage:
Example QML usage:
Definition at line 53 of file QGCCachedFileDownload.h.
|
explicit |
Current download progress (0.0 to 1.0)
Whether a download is currently in progress Error message from last failed download URL being downloaded Local file path (cached or downloaded) Whether the last result came from cache Cache directory path Maximum cache size in bytes (0 = unlimited) Current cache size in bytes Construct with cache directory
| cacheDirectory | Directory to store cached files |
| parent | Parent object |
Definition at line 18 of file QGCCachedFileDownload.cc.
References QGCFileDownload::downloadProgress(), and QGCFileDownload::finished().
|
explicit |
Construct without cache directory (must call setCacheDirectory before use)
Definition at line 33 of file QGCCachedFileDownload.cc.
References QGCFileDownload::downloadProgress(), and QGCFileDownload::finished().
|
override |
Definition at line 46 of file QGCCachedFileDownload.cc.
| int QGCCachedFileDownload::cacheAge | ( | const QString & | url | ) | const |
Get cache entry age in seconds (-1 if not cached)
| url | URL to look up |
Definition at line 133 of file QGCCachedFileDownload.cc.
References url().
| QString QGCCachedFileDownload::cacheDirectory | ( | ) | const |
Definition at line 55 of file QGCCachedFileDownload.cc.
Referenced by download(), downloadPreferCache(), and setCacheDirectory().
|
signal |
Emitted when cache directory changes.
Referenced by setCacheDirectory().
| QString QGCCachedFileDownload::cachedPath | ( | const QString & | url | ) | const |
Get the cached file path for a URL (empty if not cached)
| url | URL to look up |
Definition at line 109 of file QGCCachedFileDownload.cc.
References QGCFileHelper::atomicWrite(), QGCFileHelper::uniqueTempPath(), and url().
| qint64 QGCCachedFileDownload::cacheSize | ( | ) | const |
Definition at line 81 of file QGCCachedFileDownload.cc.
Referenced by removeFromCache().
|
signal |
Emitted when cache size changes.
Referenced by clearCache(), and removeFromCache().
|
slot |
Cancel current download.
Definition at line 260 of file QGCCachedFileDownload.cc.
References QGCFileDownload::cancel().
|
slot |
Clear all cached files.
Definition at line 283 of file QGCCachedFileDownload.cc.
References cacheSizeChanged().
|
inline |
Get the disk cache (for advanced configuration)
Definition at line 134 of file QGCCachedFileDownload.h.
|
slot |
Download a file with cache support
| url | URL to download |
| maxCacheAgeSec | Maximum cache age in seconds (0 = any age is valid) |
Definition at line 147 of file QGCCachedFileDownload.cc.
References cacheDirectory(), url(), and urlChanged().
Referenced by ComponentInformationTranslation::downloadAndTranslate().
|
slot |
Download a file, bypassing cache entirely
| url | URL to download |
Definition at line 235 of file QGCCachedFileDownload.cc.
References url(), and urlChanged().
|
slot |
Download a file, always using cache if available (no expiration check)
| url | URL to download |
Definition at line 204 of file QGCCachedFileDownload.cc.
References cacheDirectory(), url(), and urlChanged().
|
signal |
Emitted during download with byte counts.
|
inline |
Definition at line 101 of file QGCCachedFileDownload.h.
|
signal |
Emitted when error string changes.
|
inline |
Get the underlying file downloader (for advanced configuration)
Definition at line 131 of file QGCCachedFileDownload.h.
|
signal |
Emitted when download completes
| success | true if download succeeded |
| localPath | Path to downloaded/cached file |
| errorMessage | Error message (empty on success) |
| fromCache | true if result came from cache |
Referenced by ComponentInformationTranslation::downloadAndTranslate().
|
signal |
Emitted when fromCache state changes.
| bool QGCCachedFileDownload::isCached | ( | const QString & | url, |
| int | maxAgeSec = 0 |
||
| ) | const |
Check if a URL is cached and not expired
| url | URL to check |
| maxAgeSec | Maximum age in seconds (0 = any age is valid) |
Definition at line 90 of file QGCCachedFileDownload.cc.
References url().
|
inline |
Definition at line 104 of file QGCCachedFileDownload.h.
|
inline |
Definition at line 100 of file QGCCachedFileDownload.h.
|
inline |
Definition at line 103 of file QGCCachedFileDownload.h.
|
signal |
Emitted when local path changes.
| qint64 QGCCachedFileDownload::maxCacheSize | ( | ) | const |
Definition at line 68 of file QGCCachedFileDownload.cc.
Referenced by setMaxCacheSize().
|
signal |
Emitted when max cache size changes.
Referenced by setMaxCacheSize().
|
inline |
Definition at line 99 of file QGCCachedFileDownload.h.
|
signal |
Emitted when download progress changes.
|
slot |
Remove a specific URL from cache
| url | URL to remove |
Definition at line 290 of file QGCCachedFileDownload.cc.
References cacheSize(), cacheSizeChanged(), and url().
|
signal |
Emitted when running state changes.
| void QGCCachedFileDownload::setCacheDirectory | ( | const QString & | directory | ) |
Definition at line 60 of file QGCCachedFileDownload.cc.
References cacheDirectory(), and cacheDirectoryChanged().
| void QGCCachedFileDownload::setMaxCacheSize | ( | qint64 | bytes | ) |
Definition at line 73 of file QGCCachedFileDownload.cc.
References maxCacheSize(), and maxCacheSizeChanged().
|
inline |
Definition at line 102 of file QGCCachedFileDownload.h.
Referenced by cacheAge(), cachedPath(), download(), downloadNoCache(), downloadPreferCache(), isCached(), and removeFromCache().
|
signal |
Emitted when URL changes.
Referenced by download(), downloadNoCache(), and downloadPreferCache().