summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/preferences/preferences_language.cpp
blob: 7254482e2cde5a6db43caccd97daa33233fcbdd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "preferences_language.h"
#include "ui_prefs_language.h"

#include <QApplication>
#include <QSettings>
#include <QMessageBox>


PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Language"), QIcon(":/language"), 4)
{
	ui = new Ui::PreferencesLanguage();
	ui->setupUi(this);
}

PreferencesLanguage::~PreferencesLanguage()
{
	delete ui;
}

void PreferencesLanguage::refreshSettings()
{
	QSettings s;
	s.beginGroup("Language");
	ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
	QAbstractItemModel *m = ui->languageView->model();
	QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString());
	if (languages.count())
		ui->languageView->setCurrentIndex(languages.first());
	s.endGroup();
}

void PreferencesLanguage::syncSettings()
{
	// Locale
	QLocale loc;
	QSettings s;
	s.beginGroup("Language");
	bool useSystemLang = s.value("UseSystemLanguage", true).toBool();
	if (useSystemLang != ui->languageSystemDefault->isChecked() ||
	    (!useSystemLang && s.value("UiLanguage").toString() != ui->languageView->currentIndex().data(Qt::UserRole))) {
		QMessageBox::warning(this, 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));
	s.endGroup();
}