diff options
author | Alexander Tkachev | 2016-06-08 18:51:00 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 870e96eb9ca6e69bea5f47a215d171fd58ab1265 (patch) | |
tree | 57516a6cc7bf5f2c6912e15b5ad4045c4b151c9e | |
parent | 1479d126520a9f3472797c1bb98b534f0b2a6b97 (diff) | |
download | scummvm-rg350-870e96eb9ca6e69bea5f47a215d171fd58ab1265.tar.gz scummvm-rg350-870e96eb9ca6e69bea5f47a215d171fd58ab1265.tar.bz2 scummvm-rg350-870e96eb9ca6e69bea5f47a215d171fd58ab1265.zip |
CLOUD: Update CloudManager and Storage
* Storage::name();
* CloudManager::getStorageName();
* CloudManager::getStorageIndex();
* CloudManager::listStorages();
* CloudManager::switchStorage().
-rw-r--r-- | backends/cloud/cloudmanager.cpp | 38 | ||||
-rw-r--r-- | backends/cloud/cloudmanager.h | 31 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 4 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.h | 6 | ||||
-rw-r--r-- | backends/cloud/googledrive/googledrivestorage.cpp | 4 | ||||
-rw-r--r-- | backends/cloud/googledrive/googledrivestorage.h | 6 | ||||
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.cpp | 4 | ||||
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.h | 6 | ||||
-rw-r--r-- | backends/cloud/storage.h | 6 |
9 files changed, 103 insertions, 2 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index 7613b2cbbf..a9baac5d02 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -26,6 +26,7 @@ #include "backends/cloud/googledrive/googledrivestorage.h" #include "common/config-manager.h" #include "common/debug.h" +#include "common/translation.h" namespace Common { @@ -106,12 +107,47 @@ void CloudManager::addStorage(Storage *storage, bool makeCurrent, bool saveConfi if (saveConfig) save(); } -Storage *CloudManager::getCurrentStorage() { +Storage *CloudManager::getCurrentStorage() const { if (_currentStorageIndex < _storages.size()) return _storages[_currentStorageIndex]; return nullptr; } +Common::String CloudManager::getStorageName() const { + Storage *storage = getCurrentStorage(); + if (storage) return storage->name(); + return _("No active storage"); +} + +uint32 CloudManager::getStorageIndex() const { + return _currentStorageIndex; +} + +Common::StringArray CloudManager::listStorages() const { + Common::StringArray result; + for (uint32 i = 0; i < _storages.size(); ++i) { + result.push_back(_storages[i]->name()); + } + return result; +} + +bool CloudManager::switchStorage(uint32 index) { + if (index < 0 || index > _storages.size()) { + warning("CloudManager::switchStorage: invalid index passed"); + return false; + } + + Storage *storage = getCurrentStorage(); + if (storage && storage->isWorking()) { + warning("CloudManager::switchStorage: another storage is working now"); + return false; + } + + _currentStorageIndex = index; + save(); + return true; +} + void CloudManager::printBool(Storage::BoolResponse response) const { debug("bool = %s", (response.value ? "true" : "false")); } diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index dbff0184eb..7e8cfd68a3 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -26,6 +26,7 @@ #include "backends/cloud/storage.h" #include "common/array.h" #include "common/singleton.h" +#include <cge/console.h> namespace GUI { @@ -72,7 +73,35 @@ public: * * @return active Cloud::Storage or null, if there is no active Storage. */ - Cloud::Storage *getCurrentStorage(); + Cloud::Storage *getCurrentStorage() const; + + /** + * Return active Storage's name. + * + * @return active Storage's or _("No active storage"), if there is no active Storage. + */ + Common::String getStorageName() const; + + /** + * Return active Storage's index. + * + * @return active Storage's index. + */ + uint32 getStorageIndex() const; + + /** + * Return Storages names as list. + * + * @return a list of Storages names. + */ + Common::StringArray listStorages() const; + + /** + * Changes the storage to the one with given index. + * + * @param new Storage's index. + */ + bool switchStorage(uint32 index); /** * Starts saves syncing process in currently active storage if there is any. diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 038a1683bf..d11d97da39 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -91,6 +91,10 @@ void DropboxStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "user_id", _uid, "cloud"); } +Common::String DropboxStorage::name() const { + return "Dropbox"; +} + void DropboxStorage::printFiles(FileArrayResponse response) { debug("files:"); Common::Array<StorageFile> &files = response.value; diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h index 9ac0ffb166..60a8075201 100644 --- a/backends/cloud/dropbox/dropboxstorage.h +++ b/backends/cloud/dropbox/dropboxstorage.h @@ -65,6 +65,12 @@ public: */ virtual void saveConfig(Common::String keyPrefix); + /** + * Return unique storage name. + * @returns some unique storage name (for example, "Dropbox (user@example.com)") + */ + virtual Common::String name() const; + /** Public Cloud API comes down there. */ /** Returns ListDirectoryStatus struct with list of files. */ diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index bb762a4d90..30ca1be7e6 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -134,6 +134,10 @@ void GoogleDriveStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "refresh_token", _refreshToken, "cloud"); } +Common::String GoogleDriveStorage::name() const { + return "Google Drive"; +} + namespace { uint64 atoull(Common::String s) { uint64 result = 0; diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h index 2af1edea3c..489260db09 100644 --- a/backends/cloud/googledrive/googledrivestorage.h +++ b/backends/cloud/googledrive/googledrivestorage.h @@ -77,6 +77,12 @@ public: */ virtual void saveConfig(Common::String keyPrefix); + /** + * Return unique storage name. + * @returns some unique storage name (for example, "Dropbox (user@example.com)") + */ + virtual Common::String name() const; + /** Public Cloud API comes down there. */ /** Returns StorageFile with the resolved file's id. */ diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index c494f38a6c..c391065396 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -128,6 +128,10 @@ void OneDriveStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "refresh_token", _refreshToken, "cloud"); } +Common::String OneDriveStorage::name() const { + return "OneDrive"; +} + void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse response) { Common::JSONValue *json = response.value; if (!json) { diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h index 8afdac8b0f..3932d44aae 100644 --- a/backends/cloud/onedrive/onedrivestorage.h +++ b/backends/cloud/onedrive/onedrivestorage.h @@ -75,6 +75,12 @@ public: */ virtual void saveConfig(Common::String keyPrefix); + /** + * Return unique storage name. + * @returns some unique storage name (for example, "Dropbox (user@example.com)") + */ + virtual Common::String name() const; + /** Public Cloud API comes down there. */ /** Returns ListDirectoryStatus struct with list of files. */ diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index 4a5e1236b7..11d8f6beb9 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -103,6 +103,12 @@ public: virtual void saveConfig(Common::String keyPrefix) = 0; /** + * Return unique storage name. + * @returns some unique storage name (for example, "Dropbox (user@example.com)") + */ + virtual Common::String name() const = 0; + + /** * Public Cloud API comes down there. * * All Cloud API methods return Networking::Request *, which |