Improve wizzard page

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-09-12 17:57:57 +03:00
parent fa68428a90
commit c85294af9d
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
12 changed files with 384 additions and 39 deletions

View File

@ -67,8 +67,10 @@
#include "ui/pages/global/MinecraftPage.h"
#include "ui/pages/global/ProxyPage.h"
#include "ui/setupwizard/AutoJavaWizardPage.h"
#include "ui/setupwizard/JavaWizardPage.h"
#include "ui/setupwizard/LanguageWizardPage.h"
#include "ui/setupwizard/LoginWizardPage.h"
#include "ui/setupwizard/PasteWizardPage.h"
#include "ui/setupwizard/SetupWizard.h"
#include "ui/setupwizard/ThemeWizardPage.h"
@ -650,6 +652,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
auto defaultEnableAutoJava = m_settings->get("JavaPath").toString().isEmpty();
m_settings->registerSetting("AutomaticJavaSwitch", defaultEnableAutoJava);
m_settings->registerSetting("AutomaticJavaDownload", defaultEnableAutoJava);
m_settings->registerSetting("UserAskedAboutAutomaticJavaDownload", false);
// Legacy settings
m_settings->registerSetting("OnlineFixes", false);
@ -1077,13 +1080,15 @@ bool Application::createSetupWizard()
}
return false;
}();
bool askjava = BuildConfig.JAVA_DOWNLOADER_ENABLED && !javaRequired && !m_settings->get("AutomaticJavaDownload").toBool() &&
!m_settings->get("AutomaticJavaSwitch").toBool() && !m_settings->get("UserAskedAboutAutomaticJavaDownload").toBool();
bool languageRequired = settings()->get("Language").toString().isEmpty();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
bool validWidgets = m_themeManager->isValidApplicationTheme(settings()->get("ApplicationTheme").toString());
bool validIcons = m_themeManager->isValidIconTheme(settings()->get("IconTheme").toString());
bool login = !m_accounts->anyAccountIsValid() && capabilities() & Application::SupportsMSA;
bool themeInterventionRequired = !validWidgets || !validIcons;
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired || askjava || login;
if (wizardRequired) {
// set default theme after going into theme wizard
if (!validIcons)
@ -1100,6 +1105,8 @@ bool Application::createSetupWizard()
if (javaRequired) {
m_setupWizard->addPage(new JavaWizardPage(m_setupWizard));
} else if (askjava) {
m_setupWizard->addPage(new AutoJavaWizardPage(m_setupWizard));
}
if (pasteInterventionRequired) {
@ -1110,11 +1117,14 @@ bool Application::createSetupWizard()
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
}
if (login) {
m_setupWizard->addPage(new LoginWizardPage(m_setupWizard));
}
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
m_setupWizard->show();
return true;
}
return false;
return wizardRequired || login;
}
bool Application::updaterEnabled()
@ -1259,16 +1269,23 @@ Application::~Application()
void Application::messageReceived(const QByteArray& message)
{
if (status() != Initialized) {
qDebug() << "Received message" << message << "while still initializing. It will be ignored.";
return;
}
ApplicationMessage received;
received.parse(message);
auto& command = received.command;
if (status() != Initialized) {
bool isLoginAtempt = false;
if (command == "import") {
QString url = received.args["url"];
isLoginAtempt = !url.isEmpty() && normalizeImportUrl(url).scheme() == BuildConfig.LAUNCHER_APP_BINARY_NAME;
}
if (!isLoginAtempt) {
qDebug() << "Received message" << message << "while still initializing. It will be ignored.";
return;
}
}
if (command == "activate") {
showMainWindow();
} else if (command == "import") {

View File

@ -842,6 +842,10 @@ SET(LAUNCHER_SOURCES
ui/setupwizard/PasteWizardPage.h
ui/setupwizard/ThemeWizardPage.cpp
ui/setupwizard/ThemeWizardPage.h
ui/setupwizard/AutoJavaWizardPage.cpp
ui/setupwizard/AutoJavaWizardPage.h
ui/setupwizard/LoginWizardPage.cpp
ui/setupwizard/LoginWizardPage.h
# GUI - themes
ui/themes/FusionTheme.cpp
@ -1154,6 +1158,8 @@ endif()
qt_wrap_ui(LAUNCHER_UI
ui/MainWindow.ui
ui/setupwizard/PasteWizardPage.ui
ui/setupwizard/AutoJavaWizardPage.ui
ui/setupwizard/LoginWizardPage.ui
ui/setupwizard/ThemeWizardPage.ui
ui/pages/global/AccountListPage.ui
ui/pages/global/JavaPage.ui

View File

@ -0,0 +1,33 @@
#include "AutoJavaWizardPage.h"
#include "ui_AutoJavaWizardPage.h"
#include "Application.h"
AutoJavaWizardPage::AutoJavaWizardPage(QWidget* parent) : BaseWizardPage(parent), ui(new Ui::AutoJavaWizardPage)
{
ui->setupUi(this);
}
AutoJavaWizardPage::~AutoJavaWizardPage()
{
delete ui;
}
void AutoJavaWizardPage::initializePage() {}
bool AutoJavaWizardPage::validatePage()
{
auto s = APPLICATION->settings();
if (!ui->previousSettingsRadioButton->isChecked()) {
s->set("AutomaticJavaSwitch", true);
s->set("AutomaticJavaDownload", true);
}
s->set("UserAskedAboutAutomaticJavaDownload", true);
return true;
}
void AutoJavaWizardPage::retranslate()
{
ui->retranslateUi(this);
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <QWidget>
#include "BaseWizardPage.h"
namespace Ui {
class AutoJavaWizardPage;
}
class AutoJavaWizardPage : public BaseWizardPage {
Q_OBJECT
public:
explicit AutoJavaWizardPage(QWidget* parent = nullptr);
~AutoJavaWizardPage();
void initializePage() override;
bool validatePage() override;
void retranslate() override;
private:
Ui::AutoJavaWizardPage* ui;
};

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AutoJavaWizardPage</class>
<widget class="QWidget" name="AutoJavaWizardPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<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;&lt;span style=&quot; font-size:14pt; font-weight:600;&quot;&gt;New Feature Alert!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>We've added a feature to automatically download the correct Java version for each version of Minecraft(this can be changed in the Java Settings). Would you like to enable or disable this feature?</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="defaultSettingsRadioButton">
<property name="text">
<string>Enable Auto-Download</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="previousSettingsRadioButton">
<property name="text">
<string>Disable Auto-Download</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>156</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

View File

@ -55,6 +55,7 @@ bool JavaWizardPage::validatePage()
auto result = m_java_widget->validate();
settings->set("AutomaticJavaSwitch", m_java_widget->autoDetectJava());
settings->set("AutomaticJavaDownload", m_java_widget->autoDownloadJava());
settings->set("UserAskedAboutAutomaticJavaDownload", true);
switch (result) {
default:
case JavaSettingsWidget::ValidationStatus::Bad: {
@ -82,7 +83,6 @@ void JavaWizardPage::retranslate()
{
setTitle(tr("Java"));
setSubTitle(
tr("You do not have a working Java set up yet or it went missing.\n"
"Please select one of the following or browse for a Java executable."));
tr("Please select how much memory to allocate to instances and if Prism Launcher should manage java automatically or manually."));
m_java_widget->retranslate();
}

View File

@ -9,7 +9,7 @@ class JavaWizardPage : public BaseWizardPage {
public:
explicit JavaWizardPage(QWidget* parent = Q_NULLPTR);
virtual ~JavaWizardPage() {};
virtual ~JavaWizardPage() = default;
bool wantsRefreshButton() override;
void refresh() override;

View File

@ -0,0 +1,45 @@
#include "LoginWizardPage.h"
#include "minecraft/auth/AccountList.h"
#include "ui/dialogs/MSALoginDialog.h"
#include "ui_LoginWizardPage.h"
#include "Application.h"
LoginWizardPage::LoginWizardPage(QWidget* parent) : BaseWizardPage(parent), ui(new Ui::LoginWizardPage)
{
ui->setupUi(this);
}
LoginWizardPage::~LoginWizardPage()
{
delete ui;
}
void LoginWizardPage::initializePage() {}
bool LoginWizardPage::validatePage()
{
return true;
}
void LoginWizardPage::retranslate()
{
ui->retranslateUi(this);
}
void LoginWizardPage::on_pushButton_clicked()
{
wizard()->hide();
auto account = MSALoginDialog::newAccount(nullptr);
wizard()->show();
if (account) {
APPLICATION->accounts()->addAccount(account);
APPLICATION->accounts()->setDefaultAccount(account);
}
if (wizard()->currentId() == wizard()->pageIds().last()) {
wizard()->accept();
} else {
wizard()->next();
}
}

View File

@ -0,0 +1,24 @@
#pragma once
#include <QWidget>
#include "BaseWizardPage.h"
namespace Ui {
class LoginWizardPage;
}
class LoginWizardPage : public BaseWizardPage {
Q_OBJECT
public:
explicit LoginWizardPage(QWidget* parent = nullptr);
~LoginWizardPage();
void initializePage() override;
bool validatePage() override;
void retranslate() override;
private slots:
void on_pushButton_clicked();
private:
Ui::LoginWizardPage* ui;
};

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LoginWizardPage</class>
<widget class="QWidget" name="LoginWizardPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<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;&lt;span style=&quot; font-size:14pt; font-weight:600;&quot;&gt;Add Microsoft account&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>In order to play Minecraft, you must have at least one Microsoft account logged in. Do you want to log in now?</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Add Microsoft account</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>156</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

View File

@ -3,9 +3,11 @@
#include <QFileDialog>
#include <QGroupBox>
#include <QLabel>
#include <QLayoutItem>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSizePolicy>
#include <QSpinBox>
#include <QToolButton>
#include <QVBoxLayout>
@ -34,11 +36,13 @@ JavaSettingsWidget::JavaSettingsWidget(QWidget* parent) : QWidget(parent)
goodIcon = APPLICATION->getThemedIcon("status-good");
yellowIcon = APPLICATION->getThemedIcon("status-yellow");
badIcon = APPLICATION->getThemedIcon("status-bad");
m_memoryTimer = new QTimer(this);
setupUi();
connect(m_minMemSpinBox, SIGNAL(valueChanged(int)), this, SLOT(memoryValueChanged(int)));
connect(m_maxMemSpinBox, SIGNAL(valueChanged(int)), this, SLOT(memoryValueChanged(int)));
connect(m_permGenSpinBox, SIGNAL(valueChanged(int)), this, SLOT(memoryValueChanged(int)));
connect(m_minMemSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onSpinBoxValueChanged(int)));
connect(m_maxMemSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onSpinBoxValueChanged(int)));
connect(m_permGenSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onSpinBoxValueChanged(int)));
connect(m_memoryTimer, &QTimer::timeout, this, &JavaSettingsWidget::memoryValueChanged);
connect(m_versionWidget, &VersionSelectWidget::selectedVersionChanged, this, &JavaSettingsWidget::javaVersionSelected);
connect(m_javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::on_javaBrowseBtn_clicked);
connect(m_javaPathTextBox, &QLineEdit::textEdited, this, &JavaSettingsWidget::javaPathEdited);
@ -55,7 +59,6 @@ void JavaSettingsWidget::setupUi()
m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
m_versionWidget = new VersionSelectWidget(this);
m_verticalLayout->addWidget(m_versionWidget);
m_horizontalLayout = new QHBoxLayout();
m_horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
@ -73,8 +76,6 @@ void JavaSettingsWidget::setupUi()
m_javaStatusBtn->setIcon(yellowIcon);
m_horizontalLayout->addWidget(m_javaStatusBtn);
m_verticalLayout->addLayout(m_horizontalLayout);
m_memoryGroupBox = new QGroupBox(this);
m_memoryGroupBox->setObjectName(QStringLiteral("memoryGroupBox"));
m_gridLayout_2 = new QGridLayout(m_memoryGroupBox);
@ -136,8 +137,6 @@ void JavaSettingsWidget::setupUi()
m_horizontalBtnLayout->addWidget(m_javaDownloadBtn);
}
m_verticalLayout->addLayout(m_horizontalBtnLayout);
m_autoJavaGroupBox = new QGroupBox(this);
m_autoJavaGroupBox->setObjectName(QStringLiteral("autoJavaGroupBox"));
m_veriticalJavaLayout = new QVBoxLayout(m_autoJavaGroupBox);
@ -145,21 +144,42 @@ void JavaSettingsWidget::setupUi()
m_autodetectJavaCheckBox = new QCheckBox(m_autoJavaGroupBox);
m_autodetectJavaCheckBox->setObjectName("autodetectJavaCheckBox");
m_autodetectJavaCheckBox->setChecked(true);
m_veriticalJavaLayout->addWidget(m_autodetectJavaCheckBox);
if (BuildConfig.JAVA_DOWNLOADER_ENABLED) {
m_autodownloadCheckBox = new QCheckBox(m_autoJavaGroupBox);
m_autodownloadCheckBox->setObjectName("autodownloadCheckBox");
m_autodownloadCheckBox->setEnabled(false);
m_autodownloadCheckBox->setEnabled(m_autodetectJavaCheckBox->isChecked());
m_veriticalJavaLayout->addWidget(m_autodownloadCheckBox);
connect(m_autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this] {
m_autodownloadCheckBox->setEnabled(m_autodetectJavaCheckBox->isChecked());
if (!m_autodetectJavaCheckBox->isChecked())
m_autodownloadCheckBox->setChecked(false);
});
connect(m_autodownloadCheckBox, &QCheckBox::stateChanged, this, [this] {
auto isChecked = m_autodownloadCheckBox->isChecked();
m_versionWidget->setVisible(!isChecked);
m_javaStatusBtn->setVisible(!isChecked);
m_javaBrowseBtn->setVisible(!isChecked);
m_javaPathTextBox->setVisible(!isChecked);
m_javaDownloadBtn->setVisible(!isChecked);
if (!isChecked) {
m_verticalLayout->removeItem(m_verticalSpacer);
} else {
m_verticalLayout->addSpacerItem(m_verticalSpacer);
}
});
}
m_verticalLayout->addWidget(m_autoJavaGroupBox);
m_verticalLayout->addLayout(m_horizontalBtnLayout);
m_verticalLayout->addWidget(m_versionWidget);
m_verticalLayout->addLayout(m_horizontalLayout);
m_verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
retranslate();
}
@ -177,23 +197,16 @@ void JavaSettingsWidget::initialize()
m_maxMemSpinBox->setValue(observedMaxMemory);
m_permGenSpinBox->setValue(observedPermGenMemory);
updateThresholds();
if (BuildConfig.JAVA_DOWNLOADER_ENABLED) {
auto button =
CustomMessageBox::selectable(this, tr("Automatic Java Download"),
tr("%1 can automatically download the correct Java version for each version of Minecraft..\n"
"Do you want to enable Java auto-download?\n")
.arg(BuildConfig.LAUNCHER_DISPLAYNAME),
QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)
->exec();
auto checked = button == QMessageBox::Yes;
m_autodetectJavaCheckBox->setChecked(checked);
m_autodownloadCheckBox->setChecked(checked);
m_autodownloadCheckBox->setChecked(true);
}
}
void JavaSettingsWidget::refresh()
{
if (BuildConfig.JAVA_DOWNLOADER_ENABLED && m_autodownloadCheckBox->isChecked()) {
return;
}
if (JavaUtils::getJavaCheckPath().isEmpty()) {
JavaCommon::javaCheckNotFound(this);
return;
@ -297,20 +310,21 @@ int JavaSettingsWidget::permGenSize() const
return m_permGenSpinBox->value();
}
void JavaSettingsWidget::memoryValueChanged(int)
void JavaSettingsWidget::memoryValueChanged()
{
bool actuallyChanged = false;
unsigned int min = m_minMemSpinBox->value();
unsigned int max = m_maxMemSpinBox->value();
unsigned int permgen = m_permGenSpinBox->value();
QObject* obj = sender();
if (obj == m_minMemSpinBox && min != observedMinMemory) {
if (min != observedMinMemory) {
observedMinMemory = min;
actuallyChanged = true;
} else if (obj == m_maxMemSpinBox && max != observedMaxMemory) {
}
if (max != observedMaxMemory) {
observedMaxMemory = max;
actuallyChanged = true;
} else if (obj == m_permGenSpinBox && permgen != observedPermGenMemory) {
}
if (permgen != observedPermGenMemory) {
observedPermGenMemory = permgen;
actuallyChanged = true;
}
@ -505,6 +519,9 @@ void JavaSettingsWidget::updateThresholds()
} else if (observedMaxMemory < observedMinMemory) {
iconName = "status-yellow";
m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation is smaller than the minimum value"));
} else if (BuildConfig.JAVA_DOWNLOADER_ENABLED && m_autodownloadCheckBox->isChecked()) {
iconName = "status-good";
m_labelMaxMemIcon->setToolTip("");
} else if (observedMaxMemory > 2048 && !m_result.is_64bit) {
iconName = "status-bad";
m_labelMaxMemIcon->setToolTip(tr("You are exceeding the maximum allocation supported by 32-bit installations of Java."));
@ -530,3 +547,13 @@ bool JavaSettingsWidget::autoDetectJava() const
{
return m_autodetectJavaCheckBox->isChecked();
}
void JavaSettingsWidget::onSpinBoxValueChanged(int)
{
m_memoryTimer->start(500);
}
JavaSettingsWidget::~JavaSettingsWidget()
{
delete m_verticalSpacer;
};

View File

@ -17,6 +17,7 @@ class QGroupBox;
class QGridLayout;
class QLabel;
class QToolButton;
class QSpacerItem;
/**
* This is a widget for all the Java settings dialogs and pages.
@ -26,7 +27,7 @@ class JavaSettingsWidget : public QWidget {
public:
explicit JavaSettingsWidget(QWidget* parent);
virtual ~JavaSettingsWidget() = default;
virtual ~JavaSettingsWidget();
enum class JavaStatus { NotSet, Pending, Good, DoesNotExist, DoesNotStart, ReturnedInvalidData } javaStatus = JavaStatus::NotSet;
@ -48,7 +49,8 @@ class JavaSettingsWidget : public QWidget {
void updateThresholds();
protected slots:
void memoryValueChanged(int);
void onSpinBoxValueChanged(int);
void memoryValueChanged();
void javaPathEdited(const QString& path);
void javaVersionSelected(BaseVersion::Ptr version);
void on_javaBrowseBtn_clicked();
@ -65,6 +67,7 @@ class JavaSettingsWidget : public QWidget {
private: /* data */
VersionSelectWidget* m_versionWidget = nullptr;
QVBoxLayout* m_verticalLayout = nullptr;
QSpacerItem* m_verticalSpacer = nullptr;
QLineEdit* m_javaPathTextBox = nullptr;
QPushButton* m_javaBrowseBtn = nullptr;
@ -99,4 +102,5 @@ class JavaSettingsWidget : public QWidget {
uint64_t m_availableMemory = 0ull;
shared_qobject_ptr<JavaChecker> m_checker;
JavaChecker::Result m_result;
QTimer* m_memoryTimer;
};