summaryrefslogtreecommitdiffstats
path: root/application/setupwizard/SetupWizard.cpp
blob: af6b8c8eb1cb73902c6467b0b4c6d9e81dd0ad3d (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include "SetupWizard.h"
#include "translations/TranslationsModel.h"
#include <MultiMC.h>
#include <FileSystem.h>
#include <ganalytics.h>

enum Page
{
	Language,
	Java,
	Analytics,
	// Themes,
	// Accounts
};

#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>

class BaseWizardPage : public QWizardPage
{
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()
{
	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"