network/bluetooth menus: add radio toggle header, fix contentWidth

This commit is contained in:
Damocles 2026-04-14 00:58:24 +02:00
parent 86003d8eaa
commit edcc78483c
2 changed files with 170 additions and 22 deletions

View file

@ -10,18 +10,21 @@ M.HoverPanel {
contentWidth: 250
property var _networks: []
property bool _wifiEnabled: true
property Process _scanner: Process {
id: scanner
running: true
command: ["sh", "-c", "echo '---CONNS---';" + "nmcli -t -f NAME,UUID,TYPE,ACTIVE connection show 2>/dev/null;" + "echo '---WIFI---';" + "nmcli -t -f SSID,SIGNAL device wifi list --rescan no 2>/dev/null"]
command: ["sh", "-c", "echo '---RADIO---';" + "nmcli radio wifi 2>/dev/null;" + "echo '---CONNS---';" + "nmcli -t -f NAME,UUID,TYPE,ACTIVE connection show 2>/dev/null;" + "echo '---WIFI---';" + "nmcli -t -f SSID,SIGNAL device wifi list --rescan no 2>/dev/null"]
stdout: StdioCollector {
onStreamFinished: {
const radioSection = text.split("---CONNS---")[0].split("---RADIO---")[1] || "";
menuWindow._wifiEnabled = radioSection.trim() === "enabled";
const sections = text.split("---WIFI---");
const connLines = (sections[0] || "").split("---CONNS---")[1] || "";
const wifiLines = sections[1] || "";
// Visible SSIDs with signal
const visible = {};
for (const l of wifiLines.trim().split("\n")) {
if (!l)
@ -32,7 +35,6 @@ M.HoverPanel {
visible[ssid] = parseInt(parts[1]) || 0;
}
// Saved connections filter: show wired always, wifi only if visible
const nets = [];
for (const l of connLines.trim().split("\n")) {
if (!l)
@ -48,15 +50,14 @@ M.HoverPanel {
continue;
nets.push({
name: name,
uuid: uuid,
isWifi: isWifi,
active: active,
signal: isWifi ? (visible[name] || 0) : -1
"name": name,
"uuid": uuid,
"isWifi": isWifi,
"active": active,
"signal": isWifi ? (visible[name] || 0) : -1
});
}
// Active first, then by signal (wifi) or name
nets.sort((a, b) => {
if (a.active !== b.active)
return a.active ? -1 : 1;
@ -70,6 +71,14 @@ M.HoverPanel {
}
}
property Process _radioProc: Process {
id: radioProc
property string _state: ""
command: ["nmcli", "radio", "wifi", _state]
onRunningChanged: if (!running)
scanner.running = true
}
property Process _connectProc: Process {
id: connectProc
property string uuid: ""
@ -86,6 +95,70 @@ M.HoverPanel {
scanner.running = true
}
// Wi-Fi radio toggle header
Item {
width: menuWindow.contentWidth
height: 36
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: headerArea.containsMouse ? M.Theme.base02 : "transparent"
radius: M.Theme.radius
}
Text {
id: wifiHeaderIcon
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: "\uF1EB"
color: menuWindow._wifiEnabled ? menuWindow.accentColor : M.Theme.base04
font.pixelSize: M.Theme.fontSize + 1
font.family: M.Theme.iconFontFamily
}
Text {
anchors.left: wifiHeaderIcon.right
anchors.leftMargin: 8
anchors.verticalCenter: parent.verticalCenter
text: "Wi-Fi"
color: menuWindow._wifiEnabled ? M.Theme.base05 : M.Theme.base04
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily
font.bold: true
}
Text {
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: "\uF011"
color: menuWindow._wifiEnabled ? menuWindow.accentColor : M.Theme.base04
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.iconFontFamily
}
MouseArea {
id: headerArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
radioProc._state = menuWindow._wifiEnabled ? "off" : "on";
radioProc.running = true;
}
}
}
Rectangle {
width: menuWindow.contentWidth - 16
height: 1
anchors.horizontalCenter: parent.horizontalCenter
color: M.Theme.base03
}
Repeater {
model: menuWindow._networks
@ -94,7 +167,7 @@ M.HoverPanel {
required property var modelData
required property int index
width: menuWindow.panelWidth
width: menuWindow.contentWidth
height: 32
Rectangle {
@ -161,14 +234,13 @@ M.HoverPanel {
}
}
// Empty state
Text {
visible: menuWindow._networks.length === 0
width: menuWindow.panelWidth
width: menuWindow.contentWidth
height: 32
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "No networks available"
text: menuWindow._wifiEnabled ? "No networks available" : "Wi-Fi is off"
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily