aboutsummaryrefslogtreecommitdiff
path: root/src/ioutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ioutil.cpp')
-rw-r--r--src/ioutil.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ioutil.cpp b/src/ioutil.cpp
index 047a901..00caba6 100644
--- a/src/ioutil.cpp
+++ b/src/ioutil.cpp
@@ -14,3 +14,23 @@ bool IoUtil::writeAll(QIODevice &dst, QByteArray const & src)
return true;
}
+
+QString IoUtil::size_human(qint64 size)
+{
+ if(size < 1024)
+ return QString("%1 B").arg(size);
+
+ float num = size;
+ QStringList list;
+ list << "KB" << "MB" << "GB" << "TB";
+
+ QStringListIterator i(list);
+ QString unit("B");
+
+ while(num >= 1024.0 && i.hasNext())
+ {
+ unit = i.next();
+ num /= 1024.0;
+ }
+ return QString().setNum(num,'f',2)+" "+unit;
+}