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 NetworkStyle; 30 class Notificator; 31 class OptionsModel; 32 class PlatformStyle; 33 class RPCConsole; 34 class SendCoinsRecipient; 35 class UnitDisplayStatusBarControl; 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; 57 class ClickableProgressBar; 58 } 59 60 /** 61 Bitcoin GUI main class. This class represents the main window of the Bitcoin UI. It communicates with both the client and 62 wallet models to give the user an up-to-date view of the current core state. 63 */ 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 74 /** Set the client model. 75 The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic. 76 */ 77 void setClientModel(ClientModel *clientModel); 78 #ifdef ENABLE_WALLET 79 void setWalletController(WalletController* wallet_controller); 80 #endif 81 82 #ifdef ENABLE_WALLET 83 /** Set the wallet model. 84 The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending 85 functionality. 86 */ 87 void addWallet(WalletModel* walletModel); 88 void removeWallet(WalletModel* walletModel); 89 void removeAllWallets(); 90 #endif // ENABLE_WALLET 91 bool enableWallet = false; 92 93 /** Get the tray icon status. 94 Some systems have not "system tray" or "notification area" available. 95 */ hasTrayIcon()96 bool hasTrayIcon() const { return trayIcon; } 97 98 /** Disconnect core signals from GUI client */ 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: 110 interfaces::Node& m_node; 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 170 /** Keep track of previous number of blocks, to detect progress */ 171 int prevBlocks = 0; 172 int spinnerFrame = 0; 173 174 const PlatformStyle *platformStyle; 175 const NetworkStyle* const m_network_style; 176 177 /** Create the main UI actions. */ 178 void createActions(); 179 /** Create the menu bar and sub-menus. */ 180 void createMenuBar(); 181 /** Create the toolbars */ 182 void createToolBars(); 183 /** Create system tray icon and notification */ 184 void createTrayIcon(); 185 /** Create system tray menu (or setup the dock menu) */ 186 void createTrayIconMenu(); 187 188 /** Enable or disable all wallet-related actions */ 189 void setWalletActionsEnabled(bool enabled); 190 191 /** Connect core signals to GUI client */ 192 void subscribeToCoreSignals(); 193 194 /** Update UI with latest network info from model. */ 195 void updateNetworkState(); 196 197 void updateHeadersSyncProgressLabel(); 198 199 /** Open the OptionsDialog on the specified tab index */ 200 void openOptionsDialogWithTab(OptionsDialog::Tab tab); 201 202 Q_SIGNALS: 203 /** Signal raised when a URI was entered or dragged to the GUI */ 204 void receivedURI(const QString &uri); 205 /** Signal raised when RPC console shown */ 206 void consoleShown(RPCConsole* console); 207 208 public Q_SLOTS: 209 /** Set number of connections shown in the UI */ 210 void setNumConnections(int count); 211 /** Set network state shown in the UI */ 212 void setNetworkActive(bool networkActive); 213 /** Set number of blocks and last block date shown in the UI */ 214 void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers); 215 216 /** Notify the user of an event from the core network or transaction handling code. 217 @param[in] title the message box / notification title 218 @param[in] message the displayed text 219 @param[in] style modality and style definitions (icon and used buttons - buttons only for message boxes) 220 @see CClientUIInterface::MessageBoxFlags 221 @param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only) 222 */ 223 void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr); 224 225 #ifdef ENABLE_WALLET 226 void setCurrentWallet(WalletModel* wallet_model); 227 void setCurrentWalletBySelectorIndex(int index); 228 /** Set the UI status indicators based on the currently selected wallet. 229 */ 230 void updateWalletStatus(); 231 232 private: 233 /** Set the encryption status as shown in the UI. 234 @param[in] status current encryption status 235 @see WalletModel::EncryptionStatus 236 */ 237 void setEncryptionStatus(int status); 238 239 /** Set the hd-enabled status as shown in the UI. 240 @param[in] hdEnabled current hd enabled status 241 @see WalletModel::EncryptionStatus 242 */ 243 void setHDStatus(bool privkeyDisabled, int hdEnabled); 244 245 public Q_SLOTS: 246 bool handlePaymentRequest(const SendCoinsRecipient& recipient); 247 248 /** Show incoming transaction notification for new transactions. */ 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: 253 /** Set the proxy-enabled icon as shown in the UI. */ 254 void updateProxyIcon(); 255 void updateWindowTitle(); 256 257 public Q_SLOTS: 258 #ifdef ENABLE_WALLET 259 /** Switch to overview (home) page */ 260 void gotoOverviewPage(); 261 /** Switch to history (transactions) page */ 262 void gotoHistoryPage(); 263 /** Switch to receive coins page */ 264 void gotoReceiveCoinsPage(); 265 /** Switch to send coins page */ 266 void gotoSendCoinsPage(QString addr = ""); 267 268 /** Show Sign/Verify Message dialog and switch to sign message tab */ 269 void gotoSignMessageTab(QString addr = ""); 270 /** Show Sign/Verify Message dialog and switch to verify message tab */ 271 void gotoVerifyMessageTab(QString addr = ""); 272 273 /** Show open dialog */ 274 void openClicked(); 275 #endif // ENABLE_WALLET 276 /** Show configuration dialog */ 277 void optionsClicked(); 278 /** Show about dialog */ 279 void aboutClicked(); 280 /** Show debug window */ 281 void showDebugWindow(); 282 /** Show debug window and set focus to the console */ 283 void showDebugWindowActivateConsole(); 284 /** Show help message dialog */ 285 void showHelpMessageClicked(); 286 #ifndef Q_OS_MAC 287 /** Handle tray icon clicked */ 288 void trayIconActivated(QSystemTrayIcon::ActivationReason reason); 289 #else 290 /** Handle macOS Dock icon clicked */ 291 void macosDockIconActivated(); 292 #endif 293 294 /** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */ showNormalIfMinimized()295 void showNormalIfMinimized() { showNormalIfMinimized(false); } 296 void showNormalIfMinimized(bool fToggleHidden); 297 /** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */ 298 void toggleHidden(); 299 300 /** called by a timer to check if ShutdownRequested() has been set **/ 301 void detectShutdown(); 302 303 /** Show progress dialog e.g. for verifychain */ 304 void showProgress(const QString &title, int nProgress); 305 306 /** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */ 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); 318 /** Lets the control know about the Options Model (and its signals) */ 319 void setOptionsModel(OptionsModel *optionsModel); 320 321 protected: 322 /** So that it responds to left-button clicks */ 323 void mousePressEvent(QMouseEvent *event); 324 325 private: 326 OptionsModel *optionsModel; 327 QMenu* menu; 328 329 /** Shows context menu with Display Unit options by the mouse coordinates */ 330 void onDisplayUnitsClicked(const QPoint& point); 331 /** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */ 332 void createContextMenu(); 333 334 private Q_SLOTS: 335 /** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */ 336 void updateDisplayUnit(int newUnits); 337 /** Tells underlying optionsModel to update its current display unit. */ 338 void onMenuSelection(QAction* action); 339 }; 340 341 #endif // BITCOIN_QT_BITCOINGUI_H 342