aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/GpgFrontendUIInit.cpp
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2024-01-30 05:38:51 +0000
committerGitHub <[email protected]>2024-01-30 05:38:51 +0000
commit60b8aafec9b59da71ae5c36708f5533870c2f499 (patch)
tree2118b1847c356a5b0a53a13785f1b4f932fefa9f /src/ui/GpgFrontendUIInit.cpp
parentMerge pull request #126 from saturneric/dev/2.1.1/main (diff)
parentdoc: update translations (diff)
downloadGpgFrontend-60b8aafec9b59da71ae5c36708f5533870c2f499.tar.gz
GpgFrontend-60b8aafec9b59da71ae5c36708f5533870c2f499.zip
Merge pull request #127 from saturneric/dev/2.1.1/main
Develop 2.1.2.2
Diffstat (limited to '')
-rw-r--r--src/ui/GpgFrontendUIInit.cpp64
1 files changed, 39 insertions, 25 deletions
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index eca77b76..148402d4 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -40,7 +40,7 @@
namespace GpgFrontend::UI {
-extern void InitLocale();
+extern void InitUITranslations();
void WaitEnvCheckingProcess() {
GF_UI_LOG_DEBUG("need to waiting for env checking process");
@@ -50,11 +50,12 @@ void WaitEnvCheckingProcess() {
waiting_dialog->setMaximum(0);
waiting_dialog->setMinimum(0);
auto* waiting_dialog_label = new QLabel(
- QObject::tr("Loading Gnupg Info...") + "<br /><br />" +
- QObject::tr("If this process is too slow, please set the key "
- "server address appropriately in the gnupg configuration "
- "file (depending "
- "on the network situation in your country or region)."));
+ QCoreApplication::tr("Loading Gnupg Info...") + "<br /><br />" +
+ QCoreApplication::tr(
+ "If this process is too slow, please set the key "
+ "server address appropriately in the gnupg configuration "
+ "file (depending "
+ "on the network situation in your country or region)."));
waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120);
@@ -104,7 +105,16 @@ void PreInitGpgFrontendUI() { CommonUtils::GetInstance(); }
void InitGpgFrontendUI(QApplication* /*app*/) {
// init locale
- InitLocale();
+ InitUITranslations();
+
+#ifdef WINDOWS
+ // support dark mode on windows
+ QApplication::setStyle("fusion");
+#endif
+
+ // register meta types
+ qRegisterMetaType<QSharedPointer<GpgPassphraseContext> >(
+ "QSharedPointer<GpgPassphraseContext>");
// init signal station
UISignalStation::GetInstance();
@@ -172,9 +182,6 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
0) {
WaitEnvCheckingProcess();
}
-
- qRegisterMetaType<QSharedPointer<GpgPassphraseContext> >(
- "QSharedPointer<GpgPassphraseContext>");
}
auto RunGpgFrontendUI(QApplication* app) -> int {
@@ -204,26 +211,33 @@ void GPGFRONTEND_UI_EXPORT DestroyGpgFrontendUI() {}
* @brief setup the locale and load the translations
*
*/
-void InitLocale() {
- // get the instance of the GlobalSettingStation
- auto settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
-
- // read from settings file
- auto lang = settings.value("basic/lang").toString();
- GF_UI_LOG_INFO("current system default locale: {}", QLocale().name());
-
- auto target_locale = lang.isEmpty() ? QLocale() : QLocale(lang);
- QLocale::setDefault(target_locale);
- GF_UI_LOG_INFO("target locale settings: {}", target_locale.name());
-
+void InitUITranslations() {
auto* translator = new QTranslator(QCoreApplication::instance());
- if (translator->load(target_locale, QLatin1String(PROJECT_NAME),
+ if (translator->load(QLocale(), QLatin1String(PROJECT_NAME),
QLatin1String("."), QLatin1String(":/i18n"),
QLatin1String(".qm"))) {
- GF_UI_LOG_DEBUG("load target translation file done");
+ GF_UI_LOG_DEBUG("load target translation file done, locale: {}",
+ QLocale().name());
QCoreApplication::installTranslator(translator);
}
+
+ auto* base_translation = new QTranslator(QCoreApplication::instance());
+ if (base_translation->load(QLocale(), QLatin1String("qt"), QLatin1String("_"),
+ QLatin1String(":/i18n_qt"),
+ QLatin1String(".qm"))) {
+ GF_UI_LOG_DEBUG("load qt translation file done, locale: {}",
+ QLocale().name());
+ QCoreApplication::installTranslator(base_translation);
+ }
+
+ base_translation = new QTranslator(QCoreApplication::instance());
+ if (base_translation->load(QLocale(), QLatin1String("qtbase"),
+ QLatin1String("_"), QLatin1String(":/i18n_qt"),
+ QLatin1String(".qm"))) {
+ GF_UI_LOG_DEBUG("load qtbase translation file done, locale: {}",
+ QLocale().name());
+ QCoreApplication::installTranslator(base_translation);
+ }
}
} // namespace GpgFrontend::UI