summaryrefslogtreecommitdiffstats
path: root/application/setupwizard
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-12-05 02:29:08 +0100
committerPetr Mrázek <peterix@gmail.com>2017-01-01 20:04:08 +0100
commit722896d41f15a8bc78a864f7adcfd0527648073c (patch)
tree027d64870a6c38b0f93792bcf13772934ca8a1e5 /application/setupwizard
parent46c5368a784499c0ac4975b8a157a0f923c18b5a (diff)
downloadMultiMC-722896d41f15a8bc78a864f7adcfd0527648073c.tar
MultiMC-722896d41f15a8bc78a864f7adcfd0527648073c.tar.gz
MultiMC-722896d41f15a8bc78a864f7adcfd0527648073c.tar.lz
MultiMC-722896d41f15a8bc78a864f7adcfd0527648073c.tar.xz
MultiMC-722896d41f15a8bc78a864f7adcfd0527648073c.zip
NOISSUE Translations model and initial setup wizard work
Diffstat (limited to 'application/setupwizard')
-rw-r--r--application/setupwizard/SetupWizard.cpp259
-rw-r--r--application/setupwizard/SetupWizard.h11
-rw-r--r--application/setupwizard/SetupWizard.ui289
3 files changed, 261 insertions, 298 deletions
diff --git a/application/setupwizard/SetupWizard.cpp b/application/setupwizard/SetupWizard.cpp
index b51b34a7..af6b8c8e 100644
--- a/application/setupwizard/SetupWizard.cpp
+++ b/application/setupwizard/SetupWizard.cpp
@@ -1,26 +1,273 @@
#include "SetupWizard.h"
+#include "translations/TranslationsModel.h"
+#include <MultiMC.h>
+#include <FileSystem.h>
+#include <ganalytics.h>
enum Page
{
Language,
Java,
Analytics,
- Themes,
- Accounts
+ // Themes,
+ // Accounts
};
-#include "ui_SetupWizard.h"
+#include <QtCore/QVariant>
+#include <QtWidgets/QAction>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QButtonGroup>
+#include <QtWidgets/QCheckBox>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QListView>
+#include <QtWidgets/QTextBrowser>
+#include <QtWidgets/QVBoxLayout>
+#include <QtWidgets/QWizard>
+#include <QtWidgets/QWizardPage>
-SetupWizard::SetupWizard(QWidget *parent):QWizard(parent), ui(new Ui::SetupWizard)
+class BaseWizardPage : public QWizardPage
{
- ui->setupUi(this);
+public:
+ explicit BaseWizardPage(QWidget *parent = Q_NULLPTR)
+ : QWizardPage(parent)
+ {
+ }
+ virtual ~BaseWizardPage() {};
+
+protected:
+ virtual void retranslate() = 0;
+ void changeEvent(QEvent * event) override
+ {
+ if (event->type() == QEvent::LanguageChange)
+ {
+ retranslate();
+ }
+ QWizardPage::changeEvent(event);
+ }
+};
+
+class LanguageWizardPage : public BaseWizardPage
+{
+ Q_OBJECT;
+public:
+ explicit LanguageWizardPage(QWidget *parent = Q_NULLPTR)
+ : BaseWizardPage(parent)
+ {
+ setObjectName(QStringLiteral("languagePage"));
+ verticalLayout = new QVBoxLayout(this);
+ verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+ languageView = new QListView(this);
+ languageView->setObjectName(QStringLiteral("languageView"));
+ verticalLayout->addWidget(languageView);
+ retranslate();
+
+ auto translations = MMC->translations();
+ auto index = translations->selectedIndex();
+ languageView->setModel(translations.get());
+ languageView->setCurrentIndex(index);
+ connect(languageView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &LanguageWizardPage::languageRowChanged);
+ }
+ virtual ~LanguageWizardPage() {};
+
+protected:
+ void retranslate() override
+ {
+ setTitle(QApplication::translate("LanguageWizardPage", "Language", Q_NULLPTR));
+ setSubTitle(QApplication::translate("LanguageWizardPage", "Select the language to use in MultiMC", Q_NULLPTR));
+ }
+
+protected slots:
+ void languageRowChanged(const QModelIndex &current, const QModelIndex &previous)
+ {
+ if (current == previous)
+ {
+ return;
+ }
+ auto translations = MMC->translations();
+ QString key = translations->data(current, Qt::UserRole).toString();
+ translations->selectLanguage(key);
+ translations->updateLanguage(key);
+ }
+
+private:
+ QVBoxLayout *verticalLayout = nullptr;
+ QListView *languageView = nullptr;
+};
+
+class AnalyticsWizardPage : public BaseWizardPage
+{
+ Q_OBJECT;
+public:
+ explicit AnalyticsWizardPage(QWidget *parent = Q_NULLPTR)
+ : BaseWizardPage(parent)
+ {
+ setObjectName(QStringLiteral("analyticsPage"));
+ verticalLayout_3 = new QVBoxLayout(this);
+ verticalLayout_3->setObjectName(QStringLiteral("verticalLayout_3"));
+ textBrowser = new QTextBrowser(this);
+ textBrowser->setObjectName(QStringLiteral("textBrowser"));
+ textBrowser->setAcceptRichText(false);
+ textBrowser->setOpenExternalLinks(true);
+ verticalLayout_3->addWidget(textBrowser);
+
+ checkBox = new QCheckBox(this);
+ checkBox->setObjectName(QStringLiteral("checkBox"));
+ checkBox->setChecked(true);
+ verticalLayout_3->addWidget(checkBox);
+ retranslate();
+ }
+ virtual ~AnalyticsWizardPage() {};
+
+protected:
+ void retranslate() override
+ {
+ setTitle(QApplication::translate("AnalyticsWizardPage", "Analytics", Q_NULLPTR));
+ setSubTitle(QApplication::translate("AnalyticsWizardPage", "We track some anonymous statistics about users.", Q_NULLPTR));
+ textBrowser->setHtml(QApplication::translate("AnalyticsWizardPage",
+ "<html><body>"
+ "<p>MultiMC sends anonymous usage statistics on every start of the application. This helps us decide what platforms and issues to focus on.</p>"
+ "<p>The data is processed by Google Analytics, see their <a href=\"https://support.google.com/analytics/answer/6004245?hl=en\">article on the matter</a>.</p>"
+ "<p>The following data is collected:</p>"
+ "<ul><li>A random unique ID of the MultiMC installation.<br />It is stored in the application settings (multimc.cfg).</li>"
+ "<li>Anonymized IP address.<br />Last octet is set to 0 by Google and not stored.</li>"
+ "<li>MultiMC version.</li>"
+ "<li>Operating system name, version and architecture.</li>"
+ "<li>CPU architecture (kernel architecture on linux).</li>"
+ "<li>Size of system memory.</li>"
+ "<li>Java version, architecture and memory settings.</li></ul>"
+ "<p>The analytics will activate on next start, unless you disable them in the settings.</p>"
+ "<p>If we change the tracked information, analytics won't be active for the first run and you will see this page again.</p></body></html>", Q_NULLPTR));
+ checkBox->setText(QApplication::translate("AnalyticsWizardPage", "Enable Analytics", Q_NULLPTR));
+ }
+private:
+ QVBoxLayout *verticalLayout_3 = nullptr;
+ QTextBrowser *textBrowser = nullptr;
+ QCheckBox *checkBox = nullptr;
+};
+
+SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
+{
+ setObjectName(QStringLiteral("SetupWizard"));
+ resize(615, 659);
+ setOptions(QWizard::NoCancelButton);
+ if (languageIsRequired())
+ {
+ setPage(Page::Language, new LanguageWizardPage(this));
+ }
+ if(javaIsRequired())
+ {
+ // set up java selection
+ }
+ else
+ {
+ removePage(Page::Java);
+ }
+ if(analyticsIsRequired())
+ {
+ setPage(Page::Analytics, new AnalyticsWizardPage(this));
+ }
+}
+
+void SetupWizard::retranslate()
+{
+ setButtonText(QWizard::NextButton, tr("Next >"));
+ setButtonText(QWizard::BackButton, tr("< Back"));
+ setButtonText(QWizard::FinishButton, tr("Finish"));
+ setWindowTitle(QApplication::translate("SetupWizard", "MultiMC Quick Setup", Q_NULLPTR));
+}
+
+void SetupWizard::changeEvent(QEvent *event)
+{
+ if (event->type() == QEvent::LanguageChange)
+ {
+ retranslate();
+ }
+ QWizard::changeEvent(event);
}
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();
+ QString oldHostName = MMC->settings()->get("LastHostname").toString();
+ if (currentHostName != oldHostName)
+ {
+ MMC->settings()->set("LastHostname", currentHostName);
+ return true;
+ }
+ QString currentJavaPath = MMC->settings()->get("JavaPath").toString();
+ QString actualPath = FS::ResolveExecutable(currentJavaPath);
+ if (actualPath.isNull())
+ {
+ return true;
+ }
+ 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()
{
- return true;
+ if (languageIsRequired())
+ return true;
+ if (javaIsRequired())
+ return true;
+ if (analyticsIsRequired())
+ return true;
+ return false;
}
+
+/*
+void MainWindow::checkSetDefaultJava()
+{
+ qDebug() << "Java path needs resetting, showing Java selection dialog...";
+
+ JavaInstallPtr java;
+
+ VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, false);
+ vselect.setResizeOn(2);
+ vselect.exec();
+
+ if (vselect.selectedVersion())
+ java = std::dynamic_pointer_cast<JavaInstall>(vselect.selectedVersion());
+ else
+ {
+ CustomMessageBox::selectable(this, tr("Invalid version selected"), tr("You didn't select a valid Java version, so MultiMC will "
+ "select the default. "
+ "You can change this in the settings dialog."),
+ QMessageBox::Warning)
+ ->show();
+
+ JavaUtils ju;
+ java = ju.GetDefaultJava();
+ }
+ if (java)
+ {
+ MMC->settings()->set("JavaPath", java->path);
+ }
+ else
+ MMC->settings()->set("JavaPath", QString("java"));
+}
+*/
+
+#include "SetupWizard.moc"
diff --git a/application/setupwizard/SetupWizard.h b/application/setupwizard/SetupWizard.h
index 5dbe90a9..e5c8ad77 100644
--- a/application/setupwizard/SetupWizard.h
+++ b/application/setupwizard/SetupWizard.h
@@ -30,10 +30,15 @@ public: /* con/destructors */
explicit SetupWizard(QWidget *parent = 0);
virtual ~SetupWizard();
+ void changeEvent(QEvent * event) override;
+
public: /* methods */
-static bool isRequired();
+ static bool isRequired();
+ static bool javaIsRequired();
+ static bool languageIsRequired();
+ static bool analyticsIsRequired();
-private: /* data */
- Ui::SetupWizard *ui = nullptr;
+private: /* methods */
+ void retranslate();
};
diff --git a/application/setupwizard/SetupWizard.ui b/application/setupwizard/SetupWizard.ui
deleted file mode 100644
index a78f3530..00000000
--- a/application/setupwizard/SetupWizard.ui
+++ /dev/null
@@ -1,289 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>SetupWizard</class>
- <widget class="QWizard" name="SetupWizard">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>628</width>
- <height>637</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>MultiMC Quick Setup</string>
- </property>
- <property name="options">
- <set>QWizard::NoCancelButton</set>
- </property>
- <widget class="QWizardPage" name="welcomePage">
- <property name="title">
- <string>Welcome</string>
- </property>
- <property name="subTitle">
- <string>Hello and welcome the quick setup wizard!</string>
- </property>
- <attribute name="pageId">
- <string notr="true">Page::Language</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Choose your &lt;s&gt;adventure&lt;/s&gt; language:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QListView" name="languageView"/>
- </item>
- </layout>
- </widget>
- <widget class="QWizardPage" name="javaPage">
- <property name="title">
- <string>Java</string>
- </property>
- <property name="subTitle">
- <string>Your java settings need attention!</string>
- </property>
- <attribute name="pageId">
- <string notr="true">Page::Java</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QGroupBox" name="javaSettingsGroupBox">
- <property name="title">
- <string>Java Runtime</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="4" column="1">
- <widget class="QTreeView" name="javaView"/>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="memoryGroupBox">
- <property name="title">
- <string>Memory</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="1" column="1">
- <widget class="QSpinBox" name="maxMemSpinBox">
- <property name="toolTip">
- <string>The maximum amount of memory Minecraft is allowed to use.</string>
- </property>
- <property name="suffix">
- <string notr="true"> MB</string>
- </property>
- <property name="minimum">
- <number>512</number>
- </property>
- <property name="maximum">
- <number>65536</number>
- </property>
- <property name="singleStep">
- <number>128</number>
- </property>
- <property name="value">
- <number>1024</number>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QLabel" name="labelMinMem">
- <property name="text">
- <string>Minimum memory allocation:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="labelMaxMem">
- <property name="text">
- <string>Maximum memory allocation:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="labelPermGen">
- <property name="text">
- <string notr="true">PermGen:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QSpinBox" name="permGenSpinBox">
- <property name="toolTip">
- <string>The amount of memory available to store loaded Java classes.</string>
- </property>
- <property name="suffix">
- <string notr="true"> MB</string>
- </property>
- <property name="minimum">
- <number>64</number>
- </property>
- <property name="maximum">
- <number>999999999</number>
- </property>
- <property name="singleStep">
- <number>8</number>
- </property>
- <property name="value">
- <number>64</number>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QSpinBox" name="minMemSpinBox">
- <property name="toolTip">
- <string>The amount of memory Minecraft is started with.</string>
- </property>
- <property name="suffix">
- <string notr="true"> MB</string>
- </property>
- <property name="minimum">
- <number>256</number>
- </property>
- <property name="maximum">
- <number>65536</number>
- </property>
- <property name="singleStep">
- <number>128</number>
- </property>
- <property name="value">
- <number>256</number>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QWizardPage" name="analyticsPage">
- <property name="title">
- <string>Analytics</string>
- </property>
- <property name="subTitle">
- <string>We track some anonymous statistics about users.</string>
- </property>
- <attribute name="pageId">
- <string notr="true">Page::Analytics</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QScrollArea" name="scrollArea">
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="sizeAdjustPolicy">
- <enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
- </property>
- <property name="widgetResizable">
- <bool>true</bool>
- </property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
- </property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>592</width>
- <height>477</height>
- </rect>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_4">
- <item>
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
-&lt;p&gt;MultiMC sends anonymous usage statistics on every start of the application. This helps us decide what platforms and issues to focus on.&lt;/p&gt;
-&lt;p&gt;The data is processed by Google Analytics, see their &lt;a href=&quot;https://support.google.com/analytics/answer/6004245?hl=en&quot;&gt;article on the matter&lt;/a&gt;.&lt;/p&gt;
-&lt;p&gt;The following data is collected:&lt;/p&gt;
-&lt;ul&gt;
-&lt;li&gt;A random unique ID of the MultiMC installation.&lt;br /&gt;It is stored in the application settings (multimc.cfg).&lt;/li&gt;
-&lt;li&gt;Anonymized IP address.&lt;br /&gt;Last octet is set to 0 by Google and not stored.&lt;/li&gt;
-&lt;li&gt;MultiMC version.&lt;/li&gt;
-&lt;li&gt;Operating system name, version and architecture.&lt;/li&gt;
-&lt;li&gt;CPU architecture (kernel architecture on linux).&lt;/li&gt;
-&lt;li&gt;Size of system memory.&lt;/li&gt;
-&lt;li&gt;Java version, architecture and memory settings.&lt;/li&gt;
-&lt;/ul&gt;
-&lt;p&gt;The analytics will activate on next start, unless you disable them in the settings.&lt;/p&gt;
-&lt;p&gt;If we change the tracked information, analytics won't be active for the first run and you will see this page again.&lt;/p&gt;
-&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="scaledContents">
- <bool>true</bool>
- </property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- <property name="openExternalLinks">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QWizardPage" name="themePage">
- <property name="title">
- <string>Themes and icons</string>
- </property>
- <property name="subTitle">
- <string>Change how things look.</string>
- </property>
- <attribute name="pageId">
- <string notr="true">Page::Themes</string>
- </attribute>
- <widget class="QLabel" name="label_2">
- <property name="geometry">
- <rect>
- <x>230</x>
- <y>70</y>
- <width>151</width>
- <height>71</height>
- </rect>
- </property>
- <property name="text">
- <string>Put stuff here.</string>
- </property>
- </widget>
- </widget>
- <widget class="QWizardPage" name="accountsPage">
- <property name="title">
- <string>Minecraft accounts</string>
- </property>
- <property name="subTitle">
- <string>Add your account - or accounts.</string>
- </property>
- <attribute name="pageId">
- <string notr="true">Page::Accounts</string>
- </attribute>
- <widget class="QLabel" name="label_3">
- <property name="geometry">
- <rect>
- <x>60</x>
- <y>60</y>
- <width>311</width>
- <height>131</height>
- </rect>
- </property>
- <property name="text">
- <string>Put existing accounts page here.</string>
- </property>
- </widget>
- </widget>
- </widget>
- <resources/>
- <connections/>
-</ui>