summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/pages/global/MultiMCPage.cpp39
-rw-r--r--application/pages/global/MultiMCPage.h5
-rw-r--r--application/pages/global/MultiMCPage.ui4
-rw-r--r--application/setupwizard/SetupWizard.cpp93
-rw-r--r--application/setupwizard/SetupWizard.h3
5 files changed, 80 insertions, 64 deletions
diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp
index 11129d86..b2ef325d 100644
--- a/application/pages/global/MultiMCPage.cpp
+++ b/application/pages/global/MultiMCPage.cpp
@@ -55,6 +55,7 @@ MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCP
defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
+ m_languageModel = MMC->translations();
loadSettings();
if(BuildConfig.UPDATER_ENABLED)
@@ -82,6 +83,7 @@ MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCP
}
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
+ connect(ui->languageBox, SIGNAL(currentIndexChanged(int)), SLOT(languageIndexChanged(int)));
}
MultiMCPage::~MultiMCPage()
@@ -190,6 +192,19 @@ void MultiMCPage::on_lwjglDirBrowseBtn_clicked()
}
}
+void MultiMCPage::languageIndexChanged(int index)
+{
+ auto languageCode = ui->languageBox->itemData(ui->languageBox->currentIndex()).toString();
+ if(languageCode.isEmpty())
+ {
+ qWarning() << "Unknown language at index" << index;
+ return;
+ }
+ auto translations = MMC->translations();
+ translations->selectLanguage(languageCode);
+ translations->updateLanguage(languageCode);
+}
+
void MultiMCPage::refreshUpdateChannelList()
{
// Stop listening for selection changes. It's going to change a lot while we update it and
@@ -363,29 +378,7 @@ void MultiMCPage::loadSettings()
auto s = MMC->settings();
// Language
{
- using LanguageItem = std::pair<QString, QString>;
- std::vector<LanguageItem> items;
-
- QLocale english("en");
- items.push_back(std::make_pair(english.nativeLanguageName(), "en"));
- for(QString lang: QDir("translations").entryList(QStringList() << "*.qm", QDir::Files))
- {
- lang.remove(".qm");
- lang.remove("mmc_");
- QLocale locale(lang);
- QString fullLangName = locale.nativeLanguageName();
- qDebug() << fullLangName << lang;
- items.push_back(std::make_pair(fullLangName, lang));
- }
- std::sort(items.begin(), items.end(), [](const LanguageItem & a, const LanguageItem & b)
- {
- return a.first.localeAwareCompare(b.first) < 0;
- });
- ui->languageBox->clear();
- for(auto & item: items)
- {
- ui->languageBox->addItem(item.first, item.second);
- }
+ ui->languageBox->setModel(m_languageModel.get());
ui->languageBox->setCurrentIndex(ui->languageBox->findData(s->get("Language").toString()));
}
diff --git a/application/pages/global/MultiMCPage.h b/application/pages/global/MultiMCPage.h
index 5d4f048e..ed280171 100644
--- a/application/pages/global/MultiMCPage.h
+++ b/application/pages/global/MultiMCPage.h
@@ -22,6 +22,7 @@
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "ColorCache.h"
+#include <translations/TranslationsModel.h>
class QTextCharFormat;
class SettingsObject;
@@ -71,6 +72,8 @@ slots:
void on_lwjglDirBrowseBtn_clicked();
void on_iconsDirBrowseBtn_clicked();
+ void languageIndexChanged(int index);
+
/*!
* Updates the list of update channels in the combo box.
*/
@@ -100,4 +103,6 @@ private:
QTextCharFormat *defaultFormat;
std::unique_ptr<LogColorCache> m_colors;
+
+ std::shared_ptr<TranslationsModel> m_languageModel;
};
diff --git a/application/pages/global/MultiMCPage.ui b/application/pages/global/MultiMCPage.ui
index f9d74a38..bf2b4da7 100644
--- a/application/pages/global/MultiMCPage.ui
+++ b/application/pages/global/MultiMCPage.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>458</width>
+ <width>467</width>
<height>614</height>
</rect>
</property>
@@ -320,7 +320,7 @@
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
- <string>Language (needs restart):</string>
+ <string>Language:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
diff --git a/application/setupwizard/SetupWizard.cpp b/application/setupwizard/SetupWizard.cpp
index af6b8c8e..3c87759f 100644
--- a/application/setupwizard/SetupWizard.cpp
+++ b/application/setupwizard/SetupWizard.cpp
@@ -67,7 +67,27 @@ public:
languageView->setCurrentIndex(index);
connect(languageView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &LanguageWizardPage::languageRowChanged);
}
- virtual ~LanguageWizardPage() {};
+
+ virtual ~LanguageWizardPage()
+ {
+ };
+
+ bool validatePage() override
+ {
+ auto settings = MMC->settings();
+ auto translations = MMC->translations();
+ QString key = translations->data(languageView->currentIndex(), Qt::UserRole).toString();
+ settings->set("Language", key);
+ return true;
+ }
+
+ static bool isRequired()
+ {
+ auto settings = MMC->settings();
+ if (settings->get("Language").toString().isEmpty())
+ return true;
+ return false;
+ }
protected:
void retranslate() override
@@ -116,7 +136,35 @@ public:
verticalLayout_3->addWidget(checkBox);
retranslate();
}
- virtual ~AnalyticsWizardPage() {};
+
+ virtual ~AnalyticsWizardPage()
+ {
+ };
+
+ bool validatePage() override
+ {
+ auto settings = MMC->settings();
+ auto analytics = MMC->analytics();
+ auto status = checkBox->isChecked();
+ settings->set("AnalyticsSeen", analytics->version());
+ settings->set("Analytics", status);
+ return true;
+ }
+
+ static bool isRequired()
+ {
+ auto settings = MMC->settings();
+ auto analytics = MMC->analytics();
+ if(!settings->get("Analytics").toBool())
+ {
+ return false;
+ }
+ if(settings->get("AnalyticsSeen").toInt() < analytics->version())
+ {
+ return true;
+ }
+ return false;
+ }
protected:
void retranslate() override
@@ -149,20 +197,12 @@ SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
{
setObjectName(QStringLiteral("SetupWizard"));
resize(615, 659);
- setOptions(QWizard::NoCancelButton);
- if (languageIsRequired())
+ setOptions(QWizard::NoCancelButton | QWizard::IndependentPages);
+ if (LanguageWizardPage::isRequired())
{
setPage(Page::Language, new LanguageWizardPage(this));
}
- if(javaIsRequired())
- {
- // set up java selection
- }
- else
- {
- removePage(Page::Java);
- }
- if(analyticsIsRequired())
+ if(AnalyticsWizardPage::isRequired())
{
setPage(Page::Analytics, new AnalyticsWizardPage(this));
}
@@ -189,14 +229,7 @@ SetupWizard::~SetupWizard()
{
}
-bool SetupWizard::languageIsRequired()
-{
- auto settings = MMC->settings();
- if (settings->get("Language").toString().isEmpty())
- return true;
- return false;
-}
-
+/*
bool SetupWizard::javaIsRequired()
{
QString currentHostName = QHostInfo::localHostName();
@@ -214,25 +247,13 @@ bool SetupWizard::javaIsRequired()
}
return false;
}
-
-bool SetupWizard::analyticsIsRequired()
-{
- auto settings = MMC->settings();
- auto analytics = MMC->analytics();
- if(settings->get("AnalyticsSeen").toInt() < analytics->version())
- {
- return true;
- }
- return false;
-}
+*/
bool SetupWizard::isRequired()
{
- if (languageIsRequired())
- return true;
- if (javaIsRequired())
+ if (LanguageWizardPage::isRequired())
return true;
- if (analyticsIsRequired())
+ if (AnalyticsWizardPage::isRequired())
return true;
return false;
}
diff --git a/application/setupwizard/SetupWizard.h b/application/setupwizard/SetupWizard.h
index e5c8ad77..adf254c7 100644
--- a/application/setupwizard/SetupWizard.h
+++ b/application/setupwizard/SetupWizard.h
@@ -34,9 +34,6 @@ public: /* con/destructors */
public: /* methods */
static bool isRequired();
- static bool javaIsRequired();
- static bool languageIsRequired();
- static bool analyticsIsRequired();
private: /* methods */
void retranslate();