Merge bitcoin-core/gui#543: peers-tab: add connection duration column to tableview
51708c4516gui: peersWidget - ResizeToContents Age and IP/Netmask columns (randymcmillan)209301a442gui: add Age column to peers tab (randymcmillan)127de22c5fgui: 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-ACK51708c4516Jamewood: > re-ACK51708c4shaavan: reACK51708c4516hebasto: ACK51708c4516, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 27323f7080ec0d3fcdbf1b190fba1cd2d7406840ab6607c221cf8af950db9134e22721cc5a88f4fc4f390d8b05e98bc4b7521661a31fadad9e2c6c6390e71788
This commit is contained in:
6 files changed
+26
No files matched your search
@@ -80,6 +80,8 @@
|
|||||||
void ForceActivation();
|
void ForceActivation();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace GUIUtil {
|
namespace GUIUtil {
|
||||||
|
|
||||||
QString dateTimeStr(const QDateTime &date)
|
QString dateTimeStr(const QDateTime &date)
|
||||||
@@ -728,6 +730,16 @@ QString formatDurationStr(std::chrono::seconds dur)
|
|||||||
return str_list.join(" ");
|
return str_list.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FormatPeerAge(std::chrono::seconds time_connected)
|
||||||
|
{
|
||||||
|
const auto time_now{GetTime<std::chrono::seconds>()};
|
||||||
|
const auto age{time_now - time_connected};
|
||||||
|
if (age >= 24h) return QObject::tr("%1 d").arg(age / 24h);
|
||||||
|
if (age >= 1h) return QObject::tr("%1 h").arg(age / 1h);
|
||||||
|
if (age >= 1min) return QObject::tr("%1 m").arg(age / 1min);
|
||||||
|
return QObject::tr("%1 s").arg(age / 1s);
|
||||||
|
}
|
||||||
|
|
||||||
QString formatServicesStr(quint64 mask)
|
QString formatServicesStr(quint64 mask)
|
||||||
{
|
{
|
||||||
QStringList strList;
|
QStringList strList;
|
||||||
|
|||||||
@@ -223,6 +223,9 @@ namespace GUIUtil
|
|||||||
/** Convert seconds into a QString with days, hours, mins, secs */
|
/** Convert seconds into a QString with days, hours, mins, secs */
|
||||||
QString formatDurationStr(std::chrono::seconds dur);
|
QString formatDurationStr(std::chrono::seconds dur);
|
||||||
|
|
||||||
|
/** Convert peer connection time to a QString denominated in the most relevant unit. */
|
||||||
|
QString FormatPeerAge(std::chrono::seconds time_connected);
|
||||||
|
|
||||||
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
||||||
QString formatServicesStr(quint64 mask);
|
QString formatServicesStr(quint64 mask);
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
|
|||||||
switch (column) {
|
switch (column) {
|
||||||
case NetNodeId:
|
case NetNodeId:
|
||||||
return (qint64)rec->nodeStats.nodeid;
|
return (qint64)rec->nodeStats.nodeid;
|
||||||
|
case Age:
|
||||||
|
return GUIUtil::FormatPeerAge(rec->nodeStats.m_connected);
|
||||||
case Address:
|
case Address:
|
||||||
return QString::fromStdString(rec->nodeStats.m_addr_name);
|
return QString::fromStdString(rec->nodeStats.m_addr_name);
|
||||||
case Direction:
|
case Direction:
|
||||||
@@ -96,6 +98,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
|
|||||||
} else if (role == Qt::TextAlignmentRole) {
|
} else if (role == Qt::TextAlignmentRole) {
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case NetNodeId:
|
case NetNodeId:
|
||||||
|
case Age:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case Address:
|
case Address:
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public:
|
|||||||
|
|
||||||
enum ColumnIndex {
|
enum ColumnIndex {
|
||||||
NetNodeId = 0,
|
NetNodeId = 0,
|
||||||
|
Age,
|
||||||
Address,
|
Address,
|
||||||
Direction,
|
Direction,
|
||||||
ConnectionType,
|
ConnectionType,
|
||||||
@@ -82,6 +83,9 @@ private:
|
|||||||
/*: Title of Peers Table column which contains a
|
/*: Title of Peers Table column which contains a
|
||||||
unique number used to identify a connection. */
|
unique number used to identify a connection. */
|
||||||
tr("Peer"),
|
tr("Peer"),
|
||||||
|
/*: Title of Peers Table column which indicates the duration (length of time)
|
||||||
|
since the peer connection started. */
|
||||||
|
tr("Age"),
|
||||||
/*: Title of Peers Table column which contains the
|
/*: Title of Peers Table column which contains the
|
||||||
IP/Onion/I2P address of the connected peer. */
|
IP/Onion/I2P address of the connected peer. */
|
||||||
tr("Address"),
|
tr("Address"),
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
|
|||||||
switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
|
switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
|
||||||
case PeerTableModel::NetNodeId:
|
case PeerTableModel::NetNodeId:
|
||||||
return left_stats.nodeid < right_stats.nodeid;
|
return left_stats.nodeid < right_stats.nodeid;
|
||||||
|
case PeerTableModel::Age:
|
||||||
|
return left_stats.m_connected > right_stats.m_connected;
|
||||||
case PeerTableModel::Address:
|
case PeerTableModel::Address:
|
||||||
return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
|
return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
|
||||||
case PeerTableModel::Direction:
|
case PeerTableModel::Direction:
|
||||||
|
|||||||
@@ -694,6 +694,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
|
|||||||
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
|
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
|
||||||
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
||||||
}
|
}
|
||||||
|
ui->peerWidget->horizontalHeader()->setSectionResizeMode(PeerTableModel::Age, QHeaderView::ResizeToContents);
|
||||||
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
|
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
|
||||||
ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
|
ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
|
||||||
|
|
||||||
@@ -726,6 +727,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
|
|||||||
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
|
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
|
||||||
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
|
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
|
||||||
}
|
}
|
||||||
|
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(BanTableModel::Address, QHeaderView::ResizeToContents);
|
||||||
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
|
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
|
||||||
// create ban table context menu
|
// create ban table context menu
|
||||||
|
|||||||
Reference in new issue
Block a user