preferencesdialog: Suffix to identify system and default languages

Also, move the selected language to the top of the language
combo box.
This commit is contained in:
Samir Aguiar
2015-02-09 23:35:30 +01:00
parent 8a4838057d
commit 774e428b30
2 changed files with 19 additions and 5 deletions
+17 -3
View File
@@ -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);
}
+2 -2
View File
@@ -42,7 +42,7 @@
</property>
<property name="minimumSize">
<size>
<width>200</width>
<width>290</width>
<height>0</height>
</size>
</property>
@@ -86,7 +86,7 @@
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
<property name="minimumContentsLength">
<number>20</number>
<number>35</number>
</property>
</widget>
</item>