Skip to content

Commit 0f46e73

Browse files
committed
Merge #543: peers-tab: add connection duration column to tableview
51708c4 gui: peersWidget - ResizeToContents Age and IP/Netmask columns (randymcmillan) 209301a gui: add Age column to peers tab (randymcmillan) 127de22 gui: add FormatPeerAge() utility helper (Jon Atack) Pull request description: This change adds an "Age" column to the peers table view, which displays the duration of each peer's connection. ACKs for top commit: jonatack: re-ACK 51708c4 Jamewood: > re-ACK 51708c4 shaavan: reACK 51708c4 hebasto: ACK 51708c4, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 27323f7080ec0d3fcdbf1b190fba1cd2d7406840ab6607c221cf8af950db9134e22721cc5a88f4fc4f390d8b05e98bc4b7521661a31fadad9e2c6c6390e71788
2 parents 2b5a741 + 51708c4 commit 0f46e73

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

src/qt/guiutil.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
void ForceActivation();
8181
#endif
8282

83+
using namespace std::chrono_literals;
84+
8385
namespace GUIUtil {
8486

8587
QString dateTimeStr(const QDateTime &date)
@@ -728,6 +730,16 @@ QString formatDurationStr(std::chrono::seconds dur)
728730
return str_list.join(" ");
729731
}
730732

733+
QString FormatPeerAge(std::chrono::seconds time_connected)
734+
{
735+
const auto time_now{GetTime<std::chrono::seconds>()};
736+
const auto age{time_now - time_connected};
737+
if (age >= 24h) return QObject::tr("%1 d").arg(age / 24h);
738+
if (age >= 1h) return QObject::tr("%1 h").arg(age / 1h);
739+
if (age >= 1min) return QObject::tr("%1 m").arg(age / 1min);
740+
return QObject::tr("%1 s").arg(age / 1s);
741+
}
742+
731743
QString formatServicesStr(quint64 mask)
732744
{
733745
QStringList strList;

src/qt/guiutil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ namespace GUIUtil
223223
/** Convert seconds into a QString with days, hours, mins, secs */
224224
QString formatDurationStr(std::chrono::seconds dur);
225225

226+
/** Convert peer connection time to a QString denominated in the most relevant unit. */
227+
QString FormatPeerAge(std::chrono::seconds time_connected);
228+
226229
/** Format CNodeStats.nServices bitmask into a user-readable string */
227230
QString formatServicesStr(quint64 mask);
228231

src/qt/peertablemodel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
7171
switch (column) {
7272
case NetNodeId:
7373
return (qint64)rec->nodeStats.nodeid;
74+
case Age:
75+
return GUIUtil::FormatPeerAge(rec->nodeStats.m_connected);
7476
case Address:
7577
return QString::fromStdString(rec->nodeStats.m_addr_name);
7678
case Direction:
@@ -96,6 +98,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
9698
} else if (role == Qt::TextAlignmentRole) {
9799
switch (column) {
98100
case NetNodeId:
101+
case Age:
99102
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
100103
case Address:
101104
return {};

src/qt/peertablemodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class PeerTableModel : public QAbstractTableModel
4747

4848
enum ColumnIndex {
4949
NetNodeId = 0,
50+
Age,
5051
Address,
5152
Direction,
5253
ConnectionType,
@@ -82,6 +83,9 @@ public Q_SLOTS:
8283
/*: Title of Peers Table column which contains a
8384
unique number used to identify a connection. */
8485
tr("Peer"),
86+
/*: Title of Peers Table column which indicates the duration (length of time)
87+
since the peer connection started. */
88+
tr("Age"),
8589
/*: Title of Peers Table column which contains the
8690
IP/Onion/I2P address of the connected peer. */
8791
tr("Address"),

src/qt/peertablesortproxy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
2424
switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
2525
case PeerTableModel::NetNodeId:
2626
return left_stats.nodeid < right_stats.nodeid;
27+
case PeerTableModel::Age:
28+
return left_stats.m_connected > right_stats.m_connected;
2729
case PeerTableModel::Address:
2830
return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
2931
case PeerTableModel::Direction:

src/qt/rpcconsole.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
694694
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
695695
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
696696
}
697+
ui->peerWidget->horizontalHeader()->setSectionResizeMode(PeerTableModel::Age, QHeaderView::ResizeToContents);
697698
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
698699
ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
699700

@@ -726,6 +727,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
726727
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
727728
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
728729
}
730+
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(BanTableModel::Address, QHeaderView::ResizeToContents);
729731
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
730732

731733
// create ban table context menu

0 commit comments

Comments
 (0)