Files
pay/modules/peers-view/NetView.qml
T

171 lines
6.1 KiB
QML
Raw Permalink Normal View History

2022-11-15 12:08:30 +01:00
/*
* This file is part of the Flowee project
2026-01-29 23:13:43 +01:00
* Copyright (C) 2020-2026 Tom Zander <tom@flowee.org>
2022-11-15 12:08:30 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-11-26 10:44:52 +01:00
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
2022-11-15 12:08:30 +01:00
import "../Flowee" as Flowee
2024-01-04 20:37:46 +01:00
import "../mobile" as Mobile;
import Flowee.org.pay;
2022-11-15 12:08:30 +01:00
2024-01-04 20:37:46 +01:00
Mobile.Page {
2024-01-06 21:33:28 +01:00
id: root
2024-01-26 14:44:34 +01:00
headerText: qsTr("Peers") + " (" + listView.count +")";
2024-01-06 21:33:28 +01:00
property QtObject statsAction : QQC2.Action {
text: qsTr("Statistics")
onTriggered: thePile.push("./StatsPage.qml", {"stats": net.createStats(root) });
}
menuItems: [statsAction];
2025-02-26 14:04:58 +01:00
Flowee.Label {
id: offlineLabel
font.bold: true
text: qsTr("No Internet Available")
color: mainWindow.errorRed
visible: Pay.deviceOffline
}
2024-01-06 21:33:28 +01:00
2022-11-15 12:08:30 +01:00
ListView {
id: listView
2024-01-04 20:37:46 +01:00
model: net
2022-12-05 20:31:00 +01:00
anchors.fill: parent
2025-02-26 14:04:58 +01:00
anchors.topMargin: offlineLabel.visible ? offlineLabel.height + 10 : 0
2022-11-15 12:08:30 +01:00
QQC2.ScrollBar.vertical: QQC2.ScrollBar { }
focus: true
Keys.onPressed: (event)=> {
if (event.key === Qt.Key_Escape) {
2023-02-09 18:21:57 +01:00
thePile.pop();
2022-11-15 12:08:30 +01:00
event.accepted = true
}
}
2024-01-28 19:58:27 +01:00
// make removals animated to avoid the list looking 'shokking'
removeDisplaced: Transition {
NumberAnimation { properties: "y"; duration: 300; easing.type: Easing.InQuad }
}
2022-11-15 12:08:30 +01:00
delegate: Rectangle {
width: listView.width
height: peerPane.height + 12
2023-02-21 16:40:46 +01:00
color: index % 2 === 0 ? palette.button : palette.base
2024-01-26 14:26:40 +01:00
border.width: net.selectedId === model.connectionId ? 2 : 0
border.color: palette.highlight
2024-01-04 20:37:46 +01:00
opacity: {
let validity = model.validity;
if (validity === Wallet.CheckedOk || validity === Wallet.KnownGood)
return 1;
return 0.7;
2024-01-04 20:37:46 +01:00
}
2026-01-29 23:13:43 +01:00
Flowee.Label {
text: "(" + model.connectionId + ")"
anchors.right: parent.right
anchors.rightMargin: 10
y: 20
}
2022-11-15 12:08:30 +01:00
ColumnLayout {
id: peerPane
width: listView.width - 20
x: 10
y: 6
Flowee.Label {
2024-01-28 19:58:27 +01:00
text: {
var t = model.userAgent;
if (t === "")
t = model.connectionId
return t;
}
2022-11-15 12:08:30 +01:00
}
Flowee.Label {
2024-01-04 20:37:46 +01:00
text: qsTr("Address", "network address (IP)") + ": " + model.address
2022-11-15 12:08:30 +01:00
}
RowLayout {
height: secondRow.height
2024-01-04 20:37:46 +01:00
spacing: 0
Flowee.Label {
2022-11-15 12:08:30 +01:00
id: secondRow
2024-01-04 20:37:46 +01:00
text: qsTr("Start-height: %1").arg(model.startHeight)
2022-11-15 12:08:30 +01:00
}
Flowee.Label {
2024-01-04 20:37:46 +01:00
text: ", " + qsTr("ban-score: %1").arg(model.banScore)
2022-11-15 12:08:30 +01:00
}
}
Flowee.Label {
2022-11-15 12:08:30 +01:00
id : accountStatus
font.bold: true
text: {
2024-01-04 20:37:46 +01:00
var id = model.segment;
2022-11-15 12:08:30 +01:00
if (id === 0) {
2024-01-04 20:37:46 +01:00
let validity = model.validity;
2024-01-26 12:12:45 +01:00
if (validity === Wallet.OpeningConnection)
return qsTr("Opening Connection");
2024-01-04 20:37:46 +01:00
if (validity === Wallet.Checking)
return qsTr("Validating peer");
if (validity === Wallet.CheckedOk)
return qsTr("Validated");
if (validity === Wallet.KnownGood)
2024-10-14 12:55:51 +02:00
return qsTr("Good Peer", "A useful peer");
2024-01-04 20:37:46 +01:00
return ""; // unknown
2022-11-15 12:08:30 +01:00
}
2024-01-04 20:37:46 +01:00
var accounts = portfolio.rawAccounts;
2022-11-15 12:08:30 +01:00
for (var i = 0; i < accounts.length; ++i) {
if (accounts[i].id === id)
return qsTr("Peer for wallet: %1").arg(accounts[i].name);
}
2024-01-04 20:37:46 +01:00
return "Internal Error";
2022-11-15 12:08:30 +01:00
}
}
2024-01-04 20:37:46 +01:00
Flowee.Label {
text: "Downloading!"
visible: model.isDownloading
2022-11-15 12:08:30 +01:00
}
}
2024-01-26 14:26:40 +01:00
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: (event)=> {
// for mouse
net.selectedId = model.connectionId;
if (event.button === Qt.RightButton)
peerContextMenu.popup(parent, event.x, event.y)
}
onPressAndHold: (event) => {
// for touch
net.selectedId = model.connectionId;
peerContextMenu.popup(parent, event.x, event.y)
}
}
QQC2.Menu {
id: peerContextMenu
QQC2.MenuItem {
text: qsTr("Disconnect Peer")
onClicked: net.disconnectPeer(model.connectionId);
}
QQC2.MenuItem {
text: qsTr("Ban Peer")
onClicked: net.banPeer(model.connectionId);
}
}
2022-11-15 12:08:30 +01:00
}
Keys.forwardTo: Flowee.ListViewKeyHandler {
target: listView
}
}
}