Bitcoin ABC 0.30.5
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/clientmodel.h>
13#include <qt/optionsdialog.h>
14
15#include <consensus/amount.h>
16
17#include <QLabel>
18#include <QMainWindow>
19#include <QMap>
20#include <QPoint>
21#include <QSystemTrayIcon>
22
23#ifdef Q_OS_MAC
24#include <qt/macos_appnap.h>
25#endif
26
27#include <memory>
28
29class Config;
31class ModalOverlay;
32class NetworkStyle;
33class Notificator;
34class OptionsModel;
35class PlatformStyle;
36class RPCConsole;
38enum class SynchronizationState;
41class WalletFrame;
42class WalletModel;
43
44namespace interfaces {
45class Handler;
46class Node;
47struct BlockAndHeaderTipInfo;
48} // namespace interfaces
49
50QT_BEGIN_NAMESPACE
51class QAction;
52class QComboBox;
53class QMenu;
54class QProgressBar;
55class QProgressDialog;
56QT_END_NAMESPACE
57
58namespace GUIUtil {
59class ClickableLabel;
61} // namespace GUIUtil
62
68class BitcoinGUI : public QMainWindow {
69 Q_OBJECT
70
71public:
72 static const std::string DEFAULT_UIPLATFORM;
73
74 explicit BitcoinGUI(interfaces::Node &node, const Config *,
76 const NetworkStyle *networkStyle,
77 QWidget *parent = nullptr);
79
86 interfaces::BlockAndHeaderTipInfo *tip_info = nullptr);
87#ifdef ENABLE_WALLET
88 void setWalletController(WalletController *wallet_controller);
89 WalletController *getWalletController();
90#endif
91
92#ifdef ENABLE_WALLET
98 void addWallet(WalletModel *walletModel);
99 void removeWallet(WalletModel *walletModel);
100 void removeAllWallets();
101#endif // ENABLE_WALLET
102 bool enableWallet = false;
103
106
107 bool isPrivacyModeActivated() const;
108
113 bool hasTrayIcon() const { return trayIcon; }
114
115protected:
116 void changeEvent(QEvent *e) override;
117 void closeEvent(QCloseEvent *event) override;
118 void showEvent(QShowEvent *event) override;
119 void dragEnterEvent(QDragEnterEvent *event) override;
120 void dropEvent(QDropEvent *event) override;
121 bool eventFilter(QObject *object, QEvent *event) override;
122
123private:
126 std::unique_ptr<interfaces::Handler> m_handler_message_box;
127 std::unique_ptr<interfaces::Handler> m_handler_question;
130
132 QLabel *labelWalletEncryptionIcon = nullptr;
133 QLabel *labelWalletHDStatusIcon = nullptr;
137 QLabel *progressBarLabel = nullptr;
139 QProgressDialog *progressDialog = nullptr;
140
141 QMenuBar *appMenuBar = nullptr;
142 QToolBar *appToolBar = nullptr;
143 QAction *overviewAction = nullptr;
144 QAction *historyAction = nullptr;
145 QAction *quitAction = nullptr;
146 QAction *sendCoinsAction = nullptr;
147 QAction *sendCoinsMenuAction = nullptr;
148 QAction *usedSendingAddressesAction = nullptr;
150 QAction *signMessageAction = nullptr;
151 QAction *verifyMessageAction = nullptr;
152 QAction *m_load_psbt_action = nullptr;
153 QAction *aboutAction = nullptr;
154 QAction *receiveCoinsAction = nullptr;
155 QAction *receiveCoinsMenuAction = nullptr;
156 QAction *optionsAction = nullptr;
157 QAction *toggleHideAction = nullptr;
158 QAction *encryptWalletAction = nullptr;
159 QAction *backupWalletAction = nullptr;
160 QAction *changePassphraseAction = nullptr;
161 QAction *aboutQtAction = nullptr;
162 QAction *openRPCConsoleAction = nullptr;
163 QAction *openAction = nullptr;
164 QAction *showHelpMessageAction = nullptr;
165 QAction *m_create_wallet_action{nullptr};
166 QAction *m_open_wallet_action{nullptr};
167 QMenu *m_open_wallet_menu{nullptr};
168 QAction *m_close_wallet_action{nullptr};
169 QAction *m_close_all_wallets_action{nullptr};
171 QAction *m_wallet_selector_action = nullptr;
172 QAction *m_mask_values_action{nullptr};
173
174 QLabel *m_wallet_selector_label = nullptr;
175 QComboBox *m_wallet_selector = nullptr;
176
177 QSystemTrayIcon *trayIcon = nullptr;
178 const std::unique_ptr<QMenu> trayIconMenu;
183
184#ifdef Q_OS_MAC
185 CAppNapInhibitor *m_app_nap_inhibitor = nullptr;
186#endif
187
189 int prevBlocks = 0;
191
195
197 void createActions();
199 void createMenuBar();
201 void createToolBars();
203 void createTrayIcon();
205 void createTrayIconMenu();
206
208 void setWalletActionsEnabled(bool enabled);
209
212
214 void updateNetworkState();
215
217 void updateHeadersPresyncProgressLabel(int64_t height,
218 const QDateTime &blockDate);
219
222
223Q_SIGNALS:
225 void receivedURI(const QString &uri);
227 void consoleShown(RPCConsole *console);
228 void setPrivacy(bool privacy);
229
230public Q_SLOTS:
232 void setNumConnections(int count);
234 void setNetworkActive(bool networkActive);
236 void setNumBlocks(int count, const QDateTime &blockDate,
237 double nVerificationProgress, SyncType synctype,
238 SynchronizationState sync_state);
239
252 void message(const QString &title, QString message, unsigned int style,
253 bool *ret = nullptr,
254 const QString &detailed_message = QString());
255
256#ifdef ENABLE_WALLET
257 void setCurrentWallet(WalletModel *wallet_model);
258 void setCurrentWalletBySelectorIndex(int index);
261 void updateWalletStatus();
262
263private:
268 void setEncryptionStatus(int status);
269
274 void setHDStatus(bool privkeyDisabled, int hdEnabled);
275
276public Q_SLOTS:
277 bool handlePaymentRequest(const SendCoinsRecipient &recipient);
278
280 void incomingTransaction(const QString &date, int unit, const Amount amount,
281 const QString &type, const QString &address,
282 const QString &label, const QString &walletName);
283#endif // ENABLE_WALLET
284
285private:
287 void updateProxyIcon();
288 void updateWindowTitle();
289
290public Q_SLOTS:
291#ifdef ENABLE_WALLET
293 void gotoOverviewPage();
295 void gotoHistoryPage();
297 void gotoReceiveCoinsPage();
299 void gotoSendCoinsPage(QString addr = "");
300
302 void gotoSignMessageTab(QString addr = "");
304 void gotoVerifyMessageTab(QString addr = "");
306 void gotoLoadPSBT();
307
309 void openClicked();
310#endif // ENABLE_WALLET
312 void optionsClicked();
314 void aboutClicked();
316 void showDebugWindow();
321#ifndef Q_OS_MAC
323 void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
324#else
326 void macosDockIconActivated();
327#endif
328
332 void showNormalIfMinimized(bool fToggleHidden);
334 void toggleHidden();
335
337 void detectShutdown();
338
340 void showProgress(const QString &title, int nProgress);
341
344 void setTrayIconVisible(bool);
345
346 void showModalOverlay();
347};
348
349class UnitDisplayStatusBarControl : public QLabel {
350 Q_OBJECT
351
352public:
353 explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
356
357protected:
359 void mousePressEvent(QMouseEvent *event) override;
360
361private:
363 QMenu *menu;
364
366 void onDisplayUnitsClicked(const QPoint &point);
369 void createContextMenu();
370
371private Q_SLOTS:
374 void updateDisplayUnit(int newUnits);
376 void onMenuSelection(QAction *action);
377};
378
379#endif // BITCOIN_QT_BITCOINGUI_H
Bitcoin GUI main class.
Definition: bitcoingui.h:68
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime &blockDate)
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:138
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:169
void showEvent(QShowEvent *event) override
QLabel * progressBarLabel
Definition: bitcoingui.h:137
QAction * m_open_wallet_action
Definition: bitcoingui.h:166
const Config * config
Definition: bitcoingui.h:192
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:72
QAction * openAction
Definition: bitcoingui.h:163
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
Set number of blocks and last block date shown in the UI.
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Definition: bitcoingui.cpp:655
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:135
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
ModalOverlay * modalOverlay
Definition: bitcoingui.h:182
QAction * changePassphraseAction
Definition: bitcoingui.h:160
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
QAction * receiveCoinsMenuAction
Definition: bitcoingui.h:155
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:189
QAction * openRPCConsoleAction
Definition: bitcoingui.h:162
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:194
void changeEvent(QEvent *e) override
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:134
QAction * historyAction
Definition: bitcoingui.h:144
bool eventFilter(QObject *object, QEvent *event) override
QMenu * m_open_wallet_menu
Definition: bitcoingui.h:167
QAction * toggleHideAction
Definition: bitcoingui.h:157
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:849
QAction * quitAction
Definition: bitcoingui.h:145
void setPrivacy(bool privacy)
QProgressDialog * progressDialog
Definition: bitcoingui.h:139
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:126
WalletFrame * walletFrame
Definition: bitcoingui.h:129
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * receiveCoinsAction
Definition: bitcoingui.h:154
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:178
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:148
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void closeEvent(QCloseEvent *event) override
QAction * verifyMessageAction
Definition: bitcoingui.h:151
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:863
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:181
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:923
void toggleHidden()
Simply calls showNormalIfMinimized(true) for use in SLOT() macro.
QAction * encryptWalletAction
Definition: bitcoingui.h:158
void updateNetworkState()
Update UI with latest network info from model.
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:246
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:932
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:113
QAction * m_mask_values_action
Definition: bitcoingui.h:172
int spinnerFrame
Definition: bitcoingui.h:190
QAction * aboutAction
Definition: bitcoingui.h:153
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
bool isPrivacyModeActivated() const
void showDebugWindowActivateConsole()
Show debug window and set focus to the console.
Definition: bitcoingui.cpp:937
void dropEvent(QDropEvent *event) override
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:149
void subscribeToCoreSignals()
Connect core signals to GUI client.
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:616
QAction * m_wallet_selector_action
Definition: bitcoingui.h:171
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:131
QAction * optionsAction
Definition: bitcoingui.h:156
void updateWindowTitle()
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:830
const PlatformStyle * platformStyle
Definition: bitcoingui.h:193
void dragEnterEvent(QDragEnterEvent *event) override
QAction * m_close_wallet_action
Definition: bitcoingui.h:168
QLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:132
QAction * overviewAction
Definition: bitcoingui.h:143
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:136
interfaces::Node & m_node
Definition: bitcoingui.h:124
QAction * m_create_wallet_action
Definition: bitcoingui.h:165
QAction * m_load_psbt_action
Definition: bitcoingui.h:152
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:170
WalletController * m_wallet_controller
Definition: bitcoingui.h:125
bool enableWallet
Definition: bitcoingui.h:102
RPCConsole * rpcConsole
Definition: bitcoingui.h:180
QAction * backupWalletAction
Definition: bitcoingui.h:159
QAction * sendCoinsMenuAction
Definition: bitcoingui.h:147
QAction * showHelpMessageAction
Definition: bitcoingui.h:164
QAction * aboutQtAction
Definition: bitcoingui.h:161
QComboBox * m_wallet_selector
Definition: bitcoingui.h:175
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:174
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:331
ClientModel * clientModel
Definition: bitcoingui.h:128
void updateHeadersSyncProgressLabel()
void setTrayIconVisible(bool)
When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly.
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:518
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:177
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr, const QString &detailed_message=QString())
Notify the user of an event from the core network or transaction handling code.
void showHelpMessageClicked()
Show help message dialog.
Definition: bitcoingui.cpp:942
QAction * sendCoinsAction
Definition: bitcoingui.h:146
QToolBar * appToolBar
Definition: bitcoingui.h:142
QLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:133
void setNumConnections(int count)
Set number of connections shown in the UI.
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Handle tray icon clicked.
Definition: bitcoingui.cpp:906
QAction * signMessageAction
Definition: bitcoingui.h:150
void showModalOverlay()
Notificator * notificator
Definition: bitcoingui.h:179
BitcoinGUI(interfaces::Node &node, const Config *, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:76
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:127
QMenuBar * appMenuBar
Definition: bitcoingui.h:141
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Model for Bitcoin network client.
Definition: clientmodel.h:43
Definition: config.h:19
"Help message" dialog box
Definition: utilitydialog.h:20
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:21
Cross-platform desktop notification client.
Definition: notificator.h:24
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:48
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
void updateDisplayUnit(int newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
void createContextMenu()
Creates context menu, its actions, and wires up all the relevant signals for mouse events.
OptionsModel * optionsModel
Definition: bitcoingui.h:362
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
void onMenuSelection(QAction *action)
Tells underlying optionsModel to update its current display unit.
void setOptionsModel(OptionsModel *optionsModel)
Lets the control know about the Options Model (and its signals)
void onDisplayUnitsClicked(const QPoint &point)
Shows context menu with Display Unit options by the mouse coordinates.
Controller between interfaces::Node, WalletModel instances and the GUI.
A container for embedding all wallet-related controls into BitcoinGUI.
Definition: walletframe.h:29
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:59
SyncType
Definition: clientmodel.h:40
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
Definition: init.h:28
Definition: amount.h:19
Block and header tip information.
Definition: node.h:50
static int count
Definition: tests.c:31
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:114