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) {
84 if (QThread::currentThread() != qApp->thread()) {
85 qWarning() <<
"KisRecentFileIconCache::instance() called from non-GUI thread!";
93 const QMap<QUrl, CacheItem>::const_iterator findItem =
m_iconCacheMap.constFind(url);
96 return findItem.value().cachedIcon;
98 if (!url.isLocalFile()) {
103 const GetFileIconParameters param = {
109 auto *watcher =
new QFutureWatcher<IconFetchResult>(
this);
110 watcher->setFuture(future);
113 const CacheItem cacheItem = { url, future, QIcon() };
121 QMap<QUrl, CacheItem>::iterator findItem =
m_iconCacheMap.find(url);
127 if (!findItem.value().fetchingFuture.isCanceled()) {
128 findItem.value().fetchingFuture.cancel();
149 auto *watcher =
dynamic_cast<QFutureWatcher<IconFetchResult> *
>(QObject::sender());
151 qWarning() <<
"KisRecentFileIconCache::iconFetched() called but sender is not a QFutureWatcher";
155 watcher->deleteLater();
156 IconFetchResult result = future.result();
159 qWarning() <<
"KisRecentFileIconCache item not found!";
162#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
163 if (findItem.value().fetchingFuture != future) {
164 qWarning() <<
"KisRecentFileIconCache item has a different QFuture";
169 if (result.m_iconWasFetchedOk) {
170 findItem.value().cachedIcon = result.m_icon;
177 auto *watcher =
dynamic_cast<QFutureWatcher<IconFetchResult> *
>(QObject::sender());
179 qWarning() <<
"KisRecentFileIconCache::futureCanceled() called but sender is not a QFutureWatcher";
182 watcher->deleteLater();
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
PythonPluginManager * instance
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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
QMap< QUrl, CacheItem > m_iconCacheMap
void invalidateFileIcon(const QUrl &url)
void reloadFileIcon(const QUrl &url)
QFuture< IconFetchResult > fetchingFuture