Finalize the instance settings dialog, add setting reset mechanism

This commit is contained in:
Petr Mrázek 2013-07-16 00:30:32 +02:00
parent b5450042b5
commit e2ee6d6d25
11 changed files with 272 additions and 95 deletions

View File

@ -20,90 +20,161 @@
#include "instancesettings.h"
#include "ui_instancesettings.h"
InstanceSettings::InstanceSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::InstanceSettings)
InstanceSettings::InstanceSettings( SettingsObject * obj, QWidget *parent) :
m_obj(obj),
QDialog(parent),
ui(new Ui::InstanceSettings)
{
ui->setupUi(this);
ui->setupUi(this);
loadSettings();
}
InstanceSettings::~InstanceSettings()
{
delete ui;
delete ui;
}
void InstanceSettings::on_customCommandsGroupBox_toggled(bool state)
{
ui->labelCustomCmdsDescription->setEnabled(state);
ui->labelCustomCmdsDescription->setEnabled(state);
}
void InstanceSettings::applySettings(SettingsObject *s)
void InstanceSettings::on_buttonBox_accepted()
{
// Console
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
s->set("OverrideConsole", ui->consoleSettingsBox->isChecked());
// Window Size
s->set("LaunchCompatMode", ui->compatModeCheckBox->isChecked());
s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
s->set("OverrideWindow", ui->windowSizeGroupBox->isChecked());
// Auto Login
s->set("AutoLogin", ui->autoLoginChecBox->isChecked());
s->set("OverrideLogin", ui->accountSettingsGroupBox->isChecked());
// Memory
s->set("MinMemAlloc", ui->minMemSpinBox->value());
s->set("MaxMemAlloc", ui->maxMemSpinBox->value());
s->set("OverrideMemory", ui->memoryGroupBox->isChecked());
// Java Settings
s->set("JavaPath", ui->javaPathTextBox->text());
s->set("JvmArgs", ui->jvmArgsTextBox->text());
s->set("OverrideJava", ui->javaSettingsGroupBox->isChecked());
// Custom Commands
s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text());
s->set("PostExitCommand", ui->postExitCmdTextBox->text());
s->set("OverrideCommands", ui->customCommandsGroupBox->isChecked());
applySettings();
accept();
}
void InstanceSettings::loadSettings(SettingsObject *s)
void InstanceSettings::on_buttonBox_rejected()
{
// Console
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
ui->consoleSettingsBox->setChecked(s->get("OverrideConsole").toBool());
// Window Size
ui->compatModeCheckBox->setChecked(s->get("LaunchCompatMode").toBool());
ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool());
ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt());
ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt());
ui->windowSizeGroupBox->setChecked(s->get("OverrideWindow").toBool());
// Auto Login
ui->autoLoginChecBox->setChecked(s->get("AutoLogin").toBool());
ui->accountSettingsGroupBox->setChecked(s->get("OverrideLogin").toBool());
// Memory
ui->minMemSpinBox->setValue(s->get("MinMemAlloc").toInt());
ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt());
ui->memoryGroupBox->setChecked(s->get("OverrideMemory").toBool());
// Java Settings
ui->javaPathTextBox->setText(s->get("JavaPath").toString());
ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString());
ui->javaSettingsGroupBox->setChecked(s->get("OverrideJava").toBool());
// Custom Commands
ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString());
ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString());
ui->customCommandsGroupBox->setChecked(s->get("OverrideCommands").toBool());
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("LaunchCompatMode", ui->compatModeCheckBox->isChecked());
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("LaunchCompatMode");
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());
}
else
{
m_obj->reset("MinMemAlloc");
m_obj->reset("MaxMemAlloc");
}
// 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->showConsoleCheck->setChecked(m_obj->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(m_obj->get("AutoCloseConsole").toBool());
ui->consoleSettingsBox->setChecked(m_obj->get("OverrideConsole").toBool());
// Window Size
ui->compatModeCheckBox->setChecked(m_obj->get("LaunchCompatMode").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());
ui->windowSizeGroupBox->setChecked(m_obj->get("OverrideWindow").toBool());
// Auto Login
ui->autoLoginChecBox->setChecked(m_obj->get("AutoLogin").toBool());
ui->accountSettingsGroupBox->setChecked(m_obj->get("OverrideLogin").toBool());
// Memory
ui->minMemSpinBox->setValue(m_obj->get("MinMemAlloc").toInt());
ui->maxMemSpinBox->setValue(m_obj->get("MaxMemAlloc").toInt());
ui->memoryGroupBox->setChecked(m_obj->get("OverrideMemory").toBool());
// Java Settings
ui->javaPathTextBox->setText(m_obj->get("JavaPath").toString());
ui->jvmArgsTextBox->setText(m_obj->get("JvmArgs").toString());
ui->javaSettingsGroupBox->setChecked(m_obj->get("OverrideJava").toBool());
// Custom Commands
ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString());
ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString());
ui->customCommandsGroupBox->setChecked(m_obj->get("OverrideCommands").toBool());
}

