1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Cosmetics

This commit is contained in:
Martin Tůma 2018-10-04 23:02:43 +02:00
parent 06901d8d7a
commit ed4e201b08
3 changed files with 29 additions and 26 deletions

View File

@ -89,9 +89,10 @@ bool Downloader::_http2 = true;
bool Downloader::doDownload(const Download &dl,
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()));
if (redirect)
_errorDownloads.insert(redirect->origin(), RETRIES);
@ -161,11 +162,11 @@ void Downloader::insertError(const QUrl &url, QNetworkReply::NetworkError error)
void Downloader::downloadFinished(QNetworkReply *reply)
{
QUrl url = reply->request().url();
QUrl url(reply->request().url());
QNetworkReply::NetworkError error = reply->error();
if (error) {
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl());
if (origin.isEmpty()) {
insertError(url, error);
qWarning("Error downloading file: %s: %s",
@ -177,12 +178,11 @@ void Downloader::downloadFinished(QNetworkReply *reply)
qPrintable(reply->errorString()));
}
} else {
QUrl location = reply->attribute(ATTR_REDIRECT).toUrl();
QString filename = reply->request().attribute(ATTR_FILE)
.toString();
QUrl location(reply->attribute(ATTR_REDIRECT).toUrl());
QString filename(reply->request().attribute(ATTR_FILE).toString());
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();
if (level >= MAX_REDIRECT_LEVEL) {

View File

@ -15,8 +15,8 @@ class Download
public:
Download(const QUrl &url, const QString &file) : _url(url), _file(file) {}
const QUrl& url() const {return _url;}
const QString& file() const {return _file;}
const QUrl &url() const {return _url;}
const QString &file() const {return _file;}
private:
QUrl _url;

View File

@ -32,14 +32,16 @@ void TileLoader::loadTilesAsync(QList<Tile> &list)
Tile &t = list[i];
QString file(tileFile(t));
QFileInfo fi(file);
QUrl url(tileUrl(t));
if (url.isLocalFile())
loadTileFile(t, url.toLocalFile());
else if (fi.exists())
if (fi.exists())
loadTileFile(t, file);
else
dl.append(Download(url, file));
else {
QUrl url(tileUrl(t));
if (url.isLocalFile())
loadTileFile(t, url.toLocalFile());
else
dl.append(Download(url, file));
}
}
if (!dl.empty())
@ -54,14 +56,16 @@ void TileLoader::loadTilesSync(QList<Tile> &list)
Tile &t = list[i];
QString file(tileFile(t));
QFileInfo fi(file);
QUrl url(tileUrl(t));
if (url.isLocalFile())
loadTileFile(t, url.toLocalFile());
else if (fi.exists())
if (fi.exists())
loadTileFile(t, file);
else
dl.append(Download(url, file));
else {
QUrl url(tileUrl(t));
if (url.isLocalFile())
loadTileFile(t, url.toLocalFile());
else
dl.append(Download(url, file));
}
}
if (dl.empty())
@ -116,8 +120,7 @@ QUrl TileLoader::tileUrl(const Tile &tile) const
QString TileLoader::tileFile(const Tile &tile) const
{
QString file = _dir + QString("/%1-%2-%3").arg(tile.zoom().toString())
.arg(tile.xy().x()).arg(tile.xy().y());
return file;
return _dir + QLatin1Char('/') + tile.zoom().toString() + QLatin1Char('-')
+ QString::number(tile.xy().x()) + QLatin1Char('-')
+ QString::number(tile.xy().y());
}