2022-02-10 01:19:43 +00:00
|
|
|
|
2017-04-27 18:24:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-06-16 13:52:06 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#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
|
|
|
|
2024-06-13 20:59:32 +00:00
|
|
|
std::string settings_suffix;
|
2022-03-26 21:03:55 +00:00
|
|
|
static QTranslator qtTranslator, ssrfTranslator, parentLanguageTranslator;
|
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)
|
2024-06-13 20:59:32 +00:00
|
|
|
if (!settings_suffix.empty()) {
|
2016-04-29 13:17:02 +00:00
|
|
|
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)))
|
2024-06-13 20:59:32 +00:00
|
|
|
report_info("using custom config for Subsurface-Mobile-%s", settings_suffix.c_str());
|
2018-01-18 14:30:55 +00:00
|
|
|
#else
|
2024-06-13 20:59:32 +00:00
|
|
|
report_info("using custom config for Subsurface-%s", settings_suffix.c_str());
|
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)))
|
2024-06-13 20:59:32 +00:00
|
|
|
QCoreApplication::setApplicationName(QString::fromStdString("Subsurface-Mobile-" + settings_suffix));
|
2018-01-18 14:30:55 +00:00
|
|
|
#else
|
2024-06-13 20:59:32 +00:00
|
|
|
QCoreApplication::setApplicationName(QString::fromStdString("Subsurface-" + 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.
|
2022-02-10 01:19:43 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2018-07-13 20:40:02 +00:00
|
|
|
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();
|
|
|
|
}
|
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(":/");
|
2022-02-15 20:20:49 +00:00
|
|
|
#else
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
translationLocation = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
|
2016-05-04 00:20:53 +00:00
|
|
|
#else
|
2017-06-22 10:38:09 +00:00
|
|
|
translationLocation = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
2022-02-15 20:20:49 +00:00
|
|
|
#endif
|
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 {
|
2024-03-26 14:42:31 +00:00
|
|
|
report_info("can't find Qt base localization for locale %s searching in %s", qPrintable(uiLang), qPrintable(translationLocation));
|
2020-09-15 18:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-22 10:38:09 +00:00
|
|
|
}
|
2022-03-26 21:03:55 +00:00
|
|
|
// when creating our language names, we didn't define generic languages with additional
|
|
|
|
// country specific extensions, instead we included the "primary" country in the
|
|
|
|
// translation designations. This breaks the way Qt finds fall-back translations.
|
|
|
|
// Changing this now seems rather tedious, so instead we manually create a few
|
|
|
|
// obvious fallbacks
|
|
|
|
QPair<QLocale::Language, QLocale::Country> parents[] = {
|
|
|
|
{ QLocale::German, QLocale::Germany },
|
2022-03-28 00:10:46 +00:00
|
|
|
{ QLocale::Portuguese, QLocale::Portugal },
|
2022-03-26 21:03:55 +00:00
|
|
|
{ QLocale::French, QLocale::France},
|
|
|
|
{ QLocale::Spanish, QLocale::Spain}
|
|
|
|
};
|
|
|
|
for (auto parent: parents) {
|
|
|
|
if (loc.language() == parent.first && loc.country() != parent.second) {
|
|
|
|
// first load de_DE so it's used as fall-back
|
|
|
|
QLocale parentLoc = QLocale(parent.first, parent.second);
|
|
|
|
if (parentLanguageTranslator.load(parentLoc, "subsurface", "_") ||
|
|
|
|
parentLanguageTranslator.load(parentLoc, "subsurface", "_", translationLocation) ||
|
|
|
|
parentLanguageTranslator.load(parentLoc, "subsurface", "_", getSubsurfaceDataPath("translations")) ||
|
|
|
|
parentLanguageTranslator.load(parentLoc, "subsurface", "_", getSubsurfaceDataPath("../translations"))) {
|
|
|
|
if (verbose)
|
2024-03-26 14:42:31 +00:00
|
|
|
report_info("loading %s translations", qPrintable(parentLoc.name()));
|
2022-03-26 21:03:55 +00:00
|
|
|
application->installTranslator(&parentLanguageTranslator);
|
|
|
|
} else {
|
2024-03-26 14:42:31 +00:00
|
|
|
report_info("can't find Subsurface localization for locale %s", qPrintable(parentLoc.name()));
|
2022-03-26 21:03:55 +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"))) {
|
2022-03-26 21:03:55 +00:00
|
|
|
if (verbose)
|
2024-03-26 14:42:31 +00:00
|
|
|
report_info("loading %s translations", qPrintable(uiLang));
|
2020-03-22 15:54:52 +00:00
|
|
|
application->installTranslator(&ssrfTranslator);
|
2017-06-22 10:38:09 +00:00
|
|
|
} else {
|
2024-03-26 14:42:31 +00:00
|
|
|
report_info("can't find Subsurface localization for locale %s", qPrintable(uiLang));
|
2015-06-16 13:52:06 +00:00
|
|
|
}
|
|
|
|
}
|