From d6b09f7c139c73379976a9d179dd05b66afe13a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 25 Nov 2013 01:14:30 +0100 Subject: Add java checker to the instance settings --- gui/dialogs/InstanceSettings.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ gui/dialogs/InstanceSettings.h | 9 ++++++ gui/dialogs/InstanceSettings.ui | 36 +++++++++++++++-------- gui/dialogs/SettingsDialog.cpp | 2 +- gui/dialogs/SettingsDialog.ui | 28 +++++++++--------- logic/JavaChecker.cpp | 1 - 6 files changed, 110 insertions(+), 28 deletions(-) diff --git a/gui/dialogs/InstanceSettings.cpp b/gui/dialogs/InstanceSettings.cpp index add135b4..f059047f 100644 --- a/gui/dialogs/InstanceSettings.cpp +++ b/gui/dialogs/InstanceSettings.cpp @@ -17,10 +17,19 @@ * limitations under the License. */ +#include "MultiMC.h" #include "InstanceSettings.h" #include "ui_InstanceSettings.h" #include "gui/Platform.h" +#include "gui/dialogs/VersionSelectDialog.h" + +#include "logic/JavaUtils.h" #include "logic/NagUtils.h" +#include "logic/lists/JavaVersionList.h" +#include "logic/JavaChecker.h" + +#include +#include InstanceSettings::InstanceSettings(SettingsObject *obj, QWidget *parent) : m_obj(obj), QDialog(parent), ui(new Ui::InstanceSettings) @@ -181,3 +190,56 @@ void InstanceSettings::loadSettings() ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString()); ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString()); } + +void InstanceSettings::on_javaDetectBtn_clicked() +{ + JavaVersionPtr java; + + VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true); + vselect.setResizeOn(2); + vselect.exec(); + + if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) + { + java = std::dynamic_pointer_cast(vselect.selectedVersion()); + ui->javaPathTextBox->setText(java->path); + } +} + +void InstanceSettings::on_javaBrowseBtn_clicked() +{ + QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable")); + if (!dir.isNull()) + { + ui->javaPathTextBox->setText(dir); + } +} + +void InstanceSettings::on_javaTestBtn_clicked() +{ + checker.reset(new JavaChecker()); + connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this, + SLOT(checkFinished(JavaCheckResult))); + checker->performCheck(ui->javaPathTextBox->text()); +} + +void InstanceSettings::checkFinished(JavaCheckResult result) +{ + if (result.valid) + { + QString text; + text += "Java test succeeded!\n"; + if (result.is_64bit) + text += "Using 64bit java.\n"; + text += "\n"; + text += "Platform reported: " + result.realPlatform; + QMessageBox::information(this, tr("Java test success"), text); + } + else + { + QMessageBox::warning( + this, tr("Java test failure"), + tr("The specified java binary didn't work. You should use the auto-detect feature, " + "or set the path to the java executable.")); + } +} \ No newline at end of file diff --git a/gui/dialogs/InstanceSettings.h b/gui/dialogs/InstanceSettings.h index 452e7a58..1e7b9f6e 100644 --- a/gui/dialogs/InstanceSettings.h +++ b/gui/dialogs/InstanceSettings.h @@ -17,6 +17,7 @@ #include #include "settingsobject.h" +#include "logic/JavaChecker.h" namespace Ui { @@ -44,7 +45,15 @@ slots: void on_buttonBox_accepted(); void on_buttonBox_rejected(); + void on_javaDetectBtn_clicked(); + + void on_javaTestBtn_clicked(); + + void on_javaBrowseBtn_clicked(); + + void checkFinished(JavaCheckResult result); private: Ui::InstanceSettings *ui; SettingsObject *m_obj; + std::shared_ptr checker; }; diff --git a/gui/dialogs/InstanceSettings.ui b/gui/dialogs/InstanceSettings.ui index 27004ed8..04c32108 100644 --- a/gui/dialogs/InstanceSettings.ui +++ b/gui/dialogs/InstanceSettings.ui @@ -7,7 +7,7 @@ 0 0 526 - 590 + 622 @@ -278,6 +278,13 @@ false + + + + Test + + + @@ -285,25 +292,32 @@ - - - - + JVM arguments: - - + + + + + + + + - Auto-detect + Browse... - - + + + + Auto-detect... + + @@ -403,8 +417,6 @@ maxMemSpinBox permGenSpinBox javaSettingsGroupBox - javaPathTextBox - pushButton jvmArgsTextBox customCommandsGroupBox preLaunchCmdTextBox diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 57e15a5b..5dcf60f8 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -276,7 +276,7 @@ void SettingsDialog::checkFinished(JavaCheckResult result) } else { - QMessageBox::information( + QMessageBox::warning( this, tr("Java test failure"), tr("The specified java binary didn't work. You should use the auto-detect feature, " "or set the path to the java executable.")); diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 6a44a631..0dbc8def 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -394,7 +394,7 @@ - + @@ -410,45 +410,45 @@ - + - - + + - + 0 0 - Test + Auto-detect... - - + + - + 0 0 - Browse... + Test - - + + - + 0 0 - Auto-detect... + Browse... diff --git a/logic/JavaChecker.cpp b/logic/JavaChecker.cpp index 10b84fe1..fb37245f 100644 --- a/logic/JavaChecker.cpp +++ b/logic/JavaChecker.cpp @@ -84,6 +84,5 @@ void JavaChecker::timeout() { process->kill(); process.reset(); - emit checkFinished({}); } } -- cgit v1.2.3