6#include <QtCore/QDateTime>
7#include <QtCore/QLoggingCategory>
8#include <QtCore/QObject>
9#include <QtCore/QString>
13class QNetworkDiskCache;
61 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged FINAL)
64 Q_PROPERTY(
bool running READ isRunning NOTIFY runningChanged FINAL)
70 Q_PROPERTY(QUrl url READ url NOTIFY urlChanged FINAL)
73 Q_PROPERTY(QString localPath READ localPath NOTIFY localPathChanged FINAL)
76 Q_PROPERTY(
bool fromCache READ isFromCache NOTIFY fromCacheChanged FINAL)
79 Q_PROPERTY(QString cacheDirectory READ cacheDirectory WRITE setCacheDirectory
80 NOTIFY cacheDirectoryChanged FINAL)
83 Q_PROPERTY(qint64 maxCacheSize READ maxCacheSize WRITE setMaxCacheSize
84 NOTIFY maxCacheSizeChanged FINAL)
87 Q_PROPERTY(qint64 cacheSize READ cacheSize NOTIFY cacheSizeChanged FINAL)
101 qreal progress()
const {
return _progress; }
102 bool isRunning()
const {
return _running; }
103 QString
errorString()
const {
return _errorString; }
104 QUrl url()
const {
return _url; }
105 QString localPath()
const {
return _localPath; }
106 bool isFromCache()
const {
return _fromCache; }
107 QString cacheDirectory()
const;
108 qint64 maxCacheSize()
const;
109 qint64 cacheSize()
const;
112 void setCacheDirectory(
const QString &directory);
113 void setMaxCacheSize(qint64 bytes);
119 Q_INVOKABLE
bool isCached(
const QString &url,
int maxAgeSec = 0)
const;
125 Q_INVOKABLE QString cachedPath(
const QString &url)
const;
130 Q_INVOKABLE
int cacheAge(
const QString &url)
const;
136 QNetworkDiskCache *diskCache()
const {
return _diskCache; }
143 bool download(
const QString &url,
int maxCacheAgeSec);
148 bool downloadPreferCache(
const QString &url);
153 bool downloadNoCache(
const QString &url);
164 bool removeFromCache(
const QString &url);
199 void finished(
bool success,
const QString &localPath,
200 const QString &errorMessage,
bool fromCache);
206 void _onDownloadFinished(
bool success,
const QString &localPath,
const QString &errorMessage);
207 void _onDownloadProgress(qint64 bytesReceived, qint64 totalBytes);
210 void _initializeCache(
const QString &directory);
211 void _setRunning(
bool running);
212 void _setProgress(qreal progress);
213 void _setErrorString(
const QString &
error);
214 void _setFromCache(
bool fromCache);
215 void _updateCacheTimestamp(
const QString &url);
216 QDateTime _getCacheTimestamp(
const QString &url)
const;
217 bool _startDownload(
const QString &url,
bool forceNetwork,
bool preferCache);
218 void _emitFinished(
bool success,
const QString &path,
const QString &
error);
221 QNetworkDiskCache *_diskCache =
nullptr;
225 QString _errorString;
228 qreal _progress = 0.0;
229 int _maxCacheAgeSec = 0;
230 bool _running =
false;
231 bool _fromCache =
false;
232 bool _networkAttemptFailed =
false;
233 bool _forceNetwork =
false;
234 bool _cancelRequested =
false;
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
void maxCacheSizeChanged(qint64 bytes)
Emitted when max cache size changes.
void urlChanged(const QUrl &url)
Emitted when URL changes.
void downloadProgress(qint64 bytesReceived, qint64 totalBytes)
Emitted during download with byte counts.
void localPathChanged(const QString &localPath)
Emitted when local path changes.
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 errorStringChanged(const QString &errorString)
Emitted when error string changes.
void runningChanged(bool running)
Emitted when running state changes.
void finished(bool success, const QString &localPath, const QString &errorMessage, bool fromCache)
void fromCacheChanged(bool fromCache)
Emitted when fromCache state changes.