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 }
47 
48 QT_BEGIN_NAMESPACE
49 class QAction;
50 class QComboBox;
51 class QMenu;
52 class QProgressBar;
53 class QProgressDialog;
54 QT_END_NAMESPACE
55 
56 namespace GUIUtil {
57 class ClickableLabel;
59 }
60 
65 class BitcoinGUI : public QMainWindow
66 {
67  Q_OBJECT
68 
69 public:
70  static const std::string DEFAULT_UIPLATFORM;
71 
72  explicit BitcoinGUI(interfaces::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = nullptr);
73  ~BitcoinGUI();
74 
78  void setClientModel(ClientModel *clientModel);
79 #ifdef ENABLE_WALLET
80  void setWalletController(WalletController* wallet_controller);
81 #endif
82 
83 #ifdef ENABLE_WALLET
84 
88  void addWallet(WalletModel* walletModel);
89  void removeWallet(WalletModel* walletModel);
90  void removeAllWallets();
91 #endif // ENABLE_WALLET
92  bool enableWallet = false;
93 
97  bool hasTrayIcon() const { return trayIcon; }
98 
100  void unsubscribeFromCoreSignals();
101 
102  bool isPrivacyModeActivated() const;
103 
104 protected:
105  void changeEvent(QEvent *e) override;
106  void closeEvent(QCloseEvent *event) override;
107  void showEvent(QShowEvent *event) override;
108  void dragEnterEvent(QDragEnterEvent *event) override;
109  void dropEvent(QDropEvent *event) override;
110  bool eventFilter(QObject *object, QEvent *event) override;
111 
112 private:
114  WalletController* m_wallet_controller{nullptr};
115  std::unique_ptr<interfaces::Handler> m_handler_message_box;
116  std::unique_ptr<interfaces::Handler> m_handler_question;
117  ClientModel* clientModel = nullptr;
118  WalletFrame* walletFrame = nullptr;
119 
120  UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
121  QLabel* labelWalletEncryptionIcon = nullptr;
122  QLabel* labelWalletHDStatusIcon = nullptr;
123  GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
124  GUIUtil::ClickableLabel* connectionsControl = nullptr;
125  GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
126  QLabel* progressBarLabel = nullptr;
127  GUIUtil::ClickableProgressBar* progressBar = nullptr;
128  QProgressDialog* progressDialog = nullptr;
129 
130  QMenuBar* appMenuBar = nullptr;
131  QToolBar* appToolBar = nullptr;
132  QAction* overviewAction = nullptr;
133  QAction* historyAction = nullptr;
134  QAction* quitAction = nullptr;
135  QAction* sendCoinsAction = nullptr;
136  QAction* sendCoinsMenuAction = nullptr;
137  QAction* usedSendingAddressesAction = nullptr;
138  QAction* usedReceivingAddressesAction = nullptr;
139  QAction* signMessageAction = nullptr;
140  QAction* verifyMessageAction = nullptr;
141  QAction* m_load_psbt_action = nullptr;
142  QAction* m_load_psbt_clipboard_action = nullptr;
143  QAction* aboutAction = nullptr;
144  QAction* receiveCoinsAction = nullptr;
145  QAction* receiveCoinsMenuAction = nullptr;
146  QAction* optionsAction = nullptr;
147  QAction* toggleHideAction = nullptr;
148  QAction* encryptWalletAction = nullptr;
149  QAction* backupWalletAction = nullptr;
150  QAction* changePassphraseAction = nullptr;
151  QAction* aboutQtAction = nullptr;
152  QAction* openRPCConsoleAction = nullptr;
153  QAction* openAction = nullptr;
154  QAction* showHelpMessageAction = nullptr;
155  QAction* m_create_wallet_action{nullptr};
156  QAction* m_open_wallet_action{nullptr};
157  QMenu* m_open_wallet_menu{nullptr};
158  QAction* m_close_wallet_action{nullptr};
159  QAction* m_close_all_wallets_action{nullptr};
160  QAction* m_wallet_selector_label_action = nullptr;
161  QAction* m_wallet_selector_action = nullptr;
162  QAction* m_mask_values_action{nullptr};
163 
164  QLabel *m_wallet_selector_label = nullptr;
165  QComboBox* m_wallet_selector = nullptr;
166 
167  QSystemTrayIcon* trayIcon = nullptr;
168  const std::unique_ptr<QMenu> trayIconMenu;
169  Notificator* notificator = nullptr;
170  RPCConsole* rpcConsole = nullptr;
171  HelpMessageDialog* helpMessageDialog = nullptr;
172  ModalOverlay* modalOverlay = nullptr;
173 
174 #ifdef Q_OS_MAC
175  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
176 #endif
177 
179  int prevBlocks = 0;
180  int spinnerFrame = 0;
181 
184 
186  void createActions();
188  void createMenuBar();
190  void createToolBars();
192  void createTrayIcon();
194  void createTrayIconMenu();
195 
197  void setWalletActionsEnabled(bool enabled);
198 
200  void subscribeToCoreSignals();
201 
203  void updateNetworkState();
204 
205  void updateHeadersSyncProgressLabel();
206 
208  void openOptionsDialogWithTab(OptionsDialog::Tab tab);
209 
210 Q_SIGNALS:
212  void receivedURI(const QString &uri);
214  void consoleShown(RPCConsole* console);
215  void setPrivacy(bool privacy);
216 
217 public Q_SLOTS:
219  void setNumConnections(int count);
221  void setNetworkActive(bool networkActive);
223  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state);
224 
233  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr, const QString& detailed_message = QString());
234 
235 #ifdef ENABLE_WALLET
236  void setCurrentWallet(WalletModel* wallet_model);
237  void setCurrentWalletBySelectorIndex(int index);
240  void updateWalletStatus();
241 
242 private:
247  void setEncryptionStatus(int status);
248 
253  void setHDStatus(bool privkeyDisabled, int hdEnabled);
254 
255 public Q_SLOTS:
256  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
257 
259  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
260 #endif // ENABLE_WALLET
261 
262 private:
264  void updateProxyIcon();
265  void updateWindowTitle();
266 
267 public Q_SLOTS:
268 #ifdef ENABLE_WALLET
269 
270  void gotoOverviewPage();
272  void gotoHistoryPage();
274  void gotoReceiveCoinsPage();
276  void gotoSendCoinsPage(QString addr = "");
277 
279  void gotoSignMessageTab(QString addr = "");
281  void gotoVerifyMessageTab(QString addr = "");
283  void gotoLoadPSBT(bool from_clipboard = false);
284 
286  void openClicked();
287 #endif // ENABLE_WALLET
288 
289  void optionsClicked();
291  void aboutClicked();
293  void showDebugWindow();
295  void showDebugWindowActivateConsole();
297  void showHelpMessageClicked();
298 #ifndef Q_OS_MAC
299 
300  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
301 #else
302 
303  void macosDockIconActivated();
304 #endif
305 
308  void showNormalIfMinimized(bool fToggleHidden);
310  void toggleHidden();
311 
313  void detectShutdown();
314 
316  void showProgress(const QString &title, int nProgress);
317 
319  void setTrayIconVisible(bool);
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:36
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:56
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:108
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:307
Controller between interfaces::Node, WalletModel instances and the GUI.
Bitcoin GUI main class.
Definition: bitcoingui.h:65
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:183
const PlatformStyle * platformStyle
Definition: bitcoingui.h:182
OptionsModel * optionsModel
Definition: bitcoingui.h:338
Cross-platform desktop notification client.
Definition: notificator.h:24
Model for Bitcoin network client.
Definition: clientmodel.h:46
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:97
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:168
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:37
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:116
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
interfaces::Node & m_node
Definition: bitcoingui.h:113
static int count
Definition: tests.c:35
"Help message" dialog box
Definition: utilitydialog.h:24
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:70
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:43
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:115