aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.cpp
diff options
context:
space:
mode:
authorchromatic <[email protected]>2021-06-03 18:37:38 -0700
committerchromatic <[email protected]>2021-06-08 10:13:37 -0700
commitc5165e9b8311d07df0ea9914a04596e145a2a552 (patch)
tree4f53c55ae76822ebaabbffe456c6f26c365d0832 /src/qt/guiutil.cpp
parentMerge pull request #2111 from rnicoll/contributing (diff)
downloaddiscoin-c5165e9b8311d07df0ea9914a04596e145a2a552.tar.xz
discoin-c5165e9b8311d07df0ea9914a04596e145a2a552.zip
Add sortable sent/recv bytes to Peers debug table
See GH #2240.
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r--src/qt/guiutil.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 6912b9312..cfd5b0e98 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -1,4 +1,5 @@
// Copyright (c) 2011-2016 The Bitcoin Core developers
+// Copyright (c) 2021 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -941,6 +942,38 @@ QString formatPingTime(double dPingTime)
return (dPingTime == std::numeric_limits<int64_t>::max()/1e6 || dPingTime == 0) ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(dPingTime * 1000), 10));
}
+QString formatDataSizeValue(uint64_t uValue)
+{
+ // Why handle these comparisons directly, instead of a clever algorithm?
+ // This is likely to be called in a tight loop, so avoid the overhead of
+ // setting up a constant list and walking an iterator.
+ static const uint64_t TERABYTE_SIZE = UINT64_C(1024*1024*1024*1024);
+ static const uint64_t GIGABYTE_SIZE = UINT64_C(1024*1024*1024);
+ static const uint64_t MEGABYTE_SIZE = UINT64_C(1024*1024);
+ static const uint64_t KILOBYTE_SIZE = UINT64_C(1024);
+
+ QString unitFormat = QObject::tr("%1 B");
+
+ if (uValue == std::numeric_limits<int64_t>::max()/1e6 || uValue == 0)
+ return QObject::tr("N/A");
+
+ if (uValue > TERABYTE_SIZE) {
+ unitFormat = QObject::tr("%1 TB");
+ uValue /= TERABYTE_SIZE;
+ } else if (uValue > GIGABYTE_SIZE) {
+ unitFormat = QObject::tr("%1 GB");
+ uValue /= GIGABYTE_SIZE;
+ } else if (uValue > MEGABYTE_SIZE) {
+ unitFormat = QObject::tr("%1 MB");
+ uValue /= MEGABYTE_SIZE;
+ } else if (uValue > KILOBYTE_SIZE) {
+ unitFormat = QObject::tr("%1 KB");
+ uValue /= KILOBYTE_SIZE;
+ }
+
+ return QString(unitFormat).arg(QString::number(uValue), 10);
+}
+
QString formatTimeOffset(int64_t nTimeOffset)
{
return QString(QObject::tr("%1 s")).arg(QString::number((int)nTimeOffset, 10));