Commit f7a3318f authored by Ismael Asensio's avatar Ismael Asensio
Browse files

Detect animated format using mimeType instead of file path

This allows to extend the functionality to non-local files and avoids a warning
on such files (`QFSFileEngine::open: No file name specified`)
parent f987a1c4
......@@ -236,7 +236,7 @@ void InformationPanelContent::refreshPreview()
refreshPixmapView();
const QString mimeType = m_item.mimetype();
const bool isAnimatedImage = m_preview->isAnimatedImage(itemUrl.toLocalFile());
const bool isAnimatedImage = m_preview->isAnimatedMimeType(mimeType);
m_isVideo = !isAnimatedImage && mimeType.startsWith(QLatin1String("video/"));
bool usePhonon = m_isVideo || mimeType.startsWith(QLatin1String("audio/"));
......
......@@ -186,8 +186,9 @@ void PixmapViewer::stopAnimatedImage()
}
}
bool PixmapViewer::isAnimatedImage(const QString &fileName)
bool PixmapViewer::isAnimatedMimeType(const QString &mimeType)
{
const QByteArray imageFormat = QImageReader::imageFormat(fileName);
return !imageFormat.isEmpty() && QMovie::supportedFormats().contains(imageFormat);
const QList<QByteArray> imageFormats = QImageReader::imageFormatsForMimeType(mimeType.toUtf8());
return std::any_of(imageFormats.begin(), imageFormats.end(),
[](const QByteArray &format){ return QMovie::supportedFormats().contains(format); });
}
......@@ -80,9 +80,9 @@ public:
void stopAnimatedImage();
/**
* Checks if \a fileName contains an animated image supported by QMovie.
* Checks if \a mimeType has a format supported by QMovie.
*/
static bool isAnimatedImage(const QString &fileName);
static bool isAnimatedMimeType(const QString &mimeType);
protected:
void paintEvent(QPaintEvent* event) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment