Bitcoin Core  0.18.99
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)
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 
42 namespace interfaces {
43 class Handler;
44 class Node;
45 }
46 
47 QT_BEGIN_NAMESPACE
48 class QAction;
49 class QComboBox;
50 class QMenu;
51 class QProgressBar;
52 class QProgressDialog;
53 QT_END_NAMESPACE
54 
55 namespace GUIUtil {
56 class ClickableLabel;
58 }
59 
64 class BitcoinGUI : public QMainWindow
65 {
66  Q_OBJECT
67 
68 public:
69  static const std::string DEFAULT_UIPLATFORM;
70 
71  explicit BitcoinGUI(interfaces::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = nullptr);
72  ~BitcoinGUI();
73 
77  void setClientModel(ClientModel *clientModel);
78 #ifdef ENABLE_WALLET
79  void setWalletController(WalletController* wallet_controller);
80 #endif
81 
82 #ifdef ENABLE_WALLET
83 
87  void addWallet(WalletModel* walletModel);
88  void removeWallet(WalletModel* walletModel);
89  void removeAllWallets();
90 #endif // ENABLE_WALLET
91  bool enableWallet = false;
92 
96  bool hasTrayIcon() const { return trayIcon; }
97 
99  void unsubscribeFromCoreSignals();
100 
101 protected:
102  void changeEvent(QEvent *e);
103  void closeEvent(QCloseEvent *event);
104  void showEvent(QShowEvent *event);
105  void dragEnterEvent(QDragEnterEvent *event);
106  void dropEvent(QDropEvent *event);
107  bool eventFilter(QObject *object, QEvent *event);
108 
109 private:
111  WalletController* m_wallet_controller{nullptr};
112  std::unique_ptr<interfaces::Handler> m_handler_message_box;
113  std::unique_ptr<interfaces::Handler> m_handler_question;
114  ClientModel* clientModel = nullptr;
115  WalletFrame* walletFrame = nullptr;
116 
117  UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
118  QLabel* labelWalletEncryptionIcon = nullptr;
119  QLabel* labelWalletHDStatusIcon = nullptr;
120  GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
121  GUIUtil::ClickableLabel* connectionsControl = nullptr;
122  GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
123  QLabel* progressBarLabel = nullptr;
124  GUIUtil::ClickableProgressBar* progressBar = nullptr;
125  QProgressDialog* progressDialog = nullptr;
126 
127  QMenuBar* appMenuBar = nullptr;
128  QToolBar* appToolBar = nullptr;
129  QAction* overviewAction = nullptr;
130  QAction* historyAction = nullptr;
131  QAction* quitAction = nullptr;
132  QAction* sendCoinsAction = nullptr;
133  QAction* sendCoinsMenuAction = nullptr;
134  QAction* usedSendingAddressesAction = nullptr;
135  QAction* usedReceivingAddressesAction = nullptr;
136  QAction* signMessageAction = nullptr;
137  QAction* verifyMessageAction = nullptr;
138  QAction* aboutAction = nullptr;
139  QAction* receiveCoinsAction = nullptr;
140  QAction* receiveCoinsMenuAction = nullptr;
141  QAction* optionsAction = nullptr;
142  QAction* toggleHideAction = nullptr;
143  QAction* encryptWalletAction = nullptr;
144  QAction* backupWalletAction = nullptr;
145  QAction* changePassphraseAction = nullptr;
146  QAction* aboutQtAction = nullptr;
147  QAction* openRPCConsoleAction = nullptr;
148  QAction* openAction = nullptr;
149  QAction* showHelpMessageAction = nullptr;
150  QAction* m_open_wallet_action{nullptr};
151  QMenu* m_open_wallet_menu{nullptr};
152  QAction* m_close_wallet_action{nullptr};
153  QAction* m_wallet_selector_label_action = nullptr;
154  QAction* m_wallet_selector_action = nullptr;
155 
156  QLabel *m_wallet_selector_label = nullptr;
157  QComboBox* m_wallet_selector = nullptr;
158 
159  QSystemTrayIcon* trayIcon = nullptr;
160  const std::unique_ptr<QMenu> trayIconMenu;
161  Notificator* notificator = nullptr;
162  RPCConsole* rpcConsole = nullptr;
163  HelpMessageDialog* helpMessageDialog = nullptr;
164  ModalOverlay* modalOverlay = nullptr;
165 
166 #ifdef Q_OS_MAC
167  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
168 #endif
169 
171  int prevBlocks = 0;
172  int spinnerFrame = 0;
173 
176 
178  void createActions();
180  void createMenuBar();
182  void createToolBars();
184  void createTrayIcon();
186  void createTrayIconMenu();
187 
189  void setWalletActionsEnabled(bool enabled);
190 
192  void subscribeToCoreSignals();
193 
195  void updateNetworkState();
196 
197  void updateHeadersSyncProgressLabel();
198 
200  void openOptionsDialogWithTab(OptionsDialog::Tab tab);
201 
202 Q_SIGNALS:
204  void receivedURI(const QString &uri);
206  void consoleShown(RPCConsole* console);
207 
208 public Q_SLOTS:
210  void setNumConnections(int count);
212  void setNetworkActive(bool networkActive);
214  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
215 
223  void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr);
224 
225 #ifdef ENABLE_WALLET
226  void setCurrentWallet(WalletModel* wallet_model);
227  void setCurrentWalletBySelectorIndex(int index);
230  void updateWalletStatus();
231 
232 private:
237  void setEncryptionStatus(int status);
238 
243  void setHDStatus(bool privkeyDisabled, int hdEnabled);
244 
245 public Q_SLOTS:
246  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
247 
249  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
250 #endif // ENABLE_WALLET
251 
252 private:
254  void updateProxyIcon();
255  void updateWindowTitle();
256 
257 public Q_SLOTS:
258 #ifdef ENABLE_WALLET
259 
260  void gotoOverviewPage();
262  void gotoHistoryPage();
264  void gotoReceiveCoinsPage();
266  void gotoSendCoinsPage(QString addr = "");
267 
269  void gotoSignMessageTab(QString addr = "");
271  void gotoVerifyMessageTab(QString addr = "");
272 
274  void openClicked();
275 #endif // ENABLE_WALLET
276 
277  void optionsClicked();
279  void aboutClicked();
281  void showDebugWindow();
283  void showDebugWindowActivateConsole();
285  void showHelpMessageClicked();
286 #ifndef Q_OS_MAC
287 
288  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
289 #else
290 
291  void macosDockIconActivated();
292 #endif
293 
296  void showNormalIfMinimized(bool fToggleHidden);
298  void toggleHidden();
299 
301  void detectShutdown();
302 
304  void showProgress(const QString &title, int nProgress);
305 
307  void setTrayIconVisible(bool);
308 
309  void showModalOverlay();
310 };
311 
312 class UnitDisplayStatusBarControl : public QLabel
313 {
314  Q_OBJECT
315 
316 public:
317  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
319  void setOptionsModel(OptionsModel *optionsModel);
320 
321 protected:
323  void mousePressEvent(QMouseEvent *event);
324 
325 private:
327  QMenu* menu;
328 
330  void onDisplayUnitsClicked(const QPoint& point);
332  void createContextMenu();
333 
334 private Q_SLOTS:
336  void updateDisplayUnit(int newUnits);
338  void onMenuSelection(QAction* action);
339 };
340 
341 #endif // BITCOIN_QT_BITCOINGUI_H
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:55
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:295
Controller between interfaces::Node, WalletModel instances and the GUI.
Bitcoin GUI main class.
Definition: bitcoingui.h:64
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:19
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:175
const PlatformStyle * platformStyle
Definition: bitcoingui.h:174
OptionsModel * optionsModel
Definition: bitcoingui.h:326
Cross-platform desktop notification client.
Definition: notificator.h:24
Model for Bitcoin network client.
Definition: clientmodel.h:44
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:96
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:160
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:29
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:113
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
interfaces::Node & m_node
Definition: bitcoingui.h:110
static int count
Definition: tests.c:45
"Help message" dialog box
Definition: utilitydialog.h:22
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:69
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:36
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:112