GUI: Update DownloadDialog
It now has download size and speed labels. Commit also fixes minor mistake in ConnMan.
This commit is contained in:
parent
c431ae6d84
commit
1b56f59add
5 changed files with 83 additions and 10 deletions
|
@ -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:
|
||||
|
|
|
@ -40,7 +40,7 @@ enum {
|
|||
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;
|
||||
|
||||
|
@ -56,6 +56,8 @@ 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));
|
||||
_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
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue