Skip to content

Commit 1122590

Browse files
committed
Merge bitcoin-core/gui#309: Add access to the Peers tab from the network icon
d29ea72 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 d29ea72 kristapsk: re-ACK d29ea72 promag: Code review ACK d29ea72. Tree-SHA512: dd871415fe514a19c6a22100d58f31954d9e55b80585d5a3f26e17a8d51dadf912441786fc0d23beabd812f1b501658fec1dbe345cd41beae5832a8eda890f77
2 parents 8462cd5 + d29ea72 commit 1122590

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->setThemedPixmap(icon, 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
@@ -17,6 +17,7 @@
1717
#include <QLabel>
1818
#include <QMainWindow>
1919
#include <QMap>
20+
#include <QMenu>
2021
#include <QPoint>
2122
#include <QSystemTrayIcon>
2223

@@ -51,7 +52,6 @@ QT_BEGIN_NAMESPACE
5152
class QAction;
5253
class QComboBox;
5354
class QDateTime;
54-
class QMenu;
5555
class QProgressBar;
5656
class QProgressDialog;
5757
QT_END_NAMESPACE
@@ -175,6 +175,8 @@ class BitcoinGUI : public QMainWindow
175175
HelpMessageDialog* helpMessageDialog = nullptr;
176176
ModalOverlay* modalOverlay = nullptr;
177177

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

0 commit comments

Comments
 (0)