Line data Source code
1 : // Copyright (c) 2011-2013 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.
4 :
5 : #ifndef BITCOIN_QT_CLIENTMODEL_H
6 : #define BITCOIN_QT_CLIENTMODEL_H
7 :
8 : #include <QObject>
9 : #include <QDateTime>
10 :
11 : class AddressTableModel;
12 : class BanTableModel;
13 : class OptionsModel;
14 : class PeerTableModel;
15 : class TransactionTableModel;
16 :
17 : class CWallet;
18 :
19 : QT_BEGIN_NAMESPACE
20 : class QTimer;
21 : QT_END_NAMESPACE
22 :
23 : enum BlockSource {
24 : BLOCK_SOURCE_NONE,
25 : BLOCK_SOURCE_REINDEX,
26 : BLOCK_SOURCE_DISK,
27 : BLOCK_SOURCE_NETWORK
28 : };
29 :
30 : enum NumConnections {
31 : CONNECTIONS_NONE = 0,
32 : CONNECTIONS_IN = (1U << 0),
33 : CONNECTIONS_OUT = (1U << 1),
34 : CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
35 : };
36 :
37 : /** Model for Bitcoin network client. */
38 : class ClientModel : public QObject
39 : {
40 0 : Q_OBJECT
41 :
42 : public:
43 : explicit ClientModel(OptionsModel *optionsModel, QObject *parent = 0);
44 : ~ClientModel();
45 :
46 : OptionsModel *getOptionsModel();
47 : PeerTableModel *getPeerTableModel();
48 : BanTableModel *getBanTableModel();
49 :
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 :
54 : quint64 getTotalBytesRecv() const;
55 : quint64 getTotalBytesSent() const;
56 :
57 : double getVerificationProgress() const;
58 : QDateTime getLastBlockDate() const;
59 :
60 : //! Return true if core is doing initial block download
61 : bool inInitialBlockDownload() const;
62 : //! Return true if core is importing blocks
63 : enum BlockSource getBlockSource() const;
64 : //! Return warnings to be displayed in status bar
65 : QString getStatusBarWarnings() const;
66 :
67 : QString formatFullVersion() const;
68 : QString formatSubVersion() const;
69 : QString formatBuildDate() const;
70 : bool isReleaseVersion() const;
71 : QString clientName() const;
72 : QString formatClientStartupTime() const;
73 :
74 : private:
75 : OptionsModel *optionsModel;
76 : PeerTableModel *peerTableModel;
77 : BanTableModel *banTableModel;
78 :
79 : int cachedNumBlocks;
80 : QDateTime cachedBlockDate;
81 : bool cachedReindexing;
82 : bool cachedImporting;
83 :
84 : QTimer *pollTimer;
85 :
86 : void subscribeToCoreSignals();
87 : void unsubscribeFromCoreSignals();
88 :
89 : Q_SIGNALS:
90 : void numConnectionsChanged(int count);
91 : void numBlocksChanged(int count, const QDateTime& blockDate);
92 : void alertsChanged(const QString &warnings);
93 : void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
94 :
95 : //! Fired when a message should be reported to the user
96 : void message(const QString &title, const QString &message, unsigned int style);
97 :
98 : // Show progress dialog e.g. for verifychain
99 : void showProgress(const QString &title, int nProgress);
100 :
101 : public Q_SLOTS:
102 : void updateTimer();
103 : void updateNumConnections(int numConnections);
104 : void updateAlert(const QString &hash, int status);
105 : void updateBanlist();
106 : };
107 :
108 : #endif // BITCOIN_QT_CLIENTMODEL_H
|