2013-07-14 20:01:30 +00:00
|
|
|
/* Copyright 2013 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Authors: Andrew Okin
|
|
|
|
* Peterix
|
|
|
|
* Orochimarufan <orochimarufan.x3@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-11-25 00:14:30 +00:00
|
|
|
#include "MultiMC.h"
|
2013-11-04 01:53:05 +00:00
|
|
|
#include "InstanceSettings.h"
|
|
|
|
#include "ui_InstanceSettings.h"
|
|
|
|
#include "gui/Platform.h"
|
2013-11-25 00:14:30 +00:00
|
|
|
#include "gui/dialogs/VersionSelectDialog.h"
|
|
|
|
|
|
|
|
#include "logic/JavaUtils.h"
|
2013-11-06 01:18:47 +00:00
|
|
|
#include "logic/NagUtils.h"
|
2013-11-25 00:14:30 +00:00
|
|
|
#include "logic/lists/JavaVersionList.h"
|
|
|
|
#include "logic/JavaChecker.h"
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2013-11-04 01:53:05 +00:00
|
|
|
|
|
|
|
InstanceSettings::InstanceSettings(SettingsObject *obj, QWidget *parent)
|
2013-12-01 15:34:51 +00:00
|
|
|
: QDialog(parent), ui(new Ui::InstanceSettings), m_obj(obj)
|
2013-07-14 18:26:53 +00:00
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
MultiMCPlatform::fixWM_CLASS(this);
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
loadSettings();
|
2013-07-14 18:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InstanceSettings::~InstanceSettings()
|
|
|
|
{
|
2013-07-15 22:30:32 +00:00
|
|
|
delete ui;
|
2013-07-14 18:26:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
void InstanceSettings::showEvent(QShowEvent *ev)
|
2013-08-26 02:34:37 +00:00
|
|
|
{
|
|
|
|
QDialog::showEvent(ev);
|
|
|
|
adjustSize();
|
|
|
|
}
|
|
|
|
|
2013-07-14 18:26:53 +00:00
|
|
|
void InstanceSettings::on_customCommandsGroupBox_toggled(bool state)
|
|
|
|
{
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->labelCustomCmdsDescription->setEnabled(state);
|
2013-07-14 18:26:53 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 22:30:32 +00:00
|
|
|
void InstanceSettings::on_buttonBox_accepted()
|
2013-07-14 18:26:53 +00:00
|
|
|
{
|
2013-07-15 22:30:32 +00:00
|
|
|
applySettings();
|
|
|
|
accept();
|
|
|
|
}
|
2013-07-14 18:26:53 +00:00
|
|
|
|
2013-07-15 22:30:32 +00:00
|
|
|
void InstanceSettings::on_buttonBox_rejected()
|
|
|
|
{
|
|
|
|
reject();
|
2013-07-14 18:26:53 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 22:30:32 +00:00
|
|
|
void InstanceSettings::applySettings()
|
2013-07-14 18:26:53 +00:00
|
|
|
{
|
2013-07-15 22:30:32 +00:00
|
|
|
// Console
|
|
|
|
bool console = ui->consoleSettingsBox->isChecked();
|
|
|
|
m_obj->set("OverrideConsole", console);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (console)
|
2013-07-15 22:30:32 +00:00
|
|
|
{
|
|
|
|
m_obj->set("ShowConsole", ui->showConsoleCheck->isChecked());
|
|
|
|
m_obj->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_obj->reset("ShowConsole");
|
|
|
|
m_obj->reset("AutoCloseConsole");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window Size
|
|
|
|
bool window = ui->windowSizeGroupBox->isChecked();
|
|
|
|
m_obj->set("OverrideWindow", window);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (window)
|
2013-07-15 22:30:32 +00:00
|
|
|
{
|
|
|
|
m_obj->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
|
|
|
|
m_obj->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
|
|
|
|
m_obj->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_obj->reset("LaunchMaximized");
|
|
|
|
m_obj->reset("MinecraftWinWidth");
|
|
|
|
m_obj->reset("MinecraftWinHeight");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto Login
|
2013-11-06 01:01:09 +00:00
|
|
|
bool login = ui->accountSettingsBox->isChecked();
|
2013-07-15 22:30:32 +00:00
|
|
|
m_obj->set("OverrideLogin", login);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (login)
|
2013-07-15 22:30:32 +00:00
|
|
|
{
|
2013-11-06 01:01:09 +00:00
|
|
|
m_obj->set("AutoLogin", ui->autoLoginCheckBox->isChecked());
|
2013-07-15 22:30:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_obj->reset("AutoLogin");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory
|
|
|
|
bool memory = ui->memoryGroupBox->isChecked();
|
|
|
|
m_obj->set("OverrideMemory", memory);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (memory)
|
2013-07-15 22:30:32 +00:00
|
|
|
{
|
|
|
|
m_obj->set("MinMemAlloc", ui->minMemSpinBox->value());
|
|
|
|
m_obj->set("MaxMemAlloc", ui->maxMemSpinBox->value());
|
2013-08-25 20:48:41 +00:00
|
|
|
m_obj->set("PermGen", ui->permGenSpinBox->value());
|
2013-07-15 22:30:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_obj->reset("MinMemAlloc");
|
|
|
|
m_obj->reset("MaxMemAlloc");
|
2013-08-25 20:48:41 +00:00
|
|
|
m_obj->reset("PermGen");
|
2013-07-15 22:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Java Settings
|
2013-11-04 01:53:05 +00:00
|
|
|
bool java = ui->javaSettingsGroupBox->isChecked();
|
2013-07-15 22:30:32 +00:00
|
|
|
m_obj->set("OverrideJava", java);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (java)
|
2013-07-15 22:30:32 +00:00
|
|
|
{
|
|
|
|
m_obj->set("JavaPath", ui->javaPathTextBox->text());
|
|
|
|
m_obj->set("JvmArgs", ui->jvmArgsTextBox->text());
|
2013-11-06 01:18:47 +00:00
|
|
|
|
|
|
|
NagUtils::checkJVMArgs(m_obj->get("JvmArgs").toString(), this->parentWidget());
|
2013-07-15 22:30:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_obj->reset("JavaPath");
|
|
|
|
m_obj->reset("JvmArgs");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Custom Commands
|
|
|
|
bool custcmd = ui->customCommandsGroupBox->isChecked();
|
|
|
|
m_obj->set("OverrideCommands", custcmd);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (custcmd)
|
2013-07-15 22:30:32 +00:00
|
|
|
{
|
|
|
|
m_obj->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text());
|
|
|
|
m_obj->set("PostExitCommand", ui->postExitCmdTextBox->text());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_obj->reset("PreLaunchCommand");
|
|
|
|
m_obj->reset("PostExitCommand");
|
|
|
|
}
|
|
|
|
}
|
2013-07-14 20:01:30 +00:00
|
|
|
|
2013-07-15 22:30:32 +00:00
|
|
|
void InstanceSettings::loadSettings()
|
|
|
|
{
|
|
|
|
// Console
|
2013-08-03 13:57:33 +00:00
|
|
|
ui->consoleSettingsBox->setChecked(m_obj->get("OverrideConsole").toBool());
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->showConsoleCheck->setChecked(m_obj->get("ShowConsole").toBool());
|
|
|
|
ui->autoCloseConsoleCheck->setChecked(m_obj->get("AutoCloseConsole").toBool());
|
|
|
|
|
|
|
|
// Window Size
|
2013-08-03 13:57:33 +00:00
|
|
|
ui->windowSizeGroupBox->setChecked(m_obj->get("OverrideWindow").toBool());
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->maximizedCheckBox->setChecked(m_obj->get("LaunchMaximized").toBool());
|
|
|
|
ui->windowWidthSpinBox->setValue(m_obj->get("MinecraftWinWidth").toInt());
|
|
|
|
ui->windowHeightSpinBox->setValue(m_obj->get("MinecraftWinHeight").toInt());
|
|
|
|
|
|
|
|
// Auto Login
|
2013-11-06 01:01:09 +00:00
|
|
|
ui->accountSettingsBox->setChecked(m_obj->get("OverrideLogin").toBool());
|
|
|
|
ui->autoLoginCheckBox->setChecked(m_obj->get("AutoLogin").toBool());
|
2013-07-15 22:30:32 +00:00
|
|
|
|
|
|
|
// Memory
|
2013-08-03 13:57:33 +00:00
|
|
|
ui->memoryGroupBox->setChecked(m_obj->get("OverrideMemory").toBool());
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->minMemSpinBox->setValue(m_obj->get("MinMemAlloc").toInt());
|
|
|
|
ui->maxMemSpinBox->setValue(m_obj->get("MaxMemAlloc").toInt());
|
2013-08-25 20:48:41 +00:00
|
|
|
ui->permGenSpinBox->setValue(m_obj->get("PermGen").toInt());
|
2013-07-15 22:30:32 +00:00
|
|
|
|
|
|
|
// Java Settings
|
2013-08-03 13:57:33 +00:00
|
|
|
ui->javaSettingsGroupBox->setChecked(m_obj->get("OverrideJava").toBool());
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->javaPathTextBox->setText(m_obj->get("JavaPath").toString());
|
|
|
|
ui->jvmArgsTextBox->setText(m_obj->get("JvmArgs").toString());
|
|
|
|
|
|
|
|
// Custom Commands
|
2013-08-03 13:57:33 +00:00
|
|
|
ui->customCommandsGroupBox->setChecked(m_obj->get("OverrideCommands").toBool());
|
2013-07-15 22:30:32 +00:00
|
|
|
ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString());
|
|
|
|
ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString());
|
2013-07-14 18:26:53 +00:00
|
|
|
}
|
2013-11-25 00:14:30 +00:00
|
|
|
|
|
|
|
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<JavaVersion>(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."));
|
|
|
|
}
|
|
|
|
}
|