diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 3491f07ee00..a46ddb630a2 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -56,6 +56,7 @@ QT_MOC_CPP = \ qt/moc_macdockiconhandler.cpp \ qt/moc_macnotificationhandler.cpp \ qt/moc_modaloverlay.cpp \ + qt/moc_netwatch.cpp \ qt/moc_notificator.cpp \ qt/moc_openuridialog.cpp \ qt/moc_optionsdialog.cpp \ @@ -129,6 +130,7 @@ BITCOIN_QT_H = \ qt/macnotificationhandler.h \ qt/macos_appnap.h \ qt/modaloverlay.h \ + qt/netwatch.h \ qt/networkstyle.h \ qt/notificator.h \ qt/openuridialog.h \ @@ -232,6 +234,7 @@ BITCOIN_QT_BASE_CPP = \ qt/initexecutor.cpp \ qt/intro.cpp \ qt/modaloverlay.cpp \ + qt/netwatch.cpp \ qt/networkstyle.cpp \ qt/notificator.cpp \ qt/optionsdialog.cpp \ diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 7c22880dd1c..8f5c5aadbcc 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -239,6 +240,7 @@ BitcoinGUI::~BitcoinGUI() MacDockIconHandler::cleanup(); #endif + delete NetWatch; delete rpcConsole; } @@ -320,6 +322,9 @@ void BitcoinGUI::createActions() m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from &clipboard…"), this); m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard")); + m_show_netwatch_action = new QAction(tr("&Watch network activity"), this); + m_show_netwatch_action->setStatusTip(tr("Open p2p network watching window")); + openRPCConsoleAction = new QAction(tr("Node window"), this); openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console")); // initially disable the debug window menu item @@ -363,6 +368,7 @@ void BitcoinGUI::createActions() connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt); connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked); connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked); + connect(m_show_netwatch_action, &QAction::triggered, this, &BitcoinGUI::showNetWatch); connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow); // prevents an open debug window from becoming stuck/unusable on client shutdown connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide); @@ -509,6 +515,8 @@ void BitcoinGUI::createMenuBar() window_menu->addAction(usedReceivingAddressesAction); } + window_menu->addAction(m_show_netwatch_action); + window_menu->addSeparator(); for (RPCConsole::TabTypes tab_type : rpcConsole->tabs()) { QAction* tab_action = window_menu->addAction(rpcConsole->tabTitle(tab_type)); @@ -591,6 +599,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH // Show progress dialog connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress); + if (NetWatch) { + NetWatch->setClientModel(_clientModel); + } + rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->verification_progress); updateProxyIcon(); @@ -618,6 +630,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH trayIconMenu->clear(); } // Propagate cleared model to child objects + if (NetWatch) { + NetWatch->setClientModel(nullptr); + } rpcConsole->setClientModel(nullptr); #ifdef ENABLE_WALLET if (walletFrame) @@ -856,6 +871,15 @@ void BitcoinGUI::aboutClicked() GUIUtil::ShowModalDialogAsynchronously(dlg); } +void BitcoinGUI::showNetWatch() +{ + if (!NetWatch) { + NetWatch = new GuiNetWatch(platformStyle, m_network_style); + NetWatch->setClientModel(clientModel); + } + GUIUtil::bringToFront(NetWatch); +} + void BitcoinGUI::showDebugWindow() { GUIUtil::bringToFront(rpcConsole); @@ -1218,6 +1242,9 @@ void BitcoinGUI::closeEvent(QCloseEvent *event) { if(!clientModel->getOptionsModel()->getMinimizeOnClose()) { + if (NetWatch) { + NetWatch->close(); + } // close rpcConsole in case it was open to make some space for the shutdown window rpcConsole->close(); @@ -1411,6 +1438,9 @@ void BitcoinGUI::detectShutdown() { if (m_node.shutdownRequested()) { + if (NetWatch) { + NetWatch->hide(); + } if(rpcConsole) rpcConsole->hide(); Q_EMIT quitRequested(); diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 0ae5f7331e2..1f8dbbd3525 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -28,6 +28,7 @@ #include class ClientModel; +class GuiNetWatch; class NetworkStyle; class Notificator; class OptionsModel; @@ -150,6 +151,7 @@ class BitcoinGUI : public QMainWindow QAction* backupWalletAction = nullptr; QAction* changePassphraseAction = nullptr; QAction* aboutQtAction = nullptr; + QAction* m_show_netwatch_action = nullptr; QAction* openRPCConsoleAction = nullptr; QAction* openAction = nullptr; QAction* showHelpMessageAction = nullptr; @@ -168,6 +170,7 @@ class BitcoinGUI : public QMainWindow QSystemTrayIcon* trayIcon = nullptr; const std::unique_ptr trayIconMenu; Notificator* notificator = nullptr; + GuiNetWatch* NetWatch = nullptr; RPCConsole* rpcConsole = nullptr; HelpMessageDialog* helpMessageDialog = nullptr; ModalOverlay* modalOverlay = nullptr; @@ -293,6 +296,7 @@ public Q_SLOTS: void optionsClicked(); /** Show about dialog */ void aboutClicked(); + void showNetWatch(); /** Show debug window */ void showDebugWindow(); /** Show debug window and set focus to the console */ diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index fcdf6056c95..5c6f0eb68fb 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -26,6 +26,8 @@ static const bool DEFAULT_SPLASHSCREEN = true; /* Invalid field background style */ #define STYLE_INVALID "background:#FF8080" +/* Background style for active search in NetWatch */ +#define STYLE_ACTIVE "background:#80FF80" /* Transaction list -- unconfirmed transaction */ #define COLOR_UNCONFIRMED QColor(128, 128, 128) diff --git a/src/qt/netwatch.cpp b/src/qt/netwatch.cpp new file mode 100644 index 00000000000..58a62c1215f --- /dev/null +++ b/src/qt/netwatch.cpp @@ -0,0 +1,838 @@ +// Copyright (c) 2017-2021 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#if defined(HAVE_CONFIG_H) +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include