View File

@ -10,22 +10,25 @@ class InstanceSettings;
class InstanceSettings : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit InstanceSettings(QWidget *parent = 0);
~InstanceSettings();
explicit InstanceSettings(SettingsObject *s, QWidget *parent = 0);
~InstanceSettings();
void updateCheckboxStuff();
void updateCheckboxStuff();
void applySettings(SettingsObject *s);
void loadSettings(SettingsObject* s);
void applySettings();
void loadSettings();
private slots:
void on_customCommandsGroupBox_toggled(bool arg1);
void on_customCommandsGroupBox_toggled(bool arg1);
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::InstanceSettings *ui;
Ui::InstanceSettings *ui;
SettingsObject * m_obj;
};
#endif // INSTANCESETTINGS_H

View File

@ -162,7 +162,7 @@
<item>
<widget class="QCheckBox" name="autoLoginChecBox">
<property name="enabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="text">
<string>Login automatically when an instance icon is double clicked?</string>
@ -319,6 +319,9 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="QLineEdit" name="preLaunchCmdTextBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPostExitCmd">
<property name="text">
@ -333,9 +336,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="preLaunchCmdTextBox"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="postExitCmdTextBox"/>
</item>
@ -362,6 +362,9 @@
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
@ -384,6 +387,30 @@
</property>
</widget>
</widget>
<tabstops>
<tabstop>settingsTabs</tabstop>
<tabstop>windowSizeGroupBox</tabstop>
<tabstop>compatModeCheckBox</tabstop>
<tabstop>maximizedCheckBox</tabstop>
<tabstop>windowWidthSpinBox</tabstop>
<tabstop>windowHeightSpinBox</tabstop>
<tabstop>consoleSettingsBox</tabstop>
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
<tabstop>accountSettingsGroupBox</tabstop>
<tabstop>autoLoginChecBox</tabstop>
<tabstop>memoryGroupBox</tabstop>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>
<tabstop>javaSettingsGroupBox</tabstop>
<tabstop>javaPathTextBox</tabstop>
<tabstop>pushButton</tabstop>
<tabstop>jvmArgsTextBox</tabstop>
<tabstop>customCommandsGroupBox</tabstop>
<tabstop>preLaunchCmdTextBox</tabstop>
<tabstop>postExitCmdTextBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -560,19 +560,15 @@ void MainWindow::on_actionChangeInstLWJGLVersion_triggered()
void MainWindow::on_actionInstanceSettings_triggered()
{
if (view->selectionModel()->selectedIndexes().count() < 1)
return;
if (view->selectionModel()->selectedIndexes().count() < 1)
return;
Instance *inst = selectedInstance();
SettingsObject *s;
s = &inst->settings();
InstanceSettings *settings = new InstanceSettings (this);
settings->setWindowTitle(QString("Instance settings"));
settings->loadSettings(s);
if (settings->exec()) {
settings->applySettings(s);
}
delete settings;
Instance *inst = selectedInstance();
SettingsObject *s;
s = &inst->settings();
InstanceSettings settings(s, this);
settings.setWindowTitle(QString("Instance settings"));
settings.exec();
}
void MainWindow::instanceChanged(QModelIndex idx) {

View File

@ -62,6 +62,18 @@ Instance::Instance(const QString &rootDir, QObject *parent) :
// Auto login
settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin")));
// Console
settings().registerSetting(new OverrideSetting("ShowConsole", globalSettings->getSetting("ShowConsole")));
settings().registerSetting(new OverrideSetting("AutoCloseConsole", globalSettings->getSetting("AutoCloseConsole")));
// Overrides
settings().registerSetting(new Setting("OverrideConsole", false));
settings().registerSetting(new Setting("OverrideWindow", false));
settings().registerSetting(new Setting("OverrideLogin", false));
settings().registerSetting(new Setting("OverrideMemory", false));
settings().registerSetting(new Setting("OverrideJava", false));
settings().registerSetting(new Setting("OverrideCommands", false));
}
QString Instance::id() const

