diff --git a/doomsday/libshell/include/de/shell/localserver.h b/doomsday/libshell/include/de/shell/localserver.h index d6539ab75a..b6626efef4 100644 --- a/doomsday/libshell/include/de/shell/localserver.h +++ b/doomsday/libshell/include/de/shell/localserver.h @@ -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; diff --git a/doomsday/libshell/src/localserver.cpp b/doomsday/libshell/src/localserver.cpp index a180980161..1d5d366d6e 100644 --- a/doomsday/libshell/src/localserver.cpp +++ b/doomsday/libshell/src/localserver.cpp @@ -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) @@ -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()) @@ -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); diff --git a/doomsday/tools/shell/shell-gui/src/guishellapp.cpp b/doomsday/tools/shell/shell-gui/src/guishellapp.cpp index ca571fb551..d8284b552c 100644 --- a/doomsday/tools/shell/shell-gui/src/guishellapp.cpp +++ b/doomsday/tools/shell/shell-gui/src/guishellapp.cpp @@ -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) diff --git a/doomsday/tools/shell/shell-gui/src/linkwindow.cpp b/doomsday/tools/shell/shell-gui/src/linkwindow.cpp index 82853dd076..9d2baff46e 100644 --- a/doomsday/tools/shell/shell-gui/src/linkwindow.cpp +++ b/doomsday/tools/shell/shell-gui/src/linkwindow.cpp @@ -296,22 +296,19 @@ 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); @@ -319,6 +316,14 @@ void LinkWindow::openConnection(QString address) 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) diff --git a/doomsday/tools/shell/shell-gui/src/linkwindow.h b/doomsday/tools/shell/shell-gui/src/linkwindow.h index 8c21ef58c9..1b721baaf4 100644 --- a/doomsday/tools/shell/shell-gui/src/linkwindow.h +++ b/doomsday/tools/shell/shell-gui/src/linkwindow.h @@ -21,6 +21,7 @@ #include #include +#include /** * Window for a server link. @@ -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(); diff --git a/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp b/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp index c2e71ae4ac..ce63094d4f 100644 --- a/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp +++ b/doomsday/tools/shell/shell-gui/src/localserverdialog.cpp @@ -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; } @@ -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()); } @@ -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); } diff --git a/doomsday/tools/shell/shell-gui/src/preferences.cpp b/doomsday/tools/shell/shell-gui/src/preferences.cpp index b7f7218b64..572ce7a27c 100644 --- a/doomsday/tools/shell/shell-gui/src/preferences.cpp +++ b/doomsday/tools/shell/shell-gui/src/preferences.cpp @@ -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 ""; } diff --git a/doomsday/tools/shell/shell-gui/src/preferences.h b/doomsday/tools/shell/shell-gui/src/preferences.h index 66c80b8e34..39b51ab349 100644 --- a/doomsday/tools/shell/shell-gui/src/preferences.h +++ b/doomsday/tools/shell/shell-gui/src/preferences.h @@ -30,7 +30,7 @@ class Preferences : public QDialog explicit Preferences(QWidget *parent = 0); ~Preferences(); - de::NativePath iwadFolder() const; + static de::NativePath iwadFolder(); signals: