ui_interface.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #ifndef ECOIN_UI_INTERFACE_H
  3. #define ECOIN_UI_INTERFACE_H
  4. #include <string>
  5. #include "util.h" // for int64
  6. #include <boost/signals2/signal.hpp>
  7. #include <boost/signals2/last_value.hpp>
  8. class CBasicKeyStore;
  9. class CWallet;
  10. class uint256;
  11. /** General change type (added, updated, removed). */
  12. enum ChangeType
  13. {
  14. CT_NEW,
  15. CT_UPDATED,
  16. CT_DELETED
  17. };
  18. /** Signals for UI communication. */
  19. class CClientUIInterface
  20. {
  21. public:
  22. /** Flags for CClientUIInterface::ThreadSafeMessageBox */
  23. enum MessageBoxFlags
  24. {
  25. YES = 0x00000002,
  26. OK = 0x00000004,
  27. NO = 0x00000008,
  28. YES_NO = (YES|NO),
  29. CANCEL = 0x00000010,
  30. APPLY = 0x00000020,
  31. CLOSE = 0x00000040,
  32. OK_DEFAULT = 0x00000000,
  33. YES_DEFAULT = 0x00000000,
  34. NO_DEFAULT = 0x00000080,
  35. CANCEL_DEFAULT = 0x80000000,
  36. ICON_EXCLAMATION = 0x00000100,
  37. ICON_HAND = 0x00000200,
  38. ICON_WARNING = ICON_EXCLAMATION,
  39. ICON_ERROR = ICON_HAND,
  40. ICON_QUESTION = 0x00000400,
  41. ICON_INFORMATION = 0x00000800,
  42. ICON_STOP = ICON_HAND,
  43. ICON_ASTERISK = ICON_INFORMATION,
  44. ICON_MASK = (0x00000100|0x00000200|0x00000400|0x00000800),
  45. FORWARD = 0x00001000,
  46. BACKWARD = 0x00002000,
  47. RESET = 0x00004000,
  48. HELP = 0x00008000,
  49. MORE = 0x00010000,
  50. SETUP = 0x00020000,
  51. // Force blocking, modal message box dialog (not just OS notification)
  52. MODAL = 0x00040000
  53. };
  54. /** Show message box. */
  55. boost::signals2::signal<void (const std::string& message, const std::string& caption, int style)> ThreadSafeMessageBox;
  56. /** Ask the user whether they want to pay a fee or not. */
  57. boost::signals2::signal<bool (int64 nFeeRequired, const std::string& strCaption), boost::signals2::last_value<bool> > ThreadSafeAskFee;
  58. /** Handle a URL passed at the command line. */
  59. boost::signals2::signal<void (const std::string& strURI)> ThreadSafeHandleURI;
  60. /** Progress message during initialization. */
  61. boost::signals2::signal<void (const std::string &message)> InitMessage;
  62. /** Initiate client shutdown. */
  63. boost::signals2::signal<void ()> QueueShutdown;
  64. /** Translate a message to the native language of the user. */
  65. boost::signals2::signal<std::string (const char* psz)> Translate;
  66. /** Block chain changed. */
  67. boost::signals2::signal<void ()> NotifyBlocksChanged;
  68. /** Number of network connections changed. */
  69. boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
  70. /**
  71. * New, updated or cancelled alert.
  72. * @note called with lock cs_mapAlerts held.
  73. */
  74. boost::signals2::signal<void (const uint256 &hash, ChangeType status)> NotifyAlertChanged;
  75. };
  76. extern CClientUIInterface uiInterface;
  77. /**
  78. * Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
  79. * If no translation slot is registered, nothing is returned, and simply return the input.
  80. */
  81. inline std::string _(const char* psz)
  82. {
  83. boost::optional<std::string> rv = uiInterface.Translate(psz);
  84. return rv ? (*rv) : psz;
  85. }
  86. #endif