2017-04-27 18:24:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-06-16 13:52:06 +00:00
|
|
|
#include <QApplication>
|
2018-07-13 20:40:02 +00:00
|
|
|
#include <Qt>
|
2015-06-16 13:52:06 +00:00
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QTextCodec>
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "qthelper.h"
|
2018-08-15 09:54:37 +00:00
|
|
|
#include "core/settings/qPref.h"
|
2015-06-16 13:52:06 +00:00
|
|
|
|
2016-04-29 13:17:02 +00:00
|
|
|
char *settings_suffix = NULL;
|
2017-12-22 13:02:07 +00:00
|
|
|
static QTranslator *qtTranslator, *ssrfTranslator;
|
2016-04-29 13:17:02 +00:00
|
|
|
|
2015-06-16 13:52:06 +00:00
|
|
|
void init_qt_late()
|
|
|
|
{
|
|
|
|
QApplication *application = qApp;
|
|
|
|
// tell Qt to use system proxies
|
|
|
|
// note: on Linux, "system" == "environment variables"
|
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
|
|
|
|
2018-03-13 17:50:01 +00:00
|
|
|
// Set the locale codec to UTF-8.
|
|
|
|
// This makes QFile::encodeName() work on Windows and qPrintable() is equivalent to qUtf8Printable().
|
2015-06-16 13:52:06 +00:00
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
|
|
|
|
|
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
2018-09-03 20:05:48 +00:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && defined(Q_OS_LINUX)
|
|
|
|
QGuiApplication::setDesktopFileName("subsurface");
|
|
|
|
#endif
|
2016-04-29 13:17:02 +00:00
|
|
|
// enable user specific settings (based on command line argument)
|
|
|
|
if (settings_suffix) {
|
|
|
|
if (verbose)
|
2018-01-18 14:30:55 +00:00
|
|
|
#if defined(SUBSURFACE_MOBILE) && ((defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || (defined(Q_OS_DARWIN) && !defined(Q_OS_IOS)))
|
|
|
|
qDebug() << "using custom config for" << QString("Subsurface-Mobile-%1").arg(settings_suffix);
|
|
|
|
#else
|
2016-04-29 13:17:02 +00:00
|
|
|
qDebug() << "using custom config for" << QString("Subsurface-%1").arg(settings_suffix);
|
2018-01-18 14:30:55 +00:00
|
|
|
#endif
|
|
|
|
#if defined(SUBSURFACE_MOBILE) && ((defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || (defined(Q_OS_DARWIN) && !defined(Q_OS_IOS)))
|
|
|
|
QCoreApplication::setApplicationName(QString("Subsurface-Mobile-%1").arg(settings_suffix));
|
|
|
|
#else
|
2016-04-29 13:17:02 +00:00
|
|
|
QCoreApplication::setApplicationName(QString("Subsurface-%1").arg(settings_suffix));
|
2018-01-18 14:30:55 +00:00
|
|
|
#endif
|
2016-04-29 13:17:02 +00:00
|
|
|
} else {
|
2018-01-18 14:30:55 +00:00
|
|
|
#if defined(SUBSURFACE_MOBILE) && ((defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || (defined(Q_OS_DARWIN) && !defined(Q_OS_IOS)))
|
|
|
|
QCoreApplication::setApplicationName("Subsurface-Mobile");
|
|
|
|
#else
|
2016-04-29 13:17:02 +00:00
|
|
|
QCoreApplication::setApplicationName("Subsurface");
|
2018-01-18 14:30:55 +00:00
|
|
|
#endif
|
2016-04-29 13:17:02 +00:00
|
|
|
}
|
2018-07-13 20:40:02 +00:00
|
|
|
// Disables the WindowContextHelpButtonHint by default on Qt::Sheet and Qt::Dialog widgets.
|
|
|
|
// This hides the ? button on Windows, which only makes sense if you use QWhatsThis functionality.
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
|
|
|
|
#endif
|
2018-08-14 08:07:22 +00:00
|
|
|
qPref::load();
|
2016-08-26 19:52:51 +00:00
|
|
|
|
2018-11-01 16:30:14 +00:00
|
|
|
// find plugins installed in the application directory (without this SVGs don't work on Windows)
|
2015-06-16 13:52:06 +00:00
|
|
|
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
|
|
|
|
QLocale loc;
|
2018-11-01 16:30:14 +00:00
|
|
|
|
|
|
|
// assign en_GB for use in South African locale
|
|
|
|
if (loc.country() == QLocale::SouthAfrica) {
|
|
|
|
loc.setDefault(QLocale("en_GB"));
|
|
|
|
loc = QLocale();
|
|
|
|
}
|
2015-06-16 13:52:06 +00:00
|
|
|
QString uiLang = uiLanguage(&loc);
|
|
|
|
QLocale::setDefault(loc);
|
|
|
|
|
2017-06-22 10:38:09 +00:00
|
|
|
qtTranslator = new QTranslator;
|
|
|
|
QString translationLocation;
|
2016-05-04 20:51:55 +00:00
|
|
|
#if defined(Q_OS_ANDROID)
|
2017-06-22 10:38:09 +00:00
|
|
|
translationLocation = QLatin1Literal("assets:/translations");
|
2016-05-04 20:51:55 +00:00
|
|
|
#elif defined(Q_OS_IOS)
|
2018-07-03 18:46:24 +00:00
|
|
|
translationLocation = QLatin1Literal(":/");
|
2016-05-04 00:20:53 +00:00
|
|
|
#else
|
2017-06-22 10:38:09 +00:00
|
|
|
translationLocation = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
2016-05-04 00:20:53 +00:00
|
|
|
#endif
|
2017-06-22 10:38:09 +00:00
|
|
|
if (qtTranslator->load(loc, "qt", "_", translationLocation)) {
|
|
|
|
application->installTranslator(qtTranslator);
|
|
|
|
} else {
|
2017-10-20 10:26:28 +00:00
|
|
|
if (verbose && uiLang != "en_US" && uiLang != "en-US")
|
2017-07-03 20:29:25 +00:00
|
|
|
qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << translationLocation;
|
2017-06-22 10:38:09 +00:00
|
|
|
}
|
|
|
|
ssrfTranslator = new QTranslator;
|
|
|
|
if (ssrfTranslator->load(loc, "subsurface", "_") ||
|
|
|
|
ssrfTranslator->load(loc, "subsurface", "_", translationLocation) ||
|
|
|
|
ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("translations")) ||
|
|
|
|
ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("../translations"))) {
|
|
|
|
application->installTranslator(ssrfTranslator);
|
|
|
|
} else {
|
|
|
|
qDebug() << "can't find Subsurface localization for locale" << uiLang;
|
2015-06-16 13:52:06 +00:00
|
|
|
}
|
|
|
|
}
|