From c409d29f66057a1a2c0e405e60cc8aa5623bc52f Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 5 Jul 2016 20:42:57 +0600 Subject: CLOUD: Add "/files" handler Shows the page with controls, but doesn't actually list the directories, create the specified ones or allows to upload files yet. --- backends/networking/sdl_net/indexpagehandler.cpp | 28 +++++++++- backends/networking/sdl_net/indexpagehandler.h | 1 + backends/networking/wwwroot.zip | Bin 228232 -> 230835 bytes backends/networking/wwwroot/files.html | 50 ++++++++++++++++++ backends/networking/wwwroot/style.css | 64 +++++++++++++++++++++++ 5 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 backends/networking/wwwroot/files.html (limited to 'backends/networking') diff --git a/backends/networking/sdl_net/indexpagehandler.cpp b/backends/networking/sdl_net/indexpagehandler.cpp index 2d1f2c2cd7..c2ea470802 100644 --- a/backends/networking/sdl_net/indexpagehandler.cpp +++ b/backends/networking/sdl_net/indexpagehandler.cpp @@ -33,11 +33,13 @@ namespace Networking { #define ARCHIVE_NAME "wwwroot.zip" #define INDEX_PAGE_NAME "index.html" +#define FILES_PAGE_NAME "files.html" IndexPageHandler::IndexPageHandler(): CommandSender(nullptr) {} IndexPageHandler::~IndexPageHandler() { LocalServer.removePathHandler("/"); + LocalServer.removePathHandler("/files/"); Common::ArchiveMemberList fileList = listArchive(); for (Common::ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { @@ -68,6 +70,28 @@ void IndexPageHandler::handle(Client &client) { LocalWebserver::setClientGetHandler(client, response); } +void IndexPageHandler::handleFiles(Client &client) { + Common::String response = "ScummVM{content}"; //TODO + + // load stylish response page from the archive + Common::SeekableReadStream *const stream = getArchiveFile(FILES_PAGE_NAME); + if (stream) response = readEverythingFromStream(stream); + + // TODO: list specified directory + Common::String path = client.queryParameter("path"); + Common::String content = ""; + + //these occur twice: + replace(response, "{create_directory_button}", _("Create directory")); + replace(response, "{create_directory_button}", _("Create directory")); + replace(response, "{upload_files_button}", _("Upload files")); //tab + replace(response, "{upload_file_button}", _("Upload files")); //button in the tab + replace(response, "{create_directory_desc}", _("Type new directory name:")); + replace(response, "{upload_file_desc}", _("Select a file to upload:")); + replace(response, "{content}", content); + LocalWebserver::setClientGetHandler(client, response); +} + void IndexPageHandler::handleResource(Client &client) { Common::String filename = client.path(); filename.deleteChar(0); @@ -80,11 +104,13 @@ void IndexPageHandler::addPathHandler(LocalWebserver &server) { // we can't use LocalServer yet, because IndexPageHandler is created while LocalWebserver is created // (thus no _instance is available and it causes stack overflow) server.addPathHandler("/", new Common::Callback(this, &IndexPageHandler::handle)); + server.addPathHandler("/files", new Common::Callback(this, &IndexPageHandler::handleFiles)); Common::ArchiveMemberList fileList = listArchive(); for (Common::ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { Common::ArchiveMember const &m = **it; - if (m.getName() == INDEX_PAGE_NAME) continue; + if (m.getName() == INDEX_PAGE_NAME) continue; + if (m.getName() == FILES_PAGE_NAME) continue; server.addPathHandler("/" + m.getName(), new Common::Callback(this, &IndexPageHandler::handleResource)); } } diff --git a/backends/networking/sdl_net/indexpagehandler.h b/backends/networking/sdl_net/indexpagehandler.h index cbcc6dab6e..e70ffd5236 100644 --- a/backends/networking/sdl_net/indexpagehandler.h +++ b/backends/networking/sdl_net/indexpagehandler.h @@ -34,6 +34,7 @@ class IndexPageHandler: public GUI::CommandSender { Common::String _code; void handle(Client &client); + void handleFiles(Client &client); void handleResource(Client &client); void replace(Common::String &source, const Common::String &what, const Common::String &with); diff --git a/backends/networking/wwwroot.zip b/backends/networking/wwwroot.zip index 403385ba2e..1a301f5db5 100644 Binary files a/backends/networking/wwwroot.zip and b/backends/networking/wwwroot.zip differ diff --git a/backends/networking/wwwroot/files.html b/backends/networking/wwwroot/files.html new file mode 100644 index 0000000000..8a2788905a --- /dev/null +++ b/backends/networking/wwwroot/files.html @@ -0,0 +1,50 @@ + + + + ScummVM + + + + +
+
+
+
+
+ + + +
{create_directory_button}{upload_files_button}
+ + +
+
+ {content} +
+
+ + + \ No newline at end of file diff --git a/backends/networking/wwwroot/style.css b/backends/networking/wwwroot/style.css index 75c8378229..59d96671db 100644 --- a/backends/networking/wwwroot/style.css +++ b/backends/networking/wwwroot/style.css @@ -22,3 +22,67 @@ html { } .content p { margin: 0 0 6pt 0; } + +.controls { + padding: 8pt; + background: #FFF; + font-family: Tahoma; + font-size: 16pt; +} + +.controls .buttons { + width: 100%; + max-width: 500pt; + margin: -8pt auto; + border: 0; + border-spacing: 0; +} + +.controls .buttons td { + width: 50%; + text-align: center; + margin: 0; + padding: 0; +} + +.controls .buttons a { + display: block; + height: 40pt; + line-height: 38pt; + vertical-align: middle; + color: #000; + text-decoration: none; +} + +.controls .buttons a:hover { + background: #F3F3F3; +} + +.modal { + margin-top: 10pt; + display: none; +} + +.modal p { margin: 0 0 6pt 0; } + +#create_directory input[type="text"], #upload_file input[type="file"] { + width: calc(100% - 2 * 5pt); +} + +.modal input { + border: 1px solid #EEE; + padding: 5pt; + font-size: 12pt; +} + +.modal input[type="submit"] { + display: block; + margin: 6pt auto; + background: #DDD; + border: 0; +} + +.modal input[type="submit"]:hover { + background: #F3F3F3; + cursor: pointer; +} \ No newline at end of file -- cgit v1.2.3