2017-04-27 20:24:53 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-06-16 06:52:06 -07:00
|
|
|
#include <QApplication>
|
2018-07-13 22:40:02 +02:00
|
|
|
#include <Qt>
|
2015-06-16 06:52:06 -07:00
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QTextCodec>
|
2018-06-03 22:15:19 +02:00
|
|
|
#include "qthelper.h"
|
2019-08-05 19:41:15 +02:00
|
|
|
#include "errorhelper.h"
|
2018-08-15 11:54:37 +02:00
|
|
|
#include "core/settings/qPref.h"
|
2015-06-16 06:52:06 -07:00
|
|
|
|
2016-04-29 06:17:02 -07:00
|
|
|
char *settings_suffix = NULL;
|
2020-03-22 16:54:52 +01:00
|
|
|
static QTranslator qtTranslator, ssrfTranslator;
|
2016-04-29 06:17:02 -07:00
|
|
|
|
2015-06-16 06:52:06 -07: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 18:50:01 +01:00
|
|
|
// Set the locale codec to UTF-8.
|
|
|
|
// This makes QFile::encodeName() work on Windows and qPrintable() is equivalent to qUtf8Printable().
|
2015-06-16 06:52:06 -07:00
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
|
|
|
|
|
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
2019-10-14 10:35:45 -07:00
|
|
|
#if defined(Q_OS_LINUX)
|
2018-09-03 22:05:48 +02:00
|
|
|
QGuiApplication::setDesktopFileName("subsurface");
|
|
|
|
#endif
|
2016-04-29 06:17:02 -07:00
|
|
|
// enable user specific settings (based on command line argument)
|
|
|
|
if (settings_suffix) {
|
|
|
|
if (verbose)
|
2018-01-18 15:30:55 +01: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 06:17:02 -07:00
|
|
|
qDebug() << "using custom config for" << QString("Subsurface-%1").arg(settings_suffix);
|
2018-01-18 15:30:55 +01: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 06:17:02 -07:00
|
|
|
QCoreApplication::setApplicationName(QString("Subsurface-%1").arg(settings_suffix));
|
2018-01-18 15:30:55 +01:00
|
|
|
#endif
|
2016-04-29 06:17:02 -07:00
|
|
|
} else {
|
2018-01-18 15:30:55 +01: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 06:17:02 -07:00
|
|
|
QCoreApplication::setApplicationName("Subsurface");
|
2018-01-18 15:30:55 +01:00
|
|
|
#endif
|
2016-04-29 06:17:02 -07:00
|
|
|
}
|
2018-07-13 22:40:02 +02: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 10:07:22 +02:00
|
|
|
qPref::load();
|
2016-08-26 16:52:51 -03:00
|
|
|
|
2018-11-01 09:30:14 -07:00
|
|
|
// find plugins installed in the application directory (without this SVGs don't work on Windows)
|
2015-06-16 06:52:06 -07:00
|
|
|
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
|
|
|
|
QLocale loc;
|
2018-11-01 09:30:14 -07:00
|
|
|
|
|
|
|
// assign en_GB for use in South African locale
|
2019-11-20 21:17:28 -08:00
|
|
|
// and capture other French and Spanish speaking countries with the corresponding canonical locales
|
2018-11-01 09:30:14 -07:00
|
|
|
if (loc.country() == QLocale::SouthAfrica) {
|
|
|
|
loc.setDefault(QLocale("en_GB"));
|
|
|
|
loc = QLocale();
|
2019-11-20 21:17:28 -08:00
|
|
|
} else if (loc.language() == QLocale::French) {
|
|
|
|
loc.setDefault(QLocale("fr_FR"));
|
|
|
|
loc = QLocale();
|
|
|
|
} else if (loc.language() == QLocale::Spanish) {
|
|
|
|
loc.setDefault(QLocale("es_ES"));
|
|
|
|
loc = QLocale();
|
2020-03-21 14:27:15 -07:00
|
|
|
} else if (loc.language() == QLocale::German && loc.country() != QLocale::Switzerland) {
|
|
|
|
loc.setDefault(QLocale("de_DE"));
|
|
|
|
loc = QLocale();
|
2018-11-01 09:30:14 -07:00
|
|
|
}
|
2020-03-22 16:43:21 +01:00
|
|
|
initUiLanguage();
|
|
|
|
QString uiLang = getUiLanguage();
|
|
|
|
loc = getLocale();
|
2015-06-16 06:52:06 -07:00
|
|
|
QLocale::setDefault(loc);
|
|
|
|
|
2017-06-22 03:38:09 -07:00
|
|
|
QString translationLocation;
|
2016-05-04 13:51:55 -07:00
|
|
|
#if defined(Q_OS_ANDROID)
|
2020-01-26 16:49:42 -08:00
|
|
|
translationLocation = QLatin1String("assets:/translations");
|
2016-05-04 13:51:55 -07:00
|
|
|
#elif defined(Q_OS_IOS)
|
2020-01-26 16:49:42 -08:00
|
|
|
translationLocation = QLatin1String(":/");
|
2016-05-03 17:20:53 -07:00
|
|
|
#else
|
2017-06-22 03:38:09 -07:00
|
|
|
translationLocation = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
2016-05-03 17:20:53 -07:00
|
|
|
#endif
|
2020-03-22 16:54:52 +01:00
|
|
|
if (qtTranslator.load(loc, "qt", "_", translationLocation)) {
|
|
|
|
application->installTranslator(&qtTranslator);
|
2017-06-22 03:38:09 -07:00
|
|
|
} else {
|
2017-10-20 06:26:28 -04:00
|
|
|
if (verbose && uiLang != "en_US" && uiLang != "en-US")
|
2017-07-03 13:29:25 -07:00
|
|
|
qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << translationLocation;
|
2017-06-22 03:38:09 -07:00
|
|
|
}
|
2020-03-22 16:54:52 +01:00
|
|
|
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);
|
2017-06-22 03:38:09 -07:00
|
|
|
} else {
|
|
|
|
qDebug() << "can't find Subsurface localization for locale" << uiLang;
|
2015-06-16 06:52:06 -07:00
|
|
|
}
|
|
|
|
}
|