| 1 | import QtQuick |
| 2 | import QtQuick.Layouts |
| 3 | |
| 4 | ColumnLayout { |
| 5 | id: page |
| 6 | property bool active: false |
| 7 | onActiveChanged: Net.active = active |
| 8 | spacing: 8 |
| 9 | |
| 10 | RowLayout { |
| 11 | Layout.fillWidth: true |
| 12 | spacing: 6 |
| 13 | Text { |
| 14 | Layout.fillWidth: true |
| 15 | elide: Text.ElideRight |
| 16 | text: !Net.wifiEnabled ? "wi-fi is off" |
| 17 | : (Net.connected !== "" ? "connected · " + Net.connected : "not connected") |
| 18 | color: Net.connected !== "" && Net.wifiEnabled ? Theme.accent : Theme.dim |
| 19 | font.family: Theme.font |
| 20 | font.pixelSize: Theme.fontSize |
| 21 | } |
| 22 | IconBtn { |
| 23 | icon: Theme.iRefresh |
| 24 | active: Net.scanning |
| 25 | onClicked: Net.rescan() |
| 26 | } |
| 27 | IconBtn { |
| 28 | icon: Net.wifiEnabled ? Theme.iWifi : Theme.iWifiOff |
| 29 | active: Net.wifiEnabled |
| 30 | onClicked: Net.setWifi(!Net.wifiEnabled) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | Text { |
| 35 | visible: Net.message !== "" |
| 36 | Layout.fillWidth: true |
| 37 | text: Net.message |
| 38 | wrapMode: Text.WordWrap |
| 39 | color: Theme.err |
| 40 | font.family: Theme.font |
| 41 | font.pixelSize: Theme.fontSize - 2 |
| 42 | } |
| 43 | |
| 44 | SectionLabel { text: Net.busy ? "working…" : "networks" } |
| 45 | |
| 46 | Flickable { |
| 47 | id: flick |
| 48 | Layout.fillWidth: true |
| 49 | Layout.fillHeight: true |
| 50 | clip: true |
| 51 | contentWidth: width |
| 52 | contentHeight: list.implicitHeight |
| 53 | boundsBehavior: Flickable.StopAtBounds |
| 54 | |
| 55 | ColumnLayout { |
| 56 | id: list |
| 57 | width: flick.width |
| 58 | spacing: 2 |
| 59 | |
| 60 | Repeater { |
| 61 | model: Net.wifiEnabled ? Net.networks : [] |
| 62 | delegate: ColumnLayout { |
| 63 | id: item |
| 64 | required property var modelData |
| 65 | Layout.fillWidth: true |
| 66 | spacing: 0 |
| 67 | |
| 68 | ListRow { |
| 69 | icon: Theme.wifiIcon(item.modelData.signal) |
| 70 | title: item.modelData.ssid |
| 71 | subtitle: item.modelData.inUse ? "connected" |
| 72 | : (item.modelData.saved ? "saved" |
| 73 | : (item.modelData.security === "" ? "open" : item.modelData.security)) |
| 74 | trailing: item.modelData.signal + "%" |
| 75 | current: item.modelData.inUse |
| 76 | onClicked: Net.connectTo(item.modelData) |
| 77 | |
| 78 | IconBtn { |
| 79 | visible: item.modelData.inUse |
| 80 | icon: Theme.iClose |
| 81 | height: 26 |
| 82 | onClicked: Net.disconnect() |
| 83 | } |
| 84 | IconBtn { |
| 85 | visible: item.modelData.saved |
| 86 | icon: Theme.iTrash |
| 87 | height: 26 |
| 88 | onClicked: Net.forget(item.modelData.ssid) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | Rectangle { |
| 93 | id: pwBox |
| 94 | visible: Net.askFor === item.modelData.ssid |
| 95 | Layout.fillWidth: true |
| 96 | Layout.preferredHeight: visible ? 34 : 0 |
| 97 | color: Theme.surface |
| 98 | border.width: 1 |
| 99 | border.color: Theme.accent |
| 100 | onVisibleChanged: if (visible) { pw.text = ""; pw.forceActiveFocus() } |
| 101 | |
| 102 | RowLayout { |
| 103 | anchors.fill: parent |
| 104 | anchors.leftMargin: 10 |
| 105 | anchors.rightMargin: 4 |
| 106 | TextInput { |
| 107 | id: pw |
| 108 | Layout.fillWidth: true |
| 109 | Layout.alignment: Qt.AlignVCenter |
| 110 | echoMode: TextInput.Password |
| 111 | color: Theme.fg |
| 112 | selectionColor: Theme.accent |
| 113 | selectedTextColor: Theme.bg |
| 114 | font.family: Theme.font |
| 115 | font.pixelSize: Theme.fontSize |
| 116 | clip: true |
| 117 | onAccepted: Net.connect(item.modelData.ssid, text) |
| 118 | Text { |
| 119 | visible: !pw.text |
| 120 | text: "password…" |
| 121 | color: Theme.dim |
| 122 | font: pw.font |
| 123 | } |
| 124 | } |
| 125 | IconBtn { |
| 126 | icon: Theme.iCheck |
| 127 | height: 26 |
| 128 | onClicked: Net.connect(item.modelData.ssid, pw.text) |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |