interface_ui.h
1 // Copyright (c) 2010 Satoshi Nakamoto 2 // Copyright (c) 2012-present 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_INTERFACE_UI_H 7 #define BITCOIN_NODE_INTERFACE_UI_H 8 9 #include <cstdint> 10 #include <functional> 11 #include <string> 12 #include <vector> 13 14 class CBlockIndex; 15 enum class SynchronizationState; 16 struct bilingual_str; 17 18 namespace boost { 19 namespace signals2 { 20 class connection; 21 } 22 } // namespace boost 23 24 /** Signals for UI communication. */ 25 class CClientUIInterface 26 { 27 public: 28 /** Flags for CClientUIInterface::ThreadSafeMessageBox */ 29 enum MessageBoxFlags : uint32_t { 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, unsigned int style); 78 79 /** If possible, ask the user a question. If not, falls back to ThreadSafeMessageBox(noninteractive_message, style) and returns false. */ 80 ADD_SIGNALS_DECL_WRAPPER(ThreadSafeQuestion, bool, const bilingual_str& message, const std::string& noninteractive_message, unsigned int style); 81 82 /** Progress message during initialization. */ 83 ADD_SIGNALS_DECL_WRAPPER(InitMessage, void, const std::string& message); 84 85 /** Wallet loader created. */ 86 ADD_SIGNALS_DECL_WRAPPER(InitWallet, void, ); 87 88 /** Number of network connections changed. */ 89 ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, int newNumConnections); 90 91 /** Network activity state changed. */ 92 ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, bool networkActive); 93 94 /** 95 * Status bar alerts changed. 96 */ 97 ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, ); 98 99 /** 100 * Show progress e.g. for verifychain. 101 * resume_possible indicates shutting down now will result in the current progress action resuming upon restart. 102 */ 103 ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible); 104 105 /** New block has been accepted */ 106 ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState, const CBlockIndex& block, double verification_progress); 107 108 /** Best header has changed */ 109 ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState, int64_t height, int64_t timestamp, bool presync); 110 111 /** Banlist did change. */ 112 ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void); 113 }; 114 115 /** Show warning message **/ 116 void InitWarning(const bilingual_str& str); 117 118 /** Show error message **/ 119 bool InitError(const bilingual_str& str); 120 bool InitError(const bilingual_str& str, const std::vector<std::string>& details); 121 122 extern CClientUIInterface uiInterface; 123 124 #endif // BITCOIN_NODE_INTERFACE_UI_H