View File

@ -47,6 +47,7 @@ public:
protected slots:
virtual void changeSetting(const Setting &setting, QVariant value);
virtual void resetSetting ( const Setting& setting );
protected:
virtual QVariant retrieveValue(const Setting &setting);

View File

@ -84,6 +84,12 @@ signals:
*/
void settingChanged(const Setting &setting, QVariant value);
/*!
* \brief Signal emitted when this Setting object's value resets to default.
* \param setting A reference to the Setting that changed.
*/
void settingReset(const Setting &setting);
public slots:
/*!
* \brief Changes the setting's value.
@ -93,6 +99,13 @@ public slots:
*/
virtual void set(QVariant value);
/*!
* \brief Reset the setting to default
* This is done by emitting the settingReset() signal which will then be
* handled by the SettingsObject object and cause the setting to change.
* \param value The new value.
*/
virtual void reset();
protected:
QString m_id;
QVariant m_defVal;

View File

@ -100,6 +100,11 @@ public:
*/
virtual bool set(const QString &id, QVariant value);
/*!
* \brief Reverts the setting with the given ID to default.
* \param id The ID of the setting to reset.
*/
virtual void reset(const QString &id) const;
/*!
* \brief Gets a QList with pointers to all of the registered settings.
@ -125,6 +130,14 @@ signals:
*/
void settingChanged(const Setting &setting, QVariant value);
/*!
* \brief Signal emitted when one of this SettingsObject object's settings resets.
* This is usually just connected directly to each Setting object's
* settingReset() signals.
* \param setting A reference to the Setting object that changed.
*/
void settingReset(const Setting &setting);
protected slots:
/*!
* \brief Changes a setting.
@ -136,6 +149,15 @@ protected slots:
*/
virtual void changeSetting(const Setting &setting, QVariant value) = 0;
/*!
* \brief Resets a setting.
* This slot is usually connected to each Setting object's
* settingReset() signal. The signal is emitted, causing this slot
* to update the setting's value in the config file.
* \param setting A reference to the Setting object that changed.
*/
virtual void resetSetting(const Setting &setting) = 0;
protected:
/*!
* \brief Connects the necessary signals to the given Setting.

View File

@ -40,6 +40,15 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
}
}
void INISettingsObject::resetSetting ( const Setting& setting )
{
if (contains(setting.id()))
{
m_ini.remove(setting.configKey());
m_ini.saveFile(m_filePath);
}
}
QVariant INISettingsObject::retrieveValue(const Setting &setting)
{
if (contains(setting.id()))

View File

@ -47,3 +47,8 @@ void Setting::set(QVariant value)
{
emit settingChanged(*this, value);
}
void Setting::reset()
{
emit settingReset(*this);
}

View File

@ -98,6 +98,14 @@ bool SettingsObject::set(const QString &id, QVariant value)
}
}
void SettingsObject::reset(const QString &id) const
{
Setting *setting = getSetting(id);
if(setting)
setting->reset();
}
QList<Setting *> SettingsObject::getSettings()
{
return m_settings.values();
@ -115,6 +123,11 @@ void SettingsObject::connectSignals(const Setting &setting)
SLOT(changeSetting(const Setting &, QVariant)));
connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)),
SIGNAL(settingChanged(const Setting &, QVariant)));
connect(&setting, SIGNAL(settingReset(Setting)),
SLOT(resetSetting(const Setting &)));
connect(&setting, SIGNAL(settingReset(Setting)),
SIGNAL(settingReset(const Setting &)));
}
void SettingsObject::disconnectSignals(const Setting &setting)
@ -123,4 +136,9 @@ void SettingsObject::disconnectSignals(const Setting &setting)
this, SLOT(changeSetting(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)),
this, SIGNAL(settingChanged(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)),
this, SLOT(resetSetting(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)),
this, SIGNAL(settingReset(const Setting &, QVariant)));
}