mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-04-21 12:49:10 +02:00
Compare commits
No commits in common. "c6a37594ae4f094e0bf6abfe031f16d90d9ec9c3" and "aed09a0e6a27caaa02de1bb99c6f4d1959a7c8c0" have entirely different histories.
c6a37594ae
...
aed09a0e6a
@ -1,4 +1,5 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QNetworkRequest>
|
||||
#include <QDir>
|
||||
#include <QTimerEvent>
|
||||
@ -55,7 +56,6 @@ Authorization::Authorization(const QString &username, const QString &password)
|
||||
_header = HTTPHeader("Authorization", "Basic " + data);
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||
NetworkTimeout::NetworkTimeout(int timeout, QNetworkReply *reply)
|
||||
: QObject(reply), _timeout(timeout)
|
||||
{
|
||||
@ -77,7 +77,6 @@ void NetworkTimeout::timerEvent(QTimerEvent *ev)
|
||||
reply->abort();
|
||||
_timer.stop();
|
||||
}
|
||||
#endif // QT 5.15
|
||||
|
||||
|
||||
QNetworkAccessManager *Downloader::_manager = 0;
|
||||
@ -105,15 +104,11 @@ bool Downloader::doDownload(const Download &dl, const QList<HTTPHeader> &headers
|
||||
request.setAttribute(ATTR_REDIRECT_POLICY,
|
||||
QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
request.setAttribute(ATTR_HTTP2_ALLOWED, QVariant(_http2));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
request.setTransferTimeout(_timeout * 1000);
|
||||
#endif // QT 5.15
|
||||
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
const HTTPHeader &hdr = headers.at(i);
|
||||
request.setRawHeader(hdr.key(), hdr.value());
|
||||
// QByteArray::compare() not available in Qt < 5.12
|
||||
if (!QString(hdr.key()).compare("User-Agent", Qt::CaseInsensitive))
|
||||
if (hdr.key() == "User-Agent")
|
||||
userAgent = true;
|
||||
}
|
||||
if (!userAgent)
|
||||
@ -133,9 +128,9 @@ bool Downloader::doDownload(const Download &dl, const QList<HTTPHeader> &headers
|
||||
_currentDownloads.insert(url, file);
|
||||
|
||||
if (reply->isRunning()) {
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||
/* Starting with Qt 5.15 this can be replaced by
|
||||
QNetworkRequest::setTransferTimeout() */
|
||||
new NetworkTimeout(_timeout, reply);
|
||||
#endif // QT 5.15
|
||||
connect(reply, &QIODevice::readyRead, this, &Downloader::emitReadReady);
|
||||
connect(reply, &QNetworkReply::finished, this, &Downloader::emitFinished);
|
||||
} else {
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||
#include <QBasicTimer>
|
||||
#endif // QT 5.15
|
||||
#include <QUrl>
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
@ -41,7 +39,6 @@ private:
|
||||
HTTPHeader _header;
|
||||
};
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||
class NetworkTimeout : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -58,7 +55,6 @@ private:
|
||||
QBasicTimer _timer;
|
||||
int _timeout;
|
||||
};
|
||||
#endif // QT 5.15
|
||||
|
||||
class Downloader : public QObject
|
||||
{
|
||||
@ -83,6 +79,8 @@ private slots:
|
||||
void emitReadReady();
|
||||
|
||||
private:
|
||||
class ReplyTimeout;
|
||||
|
||||
void insertError(const QUrl &url, QNetworkReply::NetworkError error);
|
||||
bool doDownload(const Download &dl, const QList<HTTPHeader> &headers);
|
||||
void downloadFinished(QNetworkReply *reply);
|
||||
|
Loading…
x
Reference in New Issue
Block a user