Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
void ForceActivation();
#endif

using namespace std::chrono_literals;

namespace GUIUtil {

QString dateTimeStr(const QDateTime &date)
Expand Down Expand Up @@ -727,6 +729,16 @@ QString formatDurationStr(std::chrono::seconds dur)
return str_list.join(" ");
}

QString FormatPeerAge(std::chrono::seconds time_connected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abf93dd

I think this could be idempotent QString FormatAge(std::chrono::seconds age), to avoid GetTime.

Note that PeerTableModel has a timer to refresh the data, just call GetTime once there.

Copy link
Member

@jonatack jonatack Mar 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promag I agree this would be an improvement and am looking into it, but am not sure how to integrate GetTime into the peertablemodel.cpp QTimer code. Pointers welcome.

{
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)
{
QStringList strList;
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ namespace GUIUtil
/** Convert seconds into a QString with days, hours, mins, secs */
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 */
QString formatServicesStr(quint64 mask);

Expand Down
3 changes: 3 additions & 0 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
switch (column) {
case NetNodeId:
return (qint64)rec->nodeStats.nodeid;
case Age:
return GUIUtil::FormatPeerAge(rec->nodeStats.m_connected);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

852b036

Following my previous comment, this could be

return GUIUtil::FormatAge(m_now - rec->nodeStats.m_connected);

case Address:
return QString::fromStdString(rec->nodeStats.m_addr_name);
case Direction:
Expand All @@ -96,6 +98,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
} else if (role == Qt::TextAlignmentRole) {
switch (column) {
case NetNodeId:
case Age:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case Address:
return {};
Expand Down
4 changes: 4 additions & 0 deletions src/qt/peertablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PeerTableModel : public QAbstractTableModel

enum ColumnIndex {
NetNodeId = 0,
Age,
Address,
Direction,
ConnectionType,
Expand Down Expand Up @@ -82,6 +83,9 @@ public Q_SLOTS:
/*: Title of Peers Table column which contains a
unique number used to identify a connection. */
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
IP/Onion/I2P address of the connected peer. */
tr("Address"),
Expand Down
2 changes: 2 additions & 0 deletions src/qt/peertablesortproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
case PeerTableModel::NetNodeId:
return left_stats.nodeid < right_stats.nodeid;
case PeerTableModel::Age:
return left_stats.m_connected > right_stats.m_connected;
case PeerTableModel::Address:
return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
case PeerTableModel::Direction:
Expand Down
2 changes: 2 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_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->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));

Expand Down Expand Up @@ -725,6 +726,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
}
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(BanTableModel::Address, QHeaderView::ResizeToContents);
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);

// create ban table context menu
Expand Down