1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/GUI/app.cpp

110 lines
2.5 KiB
C++
Raw Normal View History

#include <QtGlobal>
#include <QTranslator>
#include <QLocale>
#include <QFileOpenEvent>
#include <QNetworkProxyFactory>
#include <QLibraryInfo>
2017-11-26 18:54:03 +01:00
#include "map/onlinemap.h"
#include "map/downloader.h"
#include "map/ellipsoid.h"
#include "map/datum.h"
2016-12-20 00:11:30 +01:00
#include "opengl.h"
#include "gui.h"
#include "config.h"
#include "app.h"
App::App(int &argc, char **argv) : QApplication(argc, argv),
_argc(argc), _argv(argv)
{
QTranslator *gpxsee = new QTranslator(this);
QString locale = QLocale::system().name();
gpxsee->load(QString(":/lang/gpxsee_") + locale);
installTranslator(gpxsee);
QTranslator *qt = new QTranslator(this);
2017-06-18 16:06:59 +02:00
qt->load(QLocale::system(), "qt", "_", QLibraryInfo::location(
QLibraryInfo::TranslationsPath));
installTranslator(qt);
#ifdef Q_OS_MAC
setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // Q_OS_MAC
QNetworkProxyFactory::setUseSystemConfiguration(true);
OnlineMap::setDownloader(new Downloader(this));
2016-12-20 00:11:30 +01:00
OPENGL_SET_SAMPLES(4);
loadDatums();
2016-12-06 01:48:26 +01:00
_gui = new GUI();
}
App::~App()
{
delete _gui;
}
void App::run()
{
_gui->show();
for (int i = 1; i < _argc; i++)
_gui->openFile(QString::fromLocal8Bit(_argv[i]));
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 ef, df;
bool ok = false;
if (QFile::exists(USER_ELLIPSOID_FILE))
ef = USER_ELLIPSOID_FILE;
else if (QFile::exists(GLOBAL_ELLIPSOID_FILE))
ef = GLOBAL_ELLIPSOID_FILE;
else
qWarning("No ellipsoids file found.");
if (QFile::exists(USER_DATUM_FILE))
df = USER_DATUM_FILE;
else if (QFile::exists(GLOBAL_DATUM_FILE))
df = GLOBAL_DATUM_FILE;
else
qWarning("No datums file found.");
if (!ef.isNull() && !df.isNull()) {
if (!Ellipsoid::loadList(ef)) {
if (Ellipsoid::errorLine())
qWarning("%s: parse error on line %d: %s", qPrintable(ef),
Ellipsoid::errorLine(), qPrintable(Ellipsoid::errorString()));
else
qWarning("%s: %s", qPrintable(ef), qPrintable(
Ellipsoid::errorString()));
} else {
if (!Datum::loadList(df)) {
if (Datum::errorLine())
2017-12-23 11:10:39 +01:00
qWarning("%s: parse error on line %d: %s", qPrintable(df),
Datum::errorLine(), qPrintable(Datum::errorString()));
else
qWarning("%s: %s", qPrintable(ef), qPrintable(
Datum::errorString()));
} else
ok = true;
}
}
if (!ok)
qWarning("Maps based on a datum different from WGS84 won't work.");
}