diff options
| -rw-r--r-- | modules/background/Wallpaper.qml | 1 | ||||
| -rw-r--r-- | services/Thumbnailer.qml | 54 | ||||
| -rw-r--r-- | widgets/CachingImage.qml | 16 |
3 files changed, 28 insertions, 43 deletions
diff --git a/modules/background/Wallpaper.qml b/modules/background/Wallpaper.qml index 78624d5..af71da6 100644 --- a/modules/background/Wallpaper.qml +++ b/modules/background/Wallpaper.qml @@ -41,6 +41,7 @@ Item { anchors.fill: parent + loadOriginal: true asynchronous: true cache: false fillMode: Image.PreserveAspectCrop diff --git a/services/Thumbnailer.qml b/services/Thumbnailer.qml index 3b22ada..3d7a6c1 100644 --- a/services/Thumbnailer.qml +++ b/services/Thumbnailer.qml @@ -11,11 +11,12 @@ Singleton { readonly property string thumbDir: `${StandardPaths.standardLocations(StandardPaths.GenericCacheLocation)[0]}/caelestia/thumbnails`.slice(7) - function go(path: string, width: int, height: int): var { - return thumbComp.createObject(root, { - originalPath: path, - width: width, - height: height + function go(obj: var): var { + return thumbComp.createObject(obj, { + originalPath: obj.path, + width: obj.width, + height: obj.height, + loadOriginal: obj.loadOriginal }); } @@ -25,46 +26,41 @@ Singleton { required property string originalPath required property int width required property int height + required property bool loadOriginal property string path - readonly property Process shaProc: Process { + readonly property Process proc: Process { running: true - command: ["sha1sum", obj.originalPath] - stdout: SplitParser { - onRead: data => { - const sha = data.split(" ")[0]; - obj.path = `${root.thumbDir}/${sha}@${obj.width}x${obj.height}-exact.png`; - obj.thumbProc.signal(9); - obj.thumbProc.running = true; - } - } - } - - readonly property Process thumbProc: Process { command: ["fish", "-c", ` -if test -f ${obj.path} - exit 1 +set -l path "${root.thumbDir}/$(sha1sum ${obj.originalPath} | cut -d ' ' -f 1)@${obj.width}x${obj.height}-exact.png" +if test -f $path + echo $path else + echo 'start' set -l size (identify -ping -format '%w\n%h' ${obj.originalPath}) if test $size[1] -gt ${obj.width} -o $size[2] -gt ${obj.height} - magick ${obj.originalPath} -${obj.width > 1024 || obj.height > 1024 ? "resize" : "thumbnail"} ${obj.width}x${obj.height}^ -background none -gravity center -extent ${obj.width}x${obj.height} -unsharp 0x.5 ${obj.path} + magick ${obj.originalPath} -${obj.width > 1024 || obj.height > 1024 ? "resize" : "thumbnail"} ${obj.width}x${obj.height}^ -background none -gravity center -extent ${obj.width}x${obj.height} -unsharp 0x.5 $path else - cp ${obj.originalPath} ${obj.path} + cp ${obj.originalPath} $path end + echo $path end`] - onExited: code => { - if (code === 0) { - const path = obj.path; - obj.path = ""; - obj.path = path; + stdout: SplitParser { + onRead: data => { + if (data === "start") { + if (obj.loadOriginal) + obj.path = obj.originalPath; + } else { + obj.path = data; + } } } } function reload(): void { - shaProc.signal(9); - shaProc.running = true; + proc.signal(9); + proc.running = true; } } diff --git a/widgets/CachingImage.qml b/widgets/CachingImage.qml index 08be473..0622d69 100644 --- a/widgets/CachingImage.qml +++ b/widgets/CachingImage.qml @@ -6,22 +6,10 @@ Image { id: root property string path - readonly property Thumbnailer.Thumbnail thumbnail: Thumbnailer.go(path, width, height) + property bool loadOriginal + readonly property Thumbnailer.Thumbnail thumbnail: Thumbnailer.go(this) source: thumbnail.path ? `file://${thumbnail.path}` : "" asynchronous: true fillMode: Image.PreserveAspectCrop - - onPathChanged: { - thumbnail.originalPath = path; - thumbnail.reload(); - } - onWidthChanged: { - thumbnail.width = width; - thumbnail.reload(); - } - onHeightChanged: { - thumbnail.height = height; - thumbnail.reload(); - } } |