diff --git a/doomsday/tools/shell/shell-gui/src/aboutdialog.cpp b/doomsday/tools/shell/shell-gui/src/aboutdialog.cpp index 93aac2fe3e..0c398ddb2f 100644 --- a/doomsday/tools/shell/shell-gui/src/aboutdialog.cpp +++ b/doomsday/tools/shell/shell-gui/src/aboutdialog.cpp @@ -33,5 +33,5 @@ AboutDialog::AboutDialog(QWidget *parent) QDialogButtonBox *bbox = new QDialogButtonBox; box->addWidget(bbox); QPushButton *button = bbox->addButton(QDialogButtonBox::Close); - connect(button, SIGNAL(pressed()), this, SLOT(accept())); + connect(button, SIGNAL(clicked()), this, SLOT(accept())); } diff --git a/doomsday/tools/shell/shell-gui/src/guishellapp.cpp b/doomsday/tools/shell/shell-gui/src/guishellapp.cpp index 14ac4db4fd..2a7cd15c9b 100644 --- a/doomsday/tools/shell/shell-gui/src/guishellapp.cpp +++ b/doomsday/tools/shell/shell-gui/src/guishellapp.cpp @@ -20,7 +20,9 @@ #include "mainwindow.h" #include "opendialog.h" #include "aboutdialog.h" +#include "localserverdialog.h" #include +#include #include using namespace de; @@ -168,6 +170,11 @@ void GuiShellApp::closeActiveWindow() void GuiShellApp::startLocalServer() { + LocalServerDialog dlg; + if(dlg.exec() == QDialog::Accepted) + { + + } } void GuiShellApp::updateLocalServerMenu() diff --git a/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp b/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp index aee252f605..f116181bc8 100644 --- a/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp +++ b/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp @@ -18,22 +18,132 @@ #include "localserverdialog.h" #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace de; +using namespace de::shell; DENG2_PIMPL(LocalServerDialog) { + QPushButton *yes; + QComboBox *games; + QLineEdit *port; + QLineEdit *options; + QLineEdit *folder; + Instance(Public &i) : Private(i) { + QSettings st; + + self.setWindowTitle(tr("Start Local Server")); + + QVBoxLayout *mainLayout = new QVBoxLayout; + self.setLayout(mainLayout); + + QFormLayout *form = new QFormLayout; + mainLayout->addLayout(form); + + games = new QComboBox; + games->setEditable(false); + foreach(DoomsdayInfo::GameMode const &mode, DoomsdayInfo::allGameModes()) + { + games->addItem(mode.title, mode.option); + } + games->setCurrentIndex(games->findData(st.value("LocalServer/gameMode", "doom1-share"))); + form->addRow(tr("Game mode:"), games); + + port = new QLineEdit; + port->setMaximumWidth(80); + port->setText(QString::number(st.value("LocalServer/port", 13209).toInt())); + port->setToolTip(tr("Port must be between 0 and 65535.")); + form->addRow(tr("TCP port:"), port); + folder = new QLineEdit; + folder->setMinimumWidth(300); + folder->setText(st.value("LocalServer/runtime", + DoomsdayInfo::defaultServerRuntimeFolder().toString()).toString()); + form->addRow(tr("Runtime folder:"), folder); + + QPushButton *folderButton = new QPushButton(tr("Select Folder")); + connect(folderButton, SIGNAL(clicked()), &self, SLOT(pickFolder())); + form->addRow(0, folderButton); + + options = new QLineEdit; + options->setMinimumWidth(300); + options->setText(st.value("LocalServer/options").toString()); + form->addRow(tr("Options:"), options); + + QDialogButtonBox *bbox = new QDialogButtonBox; + mainLayout->addWidget(bbox); + yes = bbox->addButton(tr("&Start Server"), QDialogButtonBox::YesRole); + QPushButton* no = bbox->addButton(tr("&Cancel"), QDialogButtonBox::RejectRole); + QPushButton *opt = bbox->addButton(tr("Game Options..."), QDialogButtonBox::ActionRole); + QObject::connect(yes, SIGNAL(clicked()), &self, SLOT(accept())); + QObject::connect(no, SIGNAL(clicked()), &self, SLOT(reject())); + QObject::connect(opt, SIGNAL(clicked()), &self, SLOT(configureGameOptions())); + yes->setDefault(true); } }; LocalServerDialog::LocalServerDialog(QWidget *parent) : QDialog(parent), d(new Instance(*this)) { + connect(d->port, SIGNAL(textChanged(QString)), this, SLOT(validate())); + connect(this, SIGNAL(accepted()), this, SLOT(saveState())); + validate(); } LocalServerDialog::~LocalServerDialog() { delete d; } + +void LocalServerDialog::pickFolder() +{ + QString dir = QFileDialog::getExistingDirectory(this, + tr("Select Runtime Folder"), + d->folder->text()); + if(!dir.isEmpty()) d->folder->setText(dir); + + validate(); +} + +void LocalServerDialog::configureGameOptions() +{ +} + +void LocalServerDialog::saveState() +{ + QSettings st; + st.setValue("LocalServer/gameMode", d->games->itemData(d->games->currentIndex()).toString()); + st.setValue("LocalServer/port", d->port->text().toInt()); + st.setValue("LocalServer/runtime", d->folder->text()); + st.setValue("LocalServer/options", d->options->text()); +} + +void LocalServerDialog::validate() +{ + bool isValid = true; + + // Check port. + QString txt = d->port->text().trimmed(); + int num = txt.toInt(); + if(txt.isEmpty() || num < 0 || num >= 0x10000) + { + isValid = false; + } + + if(d->folder->text().isEmpty()) isValid = false; + + d->yes->setEnabled(isValid); +} diff --git a/doomsday/tools/shell/shell-gui/src/localserverdialog.h b/doomsday/tools/shell/shell-gui/src/localserverdialog.h index 0763ecdea3..c66c11667b 100644 --- a/doomsday/tools/shell/shell-gui/src/localserverdialog.h +++ b/doomsday/tools/shell/shell-gui/src/localserverdialog.h @@ -23,10 +23,18 @@ class LocalServerDialog : public QDialog { + Q_OBJECT + public: explicit LocalServerDialog(QWidget *parent = 0); ~LocalServerDialog(); +protected slots: + void pickFolder(); + void configureGameOptions(); + void saveState(); + void validate(); + private: struct Instance; Instance *d; diff --git a/doomsday/tools/shell/shell-gui/src/opendialog.cpp b/doomsday/tools/shell/shell-gui/src/opendialog.cpp index 05571f1841..9ee90307db 100644 --- a/doomsday/tools/shell/shell-gui/src/opendialog.cpp +++ b/doomsday/tools/shell/shell-gui/src/opendialog.cpp @@ -73,7 +73,7 @@ DENG2_PIMPL(OpenDialog) item->setAlignment(Qt::AlignBottom); localCount = new QLabel; - form->addRow(new QWidget, localCount); + form->addRow(0, localCount); QObject::connect(&GuiShellApp::app().serverFinder(), SIGNAL(updated()), &self, SLOT(updateLocalList()));