aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-14 16:53:38 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit1b56f59add45af1894957a58fb4cf662f534d54d (patch)
tree69cd0e29027ff79258900aa9b538af6963bd469a
parentc431ae6d84be1ef73c44b84c58ee3d9edff3d5e3 (diff)
downloadscummvm-rg350-1b56f59add45af1894957a58fb4cf662f534d54d.tar.gz
scummvm-rg350-1b56f59add45af1894957a58fb4cf662f534d54d.tar.bz2
scummvm-rg350-1b56f59add45af1894957a58fb4cf662f534d54d.zip
GUI: Update DownloadDialog
It now has download size and speed labels. Commit also fixes minor mistake in ConnMan.
-rw-r--r--backends/networking/curl/connectionmanager.cpp2
-rw-r--r--gui/downloaddialog.cpp74
-rw-r--r--gui/downloaddialog.h5
-rw-r--r--gui/themes/scummmodern/scummmodern_layout.stx6
-rw-r--r--gui/themes/scummmodern/scummmodern_layout_lowres.stx6
5 files changed, 83 insertions, 10 deletions
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index 415151d40d..b553e8f1ac 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -92,7 +92,7 @@ Common::String ConnectionManager::urlEncode(Common::String s) {
}
uint32 ConnectionManager::getCloudRequestsPeriodInMicroseconds() {
- return TIMER_INTERVAL * FRAMES_PER_SECOND / CLOUD_PERIOD;
+ return TIMER_INTERVAL * CLOUD_PERIOD;
}
//private goes here:
diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp
index d734839cea..42c962895f 100644
--- a/gui/downloaddialog.cpp
+++ b/gui/downloaddialog.cpp
@@ -37,16 +37,16 @@
namespace GUI {
enum {
- kDownloadDialogButtonCmd = 'Dldb'
+ kDownloadDialogButtonCmd = 'Dldb'
};
-DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher):
+DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher) :
Dialog("GlobalOptions_Cloud_DownloadDialog"), _launcher(launcher), _close(false) {
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
_browser = new BrowserDialog(_("Select directory where to download game data"), true);
_remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data"));
-
+
_remoteDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.RemoteDirectory", _("From: "));
_localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: "));
uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress());
@@ -56,14 +56,16 @@ DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher):
_progressBar->setValue(progress);
_progressBar->setEnabled(false);
_percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress));
- if (g_system->getOverlayWidth() > 320)
+ _downloadSizeLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DownloadSize", "");
+ _downloadSpeedLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DownloadSpeed", "");
+ if (g_system->getOverlayWidth() > 320)
_cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Cancel download"), 0, kDownloadDialogButtonCmd);
else
_cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _c("Cancel download", "lowres"), 0, kDownloadDialogButtonCmd);
-
+
_closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("Hide"), 0, kCloseCmd);
refreshWidgets();
-
+
CloudMan.setDownloadTarget(this);
}
@@ -88,7 +90,8 @@ void DownloadDialog::close() {
void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
- case kDownloadDialogButtonCmd: {
+ case kDownloadDialogButtonCmd:
+ {
CloudMan.setDownloadTarget(nullptr);
CloudMan.cancelDownload();
close();
@@ -138,7 +141,7 @@ bool DownloadDialog::selectDirectories() {
Common::String::format(_("The \"%s\" already exists in the specified directory.\nDo you really want to download files into that directory?"), remoteDirectory.name().c_str()),
_("Yes"),
_("No")
- );
+ );
if (alert.runModal() != GUI::kMessageOK) return false;
break;
}
@@ -187,12 +190,65 @@ void DownloadDialog::reflowLayout() {
refreshWidgets();
}
+namespace {
+Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut) {
+ Common::String result = Common::String::format("%u", bytes);
+ unitsOut = "B";
+
+ if (bytes >= 1024) {
+ bytes /= 1024;
+ result = Common::String::format("%u", bytes);
+ unitsOut = "KB";
+ }
+
+ double floating = bytes;
+
+ if (bytes >= 1024) {
+ bytes /= 1024;
+ floating /= 1024.0;
+ unitsOut = "MB";
+ }
+
+ if (bytes >= 1024) {
+ bytes /= 1024;
+ floating /= 1024.0;
+ unitsOut = "GB";
+ }
+
+ if (bytes >= 1024) { // woah
+ bytes /= 1024;
+ floating /= 1024.0;
+ unitsOut = "TB";
+ }
+
+ // print one digit after floating point
+ result = Common::String::format("%.1lf", floating);
+ return result;
+}
+}
+
+Common::String DownloadDialog::getSizeLabelText() {
+ Common::String downloaded, downloadedUnits, total, totalUnits;
+ downloaded = getHumanReadableBytes(CloudMan.getDownloadBytesNumber(), downloadedUnits);
+ total = getHumanReadableBytes(CloudMan.getDownloadTotalBytesNumber(), totalUnits);
+ return Common::String::format(_("Downloaded %s %s / %s %s"), downloaded.c_str(), _(downloadedUnits.c_str()), total.c_str(), _(totalUnits.c_str()));
+}
+
+Common::String DownloadDialog::getSpeedLabelText() {
+ Common::String speed, speedUnits;
+ speed = getHumanReadableBytes(CloudMan.getDownloadSpeed(), speedUnits);
+ speedUnits += "/s";
+ return Common::String::format("Download speed: %s %s", speed.c_str(), _(speedUnits.c_str()));
+}
+
void DownloadDialog::refreshWidgets() {
_localDirectory = CloudMan.getDownloadLocalDirectory();
_remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory());
_localDirectoryLabel->setLabel(_("To: ") + _localDirectory);
uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress());
- _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u - %u bytes per second)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber(), CloudMan.getDownloadSpeed()));
+ _percentLabel->setLabel(Common::String::format("%u %%", progress));
+ _downloadSizeLabel->setLabel(getSizeLabelText());
+ _downloadSpeedLabel->setLabel(getSpeedLabelText());
_progressBar->setValue(progress);
}
diff --git a/gui/downloaddialog.h b/gui/downloaddialog.h
index 4b277c8334..e91318bb86 100644
--- a/gui/downloaddialog.h
+++ b/gui/downloaddialog.h
@@ -51,6 +51,8 @@ class DownloadDialog : public Dialog {
StaticTextWidget *_remoteDirectoryLabel;
StaticTextWidget *_localDirectoryLabel;
StaticTextWidget *_percentLabel;
+ StaticTextWidget *_downloadSizeLabel;
+ StaticTextWidget *_downloadSpeedLabel;
SliderWidget *_progressBar;
ButtonWidget *_cancelButton;
ButtonWidget *_closeButton;
@@ -58,6 +60,9 @@ class DownloadDialog : public Dialog {
Common::String _localDirectory;
bool _close;
+ Common::String getSizeLabelText();
+ Common::String getSpeedLabelText();
+
void refreshWidgets();
bool selectDirectories();
diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx
index 6edfebc0d4..5f4ef6f14d 100644
--- a/gui/themes/scummmodern/scummmodern_layout.stx
+++ b/gui/themes/scummmodern/scummmodern_layout.stx
@@ -616,6 +616,12 @@
height = 'Globals.Line.Height'
textalign = 'center'
/>
+ <widget name = 'DownloadSize'
+ height = 'Globals.Line.Height'
+ />
+ <widget name = 'DownloadSpeed'
+ height = 'Globals.Line.Height'
+ />
<space/>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10'>
<widget name = 'MainButton'
diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx
index e183ceea2d..24476e3619 100644
--- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx
+++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx
@@ -613,6 +613,12 @@
height = 'Globals.Line.Height'
textalign = 'center'
/>
+ <widget name = 'DownloadSize'
+ height = 'Globals.Line.Height'
+ />
+ <widget name = 'DownloadSpeed'
+ height = 'Globals.Line.Height'
+ />
<space/>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6'>
<widget name = 'MainButton'