pragma ComponentBehavior: Bound import QtQuick import "Util.js" as Util Column { id: root required property Theme theme required property Power powerService property var panelState: powerService ? Util.parseJson(powerService.stateJson(), { "battery": {}, "externalDevices": [] }) : ({ "battery": {}, "externalDevices": [] }) readonly property var battery: panelState.battery || ({}) readonly property var devices: panelState.externalDevices || [] readonly property var sessionActions: panelState.sessionActions || ["lock", "suspend", "monitor-off", "monitor-on", "logout", "reboot", "poweroff"] readonly property bool hasMainBattery: !!(battery && battery.present) readonly property var safeActionNames: ["lock", "suspend", "monitor-off"] readonly property var destructiveActionNames: ["logout", "reboot", "poweroff"] readonly property var safeActions: actionSubset(safeActionNames) readonly property var destructiveActions: actionSubset(destructiveActionNames) function refreshFrom(text) { panelState = Util.parseJson(text, panelState); } function runSession(action) { if (powerService) refreshFrom(powerService.sessionAction(action)); } function confirm(action) { if (powerService) refreshFrom(powerService.confirmAction(action)); } function cancel() { if (powerService) refreshFrom(powerService.cancelAction()); } 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; return theme.ui.accent; } function actionSubset(names) { const rows = []; for (let i = 0; i < names.length; i++) { if (sessionActions.indexOf(names[i]) >= 0) rows.push(names[i]); } return rows; } function actionLabel(action) { if (action === "suspend") return "sleep"; if (action === "monitor-off") return "display off"; if (action === "poweroff") return "power off"; return action; } function batteryMeta() { const parts = []; if (battery.timeEstimate && battery.timeEstimate !== "unknown") parts.push(battery.timeEstimate); if (battery.health >= 0) parts.push(`health ${battery.health}%`); return parts.join(" ยท "); } spacing: 12 width: parent ? parent.width : 0 focus: true Keys.onEscapePressed: root.cancel() Keys.onReturnPressed: root.panelState.pendingConfirmation ? root.confirm(root.panelState.pendingConfirmation) : root.runSession("lock") Keys.onEnterPressed: root.panelState.pendingConfirmation ? root.confirm(root.panelState.pendingConfirmation) : root.runSession("lock") Rectangle { objectName: "batteryHero" width: parent.width height: root.hasMainBattery ? 116 : 0 radius: 18 visible: root.hasMainBattery color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.56) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.roleColor(root.battery.role || "ui.accent"), 0.65) : "transparent" Rectangle { id: batteryDial anchors.left: parent.left anchors.leftMargin: 12 anchors.verticalCenter: parent.verticalCenter width: 92 height: 92 radius: 46 color: root.theme ? root.theme.withAlpha(root.roleColor(root.battery.role || "ui.accent"), 0.18) : "transparent" border.width: 1 border.color: root.theme ? root.roleColor(root.battery.role || "ui.accent") : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "title" font.pixelSize: 25 text: `${root.battery.percent || 0}%` color: root.theme ? root.theme.content.normal : "white" } } Column { anchors.left: batteryDial.right anchors.leftMargin: 14 anchors.right: parent.right anchors.rightMargin: 14 anchors.verticalCenter: parent.verticalCenter spacing: 8 NuguText { theme: root.theme variant: "title" width: parent.width text: root.battery.state || "unknown" color: root.theme ? root.roleColor(root.battery.role || "ui.accent") : "white" elide: Text.ElideRight } NuguText { theme: root.theme variant: "meta" width: parent.width visible: root.batteryMeta().length > 0 text: root.batteryMeta() color: root.theme ? root.theme.ui.minor : "white" elide: Text.ElideRight } } } Flow { id: deviceFlow objectName: "externalDeviceBatteryChips" width: parent.width height: visible ? implicitHeight : 0 spacing: 8 visible: root.devices.length > 0 Repeater { model: root.devices delegate: Rectangle { id: deviceChip required property var modelData width: Math.floor((root.width - 8) / 2) height: 32 radius: 11 color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.55) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.42) : "transparent" NuguText { anchors.left: parent.left anchors.leftMargin: 9 anchors.right: devicePercent.left anchors.rightMargin: 8 anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "meta" text: `${deviceChip.modelData.name}` color: root.theme ? root.theme.ui.minor : "white" elide: Text.ElideRight } NuguText { id: devicePercent anchors.right: parent.right anchors.rightMargin: 9 anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "meta" text: `${deviceChip.modelData.percent}%` color: root.theme ? root.theme.content.normal : "white" } } } } Grid { id: safeGrid objectName: "safeActionGrid" width: parent.width columns: 3 columnSpacing: 8 rowSpacing: 8 Repeater { model: root.safeActions delegate: Rectangle { id: safeButton required property string modelData readonly property bool primary: modelData === "lock" width: Math.floor((root.width - safeGrid.columnSpacing * (safeGrid.columns - 1)) / safeGrid.columns) height: 42 radius: 13 color: root.theme ? root.theme.withAlpha(primary ? root.theme.ui.accent : root.theme.ui.minor, primary ? 0.22 : 0.12) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(primary ? root.theme.ui.accent : root.theme.ui.minor, primary ? 0.78 : 0.36) : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: root.actionLabel(safeButton.modelData) color: root.theme ? root.theme.content.normal : "white" } MouseArea { anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.runSession(safeButton.modelData) } } } } Rectangle { objectName: "dangerRegion" width: parent.width height: root.panelState.pendingConfirmation ? 62 : 58 radius: 18 color: root.theme ? root.theme.withAlpha(root.panelState.pendingConfirmation ? root.theme.warning : root.theme.error, root.panelState.pendingConfirmation ? 0.12 : 0.08) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.panelState.pendingConfirmation ? root.theme.warning : root.theme.error, 0.62) : "transparent" Grid { id: dangerGrid anchors.fill: parent anchors.margins: 10 columns: 3 columnSpacing: 8 visible: !root.panelState.pendingConfirmation Repeater { model: root.destructiveActions delegate: Rectangle { id: dangerButton required property string modelData width: Math.floor((dangerGrid.width - dangerGrid.columnSpacing * 2) / 3) height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.error, dangerArea.containsMouse ? 0.2 : 0.12) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.error, 0.5) : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: root.actionLabel(dangerButton.modelData) color: root.theme ? root.theme.content.normal : "white" } MouseArea { id: dangerArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.runSession(dangerButton.modelData) } } } } Row { anchors.fill: parent anchors.margins: 10 spacing: 8 visible: !!root.panelState.pendingConfirmation NuguText { anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "title" text: root.actionLabel(root.panelState.pendingConfirmation) color: root.theme ? root.theme.warning : "white" width: parent.width - confirmButton.width - cancelButton.width - 16 elide: Text.ElideRight } Rectangle { id: confirmButton anchors.verticalCenter: parent.verticalCenter width: 82 height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.warning, confirmArea.containsMouse ? 0.28 : 0.18) : "transparent" border.width: 1 border.color: root.theme ? root.theme.warning : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: "confirm" color: root.theme ? root.theme.content.normal : "white" } MouseArea { id: confirmArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.confirm(root.panelState.pendingConfirmation) } } Rectangle { id: cancelButton anchors.verticalCenter: parent.verticalCenter width: 74 height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, cancelArea.containsMouse ? 0.18 : 0.1) : "transparent" border.width: 0 border.color: "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: "cancel" color: root.theme ? root.theme.content.normal : "white" } MouseArea { id: cancelArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.cancel() } } } } }