fix things not being localized and settings not loading

This commit is contained in:
Akash Mozumdar 2020-11-02 06:27:21 -07:00
parent f0a1690c92
commit 01b6b6de16
9 changed files with 20 additions and 13 deletions

View File

@ -165,7 +165,7 @@ namespace
std::wstring path = std::wstring(process).erase(process.rfind(L'\\')); std::wstring path = std::wstring(process).erase(process.rfind(L'\\'));
PROCESS_INFORMATION info = {}; 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 (!x64 && (useLocale == ALWAYS || (useLocale == PROMPT && QMessageBox::question(This, SELECT_PROCESS, USE_JP_LOCALE) == QMessageBox::Yes)))
{ {
if (HMODULE localeEmulator = LoadLibraryW(L"LoaderDll")) if (HMODULE localeEmulator = LoadLibraryW(L"LoaderDll"))
@ -439,10 +439,10 @@ namespace
}).detach(); }).detach();
} }
void Settings() void OpenSettings()
{ {
QDialog dialog(This, Qt::WindowCloseButtonHint); QDialog dialog(This, Qt::WindowCloseButtonHint);
QSettings settings(CONFIG_FILE, QSettings::IniFormat, &dialog); Settings settings(&dialog);
QFormLayout layout(&dialog); QFormLayout layout(&dialog);
QPushButton saveButton(SAVE_SETTINGS, &dialog); QPushButton saveButton(SAVE_SETTINGS, &dialog);
for (auto [value, label] : Array<bool&, const char*>{ for (auto [value, label] : Array<bool&, const char*>{
@ -501,7 +501,7 @@ namespace
font.fromString(fontString); font.fromString(fontString);
font.setStyleStrategy(QFont::NoFontMerging); font.setStyleStrategy(QFont::NoFontMerging);
ui.textOutput->setFont(font); ui.textOutput->setFont(font);
QSettings(CONFIG_FILE, QSettings::IniFormat).setValue(FONT, font.toString()); Settings().setValue(FONT, font.toString());
} }
void ProcessConnected(DWORD processId) void ProcessConnected(DWORD processId)
@ -605,7 +605,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{ REMOVE_HOOKS, RemoveHooks }, { REMOVE_HOOKS, RemoveHooks },
{ SAVE_HOOKS, SaveHooks }, { SAVE_HOOKS, SaveHooks },
{ SEARCH_FOR_HOOKS, FindHooks }, { SEARCH_FOR_HOOKS, FindHooks },
{ SETTINGS, Settings }, { SETTINGS, OpenSettings },
{ EXTENSIONS, Extensions } { EXTENSIONS, Extensions }
}) })
{ {
@ -623,7 +623,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
connect(ui.textOutput, &QPlainTextEdit::selectionChanged, this, CopyUnlessMouseDown); connect(ui.textOutput, &QPlainTextEdit::selectionChanged, this, CopyUnlessMouseDown);
connect(ui.textOutput, &QPlainTextEdit::customContextMenuRequested, this, OutputContextMenu); 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()); 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()); SetOutputFont(settings.value(FONT, ui.textOutput->font().toString()).toString());
TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool(); TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool();
@ -672,7 +672,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
openSettings().setValue(WINDOW, geometry()); Settings().setValue(WINDOW, geometry());
CleanupExtensions(); CleanupExtensions();
SetErrorMode(SEM_NOGPFAULTERRORBOX); SetErrorMode(SEM_NOGPFAULTERRORBOX);
ExitProcess(0); ExitProcess(0);

View File

