Verified Commit 8324f118 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

wallpapers/image: Move suffix check to suffixcheck.cpp

Will be used in finders.
parent ad0578e7
SPDX-FileCopyrightText: 2007 Paolo Capriotti <>
SPDX-License-Identifier: GPL-2.0-or-later
#include "suffixcheck.h"
#include <mutex>
#include <QImageReader>
#include <QMimeDatabase>
#include <QSet>
static QStringList s_suffixes;
static std::mutex s_suffixMutex;
QStringList suffixes()
std::lock_guard lock(s_suffixMutex);
if (s_suffixes.empty()) {
QSet<QString> suffixeSet;
QMimeDatabase db;
const auto supportedMimeTypes = QImageReader::supportedMimeTypes();
for (const QByteArray &mimeType : supportedMimeTypes) {
QMimeType mime(db.mimeTypeForName(QString::fromLatin1(mimeType)));
const QStringList globPatterns = mime.globPatterns();
for (const QString &pattern : globPatterns) {
s_suffixes = suffixeSet.values();
return s_suffixes;
bool isAcceptableSuffix(const QString &suffix)
// Despite its name, suffixes() returns a list of glob patterns.
// Therefore the file suffix check needs to include the "*." prefix.
const QStringList &globPatterns = suffixes();
return globPatterns.contains(QLatin1String("*.") + suffix.toLower());
SPDX-FileCopyrightText: 2007 Paolo Capriotti <>
SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QStringList>
QStringList suffixes();
* Check if the image format is supported by QImageReader.
* @return @p true if the format is supported, @p false otherwise.
bool isAcceptableSuffix(const QString &suffix);
Supports Markdown
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