Bitcoin Core  27.99.0
P2P Digital Currency
bitcoingui.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_QT_BITCOINGUI_H
6 #define BITCOIN_QT_BITCOINGUI_H
7 
8 #include <config/bitcoin-config.h> // IWYU pragma: keep
9 
10 #include <qt/bitcoinunits.h>
11 #include <qt/clientmodel.h>
12 #include <qt/guiutil.h>
13 #include <qt/optionsdialog.h>
14 
15 #include <consensus/amount.h>
16 
17 #include <QLabel>
18 #include <QMainWindow>
19 #include <QMap>
20 #include <QMenu>
21 #include <QPoint>
22 #include <QSystemTrayIcon>
23 
24 #ifdef Q_OS_MACOS
25 #include <qt/macos_appnap.h>
26 #endif
27 
28 #include <memory>
29 
30 class NetworkStyle;
31 class Notificator;
32 class OptionsModel;
33 class PlatformStyle;
34 class RPCConsole;
35 class SendCoinsRecipient;
37 class WalletController;
38 class WalletFrame;
39 class WalletModel;
40 class HelpMessageDialog;
41 class ModalOverlay;
42 enum class SynchronizationState;
43 
44 namespace interfaces {
45 class Handler;
46 class Node;
47 struct BlockAndHeaderTipInfo;
48 }
49 
50 QT_BEGIN_NAMESPACE
51 class QAction;
52 class QComboBox;
53 class QDateTime;
54 class QProgressBar;
55 class QProgressDialog;
56 QT_END_NAMESPACE
57 
58 namespace GUIUtil {
59 class ClickableLabel;
61 }
62 
67 class BitcoinGUI : public QMainWindow
68 {
69  Q_OBJECT
70 
71 public:
72  static const std::string DEFAULT_UIPLATFORM;
73 
74  explicit BitcoinGUI(interfaces::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = nullptr);
75  ~BitcoinGUI();
76 
80  void setClientModel(ClientModel *clientModel = nullptr, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
81 #ifdef ENABLE_WALLET
82  void setWalletController(WalletController* wallet_controller, bool show_loading_minimized);
83  WalletController* getWalletController();
84 #endif
85 
86 #ifdef ENABLE_WALLET
91  void addWallet(WalletModel* walletModel);
92  void removeWallet(WalletModel* walletModel);
93  void removeAllWallets();
94 #endif // ENABLE_WALLET
95  bool enableWallet = false;
96 
100  bool hasTrayIcon() const { return trayIcon; }
101 
104 
105  bool isPrivacyModeActivated() const;
106 
107 protected:
108  void changeEvent(QEvent *e) override;
109  void closeEvent(QCloseEvent *event) override;
110  void showEvent(QShowEvent *event) override;
111  void dragEnterEvent(QDragEnterEvent *event) override;
112  void dropEvent(QDropEvent *event) override;
113  bool eventFilter(QObject *object, QEvent *event) override;
114 
115 private:
118  std::unique_ptr<interfaces::Handler> m_handler_message_box;
119  std::unique_ptr<interfaces::Handler> m_handler_question;
122 
129  QLabel* progressBarLabel = nullptr;
131  QProgressDialog* progressDialog = nullptr;
132 
133  QMenuBar* appMenuBar = nullptr;
134  QToolBar* appToolBar = nullptr;
135  QAction* overviewAction = nullptr;
136  QAction* historyAction = nullptr;
137  QAction* quitAction = nullptr;
138  QAction* sendCoinsAction = nullptr;
139  QAction* usedSendingAddressesAction = nullptr;
140  QAction* usedReceivingAddressesAction = nullptr;
141  QAction* signMessageAction = nullptr;
142  QAction* verifyMessageAction = nullptr;
143  QAction* m_load_psbt_action = nullptr;
144  QAction* m_load_psbt_clipboard_action = nullptr;
145  QAction* aboutAction = nullptr;
146  QAction* receiveCoinsAction = nullptr;
147  QAction* optionsAction = nullptr;
148  QAction* encryptWalletAction = nullptr;
149  QAction* backupWalletAction = nullptr;
150  QAction* changePassphraseAction = nullptr;
151  QAction* aboutQtAction = nullptr;
152  QAction* openRPCConsoleAction = nullptr;
153  QAction* openAction = nullptr;
154  QAction* showHelpMessageAction = nullptr;
155  QAction* m_create_wallet_action{nullptr};
156  QAction* m_open_wallet_action{nullptr};
157  QMenu* m_open_wallet_menu{nullptr};
158  QAction* m_restore_wallet_action{nullptr};
159  QAction* m_close_wallet_action{nullptr};
160  QAction* m_close_all_wallets_action{nullptr};
161  QAction* m_wallet_selector_label_action = nullptr;
162  QAction* m_wallet_selector_action = nullptr;
163  QAction* m_mask_values_action{nullptr};
164  QAction* m_migrate_wallet_action{nullptr};
165  QMenu* m_migrate_wallet_menu{nullptr};
166 
167  QLabel *m_wallet_selector_label = nullptr;
168  QComboBox* m_wallet_selector = nullptr;
169 
170  QSystemTrayIcon* trayIcon = nullptr;
171  const std::unique_ptr<QMenu> trayIconMenu;
173  RPCConsole* rpcConsole = nullptr;
176 
177  QMenu* m_network_context_menu = new QMenu(this);
178 
179 #ifdef Q_OS_MACOS
180  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
181 #endif
182 
184  int prevBlocks = 0;
185  int spinnerFrame = 0;
186 
189 
191  void createActions();
193  void createMenuBar();
195  void createToolBars();
197  void createTrayIcon();
199  void createTrayIconMenu();
200 
202  void setWalletActionsEnabled(bool enabled);
203 
205  void subscribeToCoreSignals();
206 
208  void updateNetworkState();
209 
211  void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime& blockDate);
212 
215 
216 Q_SIGNALS:
219  void receivedURI(const QString &uri);
221  void consoleShown(RPCConsole* console);
222  void setPrivacy(bool privacy);
223 
224 public Q_SLOTS:
226  void setNumConnections(int count);
228  void setNetworkActive(bool network_active);
230  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state);
232  void createWallet();
233 
242  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr, const QString& detailed_message = QString());
243 
244 #ifdef ENABLE_WALLET
245  void setCurrentWallet(WalletModel* wallet_model);
246  void setCurrentWalletBySelectorIndex(int index);
249  void updateWalletStatus();
250 
251 private:
256  void setEncryptionStatus(int status);
257 
262  void setHDStatus(bool privkeyDisabled, int hdEnabled);
263 
264 public Q_SLOTS:
265  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
266 
268  void incomingTransaction(const QString& date, BitcoinUnit unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
269 #endif // ENABLE_WALLET
270 
271 private:
273  void updateProxyIcon();
274  void updateWindowTitle();
275 
276 public Q_SLOTS:
277 #ifdef ENABLE_WALLET
279  void gotoOverviewPage();
281  void gotoHistoryPage();
283  void gotoReceiveCoinsPage();
285  void gotoSendCoinsPage(QString addr = "");
286 
288  void gotoSignMessageTab(QString addr = "");
290  void gotoVerifyMessageTab(QString addr = "");
292  void gotoLoadPSBT(bool from_clipboard = false);
294  void enableHistoryAction(bool privacy);
295 
297  void openClicked();
298 #endif // ENABLE_WALLET
300  void optionsClicked();
302  void aboutClicked();
304  void showDebugWindow();
308  void showHelpMessageClicked();
309 
312  void showNormalIfMinimized(bool fToggleHidden);
314  void toggleHidden();
315 
317  void detectShutdown();
318 
320  void showProgress(const QString &title, int nProgress);
321 
322  void showModalOverlay();
323 };
324 
325 class UnitDisplayStatusBarControl : public QLabel
326 {
327  Q_OBJECT
328 
329 public:
330  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
333 
334 protected:
336  void mousePressEvent(QMouseEvent *event) override;
337  void changeEvent(QEvent* e) override;
338 
339 private:
341  QMenu* menu{nullptr};
343 
345  void onDisplayUnitsClicked(const QPoint& point);
347  void createContextMenu();
348 
349 private Q_SLOTS:
351  void updateDisplayUnit(BitcoinUnit newUnits);
353  void onMenuSelection(QAction* action);
354 };
355 
356 #endif // BITCOIN_QT_BITCOINGUI_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
int ret
Bitcoin GUI main class.
Definition: bitcoingui.h:68
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime &blockDate)
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:130
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:160
void showEvent(QShowEvent *event) override
QLabel * progressBarLabel
Definition: bitcoingui.h:129
QAction * m_open_wallet_action
Definition: bitcoingui.h:156
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:72
QAction * openAction
Definition: bitcoingui.h:153
void createWallet()
Launch the wallet creation modal (no-op if wallet is not compiled)
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
Set number of blocks and last block date shown in the UI.
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Definition: bitcoingui.cpp:603
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:127
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
ModalOverlay * modalOverlay
Definition: bitcoingui.h:175
GUIUtil::ThemedLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:124
QAction * changePassphraseAction
Definition: bitcoingui.h:150
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:184
QAction * openRPCConsoleAction
Definition: bitcoingui.h:152
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:188
void changeEvent(QEvent *e) override
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:126
QAction * historyAction
Definition: bitcoingui.h:136
bool eventFilter(QObject *object, QEvent *event) override
QMenu * m_open_wallet_menu
Definition: bitcoingui.h:157
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:812
QAction * m_load_psbt_clipboard_action
Definition: bitcoingui.h:144
QAction * quitAction
Definition: bitcoingui.h:137
void setNetworkActive(bool network_active)
Set network state shown in the UI.
void setPrivacy(bool privacy)
QProgressDialog * progressDialog
Definition: bitcoingui.h:131
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:85
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:118
WalletFrame * walletFrame
Definition: bitcoingui.h:121
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * m_restore_wallet_action
Definition: bitcoingui.h:158
QAction * receiveCoinsAction
Definition: bitcoingui.h:146
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:171
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:139
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void closeEvent(QCloseEvent *event) override
QAction * verifyMessageAction
Definition: bitcoingui.h:142
QAction * m_migrate_wallet_action
Definition: bitcoingui.h:164
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:825
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:174
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:913
void toggleHidden()
Simply calls showNormalIfMinimized(true)
QAction * encryptWalletAction
Definition: bitcoingui.h:148
void updateNetworkState()
Update UI with latest network info from model.
Definition: bitcoingui.cpp:988
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:247
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:922
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:100
QAction * m_mask_values_action
Definition: bitcoingui.h:163
int spinnerFrame
Definition: bitcoingui.h:185
QAction * aboutAction
Definition: bitcoingui.h:145
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
bool isPrivacyModeActivated() const
QMenu * m_migrate_wallet_menu
Definition: bitcoingui.h:165
void showDebugWindowActivateConsole()
Show debug window and set focus to the console.
Definition: bitcoingui.cpp:928
void dropEvent(QDropEvent *event) override
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:140
void subscribeToCoreSignals()
Connect core signals to GUI client.
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:567
QAction * m_wallet_selector_action
Definition: bitcoingui.h:162
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:123
QAction * optionsAction
Definition: bitcoingui.h:147
void updateWindowTitle()
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:793
const PlatformStyle * platformStyle
Definition: bitcoingui.h:187
void dragEnterEvent(QDragEnterEvent *event) override
QAction * m_close_wallet_action
Definition: bitcoingui.h:159
QAction * overviewAction
Definition: bitcoingui.h:135
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:128
interfaces::Node & m_node
Definition: bitcoingui.h:116
QAction * m_create_wallet_action
Definition: bitcoingui.h:155
QAction * m_load_psbt_action
Definition: bitcoingui.h:143
void detectShutdown()
called by a timer to check if shutdown has been requested
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:161
WalletController * m_wallet_controller
Definition: bitcoingui.h:117
bool enableWallet
Definition: bitcoingui.h:95
RPCConsole * rpcConsole
Definition: bitcoingui.h:173
QMenu * m_network_context_menu
Definition: bitcoingui.h:177
QAction * backupWalletAction
Definition: bitcoingui.h:149
QAction * showHelpMessageAction
Definition: bitcoingui.h:154
QAction * aboutQtAction
Definition: bitcoingui.h:151
QComboBox * m_wallet_selector
Definition: bitcoingui.h:168
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:167
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:311
ClientModel * clientModel
Definition: bitcoingui.h:120
void updateHeadersSyncProgressLabel()
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:473
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:170
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr, const QString &detailed_message=QString())
Notify the user of an event from the core network or transaction handling code.
void showHelpMessageClicked()
Show help message dialog.
Definition: bitcoingui.cpp:934
QAction * sendCoinsAction
Definition: bitcoingui.h:138
void quitRequested()
QToolBar * appToolBar
Definition: bitcoingui.h:134
void setNumConnections(int count)
Set number of connections shown in the UI.
QAction * signMessageAction
Definition: bitcoingui.h:141
GUIUtil::ThemedLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:125
void showModalOverlay()
Notificator * notificator
Definition: bitcoingui.h:172
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:119
QMenuBar * appMenuBar
Definition: bitcoingui.h:133
Unit
Bitcoin units.
Definition: bitcoinunits.h:42
Model for Bitcoin network client.
Definition: clientmodel.h:54
"Help message" dialog box
Definition: utilitydialog.h:21
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:21
Cross-platform desktop notification client.
Definition: notificator.h:23
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
Local Bitcoin RPC console.
Definition: rpcconsole.h:42
void changeEvent(QEvent *e) override
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
void createContextMenu()
Creates context menu, its actions, and wires up all the relevant signals for mouse events.
void updateDisplayUnit(BitcoinUnit newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
OptionsModel * optionsModel
Definition: bitcoingui.h:340
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
void onMenuSelection(QAction *action)
Tells underlying optionsModel to update its current display unit.
const PlatformStyle * m_platform_style
Definition: bitcoingui.h:342
void setOptionsModel(OptionsModel *optionsModel)
Lets the control know about the Options Model (and its signals)
void onDisplayUnitsClicked(const QPoint &point)
Shows context menu with Display Unit options by the mouse coordinates.
Controller between interfaces::Node, WalletModel instances and the GUI.
A container for embedding all wallet-related controls into BitcoinGUI.
Definition: walletframe.h:29
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:48
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
SyncType
Definition: clientmodel.h:39
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
Definition: init.h:25
Block and header tip information.
Definition: node.h:50
static int count
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:80