interface_ui.h raw

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