10#include <QtConcurrent>
11#include <QApplication>
12#include <QGlobalStatic>
22 struct GetFileIconParameters
26 qreal m_devicePixelRatioF;
32 struct IconFetchResult
34 bool m_iconWasFetchedOk =
false;
46 IconFetchResult getFileIcon(GetFileIconParameters gfip)
49 IconFetchResult iconFetched;
50 iconFetched.m_documentUrl = gfip.m_documentUrl;
51 iconFetched.m_iconWasFetchedOk = iconCreator.
createFileIcon(gfip.m_documentUrl.toLocalFile(),
53 gfip.m_devicePixelRatioF,
72 if (QThread::idealThreadCount() > 2) {
87 if (QThread::currentThread() != qApp->thread()) {
88 qWarning() <<
"KisRecentFileIconCache::instance() called from non-GUI thread!";
96 const QMap<QUrl, CacheItem>::const_iterator findItem =
m_iconCacheMap.constFind(url);
99 return findItem.value().cachedIcon;
101 if (!url.isLocalFile()) {
106 const GetFileIconParameters param = {
112 auto *watcher =
new QFutureWatcher<IconFetchResult>(
this);
113 watcher->setFuture(future);
114 connect(watcher, SIGNAL(finished()), SLOT(
iconFetched()));
116 const CacheItem cacheItem = { url, future, QIcon() };
124 QMap<QUrl, CacheItem>::iterator findItem =
m_iconCacheMap.find(url);
130 if (!findItem.value().fetchingFuture.isCanceled()) {
131 findItem.value().fetchingFuture.cancel();
152 auto *watcher =
dynamic_cast<QFutureWatcher<IconFetchResult> *
>(QObject::sender());
154 qWarning() <<
"KisRecentFileIconCache::iconFetched() called but sender is not a QFutureWatcher";
158 watcher->deleteLater();
159 IconFetchResult result = future.result();
162 qWarning() <<
"KisRecentFileIconCache item not found!";
165#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
166 if (findItem.value().fetchingFuture != future) {
167 qWarning() <<
"KisRecentFileIconCache item has a different QFuture";
172 if (result.m_iconWasFetchedOk) {
173 findItem.value().cachedIcon = result.m_icon;
180 auto *watcher =
dynamic_cast<QFutureWatcher<IconFetchResult> *
>(QObject::sender());
182 qWarning() <<
"KisRecentFileIconCache::futureCanceled() called but sender is not a QFutureWatcher";
185 watcher->deleteLater();
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
PythonPluginManager * instance
int iconSize(qreal width, qreal height)
The KisFileIconCreator class creates a thumbnail from a file on disk.
bool createFileIcon(QString path, QIcon &icon, qreal devicePixelRatioF, QSize iconSize) override
createFileIcon creates an icon from the file on disk
static constexpr const int ICON_SIZE_LENGTH
void fileIconChanged(const QUrl &url, const QIcon &icon)
QIcon getOrQueueFileIcon(const QUrl &url)
~KisRecentFileIconCache()
QThreadPool m_iconFetchThreadPool
float m_devicePixelRatioF
QMap< QUrl, CacheItem > m_iconCacheMap
void invalidateFileIcon(const QUrl &url)
void reloadFileIcon(const QUrl &url)
QFuture< IconFetchResult > fetchingFuture