CLOUD: Update StorageWizardDialog

It now hides code fields not just when built with SDL_Net, but also when
LocalWebserver's using default port.

So that's why NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE is defined
in localwebserver.h now.
This commit is contained in:
Alexander Tkachev 2016-07-20 16:36:44 +06:00
parent 39865e6e6c
commit 85f4c69fc9
3 changed files with 34 additions and 24 deletions

View File

@ -47,10 +47,11 @@ typedef struct _TCPsocket *TCPsocket;
namespace Networking {
#define NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
class LocalWebserver : public Common::Singleton<LocalWebserver> {
static const uint32 FRAMES_PER_SECOND = 20;
static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
static const uint32 DEFAULT_SERVER_PORT = 12345;
static const uint32 MAX_CONNECTIONS = 10;
friend void localWebserverTimer(void *); //calls handle()
@ -84,6 +85,8 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> {
void resolveAddress(void *ipAddress);
public:
static const uint32 DEFAULT_SERVER_PORT = 12345;
LocalWebserver();
virtual ~LocalWebserver();

View File

@ -61,15 +61,15 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId):
new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd);
_connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd);
#ifdef USE_SDL_NET
// hide fields and even the button if local webserver is on
returnLine1->setLabel(_s("You would be navigated to ScummVM's page"));
returnLine2->setLabel(_s("when you'd allow it to use your storage."));
for (uint32 i = 0; i < CODE_FIELDS; ++i)
_codeWidget[i]->setVisible(false);
_messageWidget->setVisible(false);
_connectWidget->setVisible(false);
#endif
if (couldUseLocalServer()) {
// hide fields and even the button if local webserver is on
returnLine1->setLabel(_s("You would be navigated to ScummVM's page"));
returnLine2->setLabel(_s("when you'd allow it to use your storage."));
for (uint32 i = 0; i < CODE_FIELDS; ++i)
_codeWidget[i]->setVisible(false);
_messageWidget->setVisible(false);
_connectWidget->setVisible(false);
}
}
void StorageWizardDialog::open() {
@ -97,18 +97,18 @@ void StorageWizardDialog::open() {
}
}
#ifdef USE_SDL_NET
_stopServerOnClose = !LocalServer.isRunning();
LocalServer.start();
LocalServer.indexPageHandler().setTarget(this);
#endif
if (couldUseLocalServer()) {
_stopServerOnClose = !LocalServer.isRunning();
LocalServer.start();
LocalServer.indexPageHandler().setTarget(this);
}
}
void StorageWizardDialog::close() {
#ifdef USE_SDL_NET
if (_stopServerOnClose) LocalServer.stopOnIdle();
LocalServer.indexPageHandler().setTarget(nullptr);
#endif
if (couldUseLocalServer()) {
if (_stopServerOnClose) LocalServer.stopOnIdle();
LocalServer.indexPageHandler().setTarget(nullptr);
}
Dialog::close();
}
@ -182,12 +182,10 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
close();
break;
}
#ifdef USE_SDL_NET
case kStorageCodePassedCmd:
CloudMan.connectStorage(_storageId, LocalServer.indexPageHandler().code());
_close = true;
break;
#endif
default:
Dialog::handleCommand(sender, cmd, data);
}
@ -210,12 +208,18 @@ Common::String StorageWizardDialog::getUrl() const {
case Cloud::kStorageGoogleDriveId: url += "gd"; break;
case Cloud::kStorageBoxId: url += "bx"; break;
}
#ifdef USE_SDL_NET
url += "s";
#endif
if (couldUseLocalServer()) url += "s";
return url;
}
bool StorageWizardDialog::couldUseLocalServer() const {
#ifdef USE_SDL_NET
return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT;
#else
return false;
#endif
}
int StorageWizardDialog::decodeHashchar(char c) {
const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!";

View File

@ -51,6 +51,9 @@ class StorageWizardDialog : public Dialog {
/** Return short scummvm.org URL for user to navigate to. */
Common::String getUrl() const;
/** Return whether fields should be used or not. */
bool couldUseLocalServer() const;
/**
* Return the value corresponding to the given character.
*