From 678b57227e5c163cfbe77444d2c8b39c357678c2 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 23 Apr 2021 14:57:05 +0200 Subject: [PATCH 1/4] gui: add Direction column to peers tab --- src/qt/peertablemodel.cpp | 7 +++++-- src/qt/peertablemodel.h | 4 +++- src/qt/peertablesortproxy.cpp | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp index 6c4e3260119..9c2313e2b8d 100644 --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -113,8 +113,10 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const case NetNodeId: return (qint64)rec->nodeStats.nodeid; case Address: - // prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection - return QString(rec->nodeStats.fInbound ? "↓ " : "↑ ") + QString::fromStdString(rec->nodeStats.addrName); + return QString::fromStdString(rec->nodeStats.addrName); + case Direction: + //: Connection direction. Also used in ConnectionTypeToQString() and CONNECTION_TYPE_DOC. + return QString(rec->nodeStats.fInbound ? tr("Inbound") : tr("Outbound")); case ConnectionType: return GUIUtil::ConnectionTypeToQString(rec->nodeStats.m_conn_type, /* prepend_direction */ false); case Network: @@ -134,6 +136,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const case NetNodeId: case Address: return {}; + case Direction: case ConnectionType: case Network: return QVariant(Qt::AlignCenter); diff --git a/src/qt/peertablemodel.h b/src/qt/peertablemodel.h index 9c7bc25da21..19361f0e17a 100644 --- a/src/qt/peertablemodel.h +++ b/src/qt/peertablemodel.h @@ -47,6 +47,7 @@ class PeerTableModel : public QAbstractTableModel enum ColumnIndex { NetNodeId = 0, Address, + Direction, ConnectionType, Network, Ping, @@ -74,7 +75,8 @@ public Q_SLOTS: private: interfaces::Node& m_node; - const QStringList columns{tr("Peer Id"), tr("Address"), tr("Type"), tr("Network"), tr("Ping"), tr("Sent"), tr("Received"), tr("User Agent")}; + /*: Column titles of the Peers tab window. */ + const QStringList columns{tr("Peer Id"), tr("Address"), tr("Direction"), tr("Type"), tr("Network"), tr("Ping"), tr("Sent"), tr("Received"), tr("User Agent")}; std::unique_ptr priv; QTimer *timer; }; diff --git a/src/qt/peertablesortproxy.cpp b/src/qt/peertablesortproxy.cpp index 78932da8d48..f92eef48f10 100644 --- a/src/qt/peertablesortproxy.cpp +++ b/src/qt/peertablesortproxy.cpp @@ -26,6 +26,8 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd return left_stats.nodeid < right_stats.nodeid; case PeerTableModel::Address: return left_stats.addrName.compare(right_stats.addrName) < 0; + case PeerTableModel::Direction: + return left_stats.fInbound > right_stats.fInbound; // default sort Inbound, then Outbound case PeerTableModel::ConnectionType: return left_stats.m_conn_type < right_stats.m_conn_type; case PeerTableModel::Network: From 842f4e834dfe5fd2786a5092f78ea28da1b36e4f Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 25 Apr 2021 15:34:29 +0200 Subject: [PATCH 2/4] gui: improve connection type translations and translator comments --- src/qt/guiutil.cpp | 2 ++ src/qt/rpcconsole.cpp | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index d10bf9f9aeb..d498f271d3e 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -666,10 +666,12 @@ QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction { QString prefix; if (prepend_direction) { + //: Connection direction. Also used in CONNECTION_TYPE_DOC and PeerTableModel::data(). prefix = (conn_type == ConnectionType::INBOUND) ? QObject::tr("Inbound") : QObject::tr("Outbound") + " "; } switch (conn_type) { case ConnectionType::INBOUND: return prefix; + //: The connection types (Full Relay, Block Relay, Manual, Feeler, Address Fetch) are also used in CONNECTION_TYPE_DOC. case ConnectionType::OUTBOUND_FULL_RELAY: return prefix + QObject::tr("Full Relay"); case ConnectionType::BLOCK_RELAY: return prefix + QObject::tr("Block Relay"); case ConnectionType::MANUAL: return prefix + QObject::tr("Manual"); diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 006f60e7a1c..7fafb290058 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -37,12 +37,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -53,6 +55,9 @@ const int INITIAL_TRAFFIC_GRAPH_MINS = 30; const QSize FONT_RANGE(4, 40); const char fontSizeSettingsKey[] = "consoleFontSize"; +const QLatin1String COLON_SPACE{": "}; +const QLatin1String SPACE{" "}; + const struct { const char *url; const char *source; @@ -463,16 +468,18 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty constexpr QChar nonbreaking_hyphen(8209); const std::vector CONNECTION_TYPE_DOC{ - tr("Inbound: initiated by peer"), - tr("Outbound Full Relay: default"), - tr("Outbound Block Relay: does not relay transactions or addresses"), - tr("Outbound Manual: added using RPC %1 or %2/%3 configuration options") + //: The connection direction (Inbound/Outbound) is also used in ConnectionTypeToQString() and PeerTableModel::data(). + //: The connection types (Full Relay, Block Relay, Manual, Feeler, Address Fetch) are also used in ConnectionTypeToQString(). + tr("Inbound") % COLON_SPACE % tr("initiated by peer"), + tr("Outbound") % SPACE % tr("Full Relay") % COLON_SPACE % tr("default"), + tr("Outbound") % SPACE % tr("Block Relay") % COLON_SPACE % tr("does not relay transactions or addresses"), + tr("Outbound") % SPACE % tr("Manual") % COLON_SPACE % tr("added using RPC %1 or %2/%3 configuration options") .arg("addnode") - .arg(QString(nonbreaking_hyphen) + "addnode") - .arg(QString(nonbreaking_hyphen) + "connect"), - tr("Outbound Feeler: short-lived, for testing addresses"), - tr("Outbound Address Fetch: short-lived, for soliciting addresses")}; - const QString list{"
  • " + Join(CONNECTION_TYPE_DOC, QString("
  • ")) + "
