Skip to content

Commit 6f3fb61

Browse files
committed
fix: fix null pointer and improve DNS/IP configuration
Fixed a null pointer access issue in PageSystemProxy.qml by adding a null check before accessing the visibleToApp property. This prevents potential crashes when the ignoreHosts object is not available. Refactored DNS, IPv4, and IPv6 configuration sections to use DccRepeater for dynamic item management instead of manual component creation and destruction. This simplifies the code structure and eliminates the need for separate arrays to track created items. Added helper functions addAddressData() and removeAddressData() to centralize data manipulation logic. In the IPv6 validation logic, added null checks for gateway values to prevent errors when gateway fields are empty. This ensures proper validation of IPv6 configurations. Log: Fixed system proxy page visibility issue and improved DNS/IP configuration management Influence: 1. Test system proxy settings to ensure the "Ignore hosts" option appears correctly 2. Verify DNS configuration by adding and removing DNS servers 3. Test IPv4 configuration by adding multiple IP addresses 4. Test IPv6 configuration with empty and populated gateway fields 5. Validate all network configuration changes are properly saved 6. Check that UI updates correctly when modifying network settings fix: 修复空指针问题并改进DNS/IP配置 修复了PageSystemProxy.qml中的空指针访问问题,在访问visibleToApp属性前添 加了空值检查,防止ignoreHosts对象不可用时导致程序崩溃。 重构了DNS、IPv4和IPv6配置部分,使用DccRepeater进行动态项管理,替代了手动 创建和销毁组件的方式。这简化了代码结构,并消除了单独跟踪已创建项的需要。 添加了addAddressData()和removeAddressData()辅助函数来集中数据操作逻辑。 在IPv6验证逻辑中,为网关值添加了空值检查,防止网关字段为空时出现错误。这 确保了IPv6配置的正确验证。 Log: 修复系统代理页面显示问题并改进DNS/IP配置管理 Influence: 1. 测试系统代理设置,确保"忽略主机"选项正确显示 2. 验证DNS配置,测试添加和删除DNS服务器 3. 测试IPv4配置,添加多个IP地址 4. 测试IPv6配置,包括空和已填充的网关字段 5. 验证所有网络配置更改是否正确保存 6. 检查修改网络设置时UI是否正确更新
1 parent 1cf9591 commit 6f3fb61

File tree

5 files changed

+112
-151
lines changed

5 files changed

+112
-151
lines changed

