1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Improved error handling

Added file filters to open dialogs
This commit is contained in:
Martin Tůma 2016-02-12 20:12:37 +01:00
parent 580289e533
commit 932f817496
8 changed files with 149 additions and 120 deletions

View File

@ -1,57 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="cs_CZ">
<TS version="2.0" language="cs_CZ">
<context>
<name>ElevationGraph</name>
<message>
<location filename="../src/elevationgraph.cpp" line="13"/>
<location filename="../src/elevationgraph.cpp" line="14"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="14"/>
<location filename="../src/elevationgraph.cpp" line="15"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="15"/>
<location filename="../src/elevationgraph.cpp" line="82"/>
<location filename="../src/elevationgraph.cpp" line="16"/>
<location filename="../src/elevationgraph.cpp" line="83"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="16"/>
<location filename="../src/elevationgraph.cpp" line="83"/>
<location filename="../src/elevationgraph.cpp" line="17"/>
<location filename="../src/elevationgraph.cpp" line="84"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="22"/>
<location filename="../src/elevationgraph.cpp" line="23"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="24"/>
<location filename="../src/elevationgraph.cpp" line="25"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="28"/>
<location filename="../src/elevationgraph.cpp" line="29"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="87"/>
<location filename="../src/elevationgraph.cpp" line="88"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="88"/>
<location filename="../src/elevationgraph.cpp" line="89"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="26"/>
<location filename="../src/elevationgraph.cpp" line="27"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
@ -59,326 +59,336 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="139"/>
<location filename="../src/gui.cpp" line="140"/>
<source>About Qt</source>
<translation>O Qt</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="349"/>
<location filename="../src/gui.cpp" line="350"/>
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="410"/>
<location filename="../src/gui.cpp" line="411"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="153"/>
<location filename="../src/gui.cpp" line="154"/>
<source>Save as</source>
<translation>Uložit jako</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="469"/>
<location filename="../src/gui.cpp" line="471"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="144"/>
<location filename="../src/gui.cpp" line="145"/>
<source>Open</source>
<translation>Otevřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="127"/>
<location filename="../src/gui.cpp" line="128"/>
<source>Quit</source>
<translation>Ukončit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="134"/>
<location filename="../src/gui.cpp" line="365"/>
<location filename="../src/gui.cpp" line="135"/>
<location filename="../src/gui.cpp" line="366"/>
<location filename="../src/gui.cpp" line="367"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="148"/>
<location filename="../src/gui.cpp" line="149"/>
<source>Save</source>
<translation>Uložit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="158"/>
<location filename="../src/gui.cpp" line="159"/>
<source>Close</source>
<translation>Zavřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="163"/>
<location filename="../src/gui.cpp" line="164"/>
<source>Reload</source>
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="286"/>
<location filename="../src/gui.cpp" line="287"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="236"/>
<location filename="../src/gui.cpp" line="277"/>
<location filename="../src/gui.cpp" line="237"/>
<location filename="../src/gui.cpp" line="278"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="132"/>
<location filename="../src/gui.cpp" line="383"/>
<location filename="../src/gui.cpp" line="133"/>
<location filename="../src/gui.cpp" line="384"/>
<location filename="../src/gui.cpp" line="385"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="170"/>
<location filename="../src/gui.cpp" line="171"/>
<source>Load POI file</source>
<translation>Nahrát POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="173"/>
<location filename="../src/gui.cpp" line="174"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="179"/>
<location filename="../src/gui.cpp" line="180"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="192"/>
<location filename="../src/gui.cpp" line="193"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="198"/>
<location filename="../src/gui.cpp" line="199"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="205"/>
<location filename="../src/gui.cpp" line="206"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="211"/>
<location filename="../src/gui.cpp" line="212"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="218"/>
<location filename="../src/gui.cpp" line="219"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="221"/>
<location filename="../src/gui.cpp" line="222"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="225"/>
<location filename="../src/gui.cpp" line="226"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="228"/>
<location filename="../src/gui.cpp" line="229"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="250"/>
<location filename="../src/gui.cpp" line="251"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="255"/>
<location filename="../src/gui.cpp" line="256"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="259"/>
<location filename="../src/gui.cpp" line="260"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="260"/>
<location filename="../src/gui.cpp" line="261"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="267"/>
<location filename="../src/gui.cpp" line="268"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="317"/>
<location filename="../src/gui.cpp" line="318"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="318"/>
<location filename="../src/gui.cpp" line="319"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="368"/>
<location filename="../src/gui.cpp" line="369"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="369"/>
<location filename="../src/gui.cpp" line="370"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="371"/>
<location filename="../src/gui.cpp" line="372"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="372"/>
<location filename="../src/gui.cpp" line="373"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="373"/>
<location filename="../src/gui.cpp" line="374"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="387"/>
<location filename="../src/gui.cpp" line="388"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="391"/>
<location filename="../src/gui.cpp" line="392"/>
<source>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 level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="399"/>
<location filename="../src/gui.cpp" line="400"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="460"/>
<location filename="../src/gui.cpp" line="476"/>
<location filename="../src/gui.cpp" line="412"/>
<source>GPX files (*.gpx);;All files (*)</source>
<translation>soubory GPX (*.gpx);;všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="462"/>
<location filename="../src/gui.cpp" line="479"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="523"/>
<location filename="../src/gui.cpp" line="642"/>
<location filename="../src/gui.cpp" line="472"/>
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
<translation>soubory GPX (*.gpx);;soubory CSV (*.csv);;všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="526"/>
<location filename="../src/gui.cpp" line="645"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="526"/>
<location filename="../src/gui.cpp" line="528"/>
<location filename="../src/gui.cpp" line="530"/>
<location filename="../src/gui.cpp" line="532"/>
<location filename="../src/gui.cpp" line="529"/>
<location filename="../src/gui.cpp" line="531"/>
<location filename="../src/gui.cpp" line="533"/>
<location filename="../src/gui.cpp" line="535"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="529"/>
<location filename="../src/gui.cpp" line="541"/>
<location filename="../src/gui.cpp" line="532"/>
<location filename="../src/gui.cpp" line="544"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="531"/>
<location filename="../src/gui.cpp" line="543"/>
<location filename="../src/gui.cpp" line="534"/>
<location filename="../src/gui.cpp" line="546"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="137"/>
<location filename="../src/gui.cpp" line="345"/>
<location filename="../src/gui.cpp" line="138"/>
<location filename="../src/gui.cpp" line="346"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="293"/>
<location filename="../src/gui.cpp" line="294"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="347"/>
<location filename="../src/gui.cpp" line="348"/>
<source>GPX viewer and analyzer</source>
<translation>Prohlížeč a analyzátor GPX</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="386"/>
<location filename="../src/gui.cpp" line="387"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="398"/>
<location filename="../src/gui.cpp" line="399"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="522"/>
<location filename="../src/gui.cpp" line="534"/>
<location filename="../src/gui.cpp" line="525"/>
<location filename="../src/gui.cpp" line="537"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="524"/>
<location filename="../src/gui.cpp" line="536"/>
<location filename="../src/gui.cpp" line="527"/>
<location filename="../src/gui.cpp" line="539"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="525"/>
<location filename="../src/gui.cpp" line="537"/>
<location filename="../src/gui.cpp" line="528"/>
<location filename="../src/gui.cpp" line="540"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="538"/>
<location filename="../src/gui.cpp" line="540"/>
<location filename="../src/gui.cpp" line="542"/>
<location filename="../src/gui.cpp" line="544"/>
<location filename="../src/gui.cpp" line="541"/>
<location filename="../src/gui.cpp" line="543"/>
<location filename="../src/gui.cpp" line="545"/>
<location filename="../src/gui.cpp" line="547"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="527"/>
<location filename="../src/gui.cpp" line="539"/>
<location filename="../src/gui.cpp" line="530"/>
<location filename="../src/gui.cpp" line="542"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="638"/>
<location filename="../src/gui.cpp" line="641"/>
<source>%1 tracks</source>
<translation>Počet tras: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="535"/>
<location filename="../src/gui.cpp" line="645"/>
<location filename="../src/gui.cpp" line="538"/>
<location filename="../src/gui.cpp" line="648"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="462"/>
<location filename="../src/gui.cpp" line="477"/>
<location filename="../src/gui.cpp" line="464"/>
<location filename="../src/gui.cpp" line="480"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="457"/>
<location filename="../src/gui.cpp" line="459"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="473"/>
<location filename="../src/gui.cpp" line="476"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
@ -411,44 +421,44 @@
<context>
<name>SpeedGraph</name>
<message>
<location filename="../src/speedgraph.cpp" line="9"/>
<location filename="../src/speedgraph.cpp" line="10"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="10"/>
<location filename="../src/speedgraph.cpp" line="11"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="11"/>
<location filename="../src/speedgraph.cpp" line="71"/>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.cpp" line="73"/>
<source>km</source>
<translation></translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.cpp" line="72"/>
<location filename="../src/speedgraph.cpp" line="13"/>
<location filename="../src/speedgraph.cpp" line="74"/>
<source>km/h</source>
<translation>km/h</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="20"/>
<location filename="../src/speedgraph.cpp" line="21"/>
<source>Average</source>
<translation>Průměr</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="22"/>
<location filename="../src/speedgraph.cpp" line="23"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="76"/>
<location filename="../src/speedgraph.cpp" line="78"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="77"/>
<location filename="../src/speedgraph.cpp" line="79"/>
<source>mi/h</source>
<translation>mi/h</translation>
</message>

