Bitcoin Core  24.99.0
P2P Digital Currency
bitcoingui.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 #if defined(HAVE_CONFIG_H)
10 #endif
11 
12 #include <qt/bitcoinunits.h>
13 #include <qt/clientmodel.h>
14 #include <qt/guiutil.h>
15 #include <qt/optionsdialog.h>
16 
17 #include <consensus/amount.h>
18 
19 #include <QLabel>
20 #include <QMainWindow>
21 #include <QMap>
22 #include <QMenu>
23 #include <QPoint>
24 #include <QSystemTrayIcon>
25 
26 #ifdef Q_OS_MACOS
27 #include <qt/macos_appnap.h>
28 #endif
29 
30 #include <memory>
31 
32 class NetworkStyle;
33 class Notificator;
34 class OptionsModel;
35 class PlatformStyle;
36 class RPCConsole;
37 class SendCoinsRecipient;
39 class WalletController;
40 class WalletFrame;
41 class WalletModel;
42 class HelpMessageDialog;
43 class ModalOverlay;
44 enum class SynchronizationState;
45 
46 namespace interfaces {
47 class Handler;
48 class Node;
49 struct BlockAndHeaderTipInfo;
50 }
51 
52 QT_BEGIN_NAMESPACE
53 class QAction;
54 class QComboBox;
55 class QDateTime;
56 class QProgressBar;
57 class QProgressDialog;
58 QT_END_NAMESPACE
59 
60 namespace GUIUtil {
61 class ClickableLabel;
63 }
64 
69 class BitcoinGUI : public QMainWindow
70 {
71  Q_OBJECT
72 
73 public:
74  static const std::string DEFAULT_UIPLATFORM;
75 
76  explicit BitcoinGUI(interfaces::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = nullptr);
77  ~BitcoinGUI();
78 
82  void setClientModel(ClientModel *clientModel = nullptr, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
83 #ifdef ENABLE_WALLET
84  void setWalletController(WalletController* wallet_controller);
85  WalletController* getWalletController();
86 #endif
87 
88 #ifdef ENABLE_WALLET
93  void addWallet(WalletModel* walletModel);
94  void removeWallet(WalletModel* walletModel);
95  void removeAllWallets();
96 #endif // ENABLE_WALLET
97  bool enableWallet = false;
98 
102  bool hasTrayIcon() const { return trayIcon; }
103 
106 
107  bool isPrivacyModeActivated() const;
108 
109 protected:
110  void changeEvent(QEvent *e) override;
111  void closeEvent(QCloseEvent *event) override;
112  void showEvent(QShowEvent *event) override;
113  void dragEnterEvent(QDragEnterEvent *event) override;
114  void dropEvent(QDropEvent *event) override;
115  bool eventFilter(QObject *object, QEvent *event) override;
116 
117 private:
120  std::unique_ptr<interfaces::Handler> m_handler_message_box;
121  std::unique_ptr<interfaces::Handler> m_handler_question;
124 
131  QLabel* progressBarLabel = nullptr;
133  QProgressDialog* progressDialog = nullptr;
134 
135  QMenuBar* appMenuBar = nullptr;
136  QToolBar* appToolBar = nullptr;
137  QAction* overviewAction = nullptr;
138  QAction* historyAction = nullptr;
139  QAction* quitAction = nullptr;
140  QAction* sendCoinsAction = nullptr;
141  QAction* usedSendingAddressesAction = nullptr;
142  QAction* usedReceivingAddressesAction = nullptr;
143  QAction* signMessageAction = nullptr;
144  QAction* verifyMessageAction = nullptr;
145  QAction* m_load_psbt_action = nullptr;
146  QAction* m_load_psbt_clipboard_action = nullptr;
147  QAction* aboutAction = nullptr;
148  QAction* receiveCoinsAction = nullptr;
149  QAction* optionsAction = nullptr;
150  QAction* encryptWalletAction = nullptr;
151  QAction* backupWalletAction = nullptr;
152  QAction* changePassphraseAction = nullptr;
153  QAction* aboutQtAction = nullptr;
154  QAction* openRPCConsoleAction = nullptr;
155  QAction* openAction = nullptr;
156  QAction* showHelpMessageAction = nullptr;
157  QAction* m_create_wallet_action{nullptr};
158  QAction* m_open_wallet_action{nullptr};
159  QMenu* m_open_wallet_menu{nullptr};
160  QAction* m_restore_wallet_action{nullptr};
161  QAction* m_close_wallet_action{nullptr};
162  QAction* m_close_all_wallets_action{nullptr};
163  QAction* m_wallet_selector_label_action = nullptr;
164  QAction* m_wallet_selector_action = nullptr;
165  QAction* m_mask_values_action{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);
231 
240  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr, const QString& detailed_message = QString());
241 
242 #ifdef ENABLE_WALLET
243  void setCurrentWallet(WalletModel* wallet_model);
244  void setCurrentWalletBySelectorIndex(int index);
247  void updateWalletStatus();
248 
249 private:
254  void setEncryptionStatus(int status);
255 
260  void setHDStatus(bool privkeyDisabled, int hdEnabled);
261 
262 public Q_SLOTS:
263  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
264 
266  void incomingTransaction(const QString& date, BitcoinUnit unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
267 #endif // ENABLE_WALLET
268 
269 private:
271  void updateProxyIcon();
272  void updateWindowTitle();
273 
274 public Q_SLOTS:
275 #ifdef ENABLE_WALLET
277  void gotoOverviewPage();
279  void gotoHistoryPage();
281  void gotoReceiveCoinsPage();
283  void gotoSendCoinsPage(QString addr = "");
284 
286  void gotoSignMessageTab(QString addr = "");
288  void gotoVerifyMessageTab(QString addr = "");
290  void gotoLoadPSBT(bool from_clipboard = false);
291 
293  void openClicked();
294 #endif // ENABLE_WALLET
296  void optionsClicked();
298  void aboutClicked();
300  void showDebugWindow();
304  void showHelpMessageClicked();
305 
308  void showNormalIfMinimized(bool fToggleHidden);
310  void toggleHidden();
311 
313  void detectShutdown();
314 
316  void showProgress(const QString &title, int nProgress);
317 
318  void showModalOverlay();
319 };
320 
321 class UnitDisplayStatusBarControl : public QLabel
322 {
323  Q_OBJECT
324 
325 public:
326  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
329 
330 protected:
332  void mousePressEvent(QMouseEvent *event) override;
333  void changeEvent(QEvent* e) override;
334 
335 private:
337  QMenu* menu;
339 
341  void onDisplayUnitsClicked(const QPoint& point);
343  void createContextMenu();
344 
345 private Q_SLOTS:
347  void updateDisplayUnit(BitcoinUnit newUnits);
349  void onMenuSelection(QAction* action);
350 };
351 
352 #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:70
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime &blockDate)
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:132
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:162
void showEvent(QShowEvent *event) override
QLabel * progressBarLabel
Definition: bitcoingui.h:131
QAction * m_open_wallet_action
Definition: bitcoingui.h:158
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:74
QAction * openAction
Definition: bitcoingui.h:155
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:601
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:129
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:126
QAction * changePassphraseAction
Definition: bitcoingui.h:152
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:154
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:188
void changeEvent(QEvent *e) override
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:128
QAction * historyAction
Definition: bitcoingui.h:138
bool eventFilter(QObject *object, QEvent *event) override
QMenu * m_open_wallet_menu
Definition: bitcoingui.h:159
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:789
QAction * m_load_psbt_clipboard_action
Definition: bitcoingui.h:146
QAction * quitAction
Definition: bitcoingui.h:139
void setNetworkActive(bool network_active)
Set network state shown in the UI.
void setPrivacy(bool privacy)
QProgressDialog * progressDialog
Definition: bitcoingui.h:133
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:82
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:120
WalletFrame * walletFrame
Definition: bitcoingui.h:123
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * m_restore_wallet_action
Definition: bitcoingui.h:160
QAction * receiveCoinsAction
Definition: bitcoingui.h:148
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:171
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:141
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void closeEvent(QCloseEvent *event) override
QAction * verifyMessageAction
Definition: bitcoingui.h:144
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:802
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:174
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:887
void toggleHidden()
Simply calls showNormalIfMinimized(true)
QAction * encryptWalletAction
Definition: bitcoingui.h:150
void updateNetworkState()
Update UI with latest network info from model.
Definition: bitcoingui.cpp:962
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:248
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:896
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:102
QAction * m_mask_values_action
Definition: bitcoingui.h:165
int spinnerFrame
Definition: bitcoingui.h:185
QAction * aboutAction
Definition: bitcoingui.h:147
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
bool isPrivacyModeActivated() const
void showDebugWindowActivateConsole()
Show debug window and set focus to the console.
Definition: bitcoingui.cpp:902
void dropEvent(QDropEvent *event) override
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:142
void subscribeToCoreSignals()
Connect core signals to GUI client.
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:565
QAction * m_wallet_selector_action
Definition: bitcoingui.h:164
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:125
QAction * optionsAction
Definition: bitcoingui.h:149
void updateWindowTitle()
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:771
const PlatformStyle * platformStyle
Definition: bitcoingui.h:187
void dragEnterEvent(QDragEnterEvent *event) override
QAction * m_close_wallet_action
Definition: bitcoingui.h:161
QAction * overviewAction
Definition: bitcoingui.h:137
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:130
interfaces::Node & m_node
Definition: bitcoingui.h:118
QAction * m_create_wallet_action
Definition: bitcoingui.h:157
QAction * m_load_psbt_action
Definition: bitcoingui.h:145
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:163
WalletController * m_wallet_controller
Definition: bitcoingui.h:119
bool enableWallet
Definition: bitcoingui.h:97
RPCConsole * rpcConsole
Definition: bitcoingui.h:173
QMenu * m_network_context_menu
Definition: bitcoingui.h:177
QAction * backupWalletAction
Definition: bitcoingui.h:151
QAction * showHelpMessageAction
Definition: bitcoingui.h:156
QAction * aboutQtAction
Definition: bitcoingui.h:153
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:307
ClientModel * clientModel
Definition: bitcoingui.h:122
void updateHeadersSyncProgressLabel()
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:466
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:908
QAction * sendCoinsAction
Definition: bitcoingui.h:140
void quitRequested()
QToolBar * appToolBar
Definition: bitcoingui.h:136
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: bitcoingui.cpp:995
QAction * signMessageAction
Definition: bitcoingui.h:143
GUIUtil::ThemedLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:127
void showModalOverlay()
Notificator * notificator
Definition: bitcoingui.h:172
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:121
QMenuBar * appMenuBar
Definition: bitcoingui.h:135
Unit
Bitcoin units.
Definition: bitcoinunits.h:42
Model for Bitcoin network client.
Definition: clientmodel.h:55
"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:25
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:41
Local Bitcoin RPC console.
Definition: rpcconsole.h:44
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:336
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:338
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:53
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
SyncType
Definition: clientmodel.h:40
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:60
Definition: init.h:25
Block and header tip information.
Definition: node.h:50
static int count
Definition: tests.c:33
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:88