PIVX Core  5.6.99
P2P Digital Currency
clientmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2014-2015 The Dash developers
3 // Copyright (c) 2015-2022 The PIVX Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef PIVX_QT_CLIENTMODEL_H
8 #define PIVX_QT_CLIENTMODEL_H
9 
10 #include "uint256.h"
11 #include "chain.h"
12 
13 #include <QObject>
14 #include <QDateTime>
15 
16 #include <atomic>
17 #include <memory>
18 
19 class AddressTableModel;
20 class BanTableModel;
21 class OptionsModel;
22 class PeerTableModel;
24 
25 namespace interfaces {
26  class Handler;
27 }
28 
29 QT_BEGIN_NAMESPACE
30 class QDateTime;
31 class QTimer;
32 QT_END_NAMESPACE
33 
39 };
40 
43  CONNECTIONS_IN = (1U << 0),
44  CONNECTIONS_OUT = (1U << 1),
46 };
47 
49 class ClientModel : public QObject
50 {
51  Q_OBJECT
52 
53 public:
54  explicit ClientModel(OptionsModel* optionsModel, QObject* parent = 0);
55  ~ClientModel();
56 
60 
62  int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
64 
65  // from cached block index
66  int getNumBlocks();
67  QDateTime getLastBlockDate() const;
68  QString getLastBlockHash() const;
70  int getLastBlockProcessedHeight() const;
71  int64_t getLastBlockProcessedTime() const;
72  double getVerificationProgress() const;
73  bool isTipCached() const;
74 
75  quint64 getTotalBytesRecv() const;
76  quint64 getTotalBytesSent() const;
77 
79  bool inInitialBlockDownload() const;
81  enum BlockSource getBlockSource() const;
83  bool getNetworkActive() const;
85  void setNetworkActive(bool active);
87  QString getStatusBarWarnings() const;
88 
89  QString formatFullVersion() const;
90  bool isReleaseVersion() const;
91  QString clientName() const;
92  QString formatClientStartupTime() const;
93  QString dataDir() const;
94 
95  void setCacheTip(const CBlockIndex* const tip) { cacheTip = tip; }
96  void setCacheReindexing(bool reindex) { cachedReindexing = reindex; }
97  void setCacheImporting(bool import) { cachedImporting = import; }
98  void setCacheInitialSync(bool _initialSync) { cachedInitialSync = _initialSync; }
99 
100  bool getTorInfo(std::string& ip_port) const;
101 
103  static void mapPort(bool use_upnp, bool use_natpmp);
104 
105  // Start/Stop the masternode polling timer
106  void startMasternodesTimer();
107  void stopMasternodesTimer();
108  // Force a MN count update calling mnmanager directly locking its internal mutex.
109  // Future todo: implement an event based update and remove the lock requirement.
110  QString getMasternodesCountString();
112 
113 private:
114  // Listeners
115  std::unique_ptr<interfaces::Handler> m_handler_show_progress;
116  std::unique_ptr<interfaces::Handler> m_handler_notify_num_connections_changed;
117  std::unique_ptr<interfaces::Handler> m_handler_notify_net_activity_changed;
118  std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
119  std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
120  std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
121 
122  QString getMasternodeCountString();
126 
127  const CBlockIndex* cacheTip{nullptr};
131  std::atomic<bool> cachedInitialSync{false};
132 
134 
135  QTimer* pollTimer;
136  QTimer* pollMnTimer;
137 
138  std::atomic_int m_cached_masternodes_count{0};
139 
140  void subscribeToCoreSignals();
142 
143 Q_SIGNALS:
144  void numConnectionsChanged(int count);
145  void numBlocksChanged(int count);
146  void networkActiveChanged(bool networkActive);
147  void strMasternodesChanged(const QString& strMasternodes);
148  void alertsChanged(const QString& warnings);
149  void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
150 
152  void message(const QString& title, const QString& message, unsigned int style, bool* ret = nullptr);
153 
154  // Show progress dialog e.g. for verifychain
155  void showProgress(const QString& title, int nProgress);
156 
157 public Q_SLOTS:
158  void updateTimer();
159  void updateMnTimer();
160  void updateNumConnections(int numConnections);
161  void updateNetworkActive(bool networkActive);
162  void updateAlert();
163  void updateBanlist();
164 };
165 
166 #endif // PIVX_QT_CLIENTMODEL_H
Qt model of the address book in the core.
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Definition: bantablemodel.h:39
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
Model for PIVX network client.
Definition: clientmodel.h:50
void updateAlert()
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:119
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
QString getLastBlockHash() const
void updateBanlist()
void showProgress(const QString &title, int nProgress)
void setNetworkActive(bool active)
Toggle network activity state in core.
QString cachedMasternodeCountString
Definition: clientmodel.h:128
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
void setCacheReindexing(bool reindex)
Definition: clientmodel.h:96
void message(const QString &title, const QString &message, unsigned int style, bool *ret=nullptr)
Fired when a message should be reported to the user.
int numBlocksAtStartup
Definition: clientmodel.h:133
bool getTorInfo(std::string &ip_port) const
void updateMnTimer()
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:115
QString clientName() const
int64_t getLastBlockProcessedTime() const
void setCacheTip(const CBlockIndex *const tip)
Definition: clientmodel.h:95
uint256 getLastBlockProcessed() const
quint64 getTotalBytesRecv() const
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:118
quint64 getTotalBytesSent() const
int getMasternodesCount() const
Definition: clientmodel.h:111
void startMasternodesTimer()
PeerTableModel * getPeerTableModel()
void numBlocksChanged(int count)
void updateNetworkActive(bool networkActive)
int getNumBlocksAtStartup()
double getVerificationProgress() const
void setCacheImporting(bool import)
Definition: clientmodel.h:97
void updateNumConnections(int numConnections)
void stopMasternodesTimer()
void updateTimer()
QDateTime getLastBlockDate() const
void strMasternodesChanged(const QString &strMasternodes)
bool cachedImporting
Definition: clientmodel.h:130
void numConnectionsChanged(int count)
int getNumBlocks()
bool isTipCached() const
QString getMasternodeCountString()
Definition: clientmodel.cpp:79
QTimer * pollMnTimer
Definition: clientmodel.h:136
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:120
bool getNetworkActive() const
Return true if network activity in core is enabled.
QString formatClientStartupTime() const
QString getMasternodesCountString()
Definition: clientmodel.cpp:91
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:63
enum BlockSource getBlockSource() const
Return true if core is importing blocks.
static void mapPort(bool use_upnp, bool use_natpmp)
Set the automatic port mapping options.
void setCacheInitialSync(bool _initialSync)
Definition: clientmodel.h:98
std::atomic< bool > cachedInitialSync
Definition: clientmodel.h:131
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:116
OptionsModel * optionsModel
Definition: clientmodel.h:123
BanTableModel * banTableModel
Definition: clientmodel.h:125
BanTableModel * getBanTableModel()
void unsubscribeFromCoreSignals()
bool cachedReindexing
Definition: clientmodel.h:129
QTimer * pollTimer
Definition: clientmodel.h:135
std::unique_ptr< interfaces::Handler > m_handler_notify_net_activity_changed
Definition: clientmodel.h:117
void alertsChanged(const QString &warnings)
QString dataDir() const
OptionsModel * getOptionsModel()
QString formatFullVersion() const
std::atomic_int m_cached_masternodes_count
Definition: clientmodel.h:138
PeerTableModel * peerTableModel
Definition: clientmodel.h:124
int getLastBlockProcessedHeight() const
ClientModel(OptionsModel *optionsModel, QObject *parent=0)
Definition: clientmodel.cpp:36
const CBlockIndex * cacheTip
Definition: clientmodel.h:127
bool isReleaseVersion() const
bool inInitialBlockDownload() const
Return true if core is doing initial block download.
void subscribeToCoreSignals()
void networkActiveChanged(bool networkActive)
Interface from Qt to configuration data structure for PIVX client.
Definition: optionsmodel.h:22
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
UI model for the transaction table of a wallet.
256-bit opaque blob.
Definition: uint256.h:138
NumConnections
Definition: clientmodel.h:41
@ CONNECTIONS_IN
Definition: clientmodel.h:43
@ CONNECTIONS_NONE
Definition: clientmodel.h:42
@ CONNECTIONS_OUT
Definition: clientmodel.h:44
@ CONNECTIONS_ALL
Definition: clientmodel.h:45
BlockSource
Definition: clientmodel.h:34
@ BLOCK_SOURCE_NETWORK
Definition: clientmodel.h:38
@ BLOCK_SOURCE_DISK
Definition: clientmodel.h:37
@ BLOCK_SOURCE_NONE
Definition: clientmodel.h:35
@ BLOCK_SOURCE_REINDEX
Definition: clientmodel.h:36
int flags
Definition: pivx-tx.cpp:400