repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nuguland/ConnectivityPanel.qml
Rawpragma ComponentBehavior: Bound
import QtQuick
import "Util.js" as Util
import "sysinfo.js" as Sys
Column {
id: root
required property Theme theme
required property Resources resourceService
required property Network networkService
required property Bluetooth bluetoothService
property var networkState: networkService ? Util.parseJson(networkService.stateJson(), {
"networks": [],
"knownNetworks": [],
"wifi": {},
"compact": {}
}) : ({
"networks": [],
"knownNetworks": [],
"wifi": {},
"compact": {}
})
property var bluetoothState: bluetoothService ? Util.parseJson(bluetoothService.stateJson(), {
"devices": [],
"adapter": {}
}) : ({
"devices": [],
"adapter": {}
})
// ssid whose inline passphrase field is currently revealed ("" = none).
// Holds only an ssid (not a secret); the passphrase lives solely in the
// TextInput.text and is cleared on submit, never bound into networkState.
property string expandedSsid: ""
function refreshNetwork(text) {
networkState = Util.parseJson(text, networkState);
}
function refreshBluetooth(text) {
bluetoothState = Util.parseJson(text, bluetoothState);
}
function formatRate(value) {
return Sys.formatRate(value);
}
function toggleWifi() {
if (networkService)
refreshNetwork(networkService.toggleWifi(!(networkState.wifi && networkState.wifi.enabled)));
}
function scanWifi() {
if (networkService)
refreshNetwork(networkService.scan());
}
function selectNetwork(id) {
if (networkService)
refreshNetwork(networkService.select(id));
}
function forgetNetwork(id) {
if (networkService)
refreshNetwork(networkService.forget(id));
}
// Secured-connect for a new network: connect(ssid, passphrase) is the
// in-process entry (NOT an IPC handler). The passphrase is a transient
// argument only — never stored on root / networkState / any logged field.
function connectSecured(ssid, passphrase) {
if (networkService)
refreshNetwork(networkService.connect(ssid, passphrase));
}
function disconnectNetwork() {
if (networkService)
refreshNetwork(networkService.disconnect());
}
// Toggle a row's detail drawer. Opening the CONNECTED row triggers a
// lazy StationDiagnostic read (bssid/band/rate) that fills in async.
function expandRow(row) {
const willOpen = expandedSsid !== row.ssid;
expandedSsid = willOpen ? row.ssid : "";
if (willOpen && row.connected && networkService)
refreshNetwork(networkService.diagnostics());
}
function toggleBluetooth() {
if (bluetoothService)
refreshBluetooth(bluetoothService.toggle(!(bluetoothState.adapter && bluetoothState.adapter.state === "powered")));
}
function scanBluetooth() {
if (bluetoothService)
refreshBluetooth(bluetoothService.scan());
}
function bluetoothAction(kind, id) {
if (bluetoothService)
refreshBluetooth(bluetoothService.deviceAction(kind, id));
}
function bluetoothDeviceIcon(type) {
const t = String(type || "");
if (t.indexOf("gaming") >= 0)
return "\uF11B";
if (t.indexOf("headset") >= 0 || t.indexOf("headphone") >= 0)
return "\uF025";
if (t.indexOf("card") >= 0 || t.indexOf("speaker") >= 0 || t.indexOf("audio") >= 0)
return "\uF028";
if (t.indexOf("keyboard") >= 0)
return "\uF11C";
return "\uF293";
}
function bluetoothBatteryLabel(device) {
return device && device.battery >= 0 ? "\uF240 " + device.battery + "%" : "";
}
function roleColor(role) {
if (!theme)
return "white";
if (role === "warning")
return theme.warning;
if (role === "error")
return theme.error;
if (role === "ui.minor")
return theme.ui.minor;
if (role === "content.accent")
return theme.content.accent;
return theme.ui.accent;
}
spacing: 10
width: parent ? parent.width : 0
// Async reads (scan retries, post-action refresh) update the service
// model and emit refreshed(); re-pull stateJson so the scan spinner
// clears and new/connected rows land without a user action.
Connections {
target: root.networkService
function onRefreshed() {
if (root.networkService)
root.refreshNetwork(root.networkService.stateJson());
}
}
// One scroll pane for the whole panel: a long Wi-Fi scan + the
// Bluetooth list scroll together, and an expanded row's detail drawer
// grows inside it without clipping. Idle (no overflow) => not interactive.
Flickable {
width: parent.width
height: root.height
contentWidth: width
contentHeight: panelCol.height
clip: true
interactive: contentHeight > height
boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.VerticalFlick
Column {
id: panelCol
width: parent.width
spacing: 10
Row {
objectName: "networkRateRow"
width: parent.width
spacing: 8
NuguText {
theme: root.theme
text: root.resourceService ? `↓ ${root.formatRate(root.resourceService.networkRxRate)}` : "↓ 0 B/s"
color: root.theme ? root.theme.ui.accent : "white"
}
NuguText {
theme: root.theme
text: root.resourceService ? `↑ ${root.formatRate(root.resourceService.networkTxRate)}` : "↑ 0 B/s"
color: root.theme ? root.theme.ui.focus : "white"
}
}
Column {
objectName: "wifiToggleScanList"
width: parent.width
spacing: 6
Row {
width: parent.width
spacing: 6
NuguText {
theme: root.theme
variant: "title"
text: "wireless"
width: parent.width - 132
}
Rectangle {
width: 58
height: 26
radius: 9
color: root.theme ? root.theme.withAlpha(root.networkState.wifi && root.networkState.wifi.enabled ? root.theme.ui.focus : root.theme.ui.minor, 0.22) : "transparent"
border.width: 0
border.color: root.roleColor(root.networkState.compact ? root.networkState.compact.role : "ui.minor")
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: root.networkState.wifi && root.networkState.wifi.enabled ? "on" : "off"
}
MouseArea {
anchors.fill: parent
onClicked: root.toggleWifi()
}
}
Rectangle {
width: 58
height: 26
radius: 9
color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, root.networkState.scanning ? 0.32 : 0.16) : "transparent"
border.width: 0
border.color: root.theme ? root.theme.ui.accent : "transparent"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: root.networkState.scanning ? "scan…" : "scan"
}
MouseArea {
anchors.fill: parent
onClicked: root.scanWifi()
}
}
}
Column {
width: parent.width
spacing: 6
Repeater {
model: root.networkState.networks || []
delegate: Column {
id: wifiRow
required property var modelData
readonly property bool active: modelData.connected === true
readonly property bool revealed: root.expandedSsid === modelData.ssid
readonly property var detail: root.networkState.connectionDetail || ({})
width: parent.width
spacing: 4
// --- washout-fixed card: solid dark base, identity via thin
// accent bar + border; whole card taps to open its drawer.
Rectangle {
width: parent.width
height: 40
radius: 12
color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, wifiRow.active ? 0.82 : 0.55) : "#333333"
border.width: (wifiRow.active || wifiRow.revealed) ? 2 : 1
border.color: root.theme ? (wifiRow.active ? root.theme.ui.accent : (wifiRow.modelData.state === "connecting" ? root.roleColor("warning") : (wifiRow.revealed ? root.theme.withAlpha(root.theme.ui.accent, 0.6) : root.theme.withAlpha(root.theme.ui.minor, 0.45)))) : "white"
// left accent bar — only on the connected network
Rectangle {
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.margins: 2
width: 3
radius: 2
color: root.theme ? root.theme.ui.accent : "transparent"
opacity: wifiRow.active ? 1 : 0
}
Text {
id: wifiGlyph
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 18
text: wifiRow.modelData.signalGlyph || ""
color: root.roleColor(wifiRow.modelData.signalRole || "ui.minor")
}
// chevron hints the row expands; rotates when open
Text {
id: wifiChevron
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 16
text: ""
rotation: wifiRow.revealed ? 90 : 0
color: root.roleColor(wifiRow.active ? "content.accent" : "ui.minor")
}
NuguText {
id: wifiLabel
anchors.right: wifiChevron.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
variant: "meta"
text: wifiRow.active ? "connected" : (wifiRow.modelData.securityLabel || "")
color: root.roleColor(wifiRow.active ? "content.accent" : "ui.minor")
}
NuguText {
anchors.left: wifiGlyph.right
anchors.leftMargin: 10
anchors.right: wifiLabel.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
text: wifiRow.modelData.ssid
elide: Text.ElideRight
}
MouseArea {
anchors.fill: parent
onClicked: root.expandRow(wifiRow.modelData)
}
}
// --- detail + actions drawer (revealed on tap) -----------
Rectangle {
id: wifiDrawer
visible: wifiRow.revealed
width: parent.width
height: visible ? drawerCol.height + 16 : 0
radius: 10
color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.55) : "#333333"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.4) : "white"
clip: true
Column {
id: drawerCol
x: 12
y: 8
width: parent.width - 24
spacing: 6
// signal + security — available for every row
NuguText {
theme: root.theme
variant: "meta"
text: {
const dbm = wifiRow.modelData.signalDbm;
const sig = (dbm === null || dbm === undefined) ? `${wifiRow.modelData.signal}/4 bars` : `${dbm} dBm`;
return `${wifiRow.modelData.securityLabel || "Open"} · ${sig}`;
}
color: root.theme ? root.theme.content.normal : "white"
}
// connected-only BSS detail (StationDiagnostic)
Column {
visible: wifiRow.active && !!wifiRow.detail.bssid
width: parent.width
spacing: 2
NuguText {
theme: root.theme
variant: "meta"
text: `${wifiRow.detail.band || "?"}${wifiRow.detail.channel ? " · ch " + wifiRow.detail.channel : ""}${wifiRow.detail.mode ? " · " + wifiRow.detail.mode : ""}`
opacity: 0.8
}
NuguText {
theme: root.theme
variant: "meta"
visible: !!wifiRow.detail.rxRate || !!wifiRow.detail.txRate
text: `↓ ${wifiRow.detail.rxRate || "?"} ↑ ${wifiRow.detail.txRate || "?"}`
opacity: 0.8
}
NuguText {
theme: root.theme
variant: "meta"
text: wifiRow.detail.bssid
opacity: 0.6
}
}
// action pills — hidden when a passphrase is needed
Row {
visible: !wifiRow.modelData.needsPassphrase
spacing: 8
Rectangle {
visible: !wifiRow.active
width: 96
height: 28
radius: 9
color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.18) : "transparent"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.7) : "white"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: "connect"
}
MouseArea {
anchors.fill: parent
onClicked: {
root.expandedSsid = "";
root.selectNetwork(wifiRow.modelData.id);
}
}
}
Rectangle {
visible: wifiRow.active
width: 96
height: 28
radius: 9
color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.18) : "transparent"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.7) : "white"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: "disconnect"
}
MouseArea {
anchors.fill: parent
onClicked: {
root.expandedSsid = "";
root.disconnectNetwork();
}
}
}
Rectangle {
visible: wifiRow.active || wifiRow.modelData.known
width: 96
height: 28
radius: 9
color: root.theme ? root.theme.withAlpha(root.theme.error, 0.18) : "transparent"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.error, 0.7) : "white"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: "forget"
}
MouseArea {
anchors.fill: parent
onClicked: {
root.expandedSsid = "";
root.forgetNetwork(wifiRow.modelData.id);
}
}
}
}
// --- inline passphrase entry for a NEW secured network.
// echoMode Password; text lives only here, cleared on
// submit, never bound into networkState / any logged field.
Rectangle {
id: wifiPpRow
function submit() {
root.connectSecured(wifiRow.modelData.ssid, wifiPp.text);
wifiPp.text = "";
root.expandedSsid = "";
}
visible: wifiRow.modelData.needsPassphrase
width: parent.width
height: visible ? 34 : 0
radius: 10
color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.7) : "#333333"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.6) : "white"
onVisibleChanged: {
if (visible && wifiRow.revealed)
Qt.callLater(function () {
wifiPp.forceActiveFocus();
});
}
TextInput {
id: wifiPp
anchors.left: parent.left
anchors.leftMargin: 12
anchors.right: wifiPpConfirm.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: TextInput.AlignVCenter
color: root.theme ? root.theme.content.normal : "white"
selectionColor: root.theme ? root.theme.ui.focus : "#ffffff"
selectedTextColor: root.theme ? root.theme.content.backdrop : "black"
font.family: "IBM Plex Sans"
font.pixelSize: 13
echoMode: TextInput.Password
clip: true
onAccepted: wifiPpRow.submit()
Keys.onReturnPressed: event => {
event.accepted = true;
wifiPpRow.submit();
}
Keys.onEnterPressed: event => {
event.accepted = true;
wifiPpRow.submit();
}
Keys.onEscapePressed: event => {
event.accepted = true;
wifiPp.text = "";
root.expandedSsid = "";
}
}
NuguText {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
visible: wifiPp.text.length === 0
theme: root.theme
variant: "meta"
text: "passphrase"
opacity: 0.7
}
Rectangle {
id: wifiPpConfirm
anchors.right: parent.right
anchors.rightMargin: 6
anchors.verticalCenter: parent.verticalCenter
width: 56
height: 24
radius: 8
color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.22) : "transparent"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.7) : "white"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: "join"
}
MouseArea {
anchors.fill: parent
onClicked: wifiPpRow.submit()
}
}
}
}
}
}
}
}
NuguText {
visible: !!(root.networkState.wifi && root.networkState.wifi.enabled) && (!root.networkState.networks || root.networkState.networks.length === 0)
theme: root.theme
variant: "meta"
text: root.networkState.scanning ? "scanning…" : "no networks"
opacity: 0.7
}
}
Rectangle {
width: parent.width
height: 1
color: root.theme ? root.theme.ui.accent : "transparent"
}
Column {
objectName: "bluetoothToggleScanList"
width: parent.width
spacing: 6
Row {
width: parent.width
spacing: 6
NuguText {
theme: root.theme
variant: "title"
text: "bluetooth"
width: parent.width - 132
}
Rectangle {
width: 58
height: 26
radius: 9
color: root.theme ? root.theme.withAlpha(root.bluetoothState.adapter && root.bluetoothState.adapter.state === "powered" ? root.theme.ui.focus : root.theme.ui.minor, 0.22) : "transparent"
border.width: 0
border.color: root.roleColor(root.bluetoothState.compact ? root.bluetoothState.compact.role : "ui.minor")
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: root.bluetoothState.adapter && root.bluetoothState.adapter.state === "powered" ? "on" : "off"
}
MouseArea {
anchors.fill: parent
onClicked: root.toggleBluetooth()
}
}
Rectangle {
width: 58
height: 26
radius: 9
color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, root.bluetoothState.adapter && root.bluetoothState.adapter.discovering ? 0.32 : 0.16) : "transparent"
border.width: 0
border.color: root.theme ? root.theme.ui.accent : "transparent"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: root.bluetoothState.adapter && root.bluetoothState.adapter.discovering ? "scan…" : "scan"
}
MouseArea {
anchors.fill: parent
onClicked: root.scanBluetooth()
}
}
}
Column {
width: parent.width
spacing: 6
Row {
id: bluetoothHeader
width: parent.width
height: 22
spacing: 6
Item {
width: 34
height: 1
}
NuguText {
theme: root.theme
variant: "meta"
text: "device"
width: bluetoothHeader.width - 34 - 78 - 84 - 96 - bluetoothHeader.spacing * 4
opacity: 0.75
}
NuguText {
theme: root.theme
variant: "meta"
text: "trust"
width: 78
horizontalAlignment: Text.AlignHCenter
opacity: 0.75
}
NuguText {
theme: root.theme
variant: "meta"
text: "state"
width: 84
horizontalAlignment: Text.AlignHCenter
opacity: 0.75
}
NuguText {
theme: root.theme
variant: "meta"
text: "battery"
width: 96
horizontalAlignment: Text.AlignRight
opacity: 0.75
}
}
Rectangle {
width: parent.width
height: 1
color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.24) : "transparent"
}
Repeater {
model: root.bluetoothState.devices || []
delegate: Rectangle {
id: deviceRow
required property var modelData
width: root.width
height: 42
radius: 10
color: root.theme ? root.theme.withAlpha(modelData.connected ? root.theme.ui.focus : root.theme.ui.minor, modelData.connected ? 0.24 : 0.1) : "transparent"
border.width: modelData.connected ? 1 : 0
border.color: root.roleColor(modelData.blocked ? "error" : modelData.connected ? "ui.accent" : "ui.minor")
Row {
id: deviceLine
anchors.fill: parent
anchors.leftMargin: 8
anchors.rightMargin: 8
spacing: 6
Text {
width: 26
anchors.verticalCenter: parent.verticalCenter
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 17
color: root.roleColor(deviceRow.modelData.connected ? "ui.accent" : "ui.minor")
text: root.bluetoothDeviceIcon(deviceRow.modelData.type)
horizontalAlignment: Text.AlignHCenter
}
NuguText {
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
text: deviceRow.modelData.name
width: deviceLine.width - 26 - 78 - 84 - 96 - deviceLine.spacing * 4
elide: Text.ElideRight
}
Rectangle {
width: 78
height: 23
anchors.verticalCenter: parent.verticalCenter
radius: 8
color: root.theme ? root.theme.withAlpha(deviceRow.modelData.trusted ? root.theme.ui.accent : root.theme.ui.minor, deviceRow.modelData.trusted ? 0.18 : 0.1) : "transparent"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: deviceRow.modelData.trusted ? "✓ trusted" : "untrusted"
color: root.roleColor(deviceRow.modelData.trusted ? "ui.accent" : "ui.minor")
}
}
Rectangle {
width: 84
height: 23
anchors.verticalCenter: parent.verticalCenter
radius: 8
color: root.theme ? root.theme.withAlpha(deviceRow.modelData.connected ? root.theme.ui.accent : root.theme.ui.minor, deviceRow.modelData.connected ? 0.22 : 0.1) : "transparent"
NuguText {
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: deviceRow.modelData.connected ? "● linked" : "○ off"
color: root.roleColor(deviceRow.modelData.connected ? "ui.accent" : "ui.minor")
}
}
NuguText {
objectName: "batteryBadges"
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
variant: "mono"
width: 96
horizontalAlignment: Text.AlignRight
font.family: "Symbols Nerd Font Mono"
color: root.roleColor(deviceRow.modelData.battery >= 0 ? "content.accent" : "ui.minor")
text: root.bluetoothBatteryLabel(deviceRow.modelData)
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
onClicked: event => {
if (event.button === Qt.MiddleButton)
root.bluetoothAction("forget", deviceRow.modelData.id);
else if (event.button === Qt.RightButton)
root.bluetoothAction(deviceRow.modelData.trusted ? "block" : "trust", deviceRow.modelData.id);
else
root.bluetoothAction(deviceRow.modelData.connected ? "disconnect" : "connect", deviceRow.modelData.id);
}
}
}
}
}
}
}
}
}