mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Compare commits
3 Commits
8b391fc871
...
1186cb104b
Author | SHA1 | Date | |
---|---|---|---|
1186cb104b | |||
8b51f3ff04 | |||
ee0c49db9d |
@ -37,6 +37,80 @@
|
|||||||
|
|
||||||
#define TMP_SUFFIX ".download"
|
#define TMP_SUFFIX ".download"
|
||||||
|
|
||||||
|
// QNetworkReply::errorString() returns bullshit, use our own reporting
|
||||||
|
static const char *errorString(QNetworkReply::NetworkError error)
|
||||||
|
{
|
||||||
|
switch (error) {
|
||||||
|
case QNetworkReply::ConnectionRefusedError:
|
||||||
|
return "Connection refused";
|
||||||
|
case QNetworkReply::RemoteHostClosedError:
|
||||||
|
return "Connection closed";
|
||||||
|
case QNetworkReply::HostNotFoundError:
|
||||||
|
return "Host not found";
|
||||||
|
case QNetworkReply::TimeoutError:
|
||||||
|
return "Connection timeout";
|
||||||
|
case QNetworkReply::OperationCanceledError:
|
||||||
|
return "Operation canceled";
|
||||||
|
case QNetworkReply::SslHandshakeFailedError:
|
||||||
|
return "SSL handshake failed";
|
||||||
|
case QNetworkReply::TemporaryNetworkFailureError:
|
||||||
|
return "Temporary network failure";
|
||||||
|
case QNetworkReply::NetworkSessionFailedError:
|
||||||
|
return "Network session failed";
|
||||||
|
case QNetworkReply::BackgroundRequestNotAllowedError:
|
||||||
|
return "Background request not allowed";
|
||||||
|
case QNetworkReply::TooManyRedirectsError:
|
||||||
|
return "Too many redirects";
|
||||||
|
case QNetworkReply::InsecureRedirectError:
|
||||||
|
return "Insecure redirect";
|
||||||
|
case QNetworkReply::ProxyConnectionRefusedError:
|
||||||
|
return "Proxy connection refused";
|
||||||
|
case QNetworkReply::ProxyConnectionClosedError:
|
||||||
|
return "Proxy connection closed";
|
||||||
|
case QNetworkReply::ProxyNotFoundError:
|
||||||
|
return "Proxy not found";
|
||||||
|
case QNetworkReply::ProxyTimeoutError:
|
||||||
|
return "Proxy timeout error";
|
||||||
|
case QNetworkReply::ProxyAuthenticationRequiredError:
|
||||||
|
return "Proxy authentication required";
|
||||||
|
case QNetworkReply::ContentAccessDenied:
|
||||||
|
return "Content access denied";
|
||||||
|
case QNetworkReply::ContentOperationNotPermittedError:
|
||||||
|
return "Content operation not permitted";
|
||||||
|
case QNetworkReply::ContentNotFoundError:
|
||||||
|
return "Content not found";
|
||||||
|
case QNetworkReply::AuthenticationRequiredError:
|
||||||
|
return "Authentication required";
|
||||||
|
case QNetworkReply::ContentReSendError:
|
||||||
|
return "Content re-send error";
|
||||||
|
case QNetworkReply::ContentConflictError:
|
||||||
|
return "Content conflict";
|
||||||
|
case QNetworkReply::ContentGoneError:
|
||||||
|
return "Content gone";
|
||||||
|
case QNetworkReply::InternalServerError:
|
||||||
|
return "Internal server error";
|
||||||
|
case QNetworkReply::OperationNotImplementedError:
|
||||||
|
return "Operation not implemented";
|
||||||
|
case QNetworkReply::ServiceUnavailableError:
|
||||||
|
return "Service unavailable";
|
||||||
|
case QNetworkReply::ProtocolUnknownError:
|
||||||
|
return "Protocol unknown";
|
||||||
|
case QNetworkReply::ProtocolInvalidOperationError:
|
||||||
|
return "Protocol invalid operation";
|
||||||
|
case QNetworkReply::UnknownNetworkError:
|
||||||
|
return "Unknown network error";
|
||||||
|
case QNetworkReply::UnknownProxyError:
|
||||||
|
return "Unknown proxy error";
|
||||||
|
case QNetworkReply::UnknownContentError:
|
||||||
|
return "Unknown content error";
|
||||||
|
case QNetworkReply::ProtocolFailure:
|
||||||
|
return "Protocol failure";
|
||||||
|
case QNetworkReply::UnknownServerError:
|
||||||
|
return "Unknown server error";
|
||||||
|
default:
|
||||||
|
return "Unknown error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static QString tmpName(const QString &origName)
|
static QString tmpName(const QString &origName)
|
||||||
{
|
{
|
||||||
@ -158,11 +232,17 @@ void Downloader::emitReadReady()
|
|||||||
|
|
||||||
void Downloader::insertError(const QUrl &url, QNetworkReply::NetworkError error)
|
void Downloader::insertError(const QUrl &url, QNetworkReply::NetworkError error)
|
||||||
{
|
{
|
||||||
if (error == QNetworkReply::OperationCanceledError)
|
switch (error) {
|
||||||
|
case QNetworkReply::OperationCanceledError:
|
||||||
|
case QNetworkReply::TimeoutError:
|
||||||
|
case QNetworkReply::RemoteHostClosedError:
|
||||||
|
case QNetworkReply::ConnectionRefusedError:
|
||||||
_errorDownloads.insert(url, _errorDownloads.value(url) + 1);
|
_errorDownloads.insert(url, _errorDownloads.value(url) + 1);
|
||||||
else
|
break;
|
||||||
|
default:
|
||||||
_errorDownloads.insert(url, RETRIES);
|
_errorDownloads.insert(url, RETRIES);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Downloader::readData(QNetworkReply *reply)
|
void Downloader::readData(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
@ -179,8 +259,7 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
QFile *file = _currentDownloads.value(reply->request().url());
|
QFile *file = _currentDownloads.value(reply->request().url());
|
||||||
if (error) {
|
if (error) {
|
||||||
insertError(url, error);
|
insertError(url, error);
|
||||||
qWarning("%s: %s", url.toEncoded().constData(),
|
qWarning("%s: %s", url.toEncoded().constData(), errorString(error));
|
||||||
qPrintable(reply->errorString()));
|
|
||||||
file->remove();
|
file->remove();
|
||||||
} else {
|
} else {
|
||||||
file->close();
|
file->close();
|
||||||
|
@ -2,45 +2,71 @@
|
|||||||
|
|
||||||
using namespace ENC;
|
using namespace ENC;
|
||||||
|
|
||||||
bool AtlasData::pointCb(const QString *map, void *context)
|
bool AtlasData::pointCb(MapEntry *map, void *context)
|
||||||
{
|
{
|
||||||
PointCTX *ctx = (PointCTX*)context;
|
PointCTX *ctx = (PointCTX*)context;
|
||||||
|
|
||||||
ctx->lock.lock();
|
start:
|
||||||
|
ctx->cacheLock.lock();
|
||||||
|
|
||||||
MapData *cached = ctx->cache.object(map);
|
MapData *cached = ctx->cache.object(map->path);
|
||||||
|
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
MapData *data = new MapData(*map);
|
ctx->cacheLock.unlock();
|
||||||
|
|
||||||
|
if (map->lock.tryLock()) {
|
||||||
|
MapData *data = new MapData(map->path);
|
||||||
data->points(ctx->rect, ctx->points);
|
data->points(ctx->rect, ctx->points);
|
||||||
ctx->cache.insert(map, data);
|
|
||||||
|
ctx->cacheLock.lock();
|
||||||
|
ctx->cache.insert(map->path, data);
|
||||||
|
|
||||||
|
map->lock.unlock();
|
||||||
|
} else {
|
||||||
|
map->lock.lock();
|
||||||
|
map->lock.unlock();
|
||||||
|
goto start;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
cached->points(ctx->rect, ctx->points);
|
cached->points(ctx->rect, ctx->points);
|
||||||
|
|
||||||
ctx->lock.unlock();
|
ctx->cacheLock.unlock();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtlasData::polyCb(const QString *map, void *context)
|
bool AtlasData::polyCb(MapEntry *map, void *context)
|
||||||
{
|
{
|
||||||
PolyCTX *ctx = (PolyCTX*)context;
|
PolyCTX *ctx = (PolyCTX*)context;
|
||||||
|
|
||||||
ctx->lock.lock();
|
start:
|
||||||
|
ctx->cacheLock.lock();
|
||||||
|
|
||||||
MapData *cached = ctx->cache.object(map);
|
MapData *cached = ctx->cache.object(map->path);
|
||||||
|
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
MapData *data = new MapData(*map);
|
ctx->cacheLock.unlock();
|
||||||
|
|
||||||
|
if (map->lock.tryLock()) {
|
||||||
|
MapData *data = new MapData(map->path);
|
||||||
data->polygons(ctx->rect, ctx->polygons);
|
data->polygons(ctx->rect, ctx->polygons);
|
||||||
data->lines(ctx->rect, ctx->lines);
|
data->lines(ctx->rect, ctx->lines);
|
||||||
ctx->cache.insert(map, data);
|
|
||||||
|
ctx->cacheLock.lock();
|
||||||
|
ctx->cache.insert(map->path, data);
|
||||||
|
|
||||||
|
map->lock.unlock();
|
||||||
|
} else {
|
||||||
|
map->lock.lock();
|
||||||
|
map->lock.unlock();
|
||||||
|
goto start;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cached->polygons(ctx->rect, ctx->polygons);
|
cached->polygons(ctx->rect, ctx->polygons);
|
||||||
cached->lines(ctx->rect, ctx->lines);
|
cached->lines(ctx->rect, ctx->lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->lock.unlock();
|
ctx->cacheLock.unlock();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -61,14 +87,14 @@ void AtlasData::addMap(const RectC &bounds, const QString &path)
|
|||||||
max[0] = bounds.right();
|
max[0] = bounds.right();
|
||||||
max[1] = bounds.top();
|
max[1] = bounds.top();
|
||||||
|
|
||||||
_tree.Insert(min, max, new QString(path));
|
_tree.Insert(min, max, new MapEntry(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtlasData::polys(const RectC &rect, QList<MapData::Poly> *polygons,
|
void AtlasData::polys(const RectC &rect, QList<MapData::Poly> *polygons,
|
||||||
QList<MapData::Line> *lines)
|
QList<MapData::Line> *lines)
|
||||||
{
|
{
|
||||||
double min[2], max[2];
|
double min[2], max[2];
|
||||||
PolyCTX polyCtx(rect, polygons, lines, _cache, _lock);
|
PolyCTX polyCtx(rect, polygons, lines, _cache, _cacheLock);
|
||||||
|
|
||||||
min[0] = rect.left();
|
min[0] = rect.left();
|
||||||
min[1] = rect.bottom();
|
min[1] = rect.bottom();
|
||||||
@ -81,7 +107,7 @@ void AtlasData::polys(const RectC &rect, QList<MapData::Poly> *polygons,
|
|||||||
void AtlasData::points(const RectC &rect, QList<MapData::Point> *points)
|
void AtlasData::points(const RectC &rect, QList<MapData::Point> *points)
|
||||||
{
|
{
|
||||||
double min[2], max[2];
|
double min[2], max[2];
|
||||||
PointCTX pointCtx(rect, points, _cache, _lock);
|
PointCTX pointCtx(rect, points, _cache, _cacheLock);
|
||||||
|
|
||||||
min[0] = rect.left();
|
min[0] = rect.left();
|
||||||
min[1] = rect.bottom();
|
min[1] = rect.bottom();
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
namespace ENC {
|
namespace ENC {
|
||||||
|
|
||||||
typedef QCache<const QString*, MapData> MapCache;
|
typedef QCache<QString, MapData> MapCache;
|
||||||
|
|
||||||
class AtlasData
|
class AtlasData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AtlasData(MapCache &cache, QMutex &lock)
|
AtlasData(MapCache &cache, QMutex &cacheLock)
|
||||||
: _cache(cache), _lock(lock) {}
|
: _cache(cache), _cacheLock(cacheLock) {}
|
||||||
~AtlasData();
|
~AtlasData();
|
||||||
|
|
||||||
void addMap(const RectC &bounds, const QString &path);
|
void addMap(const RectC &bounds, const QString &path);
|
||||||
@ -24,40 +24,47 @@ public:
|
|||||||
void points(const RectC &rect, QList<MapData::Point> *points);
|
void points(const RectC &rect, QList<MapData::Point> *points);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef RTree<const QString*, double, 2> MapTree;
|
struct MapEntry {
|
||||||
|
MapEntry(const QString &path) : path(path) {}
|
||||||
|
|
||||||
|
QString path;
|
||||||
|
QMutex lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef RTree<MapEntry*, double, 2> MapTree;
|
||||||
|
|
||||||
struct PolyCTX
|
struct PolyCTX
|
||||||
{
|
{
|
||||||
PolyCTX(const RectC &rect, QList<MapData::Poly> *polygons,
|
PolyCTX(const RectC &rect, QList<MapData::Poly> *polygons,
|
||||||
QList<MapData::Line> *lines, MapCache &cache, QMutex &lock)
|
QList<MapData::Line> *lines, MapCache &cache, QMutex &cacheLock)
|
||||||
: rect(rect), polygons(polygons), lines(lines), cache(cache),
|
: rect(rect), polygons(polygons), lines(lines), cache(cache),
|
||||||
lock(lock) {}
|
cacheLock(cacheLock) {}
|
||||||
|
|
||||||
const RectC ▭
|
const RectC ▭
|
||||||
QList<MapData::Poly> *polygons;
|
QList<MapData::Poly> *polygons;
|
||||||
QList<MapData::Line> *lines;
|
QList<MapData::Line> *lines;
|
||||||
MapCache &cache;
|
MapCache &cache;
|
||||||
QMutex &lock;
|
QMutex &cacheLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PointCTX
|
struct PointCTX
|
||||||
{
|
{
|
||||||
PointCTX(const RectC &rect, QList<MapData::Point> *points,
|
PointCTX(const RectC &rect, QList<MapData::Point> *points,
|
||||||
MapCache &cache, QMutex &lock) : rect(rect), points(points),
|
MapCache &cache, QMutex &cacheLock)
|
||||||
cache(cache), lock(lock) {}
|
: rect(rect), points(points), cache(cache), cacheLock(cacheLock) {}
|
||||||
|
|
||||||
const RectC ▭
|
const RectC ▭
|
||||||
QList<MapData::Point> *points;
|
QList<MapData::Point> *points;
|
||||||
MapCache &cache;
|
MapCache &cache;
|
||||||
QMutex &lock;
|
QMutex &cacheLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool polyCb(const QString *map, void *context);
|
static bool polyCb(MapEntry *map, void *context);
|
||||||
static bool pointCb(const QString *map, void *context);
|
static bool pointCb(MapEntry *map, void *context);
|
||||||
|
|
||||||
MapTree _tree;
|
MapTree _tree;
|
||||||
MapCache &_cache;
|
MapCache &_cache;
|
||||||
QMutex &_lock;
|
QMutex &_cacheLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ void ENCAtlas::addMap(const QDir &dir, const QByteArray &file,
|
|||||||
IntendedUsage iu = usage(path);
|
IntendedUsage iu = usage(path);
|
||||||
auto it = _data.find(iu);
|
auto it = _data.find(iu);
|
||||||
if (it == _data.end())
|
if (it == _data.end())
|
||||||
it = _data.insert(iu, new AtlasData(_cache, _lock));
|
it = _data.insert(iu, new AtlasData(_cache, _cacheLock));
|
||||||
|
|
||||||
it.value()->addMap(bounds, path);
|
it.value()->addMap(bounds, path);
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ private:
|
|||||||
QMap<IntendedUsage, ENC::AtlasData*> _data;
|
QMap<IntendedUsage, ENC::AtlasData*> _data;
|
||||||
ENC::Style *_style;
|
ENC::Style *_style;
|
||||||
ENC::MapCache _cache;
|
ENC::MapCache _cache;
|
||||||
QMutex _lock;
|
QMutex _cacheLock;
|
||||||
IntendedUsage _usage;
|
IntendedUsage _usage;
|
||||||
int _zoom;
|
int _zoom;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user