diff options
Diffstat (limited to 'app/wifi')
-rw-r--r-- | app/wifi/Wifi.qml | 308 |
1 files changed, 111 insertions, 197 deletions
diff --git a/app/wifi/Wifi.qml b/app/wifi/Wifi.qml index f5fdae1..dcde6ed 100644 --- a/app/wifi/Wifi.qml +++ b/app/wifi/Wifi.qml @@ -17,6 +17,7 @@ import QtQuick 2.6 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.0 +import AGL.Demo.Controls 1.0 import '..' SettingPage { @@ -25,21 +26,7 @@ SettingPage { title: 'Wifi' checkable: true - property string protocol: 'http://' - property string ipAddress: '127.0.0.1' - property string portNumber: Qt.application.arguments[1] - property string tokenString: Qt.application.arguments[2] - property string wifiAPI: '/api/wifi-manager/' - property string wifiAPIpath: protocol + ipAddress + ':' + portNumber + wifiAPI - - Text { - id: log - anchors.fill: parent - anchors.margins: 10 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - //text: "log" - } + property string wifiAPIpath: bindingAddress + '/wifi-manager/' onCheckedChanged: { console.log("Wifi set to", checked) @@ -88,214 +75,89 @@ SettingPage { Component { id: wifiDevice - Rectangle { + MouseArea { height: 120 - width: parent.width - color: "transparent" + width: ListView.view.width Image { - anchors.left: parent.left - anchors.leftMargin: 80 //width: 70 //height: 50 id: icon source: { + var svg + if (strength < 30) + svg = "1Bar" + else if (strength < 50) + svg = "2Bars" + else if (strength < 70) + svg = "3Bars" + else + svg = "Full" if (securityType(security) === "unsecured") { - if (strength < 30) - source = "images/HMI_Settings_Wifi_1Bar.svg" - else if (strength >= 30 && strength < 50) - source = "images/HMI_Settings_Wifi_2Bars.svg" - else if (strength >= 50 && strength < 70) - source = "images/HMI_Settings_Wifi_3Bars.svg" - else - source = "images/HMI_Settings_Wifi_Full.svg" + return 'images/HMI_Settings_Wifi_%1.svg'.arg(svg) } else { - if (strength < 30) - source = "images/HMI_Settings_Wifi_Locked_1Bar.svg" - else if (strength >= 30 && strength < 50) - source = "images/HMI_Settings_Wifi_Locked_2Bars.svg" - else if (strength >= 50 && strength < 70) - source = "images/HMI_Settings_Wifi_Locked_3Bars.svg" - else - source = "images/HMI_Settings_Wifi_Locked_Full.svg" + return 'images/HMI_Settings_Wifi_Locked_%1.svg'.arg(svg) } } } Column { anchors.left: icon.right anchors.leftMargin: 5 - Text { + Label { id: networkNameText text: name color: '#66FF99' font.pixelSize: 48 - font.bold: { - if ((serviceState === "ready") - || serviceState === "online") - font.bold = true - else - font.bold = false - } + font.bold: serviceState === "ready" || serviceState === "online" } - Text { - visible: ((serviceState === "ready") - || serviceState === "online") ? true : false + Label { + visible: serviceState === "ready" || serviceState === "online" text: "connected, " + address font.pointSize: 18 color: "white" //font.italic: true } } - Button { - id: connectButton - anchors.top: parent.top - anchors.topMargin: 5 - //anchors.horizontalCenter: networkNameText.horizontalCenter - anchors.rightMargin: 50 - anchors.right: parent.right - width: 250 - - MouseArea { - anchors.fill: parent - - Text { - anchors.fill: parent - id: buttonTextLabel - font.pixelSize: 15 - font.bold: true - color: "black" - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - text: { - if ((serviceState === "ready") - || serviceState === "online") - text = "Forget" - else - text = "Connect" - } - } - - onClicked: { - - //connectButton.border.color = "steelblue" - if ((serviceState === "ready") - || serviceState === "online") { - - //means we are connected - console.log("Disconnecting from", index, " ,", name) - request(wifiAPIpath + 'disconnect?network=' + index, - function (o) { - - //showRequestInfo(o.responseText) - console.log(o.responseText) - }) - } else { - console.log("Conect to", index, " ,", name) - - //passwordDialog.open() - request(wifiAPIpath + 'connect?network=' + index, - function (o) { - - // log the json response - //showRequestInfo(o.responseText) - console.log(o.responseText) - }) - } - } - } - } - - Button { - id: passwordButton - anchors.top: parent.top - anchors.topMargin: 5 - anchors.right: connectButton.right - width: 40 - visible: (securityType(security) === "unsecured") ? false : true - - text: { - "Key" - } - - MouseArea { - anchors.fill: parent - onClicked: { - - //connectButton.border.color = "steelblue" - passwordInputText.visible = true - connectButton.visible = false - passwordValidateButton.visible = true - - //passwordInputText.o - periodicRefresh.stop() - - var passkey = passwordInputText.text.valueOf() - - //var passkey = 'randompassword' - console.log("Disconnecting from", index, " ,", name) - } - } - } - - Button { - id: passwordValidateButton - anchors.top: parent.top - anchors.topMargin: 5 - anchors.right: parent.right - anchors.rightMargin: connectButton.width + 5 - width: 40 - visible: false - - //anchors.rightMargin: connectButton.width + 5 - //buttonText: "Connect" - text: { - "ok" //or some icon? - } - - MouseArea { - anchors.fill: parent - - onClicked: { - //passwordInputText = "" - var passkey = passwordInputText.text.valueOf() - console.log("Validating", passkey) - - console.log("Passkey is", passkey) - request(wifiAPIpath + 'security?passkey=' + passkey, + onClicked: { + //connectButton.border.color = "steelblue" + if ((serviceState === "ready") + || serviceState === "online") { + + //means we are connected + console.log("Disconnecting from", index, " ,", name) + request(wifiAPIpath + 'disconnect?network=' + index, + function (o) { + + //showRequestInfo(o.responseText) + console.log(o.responseText) + }) + } else { + console.log("Conect to", index, " ,", name) + view.currentIndex = model.index + if (securityType(security) === "unsecured") { + request(wifiAPIpath + 'connect?network=' + view.currentIndex, function (o) { + // log the json response //showRequestInfo(o.responseText) console.log(o.responseText) }) - passwordValidateButton.visible = false - passwordInputText.visible = false - connectButton.visible = true - - periodicRefresh.start() + } else { + dialog.visible = true } } } - TextInput { - id: passwordInputText - anchors.top: parent.top - anchors.topMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 0 - readOnly: false - //horizontalAlignment: TextInput.AlignHCenter - //verticalAlignment: TextInput.AlignVCenter - +// ImageButton { +// anchors.verticalCenter: parent.verticalCenter +// anchors.right: parent.right +// offImage: '../images/HMI_Settings_X.svg' +// onClicked: { - font.pointSize: 15 - color: "#ffffff" +// } +// } - width: connectButton.width - visible: false - text: "password" - /*hardcore until virtual keyboard works*/ - } Image { source: '../images/HMI_Settings_DividingLine.svg' @@ -305,27 +167,80 @@ SettingPage { visible: model.index > 0 } - } - - } + ListView { - width: parent.width - anchors.top: parent.top - anchors.topMargin: 70 - anchors.bottom: parent.bottom - anchors.bottomMargin: 150 + id: view + anchors.fill: parent + anchors.margins: 100 model: networkList //WifiList {} delegate: wifiDevice clip: true } + MouseArea { + id: dialog + anchors.fill: parent + visible: false + z: 1 + onVisibleChanged: if (visible) password.forceActiveFocus() + ColumnLayout { + anchors.fill: parent + Item { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 1 + Rectangle { + anchors.fill: parent + color: 'black' + opacity: 0.5 + } + RowLayout { + anchors.centerIn: parent + TextField { + id: password + placeholderText: 'Password' + } + Button { + text: 'Connect' + highlighted: true + onClicked: { + var passkey = password.text + console.log("Validating", passkey) + + console.log("Passkey is", passkey) + request(wifiAPIpath + 'security?passkey=' + passkey, + function (o) { + + //showRequestInfo(o.responseText) + console.log(o.responseText) + }) + dialog.visible = false + } + } + Button { + text: 'Cancel' + onClicked: dialog.visible = false + } + } + } + + Keyboard { + id: keyboard + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 1 + target: activeFocusControl + } + } + } //Timer for periodic refresh; this is BAD solution, need to figure out how to subscribe for events Timer { id: periodicRefresh - interval: 5000 // 5seconds + interval: 1000 // 1second + running: !dialog.visible onTriggered: { networkList.clear() @@ -334,9 +249,8 @@ SettingPage { console.log(o.responseText) // translate response into object - var jsonObject = eval('(' + o.responseText + ')') - var jsonObjectNetworks = eval('(' + JSON.stringify( - jsonObject.response) + ')') + var jsonObject = JSON.parse(o.responseText) + var jsonObjectNetworks = jsonObject.response console.log("WiFi list refreshed") //console.log(jsonObject.response) for (var i = 0; i < jsonObjectNetworks.length; i++) { |