MultiMC5/application/setupwizard/LanguageWizardPage.cpp

67 lines
1.8 KiB
C++
Raw Normal View History

2017-01-05 03:05:08 +00:00
#include "LanguageWizardPage.h"
#include <MultiMC.h>
#include <translations/TranslationsModel.h>
#include <QVBoxLayout>
#include <QListView>
LanguageWizardPage::LanguageWizardPage(QWidget *parent)
2018-07-15 12:51:05 +00:00
: BaseWizardPage(parent)
2017-01-05 03:05:08 +00:00
{
2018-07-15 12:51:05 +00:00
setObjectName(QStringLiteral("languagePage"));
verticalLayout = new QVBoxLayout(this);
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
languageView = new QListView(this);
languageView->setObjectName(QStringLiteral("languageView"));
verticalLayout->addWidget(languageView);
retranslate();
2017-01-05 03:05:08 +00:00
2018-07-15 12:51:05 +00:00
auto translations = MMC->translations();
auto index = translations->selectedIndex();
languageView->setModel(translations.get());
languageView->setCurrentIndex(index);
connect(languageView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &LanguageWizardPage::languageRowChanged);
2017-01-05 03:05:08 +00:00
}
LanguageWizardPage::~LanguageWizardPage()
{
}
bool LanguageWizardPage::wantsRefreshButton()
{
2018-07-15 12:51:05 +00:00
return true;
2017-01-05 03:05:08 +00:00
}
void LanguageWizardPage::refresh()
{
2018-07-15 12:51:05 +00:00
auto translations = MMC->translations();
translations->downloadIndex();
2017-01-05 03:05:08 +00:00
}
bool LanguageWizardPage::validatePage()
{
2018-07-15 12:51:05 +00:00
auto settings = MMC->settings();
auto translations = MMC->translations();
QString key = translations->data(languageView->currentIndex(), Qt::UserRole).toString();
settings->set("Language", key);
return true;
2017-01-05 03:05:08 +00:00
}
void LanguageWizardPage::retranslate()
{
2018-07-15 12:51:05 +00:00
setTitle(tr("Language"));
setSubTitle(tr("Select the language to use in MultiMC"));
2017-01-05 03:05:08 +00:00
}
void LanguageWizardPage::languageRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
2018-07-15 12:51:05 +00:00
if (current == previous)
{
return;
}
auto translations = MMC->translations();
QString key = translations->data(current, Qt::UserRole).toString();
translations->selectLanguage(key);
translations->updateLanguage(key);
2017-01-05 03:05:08 +00:00
}