diff options
author | Alexander Tkachev | 2016-07-04 17:11:58 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | ddb1a6ccb6238aaed599b271506a94a7c0f18844 (patch) | |
tree | 7ed9d88ad605383f043a12e62528b09e1ca73422 /backends/cloud | |
parent | b8ee9d4e7d32d0cc0dd832cbd0ffec5c5d08db34 (diff) | |
download | scummvm-rg350-ddb1a6ccb6238aaed599b271506a94a7c0f18844.tar.gz scummvm-rg350-ddb1a6ccb6238aaed599b271506a94a7c0f18844.tar.bz2 scummvm-rg350-ddb1a6ccb6238aaed599b271506a94a7c0f18844.zip |
GUI: Upgrade DownloadDialog
It now shows the remote and local directories and a progress bar.
Storage now shows OSD messages on download success and failure.
Diffstat (limited to 'backends/cloud')
-rw-r--r-- | backends/cloud/cloudmanager.cpp | 12 | ||||
-rw-r--r-- | backends/cloud/cloudmanager.h | 6 | ||||
-rw-r--r-- | backends/cloud/folderdownloadrequest.cpp | 13 | ||||
-rw-r--r-- | backends/cloud/folderdownloadrequest.h | 7 | ||||
-rw-r--r-- | backends/cloud/storage.cpp | 33 | ||||
-rw-r--r-- | backends/cloud/storage.h | 6 |
6 files changed, 71 insertions, 6 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index a1756ed5a6..dfe65e7f44 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -340,4 +340,16 @@ double CloudManager::getDownloadingProgress() { return 1; } +Common::String CloudManager::getDownloadRemoteDirectory() { + Storage *storage = getCurrentStorage(); + if (storage) return storage->getDownloadRemoteDirectory(); + return ""; +} + +Common::String CloudManager::getDownloadLocalDirectory() { + Storage *storage = getCurrentStorage(); + if (storage) return storage->getDownloadLocalDirectory(); + return ""; +} + } // End of namespace Cloud diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index 2617a9c62e..1cdbbccdb9 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -242,6 +242,12 @@ public: /** Returns a number in [0, 1] range which represents current download progress (1 = complete). */ double getDownloadingProgress(); + + /** Returns remote directory path. */ + virtual Common::String getDownloadRemoteDirectory(); + + /** Returns local directory path. */ + virtual Common::String getDownloadLocalDirectory(); }; /** Shortcut for accessing the connection manager. */ diff --git a/backends/cloud/folderdownloadrequest.cpp b/backends/cloud/folderdownloadrequest.cpp index e00f85121f..d57da6bc7f 100644 --- a/backends/cloud/folderdownloadrequest.cpp +++ b/backends/cloud/folderdownloadrequest.cpp @@ -22,17 +22,19 @@ #include "backends/cloud/folderdownloadrequest.h" #include "common/debug.h" +#include "gui/downloaddialog.h" namespace Cloud { FolderDownloadRequest::FolderDownloadRequest(Storage *storage, Storage::FileArrayCallback callback, Networking::ErrorCallback ecb, Common::String remoteDirectoryPath, Common::String localDirectoryPath, bool recursive): Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _fileArrayCallback(callback), _remoteDirectoryPath(remoteDirectoryPath), _localDirectoryPath(localDirectoryPath), _recursive(recursive), - _workingRequest(nullptr), _ignoreCallback(false) { + _workingRequest(nullptr), _ignoreCallback(false), _totalFiles(0) { start(); } FolderDownloadRequest::~FolderDownloadRequest() { + sendCommand(GUI::kDownloadEndedCmd, 0); _ignoreCallback = true; if (_workingRequest) _workingRequest->finish(); delete _fileArrayCallback; @@ -46,6 +48,7 @@ void FolderDownloadRequest::start() { _files.clear(); _failedFiles.clear(); _ignoreCallback = false; + _totalFiles = 0; //list directory first _workingRequest = _storage->listDirectory( @@ -60,6 +63,7 @@ void FolderDownloadRequest::directoryListedCallback(Storage::ListDirectoryRespon _workingRequest = nullptr; if (_ignoreCallback) return; _files = response.value; + _totalFiles = _files.size(); downloadNextFile(); } @@ -91,6 +95,8 @@ void FolderDownloadRequest::downloadNextFile() { _files.pop_back(); } while (_currentFile.isDirectory()); //TODO: may be create these directories (in case those are empty) + sendCommand(GUI::kDownloadProgressCmd, (int)(getProgress() * 100)); + Common::String remotePath = _currentFile.path(); Common::String localPath = remotePath; if (_remoteDirectoryPath == "" || remotePath.hasPrefix(_remoteDirectoryPath)) { @@ -125,6 +131,9 @@ void FolderDownloadRequest::finishDownload(Common::Array<StorageFile> &files) { if (_fileArrayCallback) (*_fileArrayCallback)(Storage::FileArrayResponse(this, files)); } -double FolderDownloadRequest::getProgress() { return 0; } //TODO +double FolderDownloadRequest::getProgress() { + if (_totalFiles == 0) return 0; + return (double)(_totalFiles - _files.size()) / (double)(_totalFiles); +} } // End of namespace Cloud diff --git a/backends/cloud/folderdownloadrequest.h b/backends/cloud/folderdownloadrequest.h index 83d3432746..41eacc2afe 100644 --- a/backends/cloud/folderdownloadrequest.h +++ b/backends/cloud/folderdownloadrequest.h @@ -39,6 +39,7 @@ class FolderDownloadRequest: public Networking::Request, public GUI::CommandSend StorageFile _currentFile; Request *_workingRequest; bool _ignoreCallback; + uint32 _totalFiles; void start(); void directoryListedCallback(Storage::ListDirectoryResponse response); @@ -56,6 +57,12 @@ public: /** Returns a number in range [0, 1], where 1 is "complete". */ double getProgress(); + + /** Returns remote directory path. */ + Common::String getRemotePath() { return _remoteDirectoryPath; } + + /** Returns local directory path. */ + Common::String getLocalPath() { return _localDirectoryPath; } }; } // End of namespace Cloud diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index a08fe11a70..4e3dc435a6 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -27,6 +27,7 @@ #include "backends/networking/curl/connectionmanager.h" #include "common/debug.h" #include "common/file.h" +#include <common/translation.h> namespace Cloud { @@ -198,7 +199,7 @@ bool Storage::startDownload(Common::String remotePath, Common::String localPath) } _downloadFolderRequest = (FolderDownloadRequest *)downloadFolder( remotePath, localPath, - new Common::Callback<Storage, Cloud::Storage::FileArrayResponse>(this, &Storage::directoryDownloadedCallback), + new Common::Callback<Storage, FileArrayResponse>(this, &Storage::directoryDownloadedCallback), new Common::Callback<Storage, Networking::ErrorResponse>(this, &Storage::directoryDownloadedErrorCallback), true ); @@ -236,12 +237,36 @@ double Storage::getDownloadingProgress() { return result; } -void Storage::directoryDownloadedCallback(Cloud::Storage::FileArrayResponse response) { +Common::String Storage::getDownloadRemoteDirectory() { + Common::String result = ""; + _runningRequestsMutex.lock(); + if (_downloadFolderRequest) + result = _downloadFolderRequest->getRemotePath(); + _runningRequestsMutex.unlock(); + return result; +} + +Common::String Storage::getDownloadLocalDirectory() { + Common::String result = ""; + _runningRequestsMutex.lock(); + if (_downloadFolderRequest) + result = _downloadFolderRequest->getLocalPath(); + _runningRequestsMutex.unlock(); + return result; +} + +void Storage::directoryDownloadedCallback(FileArrayResponse response) { _runningRequestsMutex.lock(); _downloadFolderRequest = nullptr; _runningRequestsMutex.unlock(); - //TODO: show response.value (if not empty), show message on OSD + Common::String message; + if (response.value.size()) { + message = Common::String::format(_("Download complete.\nFailed to download %u files."), response.value.size()); + } else { + message = _("Download complete."); + } + g_system->displayMessageOnOSD(message.c_str()); } void Storage::directoryDownloadedErrorCallback(Networking::ErrorResponse error) { @@ -249,7 +274,7 @@ void Storage::directoryDownloadedErrorCallback(Networking::ErrorResponse error) _downloadFolderRequest = nullptr; _runningRequestsMutex.unlock(); - //TODO: _showError = true; + g_system->displayMessageOnOSD(_("Download failed.")); } } // End of namespace Cloud diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index 28a20720b7..62b42697e6 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -198,6 +198,12 @@ public: /** Returns a number in [0, 1] range which represents current download progress (1 = complete). */ virtual double getDownloadingProgress(); + /** Returns remote directory path. */ + virtual Common::String getDownloadRemoteDirectory(); + + /** Returns local directory path. */ + virtual Common::String getDownloadLocalDirectory(); + protected: /** Finishes the download. Shows an OSD message. */ virtual void directoryDownloadedCallback(FileArrayResponse response); |