summaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-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]
+ }
+ }
}