Navigation Menu

Skip to content

Commit

Permalink
Shell|GUI: Implemented dialog for starting a local server
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 9, 2013
1 parent 29b6705 commit bb95229
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doomsday/tools/shell/shell-gui/src/aboutdialog.cpp
Expand Up @@ -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()));
}
7 changes: 7 additions & 0 deletions doomsday/tools/shell/shell-gui/src/guishellapp.cpp
Expand Up @@ -20,7 +20,9 @@
#include "mainwindow.h"
#include "opendialog.h"
#include "aboutdialog.h"
#include "localserverdialog.h"
#include <QMenuBar>
#include <de/shell/LocalServer>
#include <de/shell/ServerFinder>

using namespace de;
Expand Down Expand Up @@ -168,6 +170,11 @@ void GuiShellApp::closeActiveWindow()

void GuiShellApp::startLocalServer()
{
LocalServerDialog dlg;
if(dlg.exec() == QDialog::Accepted)
{

}
}

void GuiShellApp::updateLocalServerMenu()
Expand Down
110 changes: 110 additions & 0 deletions doomsday/tools/shell/shell-gui/src/localserverdialog.cpp
Expand Up @@ -18,22 +18,132 @@

#include "localserverdialog.h"
#include <de/libdeng2.h>
#include <de/shell/DoomsdayInfo>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QPushButton>
#include <QComboBox>
#include <QLineEdit>
#include <QLabel>
#include <QFileDialog>
#include <QSettings>

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);
}
8 changes: 8 additions & 0 deletions doomsday/tools/shell/shell-gui/src/localserverdialog.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tools/shell/shell-gui/src/opendialog.cpp
Expand Up @@ -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()));

Expand Down

0 comments on commit bb95229

Please sign in to comment.