network/bluetooth menus: add radio toggle header, fix contentWidth
This commit is contained in:
parent
86003d8eaa
commit
edcc78483c
2 changed files with 170 additions and 22 deletions
|
|
@ -10,15 +10,19 @@ M.HoverPanel {
|
|||
contentWidth: 250
|
||||
|
||||
property var _devices: []
|
||||
property bool _btEnabled: true
|
||||
|
||||
property Process _scanner: Process {
|
||||
id: scanner
|
||||
running: true
|
||||
command: ["sh", "-c", "bluetoothctl devices Paired 2>/dev/null | while read -r _ mac name; do " + "info=$(bluetoothctl info \"$mac\" 2>/dev/null); " + "conn=$(echo \"$info\" | grep -c 'Connected: yes'); " + "bat=$(echo \"$info\" | awk -F'[(): ]' '/Battery Percentage/{for(i=1;i<=NF;i++) if($i+0==$i && $i!=\"\") print $i}'); " + "echo \"$mac:$conn:${bat:-}:$name\"; " + "done"]
|
||||
command: ["sh", "-c", "bluetoothctl show 2>/dev/null | awk '/Powered:/{print $2; exit}';" + "echo '---DEVICES---';" + "bluetoothctl devices Paired 2>/dev/null | while read -r _ mac name; do " + "info=$(bluetoothctl info \"$mac\" 2>/dev/null); " + "conn=$(echo \"$info\" | grep -c 'Connected: yes'); " + "bat=$(echo \"$info\" | awk -F'[(): ]' '/Battery Percentage/{for(i=1;i<=NF;i++) if($i+0==$i && $i!=\"\") print $i}'); " + "echo \"$mac:$conn:${bat:-}:$name\"; " + "done"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const sections = text.split("---DEVICES---");
|
||||
menuWindow._btEnabled = (sections[0] || "").trim() === "yes";
|
||||
|
||||
const devs = [];
|
||||
for (const line of text.trim().split("\n")) {
|
||||
for (const line of (sections[1] || "").trim().split("\n")) {
|
||||
if (!line)
|
||||
continue;
|
||||
const i1 = line.indexOf(":");
|
||||
|
|
@ -27,10 +31,10 @@ M.HoverPanel {
|
|||
if (i3 < 0)
|
||||
continue;
|
||||
devs.push({
|
||||
mac: line.slice(0, i1),
|
||||
connected: line.slice(i1 + 1, i2) === "1",
|
||||
battery: parseInt(line.slice(i2 + 1, i3)) || -1,
|
||||
name: line.slice(i3 + 1)
|
||||
"mac": line.slice(0, i1),
|
||||
"connected": line.slice(i1 + 1, i2) === "1",
|
||||
"battery": parseInt(line.slice(i2 + 1, i3)) || -1,
|
||||
"name": line.slice(i3 + 1)
|
||||
});
|
||||
}
|
||||
devs.sort((a, b) => {
|
||||
|
|
@ -43,6 +47,14 @@ M.HoverPanel {
|
|||
}
|
||||
}
|
||||
|
||||
property Process _powerProc: Process {
|
||||
id: powerProc
|
||||
property string _action: ""
|
||||
command: ["bluetoothctl", "power", _action]
|
||||
onRunningChanged: if (!running)
|
||||
scanner.running = true
|
||||
}
|
||||
|
||||
property Process _toggleProc: Process {
|
||||
id: toggleProc
|
||||
property string action: ""
|
||||
|
|
@ -52,6 +64,70 @@ M.HoverPanel {
|
|||
scanner.running = true
|
||||
}
|
||||
|
||||
// Bluetooth radio toggle header
|
||||
Item {
|
||||
width: menuWindow.contentWidth
|
||||
height: 36
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 4
|
||||
anchors.rightMargin: 4
|
||||
color: btHeaderArea.containsMouse ? M.Theme.base02 : "transparent"
|
||||
radius: M.Theme.radius
|
||||
}
|
||||
|
||||
Text {
|
||||
id: btHeaderIcon
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "\uF294"
|
||||
color: menuWindow._btEnabled ? menuWindow.accentColor : M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize + 1
|
||||
font.family: M.Theme.iconFontFamily
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.left: btHeaderIcon.right
|
||||
anchors.leftMargin: 8
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "Bluetooth"
|
||||
color: menuWindow._btEnabled ? 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._btEnabled ? menuWindow.accentColor : M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize
|
||||
font.family: M.Theme.iconFontFamily
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: btHeaderArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
powerProc._action = menuWindow._btEnabled ? "off" : "on";
|
||||
powerProc.running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: menuWindow.contentWidth - 16
|
||||
height: 1
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
color: M.Theme.base03
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: menuWindow._devices
|
||||
|
||||
|
|
@ -60,7 +136,7 @@ M.HoverPanel {
|
|||
required property var modelData
|
||||
required property int index
|
||||
|
||||
width: menuWindow.panelWidth
|
||||
width: menuWindow.contentWidth
|
||||
height: 32
|
||||
|
||||
Rectangle {
|
||||
|
|
@ -125,11 +201,11 @@ M.HoverPanel {
|
|||
|
||||
Text {
|
||||
visible: menuWindow._devices.length === 0
|
||||
width: menuWindow.panelWidth
|
||||
width: menuWindow.contentWidth
|
||||
height: 32
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: "No paired devices"
|
||||
text: menuWindow._btEnabled ? "No paired devices" : "Bluetooth is off"
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize
|
||||
font.family: M.Theme.fontFamily
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue