| 1 | import QtQuick |
| 2 | import QtQuick.Layouts |
| 3 | |
| 4 | ColumnLayout { |
| 5 | id: page |
| 6 | property bool active: false |
| 7 | onActiveChanged: Net.active = active |
| 8 | // the settings app creates this page already active and destroys it when leaving the section |
| 9 | Component.onCompleted: if (active) Net.active = true |
| 10 | Component.onDestruction: if (active) Net.active = false |
| 11 | spacing: 8 |
| 12 | |
| 13 | // wired / usb tethering (read-only status, plus a disconnect button) |
| 14 | ColumnLayout { |
| 15 | visible: Net.wiredDevs.length > 0 |
| 16 | Layout.fillWidth: true |
| 17 | spacing: 2 |
| 18 | SectionLabel { text: "wired" } |
| 19 | Repeater { |
| 20 | model: Net.wiredDevs |
| 21 | delegate: ListRow { |
| 22 | required property var modelData |
| 23 | icon: modelData.usb ? Theme.iPhone : Theme.iEthernet |
| 24 | title: modelData.name |
| 25 | subtitle: Net.portal && Net.portalNet === modelData.name ? "sign in required" |
| 26 | : modelData.dev + (modelData.ip !== "" ? " · " + modelData.ip : "") |
| 27 | trailing: modelData.usb ? "usb" : "" |
| 28 | current: true |
| 29 | IconBtn { |
| 30 | visible: Net.portal && Net.portalNet === modelData.name |
| 31 | icon: Theme.iLogin |
| 32 | height: 26 |
| 33 | onClicked: Net.openPortal() |
| 34 | } |
| 35 | IconBtn { |
| 36 | icon: Theme.iClose |
| 37 | height: 26 |
| 38 | onClicked: Net.disconnectDev(modelData.dev) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | RowLayout { |
| 45 | Layout.fillWidth: true |
| 46 | spacing: 6 |
| 47 | Text { |
| 48 | Layout.fillWidth: true |
| 49 | elide: Text.ElideRight |
| 50 | text: !Net.wifiEnabled ? "wi-fi off" |
| 51 | : (Net.connected !== "" ? "wi-fi · " + Net.connected : "wi-fi not connected") |
| 52 | color: Net.connected !== "" && Net.wifiEnabled ? Theme.accent : Theme.dim |
| 53 | font.family: Theme.font |
| 54 | font.pixelSize: Theme.fontSize |
| 55 | } |
| 56 | IconBtn { |
| 57 | icon: Theme.iRefresh |
| 58 | active: Net.scanning |
| 59 | onClicked: Net.rescan() |
| 60 | } |
| 61 | IconBtn { |
| 62 | icon: Net.wifiEnabled ? Theme.iWifi : Theme.iWifiOff |
| 63 | active: Net.wifiEnabled |
| 64 | onClicked: Net.setWifi(!Net.wifiEnabled) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | Text { |
| 69 | visible: Net.message !== "" |
| 70 | Layout.fillWidth: true |
| 71 | text: Net.message |
| 72 | wrapMode: Text.WordWrap |
| 73 | color: Theme.err |
| 74 | font.family: Theme.font |
| 75 | font.pixelSize: Theme.fontSize - 2 |
| 76 | } |
| 77 | |
| 78 | SectionLabel { text: Net.busy ? "working…" : "networks" } |
| 79 | |
| 80 | Flickable { |
| 81 | id: flick |
| 82 | Layout.fillWidth: true |
| 83 | Layout.fillHeight: true |
| 84 | clip: true |
| 85 | contentWidth: width |
| 86 | contentHeight: list.implicitHeight |
| 87 | boundsBehavior: Flickable.StopAtBounds |
| 88 | |
| 89 | ColumnLayout { |
| 90 | id: list |
| 91 | width: flick.width |
| 92 | spacing: 2 |
| 93 | |
| 94 | Repeater { |
| 95 | model: Net.wifiEnabled ? Net.networks : [] |
| 96 | delegate: ColumnLayout { |
| 97 | id: item |
| 98 | required property var modelData |
| 99 | Layout.fillWidth: true |
| 100 | spacing: 0 |
| 101 | |
| 102 | ListRow { |
| 103 | id: row |
| 104 | icon: Theme.wifiIcon(item.modelData.signal) |
| 105 | title: item.modelData.ssid |
| 106 | readonly property bool portal: item.modelData.inUse && Net.portal && Net.portalNet === item.modelData.ssid |
| 107 | subtitle: portal ? "sign in required" |
| 108 | : item.modelData.inUse ? "connected" |
| 109 | : (item.modelData.saved ? "saved" |
| 110 | : (item.modelData.security === "" ? "open" : item.modelData.security)) |
| 111 | trailing: item.modelData.signal + "%" |
| 112 | current: item.modelData.inUse |
| 113 | onClicked: Net.connectTo(item.modelData) |
| 114 | |
| 115 | IconBtn { |
| 116 | visible: row.portal |
| 117 | icon: Theme.iLogin |
| 118 | height: 26 |
| 119 | onClicked: Net.openPortal() |
| 120 | } |
| 121 | IconBtn { |
| 122 | visible: item.modelData.inUse |
| 123 | icon: Theme.iClose |
| 124 | height: 26 |
| 125 | onClicked: Net.disconnect() |
| 126 | } |
| 127 | IconBtn { |
| 128 | visible: item.modelData.saved |
| 129 | icon: Theme.iTrash |
| 130 | height: 26 |
| 131 | onClicked: Net.forget(item.modelData.ssid) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | Rectangle { |
| 136 | id: pwBox |
| 137 | visible: Net.askFor === item.modelData.ssid |
| 138 | Layout.fillWidth: true |
| 139 | Layout.preferredHeight: visible ? 34 : 0 |
| 140 | color: Theme.surface |
| 141 | border.width: 1 |
| 142 | border.color: Theme.accent |
| 143 | onVisibleChanged: if (visible) { pw.text = ""; pw.forceActiveFocus() } |
| 144 | |
| 145 | RowLayout { |
| 146 | anchors.fill: parent |
| 147 | anchors.leftMargin: 10 |
| 148 | anchors.rightMargin: 4 |
| 149 | TextInput { |
| 150 | id: pw |
| 151 | Layout.fillWidth: true |
| 152 | Layout.alignment: Qt.AlignVCenter |
| 153 | echoMode: TextInput.Password |
| 154 | color: Theme.fg |
| 155 | selectionColor: Theme.accent |
| 156 | selectedTextColor: Theme.bg |
| 157 | font.family: Theme.font |
| 158 | font.pixelSize: Theme.fontSize |
| 159 | clip: true |
| 160 | onAccepted: Net.connect(item.modelData.ssid, text) |
| 161 | Text { |
| 162 | visible: !pw.text |
| 163 | text: "password…" |
| 164 | color: Theme.dim |
| 165 | font: pw.font |
| 166 | } |
| 167 | } |
| 168 | IconBtn { |
| 169 | icon: Theme.iCheck |
| 170 | height: 26 |
| 171 | onClicked: Net.connect(item.modelData.ssid, pw.text) |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |