aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/main.cpp b/src/main.cpp
index ee542ff0..f4739767 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,6 +22,8 @@
*
*/
+#include <cstdlib>
+
#include "GpgFrontendBuildInfo.h"
#include "ui/MainWindow.h"
#include "ui/settings/GlobalSettingStation.h"
@@ -38,13 +40,11 @@ int main(int argc, char* argv[]) {
// Qt App
QApplication app(argc, argv);
+ QApplication::setWindowIcon(QIcon(":gpgfrontend.png"));
// logging system
init_logging();
- // i18n
- init_locale();
-
// App config
QApplication::setApplicationVersion(BUILD_VERSION);
QApplication::setApplicationName(PROJECT_NAME);
@@ -65,25 +65,16 @@ int main(int argc, char* argv[]) {
#endif
/**
- * internationalisation. loop to restart mainwindow
+ * internationalisation. loop to restart main window
* with changed translation when settings change.
*/
int return_from_event_loop_code;
do {
- QApplication::setQuitOnLastWindowClosed(true);
-
- /**
- * The function `gpgme_check_version' must be called before any other
- * function in the library, because it initializes the thread support
- * subsystem in GPGME. (from the info page) */
- gpgme_check_version(nullptr);
+ // i18n
+ init_locale();
- /** set locale, because tests do also */
- gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr));
-#ifndef _WIN32
- gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
-#endif
+ QApplication::setQuitOnLastWindowClosed(true);
auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>();
main_window->init();
@@ -136,8 +127,7 @@ void init_locale() {
GpgFrontend::UI::GlobalSettingStation::GetInstance().Sync();
- auto* locale_name = setlocale(LC_ALL, nullptr);
- LOG(INFO) << "current system locale" << locale_name;
+ LOG(INFO) << "current system locale" << setlocale(LC_ALL, nullptr);
// read from settings file
std::string lang;
@@ -145,20 +135,29 @@ void init_locale() {
LOG(ERROR) << _("Could not read properly from configure file");
};
- LOG(INFO) << "lang" << lang;
+ LOG(INFO) << "lang from settings" << lang;
LOG(INFO) << "PROJECT_NAME" << PROJECT_NAME;
LOG(INFO) << "locales path"
<< GpgFrontend::UI::GlobalSettingStation::GetInstance()
.GetLocaleDir()
.c_str();
- if (!lang.empty()) lang += ".UTF8";
- // GNU gettext settings
- locale_name = setlocale(LC_ALL, lang.c_str());
- if (locale_name == nullptr) {
- LOG(WARNING) << "set locale name failed";
- } else {
- LOG(INFO) << "locale name now" << locale_name;
+ if (!lang.empty()) {
+ std::string lc = lang.empty() ? "" : lang + ".UTF-8";
+
+ // set LC_ALL
+ auto* locale_name = setlocale(LC_ALL, lc.c_str());
+ if (locale_name == nullptr) LOG(WARNING) << "set LC_ALL failed" << lc;
+#ifndef WINDOWS
+ auto language = getenv("LANGUAGE");
+ // set LANGUAGE
+ std::string language_env = language == nullptr ? "en" : language;
+ language_env.insert(0, lang + ":");
+ LOG(INFO) << "language env" << language_env;
+ if (setenv("LANGUAGE", language_env.c_str(), 1)) {
+ LOG(WARNING) << "set LANGUAGE failed" << language_env;
+ };
+#endif
}
bindtextdomain(PROJECT_NAME,