summaryrefslogtreecommitdiff
path: root/widgets/CachingImage.qml
diff options
context:
space:
mode:
authorTim Hämisch <haemtim@gmail.com>2025-06-13 17:49:49 +0200
committerGitHub <noreply@github.com>2025-06-13 17:49:49 +0200
commit5fb727a4c8d9e89acc63a1c353202423bc7b120e (patch)
tree28839211a383025df53168993d090cdccaa9bf7a /widgets/CachingImage.qml
parentAdd shutdown, reboot, and logout actions to launcher (diff)
parentdocs: add contributing.md (diff)
downloadcaelestia-shell-5fb727a4c8d9e89acc63a1c353202423bc7b120e.tar.gz
caelestia-shell-5fb727a4c8d9e89acc63a1c353202423bc7b120e.tar.bz2
caelestia-shell-5fb727a4c8d9e89acc63a1c353202423bc7b120e.zip
Merge branch 'caelestia-dots:main' into betteractions
Diffstat (limited to 'widgets/CachingImage.qml')
-rw-r--r--widgets/CachingImage.qml42
1 files changed, 39 insertions, 3 deletions
diff --git a/widgets/CachingImage.qml b/widgets/CachingImage.qml
index cd164b4..3382615 100644
--- a/widgets/CachingImage.qml
+++ b/widgets/CachingImage.qml
@@ -1,14 +1,50 @@
import "root:/services"
+import "root:/utils"
+import Quickshell.Io
import QtQuick
Image {
id: root
property string path
- property bool loadOriginal
- readonly property Thumbnailer.Thumbnail thumbnail: Thumbnailer.go(this)
+ property string hash
+ readonly property string cachePath: `${Paths.imagecache}/${hash}@${width}x${height}.png`.slice(7)
- source: thumbnail.path ? `file://${thumbnail.path}` : ""
asynchronous: true
+ cache: false
fillMode: Image.PreserveAspectCrop
+ sourceSize.width: width
+ sourceSize.height: height
+
+ onPathChanged: {
+ shaProc.signal(9);
+ shaProc.path = path.replace("file://", "");
+ shaProc.running = true;
+ }
+
+ onCachePathChanged: {
+ if (hash)
+ source = cachePath;
+ }
+
+ onStatusChanged: {
+ if (source == cachePath && status === Image.Error)
+ source = path;
+ else if (source == path && status === Image.Ready) {
+ Paths.mkdir(Paths.imagecache);
+ const grabPath = cachePath;
+ grabToImage(res => res.saveToFile(grabPath));
+ }
+ }
+
+ Process {
+ id: shaProc
+
+ property string path
+
+ command: ["sha256sum", path]
+ stdout: SplitParser {
+ onRead: data => root.hash = data.split(" ")[0]
+ }
+ }
}