import QtQuick 2.0 import Sailfish.Silica 1.0 // Dettaglio della card Memoria: chi occupa la RAM, dal più grande. // La fonte è la memoria ANONIMA dei cgroup: con hidepid=invisible i processi // degli altri utenti non sono leggibili da /proc, quindi l'unità di misura è // il servizio o il contenitore, non il singolo PID. Page { id: page allowedOrientations: Orientation.All function list() { var d = statusClient.data if (!d || !d.memory || !d.memory.consumers) return [] return d.memory.consumers } function totalBytes() { var d = statusClient.data return (d && d.memory && d.memory.total_bytes) ? d.memory.total_bytes : 0 } function maxBytes() { var l = list() return (l.length > 0 && l[0].bytes > 0) ? l[0].bytes : 1 } function sharePct(bytes) { var t = totalBytes() return t > 0 ? bytes / t * 100 : 0 } function usedText() { var d = statusClient.data if (!d || !d.memory) return "" return qsTr("usata ") + statusClient.fmtNum(d.memory.percent, 0) + "% · " + qsTr("su ") + statusClient.fmtBytes(d.memory.total_bytes) } SilicaListView { id: view anchors.fill: parent model: page.list() PullDownMenu { MenuItem { text: qsTr("Aggiorna") onClicked: statusClient.refresh() } } header: Column { width: view.width spacing: Theme.paddingSmall PageHeader { title: qsTr("Memoria") } Label { x: Theme.paddingLarge width: parent.width - 2 * Theme.paddingLarge text: statusClient.busy ? qsTr("aggiornamento…") : qsTr("aggiornato alle ") + statusClient.fetchedAt font.pixelSize: Theme.fontSizeExtraSmall color: statusClient.error !== "" ? "#e53935" : Theme.secondaryColor } Label { x: Theme.paddingLarge width: parent.width - 2 * Theme.paddingLarge text: page.usedText() font.pixelSize: Theme.fontSizeSmall color: Theme.secondaryColor } Label { x: Theme.paddingLarge width: parent.width - 2 * Theme.paddingLarge text: qsTr("Memoria anonima per servizio e contenitore, ordinata dal più grande.") font.pixelSize: Theme.fontSizeExtraSmall color: Theme.secondaryColor wrapMode: Text.WordWrap } Item { width: 1; height: Theme.paddingSmall } } delegate: Column { x: Theme.paddingLarge width: view.width - 2 * Theme.paddingLarge spacing: Theme.paddingSmall / 2 Row { width: parent.width Label { text: modelData.name + (modelData.kind === "container" ? qsTr(" · contenitore") : "") width: parent.width * 0.50 font.pixelSize: Theme.fontSizeSmall truncationMode: TruncationMode.Fade } Label { text: statusClient.fmtBytes(modelData.bytes) width: parent.width * 0.32 horizontalAlignment: Text.AlignRight font.pixelSize: Theme.fontSizeSmall color: Theme.highlightColor } Label { text: statusClient.fmtNum(page.sharePct(modelData.bytes), 1) + "%" width: parent.width * 0.18 horizontalAlignment: Text.AlignRight font.pixelSize: Theme.fontSizeExtraSmall color: Theme.secondaryColor } } // Barra relativa al primo della lista: serve a confrontare le // grandezze fra loro, mentre la percentuale è sul totale della RAM. Rectangle { width: parent.width * Math.max(2, Math.min(100, modelData.bytes / page.maxBytes() * 100)) / 100 height: 3 radius: 1.5 color: Theme.rgba(Theme.highlightColor, 0.5) } } footer: Column { width: view.width spacing: Theme.paddingSmall Label { x: Theme.paddingLarge width: parent.width - 2 * Theme.paddingLarge text: qsTr("Sono esclusi cache, slab e memoria non attribuita a un servizio: per questo la somma è minore della RAM usata.") font.pixelSize: Theme.fontSizeExtraSmall color: Theme.secondaryColor wrapMode: Text.WordWrap } Item { width: 1; height: Theme.paddingLarge } } ViewPlaceholder { enabled: page.list().length === 0 text: qsTr("Nessun dato") hintText: qsTr("Lo snapshot del server non è ancora arrivato") } } }