1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-25 20:25:54 +01:00
GPXSee/src/map/downloader.h

78 lines
1.6 KiB
C
Raw Normal View History

#ifndef DOWNLOADER_H
2015-11-23 02:33:01 +01:00
#define DOWNLOADER_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
2015-11-23 02:33:01 +01:00
#include <QUrl>
#include <QList>
2015-12-04 22:56:34 +01:00
#include <QSet>
#include <QHash>
2015-11-23 02:33:01 +01:00
2015-11-23 02:33:01 +01:00
class Download
{
public:
Download(const QUrl &url, const QString &file) : _url(url), _file(file) {}
2018-10-04 23:02:43 +02:00
const QUrl &url() const {return _url;}
const QString &file() const {return _file;}
2015-11-23 02:33:01 +01:00
private:
QUrl _url;
2015-11-23 02:33:01 +01:00
QString _file;
};
class Authorization
{
public:
Authorization() {}
Authorization(const QString &username, const QString &password);
const QByteArray &header() const {return _header;}
private:
QByteArray _header;
};
2015-11-23 02:33:01 +01:00
class Downloader : public QObject
{
Q_OBJECT
public:
Downloader(QObject *parent = 0) : QObject(parent) {}
bool get(const QList<Download> &list, const Authorization &authorization
= Authorization());
void clearErrors() {_errorDownloads.clear();}
2015-11-23 02:33:01 +01:00
2018-10-08 22:07:36 +02:00
static void setNetworkManager(QNetworkAccessManager *manager)
{_manager = manager;}
static void setTimeout(int timeout) {_timeout = timeout;}
2018-10-07 14:22:13 +02:00
static void enableHTTP2(bool enable);
2015-11-23 02:33:01 +01:00
signals:
void finished();
private slots:
void emitFinished();
2015-11-23 02:33:01 +01:00
void downloadFinished(QNetworkReply *reply);
private:
class Redirect;
class ReplyTimeout;
2017-01-16 21:45:27 +01:00
void insertError(const QUrl &url, QNetworkReply::NetworkError error);
bool doDownload(const Download &dl, const QByteArray &authorization,
const Redirect *redirect = 0);
2015-11-23 02:33:01 +01:00
bool saveToDisk(const QString &filename, QIODevice *data);
QSet<QUrl> _currentDownloads;
QHash<QUrl, int> _errorDownloads;
2018-10-08 22:07:36 +02:00
static QNetworkAccessManager *_manager;
static int _timeout;
2018-07-23 23:53:58 +02:00
static bool _http2;
2015-11-23 02:33:01 +01:00
};
#endif // DOWNLOADER_H