1 #ifndef OSMSCOUT_CLIENT_QT_FILEDOWNLOADER_H 2 #define OSMSCOUT_CLIENT_QT_FILEDOWNLOADER_H 25 #include <QNetworkAccessManager> 26 #include <QNetworkReply> 42 namespace FileDownloaderConfig {
60 #ifdef OSMSCOUT_CLIENT_QT_FILEDOWNLOADER_TEST 67 int downloadRetries{0};
72 bool scheduleRestart();
78 QNetworkAccessManager *manager;
82 QNetworkReply *reply{
nullptr};
87 bool finishedSuccessfully{
false};
89 uint64_t downloaded{0};
97 QObject *parent =
nullptr);
100 operator bool()
const {
return isOk; }
101 QString
getFileName()
const {
return QFileInfo(path).fileName(); }
103 uint64_t getBytesDownloaded()
const;
106 void downloadedBytes(uint64_t sz);
107 void writtenBytes(uint64_t sz);
108 void finished(QString path);
109 void error(QString error_text,
bool recoverable);
112 void startDownload();
115 void onNetworkReadyRead();
117 void onNetworkError(QNetworkReply::NetworkError code);
122 void onError(
const QString &err);
124 bool restartDownload();
143 bool successful{
false};
144 bool canceledByUser{
false};
146 uint64_t downloadedBytes{0};
154 void failed(QString error);
156 void downloadProgress();
159 void onJobFailed(QString errorMessage,
bool recoverable);
160 void onJobFinished(QString path);
161 void onDownloadProgress(uint64_t);
162 void downloadNextFile();
165 DownloadJob(QNetworkAccessManager *webCtrl, QDir target,
bool replaceExisting);
174 void start(
const QString &serverBasePath,
const QStringList &files);
184 virtual uint64_t expectedSize()
const = 0;
198 return started && !done;
208 return replaceExisting;
216 double getProgress();
217 QString getDownloadingFile();
229 #endif // OSMSCOUT_CLIENT_QT_FILEDOWNLOADER_H bool isSuccessful() const
Definition: FileDownloader.h:191
QString getFileName() const
Definition: FileDownloader.h:101
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
Definition: FileDownloader.h:131
QString getFilePath() const
Definition: FileDownloader.h:102
Downloads a file specified by URL.
Definition: FileDownloader.h:56
QList< FileDownloader * > jobs
Definition: FileDownloader.h:136
bool replaceExisting
Definition: FileDownloader.h:150
bool isDone() const
Definition: FileDownloader.h:186
static constexpr int MaxDownloadRetries
Maximal number of download retries before cancelling download.
Definition: FileDownloader.h:48
static constexpr std::chrono::seconds BackOffMax
Maximum back-off time.
Definition: FileDownloader.h:47
bool isDownloading() const
Definition: FileDownloader.h:196
bool isReplaceExisting() const
Definition: FileDownloader.h:206
QNetworkAccessManager * webCtrl
Definition: FileDownloader.h:137
static constexpr std::chrono::seconds DownloadReadTimeout
Download read timeout in seconds.
Definition: FileDownloader.h:45
static constexpr uint64_t BufferNetwork
Size of network ring buffer.
Definition: FileDownloader.h:44
QString getError() const
Definition: FileDownloader.h:201
bool operator==(const MapView &a, const MapView &b)
Definition: InputHandler.h:222
QDir target
Definition: FileDownloader.h:139
QString error
Definition: FileDownloader.h:148
QDir getDestinationDirectory() const
Definition: FileDownloader.h:211
static constexpr std::chrono::seconds BackOffInitial
Initial back-off time.
Definition: FileDownloader.h:46