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;
67 d->generalSetupPanel->setCreateServerDialog(
this);
68 d->rulesPanel->setCreateServerDialog(
this);
74 QTimer::singleShot(1,
this, SLOT(firstLoadConfigTimer()) );
77 CreateServerDialog::~CreateServerDialog()
81 void CreateServerDialog::btnCommandLineClicked()
85 if(commandLineArguments(executable, args))
91 CopyTextDlg ctd(executable +
" " + args.join(
" "),
"Host server command line:",
this);
96 void CreateServerDialog::btnLoadClicked()
98 QString dialogDir = gConfig.doomseeker.previousCreateServerConfigDir;
99 QString strFile = QFileDialog::getOpenFileName(
this, tr(
"Doomseeker - load server config"), dialogDir, tr(
"Config files (*.ini)"));
101 if (!strFile.isEmpty())
103 QFileInfo fi(strFile);
104 gConfig.doomseeker.previousCreateServerConfigDir = fi.absolutePath();
106 loadConfig(strFile,
false);
110 void CreateServerDialog::btnPlayOfflineClicked()
115 void CreateServerDialog::btnSaveClicked()
117 QString dialogDir = gConfig.doomseeker.previousCreateServerConfigDir;
118 QString strFile = QFileDialog::getSaveFileName(
this, tr(
"Doomseeker - save server config"), dialogDir, tr(
"Config files (*.ini)"));
119 if (!strFile.isEmpty())
121 QFileInfo fi(strFile);
122 gConfig.doomseeker.previousCreateServerConfigDir = fi.absolutePath();
124 if (fi.suffix().isEmpty())
129 if (!saveConfig(strFile))
131 QMessageBox::critical(NULL, tr(
"Doomseeker - save server config"), tr(
"Unable to save server configuration!"));
137 void CreateServerDialog::btnStartServerClicked()
139 if(!d->remoteGameSetup)
145 bool CreateServerDialog::commandLineArguments(QString &executable, QStringList &args)
147 const QString errorCapt = tr(
"Doomseeker - create game");
148 if (d->currentEngine == NULL)
150 QMessageBox::critical(NULL, errorCapt, tr(
"No engine selected"));
155 if (createHostInfo(gameParams,
false))
160 GameHost* gameRunner = d->currentEngine->gameHost();
167 QMessageBox::critical(NULL, tr(
"Doomseeker - error"), message.
contents());
172 executable = cli.
executable.absoluteFilePath();
180 bool CreateServerDialog::createHostInfo(
GameCreateParams& params,
bool offline)
182 if (d->remoteGameSetup)
184 params.setHostMode(GameCreateParams::Remote);
188 params.setHostMode(offline ? GameCreateParams::Offline : GameCreateParams::Host);
190 d->generalSetupPanel->fillInParams(params);
191 d->dmflagsPanel->fillInParams(params);
193 if (!fillInParamsFromPluginPages(params))
198 d->customParamsPanel->fillInParams(params);
199 d->miscPanel->fillInParams(params);
200 d->rulesPanel->fillInParams(params);
202 createHostInfoDemoRecord(params, offline);
206 void CreateServerDialog::createHostInfoDemoRecord(
GameCreateParams& params,
bool offline)
208 if (gConfig.doomseeker.bRecordDemo && offline)
210 params.setDemoPath(GameDemo::mkDemoFullPath(GameDemo::Managed, *d->currentEngine));
211 params.setDemoRecord(GameDemo::Managed);
215 GameMode CreateServerDialog::currentGameMode()
const 217 return d->generalSetupPanel->currentGameMode();
220 void CreateServerDialog::firstLoadConfigTimer()
222 initEngineSpecific(d->generalSetupPanel->currentPlugin());
223 QString tmpServerCfgPath = gDefaultDataPaths->programsDataDirectoryPath() + TEMP_SERVER_CONFIG_FILENAME;
225 QFileInfo fi(tmpServerCfgPath);
228 loadConfig(tmpServerCfgPath,
true);
232 void CreateServerDialog::initDMFlagsTabs()
234 bool flagsAdded = d->dmflagsPanel->initDMFlagsTabs(d->currentEngine);
235 int tabIndex = d->tabWidget->indexOf(d->tabFlags);
236 if (flagsAdded && tabIndex < 0)
238 d->tabWidget->insertTab(d->tabWidget->indexOf(d->tabCustomParameters), d->tabFlags, tr(
"Flags"));
240 else if (!flagsAdded && tabIndex >= 0)
242 d->tabWidget->removeTab(tabIndex);
246 void CreateServerDialog::initEngineSpecific(
EnginePlugin* engine)
248 if (engine == d->currentEngine || engine == NULL)
253 d->currentEngine = engine;
255 d->generalSetupPanel->setupForEngine(engine);
257 initEngineSpecificPages(engine);
258 initInfoAndPassword();
262 void CreateServerDialog::initEngineSpecificPages(
EnginePlugin* engine)
269 d->currentCustomPages.clear();
275 int idxInsertAt = d->tabWidget->indexOf(d->tabCustomParameters);
276 d->tabWidget->insertTab(idxInsertAt, page, page->name());
280 void CreateServerDialog::initGamemodeSpecific(
const GameMode &gameMode)
282 d->rulesPanel->setupForEngine(d->currentEngine, gameMode);
285 void CreateServerDialog::initInfoAndPassword()
287 d->miscPanel->setupForEngine(d->currentEngine);
288 d->tabWidget->setTabEnabled(d->tabWidget->indexOf(d->tabMisc), d->miscPanel->isAnythingAvailable());
291 void CreateServerDialog::initRules()
293 d->rulesPanel->setupForEngine(d->currentEngine, currentGameMode());
296 bool CreateServerDialog::loadConfig(
const QString& filename,
bool loadingPrevious)
298 QSettings settingsFile(filename, QSettings::IniFormat);
300 Ini ini(&settingsProvider);
302 d->generalSetupPanel->loadConfig(ini, loadingPrevious);
303 d->rulesPanel->loadConfig(ini);
304 d->miscPanel->loadConfig(ini);
305 d->dmflagsPanel->loadConfig(ini);
313 d->customParamsPanel->loadConfig(ini);
317 void CreateServerDialog::makeRemoteGameSetupDialog(
const EnginePlugin *plugin)
319 d->remoteGameSetup =
true;
321 d->btnCommandLine->hide();
322 d->btnPlayOffline->setDisabled(
true);
324 d->generalSetupPanel->setupForRemoteGame();
325 d->rulesPanel->setupForRemoteGame();
330 return d->rulesPanel->mapListPanel();
333 QString CreateServerDialog::mapName()
const 335 return d->generalSetupPanel->mapName();
338 bool CreateServerDialog::fillInParamsFromPluginPages(
GameCreateParams ¶ms)
349 d->tabWidget->setCurrentIndex(d->tabWidget->indexOf(page));
356 void CreateServerDialog::runGame(
bool offline)
358 const QString errorCapt = tr(
"Doomseeker - create game");
359 if (d->currentEngine == NULL)
361 QMessageBox::critical(NULL, errorCapt, tr(
"No engine selected"));
366 if (createHostInfo(gameParams, offline))
370 GameHost* gameRunner = d->currentEngine->gameHost();
377 QMessageBox::critical(NULL, tr(
"Doomseeker - error"), message.
contents());
381 QString tmpServerConfigPath = gDefaultDataPaths->programsDataDirectoryPath() + TEMP_SERVER_CONFIG_FILENAME;
382 saveConfig(tmpServerConfigPath);
387 bool CreateServerDialog::saveConfig(
const QString& filename)
389 QSettings settingsFile(filename, QSettings::IniFormat);
391 Ini ini(&settingsProvider);
394 d->generalSetupPanel->saveConfig(ini);
395 d->rulesPanel->saveConfig(ini);
396 d->miscPanel->saveConfig(ini);
397 d->dmflagsPanel->saveConfig(ini);
405 d->customParamsPanel->saveConfig(ini);
407 if (settingsFile.isWritable())
415 void CreateServerDialog::setIwadByName(
const QString &iwad)
417 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.
virtual void fillInGameCreateParams(GameCreateParams ¶ms)=0
Fills in GameCreateParams structure with the page's contents.
Dialog window allowing user to host a game.
Game mode representation.
Base class to be used by plugins to define custom pages in Create Game 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 fillInGameCreateParams().
virtual bool loadConfig(Ini &ini)=0
Loads variables that are stored in the config into the GUI.