mirror of
https://github.com/logos-storage/logos-storage-app-skeleton.git
synced 2026-06-14 20:39:27 +00:00
Move formatBytes into a util file
This commit is contained in:
parent
78cbfd2be6
commit
592abb3f84
@ -161,6 +161,7 @@ qt_add_qml_module(appqml
|
||||
NodeHeader.qml
|
||||
Widgets.qml
|
||||
DebugPanel.qml
|
||||
Utils.js
|
||||
)
|
||||
|
||||
# Set up QML module directory for runtime
|
||||
|
||||
@ -2,6 +2,7 @@ import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Logos.Theme
|
||||
import Logos.Controls
|
||||
import "Utils.js" as Utils
|
||||
|
||||
ArcWidget {
|
||||
id: root
|
||||
@ -12,26 +13,6 @@ ArcWidget {
|
||||
|
||||
fraction: root.total > 0 ? Math.min(root.used / root.total, 1.0) : 0
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (bytes <= 0) {
|
||||
return "0 B"
|
||||
}
|
||||
|
||||
if (bytes < 1024) {
|
||||
return bytes + " B"
|
||||
}
|
||||
|
||||
if (bytes < 1024 * 1024) {
|
||||
return (bytes / 1024).toFixed(1) + " KB"
|
||||
}
|
||||
|
||||
if (bytes < 1024 * 1024 * 1024) {
|
||||
return (bytes / (1024 * 1024)).toFixed(1) + " MB"
|
||||
}
|
||||
|
||||
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB"
|
||||
}
|
||||
|
||||
function refreshSpace() {
|
||||
let space = root.backend.space()
|
||||
root.total = space.total
|
||||
@ -52,15 +33,14 @@ ArcWidget {
|
||||
spacing: 2
|
||||
|
||||
LogosText {
|
||||
text: root.total > 0 ? root.formatBytes(root.used) : "—"
|
||||
text: root.total > 0 ? Utils.formatBytes(root.used) : "—"
|
||||
font.pixelSize: 15
|
||||
font.bold: true
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
LogosText {
|
||||
text: root.total > 0 ? "/ " + root.formatBytes(
|
||||
root.total) : "STORAGE"
|
||||
text: root.total > 0 ? "/ " + Utils.formatBytes(root.total) : "STORAGE"
|
||||
font.pixelSize: 9
|
||||
color: Theme.palette.textTertiary
|
||||
font.letterSpacing: 1.3
|
||||
|
||||
@ -5,6 +5,7 @@ import QtQuick.Layouts
|
||||
import QtCore
|
||||
import Logos.Theme
|
||||
import Logos.Controls
|
||||
import "Utils.js" as Utils
|
||||
|
||||
// qmllint disable unqualified
|
||||
ColumnLayout {
|
||||
@ -31,17 +32,6 @@ ColumnLayout {
|
||||
onRejected: pendingManifest = null
|
||||
}
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (bytes <= 0)
|
||||
return "0 B"
|
||||
if (bytes < 1024)
|
||||
return bytes + " B"
|
||||
if (bytes < 1024 * 1024)
|
||||
return (bytes / 1024).toFixed(1) + " KB"
|
||||
if (bytes < 1024 * 1024 * 1024)
|
||||
return (bytes / (1024 * 1024)).toFixed(1) + " MB"
|
||||
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB"
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: root.backend
|
||||
@ -189,7 +179,7 @@ ColumnLayout {
|
||||
}
|
||||
Text {
|
||||
width: 80
|
||||
text: root.formatBytes(parseInt(modelData.datasetSize))
|
||||
text: Utils.formatBytes(parseInt(modelData.datasetSize))
|
||||
color: Theme.palette.textSecondary
|
||||
font.pixelSize: 11
|
||||
elide: Text.ElideRight
|
||||
|
||||
@ -18,12 +18,10 @@ ArcWidget {
|
||||
fraction: root.uploadProgress / 100.0
|
||||
fillColor: root.isDone ? Theme.palette.success : Theme.palette.text
|
||||
|
||||
// ── Center content ────────────────────────────────────────────────────────
|
||||
ColumnLayout {
|
||||
anchors.centerIn: parent
|
||||
spacing: 2
|
||||
|
||||
// Idle or done: upload icon
|
||||
UploadIcon {
|
||||
dotColor: Theme.palette.textSecondary
|
||||
dotSize: 4
|
||||
|
||||
13
src/qml/Utils.js
Normal file
13
src/qml/Utils.js
Normal file
@ -0,0 +1,13 @@
|
||||
.pragma library
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (bytes <= 0)
|
||||
return "0 B"
|
||||
if (bytes < 1024)
|
||||
return bytes + " B"
|
||||
if (bytes < 1024 * 1024)
|
||||
return (bytes / 1024).toFixed(1) + " KB"
|
||||
if (bytes < 1024 * 1024 * 1024)
|
||||
return (bytes / (1024 * 1024)).toFixed(1) + " MB"
|
||||
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB"
|
||||
}
|
||||
@ -35,6 +35,7 @@
|
||||
<file alias="DownloadIcon.qml">qml/icons/DownloadIcon.qml</file>
|
||||
<file alias="DeleteIcon.qml">qml/icons/DeleteIcon.qml</file>
|
||||
<file alias="ArcWidget.qml">qml/icons/ArcWidget.qml</file>
|
||||
<file alias="Utils.js">qml/Utils.js</file>
|
||||
<file>icons/storage.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user