23 #include "createserverdialog.h"
24 #include "ui_createserverdialog.h"
26 #include "configuration/doomseekerconfig.h"
27 #include "copytextdlg.h"
28 #include "gui/widgets/createserverdialogpage.h"
29 #include "datapaths.h"
31 #include "ini/settingsproviderqt.h"
32 #include "plugins/engineplugin.h"
33 #include "serverapi/gamecreateparams.h"
34 #include "serverapi/gamehost.h"
35 #include "serverapi/message.h"
36 #include "apprunner.h"
37 #include "commandline.h"
40 #include <QFileDialog>
41 #include <QMessageBox>
44 DClass<CreateServerDialog> :
public Ui::CreateServerDialog
48 QList<CreateServerDialogPage*> currentCustomPages;
60 setAttribute(Qt::WA_DeleteOnClose);
62 d->remoteGameSetup =
false;
63 d->currentEngine = NULL;
71 QTimer::singleShot(1,
this, SLOT(firstLoadConfigTimer()) );
74 CreateServerDialog::~CreateServerDialog()
78 void CreateServerDialog::btnCommandLineClicked()
82 if(commandLineArguments(executable, args))
88 CopyTextDlg ctd(executable +
" " + args.join(
" "),
"Host server command line:",
this);
93 void CreateServerDialog::btnLoadClicked()
95 QString dialogDir = gConfig.doomseeker.previousCreateServerConfigDir;
96 QString strFile = QFileDialog::getOpenFileName(
this, tr(
"Doomseeker - load server config"), dialogDir, tr(
"Config files (*.ini)"));
98 if (!strFile.isEmpty())
100 QFileInfo fi(strFile);
101 gConfig.doomseeker.previousCreateServerConfigDir = fi.absolutePath();
103 loadConfig(strFile,
false);
107 void CreateServerDialog::btnPlayOfflineClicked()
112 void CreateServerDialog::btnSaveClicked()
114 QString dialogDir = gConfig.doomseeker.previousCreateServerConfigDir;
115 QString strFile = QFileDialog::getSaveFileName(
this, tr(
"Doomseeker - save server config"), dialogDir, tr(
"Config files (*.ini)"));
116 if (!strFile.isEmpty())
118 QFileInfo fi(strFile);
119 gConfig.doomseeker.previousCreateServerConfigDir = fi.absolutePath();
121 if (fi.suffix().isEmpty())
126 if (!saveConfig(strFile))
128 QMessageBox::critical(NULL, tr(
"Doomseeker - save server config"), tr(
"Unable to save server configuration!"));
134 void CreateServerDialog::btnStartServerClicked()
136 if(!d->remoteGameSetup)
142 bool CreateServerDialog::commandLineArguments(QString &executable, QStringList &args)
144 const QString errorCapt = tr(
"Doomseeker - create game");
145 if (d->currentEngine == NULL)
147 QMessageBox::critical(NULL, errorCapt, tr(
"No engine selected"));
152 if (createHostInfo(gameParams,
false))
157 GameHost* gameRunner = d->currentEngine->gameHost();
164 QMessageBox::critical(NULL, tr(
"Doomseeker - error"), message.
contents());
169 executable = cli.
executable.absoluteFilePath();
177 bool CreateServerDialog::createHostInfo(
GameCreateParams& params,
bool offline)
179 d->generalSetupPanel->fillInParams(params, offline);
180 d->dmflagsPanel->fillInParams(params);
182 if (!fillInParamsFromPluginPages(params))
187 d->customParamsPanel->fillInParams(params);
188 d->miscPanel->fillInParams(params);
189 d->rulesPanel->fillInParams(params);
191 createHostInfoDemoRecord(params, offline);
195 void CreateServerDialog::createHostInfoDemoRecord(
GameCreateParams& params,
bool offline)
197 if (gConfig.doomseeker.bRecordDemo && offline)
199 params.setDemoPath(GameDemo::mkDemoFullPath(GameDemo::Managed, *d->currentEngine));
200 params.setDemoRecord(GameDemo::Managed);
204 GameMode CreateServerDialog::currentGameMode()
const
206 return d->generalSetupPanel->currentGameMode();
209 void CreateServerDialog::firstLoadConfigTimer()
211 initEngineSpecific(d->generalSetupPanel->currentPlugin());
212 QString tmpServerCfgPath = gDefaultDataPaths->programsDataDirectoryPath() + TEMP_SERVER_CONFIG_FILENAME;
214 QFileInfo fi(tmpServerCfgPath);
217 loadConfig(tmpServerCfgPath,
true);
221 void CreateServerDialog::initDMFlagsTabs()
223 bool flagsAdded = d->dmflagsPanel->initDMFlagsTabs(d->currentEngine);
224 int tabIndex = d->tabWidget->indexOf(d->tabFlags);
225 if (flagsAdded && tabIndex < 0)
227 d->tabWidget->insertTab(d->tabWidget->indexOf(d->tabCustomParameters), d->tabFlags, tr(
"Flags"));
229 else if (!flagsAdded && tabIndex >= 0)
231 d->tabWidget->removeTab(tabIndex);
235 void CreateServerDialog::initEngineSpecific(
EnginePlugin* engine)
237 if (engine == d->currentEngine || engine == NULL)
242 d->currentEngine = engine;
244 d->generalSetupPanel->setupForEngine(engine);
246 initEngineSpecificPages(engine);
247 initInfoAndPassword();
251 void CreateServerDialog::initEngineSpecificPages(
EnginePlugin* engine)
258 d->currentCustomPages.clear();
264 int idxInsertAt = d->tabWidget->indexOf(d->tabCustomParameters);
265 d->tabWidget->insertTab(idxInsertAt, page, page->name());
269 void CreateServerDialog::initGamemodeSpecific(
const GameMode &gameMode)
271 d->rulesPanel->setupForEngine(d->currentEngine, gameMode);
274 void CreateServerDialog::initInfoAndPassword()
276 d->miscPanel->setupForEngine(d->currentEngine);
277 d->tabWidget->setTabEnabled(d->tabWidget->indexOf(d->tabMisc), d->miscPanel->isAnythingAvailable());
280 void CreateServerDialog::initRules()
282 d->rulesPanel->setupForEngine(d->currentEngine, currentGameMode());
285 bool CreateServerDialog::loadConfig(
const QString& filename,
bool loadingPrevious)
287 QSettings settingsFile(filename, QSettings::IniFormat);
289 Ini ini(&settingsProvider);
291 d->generalSetupPanel->loadConfig(ini, loadingPrevious);
292 d->rulesPanel->loadConfig(ini);
293 d->miscPanel->loadConfig(ini);
294 d->dmflagsPanel->loadConfig(ini);
302 d->customParamsPanel->loadConfig(ini);
306 void CreateServerDialog::makeRemoteGameSetupDialog(
const EnginePlugin *plugin)
308 d->remoteGameSetup =
true;
310 d->btnCommandLine->hide();
311 d->btnPlayOffline->setDisabled(
true);
313 d->generalSetupPanel->setupForRemoteGame();
314 d->rulesPanel->setupForRemoteGame();
317 bool CreateServerDialog::fillInParamsFromPluginPages(
GameCreateParams ¶ms)
328 d->tabWidget->setCurrentIndex(d->tabWidget->indexOf(page));
335 void CreateServerDialog::runGame(
bool offline)
337 const QString errorCapt = tr(
"Doomseeker - create game");
338 if (d->currentEngine == NULL)
340 QMessageBox::critical(NULL, errorCapt, tr(
"No engine selected"));
345 if (createHostInfo(gameParams, offline))
349 GameHost* gameRunner = d->currentEngine->gameHost();
356 QMessageBox::critical(NULL, tr(
"Doomseeker - error"), message.
contents());
360 QString tmpServerConfigPath = gDefaultDataPaths->programsDataDirectoryPath() + TEMP_SERVER_CONFIG_FILENAME;
361 saveConfig(tmpServerConfigPath);
366 bool CreateServerDialog::saveConfig(
const QString& filename)
368 QSettings settingsFile(filename, QSettings::IniFormat);
370 Ini ini(&settingsProvider);
373 d->generalSetupPanel->saveConfig(ini);
374 d->rulesPanel->saveConfig(ini);
375 d->miscPanel->saveConfig(ini);
376 d->dmflagsPanel->saveConfig(ini);
384 d->customParamsPanel->saveConfig(ini);
386 if (settingsFile.isWritable())
394 void CreateServerDialog::setIwadByName(
const QString &iwad)
396 d->generalSetupPanel->setIwadByName(iwad);
virtual bool saveConfig(Ini &ini)=0
Saves variables defined by this page to a config.
Game parametrization data used when creating new games.
Structure holding parameters for application launch.
Message object used to pass messages throughout the Doomseeker's system.
QStringList args
launch parameters
bool isError() const
True if type() is equal to or greater than CUSTOM_ERROR.
virtual QList< CreateServerDialogPage * > createServerDialogPages(CreateServerDialog *pDialog)
Creates a list of custom Create Game dialog pages.
Dialog window allowing user to host a game.
Game mode representation.
virtual QStringList generateGameRunParameters()=0
Generates game run parameters basing on the page's contents.
Base class to be used by plugins to define custom pages in Create Server dialog.
Message createHostCommandLine(const GameCreateParams ¶ms, CommandLineInfo &cmdLine)
INI section representation.
static void escapeExecutable(QString &arg)
Escapes the executable path and handles OS X bundles.
Creates game servers, offline games or demo playbacks.
QString contents() const
Customized displayable contents of this Message.
static void escapeArgs(QStringList &args)
Escapes all characters in all strings on the list.
Message host(const GameCreateParams ¶ms)
QFileInfo executable
path to the executable
virtual bool validate()
Validates contents of the page before the saveConfig().
virtual bool loadConfig(Ini &ini)=0
Loads variables that are stored in the config into the GUI.