From 774e428b30a2973b8374c80c25a32ad10b09f34a Mon Sep 17 00:00:00 2001 From: Samir Aguiar Date: Mon, 9 Feb 2015 23:35:30 +0100 Subject: [PATCH] preferencesdialog: Suffix to identify system and default languages Also, move the selected language to the top of the language combo box. --- src/PreferencesDialog.cpp | 20 +++++++++++++++++--- src/PreferencesDialog.ui | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index 4d15058d..584f0d61 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -259,20 +259,28 @@ void PreferencesDialog::fillLanguageBox() QDir translationsDir(QCoreApplication::applicationDirPath() + "/translations", "sqlb_*.qm"); + QLocale systemLocale = QLocale::system(); + // Add default language - ui->languageComboBox->addItem("English (United States)", "en_US"); + if (systemLocale.name() == "en_US") + ui->languageComboBox->addItem("English (United States) [System Language]","en_US"); + else + ui->languageComboBox->addItem("English (United States) [Default Language]","en_US"); foreach(const QFileInfo &file, translationsDir.entryInfoList()) { QLocale locale(file.baseName().remove("sqlb_")); - // Prevent invalid locales from being added to the box + // Skip invalid locales if(locale.name() == "C") continue; QString language = QLocale::languageToString(locale.language()) + " (" + QLocale::countryToString(locale.country()) + ")"; + if (locale == systemLocale) + language += " [System language]"; + ui->languageComboBox->addItem(language, locale.name()); } @@ -286,5 +294,11 @@ void PreferencesDialog::fillLanguageBox() if(index < 0) index = ui->languageComboBox->findData("en_US", Qt::UserRole, Qt::MatchExactly); - ui->languageComboBox->setCurrentIndex(index); + QString chosenLanguage = ui->languageComboBox->itemText(index); + QVariant chosenLocale = ui->languageComboBox->itemData(index); + + // There's no "move" method, so we remove and add the chosen language again at the top + ui->languageComboBox->removeItem(index); + ui->languageComboBox->insertItem(0, chosenLanguage, chosenLocale); + ui->languageComboBox->setCurrentIndex(0); } diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index 851a2c26..7cc347c2 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -42,7 +42,7 @@ - 200 + 290 0 @@ -86,7 +86,7 @@ QComboBox::AdjustToMinimumContentsLength - 20 + 35