summaryrefslogtreecommitdiffstats
path: root/gui/instancesettings.cpp
blob: dfb04f3d1b238682c6bd6d94f7f8030c70a75d0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* 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.
 */

#include "instancesettings.h"
#include "ui_instancesettings.h"

InstanceSettings::InstanceSettings( SettingsObject * obj, QWidget *parent) :
	m_obj(obj),
	QDialog(parent),
	ui(new Ui::InstanceSettings)
{
	ui->setupUi(this);
	loadSettings();
}

InstanceSettings::~InstanceSettings()
{
	delete ui;
}

void InstanceSettings::showEvent ( QShowEvent* ev )
{
	QDialog::showEvent(ev);
	adjustSize();
}

void InstanceSettings::on_customCommandsGroupBox_toggled(bool state)
{
	ui->labelCustomCmdsDescription->setEnabled(state);
}

void InstanceSettings::on_buttonBox_accepted()
{
	applySettings();
	accept();
}

void InstanceSettings::on_buttonBox_rejected()
{
	reject();
}


void InstanceSettings::applySettings()
{
	// Console
	bool console = ui->consoleSettingsBox->isChecked();
	m_obj->set("OverrideConsole", console);
	if(console)
	{
		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);
	if(window)
	{
		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
	bool login = ui->accountSettingsGroupBox->isChecked();
	m_obj->set("OverrideLogin", login);
	if(login)
	{
		m_obj->set("AutoLogin", ui->autoLoginChecBox->isChecked());
	}
	else
	{
		m_obj->reset("AutoLogin");
	}
	

	// Memory
	bool memory = ui->memoryGroupBox->isChecked();
	m_obj->set("OverrideMemory", memory);
	if(memory)
	{
		m_obj->set("MinMemAlloc", ui->minMemSpinBox->value());
		m_obj->set("MaxMemAlloc", ui->maxMemSpinBox->value());
		m_obj->set("PermGen", ui->permGenSpinBox->value());
	}
	else
	{
		m_obj->reset("MinMemAlloc");
		m_obj->reset("MaxMemAlloc");
		m_obj->reset("PermGen");
	}
	

	// Java Settings
	bool java  = ui->javaSettingsGroupBox->isChecked();
	m_obj->set("OverrideJava", java);
	if(java)
	{
		m_obj->set("JavaPath", ui->javaPathTextBox->text());
		m_obj->set("JvmArgs", ui->jvmArgsTextBox->text());
	}
	else
	{
		m_obj->reset("JavaPath");
		m_obj->reset("JvmArgs");
	}
	

	// Custom Commands
	bool custcmd = ui->customCommandsGroupBox->isChecked();
	m_obj->set("OverrideCommands", custcmd);
	if(custcmd)
	{
		m_obj->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text());
		m_obj->set("PostExitCommand", ui->postExitCmdTextBox->text());
	}
	else
	{
		m_obj->reset("PreLaunchCommand");
		m_obj->reset("PostExitCommand");
	}
	
}

void InstanceSettings::loadSettings()
{
	// Console
	ui->consoleSettingsBox->setChecked(m_obj->get("OverrideConsole").toBool());
	ui->showConsoleCheck->setChecked(m_obj->get("ShowConsole").toBool());
	ui->autoCloseConsoleCheck->setChecked(m_obj->get("AutoCloseConsole").toBool());

	// Window Size
	ui->windowSizeGroupBox->setChecked(m_obj->get("OverrideWindow").toBool());
	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
	ui->accountSettingsGroupBox->setChecked(m_obj->get("OverrideLogin").toBool());
	ui->autoLoginChecBox->setChecked(m_obj->get("AutoLogin").toBool());

	// Memory
	ui->memoryGroupBox->setChecked(m_obj->get("OverrideMemory").toBool());
	ui->minMemSpinBox->setValue(m_obj->get("MinMemAlloc").toInt());
	ui->maxMemSpinBox->setValue(m_obj->get("MaxMemAlloc").toInt());
	ui->permGenSpinBox->setValue(m_obj->get("PermGen").toInt());

	// Java Settings
	ui->javaSettingsGroupBox->setChecked(m_obj->get("OverrideJava").toBool());
	ui->javaPathTextBox->setText(m_obj->get("JavaPath").toString());
	ui->jvmArgsTextBox->setText(m_obj->get("JvmArgs").toString());

	// Custom Commands
	ui->customCommandsGroupBox->setChecked(m_obj->get("OverrideCommands").toBool());
	ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString());
	ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString());
}