diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt
index d8dbc8a..7eda09a 100644
--- a/src/qml/CMakeLists.txt
+++ b/src/qml/CMakeLists.txt
@@ -161,6 +161,7 @@ qt_add_qml_module(appqml
NodeHeader.qml
Widgets.qml
DebugPanel.qml
+ Utils.js
)
# Set up QML module directory for runtime
diff --git a/src/qml/DiskWidget.qml b/src/qml/DiskWidget.qml
index 1d561f6..76fbb41 100644
--- a/src/qml/DiskWidget.qml
+++ b/src/qml/DiskWidget.qml
@@ -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
diff --git a/src/qml/ManifestTable.qml b/src/qml/ManifestTable.qml
index ee8d01b..14c2163 100644
--- a/src/qml/ManifestTable.qml
+++ b/src/qml/ManifestTable.qml
@@ -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
diff --git a/src/qml/UploadWidget.qml b/src/qml/UploadWidget.qml
index 3df4ea3..3d5525d 100644
--- a/src/qml/UploadWidget.qml
+++ b/src/qml/UploadWidget.qml
@@ -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
diff --git a/src/qml/Utils.js b/src/qml/Utils.js
new file mode 100644
index 0000000..f461ee6
--- /dev/null
+++ b/src/qml/Utils.js
@@ -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"
+}
diff --git a/src/storage_resources.qrc b/src/storage_resources.qrc
index 6bcdabd..419d4b1 100644
--- a/src/storage_resources.qrc
+++ b/src/storage_resources.qrc
@@ -35,6 +35,7 @@
qml/icons/DownloadIcon.qml
qml/icons/DeleteIcon.qml
qml/icons/ArcWidget.qml
+ qml/Utils.js
icons/storage.png