1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_QT_CLIENTMODEL_H
6 #define BITCOIN_QT_CLIENTMODEL_H
32 CONNECTIONS_IN
= (1U << 0),
33 CONNECTIONS_OUT
= (1U << 1),
34 CONNECTIONS_ALL
= (CONNECTIONS_IN
| CONNECTIONS_OUT
),
37 /** Model for Bitcoin network client. */
38 class ClientModel
: public QObject
43 explicit ClientModel(OptionsModel
*optionsModel
, QObject
*parent
= 0);
46 OptionsModel
*getOptionsModel();
47 PeerTableModel
*getPeerTableModel();
48 BanTableModel
*getBanTableModel();
50 //! Return number of connections, default is in- and outbound (total)
51 int getNumConnections(unsigned int flags
= CONNECTIONS_ALL
) const;
52 int getNumBlocks() const;
53 int getHeaderTipHeight() const;
54 int64_t getHeaderTipTime() const;
55 //! Return number of transactions in the mempool
56 long getMempoolSize() const;
57 //! Return the dynamic memory usage of the mempool
58 size_t getMempoolDynamicUsage() const;
60 quint64
getTotalBytesRecv() const;
61 quint64
getTotalBytesSent() const;
63 double getVerificationProgress(const CBlockIndex
*tip
) const;
64 QDateTime
getLastBlockDate() const;
66 //! Return true if core is doing initial block download
67 bool inInitialBlockDownload() const;
68 //! Returns enum BlockSource of the current importing/syncing state
69 enum BlockSource
getBlockSource() const;
70 //! Return true if network activity in core is enabled
71 bool getNetworkActive() const;
72 //! Toggle network activity state in core
73 void setNetworkActive(bool active
);
74 //! Return warnings to be displayed in status bar
75 QString
getStatusBarWarnings() const;
77 QString
formatFullVersion() const;
78 QString
formatSubVersion() const;
79 bool isReleaseVersion() const;
80 QString
formatClientStartupTime() const;
81 QString
dataDir() const;
83 // caches for the best header
84 mutable std::atomic
<int> cachedBestHeaderHeight
;
85 mutable std::atomic
<int64_t> cachedBestHeaderTime
;
88 OptionsModel
*optionsModel
;
89 PeerTableModel
*peerTableModel
;
90 BanTableModel
*banTableModel
;
94 void subscribeToCoreSignals();
95 void unsubscribeFromCoreSignals();
98 void numConnectionsChanged(int count
);
99 void numBlocksChanged(int count
, const QDateTime
& blockDate
, double nVerificationProgress
, bool header
);
100 void mempoolSizeChanged(long count
, size_t mempoolSizeInBytes
);
101 void networkActiveChanged(bool networkActive
);
102 void alertsChanged(const QString
&warnings
);
103 void bytesChanged(quint64 totalBytesIn
, quint64 totalBytesOut
);
105 //! Fired when a message should be reported to the user
106 void message(const QString
&title
, const QString
&message
, unsigned int style
);
108 // Show progress dialog e.g. for verifychain
109 void showProgress(const QString
&title
, int nProgress
);
113 void updateNumConnections(int numConnections
);
114 void updateNetworkActive(bool networkActive
);
116 void updateBanlist();
119 #endif // BITCOIN_QT_CLIENTMODEL_H