From 4e263bae987bcc343497496bcdc962c292977b6a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 6 Dec 2013 14:29:38 -0200 Subject: Added a language preference to the Settings. When the user first opens the application the default language is selected; this can be changed to a hardcoded one by going to system preferences and choosing the one you want. Restart required. Fixes #136 [Dirk Hohndel: whitespace fixes, removed qDebug() call, rephrased the message displayed prompting the user to restart.] Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/preferences.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'qt-ui/preferences.cpp') diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index f8b24da42..2155a710d 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -3,11 +3,13 @@ #include #include #include +#include PreferencesDialog* PreferencesDialog::instance() { static PreferencesDialog *dialog = new PreferencesDialog(mainWindow()); dialog->setAttribute(Qt::WA_QuitOnClose, false); + LanguageModel::instance(); return dialog; } @@ -107,6 +109,15 @@ void PreferencesDialog::setUiFromPrefs() ui.show_sac->setChecked(prefs.show_sac); ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); + + ui.languageView->setModel( LanguageModel::instance() ); + + QSettings s; + s.beginGroup("Language"); + QAbstractItemModel *m = ui.languageView->model(); + QModelIndexList languages = m->match( m->index(0,0), Qt::DisplayRole, s.value("UiLanguage").toString()); + if (languages.count()) + ui.languageView->setCurrentIndex(languages.first()); } void PreferencesDialog::restorePrefs() @@ -174,6 +185,14 @@ void PreferencesDialog::syncSettings() s.endGroup(); s.sync(); + QLocale loc; + s.beginGroup("Language"); + if (s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole)){ + QMessageBox::warning(mainWindow(), tr("Restart required"), + tr("To correctly load a new language you must restart Subsurface.")); + } + s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); + emit settingsChanged(); } -- cgit v1.2.3-70-g09d2