From 0a92bc147f91f3ecacdf66d995f01f9577107a86 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 15 Feb 2018 09:06:13 +0100 Subject: clean up "static" and "constexpr" types - use `static constexpr inline' to avoid requiring explicit declarations in object code - use `const Foo* const' to maybe put into readonly binary segment (at least for ELF DSOs) - `constexpr' in function scope has storage, avoid `static' - don't use `constexpr' where there's no advantage, like arrays We'd like to avoid overhead of atomic initialization for each function call. No idea how `static constexpr' requiring storage in the standard plays with atomic initialization requirement. Hearsay points that `constexpr' without `static' in block scope behaves more to our liking. It's all hazy though. I'm not 100% sure if `static inline constexpr' has any storage. Hopefully none, like a #define, and stuff bigger than registers gets coalesced within the same module, with small stuff being immediates. --- gui/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/init.cpp') diff --git a/gui/init.cpp b/gui/init.cpp index e648cfa0..1de98f60 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -61,7 +61,7 @@ void set_qt_style() #if defined _WIN32 || defined __APPLE__ // our layouts on OSX make some control wrongly sized -sh 20160908 { - const char* preferred[] { "fusion", "windowsvista", "macintosh" }; + const char* const preferred[] { "fusion", "windowsvista", "macintosh" }; for (const char* style_name : preferred) { QStyle* s = QStyleFactory::create(style_name); -- cgit v1.2.3 From 7ea413f202d5716de7155df46e708ce5825771d1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 12:15:33 +0100 Subject: gui: attach parent console harder --- gui/init.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'gui/init.cpp') diff --git a/gui/init.cpp b/gui/init.cpp index 1de98f60..5879c6c0 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -143,7 +143,26 @@ void add_win32_path() } } -void attach_parent_console(); +#include + +void attach_parent_console() +{ + std::fflush(stdin); + std::fflush(stderr); + + (void)qInstallMessageHandler(qdebug_to_console); + + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + _wfreopen(L"CON", L"w", stdout); + _wfreopen(L"CON", L"w", stderr); + _wfreopen(L"CON", L"r", stdin); + + freopen("CON", "w", stdout); + freopen("CON", "w", stderr); + freopen("CON", "w", stderr); + } +} #endif @@ -214,19 +233,3 @@ int otr_main(int argc, char** argv, std::function make_main_window) return ret; } -#if defined _WIN32 -#include - -void attach_parent_console() -{ - if (AttachConsole(ATTACH_PARENT_PROCESS)) - { - // XXX c++ iostreams aren't reopened - - _wfreopen(L"CON", L"w", stdout); - _wfreopen(L"CON", L"w", stderr); - _wfreopen(L"CON", L"r", stdin); - } - (void)qInstallMessageHandler(qdebug_to_console); -} -#endif -- cgit v1.2.3 From c011007165a6dee12f0b856411a8c8deaeb2d289 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 12:27:28 +0100 Subject: gui/init: allow forcing locale via env Issue: #748 --- gui/init.cpp | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'gui/init.cpp') diff --git a/gui/init.cpp b/gui/init.cpp index 5879c6c0..cf0b53c8 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -157,10 +157,13 @@ void attach_parent_console() _wfreopen(L"CON", L"w", stdout); _wfreopen(L"CON", L"w", stderr); _wfreopen(L"CON", L"r", stdin); - freopen("CON", "w", stdout); freopen("CON", "w", stderr); freopen("CON", "w", stderr); + + // skip prompt in cmd.exe window + fprintf(stderr, "\n"); + fflush(stderr); } } @@ -182,10 +185,6 @@ int run_window(QApplication& app, std::unique_ptr main_window) int otr_main(int argc, char** argv, std::function make_main_window) { -#ifdef _WIN32 - attach_parent_console(); -#endif - #if defined OTR_HAS_DENORM_CONTROL set_fp_mask(); #endif @@ -197,37 +196,42 @@ int otr_main(int argc, char** argv, std::function make_main_window) #ifdef _WIN32 add_win32_path(); + attach_parent_console(); #endif QDir::setCurrent(OPENTRACK_BASE_PATH); -#if 0 -#if !defined(__linux) && !defined _WIN32 - // workaround QTBUG-38598 - QCoreApplication::addLibraryPath("."); -#endif -#endif - set_qt_style(); QTranslator t; - // QLocale::setDefault(QLocale("ru_RU")); // force i18n for testing - - if (group::with_global_settings_object([&](QSettings& s) { - return !s.value("disable-translation", false).toBool(); - })) { - (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm"); - (void) QCoreApplication::installTranslator(&t); + const char* forced_locale = getenv("OTR_FORCE_LOCALE"); + + if (forced_locale) + { + QLocale::setDefault(QLocale(forced_locale)); // force i18n for testing + qDebug() << "locale:" << forced_locale; + } + + const bool no_i18n = group::with_global_settings_object([](QSettings& s) { + return !s.value("disable-translation", false).toBool(); + }); + + if (forced_locale || !no_i18n) + { + (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm"); + (void) QCoreApplication::installTranslator(&t); + } } int ret = run_window(app, std::unique_ptr(make_main_window())); +#if 0 // msvc crashes in Qt plugin system's dtor // Note: QLibrary::PreventUnloadHint seems to workaround it -#if defined(_MSC_VER) && 0 - qDebug() << "exit: terminating"; +#if defined _MSC_VER TerminateProcess(GetCurrentProcess(), 0); +#endif #endif return ret; -- cgit v1.2.3 From 7a973ae2ad396c8413405e40bcb2eaab67c95d15 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 13:38:30 +0100 Subject: gui/init: shorten to `OTR_FORCE_LANG' --- gui/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/init.cpp') diff --git a/gui/init.cpp b/gui/init.cpp index cf0b53c8..51ffbf3e 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -205,7 +205,7 @@ int otr_main(int argc, char** argv, std::function make_main_window) QTranslator t; { - const char* forced_locale = getenv("OTR_FORCE_LOCALE"); + const char* forced_locale = getenv("OTR_FORCE_LANG"); if (forced_locale) { -- cgit v1.2.3