Revert "Utility: Use SI units"

This reverts commit 7445fa7ef7.
and commit f654c53c35.

The server still use wrong powers, so we still need to use the same
This commit is contained in:
Olivier Goffart 2015-01-15 13:54:39 +01:00
parent c9f1b3229b
commit 863731fd6a
2 changed files with 18 additions and 17 deletions

View file

@ -102,13 +102,10 @@ void Utility::setupFavLink(const QString &folder)
QString Utility::octetsToString( qint64 octets )
{
// SI system defines kB to be 1000 B. If we want to use powers of 2, one would have to use the
// the KiB, MiB, ... notation. But powers of 10 makes more sens for the user because that's
// what the human is most confortable with.
static const qint64 kb = 1000;
static const qint64 mb = 1000 * kb;
static const qint64 gb = 1000 * mb;
static const qint64 tb = 1000 * gb;
static const qint64 kb = 1024;
static const qint64 mb = 1024 * kb;
static const qint64 gb = 1024 * mb;
static const qint64 tb = 1024 * gb;
QString s;
qreal value = octets;

View file

@ -26,27 +26,31 @@ private slots:
}
void testOctetsToString()
{
QLocale::setDefault(QLocale("en"));
QCOMPARE(octetsToString(999) , QString("999 B"));
QCOMPARE(octetsToString(1000) , QString("1 kB"));
QCOMPARE(octetsToString(1010) , QString("1 kB"));
QCOMPARE(octetsToString(1000) , QString("1,000 B"));
QCOMPARE(octetsToString(1010) , QString("1,010 B"));
QCOMPARE(octetsToString(1024) , QString("1 kB"));
QCOMPARE(octetsToString(1110) , QString("1.1 kB"));
QCOMPARE(octetsToString(9110) , QString("9.1 kB"));
QCOMPARE(octetsToString(9910) , QString("9.9 kB"));
QCOMPARE(octetsToString(9999) , QString("10 kB"));
QCOMPARE(octetsToString(9110) , QString("8.9 kB"));
QCOMPARE(octetsToString(9910) , QString("9.7 kB"));
QCOMPARE(octetsToString(9999) , QString("9.8 kB"));
QCOMPARE(octetsToString(10240) , QString("10 kB"));
QCOMPARE(octetsToString(123456) , QString("123 kB"));
QCOMPARE(octetsToString(123456) , QString("121 kB"));
QCOMPARE(octetsToString(1234567) , QString("1.2 MB"));
QCOMPARE(octetsToString(12345678) , QString("12 MB"));
QCOMPARE(octetsToString(123456789) , QString("123 MB"));
QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("5 GB"));
QCOMPARE(octetsToString(123456789) , QString("118 MB"));
QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("4.7 GB"));
QCOMPARE(octetsToString(1024LL*1024*1024 * 5) , QString("5 GB"));
QCOMPARE(octetsToString(1), QString("1 B"));
QCOMPARE(octetsToString(2), QString("2 B"));
QCOMPARE(octetsToString(1024), QString("1 kB"));
QCOMPARE(octetsToString(1024*1024), QString("1 MB"));
QCOMPARE(octetsToString(1024LL*1024*1024), QString("1.1 GB"));
QCOMPARE(octetsToString(1024LL*1024*1024*1024), QString("1.1 TB"));
QCOMPARE(octetsToString(1024LL*1024*1024), QString("1 GB"));
QCOMPARE(octetsToString(1024LL*1024*1024*1024), QString("1 TB"));
}
void testLaunchOnStartup()