24 #include "engineconfigpage.h" 25 #include "ui_engineconfigpage.h" 26 #include "gui/widgets/filepickwidget.h" 28 #include "plugins/engineplugin.h" 29 #include "serverapi/gameexefactory.h" 30 #include "serverapi/gamefile.h" 31 #include "filefilter.h" 33 #include <QFileDialog> 36 DClass<EngineConfigPage> :
public Ui::EngineConfigPage
45 this->wrapper = wrapper;
47 QStringList neighbours()
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())
140 knownPaths << picker->path();
146 QString EngineConfigPage::currentCustomParameters()
const 148 return d->cboCustomParameters->currentText().trimmed();
153 return d->plugin->icon();
156 void EngineConfigPage::makeFileBrowsers()
158 QSharedPointer<FilePickWidget::NeighbourStrategy> neighbours(
160 QList<GameFile> files = d->plugin->gameExe()->gameFiles().asQList();
161 foreach (
const GameFile &file, files)
164 widget->setFile(file);
165 widget->setNeighbourStrategy(neighbours);
166 this->connect(widget, SIGNAL(findFailed()), SLOT(showFindFailError()));
167 this->connect(widget, SIGNAL(pathChanged()), SLOT(autoFindNeighbouringPaths()));
168 this->connect(widget, SIGNAL(pathChanged()), SIGNAL(validationRequested()));
170 d->exePickArea->layout()->addWidget(widget);
171 d->filePickers << widget;
177 return d->plugin->data()->name;
189 filePicker->blockSignals(
true);
190 filePicker->load(*d->config);
191 filePicker->blockSignals(
false);
194 d->cboCustomParameters->clear();
195 d->cboCustomParameters->addItems(d->readStoredCustomParameters());
196 d->cboCustomParameters->setEditText(d->config->value(
"CustomParameters").toString());
197 if(d->plugin->data()->hasMasterClient())
198 d->leMasterserverAddress->setText(d->config->value(
"Masterserver").toString());
200 updateCustomParametersSaveState();
203 void EngineConfigPage::removeCurrentCustomParametersFromStorage()
205 QString currentParams = currentCustomParameters();
206 removeStoredCustomParametersFromConfig(currentParams);
207 removeStoredCustomParametersFromWidget(currentParams);
208 updateCustomParametersSaveState();
211 void EngineConfigPage::removeStoredCustomParametersFromConfig(
const QString ¶meters)
213 QStringList storedParameters = d->readStoredCustomParameters();
214 storedParameters.removeAll(parameters);
215 d->saveStoredCustomParameters(storedParameters);
218 void EngineConfigPage::removeStoredCustomParametersFromWidget(
const QString ¶meters)
220 int indexInWidget = d->cboCustomParameters->findText(parameters);
221 if (indexInWidget >= 0)
223 d->cboCustomParameters->removeItem(indexInWidget);
224 d->cboCustomParameters->setEditText(parameters);
228 void EngineConfigPage::saveCustomParameters()
230 if (!d->existsInStoredCustomParameters(currentCustomParameters()))
232 QStringList parameters = d->readStoredCustomParameters();
233 parameters << currentCustomParameters();
234 d->saveStoredCustomParameters(parameters);
235 d->cboCustomParameters->addItem(currentCustomParameters());
237 updateCustomParametersSaveState();
244 filePicker->save(*d->config);
246 d->config->setValue(
"CustomParameters", currentCustomParameters());
247 if (d->plugin->data()->hasMasterClient())
249 d->config->setValue(
"Masterserver", d->leMasterserverAddress->text());
253 void EngineConfigPage::showError(
const QString &error)
255 d->lblError->setText(error);
257 d->errorTimer.start();
260 void EngineConfigPage::showFindFailError()
262 showError(tr(
"Failed to automatically find file.\nYou may need to use the browse button."));
267 return tr(
"Game - %1").arg(name());
270 void EngineConfigPage::updateCustomParametersSaveState()
272 bool paramExists = d->existsInStoredCustomParameters(currentCustomParameters());
273 bool isEmpty = currentCustomParameters().isEmpty();
274 d->btnSaveCustomParameters->setVisible(!isEmpty && !paramExists);
275 d->btnDeleteCustomParameters->setVisible(!isEmpty && paramExists);
280 bool allFilesOk =
true;
283 bool thisFileOk = filePicker->validate();
284 allFilesOk = allFilesOk && thisFileOk;
286 return allFilesOk ? VALIDATION_OK : VALIDATION_ERROR;
void readSettings()
Reimplement this to read settings from config into widgets.
Validation
Result of validate()
virtual Validation validate()
Validate settings on this page.
QVariant value(const QString &key) const
Retrieves a variable directly; omits the IniVariable system.
void saveSettings()
Reimplement this to write settings to config from widgets.
QString title() const
Page title, by default returns the same string as name().
QIcon icon() const
Reimplement this to return a displayable icon for the ConfigPage.
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.
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.
QString name() const
Reimplement this to return a list-displayable name for this ConfigPage.
Base class for configuration pages.