mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Map sources are now readed from config file
This commit is contained in:
parent
c639c6deac
commit
81c0789319
@ -1,7 +1,7 @@
|
|||||||
TARGET = GPXSee
|
TARGET = GPXSee
|
||||||
QT += core \
|
QT += core \
|
||||||
gui \
|
gui \
|
||||||
network
|
network
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
|
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
|
||||||
HEADERS += src/config.h \
|
HEADERS += src/config.h \
|
||||||
@ -26,6 +26,7 @@ HEADERS += src/config.h \
|
|||||||
src/sliderinfoitem.h \
|
src/sliderinfoitem.h \
|
||||||
src/filebrowser.h \
|
src/filebrowser.h \
|
||||||
src/map.h \
|
src/map.h \
|
||||||
|
src/maplist.h \
|
||||||
src/downloader.h
|
src/downloader.h
|
||||||
SOURCES += src/main.cpp \
|
SOURCES += src/main.cpp \
|
||||||
src/gui.cpp \
|
src/gui.cpp \
|
||||||
@ -46,6 +47,7 @@ SOURCES += src/main.cpp \
|
|||||||
src/sliderinfoitem.cpp \
|
src/sliderinfoitem.cpp \
|
||||||
src/filebrowser.cpp \
|
src/filebrowser.cpp \
|
||||||
src/map.cpp \
|
src/map.cpp \
|
||||||
|
src/maplist.cpp \
|
||||||
src/downloader.cpp
|
src/downloader.cpp
|
||||||
RESOURCES += gpxsee.qrc
|
RESOURCES += gpxsee.qrc
|
||||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#define APP_NAME "GPXSee"
|
#define APP_NAME "GPXSee"
|
||||||
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
|
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
|
||||||
#define APP_VERSION "1.1"
|
#define APP_VERSION "2.0"
|
||||||
|
|
||||||
#define FONT_FAMILY "Arial"
|
#define FONT_FAMILY "Arial"
|
||||||
#define FONT_SIZE 12
|
#define FONT_SIZE 12
|
||||||
|
@ -1,10 +1,24 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include "config.h"
|
||||||
#include "downloader.h"
|
#include "downloader.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
#define PLATFORM_STR "Linux"
|
||||||
|
#elif Q_OS_WIN32
|
||||||
|
#define PLATFORM_STR "Windows"
|
||||||
|
#elif Q_OS_MAC
|
||||||
|
#define PLATFORM_STR "OS X"
|
||||||
|
#else
|
||||||
|
#define PLATFORM_STR "Unknown"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define USER_AGENT APP_NAME"/"APP_VERSION" ("PLATFORM_STR"; Qt "QT_VERSION_STR")"
|
||||||
|
|
||||||
|
|
||||||
Downloader::Downloader()
|
Downloader::Downloader()
|
||||||
{
|
{
|
||||||
connect(&manager, SIGNAL(finished(QNetworkReply*)),
|
connect(&manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
@ -16,6 +30,7 @@ void Downloader::doDownload(const Download &dl)
|
|||||||
QUrl url(dl.url());
|
QUrl url(dl.url());
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
|
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
|
||||||
|
request.setRawHeader("User-Agent", USER_AGENT);
|
||||||
QNetworkReply *reply = manager.get(request);
|
QNetworkReply *reply = manager.get(request);
|
||||||
|
|
||||||
currentDownloads.append(reply);
|
currentDownloads.append(reply);
|
||||||
@ -26,7 +41,7 @@ bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
|||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
|
|
||||||
if (!file.open(QIODevice::WriteOnly)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
fprintf(stderr, "Could not open %s for writing: %s\n",
|
fprintf(stderr, "Error writing map tile: %s: %s\n",
|
||||||
qPrintable(filename), qPrintable(file.errorString()));
|
qPrintable(filename), qPrintable(file.errorString()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -41,7 +56,7 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
{
|
{
|
||||||
QUrl url = reply->url();
|
QUrl url = reply->url();
|
||||||
if (reply->error()) {
|
if (reply->error()) {
|
||||||
fprintf(stderr, "Download of %s failed: %s\n",
|
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
||||||
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
||||||
} else {
|
} else {
|
||||||
QString filename = reply->request().attribute(QNetworkRequest::User)
|
QString filename = reply->request().attribute(QNetworkRequest::User)
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "gpx.h"
|
#include "gpx.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "maplist.h"
|
||||||
#include "elevationgraph.h"
|
#include "elevationgraph.h"
|
||||||
#include "speedgraph.h"
|
#include "speedgraph.h"
|
||||||
#include "track.h"
|
#include "track.h"
|
||||||
@ -74,12 +75,8 @@ GUI::GUI()
|
|||||||
|
|
||||||
void GUI::loadMaps()
|
void GUI::loadMaps()
|
||||||
{
|
{
|
||||||
_maps.append(new Map("Google maps",
|
_maps = MapList::load(QString("%1/"TILES_DIR"/"LIST_FILE)
|
||||||
"http://mts1.google.com/vt/x=$x&y=$y&z=$z"));
|
.arg(QDir::homePath()));
|
||||||
_maps.append(new Map("Mapy.cz",
|
|
||||||
"http://m1.mapserver.mapy.cz/wturist-m/$z-$x-$y"));
|
|
||||||
_maps.append(new Map("OSM",
|
|
||||||
"http://tile.mtbmap.cz/mtbmap_tiles/$z/$x/$y.png"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::createMapActions()
|
void GUI::createMapActions()
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#define TILES_DIR "tiles"
|
|
||||||
|
|
||||||
Map::Map(const QString &name, const QString &url)
|
Map::Map(const QString &name, const QString &url)
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
#include "downloader.h"
|
#include "downloader.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TILES_DIR "tiles"
|
||||||
|
#define LIST_FILE "list.txt"
|
||||||
|
|
||||||
class Tile
|
class Tile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
37
src/maplist.cpp
Normal file
37
src/maplist.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <QFile>
|
||||||
|
#include "maplist.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
QList<Map*> MapList::load(const QString &fileName)
|
||||||
|
{
|
||||||
|
QFile file(fileName);
|
||||||
|
QList<Map*> mapList;
|
||||||
|
int ln = 1;
|
||||||
|
|
||||||
|
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
fprintf(stderr, "Error opening map list file: %s: %s\n",
|
||||||
|
qPrintable(fileName), qPrintable(file.errorString()));
|
||||||
|
return mapList;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!file.atEnd()) {
|
||||||
|
QByteArray line = file.readLine();
|
||||||
|
QList<QByteArray> list = line.split('\t');
|
||||||
|
if (list.size() != 2) {
|
||||||
|
fprintf(stderr, "Invalid map list entry on line %d\n", ln);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray ba1 = list[0].trimmed();
|
||||||
|
QByteArray ba2 = list[1].trimmed();
|
||||||
|
|
||||||
|
mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||||
|
QString::fromAscii(ba2.data(), ba2.size())));
|
||||||
|
|
||||||
|
ln++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapList;
|
||||||
|
}
|
14
src/maplist.h
Normal file
14
src/maplist.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef MAPLIST_H
|
||||||
|
#define MAPLIST_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include "map.h"
|
||||||
|
|
||||||
|
|
||||||
|
class MapList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QList<Map*> load(const QString &fileName);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAPLIST_H
|
Loading…
Reference in New Issue
Block a user