@ -46,6 +46,7 @@ struct PrettyWindow : QDialog
{ {
PrettyWindow(const char* name) PrettyWindow(const char* name)
{ {
localize();
ui.setupUi(this); ui.setupUi(this);
ui.display->setGraphicsEffect(&outliner); ui.display->setGraphicsEffect(&outliner);
setWindowFlags(Qt::FramelessWindowHint); setWindowFlags(Qt::FramelessWindowHint);
@ -76,7 +77,7 @@ struct PrettyWindow : QDialog
protected: protected:
QMenu menu{ ui.display }; QMenu menu{ ui.display };
QSettings settings{ openSettings(this) }; Settings settings{ this };
private: private:
void RequestFont() void RequestFont()

View File

@ -47,6 +47,7 @@ public:
Window() Window()
: QDialog(nullptr, Qt::WindowMinMaxButtonsHint) : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
{ {
localize();
connect(&loadButton, &QPushButton::clicked, this, &Window::LoadScript); connect(&loadButton, &QPushButton::clicked, this, &Window::LoadScript);
if (scriptEditor.toPlainText().isEmpty()) scriptEditor.setPlainText(LUA_INTRO); if (scriptEditor.toPlainText().isEmpty()) scriptEditor.setPlainText(LUA_INTRO);

View File

@ -21,6 +21,7 @@ public:
Window() Window()
: QDialog(nullptr, Qt::WindowMinMaxButtonsHint) : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
{ {
localize();
ui.setupUi(this); ui.setupUi(this);
connect(ui.input, &QLineEdit::textEdited, this, &Window::setRegex); connect(ui.input, &QLineEdit::textEdited, this, &Window::setRegex);

View File

@ -17,6 +17,7 @@ public:
Window() Window()
: QDialog(nullptr, Qt::WindowMinMaxButtonsHint) : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
{ {
localize();
connect(&linkButton, &QPushButton::clicked, this, &Window::Link); connect(&linkButton, &QPushButton::clicked, this, &Window::Link);
layout.addWidget(&linkList); layout.addWidget(&linkList);

View File

@ -29,7 +29,7 @@ const char* LANGUAGE = u8"Language";
const std::string TRANSLATION_CACHE_FILE = FormatString("%s Cache.txt", TRANSLATION_PROVIDER); const std::string TRANSLATION_CACHE_FILE = FormatString("%s Cache.txt", TRANSLATION_PROVIDER);
QFormLayout* display; QFormLayout* display;
QSettings settings = openSettings(); Settings settings;
Synchronized<std::wstring> translateTo = L"en", apiKey; Synchronized<std::wstring> translateTo = L"en", apiKey;
Synchronized<std::map<std::wstring, std::wstring>> translationCache; Synchronized<std::map<std::wstring, std::wstring>> translationCache;
@ -50,6 +50,7 @@ public:
Window() : Window() :
QDialog(nullptr, Qt::WindowMinMaxButtonsHint) QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
{ {
localize();
display = new QFormLayout(this); display = new QFormLayout(this);
settings.beginGroup(TRANSLATION_PROVIDER); settings.beginGroup(TRANSLATION_PROVIDER);

View File

@ -148,6 +148,8 @@ inline void TEXTRACTOR_MESSAGE(const wchar_t* format, const Args&... args) { Mes
template <typename... Args> template <typename... Args>
inline void TEXTRACTOR_DEBUG(const wchar_t* format, const Args&... args) { std::thread([=] { TEXTRACTOR_MESSAGE(format, args...); }).detach(); } inline void TEXTRACTOR_DEBUG(const wchar_t* format, const Args&... args) { std::thread([=] { TEXTRACTOR_MESSAGE(format, args...); }).detach(); }
void localize();
#ifdef _DEBUG #ifdef _DEBUG
#define TEST(...) static auto _ = CreateThread(nullptr, 0, [](auto) { __VA_ARGS__; return 0UL; }, NULL, 0, nullptr); #define TEST(...) static auto _ = CreateThread(nullptr, 0, [](auto) { __VA_ARGS__; return 0UL; }, NULL, 0, nullptr);
#else #else

View File

@ -23,8 +23,8 @@ static thread_local bool ok;
constexpr auto CONFIG_FILE = u8"Textractor.ini"; constexpr auto CONFIG_FILE = u8"Textractor.ini";
constexpr auto WINDOW = u8"Window"; 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); } }; 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 std::wstring S(const QString& s) { return { s.toStdWString() }; }
inline QString S(const std::string& s) { return QString::fromStdString(s); } inline QString S(const std::string& s) { return QString::fromStdString(s); }

View File

@ -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* THREAD_LINK_TO = u8"Thread number to link to";
const char* HEXADECIMAL = u8"Hexadecimal"; const char* HEXADECIMAL = u8"Hexadecimal";
static auto _ = [] void localize()
{ {
#ifdef TURKISH #ifdef TURKISH
NATIVE_LANGUAGE = "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"; THREAD_LINK_TO = u8"Nombre du thread du lien a";
HEXADECIMAL = u8"Hexadecimal"; HEXADECIMAL = u8"Hexadecimal";
#endif // FRENCH #endif // FRENCH
};
return 0; static auto _ = (localize(), 0);
}();