mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-22 19:49:34 +00:00
RemoteNodeList, RemoteNodeDialog: different remote node for each network type; implement labels
This commit is contained in:
parent
710e3f6948
commit
bc08952c76
3 changed files with 124 additions and 10 deletions
|
@ -34,13 +34,14 @@ import "." as MoneroComponents
|
|||
|
||||
MoneroComponents.Dialog {
|
||||
id: root
|
||||
title: (editMode ? qsTr("Edit remote node") : qsTr("Add remote node")) + translationManager.emptyString
|
||||
|
||||
title: (editMode ? qsTr("Edit remote node") + (persistentSettings.nettype != 0 ? " (%1)".arg(networkTypeAsString()) : "")
|
||||
: qsTr("Add remote node") + (persistentSettings.nettype != 0 ? " (%1)".arg(networkTypeAsString()) : "")
|
||||
) + translationManager.emptyString
|
||||
property var callbackOnSuccess: null
|
||||
property bool editMode: false
|
||||
property bool success: false
|
||||
|
||||
onActiveFocusChanged: activeFocus && remoteNodeAddress.forceActiveFocus()
|
||||
onActiveFocusChanged: activeFocus && remoteNodeLabel.forceActiveFocus()
|
||||
|
||||
function onOk() {
|
||||
root.success = true;
|
||||
|
@ -62,6 +63,9 @@ MoneroComponents.Dialog {
|
|||
remoteNodeAddress.daemonAddrText = hostPort[1];
|
||||
remoteNodeAddress.daemonPortText = hostPort[2];
|
||||
}
|
||||
if (remoteNode.label) {
|
||||
remoteNodeLabel.text = remoteNode.label;
|
||||
}
|
||||
daemonUsername.text = remoteNode.username;
|
||||
daemonPassword.text = remoteNode.password;
|
||||
setTrustedDaemonCheckBox.checked = remoteNode.trusted;
|
||||
|
@ -74,6 +78,8 @@ MoneroComponents.Dialog {
|
|||
onClosed: {
|
||||
if (root.success && callbackOnSuccess) {
|
||||
callbackOnSuccess({
|
||||
label: remoteNodeLabel.text,
|
||||
networkType: persistentSettings.nettype.toString(),
|
||||
address: remoteNodeAddress.getAddress(),
|
||||
username: daemonUsername.text,
|
||||
password: daemonPassword.text,
|
||||
|
@ -81,6 +87,7 @@ MoneroComponents.Dialog {
|
|||
});
|
||||
}
|
||||
|
||||
remoteNodeLabel.text = "";
|
||||
remoteNodeAddress.daemonAddrText = "";
|
||||
remoteNodeAddress.daemonPortText = "";
|
||||
daemonUsername.text = "";
|
||||
|
@ -89,6 +96,18 @@ MoneroComponents.Dialog {
|
|||
root.success = false;
|
||||
}
|
||||
|
||||
MoneroComponents.LineEdit {
|
||||
id: remoteNodeLabel
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: 220
|
||||
labelText: qsTr("Label") + translationManager.emptyString
|
||||
placeholderText: qsTr("(optional)") + translationManager.emptyString
|
||||
placeholderFontSize: 15
|
||||
text: ""
|
||||
labelFontSize: 14
|
||||
fontSize: 15
|
||||
}
|
||||
|
||||
MoneroComponents.RemoteNodeEdit {
|
||||
id: remoteNodeAddress
|
||||
Layout.fillWidth: true
|
||||
|
|
|
@ -60,6 +60,10 @@ ColumnLayout {
|
|||
height: 30
|
||||
Layout.fillWidth: true
|
||||
color: itemMouseArea.containsMouse || trustedDaemonCheckMark.labelMouseArea.containsMouse || index === remoteNodesModel.selected ? MoneroComponents.Style.titleBarButtonHoverColor : "transparent"
|
||||
property var networkType: remoteNodesModel.get(index) ? remoteNodesModel.get(index).networkType : ""
|
||||
visible: (networkType ? networkType == persistentSettings.nettype.toString()
|
||||
: persistentSettings.nettype.toString() == 0 ? true
|
||||
: false)
|
||||
|
||||
Rectangle {
|
||||
visible: index === remoteNodesModel.selected
|
||||
|
@ -76,7 +80,7 @@ ColumnLayout {
|
|||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
height: 1
|
||||
visible: index > 0
|
||||
visible: index != remoteNodesModel.findFirstRemoteNodeAvailable(persistentSettings.nettype)
|
||||
|
||||
MoneroEffects.ColorTransition {
|
||||
targetObj: parent
|
||||
|
@ -90,6 +94,7 @@ ColumnLayout {
|
|||
anchors.rightMargin: 80
|
||||
color: "transparent"
|
||||
property var trusted: remoteNodesModel.get(index) ? remoteNodesModel.get(index).trusted : false
|
||||
property var label: remoteNodesModel.get(index) ? remoteNodesModel.get(index).label : ""
|
||||
|
||||
MoneroComponents.TextPlain {
|
||||
id: addressText
|
||||
|
@ -99,7 +104,7 @@ ColumnLayout {
|
|||
anchors.left: parent.left
|
||||
anchors.leftMargin: 6
|
||||
font.pixelSize: 16
|
||||
text: address
|
||||
text: (label ? label + " (" + address + ")" : address)
|
||||
themeTransition: false
|
||||
elide: Text.ElideMiddle
|
||||
}
|
||||
|
|
92
main.qml
92
main.qml
|
@ -358,6 +358,46 @@ ApplicationWindow {
|
|||
|
||||
if (persistentSettings.useRemoteNode) {
|
||||
const remoteNode = remoteNodesModel.currentRemoteNode();
|
||||
var firstRemoteNodeAvailable = remoteNodesModel.findFirstRemoteNodeAvailable(persistentSettings.nettype)
|
||||
if (!remoteNodesModel.currentRemoteNode()) {
|
||||
remoteNodesModel.applyRemoteNode(firstRemoteNodeAvailable)
|
||||
} else {
|
||||
if (!remoteNodesModel.currentRemoteNode().networkType) {
|
||||
//backward compatibility with previous remote nodes that don't have networkType set
|
||||
if (persistentSettings.nettype != 0) {
|
||||
if (persistentSettings.nettype == 1) {
|
||||
if (remoteNodesModel.lastTestnetNodeSelected == -1) {
|
||||
remoteNodesModel.lastTestnetNodeSelected = firstRemoteNodeAvailable
|
||||
}
|
||||
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastTestnetNodeSelected)
|
||||
} else if (persistentSettings.nettype == 2) {
|
||||
if (remoteNodesModel.lastStagenetNodeSelected == -1) {
|
||||
remoteNodesModel.lastStagenetNodeSelected = firstRemoteNodeAvailable
|
||||
}
|
||||
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastStagenetNodeSelected)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (remoteNodesModel.currentRemoteNode().networkType != persistentSettings.nettype) {
|
||||
if (persistentSettings.nettype == 0) {
|
||||
if (remoteNodesModel.lastMainnetNodeSelected == -1) {
|
||||
remoteNodesModel.lastMainnetNodeSelected = firstRemoteNodeAvailable
|
||||
}
|
||||
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastMainnetNodeSelected)
|
||||
} else if (persistentSettings.nettype == 1) {
|
||||
if (remoteNodesModel.lastTestnetNodeSelected == -1) {
|
||||
remoteNodesModel.lastTestnetNodeSelected = firstRemoteNodeAvailable
|
||||
}
|
||||
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastTestnetNodeSelected)
|
||||
} else if (persistentSettings.nettype == 2) {
|
||||
if (remoteNodesModel.lastStagenetNodeSelected == -1) {
|
||||
remoteNodesModel.lastStagenetNodeSelected = firstRemoteNodeAvailable
|
||||
}
|
||||
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastStagenetNodeSelected)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentDaemonAddress = remoteNode.address;
|
||||
currentWallet.setDaemonLogin(remoteNode.username, remoteNode.password);
|
||||
} else {
|
||||
|
@ -1480,6 +1520,9 @@ ApplicationWindow {
|
|||
id: remoteNodesModel
|
||||
|
||||
property int selected: 0
|
||||
property int lastMainnetNodeSelected: -1
|
||||
property int lastTestnetNodeSelected: -1
|
||||
property int lastStagenetNodeSelected: -1
|
||||
|
||||
signal store()
|
||||
|
||||
|
@ -1491,6 +1534,9 @@ ApplicationWindow {
|
|||
remoteNodesModel.append(remoteNode);
|
||||
}
|
||||
selected = remoteNodes.selected % remoteNodesModel.count || 0;
|
||||
lastMainnetNodeSelected = remoteNodes.lastMainnetNodeSelected;
|
||||
lastTestnetNodeSelected = remoteNodes.lastTestnetNodeSelected;
|
||||
lastStagenetNodeSelected = remoteNodes.lastStagenetNodeSelected;
|
||||
} catch (e) {
|
||||
console.error('failed to parse remoteNodesSerialized', e);
|
||||
}
|
||||
|
@ -1502,6 +1548,9 @@ ApplicationWindow {
|
|||
}
|
||||
persistentSettings.remoteNodesSerialized = JSON.stringify({
|
||||
selected: selected,
|
||||
lastMainnetNodeSelected: lastMainnetNodeSelected,
|
||||
lastTestnetNodeSelected: lastTestnetNodeSelected,
|
||||
lastStagenetNodeSelected: lastStagenetNodeSelected,
|
||||
nodes: remoteNodes
|
||||
});
|
||||
});
|
||||
|
@ -1510,7 +1559,9 @@ ApplicationWindow {
|
|||
function appendIfNotExists(newRemoteNode) {
|
||||
for (var index = 0; index < remoteNodesModel.count; ++index) {
|
||||
const remoteNode = remoteNodesModel.get(index);
|
||||
if (remoteNode.address == newRemoteNode.address &&
|
||||
if (remoteNode.label == newRemoteNode.label &&
|
||||
remoteNode.networkType == newRemoteNode.networkType &&
|
||||
remoteNode.address == newRemoteNode.address &&
|
||||
remoteNode.username == newRemoteNode.username &&
|
||||
remoteNode.password == newRemoteNode.password &&
|
||||
remoteNode.trusted == newRemoteNode.trusted) {
|
||||
|
@ -1530,6 +1581,13 @@ ApplicationWindow {
|
|||
currentWallet.setTrustedDaemon(remoteNode.trusted);
|
||||
appWindow.connectRemoteNode();
|
||||
}
|
||||
if (persistentSettings.nettype == 0) {
|
||||
remoteNodesModel.lastMainnetNodeSelected = selected;
|
||||
} else if (persistentSettings.nettype == 1) {
|
||||
remoteNodesModel.lastTestnetNodeSelected = selected;
|
||||
} else if (persistentSettings.nettype == 2) {
|
||||
remoteNodesModel.lastStagenetNodeSelected = selected;
|
||||
}
|
||||
}
|
||||
|
||||
function currentRemoteNode() {
|
||||
|
@ -1537,6 +1595,8 @@ ApplicationWindow {
|
|||
return remoteNodesModel.get(selected);
|
||||
}
|
||||
return {
|
||||
label: "",
|
||||
networkType: "",
|
||||
address: "",
|
||||
username: "",
|
||||
password: "",
|
||||
|
@ -1546,6 +1606,15 @@ ApplicationWindow {
|
|||
|
||||
function removeSelectNextIfNeeded(index) {
|
||||
remoteNodesModel.remove(index);
|
||||
if (index < remoteNodesModel.lastMainnetNodeSelected) {
|
||||
remoteNodesModel.lastMainnetNodeSelected = remoteNodesModel.lastMainnetNodeSelected - 1
|
||||
}
|
||||
if (index < remoteNodesModel.lastTestnetNodeSelected) {
|
||||
remoteNodesModel.lastTestnetNodeSelected = remoteNodesModel.lastTestnetNodeSelected - 1
|
||||
}
|
||||
if (index < remoteNodesModel.lastStagenetNodeSelected) {
|
||||
remoteNodesModel.lastStagenetNodeSelected = remoteNodesModel.lastStagenetNodeSelected - 1
|
||||
}
|
||||
if (selected == index) {
|
||||
applyRemoteNode(selected % remoteNodesModel.count || 0);
|
||||
} else if (selected > index) {
|
||||
|
@ -1553,6 +1622,16 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
function findFirstRemoteNodeAvailable(nettype) {
|
||||
for (var index = 0; index < remoteNodesModel.count; ++index) {
|
||||
const remoteNode = remoteNodesModel.get(index);
|
||||
if (remoteNode.networkType == nettype || persistentSettings.nettype == 0 && !remoteNode.networkType) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
onCountChanged: store()
|
||||
onDataChanged: store()
|
||||
onSelectedChanged: store()
|
||||
|
@ -2305,6 +2384,17 @@ ApplicationWindow {
|
|||
console.log("walletMode: " + (mode === 0 ? "simple": mode === 1 ? "simple (bootstrap)" : "Advanced"));
|
||||
}
|
||||
|
||||
function networkTypeAsString() {
|
||||
if (persistentSettings.nettype == 0){
|
||||
return "mainnet";
|
||||
}
|
||||
else if (persistentSettings.nettype == 1) {
|
||||
return "testnet";
|
||||
} else {
|
||||
return "stagenet"
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: inactiveOverlay
|
||||
visible: blur.visible
|
||||
|
|
Loading…
Reference in a new issue