summaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/CachingImage.qml45
1 files changed, 45 insertions, 0 deletions
diff --git a/widgets/CachingImage.qml b/widgets/CachingImage.qml
new file mode 100644
index 0000000..cff5676
--- /dev/null
+++ b/widgets/CachingImage.qml
@@ -0,0 +1,45 @@
+import "root:/services"
+import Quickshell.Io
+import QtQuick
+
+Image {
+ id: root
+
+ required property string path
+ property string thumbnail: path
+
+ source: `file://${thumbnail}`
+ asynchronous: true
+ fillMode: Image.PreserveAspectCrop
+
+ onPathChanged: shaProc.running = true
+ onWidthChanged: shaProc.running = true
+ onHeightChanged: shaProc.running = true
+ onStatusChanged: {
+ if (status === Image.Error)
+ waitProc.running = true;
+ }
+
+ Process {
+ id: shaProc
+
+ command: ["sha1sum", root.path]
+ stdout: SplitParser {
+ onRead: data => root.thumbnail = Thumbnailer.go(data.split(" ")[0], root.path, root.width, root.height)
+ }
+ }
+
+ Process {
+ id: waitProc
+
+ command: ["inotifywait", "-q", "-e", "close_write", "--format", "%w%f", "-m", root.thumbnail.slice(0, root.thumbnail.lastIndexOf("/"))]
+ stdout: SplitParser {
+ onRead: file => {
+ if (file === root.thumbnail) {
+ root.source = file;
+ waitProc.running = false;
+ }
+ }
+ }
+ }
+}