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