5#ifndef QMIMEGLOBPATTERN_P_H
6#define QMIMEGLOBPATTERN_P_H
19#include <QtCore/private/qglobal_p.h>
23#include <QtCore/qstringlist.h>
24#include <QtCore/qhash.h>
25#if QT_CONFIG(regularexpression)
26#include <QtCore/qregularexpression.h>
34struct QMimeGlobMatchResult
36 void addMatch(
const QString &mimeType,
int weight,
const QString &pattern,
37 qsizetype knownSuffixLength = 0);
39 QStringList m_matchingMimeTypes;
40 QStringList m_allMatchingMimeTypes;
42 qsizetype m_matchingPatternLength = 0;
43 qsizetype m_knownSuffixLength = 0;
60 m_patternType(detectPatternType(m_pattern))
62#if QT_CONFIG(regularexpression)
63 if (m_patternType == OtherPattern && !m_pattern.isEmpty())
64 m_regExp = QRegularExpression::fromWildcard(m_pattern);
70 qSwap(m_pattern, other.m_pattern);
71 qSwap(m_mimeType, other.m_mimeType);
72 qSwap(m_weight, other.m_weight);
73 qSwap(m_caseSensitivity, other.m_caseSensitivity);
74 qSwap(m_patternType, other.m_patternType);
75#if QT_CONFIG(regularexpression)
76 qSwap(m_regExp, other.m_regExp);
83 inline unsigned weight()
const {
return m_weight; }
85 inline bool isCaseSensitive()
const {
return m_caseSensitivity == Qt::CaseSensitive; }
96 template <
typename Pattern>
98 QStringView fileName, Qt::CaseSensitivity cs);
102 template <
typename Pattern>
108 Qt::CaseSensitivity m_caseSensitivity;
110#if QT_CONFIG(regularexpression)
114Q_DECLARE_SHARED(QMimeGlobPattern)
116using AddMatchFilterFunc = std::function<
bool(
const QString &)>;
121 bool hasPattern(QStringView mimeType, QStringView pattern)
const
123 auto matchesMimeAndPattern = [mimeType, pattern](
const QMimeGlobPattern &e) {
124 return e.pattern() == pattern && e.mimeType() == mimeType;
126 return std::any_of(begin(), end(), matchesMimeAndPattern);
130
131
135 return pattern.mimeType() == mimeType;
137 removeIf(isMimeTypeEqual);
140 void match(QMimeGlobMatchResult &result,
const QString &fileName,
141 const AddMatchFilterFunc &filterFunc)
const;
145
146
147
148
149
150
158 void matchingGlobs(
const QString &fileName, QMimeGlobMatchResult &result,
159 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)
bool magicRulesReject(const QString &mime, const QByteArray &data)
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
static bool matchWithoutRegularExpression(PatternType patternType, Pattern pattern, QStringView fileName, Qt::CaseSensitivity cs)
const QString & mimeType() const
static const unsigned MaxWeight
const QString & pattern() const
static PatternType detectPatternType(QLatin1StringView pattern)
bool matchFileName(const QString &fileName) 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 QStringList locateMimeDirectories()
static QString directoryMimeType()
static QString plainTextMimeType()
static constexpr auto qmime_secondsBetweenChecks
QT_REQUIRE_CONFIG(mimetype)