1
0
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:
Martin Tůma 2015-11-23 23:19:57 +01:00
parent c639c6deac
commit 81c0789319
8 changed files with 79 additions and 12 deletions

View File

@ -1,7 +1,7 @@
TARGET = GPXSee
QT += core \
gui \
network
gui \
network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
HEADERS += src/config.h \
@ -26,6 +26,7 @@ HEADERS += src/config.h \
src/sliderinfoitem.h \
src/filebrowser.h \
src/map.h \
src/maplist.h \
src/downloader.h
SOURCES += src/main.cpp \
src/gui.cpp \
@ -46,6 +47,7 @@ SOURCES += src/main.cpp \
src/sliderinfoitem.cpp \
src/filebrowser.cpp \
src/map.cpp \
src/maplist.cpp \
src/downloader.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts

View File

@ -3,7 +3,7 @@
#define APP_NAME "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_SIZE 12

View File

@ -1,10 +1,24 @@
#include <QFile>
#include <QFileInfo>
#include "config.h"
#include "downloader.h"
#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()
{
connect(&manager, SIGNAL(finished(QNetworkReply*)),
@ -16,6 +30,7 @@ void Downloader::doDownload(const Download &dl)
QUrl url(dl.url());
QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
request.setRawHeader("User-Agent", USER_AGENT);
QNetworkReply *reply = manager.get(request);
currentDownloads.append(reply);
@ -26,7 +41,7 @@ bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
QFile file(filename);
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()));
return false;
}
@ -41,7 +56,7 @@ void Downloader::downloadFinished(QNetworkReply *reply)
{
QUrl url = reply->url();
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()));
} else {
QString filename = reply->request().attribute(QNetworkRequest::User)

View File

@ -13,6 +13,7 @@
#include "keys.h"
#include "gpx.h"
#include "map.h"
#include "maplist.h"
#include "elevationgraph.h"
#include "speedgraph.h"
#include "track.h"
@ -74,12 +75,8 @@ GUI::GUI()
void GUI::loadMaps()
{
_maps.append(new Map("Google maps",
"http://mts1.google.com/vt/x=$x&y=$y&z=$z"));
_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"));
_maps = MapList::load(QString("%1/"TILES_DIR"/"LIST_FILE)
.arg(QDir::homePath()));
}
void GUI::createMapActions()

View File

@ -6,7 +6,6 @@
#include <QDebug>
#define TILES_DIR "tiles"
Map::Map(const QString &name, const QString &url)
{

View File

@ -5,6 +5,9 @@
#include "downloader.h"
#define TILES_DIR "tiles"
#define LIST_FILE "list.txt"
class Tile
{
public:

37
src/maplist.cpp Normal file
View 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
View 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