24 #include "engineconfigurationbasebox.h"
25 #include "ui_engineconfigurationbasebox.h"
27 #include "plugins/engineplugin.h"
29 #include <QFileDialog>
31 DClass<EngineConfigurationBaseBox> :
public Ui::EngineConfigurationBaseBox
38 QStringList readStoredCustomParameters()
const
40 return config->
value(
"StoredCustomParameters").toStringList();
43 void saveStoredCustomParameters(
const QStringList ¶ms)
45 config->
setValue(
"StoredCustomParameters", params);
48 bool existsInStoredCustomParameters(
const QString &text)
const
50 return readStoredCustomParameters().contains(text);
64 d->cboCustomParameters->setMinimumContentsLength(25);
65 d->cboCustomParameters->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
67 if(plugin->data()->clientOnly)
70 if(!plugin->data()->hasMasterServer)
71 d->masterAddressBox->hide();
73 this->connect(d->btnBrowseClientBinary, SIGNAL( clicked() ), SLOT( browseForClientBinary() ));
74 this->connect(d->btnBrowseServerBinary, SIGNAL( clicked() ), SLOT( browseForServerBinary() ));
77 EngineConfigurationBaseBox::~EngineConfigurationBaseBox()
83 layout()->removeItem(d->verticalSpacer);
84 layout()->addWidget(widget);
85 layout()->addItem(d->verticalSpacer);
91 #if defined(Q_OS_WIN32)
92 filter = tr(
"Binary files (*.exe);;Any files (*)");
95 filter = tr(
"Any files(*)");
97 QString filepath = QFileDialog::getOpenFileName(
this,
98 tr(
"Doomseeker - choose %1 %2").arg(d->plugin->data()->name).arg(type),
100 if (!filepath.isEmpty())
101 input->setText(filepath);
104 void EngineConfigurationBaseBox::browseForClientBinary()
110 void EngineConfigurationBaseBox::browseForServerBinary()
115 QString EngineConfigurationBaseBox::currentCustomParameters()
const
117 return d->cboCustomParameters->currentText().trimmed();
122 return d->plugin->icon();
125 void EngineConfigurationBaseBox::makeClientOnly()
127 d->clientOnly =
true;
129 d->lblClientBinary->setText(tr(
"Path to executable:"));
130 d->serverBinaryBox->hide();
135 return d->plugin->data()->name;
145 d->leClientBinaryPath->setText(d->config->value(
"BinaryPath").toString());
146 d->cboCustomParameters->clear();
147 d->cboCustomParameters->addItems(d->readStoredCustomParameters());
148 d->cboCustomParameters->setEditText(d->config->value(
"CustomParameters").toString());
149 if(d->plugin->data()->hasMasterServer)
150 d->leMasterserverAddress->setText(d->config->value(
"Masterserver").toString());
151 d->leServerBinaryPath->setText(d->config->value(
"ServerBinaryPath").toString());
153 updateCustomParametersSaveState();
156 void EngineConfigurationBaseBox::removeCurrentCustomParametersFromStorage()
158 QString currentParams = currentCustomParameters();
159 removeStoredCustomParametersFromConfig(currentParams);
160 removeStoredCustomParametersFromWidget(currentParams);
161 updateCustomParametersSaveState();
164 void EngineConfigurationBaseBox::removeStoredCustomParametersFromConfig(
const QString ¶meters)
166 QStringList storedParameters = d->readStoredCustomParameters();
167 storedParameters.removeAll(parameters);
168 d->saveStoredCustomParameters(storedParameters);
171 void EngineConfigurationBaseBox::removeStoredCustomParametersFromWidget(
const QString ¶meters)
173 int indexInWidget = d->cboCustomParameters->findText(parameters);
174 if (indexInWidget >= 0)
176 d->cboCustomParameters->removeItem(indexInWidget);
177 d->cboCustomParameters->setEditText(parameters);
181 void EngineConfigurationBaseBox::saveCustomParameters()
183 if (!d->existsInStoredCustomParameters(currentCustomParameters()))
185 QStringList parameters = d->readStoredCustomParameters();
186 parameters << currentCustomParameters();
187 d->saveStoredCustomParameters(parameters);
188 d->cboCustomParameters->addItem(currentCustomParameters());
190 updateCustomParametersSaveState();
197 executable = d->leClientBinaryPath->text();
198 d->config->setValue(
"BinaryPath", executable);
201 executable = d->leServerBinaryPath->text();
203 d->config->setValue(
"ServerBinaryPath", executable);
204 d->config->setValue(
"CustomParameters", currentCustomParameters());
205 if (d->plugin->data()->hasMasterServer)
207 d->config->setValue(
"Masterserver", d->leMasterserverAddress->text());
213 return tr(
"Game - %1").arg(
name());
216 void EngineConfigurationBaseBox::updateCustomParametersSaveState()
218 bool paramExists = d->existsInStoredCustomParameters(currentCustomParameters());
219 bool isEmpty = currentCustomParameters().isEmpty();
220 d->btnSaveCustomParameters->setVisible(!isEmpty && !paramExists);
221 d->btnDeleteCustomParameters->setVisible(!isEmpty && paramExists);
QIcon icon() const
Reimplement this to return a displayable icon for the ConfigurationBaseBox.
const EnginePlugin * plugin() const
Parent plugin handled by this page.
void browseForBinary(QLineEdit *input, const QString &type)
Open file browse dialog and update "input" when successful.
QVariant value(const QString &key) const
Retrieves a variable directly; omits the IniVariable system.
void readSettings()
Reimplement this to read settings from config into widgets.
void saveSettings()
Reimplement this to write settings to config from widgets.
QString title() const
Page title, by default returns the same string as name().
QString name() const
Reimplement this to return a list-displayable name for this ConfigurationBaseBox. ...
void addWidget(QWidget *widget)
Add a new, custom widget below the standard ones.
Base for configuration pages for plugins; provides some default behavior.
void setValue(const QString &key, const QVariant &value)
Sets a variable directly. Omits the IniVariable system.
INI section representation.
Base class for configuration pages.