Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/connectivity/ConnectivityPanel.qml

Raw
pragma ComponentBehavior: Bound
import QtQuick
import "../.."
import "../system"
import "../system/sysinfo.js" as Sys
import "../../Util.js" as Util
import "network.js" as Net
import "../../human.js" as Human

Column {
    id: root

    required property Theme theme
    readonly property Flickable scrollView: networkScroll
    required property Resources resourceService
    required property Network networkService
    required property Bluetooth bluetoothService
    // The services' typed state, bound: every service change rebinds the panel.
    readonly property var networks: networkService.networks
    readonly property var bluetoothDevices: bluetoothService.devices
    // 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 service state.
    property string expandedSsid: ""
    // Device whose forget is armed ("" = none). The panel lives only while its
    // popup is open, so every dismissal disarms.
    property string armedForget: ""
    // The card fits the content; the entry height caps it (FeatureEntry.qml).
    readonly property real naturalHeight: networkScroll.contentHeight
    // Opening focuses the first network row, or the wireless section's action
    // while it has no rows, e.g. turn on (FeatureEntry.qml).
    property Item firstNetworkRow: null
    readonly property Item initialFocus: wirelessState === "rows" ? firstNetworkRow : wirelessEmptyState.actionControl

    function toggleWifi() {
        networkService.toggleWifi(!networkService.wifiEnabled);
    }

    function scanWifi() {
        networkService.scan();
    }

    function selectNetwork(id) {
        networkService.select(id);
    }

    function forgetNetwork(id) {
        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 / the service / any logged field.
    function connectSecured(ssid, passphrase) {
        networkService.connect(ssid, passphrase);
    }

    function disconnectNetwork() {
        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.diagnostics();
    }

    function toggleBluetooth() {
        bluetoothService.toggle(!bluetoothPowered);
    }

    function scanBluetooth() {
        bluetoothService.scan();
    }

    function bluetoothAction(kind, id) {
        bluetoothService.deviceAction(kind, id);
    }

    function forgetDevice(id) {
        armedForget = "";
        // Focus leaves the row before the row goes away.
        bluetoothToggle.forceActiveFocus(Qt.TabFocusReason);
        bluetoothAction("forget", 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 + "%" : "󰂑";
    }

    // The wireless section's state: "loading" before iwd answers, "missing"
    // without a station device, "off", "empty" without networks, else "rows".
    readonly property string wirelessState: !networkService.loaded ? "loading" : (!networkService.deviceAvailable ? "missing" : (!networkService.wifiEnabled ? "off" : (networks.length === 0 ? "empty" : "rows")))
    // The wired link, shown while it carries traffic, or while nothing is
    // online and a cable port waits for one.
    readonly property string wiredState: networkService.wiredState
    readonly property bool wiredShown: wiredState === "connected" || (wiredState === "unplugged" && networkService.offline)
    readonly property string networkFailure: networkService.actionPending || networkService.scanning ? "" : Net.failureText(networkService.error, networkService.lastAction, failedRowSecured())
    readonly property bool bluetoothAvailable: bluetoothService.adapterAvailable
    readonly property bool bluetoothPowered: bluetoothService.adapterPowered

    function failedRowSecured() {
        const action = networkService.lastAction;
        const name = action.ssid || action.id;
        return networks.some(row => row.ssid === name && row.needsPassphrase);
    }

    // One line under the wireless header: pending work with its scope, a
    // failure with its next step, or why the bar flags the network.
    function networkFeedback() {
        if (networkService.actionPending)
            return Net.pendingText(networkService.lastAction);
        if (networkService.scanning)
            return wirelessState === "rows" ? "scanning for networks…" : "";
        if (networkFailure.length > 0)
            return networkFailure;
        return wirelessState === "rows" && networkService.offline ? "not connected · pick a network to join" : "";
    }

    function networkFeedbackRole() {
        if (networkFailure.length > 0)
            return "error";
        return networkService.actionPending || networkService.scanning ? "ui.minor" : "warning";
    }

    function bluetoothFeedback() {
        if (bluetoothService.adapterDiscovering && bluetoothDevices.length > 0)
            return "scanning for bluetooth devices…";
        return bluetoothService.error.length > 0 ? "bluetooth action failed · try again" : "";
    }

    spacing: 10
    // A forgotten or vanished device disarms its forget.
    onBluetoothDevicesChanged: if (armedForget && !bluetoothDevices.some(device => device.id === armedForget))
        armedForget = ""

    StableListModel {
        id: wifiRows
        rows: root.networks
    }

    // 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 {
        id: networkScroll
        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

            // The link line: the wired link in words, the routine rates quiet.
            Item {
                width: parent.width
                height: 24

                Row {
                    objectName: "wiredStatus"
                    visible: root.wiredShown
                    anchors.left: parent.left
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: root.theme.spaceSm

                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        font.family: root.theme.fontIcon
                        font.pixelSize: 16
                        text: "\u{F0200}"
                        color: root.theme.roleColor(root.wiredState === "connected" ? "content.accent" : "warning")
                        Accessible.ignored: true
                    }

                    NuguText {
                        anchors.verticalCenter: parent.verticalCenter
                        theme: root.theme
                        text: root.wiredState === "connected" ? "wired · connected" : "wired · unplugged"
                        color: root.wiredState === "connected" ? root.theme.content.normal : root.theme.warning
                    }
                }

                Row {
                    objectName: "networkRateRow"
                    anchors.right: parent.right
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: root.theme.spaceSm

                    NuguText {
                        theme: root.theme
                        variant: "meta"
                        text: root.resourceService ? "↓ " + Sys.formatRate(root.resourceService.networkRxRate) : "↓ 0 B/s"
                        color: root.theme.ui.minor
                    }

                    NuguText {
                        theme: root.theme
                        variant: "meta"
                        text: root.resourceService ? "↑ " + Sys.formatRate(root.resourceService.networkTxRate) : "↑ 0 B/s"
                        color: root.theme.ui.minor
                    }
                }
            }

            Column {
                objectName: "wifiToggleScanList"
                width: parent.width
                spacing: 6

                // Section header: the wireless toggle is the section's noun, its
                // glyph and border show the state; scan is the verb beside it.
                Item {
                    width: parent.width
                    height: 30

                    PopupButton {
                        anchors.left: parent.left
                        anchors.verticalCenter: parent.verticalCenter
                        theme: root.theme
                        height: 30
                        width: implicitWidth
                        icon: checked ? "\u{F05A9}" : "\u{F05AA}"
                        text: "wireless"
                        checked: root.networkService.deviceAvailable && root.networkService.wifiEnabled
                        enabled: root.networkService.deviceAvailable
                        tooltip: !enabled ? "no wireless device" : checked ? "turn wireless off" : "turn wireless on"
                        onClicked: root.toggleWifi()
                    }

                    PopupButton {
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter
                        theme: root.theme
                        height: 30
                        width: Math.max(72, implicitWidth)
                        text: root.networkService.scanning ? "scanning…" : "scan"
                        accessibleName: "scan for networks"
                        checked: root.networkService.scanning
                        enabled: root.networkService.deviceAvailable && root.networkService.wifiEnabled
                        onClicked: root.scanWifi()
                    }
                }

                NuguText {
                    objectName: "networkFeedback"
                    visible: text.length > 0
                    width: parent.width
                    theme: root.theme
                    variant: "meta"
                    text: root.networkFeedback()
                    color: root.theme.roleColor(root.networkFeedbackRole())
                    wrapMode: Text.WordWrap
                }

                ConnectivityEmptyState {
                    id: wirelessEmptyState

                    objectName: "wirelessEmptyState"
                    visible: root.wirelessState !== "rows"
                    width: parent.width
                    height: visible ? implicitHeight : 0
                    theme: root.theme
                    icon: root.wirelessState === "missing" || root.wirelessState === "off" ? "\u{F05AA}" : "\u{F05A9}"
                    title: ({
                            "loading": "looking for a wireless device…",
                            "missing": "no wireless device",
                            "off": "wireless is off",
                            "empty": root.networkService.scanning ? "scanning for networks…" : "no networks found"
                        })[root.wirelessState] || ""
                    detail: ({
                            "missing": root.wiredState === "connected" ? "" : "start the wireless service or plug in an adapter",
                            "off": "turn it on to see networks",
                            "empty": root.networkService.scanning ? "" : "move closer to a network, then scan"
                        })[root.wirelessState] || ""
                    actionText: root.wirelessState === "missing" ? "retry" : (root.wirelessState === "off" ? "turn on" : "")
                    actionName: root.wirelessState === "missing" ? "find wireless device" : "turn on wireless"
                    onActivated: {
                        if (root.wirelessState === "missing") {
                            root.networkService.checkConnectivity();
                        } else {
                            root.toggleWifi();
                        }
                    }
                }

                Column {
                    width: parent.width
                    spacing: 6

                    Repeater {
                        model: wifiRows

                        delegate: Column {
                            id: wifiRow

                            required property var rowData
                            required property int index
                            readonly property bool active: rowData.connected === true
                            readonly property bool revealed: root.expandedSsid === rowData.ssid
                            onRevealedChanged: if (!revealed)
                                wifiPp.text = ""
                            readonly property var detail: root.networkService.connectionDetail

                            width: parent.width
                            spacing: 4

                            PopupCard {
                                id: wifiCard

                                theme: root.theme
                                padding: 0
                                active: wifiRow.active
                                revealed: wifiRow.revealed
                                attention: wifiRow.rowData.state === "connecting"
                                interactive: true
                                accessibleName: wifiRow.revealed ? `collapse ${wifiRow.rowData.ssid}` : `expand ${wifiRow.rowData.ssid}`
                                tooltip: accessibleName
                                disclosure: true
                                width: parent.width
                                height: 44
                                onClicked: root.expandRow(wifiRow.rowData)

                                Binding {
                                    when: wifiRow.index === 0
                                    target: root
                                    property: "firstNetworkRow"
                                    value: wifiCard
                                    restoreMode: Binding.RestoreNone
                                }

                                Text {
                                    id: wifiGlyph

                                    anchors.left: parent.left
                                    anchors.leftMargin: 12
                                    anchors.verticalCenter: parent.verticalCenter
                                    font.family: root.theme.fontIcon
                                    font.pixelSize: 18
                                    text: wifiRow.rowData.signalGlyph || ""
                                    color: root.theme.roleColor(wifiRow.rowData.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: root.theme.fontIcon
                                    font.pixelSize: 16
                                    text: ""
                                    rotation: wifiRow.revealed ? 90 : 0
                                    color: root.theme.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.rowData.securityLabel || "")
                                    color: root.theme.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.rowData.ssid
                                    elide: Text.ElideRight
                                }
                            }

                            // --- detail + actions drawer (revealed on tap) -----------
                            PopupCard {
                                id: wifiDrawer

                                visible: wifiRow.revealed
                                theme: root.theme
                                padding: 0
                                revealed: true
                                width: parent.width
                                height: visible ? drawerCol.height + 16 : 0

                                Column {
                                    id: drawerCol

                                    x: 12
                                    y: 8
                                    width: parent.width - 24
                                    spacing: 6

                                    // security + signal in words — available for every row
                                    NuguText {
                                        theme: root.theme
                                        variant: "meta"
                                        text: `${wifiRow.rowData.securityLabel || "open"} · ${wifiRow.rowData.signalLabel || "signal unknown"}`
                                        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
                                        }
                                    }

                                    // action pills — hidden when a passphrase is needed
                                    Row {
                                        visible: !wifiRow.rowData.needsPassphrase
                                        spacing: 8

                                        PopupButton {
                                            visible: !wifiRow.active
                                            theme: root.theme
                                            width: 96
                                            height: 28
                                            text: "connect"
                                            role: "primary"
                                            onClicked: {
                                                root.expandedSsid = "";
                                                root.selectNetwork(wifiRow.rowData.id);
                                            }
                                        }

                                        PopupButton {
                                            visible: wifiRow.active
                                            theme: root.theme
                                            width: 96
                                            height: 28
                                            text: "disconnect"
                                            role: "primary"
                                            onClicked: {
                                                root.expandedSsid = "";
                                                root.disconnectNetwork();
                                            }
                                        }

                                        PopupButton {
                                            visible: wifiRow.active || wifiRow.rowData.known
                                            theme: root.theme
                                            width: 96
                                            height: 28
                                            text: "forget"
                                            role: "destructive"
                                            onClicked: {
                                                root.expandedSsid = "";
                                                root.forgetNetwork(wifiRow.rowData.id);
                                            }
                                        }
                                    }

                                    // --- inline passphrase entry for a NEW secured network.
                                    // echoMode Password; text lives only here, cleared on
                                    // submit, never bound into service state / any logged field.
                                    Item {
                                        id: wifiPpRow

                                        function submit() {
                                            root.connectSecured(wifiRow.rowData.ssid, wifiPp.text);
                                            wifiPp.text = "";
                                            root.expandedSsid = "";
                                        }

                                        visible: wifiRow.rowData.needsPassphrase
                                        width: parent.width
                                        height: visible ? 38 : 0
                                        onVisibleChanged: {
                                            if (visible && wifiRow.revealed)
                                                Qt.callLater(wifiPp.input.forceActiveFocus);
                                            else
                                                wifiPp.text = "";
                                        }

                                        PopupTextField {
                                            id: wifiPp

                                            anchors.left: parent.left
                                            anchors.right: wifiPpConfirm.left
                                            anchors.rightMargin: 8
                                            anchors.verticalCenter: parent.verticalCenter
                                            theme: root.theme
                                            placeholderText: "passphrase"
                                            echoMode: TextInput.Password
                                            onAccepted: wifiPpRow.submit()
                                            onCancelled: {
                                                text = "";
                                                root.expandedSsid = "";
                                            }
                                        }

                                        PopupButton {
                                            id: wifiPpConfirm

                                            anchors.right: parent.right
                                            anchors.verticalCenter: parent.verticalCenter
                                            theme: root.theme
                                            width: 64
                                            height: 32
                                            text: "join"
                                            role: "primary"
                                            onClicked: wifiPpRow.submit()
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            PopupDivider {
                theme: root.theme
                width: parent.width
            }

            Column {
                objectName: "bluetoothToggleScanList"
                width: parent.width
                spacing: 6

                Item {
                    width: parent.width
                    height: 30

                    PopupButton {
                        id: bluetoothToggle

                        anchors.left: parent.left
                        anchors.verticalCenter: parent.verticalCenter
                        theme: root.theme
                        height: 30
                        width: implicitWidth
                        icon: checked ? "\u{F00AF}" : "\u{F00B2}"
                        text: "bluetooth"
                        checked: root.bluetoothAvailable && root.bluetoothPowered
                        enabled: root.bluetoothAvailable
                        tooltip: !enabled ? "no bluetooth adapter" : checked ? "turn bluetooth off" : "turn bluetooth on"
                        onClicked: root.toggleBluetooth()
                    }

                    PopupButton {
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter
                        theme: root.theme
                        height: 30
                        width: Math.max(72, implicitWidth)
                        text: root.bluetoothService.adapterDiscovering ? "scanning…" : "scan"
                        accessibleName: "scan for devices"
                        checked: root.bluetoothService.adapterDiscovering
                        enabled: root.bluetoothAvailable
                        onClicked: root.scanBluetooth()
                    }
                }

                NuguText {
                    visible: text.length > 0
                    width: parent.width
                    theme: root.theme
                    variant: "meta"
                    text: root.bluetoothFeedback()
                    color: root.bluetoothService.error ? root.theme.roleColor("error") : root.theme.roleColor("ui.minor")
                    wrapMode: Text.WordWrap
                }

                ConnectivityEmptyState {
                    objectName: "bluetoothEmptyState"
                    visible: root.bluetoothDevices.length === 0
                    width: parent.width
                    height: visible ? implicitHeight : 0
                    theme: root.theme
                    icon: root.bluetoothAvailable && root.bluetoothPowered ? "\u{F00AF}" : "\u{F00B2}"
                    title: !root.bluetoothAvailable ? "no bluetooth adapter" : !root.bluetoothPowered ? "bluetooth is off" : root.bluetoothService.adapterDiscovering ? "looking for devices…" : "no devices"
                    detail: !root.bluetoothAvailable ? "plug in an adapter to use bluetooth devices" : !root.bluetoothPowered ? "turn it on to find devices" : root.bluetoothService.adapterDiscovering ? "" : "put a device in pairing mode, then scan"
                    actionText: root.bluetoothAvailable && !root.bluetoothPowered ? "turn on" : ""
                    actionName: "turn on bluetooth"
                    onActivated: root.toggleBluetooth()
                }

                // The device rows; their badges name each column.
                Column {
                    visible: root.bluetoothDevices.length > 0
                    width: parent.width
                    spacing: 6

                    Repeater {
                        model: root.bluetoothDevices

                        delegate: Column {
                            id: deviceItem

                            required property var modelData
                            readonly property bool forgetArmed: root.armedForget === modelData.id
                            // A device that sends no name falls back to its address; never show that.
                            readonly property string name: Human.label(modelData.name, "bluetooth device")

                            width: root.width
                            spacing: 4

                            PopupCard {
                                id: deviceRow

                                theme: root.theme
                                padding: 0
                                active: deviceItem.modelData.connected
                                destructive: deviceItem.modelData.blocked
                                interactive: true
                                accessibleName: deviceItem.modelData.connected ? `disconnect ${deviceItem.name}` : `connect ${deviceItem.name}`
                                tooltip: accessibleName
                                width: parent.width
                                height: 46
                                onClicked: root.bluetoothAction(deviceItem.modelData.connected ? "disconnect" : "connect", deviceItem.modelData.id)

                                Row {
                                    id: deviceLine

                                    anchors.fill: parent
                                    anchors.leftMargin: 8
                                    anchors.rightMargin: 8
                                    spacing: 6

                                    Text {
                                        width: 26
                                        anchors.verticalCenter: parent.verticalCenter
                                        font.family: root.theme.fontIcon
                                        font.pixelSize: 17
                                        color: root.theme.roleColor(deviceItem.modelData.connected ? "ui.accent" : "ui.minor")
                                        text: root.bluetoothDeviceIcon(deviceItem.modelData.type)
                                        horizontalAlignment: Text.AlignHCenter
                                    }

                                    NuguText {
                                        anchors.verticalCenter: parent.verticalCenter
                                        theme: root.theme
                                        text: deviceItem.name
                                        width: deviceLine.width - 26 - trustBadge.width - linkBadge.width - battery.width - deviceActions.width - deviceLine.spacing * 5
                                        elide: Text.ElideRight
                                    }

                                    PopupBadge {
                                        id: trustBadge

                                        anchors.verticalCenter: parent.verticalCenter
                                        theme: root.theme
                                        width: 84
                                        text: deviceItem.modelData.trusted ? "trusted" : "untrusted"
                                        icon: deviceItem.modelData.trusted ? "✓" : ""
                                        role: deviceItem.modelData.trusted ? "active" : "normal"
                                    }

                                    PopupBadge {
                                        id: linkBadge

                                        anchors.verticalCenter: parent.verticalCenter
                                        theme: root.theme
                                        width: 96
                                        text: deviceItem.modelData.connected ? "connected" : "off"
                                        icon: deviceItem.modelData.connected ? "●" : "○"
                                        role: deviceItem.modelData.connected ? "active" : "normal"
                                    }

                                    NuguText {
                                        id: battery

                                        objectName: "batteryBadges"
                                        anchors.verticalCenter: parent.verticalCenter
                                        theme: root.theme
                                        variant: "mono"
                                        width: 56
                                        horizontalAlignment: Text.AlignRight
                                        font.family: root.theme.fontIcon
                                        color: root.theme.roleColor(deviceItem.modelData.battery >= 0 ? "content.accent" : "ui.minor")
                                        text: root.bluetoothBatteryLabel(deviceItem.modelData)
                                    }

                                    // Every device action is a visible button; the row
                                    // itself only connects or disconnects.
                                    Row {
                                        id: deviceActions

                                        anchors.verticalCenter: parent.verticalCenter
                                        spacing: 4

                                        PopupButton {
                                            theme: root.theme
                                            width: 32
                                            height: 28
                                            role: "ghost"
                                            showText: false
                                            icon: deviceItem.modelData.trusted ? "\u{F030A}" : "\u{F030B}"
                                            accessibleName: deviceItem.modelData.trusted ? "untrust device" : "trust device"
                                            onClicked: root.bluetoothAction(deviceItem.modelData.trusted ? "untrust" : "trust", deviceItem.modelData.id)
                                        }

                                        // nf-md-cancel; checked while the device is blocked.
                                        PopupButton {
                                            theme: root.theme
                                            width: 32
                                            height: 28
                                            role: "ghost"
                                            showText: false
                                            icon: "\u{F073A}"
                                            checked: deviceItem.modelData.blocked
                                            accessibleName: deviceItem.modelData.blocked ? "unblock device" : "block device"
                                            onClicked: root.bluetoothAction(deviceItem.modelData.blocked ? "unblock" : "block", deviceItem.modelData.id)
                                        }

                                        // Forgetting needs pairing again, so it only arms.
                                        PopupButton {
                                            id: forgetButton

                                            theme: root.theme
                                            width: 32
                                            height: 28
                                            role: "ghost"
                                            showText: false
                                            icon: "\u{F01B4}"
                                            checked: deviceItem.forgetArmed
                                            accessibleName: "forget device"
                                            onClicked: root.armedForget = deviceItem.forgetArmed ? "" : deviceItem.modelData.id
                                        }
                                    }
                                }
                            }

                            // The armed confirmation, below its row so a double click never confirms.
                            Item {
                                objectName: "forgetConfirmation"
                                visible: deviceItem.forgetArmed
                                width: parent.width
                                height: visible ? 44 : 0

                                Column {
                                    anchors.left: parent.left
                                    anchors.leftMargin: 8
                                    anchors.right: forgetActions.left
                                    anchors.rightMargin: 8
                                    anchors.verticalCenter: parent.verticalCenter
                                    spacing: 2

                                    NuguText {
                                        width: parent.width
                                        theme: root.theme
                                        variant: "title"
                                        text: `forget ${deviceItem.name}?`
                                        elide: Text.ElideRight
                                    }

                                    NuguText {
                                        theme: root.theme
                                        variant: "meta"
                                        text: "pair it again to use it"
                                        color: root.theme.ui.minor
                                    }
                                }

                                Row {
                                    id: forgetActions

                                    anchors.right: parent.right
                                    anchors.verticalCenter: parent.verticalCenter
                                    spacing: 8

                                    PopupButton {
                                        theme: root.theme
                                        height: 28
                                        text: "cancel"
                                        tooltip: "keep this device"
                                        onControlFocusedChanged: if (controlFocused)
                                            Util.revealIn(this, networkScroll)
                                        onClicked: {
                                            root.armedForget = "";
                                            forgetButton.forceActiveFocus(Qt.TabFocusReason);
                                        }
                                    }

                                    PopupButton {
                                        theme: root.theme
                                        height: 28
                                        text: "forget"
                                        accessibleName: "confirm forget device"
                                        tooltip: ""
                                        role: "destructive"
                                        primary: true
                                        onControlFocusedChanged: if (controlFocused)
                                            Util.revealIn(this, networkScroll)
                                        onClicked: root.forgetDevice(deviceItem.modelData.id)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}