Files
dotfiles/quickshell/Power.qml
T
2026-11-17 18:15:16 +07:00

68 lines
3.2 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls.Material
import QtQuick.Controls
import QtQuick.Layouts
import "services"
import "components"
ColumnLayout {
id: power
Material.theme: Theme.dark ? Material.Dark : Material.Light
Material.accent: Theme.primary
signal done()
property string pending: ""
readonly property var actions: [
{id: "lock", title: "Заблокировать", question: ""},
{id: "suspend", title: "Сон", question: "Заблокировать компьютер и перейти в сон?"},
{id: "logout", title: "Выйти из сессии", question: "Завершить сессию? Несохранённые изменения могут быть потеряны."},
{id: "reboot", title: "Перезагрузка", question: "Перезагрузить компьютер?"},
{id: "poweroff", title: "Выключение", question: "Выключить компьютер?"}
]
PowerController {
id: controller
onSucceeded: action => { power.pending = ""; if (power.visible) power.done(); }
}
onVisibleChanged: {
if (visible) controller.refresh();
else pending = "";
}
spacing: 12
Repeater {
model: power.actions
ColumnLayout {
id: row
required property var modelData
Layout.fillWidth: true
ActionButton {
text: row.modelData.title + (controller.capabilities[row.modelData.id]?.state === "challenge" ? " · Авторизация" : "")
enabled: !controller.busy && controller.available(row.modelData.id)
onClicked: {
if (row.modelData.id === "lock") controller.start("lock");
else power.pending = row.modelData.id;
}
}
Label {
visible: !controller.available(row.modelData.id) && !controller.busy
text: controller.capabilities[row.modelData.id]?.reason || "Недоступно в текущей сессии"
Layout.fillWidth: true; wrapMode: Text.Wrap; color: Theme.outline; textFormat: Text.PlainText
}
}
}
Label {
Layout.fillWidth: true; wrapMode: Text.Wrap; color: Theme.foreground
visible: power.pending !== ""
text: power.actions.find(a => a.id === power.pending)?.question || ""
}
RowLayout {
visible: power.pending !== ""
ActionButton { text: "Подтвердить"; enabled: !controller.busy; onClicked: controller.start(power.pending) }
ActionButton { text: "Отмена"; enabled: !controller.busy; onClicked: power.pending = "" }
}
BusyIndicator { visible: controller.busy; running: visible }
Label { visible: controller.busy; text: "Ожидание ответа системы…"; color: Theme.foreground }
Label { Layout.fillWidth: true; wrapMode: Text.Wrap; text: controller.error || controller.capabilityError; visible: text !== ""; color: "#ffb4ab"; textFormat: Text.PlainText }
ActionButton { text: "Обновить доступность действий"; enabled: !controller.busy; onClicked: controller.refresh() }
Item { Layout.fillHeight: true }
}