CLOUD: Make ProgressDialog display downloading progress
This commit is contained in:
parent
3db80154d6
commit
0ce7be17d3
7 changed files with 40 additions and 2 deletions
|
@ -139,6 +139,12 @@ bool CloudManager::isSyncing() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double CloudManager::getSyncDownloadingProgress() {
|
||||||
|
Storage *storage = getCurrentStorage();
|
||||||
|
if (storage) return storage->getSyncDownloadingProgress();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
double CloudManager::getSyncProgress() {
|
double CloudManager::getSyncProgress() {
|
||||||
Storage *storage = getCurrentStorage();
|
Storage *storage = getCurrentStorage();
|
||||||
if (storage) return storage->getSyncProgress();
|
if (storage) return storage->getSyncProgress();
|
||||||
|
|
|
@ -90,6 +90,9 @@ public:
|
||||||
/** Returns whether there is a SavesSyncRequest running. */
|
/** Returns whether there is a SavesSyncRequest running. */
|
||||||
bool isSyncing();
|
bool isSyncing();
|
||||||
|
|
||||||
|
/** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */
|
||||||
|
double getSyncDownloadingProgress();
|
||||||
|
|
||||||
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
||||||
double getSyncProgress();
|
double getSyncProgress();
|
||||||
|
|
||||||
|
|
|
@ -208,12 +208,13 @@ void SavesSyncRequest::directoryCreatedErrorCallback(Networking::ErrorResponse e
|
||||||
|
|
||||||
void SavesSyncRequest::downloadNextFile() {
|
void SavesSyncRequest::downloadNextFile() {
|
||||||
if (_filesToDownload.empty()) {
|
if (_filesToDownload.empty()) {
|
||||||
|
_currentDownloadingFile = StorageFile("", 0, 0, false); //so getFilesToDownload() would return an empty array
|
||||||
sendCommand(kSavesSyncEndedCmd, 0);
|
sendCommand(kSavesSyncEndedCmd, 0);
|
||||||
uploadNextFile();
|
uploadNextFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCommand(kSavesSyncProgressCmd, (int)(getProgress() * 100));
|
sendCommand(kSavesSyncProgressCmd, (int)(getDownloadingProgress() * 100));
|
||||||
|
|
||||||
_currentDownloadingFile = _filesToDownload.back();
|
_currentDownloadingFile = _filesToDownload.back();
|
||||||
_filesToDownload.pop_back();
|
_filesToDownload.pop_back();
|
||||||
|
@ -295,6 +296,19 @@ void SavesSyncRequest::handle() {}
|
||||||
|
|
||||||
void SavesSyncRequest::restart() { start(); }
|
void SavesSyncRequest::restart() { start(); }
|
||||||
|
|
||||||
|
double SavesSyncRequest::getDownloadingProgress() {
|
||||||
|
if (_totalFilesToHandle == 0) {
|
||||||
|
if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon
|
||||||
|
return 0; //directory not listed yet
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_totalFilesToHandle == _filesToUpload.size()) return 1; //nothing to download => download complete
|
||||||
|
|
||||||
|
uint32 totalFilesToDownload = _totalFilesToHandle - _filesToUpload.size();
|
||||||
|
uint32 filesLeftToDownload = _filesToDownload.size() + (_currentDownloadingFile.name() != "" ? 1 : 0);
|
||||||
|
return (double)(totalFilesToDownload - filesLeftToDownload) / (double)(totalFilesToDownload);
|
||||||
|
}
|
||||||
|
|
||||||
double SavesSyncRequest::getProgress() {
|
double SavesSyncRequest::getProgress() {
|
||||||
if (_totalFilesToHandle == 0) {
|
if (_totalFilesToHandle == 0) {
|
||||||
if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon
|
if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon
|
||||||
|
|
|
@ -69,6 +69,9 @@ public:
|
||||||
virtual void handle();
|
virtual void handle();
|
||||||
virtual void restart();
|
virtual void restart();
|
||||||
|
|
||||||
|
/** Returns a number in range [0, 1], where 1 is "complete". */
|
||||||
|
double getDownloadingProgress();
|
||||||
|
|
||||||
/** Returns a number in range [0, 1], where 1 is "complete". */
|
/** Returns a number in range [0, 1], where 1 is "complete". */
|
||||||
double getProgress();
|
double getProgress();
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,15 @@ bool Storage::isSyncing() {
|
||||||
return syncing;
|
return syncing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Storage::getSyncDownloadingProgress() {
|
||||||
|
double result = 1;
|
||||||
|
_runningRequestsMutex.lock();
|
||||||
|
if (_savesSyncRequest)
|
||||||
|
result = _savesSyncRequest->getDownloadingProgress();
|
||||||
|
_runningRequestsMutex.unlock();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
double Storage::getSyncProgress() {
|
double Storage::getSyncProgress() {
|
||||||
double result = 1;
|
double result = 1;
|
||||||
_runningRequestsMutex.lock();
|
_runningRequestsMutex.lock();
|
||||||
|
|
|
@ -147,6 +147,9 @@ public:
|
||||||
/** Returns whether there is a SavesSyncRequest running. */
|
/** Returns whether there is a SavesSyncRequest running. */
|
||||||
virtual bool isSyncing();
|
virtual bool isSyncing();
|
||||||
|
|
||||||
|
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
||||||
|
virtual double getSyncDownloadingProgress();
|
||||||
|
|
||||||
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
||||||
virtual double getSyncProgress();
|
virtual double getSyncProgress();
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(): Dialog(10, 1
|
||||||
int buttonWidth = 140;
|
int buttonWidth = 140;
|
||||||
int marginBottom = 8;
|
int marginBottom = 8;
|
||||||
|
|
||||||
uint32 progress = (uint32)(100 * CloudMan.getSyncProgress());
|
uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
|
||||||
_label = new StaticTextWidget(this, 10, 10, 300, kLineHeight, Common::String::format("Downloading saves (%u%% complete)...", progress), Graphics::kTextAlignCenter);
|
_label = new StaticTextWidget(this, 10, 10, 300, kLineHeight, Common::String::format("Downloading saves (%u%% complete)...", progress), Graphics::kTextAlignCenter);
|
||||||
|
|
||||||
//if (defaultButton)
|
//if (defaultButton)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue