10#include <QtConcurrentRun>
11#include <QApplication>
12#include <QGlobalStatic>
13#include <QFutureWatcher>
23 struct GetFileIconParameters
27 qreal m_devicePixelRatioF;
33 struct IconFetchResult
35 bool m_iconWasFetchedOk =
false;
47 IconFetchResult getFileIcon(GetFileIconParameters gfip)
50 IconFetchResult iconFetched;
51 iconFetched.m_documentUrl = gfip.m_documentUrl;
52 iconFetched.m_iconWasFetchedOk = iconCreator.
createFileIcon(gfip.m_documentUrl.toLocalFile(),
54 gfip.m_devicePixelRatioF,
73 if (QThread::idealThreadCount() > 2) {
88 if (QThread::currentThread() != qApp->thread()) {
89 qWarning() <<
"KisRecentFileIconCache::instance() called from non-GUI thread!";
97 const QMap<QUrl, CacheItem>::const_iterator findItem =
m_iconCacheMap.constFind(url);
100 return findItem.value().cachedIcon;
102 if (!url.isLocalFile()) {
107 const GetFileIconParameters param = {
113 auto *watcher =
new QFutureWatcher<IconFetchResult>(
this);
114 watcher->setFuture(future);
115 connect(watcher, SIGNAL(finished()), SLOT(
iconFetched()));
117 const CacheItem cacheItem = { url, future, QIcon() };
125 QMap<QUrl, CacheItem>::iterator findItem =
m_iconCacheMap.find(url);
131 if (!findItem.value().fetchingFuture.isCanceled()) {
132 findItem.value().fetchingFuture.cancel();
153 auto *watcher =
dynamic_cast<QFutureWatcher<IconFetchResult> *
>(QObject::sender());
155 qWarning() <<
"KisRecentFileIconCache::iconFetched() called but sender is not a QFutureWatcher";
159 watcher->deleteLater();
160 IconFetchResult result = future.result();
163 qWarning() <<
"KisRecentFileIconCache item not found!";
166#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
167 if (findItem.value().fetchingFuture != future) {
168 qWarning() <<
"KisRecentFileIconCache item has a different QFuture";
173 if (result.m_iconWasFetchedOk) {
174 findItem.value().cachedIcon = result.m_icon;
181 auto *watcher =
dynamic_cast<QFutureWatcher<IconFetchResult> *
>(QObject::sender());
183 qWarning() <<
"KisRecentFileIconCache::futureCanceled() called but sender is not a QFutureWatcher";
186 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