Skip to content

Commit d29ea72

Browse files
committed
gui: Add access to the Peers tab from the network icon
1 parent d22e7ee commit d29ea72

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/qt/bitcoingui.cpp

+28-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <QAction>
4444
#include <QApplication>
4545
#include <QComboBox>
46+
#include <QCursor>
4647
#include <QDateTime>
4748
#include <QDragEnterEvent>
4849
#include <QListWidget>
@@ -199,9 +200,6 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
199200
// Subscribe to notifications from core
200201
subscribeToCoreSignals();
201202

202-
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, [this] {
203-
m_node.setNetworkActive(!m_node.getNetworkActive());
204-
});
205203
connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
206204
openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
207205
});
@@ -586,7 +584,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
586584
createTrayIconMenu();
587585

588586
// Keep up to date with client
589-
updateNetworkState();
587+
setNetworkActive(m_node.getNetworkActive());
588+
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, [this] {
589+
GUIUtil::PopupMenu(m_network_context_menu, QCursor::pos());
590+
});
590591
connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections);
591592
connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive);
592593

@@ -915,14 +916,18 @@ void BitcoinGUI::updateNetworkState()
915916
QString tooltip;
916917

917918
if (m_node.getNetworkActive()) {
918-
tooltip = tr("%n active connection(s) to Bitcoin network", "", count) + QString(".<br>") + tr("Click to disable network activity.");
919+
//: A substring of the tooltip.
920+
tooltip = tr("%n active connection(s) to Bitcoin network.", "", count);
919921
} else {
920-
tooltip = tr("Network activity disabled.") + QString("<br>") + tr("Click to enable network activity again.");
922+
//: A substring of the tooltip.
923+
tooltip = tr("Network activity disabled.");
921924
icon = ":/icons/network_disabled";
922925
}
923926

924927
// Don't word-wrap this (fixed-width) tooltip
925-
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
928+
tooltip = QLatin1String("<nobr>") + tooltip + QLatin1String("<br>") +
929+
//: A substring of the tooltip. "More actions" are available via the context menu.
930+
tr("Click for more actions.") + QLatin1String("</nobr>");
926931
connectionsControl->setToolTip(tooltip);
927932

928933
connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
@@ -933,9 +938,24 @@ void BitcoinGUI::setNumConnections(int count)
933938
updateNetworkState();
934939
}
935940

936-
void BitcoinGUI::setNetworkActive(bool networkActive)
941+
void BitcoinGUI::setNetworkActive(bool network_active)
937942
{
938943
updateNetworkState();
944+
m_network_context_menu->clear();
945+
m_network_context_menu->addAction(
946+
//: A context menu item. The "Peers tab" is an element of the "Node window".
947+
tr("Show Peers tab"),
948+
[this] {
949+
rpcConsole->setTabFocus(RPCConsole::TabTypes::PEERS);
950+
showDebugWindow();
951+
});
952+
m_network_context_menu->addAction(
953+
network_active ?
954+
//: A context menu item.
955+
tr("Disable network activity") :
956+
//: A context menu item. The network activity was disabled previously.
957+
tr("Enable network activity"),
958+
[this, new_state = !network_active] { m_node.setNetworkActive(new_state); });
939959
}
940960

941961
void BitcoinGUI::updateHeadersSyncProgressLabel()

src/qt/bitcoingui.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QLabel>
1717
#include <QMainWindow>
1818
#include <QMap>
19+
#include <QMenu>
1920
#include <QPoint>
2021
#include <QSystemTrayIcon>
2122

@@ -50,7 +51,6 @@ QT_BEGIN_NAMESPACE
5051
class QAction;
5152
class QComboBox;
5253
class QDateTime;
53-
class QMenu;
5454
class QProgressBar;
5555
class QProgressDialog;
5656
QT_END_NAMESPACE
@@ -174,6 +174,8 @@ class BitcoinGUI : public QMainWindow
174174
HelpMessageDialog* helpMessageDialog = nullptr;
175175
ModalOverlay* modalOverlay = nullptr;
176176

177+
QMenu* m_network_context_menu = new QMenu(this);
178+
177179
#ifdef Q_OS_MAC
178180
CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
179181
#endif
@@ -221,7 +223,7 @@ public Q_SLOTS:
221223
/** Set number of connections shown in the UI */
222224
void setNumConnections(int count);
223225
/** Set network state shown in the UI */
224-
void setNetworkActive(bool networkActive);
226+
void setNetworkActive(bool network_active);
225227
/** Set number of blocks and last block date shown in the UI */
226228
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state);
227229

0 commit comments

Comments
 (0)