Skip to content

Commit d0c72f8

Browse files
committed
qml: Introduce the Peers page
1 parent 4ca3b72 commit d0c72f8

File tree

8 files changed

+208
-2
lines changed

8 files changed

+208
-2
lines changed

src/Makefile.qt.include

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ QT_MOC_CPP = \
4040
qml/moc_chainmodel.cpp \
4141
qml/moc_nodemodel.cpp \
4242
qml/moc_options_model.cpp \
43+
qml/moc_peerlistsortproxy.cpp \
4344
qt/moc_addressbookpage.cpp \
4445
qt/moc_addresstablemodel.cpp \
4546
qt/moc_askpassphrasedialog.cpp \
@@ -118,6 +119,7 @@ BITCOIN_QT_H = \
118119
qml/imageprovider.h \
119120
qml/nodemodel.h \
120121
qml/options_model.h \
122+
qml/peerlistsortproxy.h \
121123
qml/util.h \
122124
qt/addressbookpage.h \
123125
qt/addresstablemodel.h \
@@ -300,6 +302,7 @@ BITCOIN_QML_BASE_CPP = \
300302
qml/imageprovider.cpp \
301303
qml/nodemodel.cpp \
302304
qml/options_model.cpp \
305+
qml/peerlistsortproxy.cpp \
303306
qml/util.cpp
304307

305308
QML_RES_FONTS = \
@@ -356,6 +359,7 @@ QML_RES_QML = \
356359
qml/pages/main.qml \
357360
qml/pages/node/NodeRunner.qml \
358361
qml/pages/node/NodeSettings.qml \
362+
qml/pages/node/Peers.qml \
359363
qml/pages/onboarding/OnboardingBlockclock.qml \
360364
qml/pages/onboarding/OnboardingConnection.qml \
361365
qml/pages/onboarding/OnboardingCover.qml \

src/qml/bitcoin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
#include <qml/imageprovider.h>
1919
#include <qml/nodemodel.h>
2020
#include <qml/options_model.h>
21+
#include <qml/peerlistsortproxy.h>
2122
#include <qml/util.h>
2223
#include <qt/guiconstants.h>
2324
#include <qt/guiutil.h>
2425
#include <qt/initexecutor.h>
2526
#include <qt/networkstyle.h>
27+
#include <qt/peertablemodel.h>
2628
#include <util/system.h>
2729
#include <util/threadnames.h>
2830
#include <util/translation.h>
@@ -184,6 +186,10 @@ int QmlGuiMain(int argc, char* argv[])
184186
node->startShutdown();
185187
});
186188

189+
PeerTableModel peer_model{*node, nullptr};
190+
PeerListSortProxy peer_model_sort_proxy{nullptr};
191+
peer_model_sort_proxy.setSourceModel(&peer_model);
192+
187193
GUIUtil::LoadFont(":/fonts/inter/regular");
188194
GUIUtil::LoadFont(":/fonts/inter/semibold");
189195

@@ -195,6 +201,8 @@ int QmlGuiMain(int argc, char* argv[])
195201

196202
engine.rootContext()->setContextProperty("nodeModel", &node_model);
197203
engine.rootContext()->setContextProperty("chainModel", &chain_model);
204+
engine.rootContext()->setContextProperty("peerTableModel", &peer_model);
205+
engine.rootContext()->setContextProperty("peerListModelProxy", &peer_model_sort_proxy);
198206

199207
OptionsQmlModel options_model{*node};
200208
engine.rootContext()->setContextProperty("optionsModel", &options_model);

src/qml/bitcoin_qml.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<file>pages/main.qml</file>
3030
<file>pages/node/NodeRunner.qml</file>
3131
<file>pages/node/NodeSettings.qml</file>
32+
<file>pages/node/Peers.qml</file>
3233
<file>pages/onboarding/OnboardingBlockclock.qml</file>
3334
<file>pages/onboarding/OnboardingConnection.qml</file>
3435
<file>pages/onboarding/OnboardingCover.qml</file>

src/qml/pages/node/NodeSettings.qml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ Item {
9191
}
9292
onClicked: loadedItem.clicked()
9393
}
94+
Setting {
95+
Layout.fillWidth: true
96+
header: qsTr("Peers")
97+
actionItem: Button {
98+
icon.source: "image://images/caret-right"
99+
icon.color: Theme.color.neutral9
100+
icon.height: 18
101+
icon.width: 18
102+
background: null
103+
onClicked: {
104+
peerTableModel.startAutoRefresh();
105+
nodeSettingsView.push(peers_page)
106+
}
107+
}
108+
onClicked: loadedItem.clicked()
109+
}
94110
}
95111
}
96112
}
@@ -130,4 +146,17 @@ Item {
130146
}
131147
}
132148
}
149+
Component {
150+
id: peers_page
151+
Peers {
152+
navLeftDetail: NavButton {
153+
iconSource: "image://images/caret-left"
154+
text: qsTr("Back")
155+
onClicked: {
156+
nodeSettingsView.pop()
157+
peerTableModel.stopAutoRefresh();
158+
}
159+
}
160+
}
161+
}
133162
}

