4 #include <QFileOpenEvent>
5 #include <QNetworkProxyFactory>
6 #include <QNetworkAccessManager>
7 #include <QLibraryInfo>
8 #include <QSurfaceFormat>
9 #include <QImageReader>
12 #include <QCoreApplication>
14 #endif // Q_OS_ANDROID
15 #include "common/programpaths.h"
16 #include "common/config.h"
17 #include "common/downloader.h"
18 #include "map/ellipsoid.h"
20 #include "map/conversion.h"
23 #include "data/waypoint.h"
25 #include "mapaction.h"
29 App::App(int &argc
, char **argv
) : QApplication(argc
, argv
)
31 #if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
32 setApplicationName(APP_NAME
);
34 setApplicationName(QString(APP_NAME
).toLower());
36 setApplicationVersion(APP_VERSION
);
38 QTranslator
*app
= new QTranslator(this);
39 if (app
->load(QLocale::system(), "gpxsee", "_",
40 ProgramPaths::translationsDir()))
41 installTranslator(app
);
43 QTranslator
*qt
= new QTranslator(this);
44 #if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
45 if (qt
->load(QLocale::system(), "qt", "_", ProgramPaths::translationsDir()))
46 #else // Q_OS_WIN32 || Q_OS_MAC
47 if (qt
->load(QLocale::system(), "qt", "_", QLibraryInfo::location(
48 QLibraryInfo::TranslationsPath
)))
49 #endif // Q_OS_WIN32 || Q_OS_MAC
50 installTranslator(qt
);
53 setAttribute(Qt::AA_DontShowIconsInMenus
);
55 QNetworkProxyFactory::setUseSystemConfiguration(true);
56 /* The QNetworkAccessManager must be a child of QApplication, otherwise it
57 triggers the following warning on exit (and may probably crash):
58 "QThreadStorage: Thread X exited after QThreadStorage Y destroyed" */
59 Downloader::setNetworkManager(new QNetworkAccessManager(this));
60 DEM::setDir(ProgramPaths::demDir());
62 fmt
.setStencilBufferSize(8);
64 QSurfaceFormat::setDefaultFormat(fmt
);
65 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
66 QImageReader::setAllocationLimit(0);
71 Waypoint::loadSymbolIcons(ProgramPaths::symbolsDir());
76 connect(this, &App::applicationStateChanged
, this, &App::appStateChanged
);
77 #endif // Q_OS_ANDROID
87 MapAction
*lastReady
= 0;
88 QStringList
args(arguments());
90 int showError
= (args
.count() - 1 > 1) ? 2 : 1;
94 for (int i
= 1; i
< args
.count(); i
++) {
95 if (!_gui
->openFile(args
.at(i
), false, silent
)) {
97 if (!_gui
->loadMap(args
.at(i
), a
, silent
))
98 _gui
->openFile(args
.at(i
), true, showError
);
107 lastReady
->trigger();
113 void App::appStateChanged(Qt::ApplicationState state
)
115 if (state
== Qt::ApplicationSuspended
)
116 _gui
->writeSettings();
117 else if (state
== Qt::ApplicationActive
) {
118 QJniObject activity
= QNativeInterface::QAndroidApplication::context();
119 QString
path(activity
.callObjectMethod
<jstring
>("intentPath").toString());
120 if (!path
.isEmpty()) {
124 if (!_gui
->openFile(path
, false, silent
)) {
126 if (!_gui
->loadMap(path
, a
, silent
))
127 _gui
->openFile(path
, true, showError
);
136 #endif // Q_OS_ANDROID
138 bool App::event(QEvent
*event
)
143 if (event
->type() == QEvent::FileOpen
) {
144 QFileOpenEvent
*e
= static_cast<QFileOpenEvent
*>(event
);
146 if (!_gui
->openFile(e
->file(), false, silent
)) {
148 if (!_gui
->loadMap(e
->file(), a
, silent
))
149 return _gui
->openFile(e
->file(), true, showError
);
159 return QApplication::event(event
);
162 void App::loadDatums()
164 QString
ellipsoidsFile(ProgramPaths::ellipsoidsFile());
165 QString
gcsFile(ProgramPaths::gcsFile());
167 if (!QFileInfo::exists(ellipsoidsFile
)) {
168 qWarning("No ellipsoids file found.");
169 ellipsoidsFile
= QString();
170 } if (!QFileInfo::exists(gcsFile
)) {
171 qWarning("No GCS file found.");
175 if (!ellipsoidsFile
.isNull() && !gcsFile
.isNull()) {
176 Ellipsoid::loadList(ellipsoidsFile
);
177 GCS::loadList(gcsFile
);
179 qWarning("Maps based on a datum different from WGS84 won't work.");
184 QString
projectionsFile(ProgramPaths::projectionsFile());
185 QString
pcsFile(ProgramPaths::pcsFile());
187 if (!QFileInfo::exists(projectionsFile
)) {
188 qWarning("No projections file found.");
189 projectionsFile
= QString();
191 if (!QFileInfo::exists(pcsFile
)) {
192 qWarning("No PCS file found.");
196 if (!projectionsFile
.isNull() && !pcsFile
.isNull()) {
197 Conversion::loadList(projectionsFile
);
198 PCS::loadList(pcsFile
);
200 qWarning("Maps based on a projection different from EPSG:3857 won't work.");