Skip to content

Commit

Permalink
gui: Add access to the Peers tab from the network icon
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 11, 2021
1 parent 39e3060 commit 86e0f80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <QAction>
#include <QApplication>
#include <QComboBox>
#include <QCursor>
#include <QDateTime>
#include <QDragEnterEvent>
#include <QListWidget>
Expand Down Expand Up @@ -199,8 +200,19 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
// Subscribe to notifications from core
subscribeToCoreSignals();

m_network_context_menu = new QMenu(this);
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(
QString(),
[this] { m_node.setNetworkActive(!m_node.getNetworkActive()); });
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, [this] {
m_node.setNetworkActive(!m_node.getNetworkActive());
GUIUtil::PopupMenu(m_network_context_menu, QCursor::pos());
});
connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
Expand Down Expand Up @@ -586,7 +598,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
createTrayIconMenu();

// Keep up to date with client
updateNetworkState();
setNetworkActive(m_node.getNetworkActive());

This comment has been minimized.

Copy link
@hebasto

hebasto May 11, 2021

Author Owner

bitcoin-core#309 (review)

It also seems more elegant to just call BitcoinGUI::updateNetworkState() in BitcoinGUI::setClientModel which already calls m_node.getNetworkActive().

But we should set the action text at the first time. However, it could be done the addAction above, but it will be a code duplication.

connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections);
connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive);

Expand Down Expand Up @@ -915,14 +927,18 @@ void BitcoinGUI::updateNetworkState()
QString tooltip;

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

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

connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
Expand All @@ -936,6 +952,12 @@ void BitcoinGUI::setNumConnections(int count)
void BitcoinGUI::setNetworkActive(bool networkActive)
{
updateNetworkState();
m_network_context_menu->actions().last()->setText(

This comment has been minimized.

Copy link
@hebasto

hebasto May 11, 2021

Author Owner

bitcoin-core#309 (review)

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.

Done.

networkActive ?
//: A context menu item.
tr("Disable network activity") :
//: A context menu item. The network activity was disabled previously.
tr("Enable network activity"));
}

void BitcoinGUI::updateHeadersSyncProgressLabel()
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class BitcoinGUI : public QMainWindow
RPCConsole* rpcConsole = nullptr;
HelpMessageDialog* helpMessageDialog = nullptr;
ModalOverlay* modalOverlay = nullptr;
QMenu* m_network_context_menu = nullptr;

#ifdef Q_OS_MAC
CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
Expand Down

0 comments on commit 86e0f80

Please sign in to comment.