Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/ConnectionItem.qml
Show All 25 Lines | |||||
26 | import org.kde.plasma.components 2.0 as PlasmaComponents | 26 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
27 | import org.kde.plasma.core 2.0 as PlasmaCore | 27 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
28 | import org.kde.plasma.networkmanagement 0.2 as PlasmaNM | 28 | import org.kde.plasma.networkmanagement 0.2 as PlasmaNM | ||
29 | 29 | | |||
30 | PlasmaComponents.ListItem { | 30 | PlasmaComponents.ListItem { | ||
31 | id: connectionItem | 31 | id: connectionItem | ||
32 | 32 | | |||
33 | property bool activating: ConnectionState == PlasmaNM.Enums.Activating | 33 | property bool activating: ConnectionState == PlasmaNM.Enums.Activating | ||
34 | property int baseHeight: Math.max(units.iconSizes.medium, connectionNameLabel.height + connectionStatusLabel.height) + Math.round(units.gridUnit / 2) | 34 | property bool deactivated: ConnectionState === PlasmaNM.Enums.Deactivated | ||
35 | property int baseHeight: Uuid ? connectionNameLabel.implicitHeight + connectionStatusLabel.implicitHeight + background.margins.top | ||||
36 | + background.margins.bottom : stateChangeButton.implicitHeight | ||||
35 | property bool expanded: visibleDetails || visiblePasswordDialog | 37 | property bool expanded: visibleDetails || visiblePasswordDialog | ||
36 | property bool predictableWirelessPassword: !Uuid && Type == PlasmaNM.Enums.Wireless && | 38 | property bool predictableWirelessPassword: !Uuid && Type == PlasmaNM.Enums.Wireless && | ||
37 | (SecurityType == PlasmaNM.Enums.StaticWep || SecurityType == PlasmaNM.Enums.WpaPsk || | 39 | (SecurityType == PlasmaNM.Enums.StaticWep || SecurityType == PlasmaNM.Enums.WpaPsk || | ||
38 | SecurityType == PlasmaNM.Enums.Wpa2Psk) | 40 | SecurityType == PlasmaNM.Enums.Wpa2Psk) | ||
39 | property bool showSpeed: plasmoid.expanded && | 41 | property bool showSpeed: plasmoid.expanded && | ||
40 | ConnectionState == PlasmaNM.Enums.Activated && | 42 | ConnectionState == PlasmaNM.Enums.Activated && | ||
41 | (Type == PlasmaNM.Enums.Wired || | 43 | (Type == PlasmaNM.Enums.Wired || | ||
42 | Type == PlasmaNM.Enums.Wireless || | 44 | Type == PlasmaNM.Enums.Wireless || | ||
43 | Type == PlasmaNM.Enums.Gsm || | 45 | Type == PlasmaNM.Enums.Gsm || | ||
44 | Type == PlasmaNM.Enums.Cdma) | 46 | Type == PlasmaNM.Enums.Cdma) | ||
45 | property bool visibleDetails: false | 47 | property bool visibleDetails: false | ||
46 | property bool visiblePasswordDialog: false | 48 | property bool visiblePasswordDialog: false | ||
47 | 49 | | |||
48 | property real rxBytes: 0 | 50 | property real rxBytes: 0 | ||
49 | property real txBytes: 0 | 51 | property real txBytes: 0 | ||
50 | 52 | | |||
51 | checked: connectionItem.containsMouse | 53 | property bool capturePublicScreenshot: false // RESTORE before commit for final review | ||
54 | | ||||
52 | enabled: true | 55 | enabled: true | ||
53 | height: expanded ? baseHeight + separator.height + expandableComponentLoader.height + (2 * Math.round(units.gridUnit / 3)) : baseHeight | 56 | height: expanded ? baseHeight + units.smallSpacing + expandableComponentLoader.height + (Uuid ? 0 : background.margins.bottom) : baseHeight | ||
57 | separatorVisible: false | ||||
58 | | ||||
59 | // Background margins metrics | ||||
60 | PlasmaCore.FrameSvgItem { | ||||
61 | id : background | ||||
62 | imagePath: "widgets/listitem" | ||||
63 | prefix: "normal" | ||||
64 | visible: false | ||||
65 | } | ||||
54 | 66 | | |||
55 | ColumnLayout { | 67 | ColumnLayout { | ||
56 | anchors.fill: parent | 68 | anchors.fill: parent | ||
69 | spacing: units.smallSpacing | ||||
57 | 70 | | |||
58 | RowLayout { | 71 | RowLayout { | ||
59 | Layout.fillWidth: true | 72 | spacing: units.smallSpacing * 2 | ||
60 | spacing: Math.round(units.gridUnit / 2) | 73 | Layout.alignment: Uuid ? Qt.AlignCenter : Qt.AlignTop | ||
74 | Layout.minimumHeight: stateChangeButton.implicitHeight | ||||
75 | Layout.topMargin: Uuid ? 0 : - background.margins.top | ||||
61 | 76 | | |||
62 | PlasmaCore.SvgItem { | 77 | PlasmaCore.SvgItem { | ||
63 | id: connectionSvgIcon | 78 | id: connectionSvgIcon | ||
64 | Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft | 79 | Layout.alignment: Qt.AlignLeft | ||
65 | Layout.preferredHeight: units.iconSizes.medium | 80 | Layout.preferredHeight: Uuid ? units.iconSizes.medium : units.iconSizes.smallMedium | ||
66 | Layout.preferredWidth: units.iconSizes.medium | 81 | Layout.preferredWidth: Layout.preferredHeight | ||
67 | elementId: ConnectionIcon | 82 | elementId: ConnectionIcon | ||
68 | svg: PlasmaCore.Svg { | 83 | svg: PlasmaCore.Svg { | ||
69 | multipleImages: true | 84 | multipleImages: true | ||
70 | imagePath: "icons/network" | 85 | imagePath: "icons/network" | ||
71 | colorGroup: PlasmaCore.ColorScope.colorGroup | 86 | colorGroup: PlasmaCore.ColorScope.colorGroup | ||
72 | } | 87 | } | ||
73 | } | 88 | } | ||
74 | 89 | | |||
75 | ColumnLayout { | 90 | ColumnLayout { | ||
76 | Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft | 91 | Layout.alignment: Qt.AlignLeft | ||
77 | spacing: 0 | 92 | spacing: 0 | ||
78 | 93 | | |||
79 | PlasmaComponents.Label { | 94 | PlasmaComponents.Label { | ||
95 | // TODO Fix bind loop messages for width. | ||||
80 | id: connectionNameLabel | 96 | id: connectionNameLabel | ||
81 | Layout.fillWidth: true | 97 | Layout.fillWidth: true | ||
82 | height: paintedHeight | | |||
83 | elide: Text.ElideRight | 98 | elide: Text.ElideRight | ||
84 | font.weight: ConnectionState == PlasmaNM.Enums.Activated ? Font.DemiBold : Font.Normal | 99 | font.weight: ConnectionState == PlasmaNM.Enums.Activated ? Font.DemiBold : Font.Normal | ||
85 | font.italic: ConnectionState == PlasmaNM.Enums.Activating ? true : false | 100 | font.italic: ConnectionState == PlasmaNM.Enums.Activating ? true : false | ||
86 | text: ItemUniqueName | 101 | text: capturePublicScreenshot ? "WIRELESS-12345" + index : ItemUniqueName // RESTORE before commit for final review | ||
87 | textFormat: Text.PlainText | 102 | textFormat: Text.PlainText | ||
88 | } | 103 | } | ||
89 | 104 | | |||
90 | PlasmaComponents.Label { | 105 | PlasmaComponents.Label { | ||
106 | // TODO Fix bind loop messages for width. | ||||
91 | id: connectionStatusLabel | 107 | id: connectionStatusLabel | ||
92 | Layout.fillWidth: true | 108 | Layout.fillWidth: true | ||
93 | height: paintedHeight | | |||
94 | elide: Text.ElideRight | 109 | elide: Text.ElideRight | ||
95 | font.pointSize: theme.smallestFont.pointSize | 110 | font.pointSize: theme.smallestFont.pointSize | ||
96 | opacity: 0.6 | 111 | opacity: 0.6 | ||
97 | text: itemText() | 112 | text: itemText() | ||
113 | visible: !!Uuid | ||||
98 | } | 114 | } | ||
99 | } | 115 | } | ||
100 | 116 | | |||
101 | PlasmaComponents.BusyIndicator { | 117 | PlasmaComponents.BusyIndicator { | ||
102 | id: connectingIndicator | 118 | id: connectingIndicator | ||
103 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight | | |||
104 | Layout.preferredHeight: units.iconSizes.medium | 119 | Layout.preferredHeight: units.iconSizes.medium | ||
105 | Layout.preferredWidth: units.iconSizes.medium | 120 | Layout.preferredWidth: Layout.preferredHeight | ||
106 | running: plasmoid.expanded && !stateChangeButton.visible && ConnectionState == PlasmaNM.Enums.Activating | 121 | running: plasmoid.expanded && !stateChangeButton.visible && ConnectionState == PlasmaNM.Enums.Activating | ||
107 | visible: running | 122 | visible: running | ||
108 | opacity: visible | 123 | opacity: visible | ||
109 | } | 124 | } | ||
110 | 125 | | |||
111 | PlasmaComponents.Button { | 126 | PlasmaComponents.Button { | ||
112 | id: stateChangeButton | 127 | id: stateChangeButton | ||
113 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight | | |||
114 | opacity: connectionView.currentVisibleButtonIndex == index ? 1 : 0 | 128 | opacity: connectionView.currentVisibleButtonIndex == index ? 1 : 0 | ||
115 | visible: opacity != 0 | 129 | visible: opacity != 0 | ||
116 | text: (ConnectionState == PlasmaNM.Enums.Deactivated) ? i18n("Connect") : i18n("Disconnect") | 130 | text: (ConnectionState == PlasmaNM.Enums.Deactivated) ? i18n("Connect") : i18n("Disconnect") | ||
117 | 131 | | |||
118 | Behavior on opacity { NumberAnimation { duration: units.shortDuration } } | 132 | Behavior on opacity { NumberAnimation { duration: units.shortDuration } } | ||
119 | 133 | | |||
120 | onClicked: changeState() | 134 | onClicked: changeState() | ||
121 | } | 135 | } | ||
122 | 136 | | |||
123 | MouseArea { | 137 | MouseArea { | ||
124 | acceptedButtons: Qt.RightButton | 138 | acceptedButtons: Qt.RightButton | ||
125 | Layout.alignment: Qt.AlignTop | Qt.AlignLeft | | |||
126 | width: parent.width | 139 | width: parent.width | ||
127 | height: parent.height | 140 | height: parent.height | ||
128 | onPressed: { | 141 | onPressed: { | ||
129 | contextMenu.visualParent = parent | 142 | contextMenu.visualParent = parent | ||
130 | contextMenu.prepare(); | 143 | contextMenu.prepare(); | ||
131 | contextMenu.open(mouse.x, mouse.y) | 144 | contextMenu.open(mouse.x, mouse.y) | ||
132 | } | 145 | } | ||
133 | } | 146 | } | ||
134 | } | 147 | } | ||
135 | 148 | | |||
136 | ColumnLayout { | | |||
137 | Layout.fillHeight: true | | |||
138 | PlasmaCore.SvgItem { | | |||
139 | id: separator | | |||
140 | height: lineSvg.elementSize("horizontal-line").height | | |||
141 | Layout.fillWidth: true | | |||
142 | Layout.maximumHeight: height | | |||
143 | elementId: "horizontal-line" | | |||
144 | svg: PlasmaCore.Svg { id: lineSvg; imagePath: "widgets/line" } | | |||
145 | visible: connectionItem.expanded | | |||
146 | opacity: visible | | |||
147 | } | | |||
148 | | ||||
149 | Loader { | 149 | Loader { | ||
150 | id: expandableComponentLoader | 150 | id: expandableComponentLoader | ||
151 | Layout.fillHeight: true | | |||
152 | Layout.fillWidth: true | 151 | Layout.fillWidth: true | ||
153 | height: childrenRect.height | | |||
154 | } | | |||
155 | } | 152 | } | ||
156 | } | 153 | } | ||
157 | 154 | | |||
158 | 155 | | |||
159 | PlasmaComponents.Menu { | 156 | PlasmaComponents.Menu { | ||
160 | id: contextMenu | 157 | id: contextMenu | ||
161 | 158 | | |||
162 | property Component showQRComponent: null | 159 | property Component showQRComponent: null | ||
Show All 40 Lines | 198 | PlasmaComponents.MenuItem { | |||
203 | icon: "settings-configure" | 200 | icon: "settings-configure" | ||
204 | onClicked: KCMShell.open([mainWindow.kcm, "--args", "Uuid=" + Uuid]) | 201 | onClicked: KCMShell.open([mainWindow.kcm, "--args", "Uuid=" + Uuid]) | ||
205 | } | 202 | } | ||
206 | } | 203 | } | ||
207 | 204 | | |||
208 | Component { | 205 | Component { | ||
209 | id: detailsComponent | 206 | id: detailsComponent | ||
210 | 207 | | |||
211 | Item { | 208 | Column { | ||
212 | height: childrenRect.height | 209 | spacing: units.smallSpacing | ||
213 | 210 | | |||
214 | PlasmaComponents.TabBar { | 211 | PlasmaComponents.TabBar { | ||
215 | id: detailsTabBar | 212 | id: detailsTabBar | ||
216 | 213 | | |||
217 | anchors { | 214 | anchors { | ||
218 | left: parent.left | 215 | left: parent.left | ||
219 | right: parent.right | 216 | right: parent.right | ||
220 | top: parent.top | | |||
221 | } | 217 | } | ||
222 | height: visible ? implicitHeight : 0 | 218 | height: visible ? implicitHeight : 0 | ||
223 | visible: showSpeed | 219 | visible: showSpeed | ||
224 | 220 | | |||
225 | PlasmaComponents.TabButton { | 221 | PlasmaComponents.TabButton { | ||
226 | id: speedTabButton | 222 | id: speedTabButton | ||
227 | text: i18n("Speed") | 223 | text: i18n("Speed") | ||
228 | } | 224 | } | ||
229 | 225 | | |||
230 | PlasmaComponents.TabButton { | 226 | PlasmaComponents.TabButton { | ||
231 | id: detailsTabButton | 227 | id: detailsTabButton | ||
232 | text: i18n("Details") | 228 | text: i18n("Details") | ||
233 | } | 229 | } | ||
234 | 230 | | |||
235 | Component.onCompleted: { | 231 | Component.onCompleted: { | ||
236 | if (!speedTabButton.visible) { | 232 | if (!speedTabButton.visible) { | ||
237 | currentTab = detailsTabButton | 233 | currentTab = detailsTabButton | ||
238 | } | 234 | } | ||
239 | } | 235 | } | ||
240 | } | 236 | } | ||
241 | 237 | | |||
242 | DetailsText { | 238 | DetailsText { | ||
243 | anchors { | 239 | anchors { | ||
244 | left: parent.left | 240 | left: parent.left | ||
245 | leftMargin: units.iconSizes.medium | 241 | leftMargin: units.iconSizes.smallMedium | ||
246 | right: parent.right | 242 | right: parent.right | ||
247 | top: detailsTabBar.visible ? detailsTabBar.bottom : parent.top | | |||
248 | topMargin: Math.round(units.gridUnit / 3) | | |||
249 | } | 243 | } | ||
250 | details: ConnectionDetails | 244 | details: ConnectionDetails | ||
251 | visible: detailsTabBar.currentTab == detailsTabButton | 245 | visible: detailsTabBar.currentTab == detailsTabButton | ||
252 | } | 246 | } | ||
253 | 247 | | |||
254 | TrafficMonitor { | 248 | TrafficMonitor { | ||
255 | anchors { | 249 | anchors { | ||
256 | left: parent.left | 250 | left: parent.left | ||
257 | right: parent.right | 251 | right: parent.right | ||
258 | top: detailsTabBar.visible ? detailsTabBar.bottom : parent.top | | |||
259 | topMargin: Math.round(units.gridUnit / 3) | | |||
260 | } | 252 | } | ||
261 | rxBytes: RxBytes | 253 | rxBytes: RxBytes | ||
262 | txBytes: TxBytes | 254 | txBytes: TxBytes | ||
263 | interval: 2000 | 255 | interval: 2000 | ||
264 | visible: detailsTabBar.currentTab == speedTabButton | 256 | visible: detailsTabBar.currentTab == speedTabButton | ||
265 | } | 257 | } | ||
266 | } | 258 | } | ||
267 | } | 259 | } | ||
268 | 260 | | |||
269 | Component { | 261 | Component { | ||
270 | id: passwordDialogComponent | 262 | id: passwordDialogComponent | ||
271 | 263 | | |||
272 | Item { | 264 | Column { | ||
273 | property alias password: passwordField.text | 265 | property alias password: passwordField.text | ||
274 | property alias passwordInput: passwordField | 266 | property alias passwordInput: passwordField | ||
275 | 267 | | |||
276 | height: childrenRect.height | | |||
277 | | ||||
278 | PasswordField { | 268 | PasswordField { | ||
279 | id: passwordField | 269 | id: passwordField | ||
280 | anchors { | 270 | | ||
281 | left: parent.left | 271 | height: implicitHeight - units.smallSpacing | ||
282 | right: parent.right | | |||
283 | top: parent.top | | |||
284 | } | | |||
285 | securityType: SecurityType | 272 | securityType: SecurityType | ||
286 | 273 | | |||
287 | onAccepted: { | 274 | onAccepted: { | ||
288 | stateChangeButton.clicked() | 275 | stateChangeButton.clicked() | ||
289 | } | 276 | } | ||
290 | 277 | | |||
291 | onAcceptableInputChanged: { | 278 | onAcceptableInputChanged: { | ||
292 | stateChangeButton.enabled = acceptableInput | 279 | stateChangeButton.enabled = acceptableInput | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 372 | if (Type == PlasmaNM.Enums.Vpn) | |||
386 | return VpnState | 373 | return VpnState | ||
387 | else | 374 | else | ||
388 | return DeviceState | 375 | return DeviceState | ||
389 | } else if (ConnectionState == PlasmaNM.Enums.Deactivating) { | 376 | } else if (ConnectionState == PlasmaNM.Enums.Deactivating) { | ||
390 | if (Type == PlasmaNM.Enums.Vpn) | 377 | if (Type == PlasmaNM.Enums.Vpn) | ||
391 | return VpnState | 378 | return VpnState | ||
392 | else | 379 | else | ||
393 | return DeviceState | 380 | return DeviceState | ||
394 | } else if (ConnectionState == PlasmaNM.Enums.Deactivated) { | 381 | } else if (Uuid && ConnectionState == PlasmaNM.Enums.Deactivated) { | ||
395 | var result = LastUsed | 382 | return LastUsed | ||
396 | if (SecurityType > PlasmaNM.Enums.NoneSecurity) | | |||
397 | result += ", " + SecurityTypeString | | |||
398 | return result | | |||
399 | } else if (ConnectionState == PlasmaNM.Enums.Activated) { | 383 | } else if (ConnectionState == PlasmaNM.Enums.Activated) { | ||
400 | if (showSpeed) { | 384 | if (showSpeed) { | ||
401 | var downloadColor = theme.highlightColor | 385 | var downloadColor = theme.highlightColor | ||
402 | // cycle upload color by 180 degrees | 386 | // cycle upload color by 180 degrees | ||
403 | var uploadColor = Qt.hsva((downloadColor.hsvHue + 0.5) % 1, downloadColor.hsvSaturation, downloadColor.hsvValue, downloadColor.a) | 387 | var uploadColor = Qt.hsva((downloadColor.hsvHue + 0.5) % 1, downloadColor.hsvSaturation, downloadColor.hsvValue, downloadColor.a) | ||
404 | 388 | | |||
405 | return i18n("Connected, <font color='%1'>⬇</font> %2/s, <font color='%3'>⬆</font> %4/s", | 389 | return i18n("Connected, <font color='%1'>⬇</font> %2/s, <font color='%3'>⬆</font> %4/s", | ||
406 | downloadColor, | 390 | downloadColor, | ||
407 | KCoreAddons.Format.formatByteSize(rxBytes), | 391 | KCoreAddons.Format.formatByteSize(rxBytes), | ||
408 | uploadColor, | 392 | uploadColor, | ||
409 | KCoreAddons.Format.formatByteSize(txBytes)) | 393 | KCoreAddons.Format.formatByteSize(txBytes)) | ||
410 | } else { | 394 | } else { | ||
411 | return i18n("Connected") | 395 | return i18n("Connected") | ||
412 | } | 396 | } | ||
413 | } | 397 | } | ||
398 | return "" | ||||
414 | } | 399 | } | ||
415 | 400 | | |||
416 | onShowSpeedChanged: { | 401 | onShowSpeedChanged: { | ||
417 | connectionModel.setDeviceStatisticsRefreshRateMs(DevicePath, showSpeed ? 2000 : 0) | 402 | connectionModel.setDeviceStatisticsRefreshRateMs(DevicePath, showSpeed ? 2000 : 0) | ||
418 | } | 403 | } | ||
419 | 404 | | |||
420 | onActivatingChanged: { | 405 | onActivatingChanged: { | ||
421 | if (ConnectionState == PlasmaNM.Enums.Activating) { | 406 | if (ConnectionState == PlasmaNM.Enums.Activating) { | ||
Show All 16 Lines | 411 | onClicked: { | |||
438 | } | 423 | } | ||
439 | } | 424 | } | ||
440 | 425 | | |||
441 | onContainsMouseChanged: { | 426 | onContainsMouseChanged: { | ||
442 | if (connectionItem.containsMouse) { | 427 | if (connectionItem.containsMouse) { | ||
443 | connectionView.currentVisibleButtonIndex = index | 428 | connectionView.currentVisibleButtonIndex = index | ||
444 | } | 429 | } | ||
445 | } | 430 | } | ||
431 | | ||||
432 | onDeactivatedChanged: { | ||||
433 | // Separator is part of section. Which only shows when available connections exist. | ||||
434 | // Only need to determine if there is a connection in use, there are always on top, checking first one is enough. | ||||
435 | if (appletProxyModel.data(appletProxyModel.index(0, 0), PlasmaNM.NetworkModel.SectionRole) !== "Available connections") { | ||||
436 | if (connectionView.showSeparator != true) { | ||||
437 | connectionView.showSeparator = true | ||||
438 | } | ||||
439 | return | ||||
440 | } | ||||
441 | connectionView.showSeparator = false | ||||
442 | return | ||||
443 | } | ||||
446 | } | 444 | } |