Bitcoin Core  0.21.1
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
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/optionsdialog.h>
13 
14 #include <amount.h>
15 
16 #include <QLabel>
17 #include <QMainWindow>
18 #include <QMap>
19 #include <QPoint>
20 #include <QSystemTrayIcon>
21 
22 #ifdef Q_OS_MAC
23 #include <qt/macos_appnap.h>
24 #endif
25 
26 #include <memory>
27 
28 class ClientModel;
29 class NetworkStyle;
30 class Notificator;
31 class OptionsModel;
32 class PlatformStyle;
33 class RPCConsole;
34 class SendCoinsRecipient;
36 class WalletController;
37 class WalletFrame;
38 class WalletModel;
39 class HelpMessageDialog;
40 class ModalOverlay;
41 enum class SynchronizationState;
42 
43 namespace interfaces {
44 class Handler;
45 class Node;
46 struct BlockAndHeaderTipInfo;
47 }
48 
49 QT_BEGIN_NAMESPACE
50 class QAction;
51 class QComboBox;
52 class QMenu;
53 class QProgressBar;
54 class QProgressDialog;
55 QT_END_NAMESPACE
56 
57 namespace GUIUtil {
58 class ClickableLabel;
60 }
61 
66 class BitcoinGUI : public QMainWindow
67 {
68  Q_OBJECT
69 
70 public:
71  static const std::string DEFAULT_UIPLATFORM;
72 
73  explicit BitcoinGUI(interfaces::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = nullptr);
74  ~BitcoinGUI();
75 
79  void setClientModel(ClientModel *clientModel = nullptr, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
80 #ifdef ENABLE_WALLET
81  void setWalletController(WalletController* wallet_controller);
82  WalletController* getWalletController();
83 #endif
84 
85 #ifdef ENABLE_WALLET
86 
90  void addWallet(WalletModel* walletModel);
91  void removeWallet(WalletModel* walletModel);
92  void removeAllWallets();
93 #endif // ENABLE_WALLET
94  bool enableWallet = false;
95 
99  bool hasTrayIcon() const { return trayIcon; }
100 
103 
104  bool isPrivacyModeActivated() const;
105 
106 protected:
107  void changeEvent(QEvent *e) override;
108  void closeEvent(QCloseEvent *event) override;
109  void showEvent(QShowEvent *event) override;
110  void dragEnterEvent(QDragEnterEvent *event) override;
111  void dropEvent(QDropEvent *event) override;
112  bool eventFilter(QObject *object, QEvent *event) override;
113 
114 private:
117  std::unique_ptr<interfaces::Handler> m_handler_message_box;
118  std::unique_ptr<interfaces::Handler> m_handler_question;
121 
123  QLabel* labelWalletEncryptionIcon = nullptr;
124  QLabel* labelWalletHDStatusIcon = nullptr;
128  QLabel* progressBarLabel = nullptr;
130  QProgressDialog* progressDialog = nullptr;
131 
132  QMenuBar* appMenuBar = nullptr;
133  QToolBar* appToolBar = nullptr;
134  QAction* overviewAction = nullptr;
135  QAction* historyAction = nullptr;
136  QAction* quitAction = nullptr;
137  QAction* sendCoinsAction = nullptr;
138  QAction* sendCoinsMenuAction = 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* receiveCoinsMenuAction = nullptr;
148  QAction* optionsAction = nullptr;
149  QAction* toggleHideAction = 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_close_wallet_action{nullptr};
161  QAction* m_close_all_wallets_action{nullptr};
162  QAction* m_wallet_selector_label_action = nullptr;
163  QAction* m_wallet_selector_action = nullptr;
164  QAction* m_mask_values_action{nullptr};
165 
166  QLabel *m_wallet_selector_label = nullptr;
167  QComboBox* m_wallet_selector = nullptr;
168 
169  QSystemTrayIcon* trayIcon = nullptr;
170  const std::unique_ptr<QMenu> trayIconMenu;
172  RPCConsole* rpcConsole = nullptr;
175 
176 #ifdef Q_OS_MAC
177  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
178 #endif
179 
181  int prevBlocks = 0;
182  int spinnerFrame = 0;
183 
186 
188  void createActions();
190  void createMenuBar();
192  void createToolBars();
194  void createTrayIcon();
196  void createTrayIconMenu();
197 
199  void setWalletActionsEnabled(bool enabled);
200 
202  void subscribeToCoreSignals();
203 
205  void updateNetworkState();
206 
208 
211 
212 Q_SIGNALS:
214  void receivedURI(const QString &uri);
216  void consoleShown(RPCConsole* console);
217  void setPrivacy(bool privacy);
218 
219 public Q_SLOTS:
221  void setNumConnections(int count);
223  void setNetworkActive(bool networkActive);
225  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state);
226 
235  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr, const QString& detailed_message = QString());
236 
237 #ifdef ENABLE_WALLET
238  void setCurrentWallet(WalletModel* wallet_model);
239  void setCurrentWalletBySelectorIndex(int index);
242  void updateWalletStatus();
243 
244 private:
249  void setEncryptionStatus(int status);
250 
255  void setHDStatus(bool privkeyDisabled, int hdEnabled);
256 
257 public Q_SLOTS:
258  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
259 
261  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
262 #endif // ENABLE_WALLET
263 
264 private:
266  void updateProxyIcon();
267  void updateWindowTitle();
268 
269 public Q_SLOTS:
270 #ifdef ENABLE_WALLET
271 
272  void gotoOverviewPage();
274  void gotoHistoryPage();
276  void gotoReceiveCoinsPage();
278  void gotoSendCoinsPage(QString addr = "");
279 
281  void gotoSignMessageTab(QString addr = "");
283  void gotoVerifyMessageTab(QString addr = "");
285  void gotoLoadPSBT(bool from_clipboard = false);
286 
288  void openClicked();
289 #endif // ENABLE_WALLET
290 
291  void optionsClicked();
293  void aboutClicked();
295  void showDebugWindow();
299  void showHelpMessageClicked();
300 #ifndef Q_OS_MAC
301 
302  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
303 #else
304 
305  void macosDockIconActivated();
306 #endif
307 
310  void showNormalIfMinimized(bool fToggleHidden);
312  void toggleHidden();
313 
315  void detectShutdown();
316 
318  void showProgress(const QString &title, int nProgress);
319 
321  void setTrayIconVisible(bool);
322 
323  void showModalOverlay();
324 };
325 
326 class UnitDisplayStatusBarControl : public QLabel
327 {
328  Q_OBJECT
329 
330 public:
331  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
334 
335 protected:
337  void mousePressEvent(QMouseEvent *event) override;
338 
339 private:
341  QMenu* menu;
342 
344  void onDisplayUnitsClicked(const QPoint& point);
346  void createContextMenu();
347 
348 private Q_SLOTS:
350  void updateDisplayUnit(int newUnits);
352  void onMenuSelection(QAction* action);
353 };
354 
355 #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
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: bitcoingui.cpp:934
QAction * receiveCoinsAction
Definition: bitcoingui.h:146
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:122
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
QMenuBar * appMenuBar
Definition: bitcoingui.h:132
QAction * m_mask_values_action
Definition: bitcoingui.h:164
QAction * signMessageAction
Definition: bitcoingui.h:141
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:57
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:106
QAction * aboutAction
Definition: bitcoingui.h:145
void updateNetworkState()
Update UI with latest network info from model.
Definition: bitcoingui.cpp:900
QLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:124
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:309
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
QProgressDialog * progressDialog
Definition: bitcoingui.h:130
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:752
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:834
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:125
ClientModel * clientModel
Definition: bitcoingui.h:119
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:540
QAction * m_load_psbt_action
Definition: bitcoingui.h:143
ModalOverlay * modalOverlay
Definition: bitcoingui.h:174
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:765
RPCConsole * rpcConsole
Definition: bitcoingui.h:172
QAction * m_wallet_selector_action
Definition: bitcoingui.h:163
QAction * overviewAction
Definition: bitcoingui.h:134
QAction * verifyMessageAction
Definition: bitcoingui.h:142
QAction * quitAction
Definition: bitcoingui.h:136
QAction * m_open_wallet_action
Definition: bitcoingui.h:158
QAction * m_close_wallet_action
Definition: bitcoingui.h:160
QAction * historyAction
Definition: bitcoingui.h:135
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:732
QAction * aboutQtAction
Definition: bitcoingui.h:153
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:159
Bitcoin GUI main class.
Definition: bitcoingui.h:66
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:173
QLabel * progressBarLabel
Definition: bitcoingui.h:128
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:169
QAction * showHelpMessageAction
Definition: bitcoingui.h:156
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:20
void changeEvent(QEvent *e) override
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:126
QAction * backupWalletAction
Definition: bitcoingui.h:151
QAction * m_load_psbt_clipboard_action
Definition: bitcoingui.h:144
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:948
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:140
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void showModalOverlay()
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:185
WalletController * m_wallet_controller
Definition: bitcoingui.h:116
const PlatformStyle * platformStyle
Definition: bitcoingui.h:184
QAction * toggleHideAction
Definition: bitcoingui.h:149
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:162
OptionsModel * optionsModel
Definition: bitcoingui.h:340
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:166
void optionsClicked()
Show configuration dialog.
Definition: bitcoingui.cpp:820
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:959
QToolBar * appToolBar
Definition: bitcoingui.h:133
WalletFrame * walletFrame
Definition: bitcoingui.h:120
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:139
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:77
void setTrayIconVisible(bool)
When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly.
bool enableWallet
Definition: bitcoingui.h:94
QAction * openRPCConsoleAction
Definition: bitcoingui.h:154
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:161
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:42
QLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:123
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:127
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:129
void updateWindowTitle()
void showHelpMessageClicked()
Show help message dialog.
Definition: bitcoingui.cpp:846
Notificator * notificator
Definition: bitcoingui.h:171
Model for Bitcoin network client.
Definition: clientmodel.h:46
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
QAction * receiveCoinsMenuAction
Definition: bitcoingui.h:147
QAction * sendCoinsAction
Definition: bitcoingui.h:137
QAction * m_create_wallet_action
Definition: bitcoingui.h:157
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:155
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Handle tray icon clicked.
Definition: bitcoingui.cpp:804
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * changePassphraseAction
Definition: bitcoingui.h:152
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:99
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:170
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:118
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
QAction * sendCoinsMenuAction
Definition: bitcoingui.h:138
bool isPrivacyModeActivated() const
bool eventFilter(QObject *object, QEvent *event) override
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:181
void toggleHidden()
Simply calls showNormalIfMinimized(true) for use in SLOT() macro.
interfaces::Node & m_node
Definition: bitcoingui.h:115
int spinnerFrame
Definition: bitcoingui.h:182
static int count
Definition: tests.c:35
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: bitcoingui.cpp:929
"Help message" dialog box
Definition: utilitydialog.h:20
void closeEvent(QCloseEvent *event) override
QComboBox * m_wallet_selector
Definition: bitcoingui.h:167
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:840
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:239
QAction * optionsAction
Definition: bitcoingui.h:148
QAction * encryptWalletAction
Definition: bitcoingui.h:150
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:825
void updateHeadersSyncProgressLabel()
Definition: bitcoingui.cpp:939
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:71
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
A container for embedding all wallet-related controls into BitcoinGUI.
Definition: walletframe.h:29
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:443
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:117
void dragEnterEvent(QDragEnterEvent *event) override