Skip to content

Commit

Permalink
Shell|libshell: LocalServer opens the link, better Preferences handling
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 13, 2013
1 parent 3dd7901 commit 894aa66
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 27 deletions.
7 changes: 5 additions & 2 deletions doomsday/libshell/include/de/shell/localserver.h
Expand Up @@ -49,9 +49,12 @@ class LIBSHELL_PUBLIC LocalServer
void stop();

/**
* Returns the Link for communicating with the server.
* Opens a link for communicating with the server. The returned link will
* initially be in the Link::Connecting state.
*
* @return Link to the local server. Caller gets ownership.
*/
//Link *openLink();
Link *openLink();

private:
struct Instance;
Expand Down
11 changes: 10 additions & 1 deletion doomsday/libshell/src/localserver.cpp
Expand Up @@ -29,8 +29,10 @@ namespace shell {
struct LocalServer::Instance
{
Link *link;
duint16 port;

Instance() : link(0) {}
Instance() : link(0), port(0)
{}
};

LocalServer::LocalServer() : d(new Instance)
Expand All @@ -44,6 +46,8 @@ LocalServer::~LocalServer()
void LocalServer::start(duint16 port, String const &gameMode, QStringList additionalOptions,
NativePath const &runtimePath)
{
d->port = port;

NativePath userDir = runtimePath;

if(userDir.isEmpty())
Expand Down Expand Up @@ -134,6 +138,11 @@ void LocalServer::stop()
DENG2_ASSERT(d->link != 0);
}

Link *LocalServer::openLink()
{
return new Link(String("localhost:%1").arg(d->port), 30);
}

/*Link &LocalServer::link()
{
DENG2_ASSERT(d->link != 0);
Expand Down
9 changes: 7 additions & 2 deletions doomsday/tools/shell/shell-gui/src/guishellapp.cpp
Expand Up @@ -206,14 +206,19 @@ void GuiShellApp::startLocalServer()
LocalServerDialog dlg;
if(dlg.exec() == QDialog::Accepted)
{
QStringList opts = dlg.additionalOptions();
if(!Preferences::iwadFolder().isEmpty())
{
opts << "-iwad" << Preferences::iwadFolder().toString();
}

LocalServer sv;
sv.start(dlg.port(),
dlg.gameMode(),
dlg.additionalOptions(),
dlg.runtimeFolder());

newOrReusedConnectionWindow()->
openConnection("localhost:" + String::number(dlg.port()));
newOrReusedConnectionWindow()->openConnection(sv.openLink());
}
}
catch(Error const &er)
Expand Down
19 changes: 12 additions & 7 deletions doomsday/tools/shell/shell-gui/src/linkwindow.cpp
Expand Up @@ -296,29 +296,34 @@ void LinkWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}

void LinkWindow::openConnection(QString address)
void LinkWindow::openConnection(Link *link, String name)
{
closeConnection();

qDebug() << "Opening connection to" << address;

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

connect(d->link, SIGNAL(addressResolved()), this, SLOT(addressResolved()));
connect(d->link, SIGNAL(connected()), this, SLOT(connected()));
connect(d->link, SIGNAL(packetsReady()), this, SLOT(handleIncomingPackets()));
connect(d->link, SIGNAL(disconnected()), this, SLOT(disconnected()));

setTitle(address);
if(name.isEmpty()) name = link->address().asText();
setTitle(name);
d->root->setOverlaidMessage(tr("Looking up host..."));
statusBar()->showMessage(tr("Looking up host..."));
d->status->linkConnected(d->link);
d->updateCurrentHost();
d->updateStyle();
}

void LinkWindow::openConnection(QString address)
{
qDebug() << "Opening connection to" << address;

// Keep trying to connect to 30 seconds.
openConnection(new Link(address, 30), address);
}

void LinkWindow::closeConnection()
{
if(d->link)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/tools/shell/shell-gui/src/linkwindow.h
Expand Up @@ -21,6 +21,7 @@

#include <QMainWindow>
#include <de/String>
#include <de/shell/Link>

/**
* Window for a server link.
Expand All @@ -45,6 +46,7 @@ class LinkWindow : public QMainWindow

public slots:
void openConnection(QString address);
void openConnection(de::shell::Link *link, de::String name = "");
void closeConnection();
void sendCommandToServer(de::String command);
void switchToStatus();
Expand Down
11 changes: 0 additions & 11 deletions doomsday/tools/shell/shell-gui/src/localserverdialog.cpp
Expand Up @@ -135,14 +135,6 @@ QString LocalServerDialog::gameMode() const
QStringList LocalServerDialog::additionalOptions() const
{
QStringList opts = d->options->text().split(' ', QString::SkipEmptyParts);

Preferences prefs;
NativePath iwadPath = prefs.iwadFolder();
if(!iwadPath.isEmpty())
{
opts << "-iwad" << iwadPath.toString();
}

return opts;
}

Expand All @@ -161,7 +153,6 @@ void LocalServerDialog::saveState()
st.setValue("LocalServer/gameMode", d->games->itemData(d->games->currentIndex()).toString());
st.setValue("LocalServer/port", d->port->text().toInt());
st.setValue("LocalServer/runtime", d->runtime->path().toString());
//st.setValue("LocalServer/iwad", d->iwadFolder->text());
st.setValue("LocalServer/options", d->options->text());
}

Expand All @@ -179,8 +170,6 @@ void LocalServerDialog::validate()

if(d->runtime->path().isEmpty()) isValid = false;

//if(d->iwadFolder->text().isEmpty()) isValid = false;

d->yes->setEnabled(isValid);
if(isValid) d->yes->setDefault(true);
}
7 changes: 4 additions & 3 deletions doomsday/tools/shell/shell-gui/src/preferences.cpp
Expand Up @@ -69,11 +69,12 @@ Preferences::~Preferences()
delete d;
}

de::NativePath Preferences::iwadFolder() const
de::NativePath Preferences::iwadFolder()
{
if(d->useCustomIwad->isChecked())
QSettings st;
if(st.value("Preferences/customIwad", false).toBool())
{
return d->iwadFolder->path();
return st.value("Preferences/iwadFolder").toString();
}
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tools/shell/shell-gui/src/preferences.h
Expand Up @@ -30,7 +30,7 @@ class Preferences : public QDialog
explicit Preferences(QWidget *parent = 0);
~Preferences();

de::NativePath iwadFolder() const;
static de::NativePath iwadFolder();

signals:

Expand Down

0 comments on commit 894aa66

Please sign in to comment.