Add download button to more pages + UI fixes
Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
@ -1,11 +1,15 @@
|
|||||||
#include "JavaDownloader.h"
|
#include "JavaDownloader.h"
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
|
#include "SysInfo.h"
|
||||||
#include "net/ChecksumValidator.h"
|
#include "net/ChecksumValidator.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
#include "quazip.h"
|
#include "quazip.h"
|
||||||
|
#include "ui/dialogs/ProgressDialog.h"
|
||||||
|
|
||||||
// Quick & dirty struct to store files
|
// Quick & dirty struct to store files
|
||||||
struct File {
|
struct File {
|
||||||
@ -95,6 +99,7 @@ void JavaDownloader::executeTask()
|
|||||||
elementDownload->addNetAction(dl);
|
elementDownload->addNetAction(dl);
|
||||||
}
|
}
|
||||||
QObject::connect(elementDownload, &NetJob::finished, [elementDownload] { elementDownload->deleteLater(); });
|
QObject::connect(elementDownload, &NetJob::finished, [elementDownload] { elementDownload->deleteLater(); });
|
||||||
|
QObject::connect(elementDownload, &NetJob::progress, this, &JavaDownloader::progress);
|
||||||
QObject::connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
|
QObject::connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
|
||||||
elementDownload->start();
|
elementDownload->start();
|
||||||
});
|
});
|
||||||
@ -182,3 +187,77 @@ void JavaDownloader::executeTask()
|
|||||||
|
|
||||||
netJob->start();
|
netJob->start();
|
||||||
}
|
}
|
||||||
|
void JavaDownloader::showPrompts(QWidget* parent)
|
||||||
|
{
|
||||||
|
QString sys = SysInfo::currentSystem();
|
||||||
|
if (sys == "osx") {
|
||||||
|
sys = "mac-os";
|
||||||
|
}
|
||||||
|
QString arch = SysInfo::useQTForArch();
|
||||||
|
QString version;
|
||||||
|
if (sys == "windows") {
|
||||||
|
if (arch == "x86_64") {
|
||||||
|
version = "windows-x64";
|
||||||
|
} else if (arch == "i386") {
|
||||||
|
version = "windows-x86";
|
||||||
|
} else {
|
||||||
|
// Unknown, maybe arm, appending arch for downloader
|
||||||
|
version = "windows-" + arch;
|
||||||
|
}
|
||||||
|
} else if (sys == "mac-os") {
|
||||||
|
if (arch == "arm64") {
|
||||||
|
version = "mac-os-arm64";
|
||||||
|
} else {
|
||||||
|
version = "mac-os";
|
||||||
|
}
|
||||||
|
} else if (sys == "linux") {
|
||||||
|
if (arch == "x86_64") {
|
||||||
|
version = "linux";
|
||||||
|
} else {
|
||||||
|
// will work for i386, and arm(64)
|
||||||
|
version = "linux-" + arch;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ? ? ? ? ? unknown os, at least it won't have a java version on mojang or azul, display warning
|
||||||
|
QMessageBox::warning(parent, tr("Unknown OS"),
|
||||||
|
tr("The OS you are running is not supported by Mojang or Azul. Please install Java manually."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Selection using QMessageBox for java 8 or 17
|
||||||
|
QMessageBox box(QMessageBox::Icon::Question, tr("Java version"),
|
||||||
|
tr("Do you want to download Java version 8 or 17?\n Java 8 is recommended for minecraft versions below 1.17\n Java 17 "
|
||||||
|
"is recommended for minecraft versions above or equal to 1.17"),
|
||||||
|
QMessageBox::NoButton, parent);
|
||||||
|
auto yes = box.addButton("Java 17", QMessageBox::AcceptRole);
|
||||||
|
auto no = box.addButton("Java 8", QMessageBox::AcceptRole);
|
||||||
|
auto both = box.addButton(tr("Download both"), QMessageBox::AcceptRole);
|
||||||
|
auto cancel = box.addButton(QMessageBox::Cancel);
|
||||||
|
|
||||||
|
if (QFileInfo::exists(FS::PathCombine(QString("java"), "java-legacy"))) {
|
||||||
|
no->setEnabled(false);
|
||||||
|
}
|
||||||
|
if (QFileInfo::exists(FS::PathCombine(QString("java"), "java-current"))) {
|
||||||
|
yes->setEnabled(false);
|
||||||
|
}
|
||||||
|
if (!yes->isEnabled() || !no->isEnabled()) {
|
||||||
|
both->setEnabled(false);
|
||||||
|
}
|
||||||
|
if (!yes->isEnabled() && !no->isEnabled()) {
|
||||||
|
QMessageBox::warning(parent, tr("Already installed !"), tr("Both versions of java are already installed !"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
box.exec();
|
||||||
|
if (box.clickedButton() == nullptr || box.clickedButton() == cancel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool isLegacy = box.clickedButton() == no;
|
||||||
|
|
||||||
|
auto down = new JavaDownloader(isLegacy, version);
|
||||||
|
ProgressDialog dialog(parent);
|
||||||
|
dialog.execWithTask(down);
|
||||||
|
if (box.clickedButton() == both) {
|
||||||
|
auto dwn = new JavaDownloader(false, version);
|
||||||
|
ProgressDialog dg(parent);
|
||||||
|
dg.execWithTask(dwn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ class JavaDownloader : public Task {
|
|||||||
explicit JavaDownloader(bool isLegacy, const QString& OS) : m_isLegacy(isLegacy), m_OS(OS) {}
|
explicit JavaDownloader(bool isLegacy, const QString& OS) : m_isLegacy(isLegacy), m_OS(OS) {}
|
||||||
|
|
||||||
void executeTask() override;
|
void executeTask() override;
|
||||||
|
static void showPrompts(QWidget* parent = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isLegacy;
|
bool m_isLegacy;
|
||||||
|
@ -52,10 +52,7 @@
|
|||||||
#include <sys.h>
|
#include <sys.h>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "JavaDownloader.h"
|
#include "JavaDownloader.h"
|
||||||
#include "SysInfo.h"
|
|
||||||
#include "settings/SettingsObject.h"
|
#include "settings/SettingsObject.h"
|
||||||
#include "ui/dialogs/ProgressDialog.h"
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
|
|
||||||
JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage)
|
JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage)
|
||||||
{
|
{
|
||||||
@ -181,57 +178,9 @@ void JavaPage::on_javaTestBtn_clicked()
|
|||||||
checker->run();
|
checker->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaPage::on_javaDownloadBtn_clicked(){
|
void JavaPage::on_javaDownloadBtn_clicked()
|
||||||
QString sys = SysInfo::currentSystem();
|
{
|
||||||
if(sys == "osx"){
|
JavaDownloader::showPrompts(this);
|
||||||
sys = "mac-os";
|
|
||||||
}
|
|
||||||
QString arch = SysInfo::useQTForArch();
|
|
||||||
QString version;
|
|
||||||
if(sys == "windows"){
|
|
||||||
if(arch == "x86_64"){
|
|
||||||
version = "windows-x64";
|
|
||||||
}else if(arch == "i386"){
|
|
||||||
version = "windows-x86";
|
|
||||||
}else{
|
|
||||||
//Unknown, maybe arm, appending arch for downloader
|
|
||||||
version = "windows-"+arch;
|
|
||||||
}
|
|
||||||
}else if(sys == "mac-os"){
|
|
||||||
if(arch == "arm64"){
|
|
||||||
version = "mac-os-arm64";
|
|
||||||
}else{
|
|
||||||
version = "mac-os";
|
|
||||||
}
|
|
||||||
}else if(sys == "linux"){
|
|
||||||
if(arch == "x86_64"){
|
|
||||||
version = "linux";
|
|
||||||
}else {
|
|
||||||
// will work for i386, and arm(64)
|
|
||||||
version = "linux-" + arch;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
// ? ? ? ? ? unknown os, at least it won't have a java version on mojang or azul, display warning
|
|
||||||
QMessageBox::warning(this, tr("Unknown OS"), tr("The OS you are running is not supported by Mojang or Azul. Please install Java manually."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Selection using QMessageBox for java 8 or 17
|
|
||||||
QMessageBox box(QMessageBox::Icon::Question, tr("Java version"), tr("Do you want to download Java version 8 or 17?\n Java 8 is recommended for minecraft versions below 1.17\n Java 17 is recommended for minecraft versions above or equal to 1.17"),
|
|
||||||
QMessageBox::NoButton, this);
|
|
||||||
box.addButton("Java 17", QMessageBox::YesRole);
|
|
||||||
auto no = box.addButton("Java 8", QMessageBox::NoRole);
|
|
||||||
auto cancel = box.addButton(tr("Download both"), QMessageBox::AcceptRole);
|
|
||||||
box.exec();
|
|
||||||
bool isLegacy = box.clickedButton() == no;
|
|
||||||
|
|
||||||
auto down = new JavaDownloader(isLegacy, version);
|
|
||||||
ProgressDialog dialog(this);
|
|
||||||
dialog.execWithTask(down);
|
|
||||||
if(box.clickedButton() == cancel) {
|
|
||||||
auto dwn = new JavaDownloader(false, version);
|
|
||||||
ProgressDialog dg(this);
|
|
||||||
dg.execWithTask(dwn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaPage::checkerFinished()
|
void JavaPage::checkerFinished()
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
#include "JavaCommon.h"
|
#include "JavaCommon.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
|
#include "JavaDownloader.h"
|
||||||
#include "java/JavaInstallList.h"
|
#include "java/JavaInstallList.h"
|
||||||
#include "java/JavaUtils.h"
|
#include "java/JavaUtils.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
@ -374,6 +375,11 @@ void InstanceSettingsPage::loadSettings()
|
|||||||
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
|
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InstanceSettingsPage::on_javaDownloadBtn_clicked()
|
||||||
|
{
|
||||||
|
JavaDownloader::showPrompts(this);
|
||||||
|
}
|
||||||
|
|
||||||
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
||||||
{
|
{
|
||||||
if (JavaUtils::getJavaCheckPath().isEmpty()) {
|
if (JavaUtils::getJavaCheckPath().isEmpty()) {
|
||||||
|
@ -81,6 +81,7 @@ private slots:
|
|||||||
void on_javaDetectBtn_clicked();
|
void on_javaDetectBtn_clicked();
|
||||||
void on_javaTestBtn_clicked();
|
void on_javaTestBtn_clicked();
|
||||||
void on_javaBrowseBtn_clicked();
|
void on_javaBrowseBtn_clicked();
|
||||||
|
void on_javaDownloadBtn_clicked();
|
||||||
|
|
||||||
void applySettings();
|
void applySettings();
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
@ -95,6 +95,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="javaDownloadBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Download Java...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "JavaCommon.h"
|
#include "JavaCommon.h"
|
||||||
#include "java/JavaInstall.h"
|
#include "java/JavaInstall.h"
|
||||||
#include "java/JavaUtils.h"
|
#include "java/JavaUtils.h"
|
||||||
|
#include "JavaDownloader.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
@ -38,6 +39,8 @@ JavaSettingsWidget::JavaSettingsWidget(QWidget* parent) : QWidget(parent)
|
|||||||
connect(m_javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::on_javaBrowseBtn_clicked);
|
connect(m_javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::on_javaBrowseBtn_clicked);
|
||||||
connect(m_javaPathTextBox, &QLineEdit::textEdited, this, &JavaSettingsWidget::javaPathEdited);
|
connect(m_javaPathTextBox, &QLineEdit::textEdited, this, &JavaSettingsWidget::javaPathEdited);
|
||||||
connect(m_javaStatusBtn, &QToolButton::clicked, this, &JavaSettingsWidget::on_javaStatusBtn_clicked);
|
connect(m_javaStatusBtn, &QToolButton::clicked, this, &JavaSettingsWidget::on_javaStatusBtn_clicked);
|
||||||
|
connect(m_javaDownloadBtn, &QPushButton::clicked, this, &JavaSettingsWidget::on_javaDownloadBtn_clicked);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaSettingsWidget::setupUi()
|
void JavaSettingsWidget::setupUi()
|
||||||
@ -115,6 +118,10 @@ void JavaSettingsWidget::setupUi()
|
|||||||
|
|
||||||
m_verticalLayout->addWidget(m_memoryGroupBox);
|
m_verticalLayout->addWidget(m_memoryGroupBox);
|
||||||
|
|
||||||
|
m_javaDownloadBtn = new QPushButton("Download Java",this);
|
||||||
|
|
||||||
|
m_verticalLayout->addWidget(m_javaDownloadBtn);
|
||||||
|
|
||||||
retranslate();
|
retranslate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +283,11 @@ void JavaSettingsWidget::on_javaBrowseBtn_clicked()
|
|||||||
m_javaPathTextBox->setText(cooked_path);
|
m_javaPathTextBox->setText(cooked_path);
|
||||||
checkJavaPath(cooked_path);
|
checkJavaPath(cooked_path);
|
||||||
}
|
}
|
||||||
|
void JavaSettingsWidget::on_javaDownloadBtn_clicked()
|
||||||
|
{
|
||||||
|
JavaDownloader::showPrompts(this);
|
||||||
|
|
||||||
|
}
|
||||||
void JavaSettingsWidget::on_javaStatusBtn_clicked()
|
void JavaSettingsWidget::on_javaStatusBtn_clicked()
|
||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
|
@ -63,6 +63,7 @@ protected slots:
|
|||||||
void javaVersionSelected(BaseVersionPtr version);
|
void javaVersionSelected(BaseVersionPtr version);
|
||||||
void on_javaBrowseBtn_clicked();
|
void on_javaBrowseBtn_clicked();
|
||||||
void on_javaStatusBtn_clicked();
|
void on_javaStatusBtn_clicked();
|
||||||
|
void on_javaDownloadBtn_clicked();
|
||||||
void checkFinished(JavaCheckResult result);
|
void checkFinished(JavaCheckResult result);
|
||||||
|
|
||||||
protected: /* methods */
|
protected: /* methods */
|
||||||
@ -88,6 +89,8 @@ private: /* data */
|
|||||||
QSpinBox *m_minMemSpinBox = nullptr;
|
QSpinBox *m_minMemSpinBox = nullptr;
|
||||||
QLabel *m_labelPermGen = nullptr;
|
QLabel *m_labelPermGen = nullptr;
|
||||||
QSpinBox *m_permGenSpinBox = nullptr;
|
QSpinBox *m_permGenSpinBox = nullptr;
|
||||||
|
|
||||||
|
QPushButton *m_javaDownloadBtn = nullptr;
|
||||||
QIcon goodIcon;
|
QIcon goodIcon;
|
||||||
QIcon yellowIcon;
|
QIcon yellowIcon;
|
||||||
QIcon badIcon;
|
QIcon badIcon;
|
||||||
|
Reference in New Issue
Block a user