all repos — mgba @ 4d3d579cae5c96bfc2e70c62b0266c2ad16fff08

mGBA Game Boy Advance Emulator

Qt: Add language selector
Vicki Pfau vi@endrift.com
Fri, 30 Jun 2017 11:00:58 -0700
commit

4d3d579cae5c96bfc2e70c62b0266c2ad16fff08

parent

f91a4195b60fdd7943ace1444031ea7043fc172d

M CHANGESCHANGES

@@ -150,6 +150,8 @@ 0.6 beta 2: (Future)

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
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -14,6 +14,7 @@

#include <QFileInfo> #include <QFileOpenEvent> #include <QIcon> +#include <QLibraryInfo> #include <QTranslator> #include <mgba/core/version.h>

@@ -44,11 +45,19 @@ #ifndef Q_OS_MAC

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*>("const uint32_t*");
M src/platform/qt/SettingsView.cppsrc/platform/qt/SettingsView.cpp

@@ -14,6 +14,7 @@ #include "InputController.h"

#include "ShortcutView.h" #include <mgba/core/serialize.h> +#include <mgba/core/version.h> #include <mgba/internal/gba/gba.h> using namespace QGBA;

@@ -164,6 +165,19 @@ }

} }); + 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);

@@ -251,6 +265,12 @@ if (displayDriver != m_controller->getQtOption("displayDriver")) {

m_controller->setQtOption("displayDriver", displayDriver); Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt())); 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();
M src/platform/qt/SettingsView.hsrc/platform/qt/SettingsView.h

@@ -29,6 +29,7 @@ void biosLoaded(int platform, const QString&);

void audioDriverChanged(); void displayDriverChanged(); void pathsChanged(); + void languageChanged(); void libraryCleared(); private slots:
M src/platform/qt/SettingsView.uisrc/platform/qt/SettingsView.ui

@@ -398,17 +398,30 @@ </layout>

</widget> <widget class="QWidget" name="interface_2"> <layout class="QFormLayout" name="formLayout_4"> - <item row="1" column="1"> - <widget class="QCheckBox" name="showLibrary"> + <item row="0" column="0"> + <widget class="QLabel" name="label_26"> <property name="text"> - <string>Show when no game open</string> - </property> - <property name="checked"> - <bool>true</bool> + <string>Language</string> </property> </widget> </item> <item row="0" column="1"> + <widget class="QComboBox" name="languages"> + <item> + <property name="text"> + <string>English</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Library:</string> + </property> + </widget> + </item> + <item row="2" column="1"> <widget class="QComboBox" name="libraryStyle"> <item> <property name="text">

@@ -422,35 +435,38 @@ </property>

</item> </widget> </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_6"> + <item row="3" column="1"> + <widget class="QCheckBox" name="showLibrary"> <property name="text"> - <string>Library:</string> + <string>Show when no game open</string> + </property> + <property name="checked"> + <bool>true</bool> </property> </widget> </item> - <item row="2" column="1"> + <item row="4" column="1"> <widget class="QPushButton" name="clearCache"> <property name="text"> <string>Clear cache</string> </property> </widget> </item> - <item row="3" column="0" colspan="2"> + <item row="5" column="0" colspan="2"> <widget class="Line" name="line_8"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="4" column="1"> + <item row="6" column="1"> <widget class="QCheckBox" name="allowOpposingDirections"> <property name="text"> <string>Allow opposing input directions</string> </property> </widget> </item> - <item row="5" column="1"> + <item row="7" column="1"> <widget class="QCheckBox" name="suspendScreensaver"> <property name="text"> <string>Suspend screensaver</string>

@@ -460,10 +476,17 @@ <bool>true</bool>

</property> </widget> </item> - <item row="6" column="1"> + <item row="8" column="1"> <widget class="QCheckBox" name="pauseOnFocusLost"> <property name="text"> <string>Pause when inactive</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="Line" name="line_10"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item>
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -459,6 +459,7 @@ SettingsView* settingsWindow = new SettingsView(m_config, &m_inputController, m_shortcutController);

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);
M src/platform/qt/main.cppsrc/platform/qt/main.cpp

@@ -10,9 +10,6 @@

#include "GBAApp.h" #include "Window.h" -#include <QLibraryInfo> -#include <QTranslator> - #include <mgba/core/version.h> #ifdef QT_STATIC

@@ -30,16 +27,6 @@ #ifdef BUILD_SDL

SDL_SetMainReady(); #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(); }