From 6696d45f563a570011906c8efa8af342907b05d8 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 29 Sep 2023 16:41:03 +0200 Subject: [PATCH] Remove custom data size formatting It is replaced by `QLocale::formattedDataSize`. Fixes: #11024 --- src/common/utility.cpp | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/src/common/utility.cpp b/src/common/utility.cpp index defc94b5b4b..586fa07a74a 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -84,44 +84,11 @@ QString Utility::formatFingerprint(const QByteArray &fmhash, bool colonSeparated QString Utility::octetsToString(qint64 octets) { -#define THE_FACTOR 1024 - static const qint64 kb = THE_FACTOR; - static const qint64 mb = THE_FACTOR * kb; - static const qint64 gb = THE_FACTOR * mb; - - QString s; - qreal value = octets; - - // Whether we care about decimals: only for GB/MB and only - // if it's less than 10 units. - bool round = true; - - // do not display terra byte with the current units, as when - // the MB, GB and KB units were made, there was no TB, - // see the JEDEC standard - // https://en.wikipedia.org/wiki/JEDEC_memory_standards - if (octets >= gb) { - s = QCoreApplication::translate("Utility", "%L1 GB"); - value /= gb; - round = false; - } else if (octets >= mb) { - s = QCoreApplication::translate("Utility", "%L1 MB"); - value /= mb; - round = false; - } else if (octets >= kb) { - s = QCoreApplication::translate("Utility", "%L1 KB"); - value /= kb; - } else { - s = QCoreApplication::translate("Utility", "%L1 B"); - } - - if (value > 9.95) - round = true; - - if (round) - return s.arg(qRound(value)); + OC_ASSERT(octets >= 0) - return s.arg(value, 0, 'g', 2); + using namespace FileSystem::SizeLiterals; + const int precesion = quint64(octets) < 1_mb ? 0 : 2; + return QLocale().formattedDataSize(octets, precesion, QLocale::DataSizeTraditionalFormat); } // Qtified version of get_platforms() in csync_owncloud.c