Merge bitcoin-core/gui#309: Add access to the Peers tab from the network icon

d29ea72393ac1d9b32a6976062e9c9fb75876295 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 d29ea72393ac1d9b32a6976062e9c9fb75876295
  kristapsk:
    re-ACK d29ea72393ac1d9b32a6976062e9c9fb75876295
  promag:
    Code review ACK d29ea72393ac1d9b32a6976062e9c9fb75876295.

Tree-SHA512: dd871415fe514a19c6a22100d58f31954d9e55b80585d5a3f26e17a8d51dadf912441786fc0d23beabd812f1b501658fec1dbe345cd41beae5832a8eda890f77
This commit is contained in:
Hennadii Stepanov 2021-05-31 19:34:28 +03:00 committed by Konstantin Akimov
parent c858325d40
commit 69a1305978
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 35 additions and 8 deletions

View File

@ -47,6 +47,7 @@
#include <QApplication>
#include <QButtonGroup>
#include <QComboBox>
#include <QCursor>
#include <QDateTime>
#include <QDragEnterEvent>
#include <QKeySequence>
@ -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("<nobr>") + tooltip + QLatin1String("<br>") +
//: A substring of the tooltip. "More actions" are available via the context menu.
tr("Click for more actions.") + QLatin1String("</nobr>");
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()

View File

@ -16,6 +16,7 @@
#include <QLabel>
#include <QMainWindow>
#include <QMap>
#include <QMenu>
#include <QPoint>
#include <QPushButton>
#include <QSystemTrayIcon>
@ -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 */