aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-04 15:34:02 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit71a326493b351b845ea800ae88495238b1a61066 (patch)
tree10c2728d5a46016658996c4f4400f6ba93591548 /gui
parent10250af2516c8f7d41cc79e3c55b59f2eeecfa92 (diff)
downloadscummvm-rg350-71a326493b351b845ea800ae88495238b1a61066.tar.gz
scummvm-rg350-71a326493b351b845ea800ae88495238b1a61066.tar.bz2
scummvm-rg350-71a326493b351b845ea800ae88495238b1a61066.zip
GUI: Initiate download in DownloadDialog
Diffstat (limited to 'gui')
-rw-r--r--gui/downloaddialog.cpp71
-rw-r--r--gui/downloaddialog.h9
2 files changed, 67 insertions, 13 deletions
diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp
index 34eddbe395..d4c44e53ff 100644
--- a/gui/downloaddialog.cpp
+++ b/gui/downloaddialog.cpp
@@ -38,7 +38,8 @@ enum {
};
DownloadDialog::DownloadDialog(uint32 storageId):
- Dialog("GlobalOptions_Cloud_DownloadDialog"), _wasInProgress(true), _inProgress(false), _close(false) {
+ Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false),
+ _workingRequest(nullptr), _ignoreCallback(false) {
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
_browser = new BrowserDialog(_("Select directory where to download game data"), true);
@@ -50,15 +51,35 @@ DownloadDialog::DownloadDialog(uint32 storageId):
updateButtons();
}
+DownloadDialog::~DownloadDialog() {
+ if (_workingRequest) {
+ _ignoreCallback = true;
+ _workingRequest->finish();
+ }
+}
+
+void DownloadDialog::close() {
+ if (_workingRequest) {
+ _ignoreCallback = true;
+ _workingRequest->finish();
+ _ignoreCallback = false;
+ }
+ Dialog::close();
+}
+
void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kDownloadDialogButtonCmd: {
- if (!_inProgress) {
+ if (_workingRequest == nullptr) {
selectDirectories();
+ } else {
+ _ignoreCallback = true;
+ _workingRequest->finish();
+ _ignoreCallback = false;
}
- _inProgress = !_inProgress;
reflowLayout();
+ draw();
break;
}
default:
@@ -102,7 +123,38 @@ void DownloadDialog::selectDirectories() {
}
}
- //TODO: initiate download
+ //make a local path
+ Common::String localPath = dir.getPath();
+
+ //simple heuristic to determine which path separator to use
+ int backslashes = 0;
+ for (uint32 i = 0; i < localPath.size(); ++i)
+ if (localPath[i] == '/') --backslashes;
+ else if (localPath[i] == '\\') ++backslashes;
+
+ if (backslashes > 0) localPath += '\\' + remoteDirectory.name();
+ else localPath += '/' + remoteDirectory.name();
+
+ _workingRequest = CloudMan.downloadFolder(
+ remoteDirectory.path(), localPath,
+ new Common::Callback<DownloadDialog, Cloud::Storage::FileArrayResponse>(this, &DownloadDialog::directoryDownloadedCallback),
+ new Common::Callback<DownloadDialog, Networking::ErrorResponse>(this, &DownloadDialog::directoryDownloadedErrorCallback),
+ true
+ );
+}
+
+void DownloadDialog::directoryDownloadedCallback(Cloud::Storage::FileArrayResponse response) {
+ _workingRequest = nullptr;
+ if (_ignoreCallback) return;
+
+ //TODO: show response.value (if not empty), show message on OSD
+}
+
+void DownloadDialog::directoryDownloadedErrorCallback(Networking::ErrorResponse error) {
+ _workingRequest = nullptr;
+ if (_ignoreCallback) return;
+
+ //TODO: _showError = true;
}
void DownloadDialog::handleTickle() {
@@ -119,19 +171,14 @@ void DownloadDialog::reflowLayout() {
updateButtons();
}
-void DownloadDialog::updateButtons() {
- if (_wasInProgress == _inProgress) return;
-
- if (_inProgress) {
+void DownloadDialog::updateButtons() {
+ if (_workingRequest != nullptr) {
_messageText->setLabel(_("Press the button to cancel the download"));
_mainButton->setLabel(_("Cancel the download"));
} else {
_messageText->setLabel(_("Press the button to download a directory"));
_mainButton->setLabel(_("Start download"));
- }
-
- _wasInProgress = _inProgress;
+ }
}
-
} // End of namespace GUI
diff --git a/gui/downloaddialog.h b/gui/downloaddialog.h
index ca702ef927..6836b38bb5 100644
--- a/gui/downloaddialog.h
+++ b/gui/downloaddialog.h
@@ -25,6 +25,7 @@
#include "gui/dialog.h"
#include "common/str.h"
+#include <backends/cloud/storage.h>
namespace GUI {
@@ -43,15 +44,21 @@ class DownloadDialog : public Dialog {
ButtonWidget *_mainButton;
ButtonWidget *_closeButton;
- bool _wasInProgress, _inProgress;
bool _close;
+ Networking::Request *_workingRequest;
+ bool _ignoreCallback;
+
void updateButtons();
void selectDirectories();
+ void directoryDownloadedCallback(Cloud::Storage::FileArrayResponse response);
+ void directoryDownloadedErrorCallback(Networking::ErrorResponse error);
public:
DownloadDialog(uint32 storageId);
+ virtual ~DownloadDialog();
+ virtual void close();
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual void handleTickle();
virtual void reflowLayout();