Skip to content

Commit

Permalink
fix: [crash] fix thumbnail crash
Browse files Browse the repository at this point in the history
[crash] fix thumbnail crash

Log: [crash] fix thumbnail crash
  • Loading branch information
pppanghu77 committed Aug 21, 2024
1 parent e47de28 commit 6cdc9d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/dfm-base/mimetype/mimetypedisplaymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class MimeTypeDisplayManager : public QObject
FileInfo::FileType displayNameToEnum(const QString &mimeType);
QString defaultIcon(const QString &mimeType);
QMap<FileInfo::FileType, QString> displayNames();
void loadSupportMimeTypes();
QStringList supportArchiveMimetypes();
QStringList supportVideoMimeTypes();
QStringList supportAudioMimeTypes();

private:
explicit MimeTypeDisplayManager(QObject *parent = nullptr);
void initData();
void loadSupportMimeTypes();
QStringList readlines(const QString &path);

private:
Expand Down
17 changes: 11 additions & 6 deletions src/dfm-base/utils/thumbnail/thumbnailhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DFMGLOBAL_USE_NAMESPACE

ThumbnailHelper::ThumbnailHelper()
{
QObject::connect(this, &ThumbnailHelper::saveImage, this, &ThumbnailHelper::onSaveImage, Qt::QueuedConnection);
}

void ThumbnailHelper::initSizeLimit()
Expand Down Expand Up @@ -141,12 +142,16 @@ QString ThumbnailHelper::saveThumbnail(const QUrl &url, const QImage &img, Thumb
tmpImg.setText(QT_STRINGIFY(Thumb::MTime), QString::number(fileModify));

makePath(thumbnailPath);
emit saveImage(tmpImg, thumbnailFilePath, fileUrl);

return thumbnailFilePath;
}

void ThumbnailHelper::onSaveImage(const QImage &tmpImg, const QString &thumbnailFilePath, const QString &fileUrl)
{
if (!tmpImg.save(thumbnailFilePath, Q_NULLPTR, 50)) {
qCWarning(logDFMBase) << "thumbnail: save failed." << fileUrl;
return "";
}

return thumbnailFilePath;
}

QImage ThumbnailHelper::thumbnailImage(const QUrl &fileUrl, ThumbnailSize size)
Expand Down Expand Up @@ -232,10 +237,10 @@ bool ThumbnailHelper::checkThumbEnable(const QUrl &url)
return false;
}

bool enable{ true };
if (FileUtils::isMtpFile(fileUrl)) { // 是否是mtpfile
bool enable { true };
if (FileUtils::isMtpFile(fileUrl)) { // 是否是mtpfile
enable = DConfigManager::instance()->value("org.deepin.dde.file-manager.preview", "mtpThumbnailEnable", true).toBool();
} else if (DevProxyMng->isFileOfProtocolMounts(fileUrl.path())) { // 是否是协议设备
} else if (DevProxyMng->isFileOfProtocolMounts(fileUrl.path())) { // 是否是协议设备
enable = Application::instance()->genericAttribute(Application::kShowThunmbnailInRemote).toBool();
}

Expand Down
7 changes: 6 additions & 1 deletion src/dfm-base/utils/thumbnail/thumbnailhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

namespace dfmbase {

class ThumbnailHelper
class ThumbnailHelper : public QObject
{
Q_OBJECT
public:
explicit ThumbnailHelper();
void initSizeLimit();
Expand All @@ -34,9 +35,13 @@ class ThumbnailHelper
static QString sizeToFilePath(DFMGLOBAL_NAMESPACE::ThumbnailSize size);
static QByteArray dataToMd5Hex(const QByteArray &data);

Q_SIGNALS:
void saveImage(const QImage &tmpImg, const QString &thumbnailFilePath, const QString &fileUrl);

private:
bool checkMimeTypeSupport(const QMimeType &mime);
void makePath(const QString &path);
void onSaveImage(const QImage &tmpImg, const QString &thumbnailFilePath, const QString &fileUrl);

private:
DMimeDatabase mimeDatabase;
Expand Down

0 comments on commit 6cdc9d1

Please sign in to comment.