mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
parent
183c35ec7a
commit
f998148fec
@ -86,14 +86,16 @@ int App::run()
|
|||||||
{
|
{
|
||||||
MapAction *lastReady = 0;
|
MapAction *lastReady = 0;
|
||||||
QStringList args(arguments());
|
QStringList args(arguments());
|
||||||
|
int silent = 0;
|
||||||
|
int showError = (args.count() - 1 > 1) ? 2 : 1;
|
||||||
|
|
||||||
_gui->show();
|
_gui->show();
|
||||||
|
|
||||||
for (int i = 1; i < args.count(); i++) {
|
for (int i = 1; i < args.count(); i++) {
|
||||||
if (!_gui->openFile(args.at(i), true)) {
|
if (!_gui->openFile(args.at(i), false, silent)) {
|
||||||
MapAction *a;
|
MapAction *a;
|
||||||
if (!_gui->loadMap(args.at(i), a, true))
|
if (!_gui->loadMap(args.at(i), a, true))
|
||||||
_gui->openFile(args.at(i), false);
|
_gui->openFile(args.at(i), true, showError);
|
||||||
else {
|
else {
|
||||||
if (a)
|
if (a)
|
||||||
lastReady = a;
|
lastReady = a;
|
||||||
@ -116,10 +118,13 @@ void App::appStateChanged(Qt::ApplicationState state)
|
|||||||
QJniObject activity = QNativeInterface::QAndroidApplication::context();
|
QJniObject activity = QNativeInterface::QAndroidApplication::context();
|
||||||
QString path(activity.callObjectMethod<jstring>("intentPath").toString());
|
QString path(activity.callObjectMethod<jstring>("intentPath").toString());
|
||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty()) {
|
||||||
if (!_gui->openFile(path, true)) {
|
int silent = 0;
|
||||||
|
int showError = 1;
|
||||||
|
|
||||||
|
if (!_gui->openFile(path, false, silent)) {
|
||||||
MapAction *a;
|
MapAction *a;
|
||||||
if (!_gui->loadMap(path, a, true))
|
if (!_gui->loadMap(path, a, true))
|
||||||
_gui->openFile(path, false);
|
_gui->openFile(path, true, showError);
|
||||||
else {
|
else {
|
||||||
if (a)
|
if (a)
|
||||||
a->trigger();
|
a->trigger();
|
||||||
@ -132,13 +137,16 @@ void App::appStateChanged(Qt::ApplicationState state)
|
|||||||
|
|
||||||
bool App::event(QEvent *event)
|
bool App::event(QEvent *event)
|
||||||
{
|
{
|
||||||
|
int silent = 0;
|
||||||
|
int showError = 1;
|
||||||
|
|
||||||
if (event->type() == QEvent::FileOpen) {
|
if (event->type() == QEvent::FileOpen) {
|
||||||
QFileOpenEvent *e = static_cast<QFileOpenEvent *>(event);
|
QFileOpenEvent *e = static_cast<QFileOpenEvent *>(event);
|
||||||
|
|
||||||
if (!_gui->openFile(e->file(), true)) {
|
if (!_gui->openFile(e->file(), false, silent)) {
|
||||||
MapAction *a;
|
MapAction *a;
|
||||||
if (!_gui->loadMap(e->file(), a, true))
|
if (!_gui->loadMap(e->file(), a, true))
|
||||||
return _gui->openFile(e->file(), false);
|
return _gui->openFile(e->file(), true, showError);
|
||||||
else {
|
else {
|
||||||
if (a)
|
if (a)
|
||||||
a->trigger();
|
a->trigger();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@ -947,9 +948,10 @@ void GUI::openFile()
|
|||||||
QStringList files(QFileDialog::getOpenFileNames(this, tr("Open file"),
|
QStringList files(QFileDialog::getOpenFileNames(this, tr("Open file"),
|
||||||
_dataDir, Data::formats()));
|
_dataDir, Data::formats()));
|
||||||
#endif // Q_OS_ANDROID
|
#endif // Q_OS_ANDROID
|
||||||
|
int showError = (files.size() > 1) ? 2 : 1;
|
||||||
|
|
||||||
for (int i = 0; i < files.size(); i++)
|
for (int i = 0; i < files.size(); i++)
|
||||||
openFile(files.at(i));
|
openFile(files.at(i), true, showError);
|
||||||
if (!files.isEmpty())
|
if (!files.isEmpty())
|
||||||
_dataDir = QFileInfo(files.last()).path();
|
_dataDir = QFileInfo(files.last()).path();
|
||||||
}
|
}
|
||||||
@ -959,20 +961,21 @@ void GUI::openDir()
|
|||||||
{
|
{
|
||||||
QString dir(QFileDialog::getExistingDirectory(this, tr("Open directory"),
|
QString dir(QFileDialog::getExistingDirectory(this, tr("Open directory"),
|
||||||
_dataDir));
|
_dataDir));
|
||||||
|
int showError = 1;
|
||||||
|
|
||||||
if (!dir.isEmpty()) {
|
if (!dir.isEmpty()) {
|
||||||
_browser->setCurrentDir(dir);
|
_browser->setCurrentDir(dir);
|
||||||
openFile(_browser->current());
|
openFile(_browser->current(), true, showError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // Q_OS_ANDROID
|
#endif // Q_OS_ANDROID
|
||||||
|
|
||||||
bool GUI::openFile(const QString &fileName, bool silent)
|
bool GUI::openFile(const QString &fileName, bool tryUnknown, int &showError)
|
||||||
{
|
{
|
||||||
if (_files.contains(fileName))
|
if (_files.contains(fileName))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!loadFile(fileName, silent))
|
if (!loadFile(fileName, tryUnknown, showError))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_files.append(fileName);
|
_files.append(fileName);
|
||||||
@ -991,14 +994,14 @@ bool GUI::openFile(const QString &fileName, bool silent)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GUI::loadFile(const QString &fileName, bool silent)
|
bool GUI::loadFile(const QString &fileName, bool tryUnknown, int &showError)
|
||||||
{
|
{
|
||||||
Data data(fileName, !silent);
|
Data data(fileName, tryUnknown);
|
||||||
|
|
||||||
if (data.isValid()) {
|
if (data.isValid()) {
|
||||||
loadData(data);
|
loadData(data);
|
||||||
return true;
|
return true;
|
||||||
} else if (!silent) {
|
} else {
|
||||||
updateNavigationActions();
|
updateNavigationActions();
|
||||||
updateStatusBarInfo();
|
updateStatusBarInfo();
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
@ -1007,14 +1010,26 @@ bool GUI::loadFile(const QString &fileName, bool silent)
|
|||||||
if (_files.isEmpty())
|
if (_files.isEmpty())
|
||||||
_fileActionGroup->setEnabled(false);
|
_fileActionGroup->setEnabled(false);
|
||||||
|
|
||||||
QString error = tr("Error loading data file:") + "\n\n"
|
if (showError) {
|
||||||
+ Util::displayName(fileName) + "\n\n" + data.errorString();
|
QString error = tr("Error loading data file:") + "\n"
|
||||||
if (data.errorLine())
|
+ Util::displayName(fileName) + ": " + data.errorString();
|
||||||
error.append("\n" + tr("Line: %1").arg(data.errorLine()));
|
if (data.errorLine())
|
||||||
QMessageBox::critical(this, APP_NAME, error);
|
error.append("\n" + tr("Line: %1").arg(data.errorLine()));
|
||||||
return false;
|
|
||||||
} else
|
if (showError > 1) {
|
||||||
|
QMessageBox message(QMessageBox::Critical, APP_NAME, error,
|
||||||
|
QMessageBox::Ok, this);
|
||||||
|
QCheckBox checkBox(tr("Don't show again"));
|
||||||
|
message.setCheckBox(&checkBox);
|
||||||
|
message.exec();
|
||||||
|
if (checkBox.isChecked())
|
||||||
|
showError = 0;
|
||||||
|
} else
|
||||||
|
QMessageBox::critical(this, APP_NAME, error);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::loadData(const Data &data)
|
void GUI::loadData(const Data &data)
|
||||||
@ -1108,8 +1123,8 @@ bool GUI::openPOIFile(const QString &fileName)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
QString error = tr("Error loading POI file:") + "\n\n"
|
QString error = tr("Error loading POI file:") + "\n"
|
||||||
+ Util::displayName(fileName) + "\n\n" + _poi->errorString();
|
+ Util::displayName(fileName) + ": " + _poi->errorString();
|
||||||
if (_poi->errorLine())
|
if (_poi->errorLine())
|
||||||
error.append("\n" + tr("Line: %1").arg(_poi->errorLine()));
|
error.append("\n" + tr("Line: %1").arg(_poi->errorLine()));
|
||||||
QMessageBox::critical(this, APP_NAME, error);
|
QMessageBox::critical(this, APP_NAME, error);
|
||||||
@ -1466,8 +1481,9 @@ void GUI::reloadFiles()
|
|||||||
_tabs.at(i)->clear();
|
_tabs.at(i)->clear();
|
||||||
_mapView->clear();
|
_mapView->clear();
|
||||||
|
|
||||||
|
int showError = 2;
|
||||||
for (int i = 0; i < _files.size(); i++) {
|
for (int i = 0; i < _files.size(); i++) {
|
||||||
if (!loadFile(_files.at(i))) {
|
if (!loadFile(_files.at(i), true, showError)) {
|
||||||
_files.removeAt(i);
|
_files.removeAt(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
@ -1692,8 +1708,8 @@ bool GUI::loadMapNode(const TreeNode<Map*> &node, MapAction *&action,
|
|||||||
if (!map->isValid()) {
|
if (!map->isValid()) {
|
||||||
if (!silent)
|
if (!silent)
|
||||||
QMessageBox::critical(this, APP_NAME,
|
QMessageBox::critical(this, APP_NAME,
|
||||||
tr("Error loading map:") + "\n\n"
|
tr("Error loading map:") + "\n"
|
||||||
+ Util::displayName(map->path()) + "\n\n"
|
+ Util::displayName(map->path()) + ": "
|
||||||
+ map->errorString());
|
+ map->errorString());
|
||||||
delete map;
|
delete map;
|
||||||
} else {
|
} else {
|
||||||
@ -1737,8 +1753,8 @@ void GUI::mapLoaded()
|
|||||||
_showMapAction->setEnabled(true);
|
_showMapAction->setEnabled(true);
|
||||||
_clearMapCacheAction->setEnabled(true);
|
_clearMapCacheAction->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
QString error = tr("Error loading map:") + "\n\n"
|
QString error = tr("Error loading map:") + "\n"
|
||||||
+ Util::displayName(map->path()) + "\n\n" + map->errorString();
|
+ Util::displayName(map->path()) + ": " + map->errorString();
|
||||||
QMessageBox::critical(this, APP_NAME, error);
|
QMessageBox::critical(this, APP_NAME, error);
|
||||||
action->deleteLater();
|
action->deleteLater();
|
||||||
}
|
}
|
||||||
@ -1756,8 +1772,8 @@ void GUI::mapLoadedDir()
|
|||||||
actions.append(action);
|
actions.append(action);
|
||||||
_mapView->loadMaps(actions);
|
_mapView->loadMaps(actions);
|
||||||
} else {
|
} else {
|
||||||
QString error = tr("Error loading map:") + "\n\n"
|
QString error = tr("Error loading map:") + "\n"
|
||||||
+ Util::displayName(map->path()) + "\n\n" + map->errorString();
|
+ Util::displayName(map->path()) + ": " + map->errorString();
|
||||||
QMessageBox::critical(this, APP_NAME, error);
|
QMessageBox::critical(this, APP_NAME, error);
|
||||||
action->deleteLater();
|
action->deleteLater();
|
||||||
}
|
}
|
||||||
@ -1779,7 +1795,7 @@ void GUI::loadMapDirNode(const TreeNode<Map *> &node, QList<MapAction*> &actions
|
|||||||
if (!(a = findMapAction(existingActions, map))) {
|
if (!(a = findMapAction(existingActions, map))) {
|
||||||
if (!map->isValid()) {
|
if (!map->isValid()) {
|
||||||
QMessageBox::critical(this, APP_NAME, tr("Error loading map:")
|
QMessageBox::critical(this, APP_NAME, tr("Error loading map:")
|
||||||
+ "\n\n" + Util::displayName(map->path()) + "\n\n"
|
+ "\n" + Util::displayName(map->path()) + ": "
|
||||||
+ map->errorString());
|
+ map->errorString());
|
||||||
delete map;
|
delete map;
|
||||||
} else {
|
} else {
|
||||||
@ -2080,48 +2096,53 @@ void GUI::setGraphType(GraphType type)
|
|||||||
|
|
||||||
void GUI::next()
|
void GUI::next()
|
||||||
{
|
{
|
||||||
|
int showError = 1;
|
||||||
QString file = _browser->next();
|
QString file = _browser->next();
|
||||||
if (file.isNull())
|
if (file.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
closeFiles();
|
closeFiles();
|
||||||
openFile(file);
|
openFile(file, true, showError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::prev()
|
void GUI::prev()
|
||||||
{
|
{
|
||||||
|
int showError = 1;
|
||||||
QString file = _browser->prev();
|
QString file = _browser->prev();
|
||||||
if (file.isNull())
|
if (file.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
closeFiles();
|
closeFiles();
|
||||||
openFile(file);
|
openFile(file, true, showError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::last()
|
void GUI::last()
|
||||||
{
|
{
|
||||||
|
int showError = 1;
|
||||||
QString file = _browser->last();
|
QString file = _browser->last();
|
||||||
if (file.isNull())
|
if (file.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
closeFiles();
|
closeFiles();
|
||||||
openFile(file);
|
openFile(file, true, showError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::first()
|
void GUI::first()
|
||||||
{
|
{
|
||||||
|
int showError = 1;
|
||||||
QString file = _browser->first();
|
QString file = _browser->first();
|
||||||
if (file.isNull())
|
if (file.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
closeFiles();
|
closeFiles();
|
||||||
openFile(file);
|
openFile(file, true, showError);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
void GUI::keyPressEvent(QKeyEvent *event)
|
void GUI::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
QString file;
|
QString file;
|
||||||
|
int showError = 1;
|
||||||
|
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
case PREV_KEY:
|
case PREV_KEY:
|
||||||
@ -2167,7 +2188,7 @@ void GUI::keyPressEvent(QKeyEvent *event)
|
|||||||
if (!file.isNull()) {
|
if (!file.isNull()) {
|
||||||
if (!(event->modifiers() & MODIFIER))
|
if (!(event->modifiers() & MODIFIER))
|
||||||
closeFiles();
|
closeFiles();
|
||||||
openFile(file);
|
openFile(file, false, showError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2200,14 +2221,16 @@ void GUI::dropEvent(QDropEvent *event)
|
|||||||
{
|
{
|
||||||
MapAction *lastReady = 0;
|
MapAction *lastReady = 0;
|
||||||
QList<QUrl> urls(event->mimeData()->urls());
|
QList<QUrl> urls(event->mimeData()->urls());
|
||||||
|
int silent = 0;
|
||||||
|
int showError = (urls.size() > 1) ? 2 : 1;
|
||||||
|
|
||||||
for (int i = 0; i < urls.size(); i++) {
|
for (int i = 0; i < urls.size(); i++) {
|
||||||
QString file(urls.at(i).toLocalFile());
|
QString file(urls.at(i).toLocalFile());
|
||||||
|
|
||||||
if (!openFile(file, true)) {
|
if (!openFile(file, false, silent)) {
|
||||||
MapAction *a;
|
MapAction *a;
|
||||||
if (!loadMap(file, a, true))
|
if (!loadMap(file, a, true))
|
||||||
openFile(file, false);
|
openFile(file, true, showError);
|
||||||
else {
|
else {
|
||||||
if (a)
|
if (a)
|
||||||
lastReady = a;
|
lastReady = a;
|
||||||
|
@ -44,7 +44,7 @@ class GUI : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
GUI();
|
GUI();
|
||||||
|
|
||||||
bool openFile(const QString &fileName, bool silent = false);
|
bool openFile(const QString &fileName, bool tryUnknown, int &showError);
|
||||||
bool loadMap(const QString &fileName, MapAction *&action,
|
bool loadMap(const QString &fileName, MapAction *&action,
|
||||||
bool silent = false);
|
bool silent = false);
|
||||||
void show();
|
void show();
|
||||||
@ -151,7 +151,7 @@ private:
|
|||||||
void createBrowser();
|
void createBrowser();
|
||||||
|
|
||||||
bool openPOIFile(const QString &fileName);
|
bool openPOIFile(const QString &fileName);
|
||||||
bool loadFile(const QString &fileName, bool silent = false);
|
bool loadFile(const QString &fileName, bool tryUnknown, int &showError);
|
||||||
void loadData(const Data &data);
|
void loadData(const Data &data);
|
||||||
bool loadMapNode(const TreeNode<Map*> &node, MapAction *&action,
|
bool loadMapNode(const TreeNode<Map*> &node, MapAction *&action,
|
||||||
bool silent, const QList<QAction*> &existingActions);
|
bool silent, const QList<QAction*> &existingActions);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
class Data
|
class Data
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Data(const QString &fileName, bool full = true);
|
Data(const QString &fileName, bool tryUnknown = true);
|
||||||
|
|
||||||
bool isValid() const {return _valid;}
|
bool isValid() const {return _valid;}
|
||||||
const QString &errorString() const {return _errorString;}
|
const QString &errorString() const {return _errorString;}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user