"}; + .arg(QString(nonbreaking_hyphen) % "addnode") + .arg(QString(nonbreaking_hyphen) % "connect"), + tr("Outbound") % SPACE % tr("Feeler") % COLON_SPACE % tr("short-lived, for testing addresses"), + tr("Outbound") % SPACE % tr("Address Fetch") % COLON_SPACE % tr("short-lived, for soliciting addresses")}; + const QString list{"
  • " % Join(CONNECTION_TYPE_DOC, QString("
  • ")) % "
"}; ui->peerConnectionTypeLabel->setToolTip(ui->peerConnectionTypeLabel->toolTip().arg(list)); const QString hb_list{"
  • \"" + ts.to + "\" – " + tr("we selected the peer for high bandwidth relay") + "
  • \"" From ad92e049680ceb4aaaa5805fb0ad7897dc157974 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 25 Apr 2021 17:35:32 +0200 Subject: [PATCH 3/4] gui: use SPACE constant, QStringBuilder concat in rpcconsole.cpp --- src/qt/rpcconsole.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 7fafb290058..288aa5f14bc 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -482,9 +482,9 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty const QString list{"
    • " % Join(CONNECTION_TYPE_DOC, QString("
    • ")) % "
    "}; ui->peerConnectionTypeLabel->setToolTip(ui->peerConnectionTypeLabel->toolTip().arg(list)); const QString hb_list{"
    • \"" - + ts.to + "\" – " + tr("we selected the peer for high bandwidth relay") + "
    • \"" - + ts.from + "\" – " + tr("the peer selected us for high bandwidth relay") + "
    • \"" - + ts.no + "\" – " + tr("no high bandwidth relay selected") + "
    "}; + % ts.to % "\" – " % tr("we selected the peer for high bandwidth relay") % "
  • \"" + % ts.from % "\" – " % tr("the peer selected us for high bandwidth relay") % "
  • \"" + % ts.no % "\" – " % tr("no high bandwidth relay selected") % "
"}; ui->peerHighBandwidthLabel->setToolTip(ui->peerHighBandwidthLabel->toolTip().arg(hb_list)); ui->dataDir->setToolTip(ui->dataDir->toolTip().arg(QString(nonbreaking_hyphen) + "datadir")); ui->blocksDir->setToolTip(ui->blocksDir->toolTip().arg(QString(nonbreaking_hyphen) + "blocksdir")); @@ -627,10 +627,10 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ // create peer table context menu peersTableContextMenu = new QMenu(this); peersTableContextMenu->addAction(tr("Disconnect"), this, &RPCConsole::disconnectSelectedNode); - peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 hour"), [this] { banSelectedNode(60 * 60); }); - peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 day"), [this] { banSelectedNode(60 * 60 * 24); }); - peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 week"), [this] { banSelectedNode(60 * 60 * 24 * 7); }); - peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 year"), [this] { banSelectedNode(60 * 60 * 24 * 365); }); + peersTableContextMenu->addAction(ts.ban_for % SPACE % tr("1 hour"), [this] { banSelectedNode(60 * 60); }); + peersTableContextMenu->addAction(ts.ban_for % SPACE % tr("1 day"), [this] { banSelectedNode(60 * 60 * 24); }); + peersTableContextMenu->addAction(ts.ban_for % SPACE % tr("1 week"), [this] { banSelectedNode(60 * 60 * 24 * 7); }); + peersTableContextMenu->addAction(ts.ban_for % SPACE % tr("1 year"), [this] { banSelectedNode(60 * 60 * 24 * 365); }); connect(ui->peerWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showPeersTableContextMenu); // peer table signal handling - update peer details when selecting new node @@ -842,12 +842,12 @@ void RPCConsole::message(int category, const QString &message, bool html) void RPCConsole::updateNetworkState() { - QString connections = QString::number(clientModel->getNumConnections()) + " ("; - connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / "; - connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")"; + QString connections = QString::number(clientModel->getNumConnections()) % " ("; + connections += tr("In:") % SPACE % QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) % " / "; + connections += tr("Out:") % SPACE % QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) % ")"; if(!clientModel->node().getNetworkActive()) { - connections += " (" + tr("Network activity disabled") + ")"; + connections += " (" % tr("Network activity disabled") % ")"; } ui->numberOfConnections->setText(connections); @@ -1029,7 +1029,7 @@ void RPCConsole::updateDetailWidget() } const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value(); // update the detail ui with latest node information - QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " "); + QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) % SPACE); peerAddrDetails += tr("(peer id: %1)").arg(QString::number(stats->nodeStats.nodeid)); if (!stats->nodeStats.addrLocal.empty()) peerAddrDetails += "
" + tr("via %1").arg(QString::fromStdString(stats->nodeStats.addrLocal)); From 2bf3f5aee014ab4e0ff72e6bdbb33ada02dec314 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 25 Apr 2021 17:36:39 +0200 Subject: [PATCH 4/4] gui: add missing QLatin1String, QStringBuilder headers --- src/qt/addressbookpage.cpp | 1 + src/qt/psbtoperationsdialog.cpp | 2 ++ src/qt/qrimagewidget.cpp | 1 + src/qt/sendcoinsdialog.cpp | 1 + src/qt/transactionview.cpp | 1 + src/qt/walletview.cpp | 1 + 6 files changed, 7 insertions(+) diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index a816a0764c0..ffbca91c39a 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include diff --git a/src/qt/psbtoperationsdialog.cpp b/src/qt/psbtoperationsdialog.cpp index 17746b395b6..2bf3615a432 100644 --- a/src/qt/psbtoperationsdialog.cpp +++ b/src/qt/psbtoperationsdialog.cpp @@ -17,6 +17,8 @@ #include +#include + PSBTOperationsDialog::PSBTOperationsDialog( QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags), diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index df6757ffd67..3447f772be3 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index e1a4faa266f..ee89b2a433c 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 890d1a1740f..9778f7af8ec 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 86128936837..2c9e666131f 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include