diff options
-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 | ||||
-rw-r--r-- | gui/downloaddialog.cpp | 53 | ||||
-rw-r--r-- | gui/downloaddialog.h | 14 | ||||
-rw-r--r-- | gui/themes/scummmodern/scummmodern_layout.stx | 14 | ||||
-rw-r--r-- | gui/themes/scummmodern/scummmodern_layout_lowres.stx | 14 |
10 files changed, 159 insertions, 13 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); diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index ac3b3d3c72..28a29fcb64 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -38,7 +38,7 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _reflow(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -46,14 +46,35 @@ DownloadDialog::DownloadDialog(uint32 storageId): _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); + _remoteDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.RemoteDirectory", _("From: ")); + _localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: ")); + uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); + _progressBar = new SliderWidget(this, "GlobalOptions_Cloud_DownloadDialog.ProgressBar"); + _progressBar->setMinValue(0); + _progressBar->setMaxValue(100); + _progressBar->setValue(progress); + _progressBar->setEnabled(false); + _percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress)); _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); updateButtons(); + + CloudMan.setDownloadTarget(this); +} + +DownloadDialog::~DownloadDialog() { + CloudMan.setDownloadTarget(nullptr); +} + +void DownloadDialog::close() { + CloudMan.setDownloadTarget(nullptr); + Dialog::close(); } void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kDownloadDialogButtonCmd: { if (CloudMan.isDownloading()) { + CloudMan.setDownloadTarget(nullptr); CloudMan.cancelDownload(); } else { selectDirectories(); @@ -63,6 +84,14 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat draw(); break; } + case kDownloadProgressCmd: + _percentLabel->setLabel(Common::String::format("%u %%", data)); + _progressBar->setValue(data); + _reflow = true; + break; + case kDownloadEndedCmd: + _reflow = true; + break; default: Dialog::handleCommand(sender, cmd, data); } @@ -117,12 +146,14 @@ void DownloadDialog::selectDirectories() { else localPath += '/' + remoteDirectory.name(); CloudMan.startDownload(remoteDirectory.path(), localPath); + CloudMan.setDownloadTarget(this); } void DownloadDialog::handleTickle() { - if (_close) { - setResult(1); - close(); + if (_reflow) { + reflowLayout(); + draw(); + _reflow = false; } Dialog::handleTickle(); @@ -133,14 +164,24 @@ void DownloadDialog::reflowLayout() { updateButtons(); } -void DownloadDialog::updateButtons() { - if (CloudMan.isDownloading()) { +void DownloadDialog::updateButtons() { + bool downloading = CloudMan.isDownloading(); + if (downloading) { _messageText->setLabel(_("Press the button to cancel the download")); _mainButton->setLabel(_("Cancel the download")); + _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); + _localDirectoryLabel->setLabel(_("To: ") + CloudMan.getDownloadLocalDirectory()); + uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); + _percentLabel->setLabel(Common::String::format("%u %%", progress)); + _progressBar->setValue(progress); } else { _messageText->setLabel(_("Press the button to download a directory")); _mainButton->setLabel(_("Start download")); } + _remoteDirectoryLabel->setVisible(downloading); + _localDirectoryLabel->setVisible(downloading); + _percentLabel->setVisible(downloading); + _progressBar->setVisible(downloading); } } // End of namespace GUI diff --git a/gui/downloaddialog.h b/gui/downloaddialog.h index 508e91adcb..429e20af98 100644 --- a/gui/downloaddialog.h +++ b/gui/downloaddialog.h @@ -33,25 +33,37 @@ class CommandSender; class EditTextWidget; class StaticTextWidget; class ButtonWidget; +class SliderWidget; class BrowserDialog; class RemoteBrowserDialog; +enum DownloadProgress { + kDownloadProgressCmd = 'DLPR', + kDownloadEndedCmd = 'DLEN' +}; + class DownloadDialog : public Dialog { BrowserDialog *_browser; RemoteBrowserDialog *_remoteBrowser; StaticTextWidget *_messageText; ButtonWidget *_mainButton; + StaticTextWidget *_remoteDirectoryLabel; + StaticTextWidget *_localDirectoryLabel; + StaticTextWidget *_percentLabel; + SliderWidget *_progressBar; ButtonWidget *_closeButton; - bool _close; + bool _reflow; void updateButtons(); void selectDirectories(); public: DownloadDialog(uint32 storageId); + virtual ~DownloadDialog(); + virtual void close(); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); virtual void handleTickle(); virtual void reflowLayout(); diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx index f9ec30b81b..e6493ba160 100644 --- a/gui/themes/scummmodern/scummmodern_layout.stx +++ b/gui/themes/scummmodern/scummmodern_layout.stx @@ -594,6 +594,20 @@ <widget name = 'MainButton' type = 'Button' /> + <widget name = 'RemoteDirectory' + height = 'Globals.Line.Height' + /> + <widget name = 'LocalDirectory' + height = 'Globals.Line.Height' + /> + <widget name = 'ProgressBar' + height = 'Globals.Button.Height' + /> + <space size = '1'/> + <widget name = 'PercentText' + height = 'Globals.Line.Height' + textalign = 'center' + /> <space/> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10'> <space/> diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx index fe15dc2410..ab78d3aee1 100644 --- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx +++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx @@ -591,6 +591,20 @@ <widget name = 'MainButton' type = 'Button' /> + <widget name = 'RemoteDirectory' + height = 'Globals.Line.Height' + /> + <widget name = 'LocalDirectory' + height = 'Globals.Line.Height' + /> + <widget name = 'ProgressBar' + height = 'Globals.Button.Height' + /> + <space size = '1'/> + <widget name = 'PercentText' + height = 'Globals.Line.Height' + textalign = 'center' + /> <space/> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6'> <space/> |