forked from linuxdeepin/dde-network-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageWirelessDevice.qml
More file actions
325 lines (314 loc) · 12.6 KB
/
Copy pathPageWirelessDevice.qml
File metadata and controls
325 lines (314 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import Qt.labs.platform 1.1
import Qt.labs.qmlmodels 1.2
import org.deepin.dtk 1.0 as D
import org.deepin.dcc 1.0
import org.deepin.dcc.network 1.0
DccObject {
id: root
property var item: null
property var airplaneItem: null
readonly property var c_levelString: ["-signal-no", "-signal-low", "-signal-medium", "-signal-high", "-signal-full"]
name: "wireless" + item.pathIndex
parentName: "network"
displayName: item.name
description: qsTr("Connect, edit network settings")
backgroundType: DccObject.Normal
icon: "dcc_wifi"
weight: 2010 + item.pathIndex
pageType: DccObject.MenuEditor
page: devCheck
Component {
id: devCheck
RowLayout {
D.Switch {
checked: root.item.isEnabled
enabled: root.item.enabledable
onClicked: {
dccData.exec(root.item.isEnabled ? NetManager.DisabledDevice : NetManager.EnabledDevice, root.item.id, {})
}
}
}
}
Component {
id: networkList
ColumnLayout {
objectName: "noPadding"
clip: true
spacing: 0
Repeater {
id: repeater
model: NetItemModel {
root: dccObj.item
}
delegate: DelegateChooser {
role: "type"
DelegateChoice {
roleValue: NetType.WirelessItem
delegate: ItemDelegate {
id: itemDelegate
height: 36
text: model.item.name
hoverEnabled: true
checked: true
backgroundVisible: false
corners: getCornersForBackground(index, repeater.count)
cascadeSelected: true
Layout.fillWidth: true
leftPadding: 10
rightPadding: 10
spacing: 10
icon {
name: "network-wireless" + (item.flags & 0x10 ? "-6" : "") + c_levelString[item.strengthLevel] + (item.secure ? "-secure" : "") + "-symbolic"
height: 16
width: 16
}
content: RowLayout {
spacing: 10
BusyIndicator {
running: model.item.status === NetType.CS_Connecting
visible: running
}
DccCheckIcon {
visible: model.item.status === NetType.CS_Connected && !itemDelegate.hovered
}
NetButton {
implicitHeight: implicitContentHeight - 4
topInset: -4
bottomInset: -4
visible: model.item.status !== NetType.CS_Connecting && itemDelegate.hovered
text: model.item.status === NetType.CS_Connected ? qsTr("Disconnect") : qsTr("Connect")
Layout.alignment: Qt.AlignVCenter
onClicked: {
dccData.exec(model.item.status === NetType.CS_Connected ? NetManager.Disconnect : NetManager.ConnectOrInfo, model.item.id, {})
}
}
D.IconLabel {
icon {
name: "arrow_ordinary_right"
palette: D.DTK.makeIconPalette(palette)
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: {
dccData.exec(NetManager.ConnectInfo, model.item.id, {})
}
}
}
}
onDoubleClicked: {
if (model.item.status === NetType.CS_UnConnected) {
dccData.exec(NetManager.ConnectOrInfo, model.item.id, {})
}
}
background: DccItemBackground {
separatorVisible: true
}
}
}
DelegateChoice {
roleValue: NetType.WirelessHiddenItem
delegate: ItemDelegate {
implicitHeight: 36
checked: true
backgroundVisible: false
corners: getCornersForBackground(index, repeater.count)
cascadeSelected: true
Layout.fillWidth: true
leftPadding: 36
contentItem: Label {
verticalAlignment: Text.AlignVCenter
text: model.item.name
color: palette.link
}
onClicked: {
dccData.exec(NetManager.ConnectInfo, model.item.id, {})
}
background: DccItemBackground {
separatorVisible: true
}
}
}
}
}
}
}
DccObject {
name: "page"
parentName: root.name
DccObject {
name: "title"
parentName: root.name + "/page"
displayName: root.item.name
icon: "dcc_wifi"
weight: 10
backgroundType: DccObject.Normal
pageType: DccObject.Editor
page: devCheck
}
DccObject {
name: "mineTitle"
parentName: root.name + "/page"
displayName: qsTr("My Networks")
visible: mineNetwork.visible
weight: 30
pageType: DccObject.Item
page: Label {
font: DccUtils.copyFont(D.DTK.fontManager.t5, {
"bold": true
})
text: dccObj.displayName
}
onParentItemChanged: {
if (parentItem) {
parentItem.topPadding = 5
parentItem.bottomPadding = 0
parentItem.leftPadding = 10
}
}
}
DccObject {
id: mineNetwork
property var item: null
name: "mineNetwork"
parentName: root.name + "/page"
weight: 40
pageType: DccObject.Item
backgroundType: DccObject.Normal
visible: root.item && root.item.isEnabled && !root.item.apMode && this.item && this.item.children.length > 0
page: networkList
}
DccObject {
name: "otherTitle"
parentName: root.name + "/page"
displayName: qsTr("Other Networks")
visible: otherNetwork.visible
weight: 50
pageType: DccObject.Item
page: Label {
font: DccUtils.copyFont(D.DTK.fontManager.t6, {
"bold": true
})
text: dccObj.displayName
}
onParentItemChanged: {
if (parentItem) {
parentItem.topPadding = 5
parentItem.bottomPadding = 0
parentItem.leftPadding = 10
}
}
}
DccObject {
id: otherNetwork
property var item: null
name: "otherNetwork"
parentName: root.name + "/page"
weight: 60
visible: root.item && root.item.isEnabled && !root.item.apMode && this.item && this.item.children.length > 0
pageType: DccObject.Item
backgroundType: DccObject.Normal
page: networkList
}
DccObject {
name: "airplaneTips"
parentName: root.name + "/page"
visible: root.airplaneItem && root.airplaneItem.isEnabled && root.airplaneItem.enabledable
displayName: qsTr("Disable Airplane Mode first if you want to connect to a wireless network")
weight: 70
pageType: DccObject.Item
page: D.Label {
textFormat: Text.RichText
text: qsTr("Disable <a style='text-decoration: none;' href='network/airplaneMode'>Airplane Mode</a> first if you want to connect to a wireless network")
wrapMode: Text.WordWrap
onLinkActivated: link => DccApp.showPage(link)
}
}
DccObject {
name: "airplaneTips"
parentName: root.name + "/page"
visible: root.item && root.item.apMode
displayName: qsTr("Disable hotspot first if you want to connect to a wireless network")
weight: 70
pageType: DccObject.Item
page: D.Label {
textFormat: Text.RichText
text: qsTr("<a style='text-decoration: none;' href='NetHotspotControlItem'>Disable hotspot</a> first if you want to connect to a wireless network")
wrapMode: Text.WordWrap
onLinkActivated: link => dccData.exec(NetManager.DisabledDevice, link, {})
}
}
PageSettings {
id: wirelessSettings
name: "wirelessSettings"
parentName: root.name + "/page/otherNetwork"
onFinished: DccApp.showPage(root)
type: NetType.WirelessItem
Connections {
target: dccData
function onRequest(cmd, id, param) {
if (cmd !== NetManager.ConnectInfo) {
return
}
const items = new Array(root.item)
while (items.length !== 0) {
let tmpItem = items[0]
if (tmpItem.id === id) {
wirelessSettings.displayName = tmpItem.name
wirelessSettings.type = tmpItem.itemType
wirelessSettings.item = tmpItem
wirelessSettings.config = param
DccApp.showPage(wirelessSettings)
break
}
for (let i in tmpItem.children) {
items.push(tmpItem.children[i])
}
// items=items.concat(tmpItem.children)
items.shift()
}
}
}
}
}
function updateItem() {
let hasNet = 0
for (let i in root.item.children) {
const child = root.item.children[i]
switch (child.itemType) {
case NetType.WirelessMineItem:
if (mineNetwork.item !== child) {
mineNetwork.item = child
}
hasNet |= 1
break
case NetType.WirelessOtherItem:
if (otherNetwork.item !== child) {
otherNetwork.item = child
}
hasNet |= 2
break
}
}
if (!(hasNet & 1)) {
mineNetwork.item = null
}
if (!(hasNet & 2)) {
otherNetwork.item = null
}
}
Connections {
target: root.item
function onChildrenChanged() {
updateItem()
}
}
Component.onCompleted: {
updateItem()
}
}