2016-04-29 21:13:38 +02:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QFileOpenEvent>
|
2016-09-22 20:57:58 +02:00
|
|
|
#include <QNetworkProxyFactory>
|
2018-04-27 19:31:27 +02:00
|
|
|
#include <QNetworkAccessManager>
|
2017-05-31 23:37:02 +02:00
|
|
|
#include <QLibraryInfo>
|
2020-12-22 22:09:09 +01:00
|
|
|
#include <QSurfaceFormat>
|
2018-11-02 20:01:19 +01:00
|
|
|
#include "common/programpaths.h"
|
|
|
|
#include "common/config.h"
|
2021-08-26 22:22:18 +02:00
|
|
|
#include "common/downloader.h"
|
2017-11-26 22:52:50 +01:00
|
|
|
#include "map/ellipsoid.h"
|
2018-01-20 20:13:56 +01:00
|
|
|
#include "map/gcs.h"
|
2018-01-08 23:47:45 +01:00
|
|
|
#include "map/pcs.h"
|
2019-01-17 00:47:44 +01:00
|
|
|
#include "data/dem.h"
|
2021-10-10 08:38:38 +02:00
|
|
|
#include "data/waypoint.h"
|
2016-04-29 21:13:38 +02:00
|
|
|
#include "gui.h"
|
2020-12-06 19:17:09 +01:00
|
|
|
#include "mapaction.h"
|
2016-04-29 21:13:38 +02:00
|
|
|
#include "app.h"
|
|
|
|
|
|
|
|
|
2019-01-04 18:58:16 +01:00
|
|
|
App::App(int &argc, char **argv) : QApplication(argc, argv)
|
2016-04-29 21:13:38 +02:00
|
|
|
{
|
2018-11-02 20:01:19 +01:00
|
|
|
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
|
|
|
|
setApplicationName(APP_NAME);
|
|
|
|
#else
|
|
|
|
setApplicationName(QString(APP_NAME).toLower());
|
|
|
|
#endif
|
|
|
|
setApplicationVersion(APP_VERSION);
|
|
|
|
|
2017-05-31 23:37:02 +02:00
|
|
|
QTranslator *gpxsee = new QTranslator(this);
|
2020-12-27 00:00:59 +01:00
|
|
|
if (gpxsee->load(QLocale::system(), "gpxsee", "_",
|
|
|
|
ProgramPaths::translationsDir()))
|
|
|
|
installTranslator(gpxsee);
|
2017-05-31 23:37:02 +02:00
|
|
|
|
|
|
|
QTranslator *qt = new QTranslator(this);
|
2018-03-29 00:29:08 +02:00
|
|
|
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
|
2020-12-27 00:00:59 +01:00
|
|
|
if (qt->load(QLocale::system(), "qt", "_", ProgramPaths::translationsDir()))
|
2018-03-29 00:29:08 +02:00
|
|
|
#else // Q_OS_WIN32 || Q_OS_MAC
|
2020-12-27 00:00:59 +01:00
|
|
|
if (qt->load(QLocale::system(), "qt", "_", QLibraryInfo::location(
|
|
|
|
QLibraryInfo::TranslationsPath)))
|
2018-03-29 00:29:08 +02:00
|
|
|
#endif // Q_OS_WIN32 || Q_OS_MAC
|
2020-12-27 00:00:59 +01:00
|
|
|
installTranslator(qt);
|
2017-05-31 23:37:02 +02:00
|
|
|
|
2016-04-29 21:13:38 +02:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
setAttribute(Qt::AA_DontShowIconsInMenus);
|
|
|
|
#endif // Q_OS_MAC
|
2016-09-22 20:57:58 +02:00
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
2018-10-08 22:07:36 +02:00
|
|
|
/* The QNetworkAccessManager must be a child of QApplication, otherwise it
|
|
|
|
triggers the following warning on exit (and may probably crash):
|
|
|
|
"QThreadStorage: Thread X exited after QThreadStorage Y destroyed" */
|
|
|
|
Downloader::setNetworkManager(new QNetworkAccessManager(this));
|
2019-01-21 23:40:29 +01:00
|
|
|
DEM::setDir(ProgramPaths::demDir());
|
2020-12-22 22:09:09 +01:00
|
|
|
QSurfaceFormat fmt;
|
|
|
|
fmt.setStencilBufferSize(8);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QSurfaceFormat::setDefaultFormat(fmt);
|
2019-01-21 23:40:29 +01:00
|
|
|
|
|
|
|
loadDatums();
|
|
|
|
loadPCSs();
|
2021-10-10 08:38:38 +02:00
|
|
|
Waypoint::loadSymbolIcons(ProgramPaths::symbolsDir());
|
2019-01-21 23:40:29 +01:00
|
|
|
|
2016-04-29 21:13:38 +02:00
|
|
|
_gui = new GUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
App::~App()
|
|
|
|
{
|
|
|
|
delete _gui;
|
|
|
|
}
|
|
|
|
|
2018-11-02 20:01:19 +01:00
|
|
|
int App::run()
|
2016-04-29 21:13:38 +02:00
|
|
|
{
|
2020-12-06 23:31:45 +01:00
|
|
|
MapAction *lastReady = 0;
|
|
|
|
QStringList args(arguments());
|
|
|
|
|
2016-04-29 21:13:38 +02:00
|
|
|
_gui->show();
|
|
|
|
|
2020-12-06 19:17:09 +01:00
|
|
|
for (int i = 1; i < args.count(); i++) {
|
|
|
|
if (!_gui->openFile(args.at(i), true)) {
|
|
|
|
MapAction *a;
|
|
|
|
if (!_gui->loadMap(args.at(i), a, true))
|
|
|
|
_gui->openFile(args.at(i), false);
|
|
|
|
else {
|
|
|
|
if (a)
|
2020-12-06 23:31:45 +01:00
|
|
|
lastReady = a;
|
2020-12-06 19:17:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 21:13:38 +02:00
|
|
|
|
2020-12-06 23:31:45 +01:00
|
|
|
if (lastReady)
|
|
|
|
lastReady->trigger();
|
|
|
|
|
2018-11-02 20:01:19 +01:00
|
|
|
return exec();
|
2016-04-29 21:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool App::event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::FileOpen) {
|
|
|
|
QFileOpenEvent *e = static_cast<QFileOpenEvent *>(event);
|
2020-12-06 19:17:09 +01:00
|
|
|
|
|
|
|
if (!_gui->openFile(e->file(), true)) {
|
|
|
|
MapAction *a;
|
|
|
|
if (!_gui->loadMap(e->file(), a, true))
|
|
|
|
return _gui->openFile(e->file(), false);
|
|
|
|
else {
|
|
|
|
if (a)
|
|
|
|
a->trigger();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return true;
|
2016-04-29 21:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return QApplication::event(event);
|
|
|
|
}
|
2017-11-26 22:52:50 +01:00
|
|
|
|
|
|
|
void App::loadDatums()
|
|
|
|
{
|
2018-11-02 20:01:19 +01:00
|
|
|
QString ellipsoidsFile(ProgramPaths::ellipsoidsFile());
|
|
|
|
QString gcsFile(ProgramPaths::gcsFile());
|
2017-11-26 22:52:50 +01:00
|
|
|
|
2018-11-02 20:01:19 +01:00
|
|
|
if (ellipsoidsFile.isNull())
|
2017-11-26 22:52:50 +01:00
|
|
|
qWarning("No ellipsoids file found.");
|
2018-11-02 20:01:19 +01:00
|
|
|
if (gcsFile.isNull())
|
|
|
|
qWarning("No GCS file found.");
|
2017-11-26 22:52:50 +01:00
|
|
|
|
2018-11-02 20:01:19 +01:00
|
|
|
if (!ellipsoidsFile.isNull() && !gcsFile.isNull()) {
|
|
|
|
Ellipsoid::loadList(ellipsoidsFile);
|
|
|
|
GCS::loadList(gcsFile);
|
2018-01-20 20:13:56 +01:00
|
|
|
} else
|
2017-11-26 22:52:50 +01:00
|
|
|
qWarning("Maps based on a datum different from WGS84 won't work.");
|
|
|
|
}
|
2018-01-08 23:47:45 +01:00
|
|
|
|
|
|
|
void App::loadPCSs()
|
|
|
|
{
|
2018-11-02 20:01:19 +01:00
|
|
|
QString pcsFile(ProgramPaths::pcsFile());
|
2018-01-08 23:47:45 +01:00
|
|
|
|
2018-11-02 20:01:19 +01:00
|
|
|
if (pcsFile.isNull())
|
2018-01-08 23:47:45 +01:00
|
|
|
qWarning("No PCS file found.");
|
2018-11-02 20:01:19 +01:00
|
|
|
else
|
|
|
|
PCS::loadList(pcsFile);
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|