Added 'English' and 'Use System Default' options.

These complete the ability to select languages from the preferences panel.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2013-12-06 17:48:38 -02:00 committed by Dirk Hohndel
parent 7436178fe0
commit 9b7b477d7c
4 changed files with 101 additions and 61 deletions

View file

@ -89,7 +89,12 @@ void init_ui(int *argcp, char ***argvp)
QSettings s;
s.beginGroup("Language");
QLocale loc(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
QLocale loc;
if (!s.value("UseSystemLanguage", true).toBool()){
loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
}
QString uiLang = loc.uiLanguages().first();
s.endGroup();

View file

@ -1772,24 +1772,24 @@ LanguageModel::LanguageModel(QObject* parent): QAbstractListModel(parent)
if ( !s.endsWith(".qm") ){
continue;
}
languages.push_back(s);
languages.push_back( (s == "subsurface_source.qm") ? "English" : s);
}
}
QVariant LanguageModel::data(const QModelIndex& index, int role) const
{
QLocale loc;
QString currentString = languages.at(index.row());
if(!index.isValid())
return QVariant();
switch(role){
case Qt::DisplayRole:{
QString currentString = languages.at(index.row());
QLocale l( currentString.remove("subsurface_"));
return l.countryToString(l.country());
return currentString == "English" ? currentString : l.countryToString(l.country());
}break;
case Qt::UserRole:{
QString currentString = languages.at(index.row());
return currentString.remove("subsurface_");
return currentString == "English" ? "en_US" : currentString.remove("subsurface_");
}break;
}
return QVariant();

View file

@ -114,8 +114,9 @@ void PreferencesDialog::setUiFromPrefs()
QSettings s;
s.beginGroup("Language");
ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage").toBool());
QAbstractItemModel *m = ui.languageView->model();
QModelIndexList languages = m->match( m->index(0,0), Qt::DisplayRole, s.value("UiLanguage").toString());
QModelIndexList languages = m->match( m->index(0,0), Qt::UserRole, s.value("UiLanguage").toString());
if (languages.count())
ui.languageView->setCurrentIndex(languages.first());
}
@ -187,10 +188,12 @@ void PreferencesDialog::syncSettings()
QLocale loc;
s.beginGroup("Language");
if (s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole)){
if (s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole) ||
s.value("UseSystemLanguage").toBool() != ui.languageSystemDefault->isChecked()) {
QMessageBox::warning(mainWindow(), tr("Restart required"),
tr("To correctly load a new language you must restart Subsurface."));
}
s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked());
s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole));
emit settingsChanged();

View file

@ -943,12 +943,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>187</x>
<y>77</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>581</x>
<y>80</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -959,12 +959,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>187</x>
<y>77</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>668</x>
<y>80</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -975,12 +975,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>186</x>
<y>121</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>581</x>
<y>124</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -991,12 +991,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>186</x>
<y>121</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>668</x>
<y>124</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1007,12 +1007,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>165</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>581</x>
<y>168</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1023,12 +1023,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>165</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>668</x>
<y>168</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1040,11 +1040,11 @@
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>209</y>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>591</x>
<y>212</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1056,11 +1056,11 @@
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>209</y>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>668</x>
<y>212</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1071,12 +1071,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>298</x>
<y>327</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>512</x>
<y>327</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1087,12 +1087,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>298</x>
<y>327</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>668</x>
<y>327</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1103,12 +1103,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>298</x>
<y>327</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>668</x>
<y>327</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1119,12 +1119,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>362</x>
<y>275</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>586</x>
<y>270</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
@ -1135,23 +1135,55 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>613</x>
<y>41</y>
<x>195</x>
<y>39</y>
</hint>
<hint type="destinationlabel">
<x>634</x>
<y>72</y>
<x>195</x>
<y>39</y>
</hint>
</hints>
</connection>
<connection>
<sender>languageSystemDefault</sender>
<signal>toggled(bool)</signal>
<receiver>languageView</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>176</x>
<y>30</y>
</hint>
<hint type="destinationlabel">
<x>171</x>
<y>79</y>
</hint>
</hints>
</connection>
<connection>
<sender>languageSystemDefault</sender>
<signal>toggled(bool)</signal>
<receiver>languageFilter</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>209</x>
<y>34</y>
</hint>
<hint type="destinationlabel">
<x>599</x>
<y>33</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="verticalSpeed"/>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup_3"/>
<buttongroup name="buttonGroup_4"/>
<buttongroup name="buttonGroup_5"/>
<buttongroup name="buttonGroup_6"/>
<buttongroup name="verticalSpeed"/>
</buttongroups>
</ui>