From 69a1305978a65978feae17e1a5715b4b70f82e91 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 31 May 2021 19:34:28 +0300 Subject: [PATCH] Merge bitcoin-core/gui#309: Add access to the Peers tab from the network icon d29ea72393ac1d9b32a6976062e9c9fb75876295 gui: Add access to the Peers tab from the network icon (Hennadii Stepanov) Pull request description: This PR add a small context menu to the network activity icon that provides an access to the Peers tab: ![gui-network-icon](https://user-images.githubusercontent.com/32963518/116794314-d64b9b80-aad4-11eb-89ca-7f75c7442ba8.gif) Closes #93. ACKs for top commit: Sjors: re-ACK d29ea72393ac1d9b32a6976062e9c9fb75876295 kristapsk: re-ACK d29ea72393ac1d9b32a6976062e9c9fb75876295 promag: Code review ACK d29ea72393ac1d9b32a6976062e9c9fb75876295. Tree-SHA512: dd871415fe514a19c6a22100d58f31954d9e55b80585d5a3f26e17a8d51dadf912441786fc0d23beabd812f1b501658fec1dbe345cd41beae5832a8eda890f77 --- src/qt/bitcoingui.cpp | 37 +++++++++++++++++++++++++++++++------ src/qt/bitcoingui.h | 6 ++++-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5191b1d17d..cc8af5afc9 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -211,8 +212,6 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, // Subscribe to notifications from core subscribeToCoreSignals(); - // Jump to peers tab by clicking on connections icon - connect(labelConnectionsIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showPeers); connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] { openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK); }); @@ -812,8 +811,11 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH } // Keep up to date with client - updateNetworkState(); + setNetworkActive(m_node.getNetworkActive()); setNumConnections(_clientModel->getNumConnections()); + connect(labelConnectionsIcon, &GUIUtil::ClickableLabel::clicked, [this] { + GUIUtil::PopupMenu(m_network_context_menu, QCursor::pos()); + }); connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections); connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive); @@ -1270,14 +1272,21 @@ void BitcoinGUI::updateNetworkState() nCountPrev = count; fNetworkActivePrev = fNetworkActive; + QString tooltip; if (fNetworkActive) { - labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Dash network", "", count)); + //: A substring of the tooltip. + tooltip = tr("%n active connection(s) to Dash network", "", count); } else { - labelConnectionsIcon->setToolTip(tr("Network activity disabled")); + tooltip = tr("Network activity disabled"); icon = "connect_4"; color = GUIUtil::ThemedColor::RED; } + // Don't word-wrap this (fixed-width) tooltip + tooltip = QLatin1String("") + tooltip + QLatin1String("
") + + //: A substring of the tooltip. "More actions" are available via the context menu. + tr("Click for more actions.") + QLatin1String("
"); + if (fNetworkActive && count == 0) { startConnectingAnimation(); } @@ -1285,6 +1294,7 @@ void BitcoinGUI::updateNetworkState() stopConnectingAnimation(); labelConnectionsIcon->setPixmap(GUIUtil::getIcon(icon, color).pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); } + labelConnectionsIcon->setToolTip(tooltip); } void BitcoinGUI::setNumConnections(int count) @@ -1292,9 +1302,24 @@ void BitcoinGUI::setNumConnections(int count) updateNetworkState(); } -void BitcoinGUI::setNetworkActive(bool networkActive) +void BitcoinGUI::setNetworkActive(bool network_active) { updateNetworkState(); + m_network_context_menu->clear(); + m_network_context_menu->addAction( + //: A context menu item. The "Peers tab" is an element of the "Node window". + tr("Show Peers tab"), + [this] { + rpcConsole->setTabFocus(RPCConsole::TabTypes::PEERS); + showDebugWindow(); + }); + m_network_context_menu->addAction( + network_active ? + //: A context menu item. + tr("Disable network activity") : + //: A context menu item. The network activity was disabled previously. + tr("Enable network activity"), + [this, new_state = !network_active] { m_node.setNetworkActive(new_state); }); } void BitcoinGUI::updateHeadersSyncProgressLabel() diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 5831ed3715..7b86531fbe 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,6 @@ class QAction; class QButtonGroup; class QComboBox; class QDateTime; -class QMenu; class QProgressBar; class QProgressDialog; class QToolButton; @@ -190,6 +190,8 @@ private: ModalOverlay* modalOverlay = nullptr; QButtonGroup* tabGroup = nullptr; + QMenu* m_network_context_menu = new QMenu(this); + #ifdef Q_OS_MAC CAppNapInhibitor* m_app_nap_inhibitor = nullptr; #endif @@ -264,7 +266,7 @@ public Q_SLOTS: /** Set number of connections shown in the UI */ void setNumConnections(int count); /** Set network state shown in the UI */ - void setNetworkActive(bool networkActive); + void setNetworkActive(bool network_active); /** Get restart command-line parameters and request restart */ void handleRestart(QStringList args); /** Set number of blocks and last block date shown in the UI */