aboutsummaryrefslogtreecommitdiff
path: root/gui/downloaddialog.cpp
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/downloaddialog.cpp
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/downloaddialog.cpp')
-rw-r--r--gui/downloaddialog.cpp71
1 files changed, 59 insertions, 12 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