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  QAction* m_close_wallet_action{nullptr};
152  QAction* m_wallet_selector_label_action = nullptr;
153  QAction* m_wallet_selector_action = nullptr;
154 
155  QLabel *m_wallet_selector_label = nullptr;
156  QComboBox* m_wallet_selector = nullptr;
157 
158  QSystemTrayIcon* trayIcon = nullptr;
159  const std::unique_ptr<QMenu> trayIconMenu;
160  Notificator* notificator = nullptr;
161  RPCConsole* rpcConsole = nullptr;
162  HelpMessageDialog* helpMessageDialog = nullptr;
163  ModalOverlay* modalOverlay = nullptr;
164 
165 #ifdef Q_OS_MAC
166  CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
167 #endif
168 
170  int prevBlocks = 0;
171  int spinnerFrame = 0;
172 
175 
177  void createActions();
179  void createMenuBar();
181  void createToolBars();
183  void createTrayIcon();
185  void createTrayIconMenu();
186 
188  void setWalletActionsEnabled(bool enabled);
189 
191  void subscribeToCoreSignals();
192 
194  void updateNetworkState();
195 
196  void updateHeadersSyncProgressLabel();
197 
199  void openOptionsDialogWithTab(OptionsDialog::Tab tab);
200 
201 Q_SIGNALS:
203  void receivedURI(const QString &uri);
205  void consoleShown(RPCConsole* console);
206 
207 public Q_SLOTS:
209  void setNumConnections(int count);
211  void setNetworkActive(bool networkActive);
213  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
214 
222  void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
223 
224 #ifdef ENABLE_WALLET
225  void setCurrentWallet(WalletModel* wallet_model);
226  void setCurrentWalletBySelectorIndex(int index);
229  void updateWalletStatus();
230 
231 private:
236  void setEncryptionStatus(int status);
237 
242  void setHDStatus(bool privkeyDisabled, int hdEnabled);
243 
244 public Q_SLOTS:
245  bool handlePaymentRequest(const SendCoinsRecipient& recipient);
246 
248  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName);
249 #endif // ENABLE_WALLET
250 
251 private:
253  void updateProxyIcon();
254  void updateWindowTitle();
255 
256 public Q_SLOTS:
257 #ifdef ENABLE_WALLET
258 
259  void gotoOverviewPage();
261  void gotoHistoryPage();
263  void gotoReceiveCoinsPage();
265  void gotoSendCoinsPage(QString addr = "");
266 
268  void gotoSignMessageTab(QString addr = "");
270  void gotoVerifyMessageTab(QString addr = "");
271 
273  void openClicked();
274 #endif // ENABLE_WALLET
275 
276  void optionsClicked();
278  void aboutClicked();
280  void showDebugWindow();
282  void showDebugWindowActivateConsole();
284  void showHelpMessageClicked();
285 #ifndef Q_OS_MAC
286 
287  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
288 #else
289 
290  void macosDockIconActivated();
291 #endif
292 
295  void showNormalIfMinimized(bool fToggleHidden);
297  void toggleHidden();
298 
300  void detectShutdown();
301 
303  void showProgress(const QString &title, int nProgress);
304 
306  void setTrayIconVisible(bool);
307 
308  void showModalOverlay();
309 };
310 
311 class UnitDisplayStatusBarControl : public QLabel
312 {
313  Q_OBJECT
314 
315 public:
316  explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
318  void setOptionsModel(OptionsModel *optionsModel);
319 
320 protected:
322  void mousePressEvent(QMouseEvent *event);
323 
324 private:
326  QMenu* menu;
327 
329  void onDisplayUnitsClicked(const QPoint& point);
331  void createContextMenu();
332 
333 private Q_SLOTS:
335  void updateDisplayUnit(int newUnits);
337  void onMenuSelection(QAction* action);
338 };
339 
340 #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:294
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:174
const PlatformStyle * platformStyle
Definition: bitcoingui.h:173
OptionsModel * optionsModel
Definition: bitcoingui.h:325
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:159
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
"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