aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-04 11:52:40 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit72b82bd2aa66223f6c740e7bf6dce316b2145b15 (patch)
tree458e223ee8c8d2406e46634c23a973b47c93b7f7 /gui
parent97c0bbd2388ac049970fc3c99ebdc072c75724f1 (diff)
downloadscummvm-rg350-72b82bd2aa66223f6c740e7bf6dce316b2145b15.tar.gz
scummvm-rg350-72b82bd2aa66223f6c740e7bf6dce316b2145b15.tar.bz2
scummvm-rg350-72b82bd2aa66223f6c740e7bf6dce316b2145b15.zip
GUI: Add RemoteBrowserDialog
WIP. Tested with Dropbox.
Diffstat (limited to 'gui')
-rw-r--r--gui/downloaddialog.cpp40
-rw-r--r--gui/downloaddialog.h8
-rw-r--r--gui/module.mk1
-rw-r--r--gui/remotebrowser.cpp220
-rw-r--r--gui/remotebrowser.h71
5 files changed, 339 insertions, 1 deletions
diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp
index b449be5ca8..e94b19634b 100644
--- a/gui/downloaddialog.cpp
+++ b/gui/downloaddialog.cpp
@@ -27,6 +27,9 @@
#include "backends/cloud/cloudmanager.h"
#include "common/translation.h"
#include "widgets/edittext.h"
+#include "message.h"
+#include "browser.h"
+#include "remotebrowser.h"
namespace GUI {
@@ -38,6 +41,9 @@ DownloadDialog::DownloadDialog(uint32 storageId):
Dialog("GlobalOptions_Cloud_DownloadDialog"), _wasInProgress(true), _inProgress(false), _close(false) {
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
+ _browser = new BrowserDialog(_("Select directory where to download game data"), true);
+ _remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data"), true);
+
_messageText = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DialogDesc", _("Press the button to download a directory"));
_mainButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Start download"), 0, kDownloadDialogButtonCmd);
_closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd);
@@ -47,6 +53,10 @@ DownloadDialog::DownloadDialog(uint32 storageId):
void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kDownloadDialogButtonCmd: {
+ if (!_inProgress) {
+ selectDirectories();
+ }
+
_inProgress = !_inProgress;
reflowLayout();
break;
@@ -56,6 +66,36 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
}
}
+void DownloadDialog::selectDirectories() {
+ //first user should select remote directory to download
+ if (_remoteBrowser->runModal() <= 0) return;
+
+ /*
+ Common::FSNode dir(_browser->getResult());
+ Common::FSList files;
+ if (!dir.getChildren(files, Common::FSNode::kListAll)) {
+ MessageDialog alert(_("ScummVM couldn't open the specified directory!"));
+ alert.runModal();
+ return;
+ }
+ */
+
+ //now user should select local directory to download into
+ if (_browser->runModal() <= 0) return;
+
+ Common::FSNode dir(_browser->getResult());
+ Common::FSList files;
+ if (!dir.getChildren(files, Common::FSNode::kListAll)) {
+ MessageDialog alert(_("ScummVM couldn't open the specified directory!"));
+ alert.runModal();
+ return;
+ }
+
+ //TODO: require empty directory?
+
+ //TODO: initiate download
+}
+
void DownloadDialog::handleTickle() {
if (_close) {
setResult(1);
diff --git a/gui/downloaddialog.h b/gui/downloaddialog.h
index 333ce0e03b..ca702ef927 100644
--- a/gui/downloaddialog.h
+++ b/gui/downloaddialog.h
@@ -32,8 +32,13 @@ class CommandSender;
class EditTextWidget;
class StaticTextWidget;
class ButtonWidget;
+class BrowserDialog;
+class RemoteBrowserDialog;
+
+class DownloadDialog : public Dialog {
+ BrowserDialog *_browser;
+ RemoteBrowserDialog *_remoteBrowser;
-class DownloadDialog : public Dialog {
StaticTextWidget *_messageText;
ButtonWidget *_mainButton;
ButtonWidget *_closeButton;
@@ -42,6 +47,7 @@ class DownloadDialog : public Dialog {
bool _close;
void updateButtons();
+ void selectDirectories();
public:
DownloadDialog(uint32 storageId);
diff --git a/gui/module.mk b/gui/module.mk
index 2d71c45106..1fdd0d459a 100644
--- a/gui/module.mk
+++ b/gui/module.mk
@@ -17,6 +17,7 @@ MODULE_OBJS := \
object.o \
options.o \
predictivedialog.o \
+ remotebrowser.o \
saveload.o \
saveload-dialog.o \
storagewizarddialog.o \
diff --git a/gui/remotebrowser.cpp b/gui/remotebrowser.cpp
new file mode 100644
index 0000000000..37a51d5341
--- /dev/null
+++ b/gui/remotebrowser.cpp
@@ -0,0 +1,220 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "gui/remotebrowser.h"
+#include "gui/widgets/list.h"
+
+#include "common/config-manager.h"
+#include "common/system.h"
+#include "common/algorithm.h"
+
+#include "common/translation.h"
+#include <backends/networking/curl/request.h>
+#include <backends/cloud/storage.h>
+#include <backends/cloud/cloudmanager.h>
+
+namespace GUI {
+
+enum {
+ kChooseCmd = 'Chos',
+ kGoUpCmd = 'GoUp',
+ kHiddenCmd = 'Hidd'
+};
+
+/* We want to use this as a general directory selector at some point... possible uses
+ * - to select the data dir for a game
+ * - to select the place where save games are stored
+ * - others???
+ */
+
+RemoteBrowserDialog::RemoteBrowserDialog(const char *title, bool dirRemoteBrowser)
+ : Dialog("Browser"), _navigationLocked(false), _updateList(false) {
+
+ _isDirRemoteBrowser = dirRemoteBrowser;
+ _fileList = NULL;
+ _currentPath = NULL;
+
+ // Headline - TODO: should be customizable during creation time
+ new StaticTextWidget(this, "Browser.Headline", title);
+
+ // Current path - TODO: handle long paths ?
+ _currentPath = new StaticTextWidget(this, "Browser.Path", "DUMMY");
+
+ // Add file list
+ _fileList = new ListWidget(this, "Browser.List");
+ _fileList->setNumberingMode(kListNumberingOff);
+ _fileList->setEditable(false);
+
+ _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
+
+ // hide checkbox for the "show hidden files" state.
+ //_showHiddenWidget = new CheckboxWidget(this, "Browser.Hidden", _("Show hidden files"), _("Show files marked with the hidden attribute"), kHiddenCmd);
+
+ // Buttons
+ if (g_system->getOverlayWidth() > 320)
+ new ButtonWidget(this, "Browser.Up", _("Go up"), _("Go to previous directory level"), kGoUpCmd);
+ else
+ new ButtonWidget(this, "Browser.Up", _c("Go up", "lowres"), _("Go to previous directory level"), kGoUpCmd);
+ new ButtonWidget(this, "Browser.Cancel", _("Cancel"), 0, kCloseCmd);
+ new ButtonWidget(this, "Browser.Choose", _("Choose"), 0, kChooseCmd);
+}
+
+void RemoteBrowserDialog::open() {
+ Dialog::open();
+ listDirectory(Cloud::StorageFile());
+}
+
+void RemoteBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
+ switch (cmd) {
+ case kChooseCmd:
+ if (_isDirRemoteBrowser) {
+ // If nothing is selected in the list widget, choose the current dir.
+ // Else, choose the dir that is selected.
+ int selection = _fileList->getSelected();
+ if (selection >= 0)
+ _choice = _nodeContent[selection];
+ else
+ _choice = _node;
+ setResult(1);
+ close();
+ } else {
+ int selection = _fileList->getSelected();
+ if (selection < 0)
+ break;
+ if (_nodeContent[selection].isDirectory()) {
+ _node = _nodeContent[selection];
+ updateListing();
+ } else {
+ _choice = _nodeContent[selection];
+ setResult(1);
+ close();
+ }
+ }
+ break;
+ case kGoUpCmd:
+ goUp();
+ break;
+ case kListItemActivatedCmd:
+ case kListItemDoubleClickedCmd:
+ if (_nodeContent[data].isDirectory()) {
+ _node = _nodeContent[data];
+ listDirectory(_node);
+ } else if (!_isDirRemoteBrowser) { //TODO: ????
+ _choice = _nodeContent[data];
+ setResult(1);
+ close();
+ }
+ break;
+ case kListSelectionChangedCmd:
+ // We do not allow selecting directories in directory
+ // RemoteBrowser mode, thus we will invalidate the selection
+ // when the user selects an directory over here.
+ if (data != (uint32)-1 && _isDirRemoteBrowser && !_nodeContent[data].isDirectory())
+ _fileList->setSelected(-1);
+ break;
+ default:
+ Dialog::handleCommand(sender, cmd, data);
+ }
+}
+
+void RemoteBrowserDialog::handleTickle() {
+ if (_updateList) {
+ updateListing();
+ _updateList = false;
+ }
+
+ Dialog::handleTickle();
+}
+
+void RemoteBrowserDialog::updateListing() {
+ // Update the path display
+ Common::String path = _node.path();
+ if (path.empty()) path = "/"; //root
+ _currentPath->setLabel(path);
+
+ if (!_navigationLocked) {
+ // Populate the ListWidget
+ ListWidget::StringArray list;
+ ListWidget::ColorList colors;
+ for (Common::Array<Cloud::StorageFile>::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) {
+ if (i->isDirectory()) {
+ list.push_back(i->name() + "/");
+ colors.push_back(ThemeEngine::kFontColorNormal);
+ } else {
+ list.push_back(i->name());
+ colors.push_back(ThemeEngine::kFontColorAlternate);
+ }
+ }
+
+ _fileList->setList(list, &colors);
+ _fileList->scrollTo(0);
+ }
+
+ _fileList->setEnabled(!_navigationLocked);
+
+ // Finally, redraw
+ draw();
+}
+
+void RemoteBrowserDialog::goUp() {
+ Common::String path = _node.path();
+ if (path.size() && (path.lastChar() == '/' || path.lastChar() == '\\')) path.deleteLastChar();
+ if (path.empty()) {
+ draw();
+ return;
+ }
+ for (int i = path.size()-1; i >= 0; --i)
+ if (path[i] == '/' || path[i] == '\\') {
+ path.erase(i);
+ break;
+ }
+ listDirectory(Cloud::StorageFile(path, 0, 0, true));
+}
+
+void RemoteBrowserDialog::listDirectory(Cloud::StorageFile node) {
+ if (_navigationLocked) return;
+ _navigationLocked = true;
+
+ _workingRequest = CloudMan.listDirectory(
+ node.path(),
+ new Common::Callback<RemoteBrowserDialog, Cloud::Storage::ListDirectoryResponse>(this, &RemoteBrowserDialog::directoryListedCallback),
+ new Common::Callback<RemoteBrowserDialog, Networking::ErrorResponse>(this, &RemoteBrowserDialog::directoryListedErrorCallback),
+ false
+ );
+
+ _node = node;
+ updateListing();
+}
+
+void RemoteBrowserDialog::directoryListedCallback(Cloud::Storage::ListDirectoryResponse response) {
+ _navigationLocked = false;
+ //TODO: list files from response
+ _nodeContent = response.value;
+ _updateList = true;
+}
+
+void RemoteBrowserDialog::directoryListedErrorCallback(Networking::ErrorResponse error) {
+ _navigationLocked = false;
+ //TODO: show error message
+}
+
+} // End of namespace GUI
diff --git a/gui/remotebrowser.h b/gui/remotebrowser.h
new file mode 100644
index 0000000000..55be1198b5
--- /dev/null
+++ b/gui/remotebrowser.h
@@ -0,0 +1,71 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef GUI_REMOTEBROWSER_DIALOG_H
+#define GUI_REMOTEBROWSER_DIALOG_H
+
+#include "gui/dialog.h"
+#include "common/fs.h"
+#include <backends/cloud/storagefile.h>
+#include <backends/networking/curl/request.h>
+#include <backends/cloud/storage.h>
+
+namespace GUI {
+
+class ListWidget;
+class StaticTextWidget;
+class CheckboxWidget;
+class CommandSender;
+
+class RemoteBrowserDialog : public Dialog {
+public:
+ RemoteBrowserDialog(const char *title, bool dirRemoteBrowser);
+
+ virtual void open();
+ virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+ virtual void handleTickle();
+
+ const Cloud::StorageFile &getResult() { return _choice; }
+
+protected:
+ ListWidget *_fileList;
+ StaticTextWidget *_currentPath;
+ Cloud::StorageFile _node;
+ Common::Array<Cloud::StorageFile> _nodeContent;
+ Cloud::StorageFile _choice;
+ bool _isDirRemoteBrowser;
+ bool _navigationLocked;
+ bool _updateList;
+
+ Networking::Request *_workingRequest;
+ bool _ignoreCallback; //?
+
+ void updateListing();
+ void goUp();
+ void listDirectory(Cloud::StorageFile node);
+ void directoryListedCallback(Cloud::Storage::ListDirectoryResponse response);
+ void directoryListedErrorCallback(Networking::ErrorResponse error);
+};
+
+} // End of namespace GUI
+
+#endif