mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-30 22:51:16 +01:00
Cosmetics
This commit is contained in:
parent
06901d8d7a
commit
ed4e201b08
@ -89,9 +89,10 @@ bool Downloader::_http2 = true;
|
|||||||
bool Downloader::doDownload(const Download &dl,
|
bool Downloader::doDownload(const Download &dl,
|
||||||
const QByteArray &authorization, const Redirect *redirect)
|
const QByteArray &authorization, const Redirect *redirect)
|
||||||
{
|
{
|
||||||
QUrl url(dl.url());
|
const QUrl &url = dl.url();
|
||||||
|
|
||||||
if (!url.isValid() || !(url.scheme() == "http" || url.scheme() == "https")) {
|
if (!url.isValid() || !(url.scheme() == QLatin1String("http")
|
||||||
|
|| url.scheme() == QLatin1String("https"))) {
|
||||||
qWarning("%s: Invalid URL", qPrintable(url.toString()));
|
qWarning("%s: Invalid URL", qPrintable(url.toString()));
|
||||||
if (redirect)
|
if (redirect)
|
||||||
_errorDownloads.insert(redirect->origin(), RETRIES);
|
_errorDownloads.insert(redirect->origin(), RETRIES);
|
||||||
@ -161,11 +162,11 @@ void Downloader::insertError(const QUrl &url, QNetworkReply::NetworkError error)
|
|||||||
|
|
||||||
void Downloader::downloadFinished(QNetworkReply *reply)
|
void Downloader::downloadFinished(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
QUrl url = reply->request().url();
|
QUrl url(reply->request().url());
|
||||||
QNetworkReply::NetworkError error = reply->error();
|
QNetworkReply::NetworkError error = reply->error();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl());
|
||||||
if (origin.isEmpty()) {
|
if (origin.isEmpty()) {
|
||||||
insertError(url, error);
|
insertError(url, error);
|
||||||
qWarning("Error downloading file: %s: %s",
|
qWarning("Error downloading file: %s: %s",
|
||||||
@ -177,12 +178,11 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
qPrintable(reply->errorString()));
|
qPrintable(reply->errorString()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QUrl location = reply->attribute(ATTR_REDIRECT).toUrl();
|
QUrl location(reply->attribute(ATTR_REDIRECT).toUrl());
|
||||||
QString filename = reply->request().attribute(ATTR_FILE)
|
QString filename(reply->request().attribute(ATTR_FILE).toString());
|
||||||
.toString();
|
|
||||||
|
|
||||||
if (!location.isEmpty()) {
|
if (!location.isEmpty()) {
|
||||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl());
|
||||||
int level = reply->request().attribute(ATTR_LEVEL).toInt();
|
int level = reply->request().attribute(ATTR_LEVEL).toInt();
|
||||||
|
|
||||||
if (level >= MAX_REDIRECT_LEVEL) {
|
if (level >= MAX_REDIRECT_LEVEL) {
|
||||||
|
@ -15,8 +15,8 @@ class Download
|
|||||||
public:
|
public:
|
||||||
Download(const QUrl &url, const QString &file) : _url(url), _file(file) {}
|
Download(const QUrl &url, const QString &file) : _url(url), _file(file) {}
|
||||||
|
|
||||||
const QUrl& url() const {return _url;}
|
const QUrl &url() const {return _url;}
|
||||||
const QString& file() const {return _file;}
|
const QString &file() const {return _file;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
|
@ -32,15 +32,17 @@ void TileLoader::loadTilesAsync(QList<Tile> &list)
|
|||||||
Tile &t = list[i];
|
Tile &t = list[i];
|
||||||
QString file(tileFile(t));
|
QString file(tileFile(t));
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
QUrl url(tileUrl(t));
|
|
||||||
|
|
||||||
|
if (fi.exists())
|
||||||
|
loadTileFile(t, file);
|
||||||
|
else {
|
||||||
|
QUrl url(tileUrl(t));
|
||||||
if (url.isLocalFile())
|
if (url.isLocalFile())
|
||||||
loadTileFile(t, url.toLocalFile());
|
loadTileFile(t, url.toLocalFile());
|
||||||
else if (fi.exists())
|
|
||||||
loadTileFile(t, file);
|
|
||||||
else
|
else
|
||||||
dl.append(Download(url, file));
|
dl.append(Download(url, file));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!dl.empty())
|
if (!dl.empty())
|
||||||
_downloader->get(dl, _authorization);
|
_downloader->get(dl, _authorization);
|
||||||
@ -54,15 +56,17 @@ void TileLoader::loadTilesSync(QList<Tile> &list)
|
|||||||
Tile &t = list[i];
|
Tile &t = list[i];
|
||||||
QString file(tileFile(t));
|
QString file(tileFile(t));
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
QUrl url(tileUrl(t));
|
|
||||||
|
|
||||||
|
if (fi.exists())
|
||||||
|
loadTileFile(t, file);
|
||||||
|
else {
|
||||||
|
QUrl url(tileUrl(t));
|
||||||
if (url.isLocalFile())
|
if (url.isLocalFile())
|
||||||
loadTileFile(t, url.toLocalFile());
|
loadTileFile(t, url.toLocalFile());
|
||||||
else if (fi.exists())
|
|
||||||
loadTileFile(t, file);
|
|
||||||
else
|
else
|
||||||
dl.append(Download(url, file));
|
dl.append(Download(url, file));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (dl.empty())
|
if (dl.empty())
|
||||||
return;
|
return;
|
||||||
@ -116,8 +120,7 @@ QUrl TileLoader::tileUrl(const Tile &tile) const
|
|||||||
|
|
||||||
QString TileLoader::tileFile(const Tile &tile) const
|
QString TileLoader::tileFile(const Tile &tile) const
|
||||||
{
|
{
|
||||||
QString file = _dir + QString("/%1-%2-%3").arg(tile.zoom().toString())
|
return _dir + QLatin1Char('/') + tile.zoom().toString() + QLatin1Char('-')
|
||||||
.arg(tile.xy().x()).arg(tile.xy().y());
|
+ QString::number(tile.xy().x()) + QLatin1Char('-')
|
||||||
|
+ QString::number(tile.xy().y());
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user