Bitcoin Core  22.0.0
P2P Digital Currency
bitcoingui.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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/guiutil.h>
13 #include <qt/optionsdialog.h>
14 
15 #include <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_MAC
25 #include <qt/macos_appnap.h>
26 #endif
27 
28 #include <memory>
29 
30 class ClientModel;
31 class NetworkStyle;
32 class Notificator;
33 class OptionsModel;
34 class PlatformStyle;
35 class RPCConsole;
36 class SendCoinsRecipient;
38 class WalletController;
39 class WalletFrame;
40 class WalletModel;
41 class HelpMessageDialog;
42 class ModalOverlay;
43 enum class SynchronizationState;
44 
45 namespace interfaces {
46 class Handler;
47 class Node;
48 struct BlockAndHeaderTipInfo;
49 }
50 
51 QT_BEGIN_NAMESPACE
52 class QAction;
53 class QComboBox;
54 class QDateTime;
55 class QProgressBar;
56 class QProgressDialog;
57 QT_END_NAMESPACE
58 
59 namespace GUIUtil {
60 class ClickableLabel;
62 }
63 
68 class BitcoinGUI : public QMainWindow
69 {
70  Q_OBJECT
71 
72 public:
73  static const std::string DEFAULT_UIPLATFORM;
74 
75  explicit BitcoinGUI(interfaces::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = nullptr);
76  ~BitcoinGUI();
77 
81  void setClientModel(ClientModel *clientModel = nullptr, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
82 #ifdef ENABLE_WALLET
83  void setWalletController(WalletController* wallet_controller);
84  WalletController* getWalletController();
85 #endif
86 
87 #ifdef ENABLE_WALLET
88 
92  void addWallet(WalletModel* walletModel);
93  void removeWallet(WalletModel* walletModel);
94  void removeAllWallets();
95 #endif // ENABLE_WALLET
96  bool enableWallet = false;
97 
101  bool hasTrayIcon() const { return trayIcon; }
102 
105 
106  bool isPrivacyModeActivated() const;
107 
108 protected:
109  void changeEvent(QEvent *e) override;
110  void closeEvent(QCloseEvent *event) override;
111  void showEvent(QShowEvent *event) override;
112  void dragEnterEvent(QDragEnterEvent *event) override;
113  void dropEvent(QDropEvent *event) override;
114  bool eventFilter(QObject *object, QEvent *event) override;
115 
116 private:
119  std::unique_ptr<interfaces::Handler> m_handler_message_box;
120  std::unique_ptr<interfaces::Handler> m_handler_question;
123 
130  QLabel* progressBarLabel = nullptr;
132  QProgressDialog* progressDialog = nullptr;
133 
134  QMenuBar* appMenuBar = nullptr;
135  QToolBar* appToolBar = nullptr;
136  QAction* overviewAction = nullptr;
137  QAction* historyAction = nullptr;
138  QAction* quitAction = nullptr;
139  QAction* sendCoinsAction = nullptr;
140  QAction* sendCoinsMenuAction = 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* receiveCoinsMenuAction = nullptr;
150  QAction* optionsAction = nullptr;
151  QAction* toggleHideAction = nullptr;
152  QAction* encryptWalletAction = nullptr;
153  QAction* backupWalletAction = nullptr;
154  QAction* changePassphraseAction = nullptr;
155  QAction* aboutQtAction = nullptr;
156  QAction* openRPCConsoleAction = nullptr;
157  QAction* openAction = nullptr;
158  QAction* showHelpMessageAction = nullptr;
159  QAction* m_create_wallet_action{nullptr};
160  QAction* m_open_wallet_action{nullptr};
161  QMenu* m_open_wallet_menu{nullptr};
162  QAction* m_close_wallet_action{nullptr};
163  QAction* m_close_all_wallets_action{nullptr};
164  QAction* m_wallet_selector_label_action = nullptr;
165  QAction* m_wallet_selector_action = nullptr;
166  QAction* m_mask_values_action{nullptr};
167 
168  QLabel *m_wallet_selector_label = nullptr;
169  QComboBox* m_wallet_selector = nullptr;
170 
171  QSystemTrayIcon* trayIcon = nullptr;
172  const std::unique_ptr<QMenu> trayIconMenu;
174  RPCConsole* rpcConsole = nullptr;
177 
178  QMenu* m_network_context_menu = new QMenu(this);
179 
180 #ifdef Q_OS_MAC
181  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
182 #endif
183 
185  int prevBlocks = 0;
186  int spinnerFrame = 0;
187 
190 
192  void createActions();
194  void createMenuBar();
196  void createToolBars();
198  void createTrayIcon();
200  void createTrayIconMenu();
201 
203  void setWalletActionsEnabled(bool enabled);
204 
206  void subscribeToCoreSignals();
207 
209  void updateNetworkState();
210 
212 
215 
216 Q_SIGNALS:
218  void receivedURI(const QString &uri);
220  void consoleShown(RPCConsole* console);
221  void setPrivacy(bool privacy);
222 
223 public Q_SLOTS:
225  void setNumConnections(int count);
227  void setNetworkActive(bool network_active);
229  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state);
230 
239  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr, const QString& detailed_message = QString());
240 
241 #ifdef ENABLE_WALLET
242  void setCurrentWallet(WalletModel* wallet_model);
243  void setCurrentWalletBySelectorIndex(int index);
246  void updateWalletStatus();
247 
248 private:
253  void setEncryptionStatus(int status);
254 
259  void setHDStatus(bool privkeyDisabled, int hdEnabled);
260 
261 public Q_SLOTS:
262  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
263 
265  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
266 #endif // ENABLE_WALLET
267 
268 private:
270  void updateProxyIcon();
271  void updateWindowTitle();
272 
273 public Q_SLOTS:
274 #ifdef ENABLE_WALLET
275 
276  void gotoOverviewPage();
278  void gotoHistoryPage();
280  void gotoReceiveCoinsPage();
282  void gotoSendCoinsPage(QString addr = "");
283 
285  void gotoSignMessageTab(QString addr = "");
287  void gotoVerifyMessageTab(QString addr = "");
289  void gotoLoadPSBT(bool from_clipboard = false);
290 
292  void openClicked();
293 #endif // ENABLE_WALLET
294 
295  void optionsClicked();
297  void aboutClicked();
299  void showDebugWindow();
303  void showHelpMessageClicked();
304 #ifndef Q_OS_MAC
305 
306  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
307 #else
308 
309  void macosDockIconActivated();
310 #endif
311 
314  void showNormalIfMinimized(bool fToggleHidden);
316  void toggleHidden();
317 
319  void detectShutdown();
320 
322  void showProgress(const QString &title, int nProgress);
323 
324  void showModalOverlay();
325 };
326 
327 class UnitDisplayStatusBarControl : public QLabel
328 {
329  Q_OBJECT
330 
331 public:
332  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
335 
336 protected:
338  void mousePressEvent(QMouseEvent *event) override;
339  void changeEvent(QEvent* e) override;
340 
341 private:
343  QMenu* menu;
345 
347  void onDisplayUnitsClicked(const QPoint& point);
349  void createContextMenu();
350 
351 private Q_SLOTS:
353  void updateDisplayUnit(int newUnits);
355  void onMenuSelection(QAction* action);
356 };
357 
358 #endif // BITCOIN_QT_BITCOINGUI_H
void subscribeToCoreSignals()
Connect core signals to GUI client.
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void showEvent(QShowEvent *event) override
QAction * receiveCoinsAction
Definition: bitcoingui.h:148
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:124
Local Bitcoin RPC console.
Definition: rpcconsole.h:38
QMenuBar * appMenuBar
Definition: bitcoingui.h:134
QAction * m_mask_values_action
Definition: bitcoingui.h:166
QAction * signMessageAction
Definition: bitcoingui.h:143
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:59
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:102
QAction * aboutAction
Definition: bitcoingui.h:147
void updateNetworkState()
Update UI with latest network info from model.
Definition: bitcoingui.cpp:918
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:313
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
QProgressDialog * progressDialog
Definition: bitcoingui.h:132
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:770
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:852
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:127
ClientModel * clientModel
Definition: bitcoingui.h:121
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:541
QAction * m_load_psbt_action
Definition: bitcoingui.h:145
ModalOverlay * modalOverlay
Definition: bitcoingui.h:176
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:783
RPCConsole * rpcConsole
Definition: bitcoingui.h:174
QAction * m_wallet_selector_action
Definition: bitcoingui.h:165
QAction * overviewAction
Definition: bitcoingui.h:136
QAction * verifyMessageAction
Definition: bitcoingui.h:144
QAction * quitAction
Definition: bitcoingui.h:138
QAction * m_open_wallet_action
Definition: bitcoingui.h:160
QAction * m_close_wallet_action
Definition: bitcoingui.h:162
QAction * historyAction
Definition: bitcoingui.h:137
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:750
QAction * aboutQtAction
Definition: bitcoingui.h:155
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Definition: bitcoingui.cpp:577
Controller between interfaces::Node, WalletModel instances and the GUI.
QMenu * m_open_wallet_menu
Definition: bitcoingui.h:161
Bitcoin GUI main class.
Definition: bitcoingui.h:68
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:175
QLabel * progressBarLabel
Definition: bitcoingui.h:130
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:171
QAction * showHelpMessageAction
Definition: bitcoingui.h:158
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:20
bool isPrivacyModeActivated() const
void changeEvent(QEvent *e) override
void changeEvent(QEvent *e) override
void setNetworkActive(bool network_active)
Set network state shown in the UI.
Definition: bitcoingui.cpp:956
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:128
QAction * backupWalletAction
Definition: bitcoingui.h:153
QAction * m_load_psbt_clipboard_action
Definition: bitcoingui.h:146
void setOptionsModel(OptionsModel *optionsModel)
Lets the control know about the Options Model (and its signals)
void dropEvent(QDropEvent *event) override
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
Definition: bitcoingui.cpp:985
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:142
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void showModalOverlay()
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:189
WalletController * m_wallet_controller
Definition: bitcoingui.h:118
const PlatformStyle * platformStyle
Definition: bitcoingui.h:188
QAction * toggleHideAction
Definition: bitcoingui.h:151
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:164
OptionsModel * optionsModel
Definition: bitcoingui.h:342
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:168
void optionsClicked()
Show configuration dialog.
Definition: bitcoingui.cpp:838
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state)
Set number of blocks and last block date shown in the UI.
Definition: bitcoingui.cpp:996
QToolBar * appToolBar
Definition: bitcoingui.h:135
WalletFrame * walletFrame
Definition: bitcoingui.h:122
void updateDisplayUnit(int newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:141
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:79
bool enableWallet
Definition: bitcoingui.h:96
QAction * openRPCConsoleAction
Definition: bitcoingui.h:156
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:163
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
Cross-platform desktop notification client.
Definition: notificator.h:24
Block and header tip information.
Definition: node.h:44
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:129
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:131
void updateWindowTitle()
void showHelpMessageClicked()
Show help message dialog.
Definition: bitcoingui.cpp:864
Notificator * notificator
Definition: bitcoingui.h:173
Model for Bitcoin network client.
Definition: clientmodel.h:47
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
QAction * receiveCoinsMenuAction
Definition: bitcoingui.h:149
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:101
QAction * sendCoinsAction
Definition: bitcoingui.h:139
QAction * m_create_wallet_action
Definition: bitcoingui.h:159
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.
QAction * openAction
Definition: bitcoingui.h:157
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Handle tray icon clicked.
Definition: bitcoingui.cpp:822
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * changePassphraseAction
Definition: bitcoingui.h:154
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:172
QMenu * m_network_context_menu
Definition: bitcoingui.h:178
void setPrivacy(bool privacy)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:120
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
QAction * sendCoinsMenuAction
Definition: bitcoingui.h:140
bool eventFilter(QObject *object, QEvent *event) override
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:185
void toggleHidden()
Simply calls showNormalIfMinimized(true) for use in SLOT() macro.
interfaces::Node & m_node
Definition: bitcoingui.h:117
int spinnerFrame
Definition: bitcoingui.h:186
GUIUtil::ThemedLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:125
static int count
Definition: tests.c:41
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: bitcoingui.cpp:951
"Help message" dialog box
Definition: utilitydialog.h:20
void closeEvent(QCloseEvent *event) override
QComboBox * m_wallet_selector
Definition: bitcoingui.h:169
void createContextMenu()
Creates context menu, its actions, and wires up all the relevant signals for mouse events...
void showDebugWindowActivateConsole()
Show debug window and set focus to the console.
Definition: bitcoingui.cpp:858
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:240
QAction * optionsAction
Definition: bitcoingui.h:150
QAction * encryptWalletAction
Definition: bitcoingui.h:152
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:843
const PlatformStyle * m_platform_style
Definition: bitcoingui.h:344
void updateHeadersSyncProgressLabel()
Definition: bitcoingui.cpp:976
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:73
GUIUtil::ThemedLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:126
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
A container for embedding all wallet-related controls into BitcoinGUI.
Definition: walletframe.h:28
void onDisplayUnitsClicked(const QPoint &point)
Shows context menu with Display Unit options by the mouse coordinates.
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:444
void onMenuSelection(QAction *action)
Tells underlying optionsModel to update its current display unit.
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:119
void dragEnterEvent(QDragEnterEvent *event) override