aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-05 20:20:22 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commite9721976aa4fc604810cf1daf6d60b206197cd9a (patch)
treedec04a05a4348dd42ed7c0f8d885ab5b0c4041ce
parente7763700e2e2016f4573e3feb77b5fab69268683 (diff)
downloadscummvm-rg350-e9721976aa4fc604810cf1daf6d60b206197cd9a.tar.gz
scummvm-rg350-e9721976aa4fc604810cf1daf6d60b206197cd9a.tar.bz2
scummvm-rg350-e9721976aa4fc604810cf1daf6d60b206197cd9a.zip
GUI: Add SaveLoadCloudSyncProgressDialog
It's shown by SaveLoadChooserDialog when files are downloaded and some save slots are locked. One can hide that dialog to interact with non-locked slots or cancel saves sync completely. Dialog's label shows current sync progress. Dialog automatically hides itself when all files are downloaded. WARNING: right now that results in a crash!
-rw-r--r--backends/cloud/cloudmanager.cpp10
-rw-r--r--backends/cloud/cloudmanager.h12
-rw-r--r--backends/cloud/savessyncrequest.cpp10
-rw-r--r--backends/cloud/storage.cpp14
-rw-r--r--backends/cloud/storage.h12
-rw-r--r--gui/saveload-dialog.cpp87
-rw-r--r--gui/saveload-dialog.h12
7 files changed, 154 insertions, 3 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index b4598d7a97..f5d60e025c 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -151,4 +151,14 @@ Common::Array<Common::String> CloudManager::getSyncingFiles() {
return Common::Array<Common::String>();
}
+void CloudManager::cancelSync() {
+ Storage *storage = getCurrentStorage();
+ if (storage) storage->cancelSync();
+}
+
+void CloudManager::setSyncTarget(GUI::CommandReceiver *target) {
+ Storage *storage = getCurrentStorage();
+ if (storage) storage->setSyncTarget(target);
+}
+
} // End of namespace Common
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index a02dc90008..c7351dab2e 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -27,6 +27,12 @@
#include "common/array.h"
#include "common/singleton.h"
+namespace GUI {
+
+class CommandReceiver;
+
+}
+
namespace Cloud {
class CloudManager : public Common::Singleton<CloudManager> {
@@ -89,6 +95,12 @@ public:
/** Returns an array of saves names which are not yet synced (thus cannot be used). */
Common::Array<Common::String> getSyncingFiles();
+
+ /** Cancels running sync. */
+ void cancelSync();
+
+ /** Sets SavesSyncRequest's target to given CommandReceiver. */
+ void setSyncTarget(GUI::CommandReceiver *target);
};
/** Shortcut for accessing the connection manager. */
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index a99c229925..e066c53a92 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -24,14 +24,19 @@
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/file.h"
+#include "common/json.h"
#include "common/savefile.h"
#include "common/system.h"
-#include <common/json.h>
namespace Cloud {
const char *SavesSyncRequest::TIMESTAMPS_FILENAME = "timestamps";
+enum {
+ kSavesSyncProgressCmd = 'SSPR',
+ kSavesSyncEndedCmd = 'SSEN'
+};
+
SavesSyncRequest::SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb):
Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _boolCallback(callback),
_workingRequest(nullptr), _ignoreCallback(false) {
@@ -203,10 +208,13 @@ void SavesSyncRequest::directoryCreatedErrorCallback(Networking::ErrorResponse e
void SavesSyncRequest::downloadNextFile() {
if (_filesToDownload.empty()) {
+ sendCommand(kSavesSyncEndedCmd, 0);
uploadNextFile();
return;
}
+ sendCommand(kSavesSyncProgressCmd, (int)(getProgress() * 100));
+
_currentDownloadingFile = _filesToDownload.back();
_filesToDownload.pop_back();
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 19f0845c47..c98310d3dd 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -142,5 +142,19 @@ Common::Array<Common::String> Storage::getSyncingFiles() {
return result;
}
+void Storage::cancelSync() {
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest)
+ _savesSyncRequest->finish();
+ _runningRequestsMutex.unlock();
+}
+
+void Storage::setSyncTarget(GUI::CommandReceiver *target) {
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest)
+ _savesSyncRequest->setTarget(target);
+ _runningRequestsMutex.unlock();
+}
+
} // End of namespace Cloud
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index 5941fe4a32..40ea14a3a1 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -33,6 +33,12 @@
#include "common/stream.h"
#include "common/str.h"
+namespace GUI {
+
+class CommandReceiver;
+
+}
+
namespace Cloud {
class SavesSyncRequest;
@@ -146,6 +152,12 @@ public:
/** Returns an array of saves names which are not yet synced (thus cannot be used). */
virtual Common::Array<Common::String> getSyncingFiles();
+
+ /** Cancels running sync. */
+ virtual void cancelSync();
+
+ /** Sets SavesSyncRequest's target to given CommandReceiver. */
+ virtual void setSyncTarget(GUI::CommandReceiver *target);
};
} // End of namespace Cloud
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index d9713505e6..e5e71a73b8 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -38,6 +38,53 @@
namespace GUI {
+enum {
+ kSavesSyncProgressCmd = 'SSPR',
+ kSavesSyncEndedCmd = 'SSEN',
+
+ kCancelSyncCmd = 'PDCS',
+ kBackgroundSyncCmd = 'PDBS'
+};
+
+SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(): Dialog(10, 10, 320, 100) {
+ int x = 10;
+ int buttonHeight = 24;
+ int buttonWidth = 140;
+ int marginBottom = 8;
+
+ uint32 progress = (uint32)(100 * CloudMan.getSyncProgress());
+ _label = new StaticTextWidget(this, 10, 10, 300, kLineHeight, Common::String::format("Downloading saves (%u%% complete)...", progress), Graphics::kTextAlignCenter);
+
+ //if (defaultButton)
+ new ButtonWidget(this, x, _h - buttonHeight - marginBottom, buttonWidth, buttonHeight, "Cancel", 0, kCancelSyncCmd, Common::ASCII_ESCAPE); // Cancel dialog
+
+ //if (altButton)
+ new ButtonWidget(this, x + buttonWidth + 10, _h - buttonHeight - 8, buttonWidth, buttonHeight, "Run in background", 0, kBackgroundSyncCmd, Common::ASCII_RETURN); // Confirm dialog
+}
+
+SaveLoadCloudSyncProgressDialog::~SaveLoadCloudSyncProgressDialog() {}
+
+void SaveLoadCloudSyncProgressDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
+ switch(cmd) {
+ case kSavesSyncProgressCmd:
+ _label->setLabel(Common::String::format("Downloading saves (%u%% complete)...", data));
+ break;
+
+ case kCancelSyncCmd:
+ setResult(kCancelSyncCmd);
+ close();
+ break;
+
+ case kSavesSyncEndedCmd:
+ case kBackgroundSyncCmd:
+ setResult(kBackgroundSyncCmd);
+ close();
+ break;
+ }
+
+ Dialog::handleCommand(sender, cmd, data);
+}
+
#ifndef DISABLE_SAVELOADCHOOSER_GRID
SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine &metaEngine) {
const Common::String &userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain);
@@ -71,7 +118,8 @@ enum {
SaveLoadChooserDialog::SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode)
: Dialog(dialogName), _metaEngine(0), _delSupport(false), _metaInfoSupport(false),
- _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode)
+ _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode),
+ _dialogWasShown(false)
#ifndef DISABLE_SAVELOADCHOOSER_GRID
, _listButton(0), _gridButton(0)
#endif // !DISABLE_SAVELOADCHOOSER_GRID
@@ -83,7 +131,8 @@ SaveLoadChooserDialog::SaveLoadChooserDialog(const Common::String &dialogName, c
SaveLoadChooserDialog::SaveLoadChooserDialog(int x, int y, int w, int h, const bool saveMode)
: Dialog(x, y, w, h), _metaEngine(0), _delSupport(false), _metaInfoSupport(false),
- _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode)
+ _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode),
+ _dialogWasShown(false)
#ifndef DISABLE_SAVELOADCHOOSER_GRID
, _listButton(0), _gridButton(0)
#endif // !DISABLE_SAVELOADCHOOSER_GRID
@@ -99,6 +148,8 @@ void SaveLoadChooserDialog::open() {
// So that quitting ScummVM will not cause the dialog result to say a
// saved game was selected.
setResult(-1);
+
+ _dialogWasShown = false;
}
int SaveLoadChooserDialog::run(const Common::String &target, const MetaEngine *metaEngine) {
@@ -137,6 +188,21 @@ void SaveLoadChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uin
}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
+ if (cmd == kSavesSyncProgressCmd || cmd == kSavesSyncEndedCmd) {
+ Cloud::SavesSyncRequest *request = (Cloud::SavesSyncRequest *)sender;
+
+ //this dialog only gets these commands if the progress dialog was shown and user clicked "run in background"
+ switch (cmd) {
+ case kSavesSyncProgressCmd:
+ //TODO: unlock that save which was downloaded
+ break;
+
+ case kSavesSyncEndedCmd:
+ //TODO: ?
+ break;
+ }
+ }
+
return Dialog::handleCommand(sender, cmd, data);
}
@@ -151,6 +217,23 @@ void SaveLoadChooserDialog::runSaveSync(bool hasSavepathOverride) {
}
}
+void SaveLoadChooserDialog::handleTickle() {
+ if (!_dialogWasShown && CloudMan.isSyncing()) {
+ Common::Array<Common::String> files = CloudMan.getSyncingFiles();
+ if (!files.empty()) {
+ SaveLoadCloudSyncProgressDialog dialog;
+ CloudMan.setSyncTarget(&dialog);
+ int result = dialog.runModal();
+ if (result == kCancelSyncCmd) {
+ CloudMan.cancelSync();
+ }
+ CloudMan.setSyncTarget(this);
+ _dialogWasShown = true;
+ }
+ }
+ Dialog::handleTickle();
+}
+
void SaveLoadChooserDialog::reflowLayout() {
#ifndef DISABLE_SAVELOADCHOOSER_GRID
addChooserButtons();
diff --git a/gui/saveload-dialog.h b/gui/saveload-dialog.h
index 0e67ba89fe..ffb8f34458 100644
--- a/gui/saveload-dialog.h
+++ b/gui/saveload-dialog.h
@@ -30,6 +30,15 @@
namespace GUI {
+class SaveLoadCloudSyncProgressDialog : public Dialog { //protected?
+ StaticTextWidget *_label;
+public:
+ SaveLoadCloudSyncProgressDialog();
+ virtual ~SaveLoadCloudSyncProgressDialog();
+
+ virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+};
+
#define kSwitchSaveLoadDialog -2
// TODO: We might want to disable the grid based save/load chooser for more
@@ -61,6 +70,8 @@ public:
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual void runSaveSync(bool hasSavepathOverride);
+
+ virtual void handleTickle();
#ifndef DISABLE_SAVELOADCHOOSER_GRID
virtual SaveLoadChooserType getType() const = 0;
@@ -80,6 +91,7 @@ protected:
bool _saveDateSupport;
bool _playTimeSupport;
Common::String _target;
+ bool _dialogWasShown;
#ifndef DISABLE_SAVELOADCHOOSER_GRID
ButtonWidget *_listButton;