Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bitcoin-build-config.h> // IWYU pragma: keep7#include <qt/bitcoingui.h>9#include <qt/bitcoinunits.h>10#include <qt/clientmodel.h>11#include <qt/createwalletdialog.h>12#include <qt/guiconstants.h>13#include <qt/guiutil.h>14#include <qt/modaloverlay.h>15#include <qt/networkstyle.h>16#include <qt/notificator.h>17#include <qt/openuridialog.h>18#include <qt/optionsdialog.h>19#include <qt/optionsmodel.h>20#include <qt/platformstyle.h>21#include <qt/rpcconsole.h>22#include <qt/utilitydialog.h>24#ifdef ENABLE_WALLET25#include <qt/walletcontroller.h>26#include <qt/walletframe.h>27#include <qt/walletmodel.h>28#include <qt/walletview.h>29#endif // ENABLE_WALLET31#ifdef Q_OS_MACOS32#include <qt/macdockiconhandler.h>33#endif35#include <chain.h>36#include <chainparams.h>37#include <common/system.h>38#include <interfaces/handler.h>39#include <interfaces/node.h>40#include <node/interface_ui.h>41#include <util/translation.h>42#include <validation.h>44#include <QAction>45#include <QActionGroup>46#include <QApplication>47#include <QComboBox>48#include <QCursor>49#include <QDateTime>50#include <QDragEnterEvent>51#include <QInputDialog>52#include <QKeySequence>53#include <QListWidget>54#include <QMenu>55#include <QMenuBar>56#include <QMessageBox>57#include <QMimeData>58#include <QProgressDialog>59#include <QScreen>60#include <QSettings>61#include <QShortcut>62#include <QStackedWidget>63#include <QStatusBar>64#include <QStyle>65#include <QSystemTrayIcon>66#include <QTimer>67#include <QToolBar>68#include <QUrlQuery>69#include <QVBoxLayout>70#include <QWindow>73/**74* Maximum gap between node time and block time used75* for the "Catching up..." mode in GUI.76*77* Ref: https://github.com/bitcoin/bitcoin/pull/102678*/79static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60;81const std::string BitcoinGUI::DEFAULT_UIPLATFORM =82#if defined(Q_OS_MACOS)83"macosx"84#elif defined(Q_OS_WIN)85"windows"86#else87"other"88#endif89;91BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :92QMainWindow(parent),93m_node(node),94trayIconMenu{new QMenu()},95platformStyle(_platformStyle),96m_network_style(networkStyle)97{98QSettings settings;99if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {100// Restore failed (perhaps missing setting), center the window101move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());102}104setContextMenuPolicy(Qt::PreventContextMenu);106#ifdef ENABLE_WALLET107enableWallet = WalletModel::isWalletEnabled();108#endif // ENABLE_WALLET109QApplication::setWindowIcon(m_network_style->getTrayAndWindowIcon());110setWindowIcon(m_network_style->getTrayAndWindowIcon());111updateWindowTitle();113rpcConsole = new RPCConsole(node, _platformStyle, nullptr);114helpMessageDialog = new HelpMessageDialog(this, false);115#ifdef ENABLE_WALLET116if(enableWallet)117{118/** Create wallet frame and make it the central widget */119walletFrame = new WalletFrame(_platformStyle, this);120connect(walletFrame, &WalletFrame::createWalletButtonClicked, this, &BitcoinGUI::createWallet);121connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {122this->message(title, message, style);123});124connect(walletFrame, &WalletFrame::currentWalletSet, [this] { updateWalletStatus(); });125setCentralWidget(walletFrame);126} else127#endif // ENABLE_WALLET128{129/* When compiled without wallet or -disablewallet is provided,130* the central widget is the rpc console.131*/132setCentralWidget(rpcConsole);133Q_EMIT consoleShown(rpcConsole);134}136modalOverlay = new ModalOverlay(enableWallet, this->centralWidget());138// Accept D&D of URIs139setAcceptDrops(true);141// Create actions for the toolbar, menu bar and tray/dock icon142// Needs walletFrame to be initialized143createActions();145// Create application menu bar146createMenuBar();148// Create the toolbars149createToolBars();151// Create system tray icon and notification152if (QSystemTrayIcon::isSystemTrayAvailable()) {153createTrayIcon();154}155notificator = new Notificator(QApplication::applicationName(), trayIcon, this);157// Create status bar158statusBar();160// Disable size grip because it looks ugly and nobody needs it161statusBar()->setSizeGripEnabled(false);163// Status bar notification icons164QFrame *frameBlocks = new QFrame();165frameBlocks->setContentsMargins(0,0,0,0);166frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);167QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);168frameBlocksLayout->setContentsMargins(3,0,3,0);169frameBlocksLayout->setSpacing(3);170unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);171labelWalletEncryptionIcon = new GUIUtil::ThemedLabel(platformStyle);172labelWalletHDStatusIcon = new GUIUtil::ThemedLabel(platformStyle);173labelProxyIcon = new GUIUtil::ClickableLabel(platformStyle);174connectionsControl = new GUIUtil::ClickableLabel(platformStyle);175labelBlocksIcon = new GUIUtil::ClickableLabel(platformStyle);176if(enableWallet)177{178frameBlocksLayout->addStretch();179frameBlocksLayout->addWidget(unitDisplayControl);180frameBlocksLayout->addStretch();181frameBlocksLayout->addWidget(labelWalletEncryptionIcon);182labelWalletEncryptionIcon->hide();183frameBlocksLayout->addWidget(labelWalletHDStatusIcon);184labelWalletHDStatusIcon->hide();185}186frameBlocksLayout->addWidget(labelProxyIcon);187frameBlocksLayout->addStretch();188frameBlocksLayout->addWidget(connectionsControl);189frameBlocksLayout->addStretch();190frameBlocksLayout->addWidget(labelBlocksIcon);191frameBlocksLayout->addStretch();193// Progress bar and label for blocks download194progressBarLabel = new QLabel();195progressBarLabel->setVisible(false);196progressBar = new GUIUtil::ProgressBar();197progressBar->setAlignment(Qt::AlignCenter);198progressBar->setVisible(false);200// Override style sheet for progress bar for styles that have a segmented progress bar,201// as they make the text unreadable (workaround for issue #1071)202// See https://doc.qt.io/qt-5/gallery.html203QString curStyle = QApplication::style()->metaObject()->className();204if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")205{206progressBar->setStyleSheet("QProgressBar { background-color: #e8e8e8; border: 1px solid grey; border-radius: 7px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); border-radius: 7px; margin: 0px; }");207}209statusBar()->addWidget(progressBarLabel);210statusBar()->addWidget(progressBar);211statusBar()->addPermanentWidget(frameBlocks);213// Install event filter to be able to catch status tip events (QEvent::StatusTip)214this->installEventFilter(this);216// Initially wallet actions should be disabled217setWalletActionsEnabled(false);219// Subscribe to notifications from core220subscribeToCoreSignals();222connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {223openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);224});226connect(labelBlocksIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showModalOverlay);227connect(progressBar, &GUIUtil::ClickableProgressBar::clicked, this, &BitcoinGUI::showModalOverlay);229#ifdef Q_OS_MACOS230m_app_nap_inhibitor = new CAppNapInhibitor;231#endif233GUIUtil::handleCloseWindowShortcut(this);234}236BitcoinGUI::~BitcoinGUI()237{238// Unsubscribe from notifications from core239unsubscribeFromCoreSignals();241QSettings settings;242settings.setValue("MainWindowGeometry", saveGeometry());243if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)244trayIcon->hide();245#ifdef Q_OS_MACOS246delete m_app_nap_inhibitor;247MacDockIconHandler::cleanup();248#endif250delete rpcConsole;
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.