Skip to content

Commit

Permalink
Shell|Mac OS X: Functional dialog for starting a local server
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 3, 2013
1 parent cd2dc39 commit bbf6606
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 36 deletions.
2 changes: 1 addition & 1 deletion doomsday/tools/shell/shell-text/src/aboutdialog.cpp
Expand Up @@ -34,7 +34,7 @@ AboutDialog::AboutDialog()
label->setExpandsToFitLines(true);
label->rule()
.setLeftTop(rule().left(), rule().top())
.setInput(RuleRectangle::Width, rule().width());
.setInput(Rule::Width, rule().width());

add(label);

Expand Down
51 changes: 35 additions & 16 deletions doomsday/tools/shell/shell-text/src/localserverdialog.cpp
Expand Up @@ -29,6 +29,7 @@ using namespace de::shell;
struct LocalServerDialog::Instance
{
ChoiceWidget *choice;
LineEditWidget *port;
};

static struct
Expand All @@ -38,7 +39,7 @@ static struct
}
gameModes[] =
{
{ "None", "" },
//{ "None", "" },

{ "Shareware DOOM", "doom1-share" },
{ "DOOM", "doom1" },
Expand All @@ -63,8 +64,12 @@ gameModes[] =

LocalServerDialog::LocalServerDialog() : d(new Instance)
{
d->choice = new ChoiceWidget(String("#%1.choice").arg(id()));
d->choice = new ChoiceWidget("gameMode");
d->port = new LineEditWidget("serverPort");
add(d->choice);
add(d->port);

// Define the contents for the choice list.
ChoiceWidget::Items modes;
for(int i = 0; gameModes[i].name; ++i)
{
Expand All @@ -74,27 +79,31 @@ LocalServerDialog::LocalServerDialog() : d(new Instance)
d->choice->setPrompt(tr("Game mode: "));
d->choice->setBackground(TextCanvas::Char(' ', TextCanvas::Char::Reverse));

setFocusCycle(WidgetList()
<< d->choice
<< &lineEdit()
<< &menu());

add(d->choice);
setFocusCycle(WidgetList() << d->choice << d->port << &lineEdit() << &menu());

d->choice->rule()
.setInput(RuleRectangle::Height, Const(1))
.setInput(RuleRectangle::Width, rule().width())
.setInput(RuleRectangle::Left, rule().left())
.setInput(RuleRectangle::Top, label().rule().bottom() + 1);
.setInput(Rule::Height, Const(1))
.setInput(Rule::Width, rule().width())
.setInput(Rule::Left, rule().left())
.setInput(Rule::Top, label().rule().bottom() + 1);

d->port->setPrompt(tr("TCP port: "));
d->port->setText("13209");

d->port->rule()
.setInput(Rule::Width, Const(16))
.setInput(Rule::Left, rule().left())
.setInput(Rule::Top, d->choice->rule().bottom() + 1);

lineEdit().rule()
.setInput(RuleRectangle::Top, d->choice->rule().bottom() + 1);
.setInput(Rule::Top, d->port->rule().bottom() + 1);

rule().setInput(RuleRectangle::Height,
label().rule().height() +
rule().setInput(Rule::Height,
label().rule() .height() +
d->choice->rule().height() +
d->port->rule() .height() +
lineEdit().rule().height() +
menu().rule().height() + 3);
menu().rule() .height() + 4);

setDescription(tr("Specify the settings for starting a new local server."));

Expand All @@ -108,6 +117,16 @@ LocalServerDialog::~LocalServerDialog()
delete d;
}

duint16 LocalServerDialog::port() const
{
return d->port->text().toInt();
}

String LocalServerDialog::gameMode() const
{
return gameModes[d->choice->selection()].mode;
}

void LocalServerDialog::prepare()
{
InputDialog::prepare();
Expand Down
5 changes: 5 additions & 0 deletions doomsday/tools/shell/shell-text/src/localserverdialog.h
Expand Up @@ -19,6 +19,7 @@
#ifndef LOCALSERVERDIALOG_H
#define LOCALSERVERDIALOG_H

#include <de/libdeng2.h>
#include <de/shell/InputDialog>

class LocalServerDialog : public de::shell::InputDialog
Expand All @@ -27,6 +28,10 @@ class LocalServerDialog : public de::shell::InputDialog
LocalServerDialog();
~LocalServerDialog();

de::duint16 port() const;

de::String gameMode() const;

protected:
void prepare();

Expand Down
48 changes: 29 additions & 19 deletions doomsday/tools/shell/shell-text/src/shellapp.cpp
Expand Up @@ -25,8 +25,9 @@
#include "aboutdialog.h"
#include <de/shell/LabelWidget>
#include <de/shell/MenuWidget>
#include <de/shell/Link>
#include <de/shell/Action>
#include <de/shell/Link>
#include <de/shell/LocalServer>
#include <de/LogBuffer>
#include <QStringList>

Expand All @@ -50,20 +51,20 @@ struct ShellApp::Instance
// Status bar in the bottom of the view.
status = new StatusWidget;
status->rule()
.setInput(RuleRectangle::Height, Const(1))
.setInput(RuleRectangle::Bottom, root.viewBottom())
.setInput(RuleRectangle::Width, root.viewWidth())
.setInput(RuleRectangle::Left, root.viewLeft());
.setInput(Rule::Height, Const(1))
.setInput(Rule::Bottom, root.viewBottom())
.setInput(Rule::Width, root.viewWidth())
.setInput(Rule::Left, root.viewLeft());

// Menu button at the left edge.
menuLabel = new LabelWidget;
menuLabel->setAlignment(AlignTop);
menuLabel->setLabel(tr(" F9:Menu "));
menuLabel->setAttribs(TextCanvas::Char::Bold);
menuLabel->rule()
.setInput(RuleRectangle::Left, root.viewLeft())
.setInput(RuleRectangle::Width, Const(menuLabel->label().size()))
.setInput(RuleRectangle::Bottom, status->rule().top());
.setInput(Rule::Left, root.viewLeft())
.setInput(Rule::Width, Const(menuLabel->label().size()))
.setInput(Rule::Bottom, status->rule().top());

menuLabel->addAction(new Action(KeyEvent(Qt::Key_F9), &self, SLOT(openMenu())));
menuLabel->addAction(new Action(KeyEvent(Qt::Key_Z, KeyEvent::Control), &self, SLOT(openMenu())));
Expand All @@ -73,19 +74,19 @@ struct ShellApp::Instance
// Expanding command line widget.
cli = new CommandLineWidget;
cli->rule()
.setInput(RuleRectangle::Left, menuLabel->rule().right())
.setInput(RuleRectangle::Right, root.viewRight())
.setInput(RuleRectangle::Bottom, status->rule().top());
.setInput(Rule::Left, menuLabel->rule().right())
.setInput(Rule::Right, root.viewRight())
.setInput(Rule::Bottom, status->rule().top());

menuLabel->rule().setInput(RuleRectangle::Top, cli->rule().top());
menuLabel->rule().setInput(Rule::Top, cli->rule().top());

// Log history covers the rest of the view.
log = new LogWidget;
log->rule()
.setInput(RuleRectangle::Left, root.viewLeft())
.setInput(RuleRectangle::Width, root.viewWidth())
.setInput(RuleRectangle::Top, root.viewTop())
.setInput(RuleRectangle::Bottom, cli->rule().top());
.setInput(Rule::Left, root.viewLeft())
.setInput(Rule::Width, root.viewWidth())
.setInput(Rule::Top, root.viewTop())
.setInput(Rule::Bottom, cli->rule().top());

// Main menu.
menu = new MenuWidget(MenuWidget::Popup);
Expand All @@ -101,8 +102,8 @@ struct ShellApp::Instance
KeyEvent(Qt::Key_X, KeyEvent::Control),
&self, SLOT(quit())), "Ctrl-X");
menu->rule()
.setInput(RuleRectangle::Bottom, menuLabel->rule().top())
.setInput(RuleRectangle::Left, menuLabel->rule().left());
.setInput(Rule::Bottom, menuLabel->rule().top())
.setInput(Rule::Left, menuLabel->rule().left());

// Compose the UI.
root.add(status);
Expand Down Expand Up @@ -130,6 +131,9 @@ ShellApp::ShellApp(int &argc, char **argv)
LogBuffer &buf = LogBuffer::appBuffer();
buf.setMaxEntryCount(50); // buffered here rather than appBuffer
buf.addSink(d->log->logSink());
#ifdef _DEBUG
buf.enable(LogEntry::DEBUG);
#endif

QStringList args = arguments();
if(args.size() > 1)
Expand All @@ -152,7 +156,8 @@ void ShellApp::openConnection(String const &address)

LOG_INFO("Opening connection to %s") << address;

d->link = new Link(address);
// Keep trying to connect to 30 seconds.
d->link = new Link(address, 30);
d->status->setShellLink(d->link);

connect(d->link, SIGNAL(packetsReady()), this, SLOT(handleIncomingPackets()));
Expand Down Expand Up @@ -191,10 +196,15 @@ void ShellApp::askToOpenConnection()

void ShellApp::askToStartLocalServer()
{
closeConnection();

LocalServerDialog dlg;
if(dlg.exec(rootWidget()))
{
LocalServer sv;
sv.start(dlg.port(), dlg.gameMode());

openConnection("localhost:" + String::number(dlg.port()));
}
}

Expand Down

0 comments on commit bbf6606

Please sign in to comment.