dcc-network/qml/PageSystemProxy.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ DccObject {
249249
parentName: root.name + "/menu/body"
250250
displayName: qsTr("Ignore the proxy configurations for the above hosts and domains")
251251
weight: 90
252-
visible: ignoreHosts.visibleToApp
252+
visible: ignoreHosts && ignoreHosts.visibleToApp
253253
pageType: DccObject.Item
254254
page: Label {
255255
text: dccObj.displayName

dcc-network/qml/SectionDNS.qml

Lines changed: 75 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ DccObject {
106106
console.log("[DNS-Check] All DNS entries validated successfully")
107107
return true
108108
}
109+
function addAddressData(addr) {
110+
config.push(addr)
111+
configChanged()
112+
editClicked()
113+
}
114+
function removeAddressData(index) {
115+
config.splice(index, 1)
116+
configChanged()
117+
editClicked()
118+
}
109119

110120
name: "dnsTitle"
111121
displayName: qsTr("DNS")
@@ -153,105 +163,81 @@ DccObject {
153163
canSearch: false
154164
pageType: DccObject.Item
155165
page: DccGroupView {}
156-
}
157-
Component {
158-
id: dnsComponent
159-
DccObject {
160-
id: dnsItem
161-
property int index: 0
162-
weight: root.weight + 30 + index
163-
name: "dns" + index
164-
displayName: qsTr("DNS") + (index + 1)
165-
parentName: root.parentName + "/dnsGroup"
166-
canSearch: false
167-
pageType: DccObject.Editor
168-
page: RowLayout {
169-
D.LineEdit {
170-
text: root.config[index]
171-
// 移除正则验证器,改用手动验证以支持IPv6
172-
// 显式允许所有字符输入,包括冒号
173-
inputMethodHints: Qt.ImhNone
174-
onTextChanged: {
175-
console.log("[DNS-Input] Text changed in DNS field", index, ":", text)
176-
if (showAlert) {
177-
errorKey = ""
166+
DccRepeater {
167+
model: root.config
168+
delegate: DccObject {
169+
id: dnsItem
170+
weight: root.weight + 30 + index
171+
name: "dns" + index
172+
displayName: qsTr("DNS") + (index + 1)
173+
parentName: root.parentName + "/dnsGroup"
174+
canSearch: false
175+
pageType: DccObject.Editor
176+
page: RowLayout {
177+
D.LineEdit {
178+
text: root.config[index]
179+
// 移除正则验证器,改用手动验证以支持IPv6
180+
// 显式允许所有字符输入,包括冒号
181+
inputMethodHints: Qt.ImhNone
182+
onTextChanged: {
183+
console.log("[DNS-Input] Text changed in DNS field", index, ":", text)
184+
if (showAlert) {
185+
errorKey = ""
186+
}
187+
if (text !== root.config[index]) {
188+
console.log("[DNS-Input] Updating config[" + index + "] from", root.config[index], "to", text)
189+
root.config[index] = text
190+
root.editClicked()
191+
}
178192
}
179-
if (text !== root.config[index]) {
180-
console.log("[DNS-Input] Updating config[" + index + "] from", root.config[index], "to", text)
181-
root.config[index] = text
182-
root.editClicked()
193+
showAlert: errorKey === dccObj.name
194+
alertDuration: 2000
195+
alertText: qsTr("Invalid IP address")
196+
onShowAlertChanged: {
197+
if (showAlert) {
198+
DccApp.showPage(dccObj)
199+
forceActiveFocus()
200+
}
183201
}
184202
}
185-
showAlert: errorKey === dccObj.name
186-
alertDuration: 2000
187-
alertText: qsTr("Invalid IP address")
188-
onShowAlertChanged: {
189-
if (showAlert) {
190-
DccApp.showPage(dccObj)
191-
forceActiveFocus()
203+
D.IconLabel {
204+
Layout.margins: 0
205+
Layout.maximumHeight: 16
206+
visible: isEdit && root.config.length < 3
207+
// enabled: root.config.length < 3
208+
icon {
209+
name: "list_add"
210+
width: 16
211+
height: 16
192212
}
193-
}
194-
}
195-
D.IconLabel {
196-
Layout.margins: 0
197-
Layout.maximumHeight: 16
198-
visible: isEdit && root.config.length < 3
199-
// enabled: root.config.length < 3
200-
icon {
201-
name: "list_add"
202-
width: 16
203-
height: 16
204-
}
205-
MouseArea {
206-
anchors.fill: parent
207-
acceptedButtons: Qt.LeftButton
208-
onClicked: {
209-
root.config.push("")
210-
root.configChanged()
213+
MouseArea {
214+
anchors.fill: parent
215+
acceptedButtons: Qt.LeftButton
216+
onClicked: {
217+
root.addAddressData("")
218+
}
211219
}
212220
}
213-
}
214-
D.IconLabel {
215-
Layout.margins: 0
216-
Layout.maximumHeight: 16
217-
visible: isEdit && root.config.length > 2
218-
// enabled: root.config.length > 2
219-
icon {
220-
name: "list_delete"
221-
width: 16
222-
height: 16
223-
}
224-
MouseArea {
225-
anchors.fill: parent
226-
acceptedButtons: Qt.LeftButton
227-
onClicked: {
228-
root.config.splice(index, 1)
229-
root.configChanged()
221+
D.IconLabel {
222+
Layout.margins: 0
223+
Layout.maximumHeight: 16
224+
visible: isEdit && root.config.length > 2
225+
// enabled: root.config.length > 2
226+
icon {
227+
name: "list_delete"
228+
width: 16
229+
height: 16
230+
}
231+
MouseArea {
232+
anchors.fill: parent
233+
acceptedButtons: Qt.LeftButton
234+
onClicked: {
235+
root.removeAddressData(index)
236+
}
230237
}
231238
}
232239
}
233240
}
234241
}
235242
}
236-
function addIpItem() {
237-
let dnsItem = dnsComponent.createObject(root, {
238-
"index": dnsItems.length
239-
})
240-
DccApp.addObject(dnsItem)
241-
dnsItems.push(dnsItem)
242-
}
243-
function removeIpItem() {
244-
let tmpItem = dnsItems.pop()
245-
DccApp.removeObject(tmpItem)
246-
tmpItem.destroy()
247-
}
248-
249-
onConfigChanged: {
250-
while (root.config.length > dnsItems.length) {
251-
addIpItem()
252-
}
253-
while (root.config.length < dnsItems.length) {
254-
removeIpItem()
255-
}
256-
}
257243
}

dcc-network/qml/SectionIPv4.qml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ DccObject {
131131
addressData = []
132132
}
133133
}
134+
function addAddressData(addr) {
135+
addressData.push(addr)
136+
addressDataChanged()
137+
editClicked()
138+
}
139+
function removeAddressData(index) {
140+
addressData.splice(index, 1)
141+
addressDataChanged()
142+
editClicked()
143+
}
134144

135145
name: "ipv4Title"
136146
displayName: qsTr("IPv4")
@@ -246,11 +256,10 @@ DccObject {
246256
}
247257
}
248258
}
249-
Component {
250-
id: ipComponent
251-
DccObject {
259+
DccRepeater {
260+
model: root.addressData
261+
delegate: DccObject {
252262
id: ipv4Item
253-
property int index: 0
254263
weight: root.weight + 30 + index
255264
name: "ipv4_" + index
256265
displayName: "IP-" + index
@@ -290,9 +299,7 @@ DccObject {
290299
anchors.fill: parent
291300
acceptedButtons: Qt.LeftButton
292301
onClicked: {
293-
root.addressData.push(["0.0.0.0", "255.255.255.0", ""])
294-
root.addressDataChanged()
295-
root.editClicked()
302+
root.addAddressData(["0.0.0.0", "255.255.255.0", ""])
296303
}
297304
}
298305
}
@@ -309,9 +316,7 @@ DccObject {
309316
anchors.fill: parent
310317
acceptedButtons: Qt.LeftButton
311318
onClicked: {
312-
root.addressData.splice(index, 1)
313-
root.addressDataChanged()
314-
root.editClicked()
319+
root.removeAddressData(index)
315320
}
316321
}
317322
}
@@ -424,18 +429,4 @@ DccObject {
424429
}
425430
}
426431
}
427-
onAddressDataChanged: {
428-
while (addressData.length > ipItems.length) {
429-
let ipItem = ipComponent.createObject(root, {
430-
"index": ipItems.length
431-
})
432-
DccApp.addObject(ipItem)
433-
ipItems.push(ipItem)
434-
}
435-
while (addressData.length < ipItems.length) {
436-
let tmpItem = ipItems.pop()
437-
DccApp.removeObject(tmpItem)
438-
tmpItem.destroy()
439-
}
440-
}
441432
}

dcc-network/qml/SectionIPv6.qml

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ DccObject {
9090
return false
9191
}
9292
// 检查网关
93-
if (gateway[k].length !== 0) {
93+
if (gateway[k] && gateway[k].length !== 0) {
9494
gatewayCount++
9595
if (gatewayCount >= 2) {
9696
errorKey = k + "gateway"
9797
errorMsg = qsTr("Only one gateway is allowed")
9898
return false
9999
}
100100
}
101-
if (gateway[k].length !== 0 && !NetUtils.ipv6RegExp.test(gateway[k])) {
101+
if (gateway[k] && gateway[k].length !== 0 && !NetUtils.ipv6RegExp.test(gateway[k])) {
102102
errorKey = k + "gateway"
103103
errorMsg = qsTr("Invalid gateway")
104104
return false
@@ -121,6 +121,16 @@ DccObject {
121121
addressData = []
122122
}
123123
}
124+
function addAddressData(addr) {
125+
addressData.push(addr)
126+
addressDataChanged()
127+
editClicked()
128+
}
129+
function removeAddressData(index) {
130+
addressData.splice(index, 1)
131+
addressDataChanged()
132+
editClicked()
133+
}
124134

125135
ListModel {
126136
id: allModel
@@ -247,11 +257,10 @@ DccObject {
247257
}
248258
}
249259
}
250-
Component {
251-
id: ipComponent
252-
DccObject {
260+
DccRepeater {
261+
model: root.addressData
262+
delegate: DccObject {
253263
id: ipv6Item
254-
property int index: 0
255264
weight: root.weight + 30 + index
256265
name: "ipv6_" + index
257266
visible: root.visible
@@ -292,12 +301,10 @@ DccObject {
292301
anchors.fill: parent
293302
acceptedButtons: Qt.LeftButton
294303
onClicked: {
295-
root.addressData.push({
296-
"address": "",
297-
"prefix": 64
298-
})
299-
root.addressDataChanged()
300-
root.editClicked()
304+
root.addAddressData({
305+
"address": "",
306+
"prefix": 64
307+
})
301308
}
302309
}
303310
}
@@ -314,9 +321,7 @@ DccObject {
314321
anchors.fill: parent
315322
acceptedButtons: Qt.LeftButton
316323
onClicked: {
317-
root.addressData.splice(index, 1)
318-
root.addressDataChanged()
319-
root.editClicked()
324+
root.removeAddressData(index)
320325
}
321326
}
322327
}
@@ -434,25 +439,4 @@ DccObject {
434439
}
435440
}
436441
}
437-
function addIpItem() {
438-
let ipItem = ipComponent.createObject(root, {
439-
"index": ipItems.length
440-
})
441-
DccApp.addObject(ipItem)
442-
ipItems.push(ipItem)
443-
}
444-
function removeIpItem() {
445-
let tmpItem = ipItems.pop()
446-
DccApp.removeObject(tmpItem)
447-
tmpItem.destroy()
448-
}
449-
450-
onAddressDataChanged: {
451-
while (root.addressData.length > ipItems.length) {
452-
addIpItem()
453-
}
454-
while (root.addressData.length < ipItems.length) {
455-
removeIpItem()
456-
}
457-
}
458442
}

src/impl/networkmanager/networkmanagerprocesser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void NetworkManagerProcesser::checkConnectivityFinished(quint32 conntity)
381381

382382
void NetworkManagerProcesser::onConnectivityChanged(NetworkManager::Connectivity conntity)
383383
{
384-
dde::network::Connectivity ctity;
384+
dde::network::Connectivity ctity = m_connectivity;
385385
switch (conntity) {
386386
case NetworkManager::Connectivity::Full: {
387387
ctity = dde::network::Connectivity::Full;

0 commit comments

Comments
 (0)