2015-09-17 18:58:26 +00:00
|
|
|
#include "preferences_language.h"
|
|
|
|
#include "ui_prefs_language.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QMessageBox>
|
2015-09-17 21:08:24 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-09-17 18:58:26 +00:00
|
|
|
|
2015-09-17 21:08:24 +00:00
|
|
|
#include "qt-models/models.h"
|
2015-09-17 18:58:26 +00:00
|
|
|
|
|
|
|
PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Language"), QIcon(":/language"), 4)
|
|
|
|
{
|
|
|
|
ui = new Ui::PreferencesLanguage();
|
|
|
|
ui->setupUi(this);
|
2015-09-17 21:08:24 +00:00
|
|
|
|
|
|
|
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel();
|
|
|
|
filterModel->setSourceModel(LanguageModel::instance());
|
|
|
|
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2015-10-30 20:14:06 +00:00
|
|
|
ui->languageDropdown->setModel(filterModel);
|
2015-09-17 21:08:24 +00:00
|
|
|
filterModel->sort(0);
|
|
|
|
connect(ui->languageFilter, &QLineEdit::textChanged,
|
|
|
|
filterModel, &QSortFilterProxyModel::setFilterFixedString);
|
2015-09-17 18:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PreferencesLanguage::~PreferencesLanguage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesLanguage::refreshSettings()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("Language");
|
|
|
|
ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
|
2015-10-30 20:14:06 +00:00
|
|
|
QAbstractItemModel *m = ui->languageDropdown->model();
|
2015-09-17 18:58:26 +00:00
|
|
|
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString());
|
|
|
|
if (languages.count())
|
2015-10-30 20:14:06 +00:00
|
|
|
ui->languageDropdown->setCurrentIndex(languages.first().row());
|
2015-09-17 18:58:26 +00:00
|
|
|
s.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesLanguage::syncSettings()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("Language");
|
|
|
|
bool useSystemLang = s.value("UseSystemLanguage", true).toBool();
|
2015-10-30 20:14:06 +00:00
|
|
|
QAbstractItemModel *m = ui->languageDropdown->model();
|
|
|
|
QString currentText = m->data(m->index(ui->languageDropdown->currentIndex(),0), Qt::UserRole).toString();
|
2015-09-17 18:58:26 +00:00
|
|
|
if (useSystemLang != ui->languageSystemDefault->isChecked() ||
|
2015-10-30 20:14:06 +00:00
|
|
|
(!useSystemLang && s.value("UiLanguage").toString() != currentText)) {
|
2015-09-17 18:58:26 +00:00
|
|
|
QMessageBox::warning(this, tr("Restart required"),
|
|
|
|
tr("To correctly load a new language you must restart Subsurface."));
|
|
|
|
}
|
|
|
|
s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked());
|
2015-10-30 20:14:06 +00:00
|
|
|
s.setValue("UiLanguage", currentText);
|
2015-09-17 18:58:26 +00:00
|
|
|
s.endGroup();
|
2015-10-30 20:14:06 +00:00
|
|
|
}
|