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,9 +176,20 @@ void JavaSettingsWidget::initialize()
m_permGenSpinBox->setValue(observedPermGenMemory); m_permGenSpinBox->setValue(observedPermGenMemory);
updateThresholds(); updateThresholds();
auto button = CustomMessageBox::selectable(this, tr("Auto Java Download"),
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_autodetectJavaCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool());
m_autodownloadCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool() && s->get("AutomaticJavaDownload").toBool()); m_autodownloadCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool() && s->get("AutomaticJavaDownload").toBool());
} }
}
void JavaSettingsWidget::refresh() void JavaSettingsWidget::refresh()
{ {
@ -192,21 +205,53 @@ 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
int button = QMessageBox::No;
if (m_result.mojangPlatform == "32" && maxHeapSize() > 2048) {
button = CustomMessageBox::selectable(
this, tr("Java x32 detected"),
tr("You selected a 32 bit java, but allocated more than 2048MiB as maximum memory.\n"
"%1 will not be able to start Minecraft.\n"
"Do you wish to proceed?"
"\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();
} 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" 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" "%1 will not be able to start Minecraft.\n"
"Do you wish to proceed without any Java?" "Do you wish to proceed without any Java?"
"\n\n" "\n\n"
"You can change the Java version in the settings later.\n") "You can change the Java version in the settings later.\n")
.arg(BuildConfig.LAUNCHER_DISPLAYNAME), .arg(BuildConfig.LAUNCHER_DISPLAYNAME),
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton) QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
QMessageBox::NoButton)
->exec(); ->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) { if (button == QMessageBox::No) {
return ValidationStatus::Bad; return ValidationStatus::Bad;
} }
}
return ValidationStatus::JavaBad; return ValidationStatus::JavaBad;
} break; } break;
case JavaStatus::Pending: { case JavaStatus::Pending: {