Bitcoin Core  0.20.99
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 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 
102  void unsubscribeFromCoreSignals();
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:
116  WalletController* m_wallet_controller{nullptr};
117  std::unique_ptr<interfaces::Handler> m_handler_message_box;
118  std::unique_ptr<interfaces::Handler> m_handler_question;
119  ClientModel* clientModel = nullptr;
120  WalletFrame* walletFrame = nullptr;
121 
122  UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
123  QLabel* labelWalletEncryptionIcon = nullptr;
124  QLabel* labelWalletHDStatusIcon = nullptr;
125  GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
126  GUIUtil::ClickableLabel* connectionsControl = nullptr;
127  GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
128  QLabel* progressBarLabel = nullptr;
129  GUIUtil::ClickableProgressBar* progressBar = 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;
171  Notificator* notificator = nullptr;
172  RPCConsole* rpcConsole = nullptr;
173  HelpMessageDialog* helpMessageDialog = nullptr;
174  ModalOverlay* modalOverlay = 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 
207  void updateHeadersSyncProgressLabel();
208 
210  void openOptionsDialogWithTab(OptionsDialog::Tab tab);
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();
297  void showDebugWindowActivateConsole();
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);
333  void setOptionsModel(OptionsModel *optionsModel);
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
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
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
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:309
Controller between interfaces::Node, WalletModel instances and the GUI.
Bitcoin GUI main class.
Definition: bitcoingui.h:66
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:185
const PlatformStyle * platformStyle
Definition: bitcoingui.h:184
OptionsModel * optionsModel
Definition: bitcoingui.h:340
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:99
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:170
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
interfaces::Node & m_node
Definition: bitcoingui.h:115
static int count
Definition: tests.c:35
"Help message" dialog box
Definition: utilitydialog.h:20
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
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:117