aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/util.cpp39
-rw-r--r--common/util.h12
-rw-r--r--gui/downloaddialog.cpp38
-rw-r--r--gui/options.cpp5
4 files changed, 56 insertions, 38 deletions
diff --git a/common/util.cpp b/common/util.cpp
index 9a4214eda8..7c309ce364 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -163,4 +163,43 @@ bool isGraph(int c) {
return isgraph((byte)c);
}
+
+#pragma mark -
+
+
+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;
+}
+
} // End of namespace Common
diff --git a/common/util.h b/common/util.h
index a90ea72167..8254e972d0 100644
--- a/common/util.h
+++ b/common/util.h
@@ -220,6 +220,18 @@ bool isCntrl(int c);
*/
bool isGraph(int c);
+
+/**
+ * Represent bytes size of a file as a number with floating point and
+ * largest suitable units. For example, 1474560 bytes as 1.4 MB.
+ *
+ * @param bytes size in bytes to be represented
+ * @param unitsOut (out-parameter) string with units
+ * @note use _() to translate units correctly
+ * @return string with a floating point number representing given size
+ */
+Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut);
+
} // End of namespace Common
#endif
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);