import QtQuick import "../services" as S import NovaStats as NS 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 ? NS.ThemeService.base02 : "transparent" radius: NS.ThemeService.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: NS.ThemeService.base05 font.pixelSize: NS.ThemeService.fontSize - 1 font.family: NS.ThemeService.fontFamily elide: Text.ElideRight } Rectangle { id: _subStateTag anchors.right: _restartBtn.left anchors.rightMargin: 6 anchors.verticalCenter: parent.verticalCenter color: NS.ThemeService.base08 opacity: 0.85 radius: 3 width: _subStateLbl.width + 8 height: 14 Text { id: _subStateLbl anchors.centerIn: parent text: root.subState color: NS.ThemeService.base00 font.pixelSize: NS.ThemeService.fontSize - 3 font.family: NS.ThemeService.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 : NS.ThemeService.base04 font.pixelSize: NS.ThemeService.fontSize font.family: NS.ThemeService.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 : NS.ThemeService.base04 font.pixelSize: NS.ThemeService.fontSize - 1 font.family: NS.ThemeService.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: NS.ThemeService.base01 radius: NS.ThemeService.radius Text { anchors.centerIn: parent visible: root._loading text: "loading..." color: NS.ThemeService.base04 font.pixelSize: NS.ThemeService.fontSize - 2 font.family: NS.ThemeService.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: NS.ThemeService.base04 font.pixelSize: NS.ThemeService.fontSize - 3 font.family: NS.ThemeService.fontFamily wrapMode: Text.WrapAnywhere } onContentHeightChanged: contentY = Math.max(0, contentHeight - height) } } } }