Bitcoin ABC  0.26.3
P2P Digital Currency
bitcoingui.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2019 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)
9 #include <config/bitcoin-config.h>
10 #endif
11 
12 #include <qt/optionsdialog.h>
13 
14 #include <consensus/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 Config;
30 class HelpMessageDialog;
31 class ModalOverlay;
32 class NetworkStyle;
33 class Notificator;
34 class OptionsModel;
35 class PlatformStyle;
36 class RPCConsole;
37 class SendCoinsRecipient;
38 enum class SynchronizationState;
40 class WalletController;
41 class WalletFrame;
42 class WalletModel;
43 
44 namespace interfaces {
45 class Handler;
46 class Node;
47 struct BlockAndHeaderTipInfo;
48 } // namespace interfaces
49 
50 QT_BEGIN_NAMESPACE
51 class QAction;
52 class QComboBox;
53 class QMenu;
54 class QProgressBar;
55 class QProgressDialog;
56 QT_END_NAMESPACE
57 
58 namespace GUIUtil {
59 class ClickableLabel;
61 } // namespace GUIUtil
62 
68 class BitcoinGUI : public QMainWindow {
69  Q_OBJECT
70 
71 public:
72  static const std::string DEFAULT_UIPLATFORM;
73 
74  explicit BitcoinGUI(interfaces::Node &node, const Config *,
76  const NetworkStyle *networkStyle,
77  QWidget *parent = nullptr);
78  ~BitcoinGUI();
79 
85  void setClientModel(ClientModel *clientModel = nullptr,
86  interfaces::BlockAndHeaderTipInfo *tip_info = nullptr);
87 #ifdef ENABLE_WALLET
88  void setWalletController(WalletController *wallet_controller);
89  WalletController *getWalletController();
90 #endif
91 
92 #ifdef ENABLE_WALLET
98  void addWallet(WalletModel *walletModel);
99  void removeWallet(WalletModel *walletModel);
100  void removeAllWallets();
101 #endif // ENABLE_WALLET
102  bool enableWallet = false;
103 
106 
107  bool isPrivacyModeActivated() const;
108 
113  bool hasTrayIcon() const { return trayIcon; }
114 
115 protected:
116  void changeEvent(QEvent *e) override;
117  void closeEvent(QCloseEvent *event) override;
118  void showEvent(QShowEvent *event) override;
119  void dragEnterEvent(QDragEnterEvent *event) override;
120  void dropEvent(QDropEvent *event) override;
121  bool eventFilter(QObject *object, QEvent *event) override;
122 
123 private:
126  std::unique_ptr<interfaces::Handler> m_handler_message_box;
127  std::unique_ptr<interfaces::Handler> m_handler_question;
130 
132  QLabel *labelWalletEncryptionIcon = nullptr;
133  QLabel *labelWalletHDStatusIcon = nullptr;
137  QLabel *progressBarLabel = nullptr;
139  QProgressDialog *progressDialog = nullptr;
140 
141  QMenuBar *appMenuBar = nullptr;
142  QToolBar *appToolBar = nullptr;
143  QAction *overviewAction = nullptr;
144  QAction *historyAction = nullptr;
145  QAction *quitAction = nullptr;
146  QAction *sendCoinsAction = nullptr;
147  QAction *sendCoinsMenuAction = nullptr;
148  QAction *usedSendingAddressesAction = nullptr;
149  QAction *usedReceivingAddressesAction = nullptr;
150  QAction *signMessageAction = nullptr;
151  QAction *verifyMessageAction = nullptr;
152  QAction *m_load_psbt_action = nullptr;
153  QAction *aboutAction = nullptr;
154  QAction *receiveCoinsAction = nullptr;
155  QAction *receiveCoinsMenuAction = nullptr;
156  QAction *optionsAction = nullptr;
157  QAction *toggleHideAction = nullptr;
158  QAction *encryptWalletAction = nullptr;
159  QAction *backupWalletAction = nullptr;
160  QAction *changePassphraseAction = nullptr;
161  QAction *aboutQtAction = nullptr;
162  QAction *openRPCConsoleAction = nullptr;
163  QAction *openAction = nullptr;
164  QAction *showHelpMessageAction = nullptr;
165  QAction *m_create_wallet_action{nullptr};
166  QAction *m_open_wallet_action{nullptr};
167  QMenu *m_open_wallet_menu{nullptr};
168  QAction *m_close_wallet_action{nullptr};
169  QAction *m_close_all_wallets_action{nullptr};
170  QAction *m_wallet_selector_label_action = nullptr;
171  QAction *m_wallet_selector_action = nullptr;
172  QAction *m_mask_values_action{nullptr};
173 
174  QLabel *m_wallet_selector_label = nullptr;
175  QComboBox *m_wallet_selector = nullptr;
176 
177  QSystemTrayIcon *trayIcon = nullptr;
178  const std::unique_ptr<QMenu> trayIconMenu;
180  RPCConsole *rpcConsole = nullptr;
183 
184 #ifdef Q_OS_MAC
185  CAppNapInhibitor *m_app_nap_inhibitor = nullptr;
186 #endif
187 
189  int prevBlocks = 0;
190  int spinnerFrame = 0;
191 
192  const Config *config;
195 
197  void createActions();
199  void createMenuBar();
201  void createToolBars();
203  void createTrayIcon();
205  void createTrayIconMenu();
206 
208  void setWalletActionsEnabled(bool enabled);
209 
211  void subscribeToCoreSignals();
212 
214  void updateNetworkState();
215 
217 
220 
221 Q_SIGNALS:
223  void receivedURI(const QString &uri);
225  void consoleShown(RPCConsole *console);
226  void setPrivacy(bool privacy);
227 
228 public Q_SLOTS:
230  void setNumConnections(int count);
232  void setNetworkActive(bool networkActive);
234  void setNumBlocks(int count, const QDateTime &blockDate,
235  double nVerificationProgress, bool headers,
236  SynchronizationState sync_state);
237 
250  void message(const QString &title, QString message, unsigned int style,
251  bool *ret = nullptr,
252  const QString &detailed_message = QString());
253 
254 #ifdef ENABLE_WALLET
255  void setCurrentWallet(WalletModel *wallet_model);
256  void setCurrentWalletBySelectorIndex(int index);
259  void updateWalletStatus();
260 
261 private:
266  void setEncryptionStatus(int status);
267 
272  void setHDStatus(bool privkeyDisabled, int hdEnabled);
273 
274 public Q_SLOTS:
275  bool handlePaymentRequest(const SendCoinsRecipient &recipient);
276 
278  void incomingTransaction(const QString &date, int unit, const Amount amount,
279  const QString &type, const QString &address,
280  const QString &label, const QString &walletName);
281 #endif // ENABLE_WALLET
282 
283 private:
285  void updateProxyIcon();
286  void updateWindowTitle();
287 
288 public Q_SLOTS:
289 #ifdef ENABLE_WALLET
291  void gotoOverviewPage();
293  void gotoHistoryPage();
295  void gotoReceiveCoinsPage();
297  void gotoSendCoinsPage(QString addr = "");
298 
300  void gotoSignMessageTab(QString addr = "");
302  void gotoVerifyMessageTab(QString addr = "");
304  void gotoLoadPSBT();
305 
307  void openClicked();
308 #endif // ENABLE_WALLET
310  void optionsClicked();
312  void aboutClicked();
314  void showDebugWindow();
318  void showHelpMessageClicked();
319 #ifndef Q_OS_MAC
321  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
322 #else
324  void macosDockIconActivated();
325 #endif
326 
330  void showNormalIfMinimized(bool fToggleHidden);
332  void toggleHidden();
333 
335  void detectShutdown();
336 
338  void showProgress(const QString &title, int nProgress);
339 
342  void setTrayIconVisible(bool);
343 
344  void showModalOverlay();
345 };
346 
347 class UnitDisplayStatusBarControl : public QLabel {
348  Q_OBJECT
349 
350 public:
351  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
354 
355 protected:
357  void mousePressEvent(QMouseEvent *event) override;
358 
359 private:
361  QMenu *menu;
362 
364  void onDisplayUnitsClicked(const QPoint &point);
367  void createContextMenu();
368 
369 private Q_SLOTS:
372  void updateDisplayUnit(int newUnits);
374  void onMenuSelection(QAction *action);
375 };
376 
377 #endif // BITCOIN_QT_BITCOINGUI_H
Bitcoin GUI main class.
Definition: bitcoingui.h:68
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:138
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:169
void showEvent(QShowEvent *event) override
QLabel * progressBarLabel
Definition: bitcoingui.h:137
QAction * m_open_wallet_action
Definition: bitcoingui.h:166
const Config * config
Definition: bitcoingui.h:192
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:72
QAction * openAction
Definition: bitcoingui.h:163
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Definition: bitcoingui.cpp:655
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:135
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
ModalOverlay * modalOverlay
Definition: bitcoingui.h:182
QAction * changePassphraseAction
Definition: bitcoingui.h:160
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
QAction * receiveCoinsMenuAction
Definition: bitcoingui.h:155
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:189
QAction * openRPCConsoleAction
Definition: bitcoingui.h:162
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:194
void changeEvent(QEvent *e) override
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:134
QAction * historyAction
Definition: bitcoingui.h:144
bool eventFilter(QObject *object, QEvent *event) override
QMenu * m_open_wallet_menu
Definition: bitcoingui.h:167
QAction * toggleHideAction
Definition: bitcoingui.h:157
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:849
QAction * quitAction
Definition: bitcoingui.h:145
void setPrivacy(bool privacy)
QProgressDialog * progressDialog
Definition: bitcoingui.h:139
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:126
WalletFrame * walletFrame
Definition: bitcoingui.h:129
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * receiveCoinsAction
Definition: bitcoingui.h:154
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:178
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:148
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void closeEvent(QCloseEvent *event) override
QAction * verifyMessageAction
Definition: bitcoingui.h:151
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:863
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:181
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:923
void toggleHidden()
Simply calls showNormalIfMinimized(true) for use in SLOT() macro.
QAction * encryptWalletAction
Definition: bitcoingui.h:158
void updateNetworkState()
Update UI with latest network info from model.
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:246
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:932
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:113
QAction * m_mask_values_action
Definition: bitcoingui.h:172
int spinnerFrame
Definition: bitcoingui.h:190
QAction * aboutAction
Definition: bitcoingui.h:153
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:937
void dropEvent(QDropEvent *event) override
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:149
void subscribeToCoreSignals()
Connect core signals to GUI client.
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:616
QAction * m_wallet_selector_action
Definition: bitcoingui.h:171
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:131
QAction * optionsAction
Definition: bitcoingui.h:156
void updateWindowTitle()
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:830
const PlatformStyle * platformStyle
Definition: bitcoingui.h:193
void dragEnterEvent(QDragEnterEvent *event) override
QAction * m_close_wallet_action
Definition: bitcoingui.h:168
QLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:132
QAction * overviewAction
Definition: bitcoingui.h:143
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:136
interfaces::Node & m_node
Definition: bitcoingui.h:124
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.
QAction * m_create_wallet_action
Definition: bitcoingui.h:165
QAction * m_load_psbt_action
Definition: bitcoingui.h:152
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:170
WalletController * m_wallet_controller
Definition: bitcoingui.h:125
bool enableWallet
Definition: bitcoingui.h:102
RPCConsole * rpcConsole
Definition: bitcoingui.h:180
QAction * backupWalletAction
Definition: bitcoingui.h:159
QAction * sendCoinsMenuAction
Definition: bitcoingui.h:147
QAction * showHelpMessageAction
Definition: bitcoingui.h:164
QAction * aboutQtAction
Definition: bitcoingui.h:161
QComboBox * m_wallet_selector
Definition: bitcoingui.h:175
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:174
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:329
ClientModel * clientModel
Definition: bitcoingui.h:128
void updateHeadersSyncProgressLabel()
void setTrayIconVisible(bool)
When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly.
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:518
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:177
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:942
QAction * sendCoinsAction
Definition: bitcoingui.h:146
QToolBar * appToolBar
Definition: bitcoingui.h:142
QLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:133
void setNumConnections(int count)
Set number of connections shown in the UI.
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Handle tray icon clicked.
Definition: bitcoingui.cpp:906
QAction * signMessageAction
Definition: bitcoingui.h:150
void showModalOverlay()
Notificator * notificator
Definition: bitcoingui.h:179
BitcoinGUI(interfaces::Node &node, const Config *, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:76
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:127
QMenuBar * appMenuBar
Definition: bitcoingui.h:141
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Model for Bitcoin network client.
Definition: clientmodel.h:36
Definition: config.h:17
"Help message" dialog box
Definition: utilitydialog.h:20
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:21
Cross-platform desktop notification client.
Definition: notificator.h:24
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:48
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
void updateDisplayUnit(int newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
void createContextMenu()
Creates context menu, its actions, and wires up all the relevant signals for mouse events.
OptionsModel * optionsModel
Definition: bitcoingui.h:360
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
void onMenuSelection(QAction *action)
Tells underlying optionsModel to update its current display unit.
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:47
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:57
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
Definition: init.h:28
Definition: amount.h:19
Block and header tip information.
Definition: node.h:48
static int count
Definition: tests.c:31
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:120