This is a rewrite of Lomiri's WallpaperResolver that takes its image candidates and loads each sequentially.
At its base level, what I've created is a Pure-QML solution that takes a long list of potentially valid images as candidates
, then loads each one in sequence. Once a valid image is found, it is returned as background
. If no valid image is found, the last item in candidates
is returned.
I built it to prevent redundant image loading inside Lomiri. The current WallpaperResolver has the same goal as this: return the first valid image in a list. It achieves its goal by taking each image that is passed in and loading it as a member of a Repeater. This is great, but it means that every potential image is loaded, not just the first valid image. If three valid images were passed in, the first was returned but the other two loaded anyway! What's worse, the entire Shell's creation hung on this process since the binding required that the entire Repeater was available and was assigned at startup. What a waste.
This solution is good, I think. It only loads the first image. However, it's pretty complex. Due to optimizations inside Qt, we need to avoid setting the Image's source to the same value twice, and we need to avoid setting it to an invalid value at all costs. Otherwise, the Image's source doesn't actually change and resolution never completes.
However, I'm not sure if this complex of a solution is required when we only have two images to load at any time. While we pass in three candidates, we don't need to load the last one since we assume that it's always loadable. That's a much easier change to make.
We can also set asynchronous: true
on the remaining images to cause them to load in parallel. That will cause the slowest-loading image, rather than the total time of each image, to be the primary slowdown. That requires a change to make the image loading look a little smoother (right now it just flashes on screen), but it's perfectly doable.
So it's here as a gist rather than a PR.