diff options
author | Alexander Tkachev | 2019-07-27 22:44:15 +0700 |
---|---|---|
committer | Matan Bareket | 2019-07-30 14:51:41 -0400 |
commit | f6a17e679f4fac2fda21dc7f64565a0dc4a10ca1 (patch) | |
tree | 115b53d284e100ae04914ac90c1a4823ef95fb4f | |
parent | 85431c39bf191725910703f699fe95da595f6adf (diff) | |
download | scummvm-rg350-f6a17e679f4fac2fda21dc7f64565a0dc4a10ca1.tar.gz scummvm-rg350-f6a17e679f4fac2fda21dc7f64565a0dc4a10ca1.tar.bz2 scummvm-rg350-f6a17e679f4fac2fda21dc7f64565a0dc4a10ca1.zip |
CLOUD: Ask user to manually enable Storage
For more security, newly connected Storage only gets username/used space
information and is disabled until user manually presses the button.
27 files changed, 241 insertions, 53 deletions
diff --git a/backends/cloud/basestorage.cpp b/backends/cloud/basestorage.cpp index ea54a97fd9..074c8596ec 100644 --- a/backends/cloud/basestorage.cpp +++ b/backends/cloud/basestorage.cpp @@ -32,8 +32,10 @@ namespace Cloud { BaseStorage::BaseStorage() {} -BaseStorage::BaseStorage(Common::String token, Common::String refreshToken): - _token(token), _refreshToken(refreshToken) {} +BaseStorage::BaseStorage(Common::String token, Common::String refreshToken, bool enabled): + _token(token), _refreshToken(refreshToken) { + _isEnabled = enabled; +} BaseStorage::~BaseStorage() {} @@ -212,4 +214,20 @@ void BaseStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse delete callback; } +void BaseStorage::saveIsEnabledFlag(const Common::String &keyPrefix) const { + ConfMan.set(keyPrefix + "enabled", _isEnabled ? "true" : "false", ConfMan.kCloudDomain); +} + +bool BaseStorage::loadIsEnabledFlag(const Common::String &keyPrefix) { + if (!ConfMan.hasKey(keyPrefix + "enabled", ConfMan.kCloudDomain)) + return false; + + Common::String enabled = ConfMan.get(keyPrefix + "enabled", ConfMan.kCloudDomain); + return (enabled == "true"); +} + +void BaseStorage::removeIsEnabledFlag(const Common::String &keyPrefix) { + ConfMan.removeKey(keyPrefix + "enabled", ConfMan.kCloudDomain); +} + } // End of namespace Cloud diff --git a/backends/cloud/basestorage.h b/backends/cloud/basestorage.h index aae1a6ec2f..de287fcba3 100644 --- a/backends/cloud/basestorage.h +++ b/backends/cloud/basestorage.h @@ -77,9 +77,19 @@ protected: private: void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response); +protected: + /** Helper function to save Storage::_isEnabled into config. */ + void saveIsEnabledFlag(const Common::String &keyPrefix) const; + + /** Helper function to load Storage::_isEnabled value from config. */ + static bool loadIsEnabledFlag(const Common::String &keyPrefix); + + /** Helper function to remove Storage::_isEnabled from config. */ + static void removeIsEnabledFlag(const Common::String &keyPrefix); + public: BaseStorage(); - BaseStorage(Common::String token, Common::String refreshToken); + BaseStorage(Common::String token, Common::String refreshToken, bool enabled = false); virtual ~BaseStorage(); /** diff --git a/backends/cloud/box/boxstorage.cpp b/backends/cloud/box/boxstorage.cpp index 13046a08e0..46af2e56be 100644 --- a/backends/cloud/box/boxstorage.cpp +++ b/backends/cloud/box/boxstorage.cpp @@ -42,8 +42,8 @@ namespace Box { #define BOX_API_FILES_CONTENT "https://api.box.com/2.0/files/%s/content" #define BOX_API_USERS_ME "https://api.box.com/2.0/users/me" -BoxStorage::BoxStorage(Common::String token, Common::String refreshToken): - IdStorage(token, refreshToken) {} +BoxStorage::BoxStorage(Common::String token, Common::String refreshToken, bool enabled): + IdStorage(token, refreshToken, enabled) {} BoxStorage::BoxStorage(Common::String code, Networking::ErrorCallback cb) { getAccessToken(code, cb); @@ -62,6 +62,7 @@ bool BoxStorage::canReuseRefreshToken() { return false; } void BoxStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain); + saveIsEnabledFlag(keyPrefix); } Common::String BoxStorage::name() const { @@ -224,12 +225,13 @@ BoxStorage *BoxStorage::loadFromConfig(Common::String keyPrefix) { Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); Common::String refreshToken = ConfMan.get(keyPrefix + "refresh_token", ConfMan.kCloudDomain); - return new BoxStorage(accessToken, refreshToken); + return new BoxStorage(accessToken, refreshToken, loadIsEnabledFlag(keyPrefix)); } void BoxStorage::removeFromConfig(Common::String keyPrefix) { ConfMan.removeKey(keyPrefix + "access_token", ConfMan.kCloudDomain); ConfMan.removeKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain); + removeIsEnabledFlag(keyPrefix); } Common::String BoxStorage::getRootDirectoryId() { diff --git a/backends/cloud/box/boxstorage.h b/backends/cloud/box/boxstorage.h index ce77192bfa..1916c88449 100644 --- a/backends/cloud/box/boxstorage.h +++ b/backends/cloud/box/boxstorage.h @@ -31,7 +31,7 @@ namespace Box { class BoxStorage: public Id::IdStorage { /** This private constructor is called from loadFromConfig(). */ - BoxStorage(Common::String token, Common::String refreshToken); + BoxStorage(Common::String token, Common::String refreshToken, bool enabled); /** Constructs StorageInfo based on JSON response from cloud. */ void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json); diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index a3e9856455..38089db0e9 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -159,7 +159,6 @@ void CloudManager::replaceStorage(Storage *storage, uint32 index) { //do what should be done on first Storage connect if (_activeStorage) { _activeStorage->info(nullptr, nullptr); //automatically calls setStorageUsername() - _activeStorage->syncSaves(nullptr, nullptr); } } @@ -365,6 +364,21 @@ bool CloudManager::canSyncFilename(const Common::String &filename) const { return true; } +bool CloudManager::isStorageEnabled() const { + Storage *storage = getCurrentStorage(); + if (storage) + return storage->isEnabled(); + return false; +} + +void CloudManager::enableStorage() { + Storage *storage = getCurrentStorage(); + if (storage) { + storage->enable(); + save(); + } +} + SavesSyncRequest *CloudManager::syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback) { Storage *storage = getCurrentStorage(); if (storage) { diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index ebcc6ea5cf..2d6c0bad43 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -230,6 +230,12 @@ public: /** Returns whether given filename could be uploaded to or downloaded from storage. */ bool canSyncFilename(const Common::String &filename) const; + /** Returns whether current Storage is manually enabled by user (or false, if there is no active Storage). */ + bool isStorageEnabled() const; + + /** Sets Storage::_isEnabled to true and updates the config. */ + void enableStorage(); + /** * 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 5d8b9e0425..7edc609969 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -40,7 +40,7 @@ namespace Dropbox { #define DROPBOX_API_FILES_DOWNLOAD "https://content.dropboxapi.com/2/files/download" -DropboxStorage::DropboxStorage(Common::String accessToken, bool unused): BaseStorage(accessToken, "") {} +DropboxStorage::DropboxStorage(Common::String accessToken, bool enabled): BaseStorage(accessToken, "", enabled) {} DropboxStorage::DropboxStorage(Common::String code, Networking::ErrorCallback cb): BaseStorage() { getAccessToken(code, cb); @@ -58,6 +58,7 @@ bool DropboxStorage::canReuseRefreshToken() { return false; } void DropboxStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); + saveIsEnabledFlag(keyPrefix); } Common::String DropboxStorage::name() const { @@ -108,12 +109,13 @@ DropboxStorage *DropboxStorage::loadFromConfig(Common::String keyPrefix) { return nullptr; } - Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); - return new DropboxStorage(accessToken, true); + Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); + return new DropboxStorage(accessToken, loadIsEnabledFlag(keyPrefix)); } void DropboxStorage::removeFromConfig(Common::String keyPrefix) { ConfMan.removeKey(keyPrefix + "access_token", ConfMan.kCloudDomain); + removeIsEnabledFlag(keyPrefix); } } // End of namespace Dropbox diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h index 0b76bb5c4a..c6a1374357 100644 --- a/backends/cloud/dropbox/dropboxstorage.h +++ b/backends/cloud/dropbox/dropboxstorage.h @@ -32,7 +32,7 @@ namespace Dropbox { class DropboxStorage: public Cloud::BaseStorage { /** This private constructor is called from loadFromConfig(). */ - DropboxStorage(Common::String token, bool unused); + DropboxStorage(Common::String token, bool enabled); protected: /** diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index a6e17e6ad3..2049d808c4 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -43,8 +43,8 @@ namespace GoogleDrive { #define GOOGLEDRIVE_API_FILES "https://www.googleapis.com/drive/v3/files" #define GOOGLEDRIVE_API_ABOUT "https://www.googleapis.com/drive/v3/about?fields=storageQuota,user" -GoogleDriveStorage::GoogleDriveStorage(Common::String token, Common::String refreshToken): - IdStorage(token, refreshToken) {} +GoogleDriveStorage::GoogleDriveStorage(Common::String token, Common::String refreshToken, bool enabled): + IdStorage(token, refreshToken, enabled) {} GoogleDriveStorage::GoogleDriveStorage(Common::String code, Networking::ErrorCallback cb) { getAccessToken(code, cb); @@ -63,6 +63,7 @@ bool GoogleDriveStorage::canReuseRefreshToken() { return true; } void GoogleDriveStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain); + saveIsEnabledFlag(keyPrefix); } Common::String GoogleDriveStorage::name() const { @@ -228,12 +229,13 @@ GoogleDriveStorage *GoogleDriveStorage::loadFromConfig(Common::String keyPrefix) Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); Common::String refreshToken = ConfMan.get(keyPrefix + "refresh_token", ConfMan.kCloudDomain); - return new GoogleDriveStorage(accessToken, refreshToken); + return new GoogleDriveStorage(accessToken, refreshToken, loadIsEnabledFlag(keyPrefix)); } void GoogleDriveStorage::removeFromConfig(Common::String keyPrefix) { ConfMan.removeKey(keyPrefix + "access_token", ConfMan.kCloudDomain); ConfMan.removeKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain); + removeIsEnabledFlag(keyPrefix); } Common::String GoogleDriveStorage::getRootDirectoryId() { diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h index db47e7cd3c..792c30a99f 100644 --- a/backends/cloud/googledrive/googledrivestorage.h +++ b/backends/cloud/googledrive/googledrivestorage.h @@ -31,7 +31,7 @@ namespace GoogleDrive { class GoogleDriveStorage: public Id::IdStorage { /** This private constructor is called from loadFromConfig(). */ - GoogleDriveStorage(Common::String token, Common::String refreshToken); + GoogleDriveStorage(Common::String token, Common::String refreshToken, bool enabled); /** Constructs StorageInfo based on JSON response from cloud. */ void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json); diff --git a/backends/cloud/id/idstorage.cpp b/backends/cloud/id/idstorage.cpp index dd8805ea9b..78c3facc2c 100644 --- a/backends/cloud/id/idstorage.cpp +++ b/backends/cloud/id/idstorage.cpp @@ -35,8 +35,8 @@ namespace Id { IdStorage::IdStorage() {} -IdStorage::IdStorage(Common::String token, Common::String refreshToken): - BaseStorage(token, refreshToken) {} +IdStorage::IdStorage(Common::String token, Common::String refreshToken, bool enabled): + BaseStorage(token, refreshToken, enabled) {} IdStorage::~IdStorage() {} diff --git a/backends/cloud/id/idstorage.h b/backends/cloud/id/idstorage.h index 35a320284e..26d2618508 100644 --- a/backends/cloud/id/idstorage.h +++ b/backends/cloud/id/idstorage.h @@ -53,7 +53,7 @@ protected: public: IdStorage(); - IdStorage(Common::String token, Common::String refreshToken); + IdStorage(Common::String token, Common::String refreshToken, bool enabled); virtual ~IdStorage(); /** Public Cloud API comes down there. */ diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index 6d05d84c39..e7ac5b70f5 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -42,8 +42,8 @@ namespace OneDrive { #define ONEDRIVE_API_SPECIAL_APPROOT_ID "https://graph.microsoft.com/v1.0/drive/special/approot:/" #define ONEDRIVE_API_SPECIAL_APPROOT "https://graph.microsoft.com/v1.0/drive/special/approot" -OneDriveStorage::OneDriveStorage(Common::String token, Common::String refreshToken): - BaseStorage(token, refreshToken) {} +OneDriveStorage::OneDriveStorage(Common::String token, Common::String refreshToken, bool enabled): + BaseStorage(token, refreshToken, enabled) {} OneDriveStorage::OneDriveStorage(Common::String code, Networking::ErrorCallback cb) { getAccessToken(code, cb); @@ -62,6 +62,7 @@ bool OneDriveStorage::canReuseRefreshToken() { return false; } void OneDriveStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain); + saveIsEnabledFlag(keyPrefix); } Common::String OneDriveStorage::name() const { @@ -206,12 +207,13 @@ OneDriveStorage *OneDriveStorage::loadFromConfig(Common::String keyPrefix) { Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); Common::String refreshToken = ConfMan.get(keyPrefix + "refresh_token", ConfMan.kCloudDomain); - return new OneDriveStorage(accessToken, refreshToken); + return new OneDriveStorage(accessToken, refreshToken, loadIsEnabledFlag(keyPrefix)); } void OneDriveStorage::removeFromConfig(Common::String keyPrefix) { ConfMan.removeKey(keyPrefix + "access_token", ConfMan.kCloudDomain); ConfMan.removeKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain); + removeIsEnabledFlag(keyPrefix); } } // End of namespace OneDrive diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h index cc46772282..edf6a5f53f 100644 --- a/backends/cloud/onedrive/onedrivestorage.h +++ b/backends/cloud/onedrive/onedrivestorage.h @@ -31,7 +31,7 @@ namespace OneDrive { class OneDriveStorage: public Cloud::BaseStorage { /** This private constructor is called from loadFromConfig(). */ - OneDriveStorage(Common::String token, Common::String refreshToken); + OneDriveStorage(Common::String token, Common::String refreshToken, bool enabled); /** Constructs StorageInfo based on JSON response from cloud. */ void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json); diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index 3a9ae53a43..ed7f8f0ae7 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -34,10 +34,18 @@ namespace Cloud { Storage::Storage(): _runningRequestsCount(0), _savesSyncRequest(nullptr), _syncRestartRequestsed(false), - _downloadFolderRequest(nullptr) {} + _downloadFolderRequest(nullptr), _isEnabled(false) {} Storage::~Storage() {} +bool Storage::isEnabled() const { + return _isEnabled; +} + +void Storage::enable() { + _isEnabled = true; +} + Networking::ErrorCallback Storage::getErrorPrintingCallback() { return new Common::Callback<Storage, Networking::ErrorResponse>(this, &Storage::printErrorResponse); } @@ -121,6 +129,12 @@ Networking::Request *Storage::downloadById(Common::String remoteId, Common::Stri } Networking::Request *Storage::downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive) { + if (!_isEnabled) { + warning("Storage::downloadFolder: cannot be run while Storage is disabled"); + if (errorCallback) + (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "Storage is disabled.", -1)); + return nullptr; + } if (!errorCallback) errorCallback = getErrorPrintingCallback(); return addRequest(new FolderDownloadRequest(this, callback, errorCallback, remotePath, localPath, recursive)); @@ -128,6 +142,13 @@ Networking::Request *Storage::downloadFolder(Common::String remotePath, Common:: SavesSyncRequest *Storage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) { _runningRequestsMutex.lock(); + if (!_isEnabled) { + warning("Storage::syncSaves: cannot be run while Storage is disabled"); + if (errorCallback) + (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "Storage is disabled.", -1)); + _runningRequestsMutex.unlock(); + return nullptr; + } if (_savesSyncRequest) { warning("Storage::syncSaves: there is a sync in progress already"); _syncRestartRequestsed = true; diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index e914834dae..aa6455b841 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -70,6 +70,9 @@ protected: /** FolderDownloadRequest-related */ FolderDownloadRequest *_downloadFolderRequest; + /** Whether user manually enabled the Storage. */ + bool _isEnabled; + /** Returns default error callback (printErrorResponse). */ virtual Networking::ErrorCallback getErrorPrintingCallback(); @@ -116,6 +119,16 @@ public: virtual Common::String name() const = 0; /** + * Return whether Storage has been manually enabled by user. + */ + bool isEnabled() const; + + /** + * Set _isEnabled to true. + */ + void enable(); + + /** * Public Cloud API comes down there. * * All Cloud API methods return Networking::Request *, which diff --git a/gui/options.cpp b/gui/options.cpp index 7d9558a4a7..6645e9db67 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -114,7 +114,8 @@ enum { kConnectStorageCmd = 'Cnnt', kOpenUrlStorageCmd = 'OpUr', kPasteCodeStorageCmd = 'PsCd', - kDisconnectStorageCmd = 'DcSt' + kDisconnectStorageCmd = 'DcSt', + kEnableStorageCmd = 'EnSt' }; #endif @@ -1481,6 +1482,8 @@ GlobalOptionsDialog::GlobalOptionsDialog(LauncherDialog *launcher) _selectedStorageIndex = CloudMan.getStorageIndex(); _storagePopUpDesc = 0; _storagePopUp = 0; + _storageDisabledHint = 0; + _storageEnableButton = 0; _storageUsernameDesc = 0; _storageUsername = 0; _storageUsedSpaceDesc = 0; @@ -1872,6 +1875,9 @@ void GlobalOptionsDialog::addCloudControls(GuiObject *boss, const Common::String _storagePopUp->appendEntry(list[i], i); _storagePopUp->setSelected(_selectedStorageIndex); + _storageDisabledHint = new StaticTextWidget(boss, prefix + "StorageDisabledHint", _c("4. Storage is yet disabled. Verify that username is correct and enable it:", context)); + _storageEnableButton = new ButtonWidget(boss, prefix + "StorageEnableButton", _("Enable storage"), _("Confirm you want to use this account for this storage"), kEnableStorageCmd); + _storageUsernameDesc = new StaticTextWidget(boss, prefix + "StorageUsernameDesc", _("Username:"), _("Username used by this storage")); _storageUsername = new StaticTextWidget(boss, prefix + "StorageUsernameLabel", "<none>", "", ThemeEngine::kFontStyleNormal); @@ -2220,6 +2226,13 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 reflowLayout(); break; } + case kEnableStorageCmd: { + CloudMan.enableStorage(); + _redrawCloudTab = true; + + // also, automatically start saves sync when user enables the storage + // fall through + } case kSyncSavesStorageCmd: { CloudMan.syncSaves( new Common::Callback<GlobalOptionsDialog, Cloud::Storage::BoolResponse>(this, &GlobalOptionsDialog::storageSavesSyncedCallback) @@ -2467,9 +2480,28 @@ void GlobalOptionsDialog::setupCloudTab() { bool storageConnected = (username != ""); bool shown = (_selectedStorageIndex != Cloud::kStorageNoneId); bool shownConnectedInfo = (shown && storageConnected); + bool showingCurrentStorage = (shownConnectedInfo && _selectedStorageIndex == CloudMan.getStorageIndex()); + bool enabled = (shownConnectedInfo && CloudMan.isStorageEnabled()); // there goes layout for connected Storage + if (_storageDisabledHint) _storageDisabledHint->setVisible(showingCurrentStorage && !enabled); + if (_storageEnableButton) _storageEnableButton->setVisible(showingCurrentStorage && !enabled); + + // calculate shift + int16 x, y; + uint16 w, h; + int16 shiftUp = 0; + if (!showingCurrentStorage || enabled) { + // "storage is disabled" hint is not shown, shift everything up + if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageDisabledHint", x, y, w, h)) + warning("GlobalOptions_Cloud_Container.StorageUsernameDesc's position is undefined"); + shiftUp = y; + if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageUsernameDesc", x, y, w, h)) + warning("GlobalOptions_Cloud_Container.StorageWizardNotConnectedHint's position is undefined"); + shiftUp = y - shiftUp; + } + if (_storageUsernameDesc) _storageUsernameDesc->setVisible(shownConnectedInfo); if (_storageUsername) { _storageUsername->setLabel(username); @@ -2499,37 +2531,42 @@ void GlobalOptionsDialog::setupCloudTab() { _storageLastSync->setLabel(sync); _storageLastSync->setVisible(shownConnectedInfo); } - if (_storageSyncSavesButton) - _storageSyncSavesButton->setVisible(shownConnectedInfo && _selectedStorageIndex == CloudMan.getStorageIndex()); + if (_storageSyncSavesButton) { + _storageSyncSavesButton->setVisible(showingCurrentStorage); + _storageSyncSavesButton->setEnabled(enabled); + } - int16 x, y; - uint16 w, h; - int16 downloadHintY, downloadButtonY, disconnectHintY; - if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageDownloadHint", x, y, w, h)) - warning("GlobalOptions_Cloud_Container.StorageDownloadHint's position is undefined"); - downloadHintY = y; - if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.DownloadButton", x, y, w, h)) - warning("GlobalOptions_Cloud_Container.DownloadButton's position is undefined"); - downloadButtonY = y; - if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageDisconnectHint", x, y, w, h)) - warning("GlobalOptions_Cloud_Container.StorageDisconnectHint's position is undefined"); - disconnectHintY = y; - - bool showDownloadButton = (shownConnectedInfo && _selectedStorageIndex == CloudMan.getStorageIndex() && _selectedStorageIndex != Cloud::kStorageGoogleDriveId); // cannot download via Google Drive + bool showDownloadButton = (showingCurrentStorage && _selectedStorageIndex != Cloud::kStorageGoogleDriveId); // cannot download via Google Drive if (_storageDownloadHint) _storageDownloadHint->setVisible(showDownloadButton); - if (_storageDownloadButton) _storageDownloadButton->setVisible(showDownloadButton); + if (_storageDownloadButton) { + _storageDownloadButton->setVisible(showDownloadButton); + _storageDownloadButton->setEnabled(enabled); + } if (_storageDisconnectHint) _storageDisconnectHint->setVisible(shownConnectedInfo); if (_storageDisconnectButton) _storageDisconnectButton->setVisible(shownConnectedInfo); - if (showDownloadButton) { - if (_storageDownloadHint) _storageDownloadHint->setPos(_storageDownloadHint->getRelX(), downloadHintY); - if (_storageDownloadButton) _storageDownloadButton->setPos(_storageDownloadButton->getRelX(), downloadButtonY); - if (_storageDisconnectHint) _storageDisconnectHint->setPos(_storageDisconnectHint->getRelX(), disconnectHintY); - if (_storageDisconnectButton)_storageDisconnectButton->setPos(_storageDisconnectButton->getRelX(), disconnectHintY + downloadButtonY - downloadHintY); - } else { - if (_storageDisconnectHint) _storageDisconnectHint->setPos(_storageDisconnectHint->getRelX(), downloadHintY); - if (_storageDisconnectButton)_storageDisconnectButton->setPos(_storageDisconnectButton->getRelX(), downloadButtonY); - } + int16 disconnectWidgetsAdditionalShift = 0; + if (!showDownloadButton) { + if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageDownloadHint", x, y, w, h)) + warning("GlobalOptions_Cloud_Container.StorageDownloadHint's position is undefined"); + disconnectWidgetsAdditionalShift = y; + if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageDisconnectHint", x, y, w, h)) + warning("GlobalOptions_Cloud_Container.DownloadButton's position is undefined"); + disconnectWidgetsAdditionalShift = y - disconnectWidgetsAdditionalShift; + } + + shiftWidget(_storageUsernameDesc, "GlobalOptions_Cloud_Container.StorageUsernameDesc", 0, -shiftUp); + shiftWidget(_storageUsername, "GlobalOptions_Cloud_Container.StorageUsernameLabel", 0, -shiftUp); + shiftWidget(_storageUsedSpaceDesc, "GlobalOptions_Cloud_Container.StorageUsedSpaceDesc", 0, -shiftUp); + shiftWidget(_storageUsedSpace, "GlobalOptions_Cloud_Container.StorageUsedSpaceLabel", 0, -shiftUp); + shiftWidget(_storageSyncHint, "GlobalOptions_Cloud_Container.StorageSyncHint", 0, -shiftUp); + shiftWidget(_storageLastSyncDesc, "GlobalOptions_Cloud_Container.StorageLastSyncDesc", 0, -shiftUp); + shiftWidget(_storageLastSync, "GlobalOptions_Cloud_Container.StorageLastSyncLabel", 0, -shiftUp); + shiftWidget(_storageSyncSavesButton, "GlobalOptions_Cloud_Container.SyncSavesButton", 0, -shiftUp); + shiftWidget(_storageDownloadHint, "GlobalOptions_Cloud_Container.StorageDownloadHint", 0, -shiftUp); + shiftWidget(_storageDownloadButton, "GlobalOptions_Cloud_Container.DownloadButton", 0, -shiftUp); + shiftWidget(_storageDisconnectHint, "GlobalOptions_Cloud_Container.StorageDisconnectHint", 0, -shiftUp - disconnectWidgetsAdditionalShift); + shiftWidget(_storageDisconnectButton, "GlobalOptions_Cloud_Container.DisconnectButton", 0, -shiftUp - disconnectWidgetsAdditionalShift); // there goes layout for non-connected Storage (connection wizard) @@ -2560,8 +2597,7 @@ void GlobalOptionsDialog::setupCloudTab() { } if (!shownConnectedInfo) { - int16 shiftUp; - if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageUsernameDesc", x, y, w, h)) + if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageDisabledHint", x, y, w, h)) warning("GlobalOptions_Cloud_Container.StorageUsernameDesc's position is undefined"); shiftUp = y; if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.StorageWizardNotConnectedHint", x, y, w, h)) diff --git a/gui/options.h b/gui/options.h index a1cdcec6bc..10ff62d81c 100644 --- a/gui/options.h +++ b/gui/options.h @@ -298,6 +298,8 @@ protected: uint32 _selectedStorageIndex; StaticTextWidget *_storagePopUpDesc; PopUpWidget *_storagePopUp; + StaticTextWidget *_storageDisabledHint; + ButtonWidget *_storageEnableButton; StaticTextWidget *_storageUsernameDesc; StaticTextWidget *_storageUsername; StaticTextWidget *_storageUsedSpaceDesc; diff --git a/gui/themes/scummclassic.zip b/gui/themes/scummclassic.zip Binary files differindex 15dd50ac2a..0eba01ad6f 100644 --- a/gui/themes/scummclassic.zip +++ b/gui/themes/scummclassic.zip diff --git a/gui/themes/scummclassic/classic_layout.stx b/gui/themes/scummclassic/classic_layout.stx index 5dbd4ca320..1ed4f6b2c6 100644 --- a/gui/themes/scummclassic/classic_layout.stx +++ b/gui/themes/scummclassic/classic_layout.stx @@ -625,6 +625,16 @@ </layout> </layout> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> + <layout type = 'vertical' padding = '0, 0, 8, 0' spacing = '4'> + <widget name = 'StorageDisabledHint' + height = 'Globals.Line.Height' + /> + <widget name = 'StorageEnableButton' + type = 'Button' + /> + </layout> + </layout> + <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> <layout type = 'vertical' padding = '0, 0, 6, 0' spacing = '2'> <widget name = 'StorageUsernameDesc' type = 'CloudTabLabel' diff --git a/gui/themes/scummclassic/classic_layout_lowres.stx b/gui/themes/scummclassic/classic_layout_lowres.stx index d849513c1d..d73327d2fa 100644 --- a/gui/themes/scummclassic/classic_layout_lowres.stx +++ b/gui/themes/scummclassic/classic_layout_lowres.stx @@ -630,6 +630,16 @@ </layout> </layout> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> + <layout type = 'vertical' padding = '0, 0, 3, 0' spacing = '4'> + <widget name = 'StorageDisabledHint' + height = 'Globals.Line.Height' + /> + <widget name = 'StorageEnableButton' + type = 'Button' + /> + </layout> + </layout> + <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> <layout type = 'vertical' padding = '0, 0, 3, 0' spacing = '1'> <widget name = 'StorageUsernameDesc' type = 'CloudTabLabel' diff --git a/gui/themes/scummmodern.zip b/gui/themes/scummmodern.zip Binary files differindex b998e352be..cf5938805d 100644 --- a/gui/themes/scummmodern.zip +++ b/gui/themes/scummmodern.zip diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx index f6d5d6167d..ad4f6d71ca 100644 --- a/gui/themes/scummmodern/scummmodern_layout.stx +++ b/gui/themes/scummmodern/scummmodern_layout.stx @@ -639,6 +639,16 @@ </layout> </layout> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> + <layout type = 'vertical' padding = '0, 0, 8, 0' spacing = '4'> + <widget name = 'StorageDisabledHint' + height = 'Globals.Line.Height' + /> + <widget name = 'StorageEnableButton' + type = 'Button' + /> + </layout> + </layout> + <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> <layout type = 'vertical' padding = '0, 0, 6, 0' spacing = '2'> <widget name = 'StorageUsernameDesc' type = 'CloudTabLabel' diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx index e44aaa901e..bb06082017 100644 --- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx +++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx @@ -628,6 +628,16 @@ </layout> </layout> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> + <layout type = 'vertical' padding = '0, 0, 3, 0' spacing = '4'> + <widget name = 'StorageDisabledHint' + height = 'Globals.Line.Height' + /> + <widget name = 'StorageEnableButton' + type = 'Button' + /> + </layout> + </layout> + <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> <layout type = 'vertical' padding = '0, 0, 3, 0' spacing = '1'> <widget name = 'StorageUsernameDesc' type = 'CloudTabLabel' diff --git a/gui/themes/scummremastered.zip b/gui/themes/scummremastered.zip Binary files differindex 57775abf02..f9bf2e4559 100644 --- a/gui/themes/scummremastered.zip +++ b/gui/themes/scummremastered.zip diff --git a/gui/themes/scummremastered/remastered_layout.stx b/gui/themes/scummremastered/remastered_layout.stx index f6d5d6167d..ad4f6d71ca 100644 --- a/gui/themes/scummremastered/remastered_layout.stx +++ b/gui/themes/scummremastered/remastered_layout.stx @@ -639,6 +639,16 @@ </layout> </layout> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> + <layout type = 'vertical' padding = '0, 0, 8, 0' spacing = '4'> + <widget name = 'StorageDisabledHint' + height = 'Globals.Line.Height' + /> + <widget name = 'StorageEnableButton' + type = 'Button' + /> + </layout> + </layout> + <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> <layout type = 'vertical' padding = '0, 0, 6, 0' spacing = '2'> <widget name = 'StorageUsernameDesc' type = 'CloudTabLabel' diff --git a/gui/themes/scummremastered/remastered_layout_lowres.stx b/gui/themes/scummremastered/remastered_layout_lowres.stx index 32191aab76..5a265e208a 100644 --- a/gui/themes/scummremastered/remastered_layout_lowres.stx +++ b/gui/themes/scummremastered/remastered_layout_lowres.stx @@ -628,6 +628,16 @@ </layout> </layout> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> + <layout type = 'vertical' padding = '0, 0, 3, 0' spacing = '4'> + <widget name = 'StorageDisabledHint' + height = 'Globals.Line.Height' + /> + <widget name = 'StorageEnableButton' + type = 'Button' + /> + </layout> + </layout> + <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> <layout type = 'vertical' padding = '0, 0, 3, 0' spacing = '1'> <widget name = 'StorageUsernameDesc' type = 'CloudTabLabel' |