1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/GUI/app.cpp

124 lines
3.0 KiB
C++
Raw Normal View History

#include <QtGlobal>
#include <QTranslator>
#include <QLocale>
#include <QFileOpenEvent>
#include <QNetworkProxyFactory>
#include <QNetworkAccessManager>
#include <QLibraryInfo>
2018-10-07 14:22:13 +02:00
#include <QSettings>
#include "common/programpaths.h"
#include "common/config.h"
2017-11-26 18:54:03 +01:00
#include "map/downloader.h"
#include "map/ellipsoid.h"
#include "map/gcs.h"
2018-01-08 23:47:45 +01:00
#include "map/pcs.h"
2016-12-20 00:11:30 +01:00
#include "opengl.h"
#include "gui.h"
2018-10-07 14:22:13 +02:00
#include "settings.h"
#include "app.h"
App::App(int &argc, char **argv) : QApplication(argc, argv),
_argc(argc), _argv(argv)
{
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
setApplicationName(APP_NAME);
#else
setApplicationName(QString(APP_NAME).toLower());
#endif
setApplicationVersion(APP_VERSION);
QTranslator *gpxsee = new QTranslator(this);
gpxsee->load(QLocale::system(), "gpxsee", "_",
ProgramPaths::translationsDir());
installTranslator(gpxsee);
QTranslator *qt = new QTranslator(this);
2018-03-29 00:29:08 +02:00
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
qt->load(QLocale::system(), "qt", "_", ProgramPaths::translationsDir());
2018-03-29 00:29:08 +02:00
#else // Q_OS_WIN32 || Q_OS_MAC
2017-06-18 16:06:59 +02:00
qt->load(QLocale::system(), "qt", "_", QLibraryInfo::location(
QLibraryInfo::TranslationsPath));
2018-03-29 00:29:08 +02:00
#endif // Q_OS_WIN32 || Q_OS_MAC
installTranslator(qt);
#ifdef Q_OS_MAC
setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // Q_OS_MAC
QNetworkProxyFactory::setUseSystemConfiguration(true);
2018-10-07 14:22:13 +02:00
QSettings settings(APP_NAME, APP_NAME);
settings.beginGroup(OPTIONS_SETTINGS_GROUP);
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));
2018-10-07 14:22:13 +02:00
#ifdef ENABLE_HTTP2
Downloader::enableHTTP2(settings.value(ENABLE_HTTP2_SETTING,
ENABLE_HTTP2_DEFAULT).toBool());
#endif // ENABLE_HTTP2
Downloader::setTimeout(settings.value(CONNECTION_TIMEOUT_SETTING,
CONNECTION_TIMEOUT_DEFAULT).toInt());
settings.endGroup();
2016-12-20 00:11:30 +01:00
OPENGL_SET_SAMPLES(4);
loadDatums();
2018-01-08 23:47:45 +01:00
loadPCSs();
2016-12-06 01:48:26 +01:00
_gui = new GUI();
}
App::~App()
{
delete _gui;
}
int App::run()
{
_gui->show();
QStringList args(arguments());
for (int i = 1; i < args.count(); i++)
_gui->openFile(args.at(i));
return exec();
}
bool App::event(QEvent *event)
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *e = static_cast<QFileOpenEvent *>(event);
return _gui->openFile(e->file());
}
return QApplication::event(event);
}
void App::loadDatums()
{
QString ellipsoidsFile(ProgramPaths::ellipsoidsFile());
QString gcsFile(ProgramPaths::gcsFile());
if (ellipsoidsFile.isNull())
qWarning("No ellipsoids file found.");
if (gcsFile.isNull())
qWarning("No GCS file found.");
if (!ellipsoidsFile.isNull() && !gcsFile.isNull()) {
Ellipsoid::loadList(ellipsoidsFile);
GCS::loadList(gcsFile);
} else
qWarning("Maps based on a datum different from WGS84 won't work.");
}
2018-01-08 23:47:45 +01:00
void App::loadPCSs()
{
QString pcsFile(ProgramPaths::pcsFile());
2018-01-08 23:47:45 +01:00
if (pcsFile.isNull())
2018-01-08 23:47:45 +01:00
qWarning("No PCS file found.");
else
PCS::loadList(pcsFile);
2018-01-08 23:47:45 +01:00
}