1 // Copyright (c) 2011-2022 The Limenka 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 LIMENKA_QT_PEERTABLEMODEL_H
6 #define LIMENKA_QT_PEERTABLEMODEL_H
7 8 #include <net_processing.h> // For CNodeStateStats
9 #include <net.h>
10 11 #include <QAbstractTableModel>
12 #include <QIcon>
13 #include <QList>
14 #include <QModelIndex>
15 #include <QStringList>
16 #include <QVariant>
17 18 class PeerTablePriv;
19 class PlatformStyle;
20 21 namespace interfaces {
22 class Node;
23 }
24 25 QT_BEGIN_NAMESPACE
26 class QTimer;
27 QT_END_NAMESPACE
28 29 struct CNodeCombinedStats {
30 CNodeStats nodeStats;
31 CNodeStateStats nodeStateStats;
32 bool fNodeStateStatsAvailable;
33 };
34 Q_DECLARE_METATYPE(CNodeCombinedStats*)
35 36 /**
37 Qt model providing information about connected peers, similar to the
38 "getpeerinfo" RPC call. Used by the rpc console UI.
39 */
40 class PeerTableModel : public QAbstractTableModel
41 {
42 Q_OBJECT
43 44 public:
45 explicit PeerTableModel(interfaces::Node& node, const PlatformStyle&, QObject* parent);
46 ~PeerTableModel();
47 void startAutoRefresh();
48 void stopAutoRefresh();
49 50 // See also RPCConsole::ColumnWidths in rpcconsole.h
51 enum ColumnIndex {
52 NetNodeId = 0,
53 Age,
54 Direction,
55 Address,
56 ConnectionType,
57 Ping,
58 Sent,
59 Received,
60 Subversion,
61 Network, // Not used, just kept at the end to avoid excessive code removal
62 };
63 64 enum {
65 StatsRole = Qt::UserRole,
66 };
67 68 /** @name Methods overridden from QAbstractTableModel
69 @{*/
70 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
71 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
72 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
73 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
74 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
75 Qt::ItemFlags flags(const QModelIndex &index) const override;
76 /*@}*/
77 78 public Q_SLOTS:
79 void refresh();
80 void updatePalette();
81 82 private:
83 //! Internal peer data structure.
84 QList<CNodeCombinedStats> m_peers_data{};
85 interfaces::Node& m_node;
86 const PlatformStyle& m_platform_style;
87 void DrawIcons();
88 QIcon m_icon_conn_in, m_icon_conn_out;
89 const QStringList columns{
90 /*: Title of Peers Table column which contains a
91 unique number used to identify a connection. */
92 tr("id"),
93 /*: Title of Peers Table column which indicates the duration (length of time)
94 since the peer connection started. */
95 tr("Age"),
96 "", // Direction column has no title
97 /*: Title of Peers Table column which contains the
98 IP/Onion/I2P address of the connected peer. */
99 tr("Address"),
100 /*: Title of Peers Table column which describes the type of
101 peer connection. The "type" describes why the connection exists. */
102 tr("Type"),
103 /*: Title of Peers Table column which indicates the current latency
104 of the connection with the peer. */
105 tr("Ping"),
106 /*: Title of Peers Table column which indicates the total amount of
107 network information we have sent to the peer. */
108 tr("Sent"),
109 /*: Title of Peers Table column which indicates the total amount of
110 network information we have received from the peer. */
111 tr("Recv'd"),
112 /*: Title of Peers Table column which contains the peer's
113 User Agent string. */
114 tr("User Agent")};
115 QTimer* timer{nullptr};
116 };
117 118 #endif // LIMENKA_QT_PEERTABLEMODEL_H
119