Add missing #pragma once + missing include * speeds up incremental builds as changes to a header will not always need the full mocs_compilation.cpp for all the target's headers rebuild, while having a moc file sourced into a source file only adds minor extra costs, due to small own code and the used headers usually already covered by the source file, being for the same class/struct * seems to not slow down clean builds, due to empty mocs_compilation.cpp resulting in those quickly processed, while the minor extra cost of the sourced moc files does not outweigh that in summary. Measured times actually improved by some percent points. (ideally CMake would just skip empty mocs_compilation.cpp & its object file one day) * enables compiler to see all methods of a class in same compilation unit to do some sanity checks * potentially more inlining in general, due to more in the compilation unit * allows to keep using more forward declarations in the header, as with the moc code being sourced into the cpp file there definitions can be ensured and often are already for the needs of the normal class methods
117 lines
3.4 KiB
C++
117 lines
3.4 KiB
C++
// SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
|
|
// SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
|
|
|
|
#include "filetypesingleton.h"
|
|
#include <QImageReader>
|
|
#include <QMovie>
|
|
|
|
static QStringList byteArrayListToStringList(const QByteArrayList &byteArrayList)
|
|
{
|
|
QStringList stringList;
|
|
for (const QByteArray &byteArray : byteArrayList) {
|
|
stringList.append(QString::fromLocal8Bit(byteArray));
|
|
}
|
|
return stringList;
|
|
}
|
|
|
|
class FileTypeSingletonPrivate
|
|
{
|
|
Q_DECLARE_PUBLIC(FileTypeSingleton)
|
|
Q_DISABLE_COPY(FileTypeSingletonPrivate)
|
|
public:
|
|
FileTypeSingletonPrivate(FileTypeSingleton *qq);
|
|
FileTypeSingleton *const q_ptr;
|
|
QMimeDatabase mimetypeDatabase;
|
|
QStringList supportedImageFormats = byteArrayListToStringList(QImageReader::supportedImageFormats());
|
|
QStringList supportedAnimatedImageFormats = byteArrayListToStringList(QMovie::supportedFormats());
|
|
};
|
|
|
|
FileTypeSingletonPrivate::FileTypeSingletonPrivate(FileTypeSingleton *qq)
|
|
: q_ptr(qq)
|
|
{
|
|
}
|
|
|
|
FileTypeSingleton::FileTypeSingleton(QObject *parent)
|
|
: QObject(parent)
|
|
, d_ptr(new FileTypeSingletonPrivate(this))
|
|
{
|
|
}
|
|
|
|
FileTypeSingleton::~FileTypeSingleton() noexcept
|
|
{
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForName(const QString &nameOrAlias) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForName(nameOrAlias);
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForFile(const QString &fileName, MatchMode mode) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForFile(fileName, static_cast<QMimeDatabase::MatchMode>(mode));
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForFile(fileInfo, static_cast<QMimeDatabase::MatchMode>(mode));
|
|
}
|
|
|
|
QList<QMimeType> FileTypeSingleton::mimeTypesForFileName(const QString &fileName) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypesForFileName(fileName);
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForData(const QByteArray &data) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForData(data);
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForData(QIODevice *device) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForData(device);
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForUrl(const QUrl &url) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForUrl(url);
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForFileNameAndData(fileName, device);
|
|
}
|
|
|
|
QMimeType FileTypeSingleton::mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.mimeTypeForFileNameAndData(fileName, data);
|
|
}
|
|
|
|
QString FileTypeSingleton::suffixForFileName(const QString &fileName) const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->mimetypeDatabase.suffixForFileName(fileName);
|
|
}
|
|
|
|
QStringList FileTypeSingleton::supportedImageFormats() const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->supportedImageFormats;
|
|
}
|
|
|
|
QStringList FileTypeSingleton::supportedAnimatedImageFormats() const
|
|
{
|
|
Q_D(const FileTypeSingleton);
|
|
return d->supportedAnimatedImageFormats;
|
|
}
|
|
|
|
#include "moc_filetypesingleton.cpp"
|