From 6bcb6ceb8d0e7d078d6e0df07dae7387bb685b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 24 Mar 2016 19:34:46 +0100 Subject: [PATCH] Now using a file on the filesystem for default maps rather than the executable --- gpxsee.nsi | 3 ++- gpxsee.qrc | 1 - src/config.h | 34 ++++++++++++++++++++++++---------- src/gui.cpp | 28 +++++++++++++++------------- src/gui.h | 3 ++- src/map.cpp | 7 +++---- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/gpxsee.nsi b/gpxsee.nsi index 65f7330a..5ea93c32 100644 --- a/gpxsee.nsi +++ b/gpxsee.nsi @@ -55,8 +55,9 @@ Section "GPXSee (required)" SEC_APP ; Set output path to the installation directory. SetOutPath $INSTDIR - ; Put file there + ; Put the files there File "gpxsee.exe" + File "maps.txt" ; Write the installation path into the registry WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR" diff --git a/gpxsee.qrc b/gpxsee.qrc index 65ac91d9..d24494c6 100644 --- a/gpxsee.qrc +++ b/gpxsee.qrc @@ -14,6 +14,5 @@ icons/arrow-left-double.png icons/arrow-right-double.png lang/gpxsee_cs.qm - maps.txt diff --git a/src/config.h b/src/config.h index 2fcd23d6..2ecf9f49 100644 --- a/src/config.h +++ b/src/config.h @@ -1,20 +1,34 @@ #ifndef CONFIG_H #define CONFIG_H -#define APP_NAME "GPXSee" -#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee" -#define APP_VERSION "2.10" +#include -#define FONT_FAMILY "Arial" -#define FONT_SIZE 12 +#define APP_NAME "GPXSee" +#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee" +#define APP_VERSION "2.10" + +#define FONT_FAMILY "Arial" +#define FONT_SIZE 12 + +#define MAP_FILE QString("maps.txt") +#define POI_DIR QString("POI") #if defined(Q_OS_WIN32) -#define APP_DIR "GPXSee" +#define USER_DIR QDir::homePath() + QString("/GPXSee") +#define GLOBAL_DIR QApplication::applicationDirPath() +#elif defined(Q_OS_MAC) +#define USER_DIR QDir::homePath() + QString("/.gpxsee") +#define GLOBAL_DIR QApplication::applicationDirPath() \ + + QString("/../Resources") #else -#define APP_DIR ".gpxsee" +#define USER_DIR QDir::homePath() + QString("/.gpxsee") +#define GLOBAL_DIR QString("/usr/share/gpxsee") #endif -#define POI_DIR APP_DIR"/POI" -#define TILES_DIR APP_DIR"/tiles" -#define MAP_LIST_FILE APP_DIR"/maps.txt" + +#define USER_MAP_FILE USER_DIR + QString("/") + MAP_FILE +#define USER_POI_DIR USER_DIR + QString("/") + POI_DIR +#define GLOBAL_MAP_FILE GLOBAL_DIR + QString("/") + MAP_FILE +#define GLOBAL_POI_DIR GLOBAL_DIR + QString("/") + POI_DIR +#define TILES_DIR USER_DIR + QString("/tiles") #endif /* CONFIG_H */ diff --git a/src/gui.cpp b/src/gui.cpp index fe68eafe..bcf9c66b 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -44,7 +44,8 @@ static QString timeSpan(qreal time) GUI::GUI(QWidget *parent) : QMainWindow(parent) { - loadFiles(); + loadMaps(); + loadPOIs(); createActions(); createMenus(); @@ -85,16 +86,19 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent) resize(600, 800); } -void GUI::loadFiles() +void GUI::loadMaps() { - // Maps - _maps = MapList::load(this, QString("%1/" MAP_LIST_FILE) - .arg(QDir::homePath())); - _maps += MapList::load(this, ":/maps.txt"); + _maps = MapList::load(this, USER_MAP_FILE); + _maps += MapList::load(this, GLOBAL_MAP_FILE); +} - // POI files - QDir dir(QString("%1/" POI_DIR).arg(QDir::homePath())); - QFileInfoList list = dir.entryInfoList(QStringList(), QDir::Files); +void GUI::loadPOIs() +{ + QDir userDir(USER_POI_DIR); + QDir globalDir(GLOBAL_POI_DIR); + + QFileInfoList list = userDir.entryInfoList(QStringList(), QDir::Files) + + globalDir.entryInfoList(QStringList(), QDir::Files); for (int i = 0; i < list.size(); ++i) _poi.loadFile(list.at(i).absoluteFilePath()); } @@ -433,8 +437,7 @@ void GUI::dataSources() QString("

") + tr("Map sources") + QString("

") + tr("Map (tiles) source URLs are read on program startup from the " "following file:") - + QString("

") + QDir::homePath() - + QString("/" MAP_LIST_FILE "

") + + QString("

") + USER_MAP_FILE + QString("

") + tr("The file format is one map entry per line, consisting of the map " "name and tiles URL delimited by a TAB character. The tile X and Y " "coordinates are replaced with $x and $y in the URL and the zoom " @@ -445,8 +448,7 @@ void GUI::dataSources() + QString("

") + tr("POIs") + QString("

") + tr("To make GPXSee load a POI file automatically on startup, add " "the file to the following directory:") - + QString("

") + QDir::homePath() - + QString("/" POI_DIR "

") + + QString("

") + USER_POI_DIR + QString("

") ); msgBox.exec(); diff --git a/src/gui.h b/src/gui.h index b1688012..47bdce47 100644 --- a/src/gui.h +++ b/src/gui.h @@ -59,7 +59,8 @@ private slots: void setImperialUnits(); private: - void loadFiles(); + void loadMaps(); + void loadPOIs(); void closeFiles(); QAction *createPOIFileAction(int index); diff --git a/src/map.cpp b/src/map.cpp index abd587ba..3f2c8de4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -15,7 +15,7 @@ Map::Map(QObject *parent, const QString &name, const QString &url) connect(&Downloader::instance(), SIGNAL(finished()), this, SLOT(emitLoaded())); - QString path = QString(TILES_DIR"/") + _name; + QString path = TILES_DIR + QString("/") + _name; if (!QDir::home().mkpath(path)) fprintf(stderr, "Error creating tiles dir: %s\n", qPrintable(path)); } @@ -31,9 +31,8 @@ void Map::loadTiles(QList &list) for (int i = 0; i < list.size(); ++i) { Tile &t = list[i]; - QString file = QString("%1/" TILES_DIR "/%2/%3-%4-%5") - .arg(QDir::homePath()).arg(_name).arg(t.zoom()).arg(t.xy().rx()) - .arg(t.xy().ry()); + QString file = TILES_DIR + QString("/%1/%2-%3-%4") + .arg(_name).arg(t.zoom()).arg(t.xy().rx()).arg(t.xy().ry()); QFileInfo fi(file); if (fi.exists()) {