aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-05 16:31:52 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commite601c39802adbb64dce4b449c617e1786ef584ed (patch)
tree47967b710c44a15524b7170885080aaefdceb949
parent3da38ca60b65d3f1bd67b049f3c4b2a90a4d6a19 (diff)
downloadscummvm-rg350-e601c39802adbb64dce4b449c617e1786ef584ed.tar.gz
scummvm-rg350-e601c39802adbb64dce4b449c617e1786ef584ed.tar.bz2
scummvm-rg350-e601c39802adbb64dce4b449c617e1786ef584ed.zip
CLOUD: Make "Run server" button active
It should show the real server's IP over there, but that doesn't work yet.
-rw-r--r--backends/networking/sdl_net/localwebserver.cpp20
-rw-r--r--backends/networking/sdl_net/localwebserver.h3
-rw-r--r--gui/options.cpp33
-rw-r--r--gui/options.h3
-rw-r--r--gui/storagewizarddialog.cpp5
-rw-r--r--gui/storagewizarddialog.h1
6 files changed, 56 insertions, 9 deletions
diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp
index 1cfbbb8819..134ccd8508 100644
--- a/backends/networking/sdl_net/localwebserver.cpp
+++ b/backends/networking/sdl_net/localwebserver.cpp
@@ -71,7 +71,10 @@ void LocalWebserver::stopTimer() {
void LocalWebserver::start() {
_handleMutex.lock();
_stopOnIdle = false;
- if (_timerStarted) return;
+ if (_timerStarted) {
+ _handleMutex.unlock();
+ return;
+ }
startTimer();
// Create a listening TCP socket
@@ -79,6 +82,11 @@ void LocalWebserver::start() {
if (SDLNet_ResolveHost(&ip, NULL, SERVER_PORT) == -1) {
error("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
}
+ _address = Common::String::format(
+ "http://%u.%u.%u.%u:%u/",
+ (ip.host>>24)&0xFF, (ip.host >> 16) & 0xFF, (ip.host >> 8) & 0xFF, ip.host & 0xFF,
+ SERVER_PORT
+ );
_serverSocket = SDLNet_TCP_Open(&ip);
if (!_serverSocket) {
error("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
@@ -130,8 +138,18 @@ void LocalWebserver::removePathHandler(Common::String path) {
_pathHandlers.erase(path);
}
+Common::String LocalWebserver::getAddress() { return _address; }
+
IndexPageHandler &LocalWebserver::indexPageHandler() { return _indexPageHandler; }
+bool LocalWebserver::isRunning() {
+ bool result = false;
+ _handleMutex.lock();
+ result = _timerStarted;
+ _handleMutex.unlock();
+ return result;
+}
+
void LocalWebserver::handle() {
_handleMutex.lock();
int numready = SDLNet_CheckSockets(_set, 0);
diff --git a/backends/networking/sdl_net/localwebserver.h b/backends/networking/sdl_net/localwebserver.h
index 2bd8daff5d..f73d1b2850 100644
--- a/backends/networking/sdl_net/localwebserver.h
+++ b/backends/networking/sdl_net/localwebserver.h
@@ -59,6 +59,7 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> {
IndexPageHandler _indexPageHandler;
uint32 _idlingFrames;
Common::Mutex _handleMutex;
+ Common::String _address;
void startTimer(int interval = TIMER_INTERVAL);
void stopTimer();
@@ -76,7 +77,9 @@ public:
void addPathHandler(Common::String path, ClientHandler handler);
void removePathHandler(Common::String path);
+ Common::String getAddress();
IndexPageHandler &indexPageHandler();
+ bool isRunning();
static void setClientGetHandler(Client &client, Common::String response, long code = 200, const char *mimeType = nullptr);
static void setClientGetHandler(Client &client, Common::SeekableReadStream *responseStream, long code = 200, const char *mimeType = nullptr);
diff --git a/gui/options.cpp b/gui/options.cpp
index 9d9833496f..bb9bf4d123 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -49,6 +49,10 @@
#include "gui/storagewizarddialog.h"
#endif
+#ifdef USE_SDL_NET
+#include "backends/networking/sdl_net/localwebserver.h"
+#endif
+
namespace GUI {
enum {
@@ -1306,10 +1310,13 @@ GlobalOptionsDialog::GlobalOptionsDialog()
_storageDownloadButton = new ButtonWidget(tab, "GlobalOptions_Cloud.DownloadButton", _("Downloads"), _("Open downloads manager dialog"), kDownloadStorageCmd);
_runServerButton = new ButtonWidget(tab, "GlobalOptions_Cloud.RunServerButton", _("Run server"), _("Run local webserver"), kRunServerCmd);
- _serverInfoLabel = new StaticTextWidget(tab, "GlobalOptions_Cloud.ServerInfoLabel", "Not running");
+ _serverInfoLabel = new StaticTextWidget(tab, "GlobalOptions_Cloud.ServerInfoLabel", _("Not running"));
setupCloudTab();
_redrawCloudTab = false;
+#ifdef USE_SDL_NET
+ _serverWasRunning = false;
+#endif
#endif
// Activate the first tab
@@ -1623,9 +1630,8 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
#ifdef USE_SDL_NET
case kRunServerCmd:
{
- //TODO
- //DownloadDialog dialog(_selectedStorageIndex);
- //dialog.runModal();
+ if (LocalServer.isRunning()) LocalServer.stopOnIdle();
+ else LocalServer.start();
break;
}
#endif
@@ -1653,6 +1659,12 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
void GlobalOptionsDialog::handleTickle() {
OptionsDialog::handleTickle();
#ifdef USE_CLOUD
+#ifdef USE_SDL_NET
+ if (LocalServer.isRunning() != _serverWasRunning) {
+ _serverWasRunning = !_serverWasRunning;
+ _redrawCloudTab = true;
+ }
+#endif
if (_redrawCloudTab) {
setupCloudTab();
draw();
@@ -1762,10 +1774,19 @@ void GlobalOptionsDialog::setupCloudTab() {
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud.ServerInfoLabel", x, y, w, h))
warning("GlobalOptions_Cloud.ServerInfoLabel's position is undefined");
serverInfoY = y;
+
+ bool serverIsRunning = LocalServer.isRunning();
if (serverLabelPosition < 0) serverLabelPosition = serverInfoY;
- if (_runServerButton) _runServerButton->setPos(_runServerButton->getRelX(), serverLabelPosition + serverButtonY - serverInfoY);
- if (_serverInfoLabel) _serverInfoLabel->setPos(_serverInfoLabel->getRelX(), serverLabelPosition);
+ if (_runServerButton) {
+ _runServerButton->setPos(_runServerButton->getRelX(), serverLabelPosition + serverButtonY - serverInfoY);
+ _runServerButton->setLabel(_(serverIsRunning ? "Stop server" : "Run server"));
+ }
+ if (_serverInfoLabel) {
+ _serverInfoLabel->setPos(_serverInfoLabel->getRelX(), serverLabelPosition);
+ if (serverIsRunning) _serverInfoLabel->setLabel(LocalServer.getAddress());
+ else _serverInfoLabel->setLabel(_("Not running"));
+ }
#else
if (_runServerButton) _runServerButton->setVisible(false);
if (_serverInfoLabel) _serverInfoLabel->setVisible(false);
diff --git a/gui/options.h b/gui/options.h
index c4c70aa369..1d7f9ffd49 100644
--- a/gui/options.h
+++ b/gui/options.h
@@ -266,6 +266,9 @@ protected:
ButtonWidget *_runServerButton;
StaticTextWidget *_serverInfoLabel;
bool _redrawCloudTab;
+#ifdef USE_SDL_NET
+ bool _serverWasRunning;
+#endif
void setupCloudTab();
#endif
diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp
index 6734d1c97e..7871017f5d 100644
--- a/gui/storagewizarddialog.cpp
+++ b/gui/storagewizarddialog.cpp
@@ -39,7 +39,7 @@ enum {
};
StorageWizardDialog::StorageWizardDialog(uint32 storageId):
- Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false) {
+ Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false), _stopServerOnClose(false) {
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str());
@@ -83,6 +83,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId):
void StorageWizardDialog::open() {
Dialog::open();
#ifdef USE_SDL_NET
+ _stopServerOnClose = !LocalServer.isRunning();
LocalServer.start();
LocalServer.indexPageHandler().setTarget(this);
#endif
@@ -90,7 +91,7 @@ void StorageWizardDialog::open() {
void StorageWizardDialog::close() {
#ifdef USE_SDL_NET
- LocalServer.stopOnIdle();
+ if (_stopServerOnClose) LocalServer.stopOnIdle();
LocalServer.indexPageHandler().setTarget(nullptr);
#endif
Dialog::close();
diff --git a/gui/storagewizarddialog.h b/gui/storagewizarddialog.h
index 93df56d300..ade3c57b47 100644
--- a/gui/storagewizarddialog.h
+++ b/gui/storagewizarddialog.h
@@ -46,6 +46,7 @@ class StorageWizardDialog : public Dialog {
StaticTextWidget *_messageWidget;
ButtonWidget *_connectWidget;
bool _close;
+ bool _stopServerOnClose;
/**
* Return the value corresponding to the given character.