From 01b6b6de160497eef4d7544c483499d90c0655a6 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 2 Nov 2020 06:27:21 -0700 Subject: [PATCH] fix things not being localized and settings not loading --- GUI/mainwindow.cpp | 14 +++++++------- extensions/extrawindow.cpp | 3 ++- extensions/lua.cpp | 1 + extensions/regexfilter.cpp | 1 + extensions/threadlinker.cpp | 1 + extensions/translatewrapper.cpp | 3 ++- include/common.h | 2 ++ include/qtcommon.h | 2 +- text.cpp | 6 +++--- 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 303df32..e2a99aa 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -165,7 +165,7 @@ namespace std::wstring path = std::wstring(process).erase(process.rfind(L'\\')); PROCESS_INFORMATION info = {}; - auto useLocale = openSettings().value(CONFIG_JP_LOCALE, PROMPT).toInt(); + auto useLocale = Settings().value(CONFIG_JP_LOCALE, PROMPT).toInt(); if (!x64 && (useLocale == ALWAYS || (useLocale == PROMPT && QMessageBox::question(This, SELECT_PROCESS, USE_JP_LOCALE) == QMessageBox::Yes))) { if (HMODULE localeEmulator = LoadLibraryW(L"LoaderDll")) @@ -439,10 +439,10 @@ namespace }).detach(); } - void Settings() + void OpenSettings() { QDialog dialog(This, Qt::WindowCloseButtonHint); - QSettings settings(CONFIG_FILE, QSettings::IniFormat, &dialog); + Settings settings(&dialog); QFormLayout layout(&dialog); QPushButton saveButton(SAVE_SETTINGS, &dialog); for (auto [value, label] : Array{ @@ -501,7 +501,7 @@ namespace font.fromString(fontString); font.setStyleStrategy(QFont::NoFontMerging); ui.textOutput->setFont(font); - QSettings(CONFIG_FILE, QSettings::IniFormat).setValue(FONT, font.toString()); + Settings().setValue(FONT, font.toString()); } void ProcessConnected(DWORD processId) @@ -605,7 +605,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { REMOVE_HOOKS, RemoveHooks }, { SAVE_HOOKS, SaveHooks }, { SEARCH_FOR_HOOKS, FindHooks }, - { SETTINGS, Settings }, + { SETTINGS, OpenSettings }, { EXTENSIONS, Extensions } }) { @@ -623,7 +623,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connect(ui.textOutput, &QPlainTextEdit::selectionChanged, this, CopyUnlessMouseDown); connect(ui.textOutput, &QPlainTextEdit::customContextMenuRequested, this, OutputContextMenu); - QSettings settings(CONFIG_FILE, QSettings::IniFormat); + Settings settings; if (settings.contains(WINDOW) && QApplication::screenAt(settings.value(WINDOW).toRect().center())) setGeometry(settings.value(WINDOW).toRect()); SetOutputFont(settings.value(FONT, ui.textOutput->font().toString()).toString()); TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool(); @@ -672,7 +672,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) MainWindow::~MainWindow() { - openSettings().setValue(WINDOW, geometry()); + Settings().setValue(WINDOW, geometry()); CleanupExtensions(); SetErrorMode(SEM_NOGPFAULTERRORBOX); ExitProcess(0); diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index b2a581d..441876f 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -46,6 +46,7 @@ struct PrettyWindow : QDialog { PrettyWindow(const char* name) { + localize(); ui.setupUi(this); ui.display->setGraphicsEffect(&outliner); setWindowFlags(Qt::FramelessWindowHint); @@ -76,7 +77,7 @@ struct PrettyWindow : QDialog protected: QMenu menu{ ui.display }; - QSettings settings{ openSettings(this) }; + Settings settings{ this }; private: void RequestFont() diff --git a/extensions/lua.cpp b/extensions/lua.cpp index de79306..0999774 100644 --- a/extensions/lua.cpp +++ b/extensions/lua.cpp @@ -47,6 +47,7 @@ public: Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint) { + localize(); connect(&loadButton, &QPushButton::clicked, this, &Window::LoadScript); if (scriptEditor.toPlainText().isEmpty()) scriptEditor.setPlainText(LUA_INTRO); diff --git a/extensions/regexfilter.cpp b/extensions/regexfilter.cpp index d8814a9..e4178ba 100644 --- a/extensions/regexfilter.cpp +++ b/extensions/regexfilter.cpp @@ -21,6 +21,7 @@ public: Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint) { + localize(); ui.setupUi(this); connect(ui.input, &QLineEdit::textEdited, this, &Window::setRegex); diff --git a/extensions/threadlinker.cpp b/extensions/threadlinker.cpp index 1414536..ed7751a 100644 --- a/extensions/threadlinker.cpp +++ b/extensions/threadlinker.cpp @@ -17,6 +17,7 @@ public: Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint) { + localize(); connect(&linkButton, &QPushButton::clicked, this, &Window::Link); layout.addWidget(&linkList); diff --git a/extensions/translatewrapper.cpp b/extensions/translatewrapper.cpp index 1e5ed6c..da22f26 100644 --- a/extensions/translatewrapper.cpp +++ b/extensions/translatewrapper.cpp @@ -29,7 +29,7 @@ const char* LANGUAGE = u8"Language"; const std::string TRANSLATION_CACHE_FILE = FormatString("%s Cache.txt", TRANSLATION_PROVIDER); QFormLayout* display; -QSettings settings = openSettings(); +Settings settings; Synchronized translateTo = L"en", apiKey; Synchronized> translationCache; @@ -50,6 +50,7 @@ public: Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint) { + localize(); display = new QFormLayout(this); settings.beginGroup(TRANSLATION_PROVIDER); diff --git a/include/common.h b/include/common.h index 13803bf..b19efcf 100644 --- a/include/common.h +++ b/include/common.h @@ -148,6 +148,8 @@ inline void TEXTRACTOR_MESSAGE(const wchar_t* format, const Args&... args) { Mes template inline void TEXTRACTOR_DEBUG(const wchar_t* format, const Args&... args) { std::thread([=] { TEXTRACTOR_MESSAGE(format, args...); }).detach(); } +void localize(); + #ifdef _DEBUG #define TEST(...) static auto _ = CreateThread(nullptr, 0, [](auto) { __VA_ARGS__; return 0UL; }, NULL, 0, nullptr); #else diff --git a/include/qtcommon.h b/include/qtcommon.h index f0278cd..6cd3d91 100644 --- a/include/qtcommon.h +++ b/include/qtcommon.h @@ -23,8 +23,8 @@ static thread_local bool ok; constexpr auto CONFIG_FILE = u8"Textractor.ini"; constexpr auto WINDOW = u8"Window"; -inline QSettings openSettings(QObject* parent = nullptr) { return { CONFIG_FILE, QSettings::IniFormat, parent }; } +struct Settings : QSettings { Settings(QObject* parent = nullptr) : QSettings(CONFIG_FILE, QSettings::IniFormat, parent) {} }; struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } }; inline std::wstring S(const QString& s) { return { s.toStdWString() }; } inline QString S(const std::string& s) { return QString::fromStdString(s); } diff --git a/text.cpp b/text.cpp index 4dd7a7f..490964a 100644 --- a/text.cpp +++ b/text.cpp @@ -215,7 +215,7 @@ const char* THREAD_LINK_FROM = u8"Thread number to link from"; const char* THREAD_LINK_TO = u8"Thread number to link to"; const char* HEXADECIMAL = u8"Hexadecimal"; -static auto _ = [] +void localize() { #ifdef TURKISH NATIVE_LANGUAGE = "Turkish"; @@ -1334,6 +1334,6 @@ Ce fichier doit ĂȘtre encodĂ© en Unicode (UTF-16 Little Endian).)"; THREAD_LINK_TO = u8"Nombre du thread du lien a"; HEXADECIMAL = u8"Hexadecimal"; #endif // FRENCH +}; - return 0; -}(); +static auto _ = (localize(), 0);