From 4d3d579cae5c96bfc2e70c62b0266c2ad16fff08 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 30 Jun 2017 11:00:58 -0700 Subject: [PATCH] Qt: Add language selector --- CHANGES | 2 ++ src/platform/qt/GBAApp.cpp | 15 ++++++++-- src/platform/qt/SettingsView.cpp | 20 +++++++++++++ src/platform/qt/SettingsView.h | 1 + src/platform/qt/SettingsView.ui | 51 +++++++++++++++++++++++--------- src/platform/qt/Window.cpp | 1 + src/platform/qt/main.cpp | 13 -------- 7 files changed, 73 insertions(+), 30 deletions(-) diff --git a/CHANGES b/CHANGES index 7e9161f5d..079c31785 100644 --- a/CHANGES +++ b/CHANGES @@ -150,6 +150,8 @@ Misc: Bugfixes: - Qt: Fix memory search close button (fixes mgba.io/i/769) - Qt: Fix window icon being stretched +Misc: + - Qt: Add language selector 0.6 beta 1: (2017-06-29) - Initial beta for 0.6 diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 5f430aaec..5c8e46bbf 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -44,11 +45,19 @@ GBAApp::GBAApp(int& argc, char* argv[]) setWindowIcon(QIcon(":/res/mgba-512.png")); #endif - QTranslator* translator = new QTranslator(this); - if (translator->load(QLocale(), QLatin1String(binaryName), QLatin1String("-"), QLatin1String(":/translations"))) { - installTranslator(translator); + QLocale locale; + + if (!m_configController.getQtOption("language").isNull()) { + locale = QLocale(m_configController.getQtOption("language").toString()); } + QTranslator qtTranslator; + qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + installTranslator(&qtTranslator); + + QTranslator langTranslator; + langTranslator.load(locale, binaryName, "-", ":/translations/"); + installTranslator(&langTranslator); SocketSubsystemInit(); qRegisterMetaType("const uint32_t*"); diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index bd7fd2cf4..0afb035b2 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -14,6 +14,7 @@ #include "ShortcutView.h" #include +#include #include using namespace QGBA; @@ -164,6 +165,19 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC } }); + m_ui.languages->setItemData(0, QLocale("en")); + QDir ts(":/translations/"); + for (auto name : ts.entryList()) { + if (!name.endsWith(".qm")) { + continue; + } + QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm")); + m_ui.languages->addItem(locale.nativeLanguageName(), locale); + if (locale == QLocale()) { + m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1); + } + } + ShortcutView* shortcutView = new ShortcutView(); shortcutView->setController(shortcutController); shortcutView->setInputController(inputController); @@ -253,6 +267,12 @@ void SettingsView::updateConfig() { emit displayDriverChanged(); } + QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale(); + if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) { + m_controller->setQtOption("language", language.bcp47Name()); + emit languageChanged(); + } + m_controller->write(); emit pathsChanged(); diff --git a/src/platform/qt/SettingsView.h b/src/platform/qt/SettingsView.h index d5cbe323d..3e85fe8bd 100644 --- a/src/platform/qt/SettingsView.h +++ b/src/platform/qt/SettingsView.h @@ -29,6 +29,7 @@ signals: void audioDriverChanged(); void displayDriverChanged(); void pathsChanged(); + void languageChanged(); void libraryCleared(); private slots: diff --git a/src/platform/qt/SettingsView.ui b/src/platform/qt/SettingsView.ui index 6f27a1fd5..2c98c5c03 100644 --- a/src/platform/qt/SettingsView.ui +++ b/src/platform/qt/SettingsView.ui @@ -398,17 +398,30 @@ - - + + - Show when no game open - - - true + Language + + + + English + + + + + + + + Library: + + + + @@ -422,35 +435,38 @@ - - + + - Library: + Show when no game open + + + true - + Clear cache - + Qt::Horizontal - + Allow opposing input directions - + Suspend screensaver @@ -460,13 +476,20 @@ - + Pause when inactive + + + + Qt::Horizontal + + + diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 1f3555999..75725e6e3 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -459,6 +459,7 @@ void Window::openSettingsWindow() { connect(settingsWindow, &SettingsView::biosLoaded, m_controller, &GameController::loadBIOS); connect(settingsWindow, &SettingsView::audioDriverChanged, m_controller, &GameController::reloadAudioDriver); connect(settingsWindow, &SettingsView::displayDriverChanged, this, &Window::mustRestart); + connect(settingsWindow, &SettingsView::languageChanged, this, &Window::mustRestart); connect(settingsWindow, &SettingsView::pathsChanged, this, &Window::reloadConfig); connect(settingsWindow, &SettingsView::libraryCleared, m_libraryView, &LibraryController::clear); openView(settingsWindow); diff --git a/src/platform/qt/main.cpp b/src/platform/qt/main.cpp index 631040d82..c58ce7837 100644 --- a/src/platform/qt/main.cpp +++ b/src/platform/qt/main.cpp @@ -10,9 +10,6 @@ #include "GBAApp.h" #include "Window.h" -#include -#include - #include #ifdef QT_STATIC @@ -31,15 +28,5 @@ int main(int argc, char* argv[]) { #endif QGBA::GBAApp application(argc, argv); - QLocale locale = QLocale::system(); - - QTranslator qtTranslator; - qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - application.installTranslator(&qtTranslator); - - QTranslator langTranslator; - langTranslator.load(locale, binaryName, "-", ":/translations/"); - application.installTranslator(&langTranslator); - return application.exec(); }