diff options
Diffstat (limited to 'plugin/src/Caelestia/cachingimagemanager.cpp')
| -rw-r--r-- | plugin/src/Caelestia/cachingimagemanager.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/plugin/src/Caelestia/cachingimagemanager.cpp b/plugin/src/Caelestia/cachingimagemanager.cpp index d549e8c..d95af27 100644 --- a/plugin/src/Caelestia/cachingimagemanager.cpp +++ b/plugin/src/Caelestia/cachingimagemanager.cpp @@ -70,34 +70,33 @@ void CachingImageManager::setPath(const QString& path) { if (!path.isEmpty()) { QThreadPool::globalInstance()->start([path, this] { - const QString filename = QString("%1@%2x%3.png") - .arg(sha256sum(path)) - .arg(effectiveWidth()) - .arg(effectiveHeight()); + const QString sha = sha256sum(path); - m_cachePath = m_cacheDir.resolved(QUrl(filename)); - emit cachePathChanged(); + QMetaObject::invokeMethod(this, [path, sha, this]() { + const QString filename = QString("%1@%2x%3.png") + .arg(sha) + .arg(effectiveWidth()) + .arg(effectiveHeight()); - if (!m_cachePath.isLocalFile()) { - qWarning() << "CachingImageManager::setPath: cachePath" << m_cachePath << "is not a local file"; - return; - } + m_cachePath = m_cacheDir.resolved(QUrl(filename)); + emit cachePathChanged(); - if (QFile::exists(m_cachePath.toLocalFile())) { - QMetaObject::invokeMethod(m_item, [this]() { - m_item->setProperty("source", m_cachePath); - }, Qt::QueuedConnection); + if (!m_cachePath.isLocalFile()) { + qWarning() << "CachingImageManager::setPath: cachePath" << m_cachePath << "is not a local file"; + return; + } - m_usingCache = true; - emit usingCacheChanged(); - } else { - QMetaObject::invokeMethod(m_item, [path, this]() { + bool cacheExists = QFile::exists(m_cachePath.toLocalFile()); + + if (cacheExists) { + m_item->setProperty("source", m_cachePath); + } else { m_item->setProperty("source", QUrl::fromLocalFile(path)); - }, Qt::QueuedConnection); + } - m_usingCache = false; + m_usingCache = cacheExists; emit usingCacheChanged(); - } + }); }); } } |