Mercurial > hg > sonic-visualiser
changeset 658:86d1f640ae1e
Add choice of interface language to the prefs dialog (in case user is unhappy with system locale)
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 10:35:55 +0000 |
parents | 1938702bb3bf |
children | d9c599c24572 |
files | main/PreferencesDialog.cpp main/PreferencesDialog.h main/main.cpp |
diffstat | 3 files changed, 60 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/main/PreferencesDialog.cpp Thu Nov 21 17:05:03 2013 +0000 +++ b/main/PreferencesDialog.cpp Tue Nov 26 10:35:55 2013 +0000 @@ -142,7 +142,7 @@ QString targetName = settings.value("audio-target", "").toString(); settings.endGroup(); - for (int i = 0; i < devices.size(); ++i) { + for (int i = 0; i < (int)devices.size(); ++i) { audioDevice->addItem(AudioTargetFactory::getInstance() ->getCallbackTargetDescription(devices[i])); if (targetName == devices[i]) audioDevice->setCurrentIndex(i); @@ -205,6 +205,41 @@ this, SLOT(backgroundModeChanged(int))); #endif + settings.beginGroup("Preferences"); + QString userLocale = settings.value("locale", "").toString(); + m_currentLocale = userLocale; + settings.endGroup(); + + QComboBox *locale = new QComboBox; + QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm"); + locale->addItem(tr("Follow system locale")); + m_locales.push_back(""); + if (userLocale == "") { + locale->setCurrentIndex(0); + } + foreach (QString f, localeFiles) { + QString f0 = f; + f.replace("sonic-visualiser_", "").replace(".qm", ""); + if (f == f0) { // our expectations about filename format were not met + std::cerr << "INFO: Unexpected filename " << f << " in i18n resource directory" << std::endl; + } else { + m_locales.push_back(f); + QString displayText; + // Add new translations here + if (f == "ru") displayText = tr("Russian"); + else if (f == "en_GB") displayText = tr("British English"); + else if (f == "en_US") displayText = tr("American English"); + else if (f == "cs_CZ") displayText = tr("Czech"); + else displayText = f; + locale->addItem(QString("%1 [%2]").arg(displayText).arg(f)); + if (userLocale == f) { + locale->setCurrentIndex(locale->count() - 1); + } + } + } + connect(locale, SIGNAL(currentIndexChanged(int)), + this, SLOT(localeChanged(int))); + QSpinBox *fontSize = new QSpinBox; int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max, &deflt); @@ -239,6 +274,10 @@ int row = 0; + subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))), + row, 0); + subgrid->addWidget(locale, row++, 1, 1, 1); + subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel ("Temporary Directory Root"))), row, 0); @@ -484,6 +523,14 @@ } void +PreferencesDialog::localeChanged(int i) +{ + m_currentLocale = m_locales[i]; + m_applyButton->setEnabled(true); + m_changesOnRestart = true; +} + +void PreferencesDialog::tempDirRootChanged(QString r) { m_tempDirRoot = r; @@ -564,6 +611,10 @@ settings.setValue("sessiontemplate", m_currentTemplate); settings.endGroup(); + settings.beginGroup("Preferences"); + settings.setValue("locale", m_currentLocale); + settings.endGroup(); + m_applyButton->setEnabled(false); if (m_changesOnRestart) {
--- a/main/PreferencesDialog.h Thu Nov 21 17:05:03 2013 +0000 +++ b/main/PreferencesDialog.h Tue Nov 26 10:35:55 2013 +0000 @@ -60,6 +60,7 @@ void viewFontSizeChanged(int sz); void showSplashChanged(int state); void defaultTemplateChanged(int); + void localeChanged(int); void tempDirButtonClicked(); @@ -78,6 +79,9 @@ QString m_currentTemplate; QStringList m_templates; + + QString m_currentLocale; + QStringList m_locales; WindowType m_windowType; int m_spectrogramSmoothing;
--- a/main/main.cpp Thu Nov 21 17:05:03 2013 +0000 +++ b/main/main.cpp Tue Nov 26 10:35:55 2013 +0000 @@ -317,6 +317,10 @@ QString language = QLocale::system().name(); + settings.beginGroup("Preferences"); + language = settings.value("locale", language).toString(); + settings.endGroup(); + QTranslator qtTranslator; QString qtTrName = QString("qt_%1").arg(language); SVDEBUG << "Loading " << qtTrName << "... ";