You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clientmodel.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef STARWELS_QT_CLIENTMODEL_H
  5. #define STARWELS_QT_CLIENTMODEL_H
  6. #include <QObject>
  7. #include <QDateTime>
  8. #include <atomic>
  9. class BanTableModel;
  10. class OptionsModel;
  11. class PeerTableModel;
  12. class CBlockIndex;
  13. QT_BEGIN_NAMESPACE
  14. class QTimer;
  15. QT_END_NAMESPACE
  16. enum BlockSource {
  17. BLOCK_SOURCE_NONE,
  18. BLOCK_SOURCE_REINDEX,
  19. BLOCK_SOURCE_DISK,
  20. BLOCK_SOURCE_NETWORK
  21. };
  22. enum NumConnections {
  23. CONNECTIONS_NONE = 0,
  24. CONNECTIONS_IN = (1U << 0),
  25. CONNECTIONS_OUT = (1U << 1),
  26. CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
  27. };
  28. /** Model for Starwels network client. */
  29. class ClientModel : public QObject
  30. {
  31. Q_OBJECT
  32. public:
  33. explicit ClientModel(OptionsModel *optionsModel, QObject *parent = 0);
  34. ~ClientModel();
  35. OptionsModel *getOptionsModel();
  36. PeerTableModel *getPeerTableModel();
  37. BanTableModel *getBanTableModel();
  38. //! Return number of connections, default is in- and outbound (total)
  39. int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
  40. int getNumBlocks() const;
  41. int getHeaderTipHeight() const;
  42. int64_t getHeaderTipTime() const;
  43. //! Return number of transactions in the mempool
  44. long getMempoolSize() const;
  45. //! Return the dynamic memory usage of the mempool
  46. size_t getMempoolDynamicUsage() const;
  47. quint64 getTotalBytesRecv() const;
  48. quint64 getTotalBytesSent() const;
  49. double getVerificationProgress(const CBlockIndex *tip) const;
  50. QDateTime getLastBlockDate() const;
  51. //! Return true if core is doing initial block download
  52. bool inInitialBlockDownload() const;
  53. //! Returns enum BlockSource of the current importing/syncing state
  54. enum BlockSource getBlockSource() const;
  55. //! Return true if network activity in core is enabled
  56. bool getNetworkActive() const;
  57. //! Toggle network activity state in core
  58. void setNetworkActive(bool active);
  59. //! Return warnings to be displayed in status bar
  60. QString getStatusBarWarnings() const;
  61. QString formatFullVersion() const;
  62. QString formatSubVersion() const;
  63. bool isReleaseVersion() const;
  64. QString formatClientStartupTime() const;
  65. QString dataDir() const;
  66. // caches for the best header
  67. mutable std::atomic<int> cachedBestHeaderHeight;
  68. mutable std::atomic<int64_t> cachedBestHeaderTime;
  69. private:
  70. OptionsModel *optionsModel;
  71. PeerTableModel *peerTableModel;
  72. BanTableModel *banTableModel;
  73. QTimer *pollTimer;
  74. void subscribeToCoreSignals();
  75. void unsubscribeFromCoreSignals();
  76. Q_SIGNALS:
  77. void numConnectionsChanged(int count);
  78. void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
  79. void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
  80. void networkActiveChanged(bool networkActive);
  81. void alertsChanged(const QString &warnings);
  82. void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
  83. //! Fired when a message should be reported to the user
  84. void message(const QString &title, const QString &message, unsigned int style);
  85. // Show progress dialog e.g. for verifychain
  86. void showProgress(const QString &title, int nProgress);
  87. public Q_SLOTS:
  88. void updateTimer();
  89. void updateNumConnections(int numConnections);
  90. void updateNetworkActive(bool networkActive);
  91. void updateAlert();
  92. void updateBanlist();
  93. };
  94. #endif // STARWELS_QT_CLIENTMODEL_H