Skip to content

Commit

Permalink
Remove custom data size formatting
Browse files Browse the repository at this point in the history
It is replaced by `QLocale::formattedDataSize`.

Fixes: #11024
  • Loading branch information
erikjv committed Sep 29, 2023
1 parent 76bcef2 commit 6696d45
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6696d45

Please sign in to comment.