View File

@ -35,7 +35,7 @@ static QString timeSpan(qreal time)
}
GUI::GUI()
GUI::GUI(QWidget *parent) : QMainWindow(parent)
{
loadFiles();
@ -75,18 +75,15 @@ GUI::GUI()
void GUI::loadFiles()
{
// Maps
_maps = MapList::load(QString("%1/" MAP_LIST_FILE).arg(QDir::homePath()));
_maps += MapList::load(":/maps.txt");
_maps = MapList::load(this, QString("%1/" MAP_LIST_FILE)
.arg(QDir::homePath()));
_maps += MapList::load(this, ":/maps.txt");
// POI files
QDir dir(QString("%1/" POI_DIR).arg(QDir::homePath()));
QFileInfoList list = dir.entryInfoList(QStringList(), QDir::Files);
for (int i = 0; i < list.size(); ++i) {
if (!_poi.loadFile(list.at(i).absoluteFilePath()))
fprintf(stderr, "Error loading POI file: %s: %s",
qPrintable(list.at(i).absoluteFilePath()),
qPrintable(_poi.errorString()));
}
for (int i = 0; i < list.size(); ++i)
_poi.loadFile(list.at(i).absoluteFilePath());
}
void GUI::createMapActions()
@ -407,7 +404,8 @@ void GUI::dataSources()
void GUI::openFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"));
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"),
QString(), tr("GPX files (*.gpx);;All files (*)"));
QStringList list = files;
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
@ -466,7 +464,8 @@ bool GUI::loadFile(const QString &fileName)
void GUI::openPOIFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open POI file"));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open POI file"),
QString(), tr("GPX files (*.gpx);;CSV files (*.csv);;All files (*)"));
if (!fileName.isEmpty()) {
if (!_poi.loadFile(fileName)) {

View File

@ -23,7 +23,7 @@ class GUI : public QMainWindow
Q_OBJECT
public:
GUI();
GUI(QWidget *parent = 0);
bool openFile(const QString &fileName);

View File

@ -6,7 +6,7 @@
#include "map.h"
Map::Map(const QString &name, const QString &url, QObject *parent)
Map::Map(QObject *parent, const QString &name, const QString &url)
: QObject(parent)
{
_name = name;

View File

@ -28,7 +28,8 @@ signals:
void loaded();
public:
Map(const QString &name, const QString &url, QObject *parent = 0);
Map(QObject *parent = 0, const QString &name = QString(),
const QString &url = QString());
const QString &name() const {return _name;}
void loadTiles(QList<Tile> &list);

View File

@ -4,7 +4,7 @@
#include "maplist.h"
QList<Map*> MapList::load(const QString &fileName)
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
{
QList<Map*> mapList;
QFileInfo fi(fileName);
@ -33,7 +33,7 @@ QList<Map*> MapList::load(const QString &fileName)
QByteArray ba1 = list[0].trimmed();
QByteArray ba2 = list[1].trimmed();
mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()),
mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()),
QString::fromLatin1(ba2.data(), ba2.size())));
}

View File

@ -3,13 +3,15 @@
#include <QList>
#include <QString>
#include <QObject>
class Map;
class MapList
{
public:
static QList<Map*> load(const QString &fileName);
static QList<Map*> load(QObject *parent = 0,
const QString &fileName = QString());
};
#endif // MAPLIST_H

View File

@ -10,14 +10,31 @@
bool POI::loadFile(const QString &fileName)
{
QString error;
int errorLine;
_error.clear();
_errorLine = 0;
if (loadCSVFile(fileName))
return true;
else {
error = _error;
errorLine = _errorLine;
}
if (loadGPXFile(fileName))
return true;
fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName));
fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error));
fprintf(stderr, "GPX: line %d: %s\n", _errorLine, qPrintable(_error));
if (errorLine > _errorLine) {
_errorLine = errorLine;
_error = error;
}
return false;
}