1 // Copyright (c) 2010 Satoshi Nakamoto 2 // Copyright (c) 2012-2020 The Bitcoin Core developers 3 // Distributed under the MIT software license, see the accompanying 4 // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 6 #ifndef BITCOIN_NODE_UI_INTERFACE_H 7 #define BITCOIN_NODE_UI_INTERFACE_H 8 9 #include <functional> 10 #include <memory> 11 #include <string> 12 13 class CBlockIndex; 14 enum class SynchronizationState; 15 struct bilingual_str; 16 17 namespace boost { 18 namespace signals2 { 19 class connection; 20 } 21 } // namespace boost 22 23 /** Signals for UI communication. */ 24 class CClientUIInterface 25 { 26 public: 27 /** Flags for CClientUIInterface::ThreadSafeMessageBox */ 28 enum MessageBoxFlags 29 { 30 ICON_INFORMATION = 0, 31 ICON_WARNING = (1U << 0), 32 ICON_ERROR = (1U << 1), 33 /** 34 * Mask of all available icons in CClientUIInterface::MessageBoxFlags 35 * This needs to be updated, when icons are changed there! 36 */ 37 ICON_MASK = (ICON_INFORMATION | ICON_WARNING | ICON_ERROR), 38 39 /** These values are taken from qmessagebox.h "enum StandardButton" to be directly usable */ 40 BTN_OK = 0x00000400U, // QMessageBox::Ok 41 BTN_YES = 0x00004000U, // QMessageBox::Yes 42 BTN_NO = 0x00010000U, // QMessageBox::No 43 BTN_ABORT = 0x00040000U, // QMessageBox::Abort 44 BTN_RETRY = 0x00080000U, // QMessageBox::Retry 45 BTN_IGNORE = 0x00100000U, // QMessageBox::Ignore 46 BTN_CLOSE = 0x00200000U, // QMessageBox::Close 47 BTN_CANCEL = 0x00400000U, // QMessageBox::Cancel 48 BTN_DISCARD = 0x00800000U, // QMessageBox::Discard 49 BTN_HELP = 0x01000000U, // QMessageBox::Help 50 BTN_APPLY = 0x02000000U, // QMessageBox::Apply 51 BTN_RESET = 0x04000000U, // QMessageBox::Reset 52 /** 53 * Mask of all available buttons in CClientUIInterface::MessageBoxFlags 54 * This needs to be updated, when buttons are changed there! 55 */ 56 BTN_MASK = (BTN_OK | BTN_YES | BTN_NO | BTN_ABORT | BTN_RETRY | BTN_IGNORE | 57 BTN_CLOSE | BTN_CANCEL | BTN_DISCARD | BTN_HELP | BTN_APPLY | BTN_RESET), 58 59 /** Force blocking, modal message box dialog (not just OS notification) */ 60 MODAL = 0x10000000U, 61 62 /** Do not print contents of message to debug log */ 63 SECURE = 0x40000000U, 64 65 /** Predefined combinations for certain default usage cases */ 66 MSG_INFORMATION = ICON_INFORMATION, 67 MSG_WARNING = (ICON_WARNING | BTN_OK | MODAL), 68 MSG_ERROR = (ICON_ERROR | BTN_OK | MODAL) 69 }; 70 71 #define ADD_SIGNALS_DECL_WRAPPER(signal_name, rtype, ...) \ 72 rtype signal_name(__VA_ARGS__); \ 73 using signal_name##Sig = rtype(__VA_ARGS__); \ 74 boost::signals2::connection signal_name##_connect(std::function<signal_name##Sig> fn); 75 76 /** Show message box. */ 77 ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, bool, const bilingual_str& message, const std::string& caption, unsigned int style); 78 79 /** If possible, ask the user a question. If not, falls back to ThreadSafeMessageBox(noninteractive_message, caption, style) and returns false. */ 80 ADD_SIGNALS_DECL_WRAPPER(ThreadSafeQuestion, bool, const bilingual_str& message, const std::string& noninteractive_message, const std::string& caption, unsigned int style); 81 82 /** Progress message during initialization. */ 83 ADD_SIGNALS_DECL_WRAPPER(InitMessage, void, const std::string& message); 84 85 /** Number of network connections changed. */ 86 ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, int newNumConnections); 87 88 /** Network activity state changed. */ 89 ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, bool networkActive); 90 91 /** 92 * Status bar alerts changed. 93 */ 94 ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, ); 95 96 /** 97 * Show progress e.g. for verifychain. 98 * resume_possible indicates shutting down now will result in the current progress action resuming upon restart. 99 */ 100 ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible); 101 102 /** New block has been accepted */ 103 ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState, const CBlockIndex*); 104 105 /** Best header has changed */ 106 ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState, const CBlockIndex*); 107 108 /** Banlist did change. */ 109 ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void); 110 }; 111 112 /** Show warning message **/ 113 void InitWarning(const bilingual_str& str); 114 115 /** Show error message **/ 116 bool InitError(const bilingual_str& str); 117 constexpr auto AbortError = InitError; 118 119 extern CClientUIInterface uiInterface; 120 121 #endif // BITCOIN_NODE_UI_INTERFACE_H 122