Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions dcc-network/qml/SectionIPv4.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ DccObject {
} else {
delete sConfig["addresses"]
delete sConfig["address-data"]
delete sConfig["gateway"] // 非手动模式下不应保留手动设置的网关
delete sConfig["gateway"] // 非手动模式下不应保留手动设置的网关

// 禁用模式下不应该有任何IPv4配置字段
if (method === "disabled") {
delete sConfig["dns"]
Expand All @@ -68,6 +68,7 @@ DccObject {
errorKey = ""
errorMsg = ""
if (method === "manual") {
let gatewayCount = 0
for (let k in addressData) {
if (!NetUtils.ipRegExp.test(addressData[k][0])) {
errorKey = k + "address"
Expand All @@ -79,6 +80,14 @@ DccObject {
errorMsg = qsTr("Invalid netmask")
return false
}
if (addressData[k][2].length !== 0) {
gatewayCount++
if (gatewayCount >= 2) {
errorKey = k + "gateway"
errorMsg = qsTr("Only one gateway is allowed")
return false
}
}
if (addressData[k][2].length !== 0 && !NetUtils.ipRegExp.test(addressData[k][2])) {
errorKey = k + "gateway"
errorMsg = qsTr("Invalid gateway")
Expand Down Expand Up @@ -131,8 +140,8 @@ DccObject {
Label {
text: dccObj.displayName
font: DccUtils.copyFont(D.DTK.fontManager.t4, {
"bold": true
})
"bold": true
})
}
Item {
Layout.fillWidth: true
Expand Down Expand Up @@ -250,8 +259,8 @@ DccObject {
Label {
text: dccObj.displayName
font: DccUtils.copyFont(D.DTK.fontManager.t6, {
"bold": true
})
"bold": true
})
}
Item {
Layout.fillWidth: true
Expand Down Expand Up @@ -391,6 +400,7 @@ DccObject {
}
showAlert: errorKey === index + dccObj.name
alertDuration: 2000
alertText: errorKey === index + dccObj.name ? root.errorMsg : ""
onShowAlertChanged: {
if (showAlert) {
DccApp.showPage(dccObj)
Expand All @@ -405,8 +415,8 @@ DccObject {
onAddressDataChanged: {
while (addressData.length > ipItems.length) {
let ipItem = ipComponent.createObject(root, {
"index": ipItems.length
})
"index": ipItems.length
})
DccApp.addObject(ipItem)
ipItems.push(ipItem)
}
Expand Down
33 changes: 24 additions & 9 deletions dcc-network/qml/SectionIPv6.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DccObject {
property var addressData: []
property bool isEdit: false
property string method: "auto"
property string gateway: ""
property var gateway: []

property string errorKey: ""
property string errorMsg: ""
Expand All @@ -31,25 +31,31 @@ DccObject {
root.config = {}
method = "auto"
addressData = []
gateway = ""
gateway = []
} else {
root.config = c
method = root.config.method
addressData = (root.config && root.config.hasOwnProperty("address-data")) ? root.config["address-data"] : []
gateway = (root.config && root.config.hasOwnProperty("gateway")) ? root.config["gateway"] : ""
gateway = []
gateway[0] = (root.config && root.config.hasOwnProperty("gateway")) ? root.config["gateway"] : ""
}
}
function getConfig() {
let sConfig = root.config
sConfig["method"] = method
if (method === "manual") {
sConfig["address-data"] = addressData
sConfig["gateway"] = gateway
for (let k in gateway) {
if (gateway[k].length !== 0) {
sConfig["gateway"] = gateway[k]
break
}
}
} else {
delete sConfig["address-data"]
delete sConfig["gateway"]
delete sConfig["addresses"]

// 禁用和忽略模式下不应该有任何IPv6配置字段
if (method === "disabled" || method === "ignore") {
delete sConfig["dns"]
Expand All @@ -64,6 +70,7 @@ DccObject {
errorKey = ""
errorMsg = ""
if (method === "manual") {
let gatewayCount = 0
let ipSet = new Set()
for (let k in addressData) {
if (!NetUtils.ipv6RegExp.test(addressData[k].address)) {
Expand All @@ -83,7 +90,15 @@ DccObject {
return false
}
// 检查网关
if (k === "0" && gateway.length !== 0 && !NetUtils.ipv6RegExp.test(gateway)) {
if (gateway[k].length !== 0) {
gatewayCount++
if (gatewayCount >= 2) {
errorKey = k + "gateway"
errorMsg = qsTr("Only one gateway is allowed")
return false
}
}
if (gateway[k].length !== 0 && !NetUtils.ipv6RegExp.test(gateway[k])) {
errorKey = k + "gateway"
errorMsg = qsTr("Invalid gateway")
return false
Expand Down Expand Up @@ -380,16 +395,16 @@ DccObject {
pageType: DccObject.Editor
page: D.LineEdit {
enabled: index === 0
text: index === 0 ? gateway : ""
text: index === 0 ? gateway[index] : ""
validator: RegularExpressionValidator {
regularExpression: NetUtils.ipv6RegExp
}
onTextChanged: {
if (showAlert) {
errorKey = ""
}
if (gateway !== text) {
gateway = text
if (gateway[index] !== text) {
gateway[index] = text
root.editClicked()
}
}
Expand Down