src/qml/pages/node/Peers.qml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (c) 2023 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+
import QtQuick 2.15
6+
import QtQuick.Controls 2.15
7+
import QtQuick.Layouts 1.15
8+
import "../../controls"
9+
10+
Page {
11+
background: null
12+
property alias navLeftDetail: navbar.leftDetail
13+
14+
header: NavigationBar {
15+
id: navbar
16+
}
17+
18+
Text {
19+
anchors.top: parent.top
20+
anchors.horizontalCenter: parent.horizontalCenter
21+
id: description
22+
height: 75
23+
width: Math.min(parent.width - 40, 450)
24+
wrapMode: Text.WordWrap
25+
text: qsTr("Peers are nodes you are connected to. You want to ensure that you are connected to x, y and z, but not a, b, and c. Learn more.")
26+
font.family: "Inter"
27+
font.styleName: "Regular"
28+
font.pixelSize: 13
29+
color: Theme.color.neutral7
30+
horizontalAlignment: Text.AlignHCenter
31+
}
32+
33+
ListView {
34+
id: listView
35+
clip: true
36+
width: Math.min(parent.width - 40, 450)
37+
anchors.top: description.bottom
38+
anchors.bottom: parent.bottom
39+
anchors.horizontalCenter: parent.horizontalCenter
40+
model: peerListModelProxy
41+
spacing: 15
42+
43+
delegate: Item {
44+
required property int nodeId;
45+
required property string address;
46+
required property string subversion;
47+
required property string direction;
48+
implicitHeight: 65
49+
implicitWidth: listView.width
50+
51+
ColumnLayout {
52+
anchors.left: parent.left
53+
Label {
54+
Layout.alignment: Qt.AlignLeft
55+
id: primary
56+
text: "#" + nodeId
57+
font.family: "Inter"
58+
font.styleName: "Regular"
59+
font.pixelSize: 18
60+
color: Theme.color.neutral9
61+
}
62+
Label {
63+
Layout.alignment: Qt.AlignLeft
64+
id: tertiary
65+
text: address
66+
font.family: "Inter"
67+
font.styleName: "Regular"
68+
font.pixelSize: 15
69+
color: Theme.color.neutral7
70+
}
71+
}
72+
ColumnLayout {
73+
anchors.right: parent.right
74+
Label {
75+
Layout.alignment: Qt.AlignRight
76+
id:secondary
77+
text: direction
78+
font.family: "Inter"
79+
font.styleName: "Regular"
80+
font.pixelSize: 18
81+
color: Theme.color.neutral9
82+
}
83+
Label {
84+
Layout.alignment: Qt.AlignRight
85+
id: quaternary
86+
text: subversion
87+
font.family: "Inter"
88+
font.styleName: "Regular"
89+
font.pixelSize: 15
90+
color: Theme.color.neutral7
91+
}
92+
}
93+
Rectangle {
94+
anchors.bottom: parent.bottom
95+
height: 1
96+
width: parent.width
97+
color: Theme.color.neutral5
98+
}
99+
}
100+
}
101+
}

src/qml/peerlistsortproxy.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2023 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+
#include <qml/peerlistsortproxy.h>
6+
#include <qt/peertablemodel.h>
7+
8+
PeerListSortProxy::PeerListSortProxy(QObject* parent)
9+
: PeerTableSortProxy(parent)
10+
{
11+
}
12+
13+
QHash<int, QByteArray> PeerListSortProxy::roleNames() const
14+
{
15+
QHash<int, QByteArray> roles;
16+
roles[PeerTableModel::NetNodeId] = "nodeId";
17+
roles[PeerTableModel::Age] = "age";
18+
roles[PeerTableModel::Address] = "address";
19+
roles[PeerTableModel::Direction] = "direction";
20+
roles[PeerTableModel::ConnectionType] = "connectionType";
21+
roles[PeerTableModel::Network] = "network";
22+
roles[PeerTableModel::Ping] = "ping";
23+
roles[PeerTableModel::Sent] = "sent";
24+
roles[PeerTableModel::Received] = "received";
25+
roles[PeerTableModel::Subversion] = "subversion";
26+
return roles;
27+
}
28+
29+
QVariant PeerListSortProxy::data(const QModelIndex& index, int role) const
30+
{
31+
if (role == PeerTableModel::StatsRole) {
32+
return PeerTableSortProxy::data(index, role);
33+
}
34+
35+
QModelIndex converted_index = PeerTableSortProxy::index(index.row(), role);
36+
return PeerTableSortProxy::data(converted_index, Qt::DisplayRole);
37+
}

src/qml/peerlistsortproxy.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2023 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_QML_PEERLISTSORTPROXY_H
6+
#define BITCOIN_QML_PEERLISTSORTPROXY_H
7+
8+
#include <qt/peertablesortproxy.h>
9+
#include <QByteArray>
10+
#include <QHash>
11+
#include <QModelIndex>
12+
#include <QVariant>
13+
14+
class PeerListSortProxy : public PeerTableSortProxy
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
explicit PeerListSortProxy(QObject* parent);
20+
~PeerListSortProxy() = default;
21+
22+
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
23+
QHash<int, QByteArray> roleNames() const override;
24+
};
25+
26+
#endif // BITCOIN_QML_PEERLISTSORTPROXY_H

src/qt/peertablemodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class PeerTableModel : public QAbstractTableModel
4242
public:
4343
explicit PeerTableModel(interfaces::Node& node, QObject* parent);
4444
~PeerTableModel();
45-
void startAutoRefresh();
46-
void stopAutoRefresh();
45+
Q_INVOKABLE void startAutoRefresh();
46+
Q_INVOKABLE void stopAutoRefresh();
4747

4848
enum ColumnIndex {
4949
NetNodeId = 0,

0 commit comments

Comments
 (0)