import QtQuick 2.0 import Sailfish.Silica 1.0 CoverBackground { id: cover // Guardie: quando lo snapshot non è ancora arrivato i campi mancano e in // JS leggere una proprietà di undefined solleva un'eccezione. function cpuPct() { var d = statusClient.data return (d && d.cpu && d.cpu.percent !== undefined) ? d.cpu.percent : -1 } function memPct() { var d = statusClient.data return (d && d.memory && d.memory.percent !== undefined) ? d.memory.percent : -1 } function diskPct() { var d = statusClient.data if (d && d.disks && d.disks.length > 0 && d.disks[0].percent !== undefined) return d.disks[0].percent return -1 } // Stesse soglie delle card: verde, giallo da 85%, rosso da 95%. function levelColor(p) { if (p < 0) return Theme.secondaryColor if (p >= 95) return "#e53935" if (p >= 85) return "#ffb300" return "#43a047" } function pctText(p) { return p < 0 ? "—" : statusClient.fmtNum(p, 0) + "%" } Column { anchors.centerIn: parent width: parent.width - 2 * Theme.paddingMedium spacing: Theme.paddingSmall Label { text: qsTr("Server") font.pixelSize: Theme.fontSizeExtraSmall color: Theme.secondaryColor anchors.horizontalCenter: parent.horizontalCenter } // CPU · RAM · disco: etichetta a sinistra, percentuale a destra. Column { width: parent.width spacing: Theme.paddingSmall / 2 Row { width: parent.width Label { text: qsTr("CPU") width: parent.width * 0.5 font.pixelSize: Theme.fontSizeSmall color: Theme.primaryColor } Label { text: pctText(cpuPct()) width: parent.width * 0.5 horizontalAlignment: Text.AlignRight font.pixelSize: Theme.fontSizeSmall color: levelColor(cpuPct()) } } Row { width: parent.width Label { text: qsTr("RAM") width: parent.width * 0.5 font.pixelSize: Theme.fontSizeSmall color: Theme.primaryColor } Label { text: pctText(memPct()) width: parent.width * 0.5 horizontalAlignment: Text.AlignRight font.pixelSize: Theme.fontSizeSmall color: levelColor(memPct()) } } Row { width: parent.width Label { text: qsTr("Disco") width: parent.width * 0.5 font.pixelSize: Theme.fontSizeSmall color: Theme.primaryColor } Label { text: pctText(diskPct()) width: parent.width * 0.5 horizontalAlignment: Text.AlignRight font.pixelSize: Theme.fontSizeSmall color: levelColor(diskPct()) } } } Label { text: statusClient.error !== "" ? qsTr("errore") : statusClient.fetchedAt font.pixelSize: Theme.fontSizeExtraSmall color: statusClient.error !== "" ? "#e53935" : Theme.secondaryColor anchors.horizontalCenter: parent.horizontalCenter } } CoverActionList { CoverAction { iconSource: "image://theme/icon-cover-refresh" onTriggered: statusClient.refresh() } } }