mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-31 09:05:14 +01:00
Never change a winning team!
This commit is contained in:
parent
0e4a5abc2b
commit
e568806366
@ -40,6 +40,11 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
QSettings settings(APP_NAME, APP_NAME);
|
||||
settings.beginGroup(OPTIONS_SETTINGS_GROUP);
|
||||
|
||||
/* The QNetworkAccessManager must be a child of QApplication, otherwise it
|
||||
triggers the following warning on exit (and may probably crash):
|
||||
"QThreadStorage: Thread X exited after QThreadStorage Y destroyed" */
|
||||
Downloader::setNetworkManager(new QNetworkAccessManager(this));
|
||||
#ifdef ENABLE_HTTP2
|
||||
Downloader::enableHTTP2(settings.value(ENABLE_HTTP2_SETTING,
|
||||
ENABLE_HTTP2_DEFAULT).toBool());
|
||||
|
@ -79,18 +79,12 @@ private:
|
||||
int _level;
|
||||
};
|
||||
|
||||
|
||||
QNetworkAccessManager *Downloader::_manager = 0;
|
||||
int Downloader::_timeout = 30;
|
||||
#ifdef ENABLE_HTTP2
|
||||
bool Downloader::_http2 = true;
|
||||
#endif // ENABLE_HTTP2
|
||||
|
||||
QNetworkAccessManager *Downloader::manager()
|
||||
{
|
||||
static QNetworkAccessManager manager;
|
||||
return &manager;
|
||||
}
|
||||
|
||||
bool Downloader::doDownload(const Download &dl,
|
||||
const QByteArray &authorization, const Redirect *redirect)
|
||||
{
|
||||
@ -123,7 +117,8 @@ bool Downloader::doDownload(const Download &dl,
|
||||
QVariant(_http2));
|
||||
#endif // ENABLE_HTTP2
|
||||
|
||||
QNetworkReply *reply = manager()->get(request);
|
||||
Q_ASSERT(_manager);
|
||||
QNetworkReply *reply = _manager->get(request);
|
||||
if (reply && reply->isRunning()) {
|
||||
_currentDownloads.insert(url);
|
||||
ReplyTimeout::setTimeout(reply, _timeout);
|
||||
@ -236,7 +231,8 @@ bool Downloader::get(const QList<Download> &list,
|
||||
#ifdef ENABLE_HTTP2
|
||||
void Downloader::enableHTTP2(bool enable)
|
||||
{
|
||||
Q_ASSERT(_manager);
|
||||
_http2 = enable;
|
||||
manager()->clearConnectionCache();
|
||||
_manager->clearConnectionCache();
|
||||
}
|
||||
#endif // ENABLE_HTTP2
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
= Authorization());
|
||||
void clearErrors() {_errorDownloads.clear();}
|
||||
|
||||
static void setNetworkManager(QNetworkAccessManager *manager)
|
||||
{_manager = manager;}
|
||||
static void setTimeout(int timeout) {_timeout = timeout;}
|
||||
#ifdef ENABLE_HTTP2
|
||||
static void enableHTTP2(bool enable);
|
||||
@ -67,11 +69,10 @@ private:
|
||||
const Redirect *redirect = 0);
|
||||
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||
|
||||
static QNetworkAccessManager *manager();
|
||||
|
||||
QSet<QUrl> _currentDownloads;
|
||||
QHash<QUrl, int> _errorDownloads;
|
||||
|
||||
static QNetworkAccessManager *_manager;
|
||||
static int _timeout;
|
||||
#ifdef ENABLE_HTTP2
|
||||
static bool _http2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user