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