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>
|
2020-12-28 13:30:57 +00:00
|
|
|
#include <QTranslator>
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "qthelper.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.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;
|
2020-03-22 15:54:52 +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");
|
2019-10-14 17:35:45 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
2018-09-03 20:05:48 +00:00
|
|
|
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
|
2019-11-21 05:17:28 +00:00
|
|
|
// and capture other French and Spanish speaking countries with the corresponding canonical locales
|
2018-11-01 16:30:14 +00:00
|
|
|
if (loc.country() == QLocale::SouthAfrica) {
|
|
|
|
loc.setDefault(QLocale("en_GB"));
|
|
|
|
loc = QLocale();
|
2019-11-21 05:17:28 +00: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 21:27:15 +00:00
|
|
|
} else if (loc.language() == QLocale::German && loc.country() != QLocale::Switzerland) {
|
|
|
|
loc.setDefault(QLocale("de_DE"));
|
|
|
|
loc = QLocale();
|
2018-11-01 16:30:14 +00:00
|
|
|
}
|
2020-03-22 15:43:21 +00:00
|
|
|
initUiLanguage();
|
|
|
|
QString uiLang = getUiLanguage();
|
|
|
|
loc = getLocale();
|
2015-06-16 13:52:06 +00:00
|
|
|
QLocale::setDefault(loc);
|
|
|
|
|
2017-06-22 10:38:09 +00:00
|
|
|
QString translationLocation;
|
2020-11-23 00:33:09 +00:00
|
|
|
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
|
2020-01-27 00:49:42 +00:00
|
|
|
translationLocation = QLatin1String(":/");
|
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
|
2020-09-15 18:54:07 +00:00
|
|
|
if (uiLang != "en_US" && uiLang != "en-US") {
|
|
|
|
if (qtTranslator.load(loc, "qtbase", "_", translationLocation) ||
|
|
|
|
qtTranslator.load(loc, "qtbase", "_", getSubsurfaceDataPath("translations")) ||
|
|
|
|
qtTranslator.load(loc, "qtbase", "_", getSubsurfaceDataPath("../translations"))) {
|
|
|
|
application->installTranslator(&qtTranslator);
|
|
|
|
} else {
|
|
|
|
// it's possible that this is one of the couple of languages that still have qt_XX translations
|
|
|
|
// and no qtbase_XX translations - as of this writing this is true for Swedish and Portuguese
|
|
|
|
if (qtTranslator.load(loc, "qt", "_", translationLocation) ||
|
|
|
|
qtTranslator.load(loc, "qt", "_", getSubsurfaceDataPath("translations")) ||
|
|
|
|
qtTranslator.load(loc, "qt", "_", getSubsurfaceDataPath("../translations"))) {
|
|
|
|
application->installTranslator(&qtTranslator);
|
|
|
|
} else {
|
|
|
|
qDebug() << "can't find Qt base localization for locale" << uiLang << "searching in" << translationLocation;
|
|
|
|
}
|
|
|
|
}
|
2017-06-22 10:38:09 +00:00
|
|
|
}
|
2020-03-22 15:54:52 +00: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 10:38:09 +00:00
|
|
|
} else {
|
|
|
|
qDebug() << "can't find Subsurface localization for locale" << uiLang;
|
2015-06-16 13:52:06 +00:00
|
|
|
}
|
|
|
|
}
|