diff options
author | Alexander Tkachev | 2016-07-04 16:14:30 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | b8ee9d4e7d32d0cc0dd832cbd0ffec5c5d08db34 (patch) | |
tree | 8394f3ff0b9e272acd8840df82c56f316698e129 /backends | |
parent | 71a326493b351b845ea800ae88495238b1a61066 (diff) | |
download | scummvm-rg350-b8ee9d4e7d32d0cc0dd832cbd0ffec5c5d08db34.tar.gz scummvm-rg350-b8ee9d4e7d32d0cc0dd832cbd0ffec5c5d08db34.tar.bz2 scummvm-rg350-b8ee9d4e7d32d0cc0dd832cbd0ffec5c5d08db34.zip |
CLOUD: Add FolderDownload-related methods in Storage
CloudManager's shortcuts are added too.
The idea is to keep FolderDownload request within Storage, and provide
necessary means to access it. The download is started and cancelled
through the DownloadDialog.
Diffstat (limited to 'backends')
-rw-r--r-- | backends/cloud/cloudmanager.cpp | 32 | ||||
-rw-r--r-- | backends/cloud/cloudmanager.h | 19 | ||||
-rw-r--r-- | backends/cloud/folderdownloadrequest.cpp | 4 | ||||
-rw-r--r-- | backends/cloud/folderdownloadrequest.h | 8 | ||||
-rw-r--r-- | backends/cloud/storage.cpp | 71 | ||||
-rw-r--r-- | backends/cloud/storage.h | 28 |
6 files changed, 158 insertions, 4 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index 68c7e9aa8a..a1756ed5a6 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -274,6 +274,8 @@ bool CloudManager::isWorking() { return false; } +///// SavesSyncRequest-related ///// + bool CloudManager::isSyncing() { Storage *storage = getCurrentStorage(); if (storage) return storage->isSyncing(); @@ -308,4 +310,34 @@ void CloudManager::setSyncTarget(GUI::CommandReceiver *target) { if (storage) storage->setSyncTarget(target); } +///// DownloadFolderRequest-related ///// + +bool CloudManager::startDownload(Common::String remotePath, Common::String localPath) { + Storage *storage = getCurrentStorage(); + if (storage) return storage->startDownload(remotePath, localPath); + return false; +} + +void CloudManager::cancelDownload() { + Storage *storage = getCurrentStorage(); + if (storage) storage->cancelDownload(); +} + +void CloudManager::setDownloadTarget(GUI::CommandReceiver *target) { + Storage *storage = getCurrentStorage(); + if (storage) storage->setDownloadTarget(target); +} + +bool CloudManager::isDownloading() { + Storage *storage = getCurrentStorage(); + if (storage) return storage->isDownloading(); + return false; +} + +double CloudManager::getDownloadingProgress() { + Storage *storage = getCurrentStorage(); + if (storage) return storage->getDownloadingProgress(); + return 1; +} + } // End of namespace Cloud diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index 574c51a439..2617a9c62e 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -206,6 +206,8 @@ public: /** Returns whether there are any requests running. */ bool isWorking(); + ///// SavesSyncRequest-related ///// + /** Returns whether there is a SavesSyncRequest running. */ bool isSyncing(); @@ -223,6 +225,23 @@ public: /** Sets SavesSyncRequest's target to given CommandReceiver. */ void setSyncTarget(GUI::CommandReceiver *target); + + ///// DownloadFolderRequest-related ///// + + /** Starts a folder download. */ + bool startDownload(Common::String remotePath, Common::String localPath); + + /** Cancels running download. */ + void cancelDownload(); + + /** Sets FolderDownloadRequest's target to given CommandReceiver. */ + void setDownloadTarget(GUI::CommandReceiver *target); + + /** Returns whether there is a FolderDownloadRequest running. */ + bool isDownloading(); + + /** Returns a number in [0, 1] range which represents current download progress (1 = complete). */ + double getDownloadingProgress(); }; /** Shortcut for accessing the connection manager. */ diff --git a/backends/cloud/folderdownloadrequest.cpp b/backends/cloud/folderdownloadrequest.cpp index 83296c3d15..e00f85121f 100644 --- a/backends/cloud/folderdownloadrequest.cpp +++ b/backends/cloud/folderdownloadrequest.cpp @@ -26,7 +26,7 @@ namespace Cloud { FolderDownloadRequest::FolderDownloadRequest(Storage *storage, Storage::FileArrayCallback callback, Networking::ErrorCallback ecb, Common::String remoteDirectoryPath, Common::String localDirectoryPath, bool recursive): - Request(nullptr, ecb), _storage(storage), _fileArrayCallback(callback), + Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _fileArrayCallback(callback), _remoteDirectoryPath(remoteDirectoryPath), _localDirectoryPath(localDirectoryPath), _recursive(recursive), _workingRequest(nullptr), _ignoreCallback(false) { start(); @@ -125,4 +125,6 @@ void FolderDownloadRequest::finishDownload(Common::Array<StorageFile> &files) { if (_fileArrayCallback) (*_fileArrayCallback)(Storage::FileArrayResponse(this, files)); } +double FolderDownloadRequest::getProgress() { return 0; } //TODO + } // End of namespace Cloud diff --git a/backends/cloud/folderdownloadrequest.h b/backends/cloud/folderdownloadrequest.h index bf55567b2d..83d3432746 100644 --- a/backends/cloud/folderdownloadrequest.h +++ b/backends/cloud/folderdownloadrequest.h @@ -26,10 +26,11 @@ #include "backends/networking/curl/request.h" #include "backends/networking/curl/networkreadstream.h" #include "backends/cloud/storage.h" +#include "gui/object.h" namespace Cloud { -class FolderDownloadRequest: public Networking::Request { +class FolderDownloadRequest: public Networking::Request, public GUI::CommandSender { Storage *_storage; Storage::FileArrayCallback _fileArrayCallback; Common::String _remoteDirectoryPath, _localDirectoryPath; @@ -51,7 +52,10 @@ public: virtual ~FolderDownloadRequest(); virtual void handle(); - virtual void restart(); + virtual void restart(); + + /** Returns a number in range [0, 1], where 1 is "complete". */ + double getProgress(); }; } // End of namespace Cloud diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index b98f213327..a08fe11a70 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -30,7 +30,9 @@ namespace Cloud { -Storage::Storage(): _runningRequestsCount(0), _savesSyncRequest(nullptr) {} +Storage::Storage(): + _runningRequestsCount(0), _savesSyncRequest(nullptr), _syncRestartRequestsed(false), + _downloadFolderRequest(nullptr) {} Storage::~Storage() {} @@ -135,6 +137,8 @@ bool Storage::isWorking() { return working; } +///// SavesSyncRequest-related ///// + bool Storage::isSyncing() { _runningRequestsMutex.lock(); bool syncing = _savesSyncRequest != nullptr; @@ -183,5 +187,70 @@ void Storage::setSyncTarget(GUI::CommandReceiver *target) { _runningRequestsMutex.unlock(); } +///// DownloadFolderRequest-related ///// + +bool Storage::startDownload(Common::String remotePath, Common::String localPath) { + _runningRequestsMutex.lock(); + if (_downloadFolderRequest) { + warning("Storage::startDownload: there is a download in progress already"); + _runningRequestsMutex.unlock(); + return false; + } + _downloadFolderRequest = (FolderDownloadRequest *)downloadFolder( + remotePath, localPath, + new Common::Callback<Storage, Cloud::Storage::FileArrayResponse>(this, &Storage::directoryDownloadedCallback), + new Common::Callback<Storage, Networking::ErrorResponse>(this, &Storage::directoryDownloadedErrorCallback), + true + ); + _runningRequestsMutex.unlock(); + return true; +} + +void Storage::cancelDownload() { + _runningRequestsMutex.lock(); + if (_downloadFolderRequest) + _downloadFolderRequest->finish(); + _runningRequestsMutex.unlock(); +} + +void Storage::setDownloadTarget(GUI::CommandReceiver *target) { + _runningRequestsMutex.lock(); + if (_downloadFolderRequest) + _downloadFolderRequest->setTarget(target); + _runningRequestsMutex.unlock(); +} + +bool Storage::isDownloading() { + _runningRequestsMutex.lock(); + bool syncing = _downloadFolderRequest != nullptr; + _runningRequestsMutex.unlock(); + return syncing; +} + +double Storage::getDownloadingProgress() { + double result = 1; + _runningRequestsMutex.lock(); + if (_downloadFolderRequest) + result = _downloadFolderRequest->getProgress(); + _runningRequestsMutex.unlock(); + return result; +} + +void Storage::directoryDownloadedCallback(Cloud::Storage::FileArrayResponse response) { + _runningRequestsMutex.lock(); + _downloadFolderRequest = nullptr; + _runningRequestsMutex.unlock(); + + //TODO: show response.value (if not empty), show message on OSD +} + +void Storage::directoryDownloadedErrorCallback(Networking::ErrorResponse error) { + _runningRequestsMutex.lock(); + _downloadFolderRequest = nullptr; + _runningRequestsMutex.unlock(); + + //TODO: _showError = true; +} + } // End of namespace Cloud diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index ace2f30864..28a20720b7 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -42,6 +42,7 @@ class CommandReceiver; namespace Cloud { class SavesSyncRequest; +class FolderDownloadRequest; class Storage { public: @@ -63,6 +64,7 @@ protected: Common::Mutex _runningRequestsMutex; SavesSyncRequest *_savesSyncRequest; bool _syncRestartRequestsed; + FolderDownloadRequest *_downloadFolderRequest; /** Returns default error callback (printErrorResponse). */ virtual Networking::ErrorCallback getErrorPrintingCallback(); @@ -159,6 +161,8 @@ public: /** Returns whether there are any requests running. */ virtual bool isWorking(); + ///// SavesSyncRequest-related ///// + /** Returns whether there is a SavesSyncRequest running. */ virtual bool isSyncing(); @@ -176,6 +180,30 @@ public: /** Sets SavesSyncRequest's target to given CommandReceiver. */ virtual void setSyncTarget(GUI::CommandReceiver *target); + + ///// DownloadFolderRequest-related ///// + + /** Starts a folder download. */ + virtual bool startDownload(Common::String remotePath, Common::String localPath); + + /** Cancels running download. */ + virtual void cancelDownload(); + + /** Sets FolderDownloadRequest's target to given CommandReceiver. */ + virtual void setDownloadTarget(GUI::CommandReceiver *target); + + /** Returns whether there is a FolderDownloadRequest running. */ + virtual bool isDownloading(); + + /** Returns a number in [0, 1] range which represents current download progress (1 = complete). */ + virtual double getDownloadingProgress(); + +protected: + /** Finishes the download. Shows an OSD message. */ + virtual void directoryDownloadedCallback(FileArrayResponse response); + + /** Finishes the download. Shows an OSD message. */ + virtual void directoryDownloadedErrorCallback(Networking::ErrorResponse error); }; } // End of namespace Cloud |