From cbe52b0a7f1cd0b776a7fa5925eaba93ac47be4a Mon Sep 17 00:00:00 2001 From: Oleg Solovyov Date: Thu, 20 Apr 2023 10:45:17 +0300 Subject: [PATCH 1/2] image plugin: reload image from disk when it was replaced Affects both wallpaper and screenlocker background --- .../image/imagepackage/contents/ui/ImageStackView.qml | 1 + wallpapers/image/plugin/utils/mediaproxy.cpp | 10 ++++++++++ wallpapers/image/plugin/utils/mediaproxy.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/wallpapers/image/imagepackage/contents/ui/ImageStackView.qml b/wallpapers/image/imagepackage/contents/ui/ImageStackView.qml index 01d6409866..ee36b12b5b 100644 --- a/wallpapers/image/imagepackage/contents/ui/ImageStackView.qml +++ b/wallpapers/image/imagepackage/contents/ui/ImageStackView.qml @@ -136,6 +136,7 @@ QQC2.StackView { targetSize: view.sourceSize + onModelImageChanged: loadImageImmediately(); onActualSizeChanged: Qt.callLater(loadImage); onColorSchemeChanged: loadImageImmediately(); } diff --git a/wallpapers/image/plugin/utils/mediaproxy.cpp b/wallpapers/image/plugin/utils/mediaproxy.cpp index da85272d9e..011e572f70 100644 --- a/wallpapers/image/plugin/utils/mediaproxy.cpp +++ b/wallpapers/image/plugin/utils/mediaproxy.cpp @@ -29,7 +29,13 @@ MediaProxy::MediaProxy(QObject *parent) : QObject(parent) , m_targetSize(qGuiApp->primaryScreen()->size() * qGuiApp->primaryScreen()->devicePixelRatio()) , m_isDarkColorScheme(isDarkColorScheme()) + , m_dirWatch(new KDirWatch(this)) { + connect(m_dirWatch, &KDirWatch::created, [&](const QString &file) { + if (file == m_source.toLocalFile()) { + Q_EMIT modelImageChanged(); + } + }); } void MediaProxy::classBegin() @@ -70,7 +76,11 @@ void MediaProxy::setSource(const QString &url) return; } + if (!m_source.isEmpty()) { + m_dirWatch->removeFile(m_source.toLocalFile()); + } m_source = sanitizedUrl; + m_dirWatch->addFile(m_source.toLocalFile()); Q_EMIT sourceChanged(); determineProviderType(); diff --git a/wallpapers/image/plugin/utils/mediaproxy.h b/wallpapers/image/plugin/utils/mediaproxy.h index b17c699a0e..ea3d0ee99b 100644 --- a/wallpapers/image/plugin/utils/mediaproxy.h +++ b/wallpapers/image/plugin/utils/mediaproxy.h @@ -6,6 +6,8 @@ #pragma once +#include + #include #include #include @@ -151,6 +153,7 @@ private: QColor m_customColor = Qt::transparent; bool m_isDarkColorScheme; + KDirWatch *m_dirWatch; friend class ImageFrontendTest; }; -- GitLab From bdbe9b33a82888dec9a845f4604aa713dae2d74d Mon Sep 17 00:00:00 2001 From: Oleg Solovyov Date: Fri, 21 Apr 2023 13:28:19 +0300 Subject: [PATCH 2/2] image plugin: reload configured image if it did not exist on startup --- wallpapers/image/plugin/utils/mediaproxy.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wallpapers/image/plugin/utils/mediaproxy.cpp b/wallpapers/image/plugin/utils/mediaproxy.cpp index 011e572f70..d45e867629 100644 --- a/wallpapers/image/plugin/utils/mediaproxy.cpp +++ b/wallpapers/image/plugin/utils/mediaproxy.cpp @@ -33,7 +33,12 @@ MediaProxy::MediaProxy(QObject *parent) { connect(m_dirWatch, &KDirWatch::created, [&](const QString &file) { if (file == m_source.toLocalFile()) { - Q_EMIT modelImageChanged(); + if (m_providerType == Provider::Type::Unknown) { + m_source.clear(); + setSource(file); + } + Q_EMIT modelImageChanged(); + return; } }); } -- GitLab