6#include <QtCore/QDateTime>
7#include <QtCore/QObject>
8#include <QtCore/QString>
12class QNetworkDiskCache;
102 QUrl
url()
const {
return _url; }
117 Q_INVOKABLE
bool isCached(
const QString &
url,
int maxAgeSec = 0)
const;
128 Q_INVOKABLE
int cacheAge(
const QString &
url)
const;
134 QNetworkDiskCache *
diskCache()
const {
return _diskCache; }
141 bool download(
const QString &
url,
int maxCacheAgeSec);
198 const QString &errorMessage,
bool fromCache);
204 void _onDownloadFinished(
bool success,
const QString &
localPath,
const QString &errorMessage);
205 void _onDownloadProgress(qint64 bytesReceived, qint64 totalBytes);
208 void _initializeCache(
const QString &directory);
209 void _setRunning(
bool running);
211 void _setErrorString(
const QString &
error);
212 void _setFromCache(
bool fromCache);
213 void _updateCacheTimestamp(
const QString &
url);
214 QDateTime _getCacheTimestamp(
const QString &
url)
const;
215 bool _startDownload(
const QString &
url,
bool forceNetwork,
bool preferCache);
216 void _emitFinished(
bool success,
const QString &path,
const QString &
error);
219 QNetworkDiskCache *_diskCache =
nullptr;
223 QString _errorString;
226 qreal _progress = 0.0;
227 int _maxCacheAgeSec = 0;
228 bool _running =
false;
229 bool _fromCache =
false;
230 bool _networkAttemptFailed =
false;
231 bool _forceNetwork =
false;
232 bool _cancelRequested =
false;
Cached file download with time-based expiration.
void maxCacheSizeChanged(qint64 bytes)
Emitted when max cache size changes.
QString errorString() const
bool downloadPreferCache(const QString &url)
void urlChanged(const QUrl &url)
Emitted when URL changes.
Q_INVOKABLE bool isCached(const QString &url, int maxAgeSec=0) const
void cancel()
Cancel current download.
bool removeFromCache(const QString &url)
void downloadProgress(qint64 bytesReceived, qint64 totalBytes)
Emitted during download with byte counts.
void localPathChanged(const QString &localPath)
Emitted when local path changes.
~QGCCachedFileDownload() override
Q_INVOKABLE QString cachedPath(const QString &url) const
void setCacheDirectory(const QString &directory)
void cacheDirectoryChanged(const QString &directory)
Emitted when cache directory changes.
void cacheSizeChanged(qint64 bytes)
Emitted when cache size changes.
void progressChanged(qreal progress)
Emitted when download progress changes.
void clearCache()
Clear all cached files.
QNetworkDiskCache * diskCache() const
Get the disk cache (for advanced configuration)
void errorStringChanged(const QString &errorString)
Emitted when error string changes.
bool downloadNoCache(const QString &url)
bool download(const QString &url, int maxCacheAgeSec)
QString cacheDirectory() const
void setMaxCacheSize(qint64 bytes)
QString localPath() const
QGCFileDownload * fileDownloader() const
Get the underlying file downloader (for advanced configuration)
qint64 maxCacheSize() const
void runningChanged(bool running)
Emitted when running state changes.
Q_INVOKABLE int cacheAge(const QString &url) const
void finished(bool success, const QString &localPath, const QString &errorMessage, bool fromCache)
void fromCacheChanged(bool fromCache)
Emitted when fromCache state changes.
File download with progress, decompression, and hash verification.