diff options
author | Alexander Tkachev | 2019-07-15 18:35:24 +0700 |
---|---|---|
committer | Matan Bareket | 2019-07-30 14:51:41 -0400 |
commit | d04c1dfad422d9ea8c2b460ff01b88911d9fd3ef (patch) | |
tree | 5f29d43b0b19b8c5c018386a38572e20af84ed48 /gui | |
parent | faa19c7bf097e6a7f1f76c29b0faba12d5781d19 (diff) | |
download | scummvm-rg350-d04c1dfad422d9ea8c2b460ff01b88911d9fd3ef.tar.gz scummvm-rg350-d04c1dfad422d9ea8c2b460ff01b88911d9fd3ef.tar.bz2 scummvm-rg350-d04c1dfad422d9ea8c2b460ff01b88911d9fd3ef.zip |
COMMON: Add getHumanReadableBytes() in util.h
This function was used in cloud-related DownloadDialog before,
and now it is also used in Options > Cloud tab.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/downloaddialog.cpp | 38 | ||||
-rw-r--r-- | gui/options.cpp | 5 |
2 files changed, 5 insertions, 38 deletions
diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 526a89538f..8b7408c8cd 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -24,6 +24,7 @@ #include "backends/cloud/cloudmanager.h" #include "common/config-manager.h" #include "common/translation.h" +#include "common/util.h" #include "engines/metaengine.h" #include "gui/browser.h" #include "gui/chooser.h" @@ -207,43 +208,6 @@ void DownloadDialog::reflowLayout() { refreshWidgets(); } -namespace { -Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut) { - Common::String result = Common::String::format("%lu", bytes); - unitsOut = "B"; - - if (bytes >= 1024) { - bytes /= 1024; - result = Common::String::format("%lu", 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("%.1f", floating); - return result; -} -} - Common::String DownloadDialog::getSizeLabelText() { Common::String downloaded, downloadedUnits, total, totalUnits; downloaded = getHumanReadableBytes(CloudMan.getDownloadBytesNumber(), downloadedUnits); diff --git a/gui/options.cpp b/gui/options.cpp index 8d2bda5af0..5d90b70813 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -38,6 +38,7 @@ #include "common/textconsole.h" #include "common/translation.h" #include "common/updates.h" +#include "common/util.h" #include "audio/mididrv.h" #include "audio/musicplugin.h" @@ -2340,7 +2341,9 @@ void GlobalOptionsDialog::setupCloudTab() { if (_storageUsedSpaceDesc) _storageUsedSpaceDesc->setVisible(shown); if (_storageUsedSpace) { uint64 usedSpace = CloudMan.getStorageUsedSpace(_selectedStorageIndex); - _storageUsedSpace->setLabel(Common::String::format(_("%llu bytes"), usedSpace)); + Common::String usedSpaceNumber, usedSpaceUnits; + usedSpaceNumber = Common::getHumanReadableBytes(usedSpace, usedSpaceUnits); + _storageUsedSpace->setLabel(Common::String::format("%s %s", usedSpaceNumber.c_str(), _(usedSpaceUnits.c_str()))); _storageUsedSpace->setVisible(shown); } if (_storageLastSyncDesc) _storageLastSyncDesc->setVisible(shown); |