24 #include "engineconfigpage.h" 25 #include "filefilter.h" 26 #include "gui/widgets/filepickwidget.h" 28 #include "plugins/engineplugin.h" 29 #include "serverapi/gameexefactory.h" 30 #include "serverapi/gamefile.h" 31 #include "ui_engineconfigpage.h" 33 #include <QFileDialog> 36 DClass<EngineConfigPage> :
public Ui::EngineConfigPage
45 this->wrapper = wrapper;
47 QStringList neighbours()
override 49 return (*wrapper)->parent->collectKnownGameFilePaths();
58 QList<FilePickWidget *> filePickers;
61 QStringList readStoredCustomParameters()
const 63 return config->
value(
"StoredCustomParameters").toStringList();
66 void saveStoredCustomParameters(
const QStringList ¶ms)
68 config->
setValue(
"StoredCustomParameters", params);
71 bool existsInStoredCustomParameters(
const QString &text)
const 73 return readStoredCustomParameters().contains(text);
89 d->errorTimer.setInterval(5000);
90 d->errorTimer.setSingleShot(
true);
91 this->connect(&d->errorTimer, SIGNAL(timeout()), d->lblError, SLOT(hide()));
94 d->cboCustomParameters->setMinimumContentsLength(25);
95 d->cboCustomParameters->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
99 if (!plugin->data()->hasMasterClient())
100 d->masterAddressBox->hide();
103 EngineConfigPage::~EngineConfigPage()
109 layout()->removeItem(d->verticalSpacer);
110 layout()->addWidget(widget);
111 layout()->addItem(d->verticalSpacer);
114 void EngineConfigPage::autoFindNeighbouringPaths()
117 if (QFileInfo(picker->path()).isFile())
119 QStringList knownPaths = collectKnownGameFilePaths();
122 if (picker->isEmpty())
124 picker->blockSignals(
true);
126 picker->blockSignals(
false);
130 emit validationRequested();
133 QStringList EngineConfigPage::collectKnownGameFilePaths()
const 135 QStringList knownPaths;
138 if (!picker->isEmpty())
139 knownPaths << picker->path();
144 QString EngineConfigPage::currentCustomParameters()
const 146 return d->cboCustomParameters->currentText().trimmed();
151 return d->plugin->icon();
154 void EngineConfigPage::makeFileBrowsers()
156 QSharedPointer<FilePickWidget::NeighbourStrategy> neighbours(
158 QList<GameFile> files = d->plugin->gameExe()->gameFiles().asQList();
162 widget->setFile(file);
163 widget->setNeighbourStrategy(neighbours);
164 this->connect(widget, SIGNAL(findFailed()), SLOT(showFindFailError()));
165 this->connect(widget, SIGNAL(pathChanged()), SLOT(autoFindNeighbouringPaths()));
166 this->connect(widget, SIGNAL(pathChanged()), SIGNAL(validationRequested()));
168 d->exePickArea->layout()->addWidget(widget);
169 d->filePickers << widget;
175 return d->plugin->data()->name;
187 filePicker->blockSignals(
true);
188 filePicker->load(*d->config);
189 filePicker->blockSignals(
false);
192 d->cboCustomParameters->clear();
193 d->cboCustomParameters->addItems(d->readStoredCustomParameters());
194 d->cboCustomParameters->setEditText(d->config->value(
"CustomParameters").toString());
195 if (d->plugin->data()->hasMasterClient())
196 d->leMasterserverAddress->setText(d->config->value(
"Masterserver").toString());
198 updateCustomParametersSaveState();
201 void EngineConfigPage::removeCurrentCustomParametersFromStorage()
203 QString currentParams = currentCustomParameters();
204 removeStoredCustomParametersFromConfig(currentParams);
205 removeStoredCustomParametersFromWidget(currentParams);
206 updateCustomParametersSaveState();
209 void EngineConfigPage::removeStoredCustomParametersFromConfig(
const QString ¶meters)
211 QStringList storedParameters = d->readStoredCustomParameters();
212 storedParameters.removeAll(parameters);
213 d->saveStoredCustomParameters(storedParameters);
216 void EngineConfigPage::removeStoredCustomParametersFromWidget(
const QString ¶meters)
218 int indexInWidget = d->cboCustomParameters->findText(parameters);
219 if (indexInWidget >= 0)
221 d->cboCustomParameters->removeItem(indexInWidget);
222 d->cboCustomParameters->setEditText(parameters);
226 void EngineConfigPage::saveCustomParameters()
228 if (!d->existsInStoredCustomParameters(currentCustomParameters()))
230 QStringList parameters = d->readStoredCustomParameters();
231 parameters << currentCustomParameters();
232 d->saveStoredCustomParameters(parameters);
233 d->cboCustomParameters->addItem(currentCustomParameters());
235 updateCustomParametersSaveState();
242 filePicker->save(*d->config);
244 d->config->setValue(
"CustomParameters", currentCustomParameters());
245 if (d->plugin->data()->hasMasterClient())
246 d->config->setValue(
"Masterserver", d->leMasterserverAddress->text());
249 void EngineConfigPage::showError(
const QString &error)
251 d->lblError->setText(error);
253 d->errorTimer.start();
256 void EngineConfigPage::showFindFailError()
258 showError(tr(
"Failed to automatically find file.\nYou may need to use the browse button."));
263 return tr(
"Game - %1").arg(name());
266 void EngineConfigPage::updateCustomParametersSaveState()
268 bool paramExists = d->existsInStoredCustomParameters(currentCustomParameters());
269 bool isEmpty = currentCustomParameters().isEmpty();
270 d->btnSaveCustomParameters->setVisible(!isEmpty && !paramExists);
271 d->btnDeleteCustomParameters->setVisible(!isEmpty && paramExists);
276 bool allFilesOk =
true;
279 bool thisFileOk = filePicker->validate();
280 allFilesOk = allFilesOk && thisFileOk;
282 return allFilesOk ? VALIDATION_OK : VALIDATION_ERROR;
Validation validate() override
Validate settings on this page.
Validation
Result of validate()
QString name() const override
Reimplement this to return a list-displayable name for this ConfigPage.
void readSettings() override
Reimplement this to read settings from config into widgets.
QIcon icon() const override
Reimplement this to return a displayable icon for the ConfigPage.
QVariant value(const QString &key) const
Retrieves a variable directly; omits the IniVariable system.
QString title() const override
Page title, by default returns the same string as name().
const EnginePlugin * plugin() const
Parent plugin handled by this page.
void setValue(const QString &key, const QVariant &value)
Sets a variable directly. Omits the IniVariable system.
void saveSettings() override
Reimplement this to write settings to config from widgets.
INI section representation.
Game file definition allows to browse this file in configuration box.
void addWidget(QWidget *widget)
Add a new, custom widget below the standard ones.
Base for configuration pages for plugins; provides some default behavior.
Base class for configuration pages.