From 8e4aa35ffbcaa0e0a3eceaa500193b0f97d957ab Mon Sep 17 00:00:00 2001 From: Aaron Golliver Date: Sat, 14 Oct 2017 16:06:21 -0700 Subject: move human-readable byte formatting to guiutil --- src/qt/guiutil.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/qt/guiutil.cpp') diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index d520d7d4be..4bd63f4649 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -984,6 +984,18 @@ QString formatNiceTimeOffset(qint64 secs) return timeBehindText; } +QString formatBytes(uint64_t bytes) +{ + if(bytes < 1024) + return QString(QObject::tr("%1 B")).arg(bytes); + if(bytes < 1024 * 1024) + return QString(QObject::tr("%1 KB")).arg(bytes / 1024); + if(bytes < 1024 * 1024 * 1024) + return QString(QObject::tr("%1 MB")).arg(bytes / 1024 / 1024); + + return QString(QObject::tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024); +} + void ClickableLabel::mouseReleaseEvent(QMouseEvent *event) { Q_EMIT clicked(event->pos()); -- cgit v1.2.3