4#ifndef QMIMEGLOBPATTERN_P_H
5#define QMIMEGLOBPATTERN_P_H
18#include <QtCore/private/qglobal_p.h>
22#include <QtCore/qstringlist.h>
23#include <QtCore/qhash.h>
29struct QMimeGlobMatchResult
31 void addMatch(
const QString &mimeType,
int weight,
const QString &pattern,
32 qsizetype knownSuffixLength = 0);
34 QStringList m_matchingMimeTypes;
35 QStringList m_allMatchingMimeTypes;
37 qsizetype m_matchingPatternLength = 0;
38 qsizetype m_knownSuffixLength = 0;
59 qSwap(m_pattern, other.m_pattern);
60 qSwap(m_mimeType, other.m_mimeType);
61 qSwap(m_weight, other.m_weight);
62 qSwap(m_caseSensitivity, other.m_caseSensitivity);
63 qSwap(m_patternType, other.m_patternType);
69 inline unsigned weight()
const {
return m_weight; }
71 inline bool isCaseSensitive()
const {
return m_caseSensitivity == Qt::CaseSensitive; }
82 PatternType detectPatternType(QStringView pattern)
const;
87 Qt::CaseSensitivity m_caseSensitivity;
88 PatternType m_patternType;
90Q_DECLARE_SHARED(QMimeGlobPattern)
92using AddMatchFilterFunc = std::function<
bool(
const QString &)>;
97 bool hasPattern(QStringView mimeType, QStringView pattern)
const
99 auto matchesMimeAndPattern = [mimeType, pattern](
const QMimeGlobPattern &e) {
100 return e.pattern() == pattern && e.mimeType() == mimeType;
102 return std::any_of(begin(), end(), matchesMimeAndPattern);
106
107
111 return pattern.mimeType() == mimeType;
113 removeIf(isMimeTypeEqual);
116 void match(QMimeGlobMatchResult &result,
const QString &fileName,
117 const AddMatchFilterFunc &filterFunc)
const;
121
122
123
124
125
126
134 void matchingGlobs(
const QString &fileName, QMimeGlobMatchResult &result,
135 const AddMatchFilterFunc &filterFunc)
const;
Result of the globs parsing, as data structures ready for efficient MIME type matching.
void addGlob(const QMimeGlobPattern &glob)
void matchingGlobs(const QString &fileName, QMimeGlobMatchResult &result, const AddMatchFilterFunc &filterFunc) const
PatternsMap m_fastPatterns
void removeMimeType(const QString &mimeType)
QHash< QString, QStringList > PatternsMap
QMimeGlobPatternList m_highWeightGlobs
QMimeGlobPatternList m_lowWeightGlobs
QString resolveAlias(const QString &nameOrAlias)
QStringList listAliases(const QString &mimeName)
QList< QMimeType > allMimeTypes()
QString genericIcon(const QString &name)
QMimeTypePrivate::LocaleHash localeComments(const QString &name)
bool mimeInherits(const QString &mime, const QString &parent)
QMimeType mimeTypeForFileExtension(const QString &fileName)
QMimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device)
QMimeType mimeTypeForData(QIODevice *device)
QStringList mimeTypeForFileName(const QString &fileName)
bool inherits(const QString &mime, const QString &parent)
QMimeType mimeTypeForName(const QString &nameOrAlias)
QStringList mimeParents(const QString &mimeName)
QStringList globPatterns(const QString &name)
const QString & defaultMimeType() const
QString icon(const QString &name)
static QMimeDatabasePrivate * instance()
QMimeType mimeTypeForFile(const QString &fileName, const QFileInfo &fileInfo, QMimeDatabase::MatchMode mode)
QStringList parents(const QString &mimeName)
QMimeGlobMatchResult findByFileName(const QString &fileName)
QMimeType findByData(const QByteArray &data, int *priorityPtr)
QMimeType mimeTypeForName(const QString &nameOrAlias) const
Returns a MIME type for nameOrAlias or an invalid one if none found.
QMimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const
Returns a MIME type for the given fileName and device data.
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode=MatchDefault) const
Returns a MIME type for fileInfo.
QList< QMimeType > mimeTypesForFileName(const QString &fileName) const
Returns the MIME types for the file name fileName.
QMimeType mimeTypeForUrl(const QUrl &url) const
Returns a MIME type for url.
QMimeType mimeTypeForData(const QByteArray &data) const
Returns a MIME type for data.
QString suffixForFileName(const QString &fileName) const
Returns the suffix for the file fileName, as known by the MIME database.
MatchMode
This enum specifies how matching a file to a MIME type is performed.
QList< QMimeType > allMimeTypes() const
Returns the list of all available MIME types.
QMimeType mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const
Returns a MIME type for the given fileName and device data.
QMimeType mimeTypeForData(QIODevice *device) const
Returns a MIME type for the data in device.
QMimeType mimeTypeForFile(const QString &fileName, MatchMode mode=MatchDefault) const
Returns a MIME type for the file named fileName using mode.
bool hasPattern(QStringView mimeType, QStringView pattern) const
void removeMimeType(QStringView mimeType)
"noglobs" is very rare occurrence, so it's ok if it's slow
void match(QMimeGlobMatchResult &result, const QString &fileName, const AddMatchFilterFunc &filterFunc) const
The QMimeGlobPattern class contains the glob pattern for file names for MIME type matching.
static const unsigned MinWeight
QMimeGlobPattern(const QString &thePattern, const QString &theMimeType, unsigned theWeight=DefaultWeight, Qt::CaseSensitivity s=Qt::CaseInsensitive)
static const unsigned DefaultWeight
void swap(QMimeGlobPattern &other) noexcept
const QString & mimeType() const
static const unsigned MaxWeight
const QString & pattern() const
bool matchFileName(const QString &inputFileName) const
bool isCaseSensitive() const
@ InternalDatabaseAvailable
QT_REQUIRE_CONFIG(animation)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
static bool isTextFile(const QByteArray &data)
static Q_CONSTINIT const int qmime_secondsBetweenChecks
static QStringList locateMimeDirectories()
static QString directoryMimeType()
static QString plainTextMimeType()
QT_REQUIRE_CONFIG(mimetype)