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 */