Improved the message boxes for java wizzard

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-02-18 12:58:34 +02:00
parent 2f489d1aec
commit 4aafa98852
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318

View file

@ -4,6 +4,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QSpinBox> #include <QSpinBox>
#include <QToolButton> #include <QToolButton>
@ -11,6 +12,7 @@
#include <sys.h> #include <sys.h>
#include "DesktopServices.h"
#include "FileSystem.h" #include "FileSystem.h"
#include "JavaCommon.h" #include "JavaCommon.h"
#include "java/JavaChecker.h" #include "java/JavaChecker.h"
@ -174,8 +176,19 @@ void JavaSettingsWidget::initialize()
m_permGenSpinBox->setValue(observedPermGenMemory); m_permGenSpinBox->setValue(observedPermGenMemory);
updateThresholds(); updateThresholds();
m_autodetectJavaCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool()); auto button = CustomMessageBox::selectable(this, tr("Auto Java Download"),
m_autodownloadCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool() && s->get("AutomaticJavaDownload").toBool()); tr("%1 has now the ability to auto downloand the correct java for each minecraft version.\n"
"Do you want to enable java auto-download?\n")
.arg(BuildConfig.LAUNCHER_DISPLAYNAME),
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)
->exec();
if (button == QMessageBox::Yes) {
m_autodetectJavaCheckBox->setChecked(true);
m_autodownloadCheckBox->setChecked(true);
} else {
m_autodetectJavaCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool());
m_autodownloadCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool() && s->get("AutomaticJavaDownload").toBool());
}
} }
void JavaSettingsWidget::refresh() void JavaSettingsWidget::refresh()
@ -192,20 +205,52 @@ JavaSettingsWidget::ValidationStatus JavaSettingsWidget::validate()
switch (javaStatus) { switch (javaStatus) {
default: default:
case JavaStatus::NotSet: case JavaStatus::NotSet:
/* fallthrough */
case JavaStatus::DoesNotExist: case JavaStatus::DoesNotExist:
/* fallthrough */
case JavaStatus::DoesNotStart: case JavaStatus::DoesNotStart:
/* fallthrough */
case JavaStatus::ReturnedInvalidData: { case JavaStatus::ReturnedInvalidData: {
int button = CustomMessageBox::selectable(this, tr("No Java version selected"), if (!m_autodownloadCheckBox->isChecked()) { // the java will not be autodownloaded
tr("You didn't select a Java version or selected something that doesn't work.\n" int button = QMessageBox::No;
"%1 will not be able to start Minecraft.\n" if (m_result.mojangPlatform == "32" && maxHeapSize() > 2048) {
"Do you wish to proceed without any Java?" button = CustomMessageBox::selectable(
"\n\n" this, tr("Java x32 detected"),
"You can change the Java version in the settings later.\n") tr("You selected a 32 bit java, but allocated more than 2048MiB as maximum memory.\n"
.arg(BuildConfig.LAUNCHER_DISPLAYNAME), "%1 will not be able to start Minecraft.\n"
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton) "Do you wish to proceed?"
->exec(); "\n\n"
if (button == QMessageBox::No) { "You can change the Java version in the settings later.\n")
return ValidationStatus::Bad; .arg(BuildConfig.LAUNCHER_DISPLAYNAME),
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No | QMessageBox::Help, QMessageBox::NoButton)
->exec();
} else {
button = CustomMessageBox::selectable(this, tr("No Java version selected"),
tr("You didn't select a Java version or selected something that doesn't work.\n"
"%1 will not be able to start Minecraft.\n"
"Do you wish to proceed without any Java?"
"\n\n"
"You can change the Java version in the settings later.\n")
.arg(BuildConfig.LAUNCHER_DISPLAYNAME),
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
QMessageBox::NoButton)
->exec();
}
switch (button) {
case QMessageBox::Yes:
return ValidationStatus::JavaBad;
case QMessageBox::Help:
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg("java-wizzard")));
/* fallthrough */
case QMessageBox::No:
/* fallthrough */
default:
return ValidationStatus::Bad;
}
if (button == QMessageBox::No) {
return ValidationStatus::Bad;
}
} }
return ValidationStatus::JavaBad; return ValidationStatus::JavaBad;
} break; } break;