add systemd and machinectl bar modules with applets

This commit is contained in:
Damocles 2026-05-01 18:43:35 +02:00
parent 7ab784e101
commit 8ab3fc5f6b
12 changed files with 1117 additions and 1 deletions

View file

@ -0,0 +1,351 @@
import QtQuick
import "../services" as S
Column {
id: root
required property color accentColor
property bool active: true
property bool _localExpanded: true
// Localhost section header
Item {
width: root.width
height: 32
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: _localHdrHover.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
z: -1
}
HoverHandler {
id: _localHdrHover
}
Text {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: " localhost"
color: S.Theme.base05
font.pixelSize: S.Theme.fontSize
font.family: S.Theme.fontFamily
}
Rectangle {
id: _localStateChip
anchors.right: _localChevron.left
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
visible: S.SystemdService.systemState !== "unknown"
color: {
const st = S.SystemdService.systemState;
if (st === "running")
return S.Theme.base0B;
if (st === "degraded")
return S.Theme.base0A;
return S.Theme.base08;
}
opacity: 0.85
radius: 3
width: _localStateLbl.width + 8
height: 14
Text {
id: _localStateLbl
anchors.centerIn: parent
text: S.SystemdService.systemState
color: S.Theme.base00
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
}
}
Text {
id: _localChevron
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: root._localExpanded ? "" : ""
color: S.Theme.base04
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.iconFontFamily
}
TapHandler {
onTapped: root._localExpanded = !root._localExpanded
}
}
// Localhost expanded content
Column {
visible: root._localExpanded
width: root.width
// System sub-section
Item {
width: root.width
height: 22
Text {
anchors.left: parent.left
anchors.leftMargin: 24
anchors.verticalCenter: parent.verticalCenter
text: "SYSTEM"
color: S.Theme.base03
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
font.letterSpacing: 1
}
}
Repeater {
model: S.SystemdService.systemUnits
delegate: SystemdUnitRow {
required property var modelData
unitName: modelData.name
description: modelData.description
subState: modelData.subState
isUser: false
machineName: ""
accentColor: root.accentColor
}
}
Item {
visible: S.SystemdService.systemUnits.length === 0
width: root.width
height: 22
Text {
anchors.centerIn: parent
text: "no failures"
color: S.Theme.base0B
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
}
// User sub-section
Item {
width: root.width
height: 22
Text {
anchors.left: parent.left
anchors.leftMargin: 24
anchors.verticalCenter: parent.verticalCenter
text: "USER"
color: S.Theme.base03
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
font.letterSpacing: 1
}
}
Repeater {
model: S.SystemdService.userUnits
delegate: SystemdUnitRow {
required property var modelData
unitName: modelData.name
description: modelData.description
subState: modelData.subState
isUser: true
machineName: ""
accentColor: root.accentColor
}
}
Item {
visible: S.SystemdService.userUnits.length === 0
width: root.width
height: 22
Text {
anchors.centerIn: parent
text: "no failures"
color: S.Theme.base0B
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
}
}
// Containers
Repeater {
model: S.MachinectlService.machines
delegate: Column {
id: _machineSection
required property var modelData
required property int index
property bool _expanded: false
property bool _loading: false
width: root.width
Connections {
target: S.MachinectlService
function onMachineReady(machineName) {
if (machineName === _machineSection.modelData.name)
_machineSection._loading = false;
}
}
Separator {}
// Machine header
Item {
width: _machineSection.width
height: 32
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: _mHdrHover.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
z: -1
}
HoverHandler {
id: _mHdrHover
}
Text {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: " " + _machineSection.modelData.name
color: S.Theme.base05
font.pixelSize: S.Theme.fontSize
font.family: S.Theme.fontFamily
elide: Text.ElideRight
width: parent.width - 100
}
Rectangle {
id: _mStateChip
anchors.right: _mChevron.left
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
visible: _machineSection._expanded && !_machineSection._loading
color: {
const st = S.MachinectlService.machineState(_machineSection.modelData.name);
if (st === "running")
return S.Theme.base0B;
if (st === "degraded")
return S.Theme.base0A;
return st === "unknown" ? "transparent" : S.Theme.base08;
}
opacity: 0.85
radius: 3
width: _mStateLbl.width + 8
height: 14
Text {
id: _mStateLbl
anchors.centerIn: parent
text: S.MachinectlService.machineState(_machineSection.modelData.name)
color: S.Theme.base00
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
}
}
Text {
id: _mChevron
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: _machineSection._expanded ? "" : ""
color: S.Theme.base04
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.iconFontFamily
}
TapHandler {
onTapped: {
_machineSection._expanded = !_machineSection._expanded;
if (_machineSection._expanded) {
_machineSection._loading = true;
S.MachinectlService.fetchMachine(_machineSection.modelData.name);
}
}
}
}
// Machine expanded content
Column {
visible: _machineSection._expanded
width: _machineSection.width
Item {
visible: _machineSection._loading
width: _machineSection.width
height: 28
Text {
anchors.centerIn: parent
text: "loading..."
color: S.Theme.base04
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
}
// System units inside the container
Item {
visible: !_machineSection._loading
width: _machineSection.width
height: 22
Text {
anchors.left: parent.left
anchors.leftMargin: 24
anchors.verticalCenter: parent.verticalCenter
text: "SYSTEM"
color: S.Theme.base03
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
font.letterSpacing: 1
}
}
Repeater {
model: !_machineSection._loading ? S.MachinectlService.machineUnits(_machineSection.modelData.name) : []
delegate: SystemdUnitRow {
required property var modelData
unitName: modelData.name
description: modelData.description
subState: modelData.subState
isUser: false
machineName: _machineSection.modelData.name
accentColor: root.accentColor
}
}
Item {
visible: !_machineSection._loading && S.MachinectlService.machineUnits(_machineSection.modelData.name).length === 0
width: _machineSection.width
height: 22
Text {
anchors.centerIn: parent
text: "no failures"
color: S.Theme.base0B
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
}
}
}
}
Item {
width: 1
height: 4
}
}

View file

@ -0,0 +1,164 @@
import QtQuick
import "../services" as S
Column {
id: root
required property color accentColor
property bool active: true
// Section header: state label + unit count
Item {
width: root.width
height: 28
Text {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: "SYSTEM"
color: S.Theme.base03
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
font.letterSpacing: 1
}
Rectangle {
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
visible: S.SystemdService.systemState !== "unknown"
color: {
const st = S.SystemdService.systemState;
if (st === "running")
return S.Theme.base0B;
if (st === "degraded")
return S.Theme.base0A;
return S.Theme.base08;
}
opacity: 0.85
radius: 3
width: _sysStateLbl.width + 8
height: 14
Text {
id: _sysStateLbl
anchors.centerIn: parent
text: S.SystemdService.systemState
color: S.Theme.base00
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
}
}
}
Repeater {
model: S.SystemdService.systemUnits
delegate: SystemdUnitRow {
required property var modelData
unitName: modelData.name
description: modelData.description
subState: modelData.subState
isUser: false
machineName: ""
accentColor: root.accentColor
onHeightChanged: root.keepPanelOpen?.(300)
}
}
Item {
visible: S.SystemdService.systemUnits.length === 0
width: root.width
height: 24
Text {
anchors.centerIn: parent
text: "no failed system units"
color: S.Theme.base0B
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
}
Separator {}
// User section
Item {
width: root.width
height: 28
Text {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: "USER"
color: S.Theme.base03
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
font.letterSpacing: 1
}
Rectangle {
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
visible: S.SystemdService.userState !== "unknown"
color: {
const st = S.SystemdService.userState;
if (st === "running")
return S.Theme.base0B;
if (st === "degraded")
return S.Theme.base0A;
return S.Theme.base08;
}
opacity: 0.85
radius: 3
width: _userStateLbl.width + 8
height: 14
Text {
id: _userStateLbl
anchors.centerIn: parent
text: S.SystemdService.userState
color: S.Theme.base00
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
}
}
}
Repeater {
model: S.SystemdService.userUnits
delegate: SystemdUnitRow {
required property var modelData
unitName: modelData.name
description: modelData.description
subState: modelData.subState
isUser: true
machineName: ""
accentColor: root.accentColor
onHeightChanged: root.keepPanelOpen?.(300)
}
}
Item {
visible: S.SystemdService.userUnits.length === 0
width: root.width
height: 24
Text {
anchors.centerIn: parent
text: "no failed user units"
color: S.Theme.base0B
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
}
Item {
width: 1
height: 4
}
}

View file

@ -0,0 +1,239 @@
import QtQuick
import "../services" as S
Item {
id: root
required property string unitName
required property string description
required property string subState
required property bool isUser
property string machineName: ""
required property color accentColor
property string _jText: ""
property bool _expanded: false
property bool _loading: false
width: parent?.width ?? 0
height: _row.height + (_expanded ? _journalArea.height : 0)
Behavior on height {
NumberAnimation {
duration: 150
}
}
Connections {
target: S.SystemdService
enabled: root.machineName === ""
function onJournalReady(unitName, isUser, text) {
if (unitName === root.unitName && isUser === root.isUser) {
root._jText = text;
root._loading = false;
}
}
}
Connections {
target: S.MachinectlService
enabled: root.machineName !== ""
function onMachineJournalReady(mname, unitName, text) {
if (mname === root.machineName && unitName === root.unitName) {
root._jText = text;
root._loading = false;
}
}
}
function _fetchJournal() {
root._loading = true;
root._jText = "";
if (root.machineName === "")
S.SystemdService.fetchJournal(root.unitName, root.isUser);
else
S.MachinectlService.fetchMachineJournal(root.machineName, root.unitName);
}
function _doRestart() {
if (root.machineName === "")
S.SystemdService.restartUnit(root.unitName, root.isUser);
else
S.MachinectlService.restartMachineUnit(root.machineName, root.unitName);
}
// Row
Item {
id: _row
width: parent.width
height: 32
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: _rowHover.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
z: -1
}
HoverHandler {
id: _rowHover
}
Text {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.right: _subStateTag.left
anchors.rightMargin: 6
anchors.verticalCenter: parent.verticalCenter
text: root.unitName
color: S.Theme.base05
font.pixelSize: S.Theme.fontSize - 1
font.family: S.Theme.fontFamily
elide: Text.ElideRight
}
Rectangle {
id: _subStateTag
anchors.right: _restartBtn.left
anchors.rightMargin: 6
anchors.verticalCenter: parent.verticalCenter
color: S.Theme.base08
opacity: 0.85
radius: 3
width: _subStateLbl.width + 8
height: 14
Text {
id: _subStateLbl
anchors.centerIn: parent
text: root.subState
color: S.Theme.base00
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
}
}
// Restart button - = fa-refresh
Item {
id: _restartBtn
anchors.right: _expandBtn.left
anchors.rightMargin: 2
anchors.verticalCenter: parent.verticalCenter
width: 24
height: 24
Text {
anchors.centerIn: parent
text: ""
color: _rHover.hovered ? root.accentColor : S.Theme.base04
font.pixelSize: S.Theme.fontSize
font.family: S.Theme.iconFontFamily
Behavior on color {
ColorAnimation {
duration: 80
}
}
}
HoverHandler {
id: _rHover
cursorShape: Qt.PointingHandCursor
}
TapHandler {
onTapped: {
root._doRestart();
if (root._expanded) {
root._jText = "";
Qt.callLater(root._fetchJournal);
}
}
}
}
// Expand chevron - = fa-chevron-down, = fa-chevron-up
Item {
id: _expandBtn
anchors.right: parent.right
anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter
width: 24
height: 24
Text {
anchors.centerIn: parent
text: root._expanded ? "" : ""
color: _expHover.hovered ? root.accentColor : S.Theme.base04
font.pixelSize: S.Theme.fontSize - 1
font.family: S.Theme.iconFontFamily
Behavior on color {
ColorAnimation {
duration: 80
}
}
}
HoverHandler {
id: _expHover
cursorShape: Qt.PointingHandCursor
}
TapHandler {
onTapped: {
root._expanded = !root._expanded;
if (root._expanded && root._jText === "")
root._fetchJournal();
}
}
}
}
// Journal area
Item {
id: _journalArea
anchors.top: _row.bottom
width: parent.width
height: 120
visible: root._expanded
clip: true
Rectangle {
anchors.fill: parent
anchors.leftMargin: 8
anchors.rightMargin: 8
anchors.bottomMargin: 4
color: S.Theme.base01
radius: S.Theme.radius
Text {
anchors.centerIn: parent
visible: root._loading
text: "loading..."
color: S.Theme.base04
font.pixelSize: S.Theme.fontSize - 2
font.family: S.Theme.fontFamily
}
Flickable {
id: _flick
anchors.fill: parent
anchors.margins: 6
visible: !root._loading
contentHeight: _jContent.height
clip: true
Text {
id: _jContent
width: _flick.width
text: root._jText
color: S.Theme.base04
font.pixelSize: S.Theme.fontSize - 3
font.family: S.Theme.fontFamily
wrapMode: Text.WrapAnywhere
}
onContentHeightChanged: contentY = Math.max(0, contentHeight - height)
}
}
}
}

View file

@ -10,6 +10,7 @@ GpuApplet 1.0 GpuApplet.qml
HexWaveBackground 1.0 HexWaveBackground.qml
HoverableListItem 1.0 HoverableListItem.qml
InfoRow 1.0 InfoRow.qml
MachinectlApplet 1.0 MachinectlApplet.qml
MemoryApplet 1.0 MemoryApplet.qml
MprisApplet 1.0 MprisApplet.qml
NetworkApplet 1.0 NetworkApplet.qml
@ -17,6 +18,8 @@ NotifApplet 1.0 NotifApplet.qml
PowerApplet 1.0 PowerApplet.qml
Separator 1.0 Separator.qml
SparklineCanvas 1.0 SparklineCanvas.qml
SystemdApplet 1.0 SystemdApplet.qml
SystemdUnitRow 1.0 SystemdUnitRow.qml
TemperatureApplet 1.0 TemperatureApplet.qml
VolumeApplet 1.0 VolumeApplet.qml
WeatherApplet 1.0 WeatherApplet.qml