Bitcoin Core  21.99.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/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 QDateTime;
53 class QMenu;
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);
83  WalletController* getWalletController();
84 #endif
85 
86 #ifdef ENABLE_WALLET
87 
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 
103  void unsubscribeFromCoreSignals();
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:
117  WalletController* m_wallet_controller{nullptr};
118  std::unique_ptr<interfaces::Handler> m_handler_message_box;
119  std::unique_ptr<interfaces::Handler> m_handler_question;
120  ClientModel* clientModel = nullptr;
121  WalletFrame* walletFrame = nullptr;
122 
123  UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
124  QLabel* labelWalletEncryptionIcon = nullptr;
125  QLabel* labelWalletHDStatusIcon = nullptr;
126  GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
127  GUIUtil::ClickableLabel* connectionsControl = nullptr;
128  GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
129  QLabel* progressBarLabel = nullptr;
130  GUIUtil::ClickableProgressBar* progressBar = 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* sendCoinsMenuAction = nullptr;
140  QAction* usedSendingAddressesAction = nullptr;
141  QAction* usedReceivingAddressesAction = nullptr;
142  QAction* signMessageAction = nullptr;
143  QAction* verifyMessageAction = nullptr;
144  QAction* m_load_psbt_action = nullptr;
145  QAction* m_load_psbt_clipboard_action = nullptr;
146  QAction* aboutAction = nullptr;
147  QAction* receiveCoinsAction = nullptr;
148  QAction* receiveCoinsMenuAction = nullptr;
149  QAction* optionsAction = nullptr;
150  QAction* toggleHideAction = nullptr;
151  QAction* encryptWalletAction = nullptr;
152  QAction* backupWalletAction = nullptr;
153  QAction* changePassphraseAction = nullptr;
154  QAction* aboutQtAction = nullptr;
155  QAction* openRPCConsoleAction = nullptr;
156  QAction* openAction = nullptr;
157  QAction* showHelpMessageAction = nullptr;
158  QAction* m_create_wallet_action{nullptr};
159  QAction* m_open_wallet_action{nullptr};
160  QMenu* m_open_wallet_menu{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;
172  Notificator* notificator = nullptr;
173  RPCConsole* rpcConsole = nullptr;
174  HelpMessageDialog* helpMessageDialog = nullptr;
175  ModalOverlay* modalOverlay = nullptr;
176 
177 #ifdef Q_OS_MAC
178  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
179 #endif
180 
182  int prevBlocks = 0;
183  int spinnerFrame = 0;
184 
187 
189  void createActions();
191  void createMenuBar();
193  void createToolBars();
195  void createTrayIcon();
197  void createTrayIconMenu();
198 
200  void setWalletActionsEnabled(bool enabled);
201 
203  void subscribeToCoreSignals();
204 
206  void updateNetworkState();
207 
208  void updateHeadersSyncProgressLabel();
209 
211  void openOptionsDialogWithTab(OptionsDialog::Tab tab);
212 
213 Q_SIGNALS:
215  void receivedURI(const QString &uri);
217  void consoleShown(RPCConsole* console);
218  void setPrivacy(bool privacy);
219 
220 public Q_SLOTS:
222  void setNumConnections(int count);
224  void setNetworkActive(bool networkActive);
226  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state);
227 
236  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr, const QString& detailed_message = QString());
237 
238 #ifdef ENABLE_WALLET
239  void setCurrentWallet(WalletModel* wallet_model);
240  void setCurrentWalletBySelectorIndex(int index);
243  void updateWalletStatus();
244 
245 private:
250  void setEncryptionStatus(int status);
251 
256  void setHDStatus(bool privkeyDisabled, int hdEnabled);
257 
258 public Q_SLOTS:
259  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
260 
262  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
263 #endif // ENABLE_WALLET
264 
265 private:
267  void updateProxyIcon();
268  void updateWindowTitle();
269 
270 public Q_SLOTS:
271 #ifdef ENABLE_WALLET
272 
273  void gotoOverviewPage();
275  void gotoHistoryPage();
277  void gotoReceiveCoinsPage();
279  void gotoSendCoinsPage(QString addr = "");
280 
282  void gotoSignMessageTab(QString addr = "");
284  void gotoVerifyMessageTab(QString addr = "");
286  void gotoLoadPSBT(bool from_clipboard = false);
287 
289  void openClicked();
290 #endif // ENABLE_WALLET
291 
292  void optionsClicked();
294  void aboutClicked();
296  void showDebugWindow();
298  void showDebugWindowActivateConsole();
300  void showHelpMessageClicked();
301 #ifndef Q_OS_MAC
302 
303  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
304 #else
305 
306  void macosDockIconActivated();
307 #endif
308 
311  void showNormalIfMinimized(bool fToggleHidden);
313  void toggleHidden();
314 
316  void detectShutdown();
317 
319  void showProgress(const QString &title, int nProgress);
320 
321  void showModalOverlay();
322 };
323 
324 class UnitDisplayStatusBarControl : public QLabel
325 {
326  Q_OBJECT
327 
328 public:
329  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
331  void setOptionsModel(OptionsModel *optionsModel);
332 
333 protected:
335  void mousePressEvent(QMouseEvent *event) override;
336 
337 private:
339  QMenu* menu;
340 
342  void onDisplayUnitsClicked(const QPoint& point);
344  void createContextMenu();
345 
346 private Q_SLOTS:
348  void updateDisplayUnit(int newUnits);
350  void onMenuSelection(QAction* action);
351 };
352 
353 #endif // BITCOIN_QT_BITCOINGUI_H
Local Bitcoin RPC console.
Definition: rpcconsole.h:37
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:98
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:310
Controller between interfaces::Node, WalletModel instances and the GUI.
Bitcoin GUI main class.
Definition: bitcoingui.h:67
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:20
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:186
const PlatformStyle * platformStyle
Definition: bitcoingui.h:185
OptionsModel * optionsModel
Definition: bitcoingui.h:338
Cross-platform desktop notification client.
Definition: notificator.h:24
Block and header tip information.
Definition: node.h:42
Model for Bitcoin network client.
Definition: clientmodel.h:46
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:100
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:171
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:119
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
interfaces::Node & m_node
Definition: bitcoingui.h:116
static int count
Definition: tests.c:35
"Help message" dialog box
Definition: utilitydialog.h:20
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:72
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
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:118