Bitcoin ABC  0.22.13
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 <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 } // namespace interfaces
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 } // namespace GUIUtil
61 
67 class BitcoinGUI : public QMainWindow {
68  Q_OBJECT
69 
70 public:
71  static const std::string DEFAULT_UIPLATFORM;
72 
73  explicit BitcoinGUI(interfaces::Node &node, const Config *,
74  const PlatformStyle *platformStyle,
75  const NetworkStyle *networkStyle,
76  QWidget *parent = nullptr);
77  ~BitcoinGUI();
78 
84  void setClientModel(ClientModel *clientModel);
85 #ifdef ENABLE_WALLET
86  void setWalletController(WalletController *wallet_controller);
87 #endif
88 
89 #ifdef ENABLE_WALLET
90 
95  void addWallet(WalletModel *walletModel);
96  void removeWallet(WalletModel *walletModel);
97  void removeAllWallets();
98 #endif // ENABLE_WALLET
99  bool enableWallet = false;
100 
102  void unsubscribeFromCoreSignals();
103 
108  bool hasTrayIcon() const { return trayIcon; }
109 
110 protected:
111  void changeEvent(QEvent *e) override;
112  void closeEvent(QCloseEvent *event) override;
113  void showEvent(QShowEvent *event) override;
114  void dragEnterEvent(QDragEnterEvent *event) override;
115  void dropEvent(QDropEvent *event) override;
116  bool eventFilter(QObject *object, QEvent *event) override;
117 
118 private:
120  WalletController *m_wallet_controller{nullptr};
121  std::unique_ptr<interfaces::Handler> m_handler_message_box;
122  std::unique_ptr<interfaces::Handler> m_handler_question;
123  ClientModel *clientModel = nullptr;
124  WalletFrame *walletFrame = nullptr;
125 
126  UnitDisplayStatusBarControl *unitDisplayControl = nullptr;
127  QLabel *labelWalletEncryptionIcon = nullptr;
128  QLabel *labelWalletHDStatusIcon = nullptr;
129  GUIUtil::ClickableLabel *labelProxyIcon = nullptr;
130  GUIUtil::ClickableLabel *connectionsControl = nullptr;
131  GUIUtil::ClickableLabel *labelBlocksIcon = nullptr;
132  QLabel *progressBarLabel = nullptr;
133  GUIUtil::ClickableProgressBar *progressBar = nullptr;
134  QProgressDialog *progressDialog = nullptr;
135 
136  QMenuBar *appMenuBar = nullptr;
137  QToolBar *appToolBar = nullptr;
138  QAction *overviewAction = nullptr;
139  QAction *historyAction = nullptr;
140  QAction *quitAction = nullptr;
141  QAction *sendCoinsAction = nullptr;
142  QAction *sendCoinsMenuAction = nullptr;
143  QAction *usedSendingAddressesAction = nullptr;
144  QAction *usedReceivingAddressesAction = nullptr;
145  QAction *signMessageAction = nullptr;
146  QAction *verifyMessageAction = nullptr;
147  QAction *m_load_psbt_action = nullptr;
148  QAction *aboutAction = nullptr;
149  QAction *receiveCoinsAction = nullptr;
150  QAction *receiveCoinsMenuAction = nullptr;
151  QAction *optionsAction = nullptr;
152  QAction *toggleHideAction = nullptr;
153  QAction *encryptWalletAction = nullptr;
154  QAction *backupWalletAction = nullptr;
155  QAction *changePassphraseAction = nullptr;
156  QAction *aboutQtAction = nullptr;
157  QAction *openRPCConsoleAction = nullptr;
158  QAction *openAction = nullptr;
159  QAction *showHelpMessageAction = nullptr;
160  QAction *m_create_wallet_action{nullptr};
161  QAction *m_open_wallet_action{nullptr};
162  QMenu *m_open_wallet_menu{nullptr};
163  QAction *m_close_wallet_action{nullptr};
164  QAction *m_wallet_selector_label_action = nullptr;
165  QAction *m_wallet_selector_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 
185  const Config *config;
188 
190  void createActions();
192  void createMenuBar();
194  void createToolBars();
196  void createTrayIcon();
198  void createTrayIconMenu();
199 
201  void setWalletActionsEnabled(bool enabled);
202 
204  void subscribeToCoreSignals();
205 
207  void updateNetworkState();
208 
209  void updateHeadersSyncProgressLabel();
210 
212  void openOptionsDialogWithTab(OptionsDialog::Tab tab);
213 
214 Q_SIGNALS:
216  void receivedURI(const QString &uri);
218  void consoleShown(RPCConsole *console);
219 
220 public Q_SLOTS:
222  void setNumConnections(int count);
224  void setNetworkActive(bool networkActive);
226  void setNumBlocks(int count, const QDateTime &blockDate,
227  double nVerificationProgress, bool headers,
228  SynchronizationState sync_state);
229 
242  void message(const QString &title, QString message, unsigned int style,
243  bool *ret = nullptr,
244  const QString &detailed_message = QString());
245 
246 #ifdef ENABLE_WALLET
247  void setCurrentWallet(WalletModel *wallet_model);
248  void setCurrentWalletBySelectorIndex(int index);
251  void updateWalletStatus();
252 
253 private:
258  void setEncryptionStatus(int status);
259 
264  void setHDStatus(bool privkeyDisabled, int hdEnabled);
265 
266 public Q_SLOTS:
267  bool handlePaymentRequest(const SendCoinsRecipient &recipient);
268 
270  void incomingTransaction(const QString &date, int unit, const Amount amount,
271  const QString &type, const QString &address,
272  const QString &label, const QString &walletName);
273 #endif // ENABLE_WALLET
274 
275 private:
277  void updateProxyIcon();
278  void updateWindowTitle();
279 
280 public Q_SLOTS:
281 #ifdef ENABLE_WALLET
282 
283  void gotoOverviewPage();
285  void gotoHistoryPage();
287  void gotoReceiveCoinsPage();
289  void gotoSendCoinsPage(QString addr = "");
290 
292  void gotoSignMessageTab(QString addr = "");
294  void gotoVerifyMessageTab(QString addr = "");
296  void gotoLoadPSBT();
297 
299  void openClicked();
300 #endif // ENABLE_WALLET
301 
302  void optionsClicked();
304  void aboutClicked();
306  void showDebugWindow();
308  void showDebugWindowActivateConsole();
310  void showHelpMessageClicked();
311 #ifndef Q_OS_MAC
312 
313  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
314 #else
315 
316  void macosDockIconActivated();
317 #endif
318 
322  void showNormalIfMinimized(bool fToggleHidden);
324  void toggleHidden();
325 
327  void detectShutdown();
328 
330  void showProgress(const QString &title, int nProgress);
331 
334  void setTrayIconVisible(bool);
335 
336  void showModalOverlay();
337 };
338 
339 class UnitDisplayStatusBarControl : public QLabel {
340  Q_OBJECT
341 
342 public:
343  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
345  void setOptionsModel(OptionsModel *optionsModel);
346 
347 protected:
349  void mousePressEvent(QMouseEvent *event) override;
350 
351 private:
353  QMenu *menu;
354 
356  void onDisplayUnitsClicked(const QPoint &point);
359  void createContextMenu();
360 
361 private Q_SLOTS:
364  void updateDisplayUnit(int newUnits);
366  void onMenuSelection(QAction *action);
367 };
368 
369 #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:128
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:321
Definition: amount.h:17
Controller between interfaces::Node, WalletModel instances and the GUI.
const Config * config
Definition: bitcoingui.h:185
Bitcoin GUI main class.
Definition: bitcoingui.h:67
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:20
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:187
const PlatformStyle * platformStyle
Definition: bitcoingui.h:186
Definition: config.h:19
OptionsModel * optionsModel
Definition: bitcoingui.h:352
Cross-platform desktop notification client.
Definition: notificator.h:24
Model for Bitcoin network client.
Definition: clientmodel.h:34
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:108
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:171
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:48
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:122
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
interfaces::Node & m_node
Definition: bitcoingui.h:119
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:45
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:121