1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-19 04:02:09 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2018-10-07 17:30:48 +02:00
parent f9af06267a
commit 24c03fc15b
3 changed files with 10 additions and 7 deletions

View File

@ -38,7 +38,6 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
#endif // Q_OS_MAC #endif // Q_OS_MAC
QNetworkProxyFactory::setUseSystemConfiguration(true); QNetworkProxyFactory::setUseSystemConfiguration(true);
Downloader::setNetworkAccessManager(new QNetworkAccessManager(this));
QSettings settings(APP_NAME, APP_NAME); QSettings settings(APP_NAME, APP_NAME);
settings.beginGroup(OPTIONS_SETTINGS_GROUP); settings.beginGroup(OPTIONS_SETTINGS_GROUP);
#ifdef ENABLE_HTTP2 #ifdef ENABLE_HTTP2

View File

@ -80,12 +80,17 @@ private:
}; };
QNetworkAccessManager *Downloader::_manager = 0;
int Downloader::_timeout = 30; int Downloader::_timeout = 30;
#ifdef ENABLE_HTTP2 #ifdef ENABLE_HTTP2
bool Downloader::_http2 = true; bool Downloader::_http2 = true;
#endif // ENABLE_HTTP2 #endif // ENABLE_HTTP2
QNetworkAccessManager *Downloader::manager()
{
static QNetworkAccessManager manager;
return &manager;
}
bool Downloader::doDownload(const Download &dl, bool Downloader::doDownload(const Download &dl,
const QByteArray &authorization, const Redirect *redirect) const QByteArray &authorization, const Redirect *redirect)
{ {
@ -118,7 +123,7 @@ bool Downloader::doDownload(const Download &dl,
QVariant(_http2)); QVariant(_http2));
#endif // ENABLE_HTTP2 #endif // ENABLE_HTTP2
QNetworkReply *reply = _manager->get(request); QNetworkReply *reply = manager()->get(request);
if (reply && reply->isRunning()) { if (reply && reply->isRunning()) {
_currentDownloads.insert(url); _currentDownloads.insert(url);
ReplyTimeout::setTimeout(reply, _timeout); ReplyTimeout::setTimeout(reply, _timeout);
@ -232,6 +237,6 @@ bool Downloader::get(const QList<Download> &list,
void Downloader::enableHTTP2(bool enable) void Downloader::enableHTTP2(bool enable)
{ {
_http2 = enable; _http2 = enable;
_manager->clearConnectionCache(); manager()->clearConnectionCache();
} }
#endif // ENABLE_HTTP2 #endif // ENABLE_HTTP2

View File

@ -50,8 +50,6 @@ public:
#ifdef ENABLE_HTTP2 #ifdef ENABLE_HTTP2
static void enableHTTP2(bool enable); static void enableHTTP2(bool enable);
#endif // ENABLE_HTTP2 #endif // ENABLE_HTTP2
static void setNetworkAccessManager(QNetworkAccessManager *manager)
{_manager = manager;}
signals: signals:
void finished(); void finished();
@ -69,6 +67,8 @@ private:
const Redirect *redirect = 0); const Redirect *redirect = 0);
bool saveToDisk(const QString &filename, QIODevice *data); bool saveToDisk(const QString &filename, QIODevice *data);
static QNetworkAccessManager *manager();
QSet<QUrl> _currentDownloads; QSet<QUrl> _currentDownloads;
QHash<QUrl, int> _errorDownloads; QHash<QUrl, int> _errorDownloads;
@ -76,7 +76,6 @@ private:
#ifdef ENABLE_HTTP2 #ifdef ENABLE_HTTP2
static bool _http2; static bool _http2;
#endif // ENABLE_HTTP2 #endif // ENABLE_HTTP2
static QNetworkAccessManager *_manager;
}; };
#endif // DOWNLOADER_H #endif // DOWNLOADER_H