зеркало из https://github.com/nextcloud/desktop.git
Adjust size description strings #3403
@jancorchardt suggested to not have decimal places on file sizes, except for GB.
This commit is contained in:
Родитель
ffbd5df25f
Коммит
4915bbf8f3
|
@ -113,6 +113,10 @@ QString Utility::octetsToString( qint64 octets )
|
|||
QString s;
|
||||
qreal value = octets;
|
||||
|
||||
// Whether we care about decimals: only for GB and only
|
||||
// if it's less than 10 GB.
|
||||
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
|
||||
|
@ -120,6 +124,7 @@ QString Utility::octetsToString( qint64 octets )
|
|||
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;
|
||||
|
@ -130,7 +135,13 @@ QString Utility::octetsToString( qint64 octets )
|
|||
s = QCoreApplication::translate("Utility", "%L1 B");
|
||||
}
|
||||
|
||||
return (value > 9.95) ? s.arg(qRound(value)) : s.arg(value, 0, 'g', 2);
|
||||
if (value > 9.95)
|
||||
round = true;
|
||||
|
||||
if (round)
|
||||
return s.arg(qRound(value));
|
||||
|
||||
return s.arg(value, 0, 'g', 2);
|
||||
}
|
||||
|
||||
// Qtified version of get_platforms() in csync_owncloud.c
|
||||
|
|
|
@ -31,14 +31,14 @@ private slots:
|
|||
QLocale::setDefault(QLocale("en"));
|
||||
QCOMPARE(octetsToString(999) , QString("999 B"));
|
||||
QCOMPARE(octetsToString(1024) , QString("1 KB"));
|
||||
QCOMPARE(octetsToString(1364) , QString("1.3 KB"));
|
||||
QCOMPARE(octetsToString(1364) , QString("1 KB"));
|
||||
|
||||
QCOMPARE(octetsToString(9110) , QString("8.9 KB"));
|
||||
QCOMPARE(octetsToString(9910) , QString("9.7 KB"));
|
||||
QCOMPARE(octetsToString(9110) , QString("9 KB"));
|
||||
QCOMPARE(octetsToString(9910) , QString("10 KB"));
|
||||
QCOMPARE(octetsToString(10240) , QString("10 KB"));
|
||||
|
||||
QCOMPARE(octetsToString(123456) , QString("121 KB"));
|
||||
QCOMPARE(octetsToString(1234567) , QString("1.2 MB"));
|
||||
QCOMPARE(octetsToString(1234567) , QString("1 MB"));
|
||||
QCOMPARE(octetsToString(12345678) , QString("12 MB"));
|
||||
QCOMPARE(octetsToString(123456789) , QString("118 MB"));
|
||||
QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("4.7 GB"));
|
||||
|
|
Загрузка…
Ссылка в новой задаче