[Pkg-owncloud-commits] [owncloud-client] 224/470: Adjust size description strings #3403

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:25:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 4915bbf8f342b7225f215fd9b0d3fb252c843b9e
Author: Christian Kamm <mail at ckamm.de>
Date:   Thu Jan 21 09:50:32 2016 +0100

    Adjust size description strings #3403
    
    @jancorchardt suggested to not have decimal places on file
    sizes, except for GB.
---
 src/libsync/utility.cpp | 13 ++++++++++++-
 test/testutility.h      |  8 ++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/libsync/utility.cpp b/src/libsync/utility.cpp
index 6fca882..613c7af 100644
--- a/src/libsync/utility.cpp
+++ b/src/libsync/utility.cpp
@@ -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
diff --git a/test/testutility.h b/test/testutility.h
index e8ce075..bc7cc4d 100644
--- a/test/testutility.h
+++ b/test/testutility.h
@@ -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"));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list