diff --git a/src/dfm-base/utils/thumbnail/private/thumbnailworker_p.h b/src/dfm-base/utils/thumbnail/private/thumbnailworker_p.h index 9ee4170c27..8c2bbae679 100644 --- a/src/dfm-base/utils/thumbnail/private/thumbnailworker_p.h +++ b/src/dfm-base/utils/thumbnail/private/thumbnailworker_p.h @@ -31,8 +31,6 @@ class ThumbnailWorkerPrivate void insertUrl(const QUrl &key, const QUrl &value); QUrl takeUrl(const QUrl &key); - QIcon createIcon(const QString &iconName); - ThumbnailWorker *q { nullptr }; DMimeDatabase mimeDb; QMutex mutex; diff --git a/src/dfm-base/utils/thumbnail/thumbnailfactory.h b/src/dfm-base/utils/thumbnail/thumbnailfactory.h index e29b137afe..6803ba8eed 100644 --- a/src/dfm-base/utils/thumbnail/thumbnailfactory.h +++ b/src/dfm-base/utils/thumbnail/thumbnailfactory.h @@ -28,7 +28,7 @@ class ThumbnailFactory final : public QObject bool registerThumbnailCreator(const QString &mimeType, ThumbnailCreator creator); Q_SIGNALS: - void produceFinished(const QUrl &src, const QIcon &thumbIcon); + void produceFinished(const QUrl &src, const QString &thumb); void produceFailed(const QUrl &src); void addTask(const QUrl &url, DFMGLOBAL_NAMESPACE::ThumbnailSize size); diff --git a/src/dfm-base/utils/thumbnail/thumbnailworker.cpp b/src/dfm-base/utils/thumbnail/thumbnailworker.cpp index 78682c9510..315742b1d4 100644 --- a/src/dfm-base/utils/thumbnail/thumbnailworker.cpp +++ b/src/dfm-base/utils/thumbnail/thumbnailworker.cpp @@ -98,21 +98,6 @@ QUrl ThumbnailWorkerPrivate::takeUrl(const QUrl &key) return localAndVirtualHash.take(key); } -QIcon ThumbnailWorkerPrivate::createIcon(const QString &iconName) -{ - QIcon icon(iconName); - if (!icon.isNull()) { - QPixmap pixmap = icon.pixmap(Global::kLarge, Global::kLarge); - QPainter pa(&pixmap); - pa.setPen(Qt::gray); - pa.drawPixmap(0, 0, pixmap); - - icon.addPixmap(pixmap); - } - - return icon; -} - ThumbnailWorker::ThumbnailWorker(QObject *parent) : QObject(parent), d(new ThumbnailWorkerPrivate(this)) @@ -163,7 +148,7 @@ void ThumbnailWorker::onTaskAdded(const QUrl &url, Global::ThumbnailSize size) const auto &img = ThumbnailHelper::instance()->thumbnailImage(fileUrl, size); if (!img.isNull()) { - Q_EMIT thumbnailCreateFinished(url, d->createIcon(img.text(QT_STRINGIFY(Thumb::Path)))); + Q_EMIT thumbnailCreateFinished(url, img.text(QT_STRINGIFY(Thumb::Path))); return; } @@ -224,7 +209,7 @@ void ThumbnailWorker::doWork() // create thumbnail const auto &thumbnailPath = d->createThumbnail(task.srcUrl, task.size); if (!thumbnailPath.isEmpty()) - Q_EMIT thumbnailCreateFinished(d->takeUrl(task.srcUrl), d->createIcon(thumbnailPath)); + Q_EMIT thumbnailCreateFinished(d->takeUrl(task.srcUrl), thumbnailPath); else Q_EMIT thumbnailCreateFailed(d->takeUrl(task.srcUrl)); } diff --git a/src/dfm-base/utils/thumbnail/thumbnailworker.h b/src/dfm-base/utils/thumbnail/thumbnailworker.h index 4d4317d923..5047ea4f9c 100644 --- a/src/dfm-base/utils/thumbnail/thumbnailworker.h +++ b/src/dfm-base/utils/thumbnail/thumbnailworker.h @@ -29,7 +29,7 @@ public Q_SLOTS: void onTaskRemoved(const QUrl &url); Q_SIGNALS: - void thumbnailCreateFinished(const QUrl &url, const QIcon &thumbnail); + void thumbnailCreateFinished(const QUrl &url, const QString &thumbnail); void thumbnailCreateFailed(const QUrl &url); private: diff --git a/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel.cpp b/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel.cpp index 5505a70dda..ffef1bb698 100644 --- a/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel.cpp +++ b/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel.cpp @@ -214,7 +214,7 @@ void FileInfoModelPrivate::dataUpdated(const QUrl &url, const bool isLinkOrg) emit q->dataChanged(index, index); } -void FileInfoModelPrivate::thumbUpdated(const QUrl &url, const QIcon &thumbIcon) +void FileInfoModelPrivate::thumbUpdated(const QUrl &url, const QString &thumb) { using namespace dfmbase::Global; FileInfoPointer info { nullptr }; @@ -227,6 +227,11 @@ void FileInfoModelPrivate::thumbUpdated(const QUrl &url, const QIcon &thumbIcon) return; } + // Creating thumbnail icon in a thread may cause the program to crash + QIcon thumbIcon(thumb); + if (thumbIcon.isNull()) + return; + info->setExtendedAttributes(ExtInfoType::kFileThumbnail, thumbIcon); const QModelIndex &index = q->index(url); if (Q_UNLIKELY(!index.isValid())) diff --git a/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel_p.h b/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel_p.h index dc233d966a..2b7107cbcc 100644 --- a/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel_p.h +++ b/src/plugins/desktop/core/ddplugin-canvas/model/fileinfomodel_p.h @@ -32,7 +32,7 @@ public slots: void replaceData(const QUrl &oldUrl, const QUrl &newUrl); void updateData(const QUrl &url); void dataUpdated(const QUrl &url, const bool isLinkOrg); - void thumbUpdated(const QUrl &url, const QIcon &thumbIcon); + void thumbUpdated(const QUrl &url, const QString &thumb); public: QDir::Filters filters = QDir::NoFilter; diff --git a/src/plugins/desktop/core/ddplugin-canvas/model/fileprovider.h b/src/plugins/desktop/core/ddplugin-canvas/model/fileprovider.h index 3c289e4196..e2e68cb6bb 100644 --- a/src/plugins/desktop/core/ddplugin-canvas/model/fileprovider.h +++ b/src/plugins/desktop/core/ddplugin-canvas/model/fileprovider.h @@ -35,7 +35,7 @@ class FileProvider : public QObject void fileRenamed(const QUrl &oldurl, const QUrl &newurl); void fileUpdated(const QUrl &url); void fileInfoUpdated(const QUrl &url, const bool isLinkOrg); - void fileThumbUpdated(const QUrl &url, const QIcon &thumb); + void fileThumbUpdated(const QUrl &url, const QString &thumb); protected slots: void traversalFinished(); void reset(QList children); diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/models/fileitemdata.cpp b/src/plugins/filemanager/core/dfmplugin-workspace/models/fileitemdata.cpp index 9d485dae8f..cc8518de07 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/models/fileitemdata.cpp +++ b/src/plugins/filemanager/core/dfmplugin-workspace/models/fileitemdata.cpp @@ -20,6 +20,8 @@ FileItemData::FileItemData(const QUrl &url, const FileInfoPointer &info, FileIte url(url), info(info) { + if (info) + info->customData(kItemFileRefreshIcon); } FileItemData::FileItemData(const SortInfoPointer &info, FileItemData *parent) @@ -85,8 +87,11 @@ QVariant FileItemData::data(int role) const switch (role) { case kItemCreateFileInfoRole: assert(qApp->thread() == QThread::currentThread()); - if (info.isNull()) + if (info.isNull()) { const_cast(this)->info = InfoFactory::create(url); + if (info) + info->customData(kItemFileRefreshIcon); + } return QVariant(); case kItemFilePathRole: if (info) diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.cpp b/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.cpp index c2a7866117..59d878b47d 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.cpp +++ b/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.cpp @@ -607,7 +607,7 @@ void FileViewModel::setReadOnly(bool value) readOnly = value; } -void FileViewModel::updateThumbnailIcon(const QModelIndex &index, const QIcon &thumbIcon) +void FileViewModel::updateThumbnailIcon(const QModelIndex &index, const QString &thumb) { if (!index.isValid() || index.row() < 0 || filterSortWorker.isNull()) return; @@ -623,16 +623,21 @@ void FileViewModel::updateThumbnailIcon(const QModelIndex &index, const QIcon &t if (!item || !item->fileInfo()) return; + // Creating thumbnail icon in a thread may cause the program to crash + QIcon thumbIcon(thumb); + if (thumbIcon.isNull()) + return; + item->fileInfo()->setExtendedAttributes(ExtInfoType::kFileThumbnail, thumbIcon); } -void FileViewModel::onFileThumbUpdated(const QUrl &url, const QIcon &thumbIcon) +void FileViewModel::onFileThumbUpdated(const QUrl &url, const QString &thumb) { auto updateIndex = getIndexByUrl(url); if (!updateIndex.isValid()) return; - updateThumbnailIcon(updateIndex, thumbIcon); + updateThumbnailIcon(updateIndex, thumb); auto view = qobject_cast(QObject::parent()); if (view) { view->update(updateIndex); diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.h b/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.h index 93289a82bd..ff725424c2 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.h +++ b/src/plugins/filemanager/core/dfmplugin-workspace/models/fileviewmodel.h @@ -89,7 +89,7 @@ class FileViewModel : public QAbstractItemModel void toggleHiddenFiles(); void setReadOnly(bool value); - void updateThumbnailIcon(const QModelIndex &index, const QIcon &thumbIcon); + void updateThumbnailIcon(const QModelIndex &index, const QString &thumb); Q_SIGNALS: void stateChanged(); @@ -112,7 +112,7 @@ class FileViewModel : public QAbstractItemModel void requestSetFilterCallback(FileViewFilterCallback callback); public Q_SLOTS: - void onFileThumbUpdated(const QUrl &url, const QIcon &thumbIcon); + void onFileThumbUpdated(const QUrl &url, const QString &thumb); void onFileUpdated(int show); void onInsert(int firstIndex, int count); void onInsertFinish();