This PR add a small context menu to the network activity icon that provides an access to the Peers tab:
Closes #93.
953+ m_network_context_menu->addAction(
954+ network_active ?
955+ //: A context menu item.
956+ tr("Disable network activity") :
957+ //: A context menu item. The network activity was disabled previously.
958+ tr("Enable network activity again"),
tACK a7f5ea589fb7a6eddca3e060eade403b2dd6ff87
Tested on macOS 11.3 Qt 5.15.2, Also tested with -disablewallet=1
.
This is ok to merge as-is. But, wanted to document how I think this should be changed around as part of a follow-up.
The ‘Peers Tab’ is for seeing your connected Peers and interacting with them, such as banning or disconnecting a peer.
The idea of “Disabling Network Activity” should be tied to the ‘Network Traffic Tab’ not the ‘Peers Tab’. This means we could add a “Disable Network Activity” button to the Network Traffic tab and a ‘Network Traffic’ widget next to the ‘Connection Count’ widget. Pressing this ‘Network Traffic’ widget would open the ‘Network Traffic’ tab where the user has the option of disabling network activity.
583@@ -586,7 +584,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
584 createTrayIconMenu();
585
586 // Keep up to date with client
587- updateNetworkState();
588+ setNetworkActive(m_node.getNetworkActive());
589+ connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, [this] {
590+ m_network_context_menu->exec(QCursor::pos());
QMenu::exec
is blocking. If you want to keep this approach then you could declare a local QMenu
instance instead - this way you can ditch the class member and the call to .clear()
.
It would be great if a key combo was added to this functionality… Maybe:
COMMAND + OPTION <W>
or <N>
would work.
It would be great if a key combo was added to this functionality… Maybe:
COMMAND + OPTION
<W>
or<N>
would work.
For switching to the Peers tab we already have the Ctrl+P shortcut. Adding a shortcut for enabling/disabling the network activity is out of this PR scope.
Adding a shortcut for enabling/disabling the network activity
I’m not even sure such shortcut is a good idea at all. Could accidentally hit that, the same that has happened to more with that icon without this PR.
Code review ACK d29ea72393ac1d9b32a6976062e9c9fb75876295.
Not fond of the approach though. It seems it would be enough to update the menu item text on BitcoinGUI::updateNetworkState()
instead of QMenu::clear()
+ QMenu::addAction()
and the slot would just query the current network state.
It also seems more elegant to just call BitcoinGUI::updateNetworkState()
in BitcoinGUI::setClientModel
which already calls m_node.getNetworkActive()
.
Worth noting that when the toggle action is triggered it calls m_node.setNetworkActive()
which results in destroying that same action due to QMenu::clear()
.
Don’t mind my feedback, it’s just another way of implementing the feature, thanks for adding the feature and addressing my previous comment.
Many thanks for your valuable review and feedback!
Not fond of the approach though. It seems it would be enough to update the menu item text on
BitcoinGUI::updateNetworkState()
instead ofQMenu::clear()
+QMenu::addAction()
and the slot would just query the current network state.It also seems more elegant to just call
BitcoinGUI::updateNetworkState()
inBitcoinGUI::setClientModel
which already callsm_node.getNetworkActive()
.Worth noting that when the toggle action is triggered it calls
m_node.setNetworkActive()
which results in destroying that same action due toQMenu::clear()
.
Do you mind having a look at https://github.com/hebasto/gui/commits/210511-pr309-alt?