1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/map/downloader.h

83 lines
1.7 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>
#include "config.h"
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-07-23 23:53:58 +02:00
#ifdef ENABLE_HTTP2
2018-10-07 14:22:13 +02:00
static void enableHTTP2(bool enable);
2018-07-23 23:53:58 +02:00
#endif // ENABLE_HTTP2
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
#ifdef ENABLE_HTTP2
static bool _http2;
#endif // ENABLE_HTTP2
2015-11-23 02:33:01 +01:00
};
#endif // DOWNLOADER_H