forked from qt-creator/qt-creator
Mimetypes v3: Rename classes
- fix includes - use pragma once - use namespace Utils - rename QMime -> Mime - fix exports - don't use QFileSystemEntry - don't use QT_REQUIRE_CONFIG - disable QT_CONFIG(mimetype_database) Change-Id: I3e27b7644a9db987ad213efada3b0d8c7199cfd9 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -40,13 +40,11 @@
|
||||
|
||||
#include <qplatformdefs.h> // always first
|
||||
|
||||
#include "qmimedatabase.h"
|
||||
#include "qmimedatabase_p.h"
|
||||
#include "mimedatabase.h"
|
||||
#include "mimedatabase_p.h"
|
||||
|
||||
#include "qmimeprovider_p.h"
|
||||
#include "qmimetype_p.h"
|
||||
|
||||
#include <private/qfilesystementry_p.h>
|
||||
#include "mimeprovider_p.h"
|
||||
#include "mimetype_p.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
@@ -59,34 +57,34 @@
|
||||
#include <functional>
|
||||
#include <stack>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
Q_GLOBAL_STATIC(QMimeDatabasePrivate, staticQMimeDatabase)
|
||||
Q_GLOBAL_STATIC(MimeDatabasePrivate, staticMimeDatabase)
|
||||
|
||||
QMimeDatabasePrivate *QMimeDatabasePrivate::instance()
|
||||
MimeDatabasePrivate *MimeDatabasePrivate::instance()
|
||||
{
|
||||
return staticQMimeDatabase();
|
||||
return staticMimeDatabase();
|
||||
}
|
||||
|
||||
QMimeDatabasePrivate::QMimeDatabasePrivate()
|
||||
MimeDatabasePrivate::MimeDatabasePrivate()
|
||||
: m_defaultMimeType(QLatin1String("application/octet-stream"))
|
||||
{
|
||||
}
|
||||
|
||||
QMimeDatabasePrivate::~QMimeDatabasePrivate()
|
||||
MimeDatabasePrivate::~MimeDatabasePrivate()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
#if 0 //def QT_BUILD_INTERNAL
|
||||
Q_CORE_EXPORT
|
||||
#else
|
||||
static const
|
||||
#endif
|
||||
int qmime_secondsBetweenChecks = 5;
|
||||
int mime_secondsBetweenChecks = 5;
|
||||
|
||||
bool QMimeDatabasePrivate::shouldCheck()
|
||||
bool MimeDatabasePrivate::shouldCheck()
|
||||
{
|
||||
if (m_lastCheck.isValid() && m_lastCheck.elapsed() < qmime_secondsBetweenChecks * 1000)
|
||||
if (m_lastCheck.isValid() && m_lastCheck.elapsed() < mime_secondsBetweenChecks * 1000)
|
||||
return false;
|
||||
m_lastCheck.start();
|
||||
return true;
|
||||
@@ -96,14 +94,14 @@ bool QMimeDatabasePrivate::shouldCheck()
|
||||
# define QT_USE_MMAP
|
||||
#endif
|
||||
|
||||
void QMimeDatabasePrivate::loadProviders()
|
||||
void MimeDatabasePrivate::loadProviders()
|
||||
{
|
||||
// We use QStandardPaths every time to check if new files appeared
|
||||
const QStringList mimeDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime"), QStandardPaths::LocateDirectory);
|
||||
const auto fdoIterator = std::find_if(mimeDirs.constBegin(), mimeDirs.constEnd(), [](const QString &mimeDir) -> bool {
|
||||
return QFileInfo::exists(mimeDir + QStringLiteral("/packages/freedesktop.org.xml")); }
|
||||
);
|
||||
const bool needInternalDB = QMimeXMLProvider::InternalDatabaseAvailable && fdoIterator == mimeDirs.constEnd();
|
||||
const bool needInternalDB = MimeXMLProvider::InternalDatabaseAvailable && fdoIterator == mimeDirs.constEnd();
|
||||
//qDebug() << "mime dirs:" << mimeDirs;
|
||||
|
||||
Providers currentProviders;
|
||||
@@ -114,16 +112,16 @@ void QMimeDatabasePrivate::loadProviders()
|
||||
for (const QString &mimeDir : mimeDirs) {
|
||||
const QString cacheFile = mimeDir + QStringLiteral("/mime.cache");
|
||||
// Check if we already have a provider for this dir
|
||||
const auto predicate = [mimeDir](const std::unique_ptr<QMimeProviderBase> &prov)
|
||||
const auto predicate = [mimeDir](const std::unique_ptr<MimeProviderBase> &prov)
|
||||
{
|
||||
return prov && prov->directory() == mimeDir;
|
||||
};
|
||||
const auto it = std::find_if(currentProviders.begin(), currentProviders.end(), predicate);
|
||||
if (it == currentProviders.end()) {
|
||||
std::unique_ptr<QMimeProviderBase> provider;
|
||||
std::unique_ptr<MimeProviderBase> provider;
|
||||
#if defined(QT_USE_MMAP)
|
||||
if (qEnvironmentVariableIsEmpty("QT_NO_MIME_CACHE") && QFileInfo::exists(cacheFile)) {
|
||||
provider.reset(new QMimeBinaryProvider(this, mimeDir));
|
||||
provider.reset(new MimeBinaryProvider(this, mimeDir));
|
||||
//qDebug() << "Created binary provider for" << mimeDir;
|
||||
if (!provider->isValid()) {
|
||||
provider.reset();
|
||||
@@ -131,7 +129,7 @@ void QMimeDatabasePrivate::loadProviders()
|
||||
}
|
||||
#endif
|
||||
if (!provider) {
|
||||
provider.reset(new QMimeXMLProvider(this, mimeDir));
|
||||
provider.reset(new MimeXMLProvider(this, mimeDir));
|
||||
//qDebug() << "Created XML provider for" << mimeDir;
|
||||
}
|
||||
m_providers.push_back(std::move(provider));
|
||||
@@ -139,7 +137,7 @@ void QMimeDatabasePrivate::loadProviders()
|
||||
auto provider = std::move(*it); // take provider out of the vector
|
||||
provider->ensureLoaded();
|
||||
if (!provider->isValid()) {
|
||||
provider.reset(new QMimeXMLProvider(this, mimeDir));
|
||||
provider.reset(new MimeXMLProvider(this, mimeDir));
|
||||
//qDebug() << "Created XML provider to replace binary provider for" << mimeDir;
|
||||
}
|
||||
m_providers.push_back(std::move(provider));
|
||||
@@ -149,20 +147,20 @@ void QMimeDatabasePrivate::loadProviders()
|
||||
// so the internal XML DB goes at the end
|
||||
if (needInternalDB) {
|
||||
// Check if we already have a provider for the InternalDatabase
|
||||
const auto isInternal = [](const std::unique_ptr<QMimeProviderBase> &prov)
|
||||
const auto isInternal = [](const std::unique_ptr<MimeProviderBase> &prov)
|
||||
{
|
||||
return prov && prov->isInternalDatabase();
|
||||
};
|
||||
const auto it = std::find_if(currentProviders.begin(), currentProviders.end(), isInternal);
|
||||
if (it == currentProviders.end()) {
|
||||
m_providers.push_back(Providers::value_type(new QMimeXMLProvider(this, QMimeXMLProvider::InternalDatabase)));
|
||||
m_providers.push_back(Providers::value_type(new MimeXMLProvider(this, MimeXMLProvider::InternalDatabase)));
|
||||
} else {
|
||||
m_providers.push_back(std::move(*it));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QMimeDatabasePrivate::Providers &QMimeDatabasePrivate::providers()
|
||||
const MimeDatabasePrivate::Providers &MimeDatabasePrivate::providers()
|
||||
{
|
||||
#ifndef Q_OS_WASM // stub implementation always returns true
|
||||
Q_ASSERT(!mutex.tryLock()); // caller should have locked mutex
|
||||
@@ -177,7 +175,7 @@ const QMimeDatabasePrivate::Providers &QMimeDatabasePrivate::providers()
|
||||
return m_providers;
|
||||
}
|
||||
|
||||
QString QMimeDatabasePrivate::resolveAlias(const QString &nameOrAlias)
|
||||
QString MimeDatabasePrivate::resolveAlias(const QString &nameOrAlias)
|
||||
{
|
||||
for (const auto &provider : providers()) {
|
||||
const QString ret = provider->resolveAlias(nameOrAlias);
|
||||
@@ -191,38 +189,38 @@ QString QMimeDatabasePrivate::resolveAlias(const QString &nameOrAlias)
|
||||
\internal
|
||||
Returns a MIME type or an invalid one if none found
|
||||
*/
|
||||
QMimeType QMimeDatabasePrivate::mimeTypeForName(const QString &nameOrAlias)
|
||||
MimeType MimeDatabasePrivate::mimeTypeForName(const QString &nameOrAlias)
|
||||
{
|
||||
const QString mimeName = resolveAlias(nameOrAlias);
|
||||
for (const auto &provider : providers()) {
|
||||
const QMimeType mime = provider->mimeTypeForName(mimeName);
|
||||
const MimeType mime = provider->mimeTypeForName(mimeName);
|
||||
if (mime.isValid())
|
||||
return mime;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QStringList QMimeDatabasePrivate::mimeTypeForFileName(const QString &fileName)
|
||||
QStringList MimeDatabasePrivate::mimeTypeForFileName(const QString &fileName)
|
||||
{
|
||||
if (fileName.endsWith(QLatin1Char('/')))
|
||||
return QStringList() << QLatin1String("inode/directory");
|
||||
|
||||
const QMimeGlobMatchResult result = findByFileName(fileName);
|
||||
const MimeGlobMatchResult result = findByFileName(fileName);
|
||||
QStringList matchingMimeTypes = result.m_matchingMimeTypes;
|
||||
matchingMimeTypes.sort(); // make it deterministic
|
||||
return matchingMimeTypes;
|
||||
}
|
||||
|
||||
QMimeGlobMatchResult QMimeDatabasePrivate::findByFileName(const QString &fileName)
|
||||
MimeGlobMatchResult MimeDatabasePrivate::findByFileName(const QString &fileName)
|
||||
{
|
||||
QMimeGlobMatchResult result;
|
||||
const QString fileNameExcludingPath = QFileSystemEntry(fileName).fileName();
|
||||
MimeGlobMatchResult result;
|
||||
const QString fileNameExcludingPath = QFileInfo(fileName).fileName();
|
||||
for (const auto &provider : providers())
|
||||
provider->addFileNameMatches(fileNameExcludingPath, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void QMimeDatabasePrivate::loadMimeTypePrivate(QMimeTypePrivate &mimePrivate)
|
||||
void MimeDatabasePrivate::loadMimeTypePrivate(MimeTypePrivate &mimePrivate)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
if (mimePrivate.name.isEmpty())
|
||||
@@ -246,7 +244,7 @@ void QMimeDatabasePrivate::loadMimeTypePrivate(QMimeTypePrivate &mimePrivate)
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeDatabasePrivate::loadGenericIcon(QMimeTypePrivate &mimePrivate)
|
||||
void MimeDatabasePrivate::loadGenericIcon(MimeTypePrivate &mimePrivate)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
if (mimePrivate.fromCache) {
|
||||
@@ -259,7 +257,7 @@ void QMimeDatabasePrivate::loadGenericIcon(QMimeTypePrivate &mimePrivate)
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeDatabasePrivate::loadIcon(QMimeTypePrivate &mimePrivate)
|
||||
void MimeDatabasePrivate::loadIcon(MimeTypePrivate &mimePrivate)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
if (mimePrivate.fromCache) {
|
||||
@@ -288,13 +286,13 @@ static QString fallbackParent(const QString &mimeTypeName)
|
||||
return QString();
|
||||
}
|
||||
|
||||
QStringList QMimeDatabasePrivate::mimeParents(const QString &mimeName)
|
||||
QStringList MimeDatabasePrivate::mimeParents(const QString &mimeName)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
return parents(mimeName);
|
||||
}
|
||||
|
||||
QStringList QMimeDatabasePrivate::parents(const QString &mimeName)
|
||||
QStringList MimeDatabasePrivate::parents(const QString &mimeName)
|
||||
{
|
||||
Q_ASSERT(!mutex.tryLock());
|
||||
QStringList result;
|
||||
@@ -308,7 +306,7 @@ QStringList QMimeDatabasePrivate::parents(const QString &mimeName)
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList QMimeDatabasePrivate::listAliases(const QString &mimeName)
|
||||
QStringList MimeDatabasePrivate::listAliases(const QString &mimeName)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
QStringList result;
|
||||
@@ -317,7 +315,7 @@ QStringList QMimeDatabasePrivate::listAliases(const QString &mimeName)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool QMimeDatabasePrivate::mimeInherits(const QString &mime, const QString &parent)
|
||||
bool MimeDatabasePrivate::mimeInherits(const QString &mime, const QString &parent)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
return inherits(mime, parent);
|
||||
@@ -342,7 +340,7 @@ static inline bool isTextFile(const QByteArray &data)
|
||||
return true;
|
||||
}
|
||||
|
||||
QMimeType QMimeDatabasePrivate::findByData(const QByteArray &data, int *accuracyPtr)
|
||||
MimeType MimeDatabasePrivate::findByData(const QByteArray &data, int *accuracyPtr)
|
||||
{
|
||||
if (data.isEmpty()) {
|
||||
*accuracyPtr = 100;
|
||||
@@ -350,7 +348,7 @@ QMimeType QMimeDatabasePrivate::findByData(const QByteArray &data, int *accuracy
|
||||
}
|
||||
|
||||
*accuracyPtr = 0;
|
||||
QMimeType candidate;
|
||||
MimeType candidate;
|
||||
for (const auto &provider : providers())
|
||||
provider->findByMagic(data, accuracyPtr, candidate);
|
||||
|
||||
@@ -365,7 +363,7 @@ QMimeType QMimeDatabasePrivate::findByData(const QByteArray &data, int *accuracy
|
||||
return mimeTypeForName(defaultMimeType());
|
||||
}
|
||||
|
||||
QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device, int *accuracyPtr)
|
||||
MimeType MimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device, int *accuracyPtr)
|
||||
{
|
||||
// First, glob patterns are evaluated. If there is a match with max weight,
|
||||
// this one is selected and we are done. Otherwise, the file contents are
|
||||
@@ -375,10 +373,10 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
|
||||
*accuracyPtr = 0;
|
||||
|
||||
// Pass 1) Try to match on the file name
|
||||
QMimeGlobMatchResult candidatesByName = findByFileName(fileName);
|
||||
MimeGlobMatchResult candidatesByName = findByFileName(fileName);
|
||||
if (candidatesByName.m_allMatchingMimeTypes.count() == 1) {
|
||||
*accuracyPtr = 100;
|
||||
const QMimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0));
|
||||
const MimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0));
|
||||
if (mime.isValid())
|
||||
return mime;
|
||||
candidatesByName = {};
|
||||
@@ -393,7 +391,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
|
||||
const QByteArray data = device->peek(16384);
|
||||
|
||||
int magicAccuracy = 0;
|
||||
QMimeType candidateByData(findByData(data, &magicAccuracy));
|
||||
MimeType candidateByData(findByData(data, &magicAccuracy));
|
||||
|
||||
// Disambiguate conflicting extensions (if magic matching found something)
|
||||
if (candidateByData.isValid() && magicAccuracy > 0) {
|
||||
@@ -421,7 +419,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
|
||||
if (candidatesByName.m_allMatchingMimeTypes.count() > 1) {
|
||||
candidatesByName.m_matchingMimeTypes.sort(); // make it deterministic
|
||||
*accuracyPtr = 20;
|
||||
const QMimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0));
|
||||
const MimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0));
|
||||
if (mime.isValid())
|
||||
return mime;
|
||||
}
|
||||
@@ -437,15 +435,15 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
|
||||
return matchOnContent(&fallbackFile);
|
||||
}
|
||||
|
||||
QList<QMimeType> QMimeDatabasePrivate::allMimeTypes()
|
||||
QList<MimeType> MimeDatabasePrivate::allMimeTypes()
|
||||
{
|
||||
QList<QMimeType> result;
|
||||
QList<MimeType> result;
|
||||
for (const auto &provider : providers())
|
||||
provider->addAllMimeTypes(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
|
||||
bool MimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
|
||||
{
|
||||
const QString resolvedParent = resolveAlias(parent);
|
||||
std::stack<QString, QStringList> toCheck;
|
||||
@@ -463,9 +461,9 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QMimeDatabase
|
||||
\class MimeDatabase
|
||||
\inmodule QtCore
|
||||
\brief The QMimeDatabase class maintains a database of MIME types.
|
||||
\brief The MimeDatabase class maintains a database of MIME types.
|
||||
|
||||
\since 5.0
|
||||
|
||||
@@ -476,14 +474,14 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
|
||||
Applications which want to define custom MIME types need to install an
|
||||
XML file into the locations searched for MIME definitions.
|
||||
These locations can be queried with
|
||||
\snippet code/src_corelib_mimetype_qmimedatabase.cpp 1
|
||||
\snippet code/src_corelib_mimetype_mimedatabase.cpp 1
|
||||
On a typical Unix system, this will be /usr/share/mime/packages/, but it is also
|
||||
possible to extend the list of directories by setting the environment variable
|
||||
\c XDG_DATA_DIRS. For instance adding /opt/myapp/share to \c XDG_DATA_DIRS will result
|
||||
in /opt/myapp/share/mime/packages/ being searched for MIME definitions.
|
||||
|
||||
Here is an example of MIME XML:
|
||||
\snippet code/src_corelib_mimetype_qmimedatabase.cpp 2
|
||||
\snippet code/src_corelib_mimetype_mimedatabase.cpp 2
|
||||
|
||||
For more details about the syntax of XML MIME definitions, including defining
|
||||
"magic" in order to detect MIME types based on data as well, read the
|
||||
@@ -497,39 +495,39 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
|
||||
|
||||
\threadsafe
|
||||
|
||||
\snippet code/src_corelib_mimetype_qmimedatabase.cpp 0
|
||||
\snippet code/src_corelib_mimetype_mimedatabase.cpp 0
|
||||
|
||||
\sa QMimeType, {MIME Type Browser Example}
|
||||
\sa MimeType, {MIME Type Browser Example}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMimeDatabase::QMimeDatabase();
|
||||
Constructs a QMimeDatabase object.
|
||||
\fn MimeDatabase::MimeDatabase();
|
||||
Constructs a MimeDatabase object.
|
||||
|
||||
It is perfectly OK to create an instance of QMimeDatabase every time you need to
|
||||
It is perfectly OK to create an instance of MimeDatabase every time you need to
|
||||
perform a lookup.
|
||||
The parsing of mimetypes is done on demand (when shared-mime-info is installed)
|
||||
or when the very first instance is constructed (when parsing XML files directly).
|
||||
*/
|
||||
QMimeDatabase::QMimeDatabase() :
|
||||
d(staticQMimeDatabase())
|
||||
MimeDatabase::MimeDatabase() :
|
||||
d(staticMimeDatabase())
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMimeDatabase::~QMimeDatabase();
|
||||
Destroys the QMimeDatabase object.
|
||||
\fn MimeDatabase::~MimeDatabase();
|
||||
Destroys the MimeDatabase object.
|
||||
*/
|
||||
QMimeDatabase::~QMimeDatabase()
|
||||
MimeDatabase::~MimeDatabase()
|
||||
{
|
||||
d = nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMimeType QMimeDatabase::mimeTypeForName(const QString &nameOrAlias) const;
|
||||
\fn MimeType MimeDatabase::mimeTypeForName(const QString &nameOrAlias) const;
|
||||
Returns a MIME type for \a nameOrAlias or an invalid one if none found.
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForName(const QString &nameOrAlias) const
|
||||
MimeType MimeDatabase::mimeTypeForName(const QString &nameOrAlias) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -562,9 +560,9 @@ QMimeType QMimeDatabase::mimeTypeForName(const QString &nameOrAlias) const
|
||||
|
||||
\a fileInfo may refer to an absolute or relative path.
|
||||
|
||||
\sa QMimeType::isDefault(), mimeTypeForData()
|
||||
\sa MimeType::isDefault(), mimeTypeForData()
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const
|
||||
MimeType MimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -617,7 +615,7 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mo
|
||||
|
||||
\overload
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode) const
|
||||
MimeType MimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode) const
|
||||
{
|
||||
if (mode == MatchExtension) {
|
||||
QMutexLocker locker(&d->mutex);
|
||||
@@ -650,12 +648,12 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode
|
||||
|
||||
\sa mimeTypeForFile()
|
||||
*/
|
||||
QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) const
|
||||
QList<MimeType> MimeDatabase::mimeTypesForFileName(const QString &fileName) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
const QStringList matches = d->mimeTypeForFileName(fileName);
|
||||
QList<QMimeType> mimes;
|
||||
QList<MimeType> mimes;
|
||||
mimes.reserve(matches.count());
|
||||
for (const QString &mime : matches)
|
||||
mimes.append(d->mimeTypeForName(mime));
|
||||
@@ -667,7 +665,7 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co
|
||||
This allows to pre-select "tar.bz2" for foo.tar.bz2, but still only
|
||||
"txt" for my.file.with.dots.txt.
|
||||
*/
|
||||
QString QMimeDatabase::suffixForFileName(const QString &fileName) const
|
||||
QString MimeDatabase::suffixForFileName(const QString &fileName) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
const int suffixLength = d->findByFileName(fileName).m_knownSuffixLength;
|
||||
@@ -681,7 +679,7 @@ QString QMimeDatabase::suffixForFileName(const QString &fileName) const
|
||||
known MIME type data, the default MIME type (application/octet-stream)
|
||||
is returned.
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForData(const QByteArray &data) const
|
||||
MimeType MimeDatabase::mimeTypeForData(const QByteArray &data) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -696,7 +694,7 @@ QMimeType QMimeDatabase::mimeTypeForData(const QByteArray &data) const
|
||||
known MIME type data, the default MIME type (application/octet-stream)
|
||||
is returned.
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForData(QIODevice *device) const
|
||||
MimeType MimeDatabase::mimeTypeForData(QIODevice *device) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -706,7 +704,7 @@ QMimeType QMimeDatabase::mimeTypeForData(QIODevice *device) const
|
||||
// Read 16K in one go (QIODEVICE_BUFFERSIZE in qiodevice_p.h).
|
||||
// This is much faster than seeking back and forth into QIODevice.
|
||||
const QByteArray data = device->peek(16384);
|
||||
const QMimeType result = d->findByData(data, &accuracy);
|
||||
const MimeType result = d->findByData(data, &accuracy);
|
||||
if (openedByUs)
|
||||
device->close();
|
||||
return result;
|
||||
@@ -728,7 +726,7 @@ QMimeType QMimeDatabase::mimeTypeForData(QIODevice *device) const
|
||||
known MIME type data, the default MIME type (application/octet-stream)
|
||||
is returned.
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForUrl(const QUrl &url) const
|
||||
MimeType MimeDatabase::mimeTypeForUrl(const QUrl &url) const
|
||||
{
|
||||
if (url.isLocalFile())
|
||||
return mimeTypeForFile(url.toLocalFile());
|
||||
@@ -759,7 +757,7 @@ QMimeType QMimeDatabase::mimeTypeForUrl(const QUrl &url) const
|
||||
but the contents will be used if the file extension is unknown, or
|
||||
matches multiple MIME types.
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const
|
||||
MimeType MimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -768,7 +766,7 @@ QMimeType QMimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, QIO
|
||||
|
||||
int accuracy = 0;
|
||||
const bool openedByUs = !device->isOpen() && device->open(QIODevice::ReadOnly);
|
||||
const QMimeType result = d->mimeTypeForFileNameAndData(fileName, device, &accuracy);
|
||||
const MimeType result = d->mimeTypeForFileNameAndData(fileName, device, &accuracy);
|
||||
if (openedByUs)
|
||||
device->close();
|
||||
return result;
|
||||
@@ -790,7 +788,7 @@ QMimeType QMimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, QIO
|
||||
but the contents will be used if the file extension is unknown, or
|
||||
matches multiple MIME types.
|
||||
*/
|
||||
QMimeType QMimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const
|
||||
MimeType MimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -810,7 +808,7 @@ QMimeType QMimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, con
|
||||
in a MIME type editor. Do not use unless really necessary in other cases
|
||||
though, prefer using the \l {mimeTypeForData()}{mimeTypeForXxx()} methods for performance reasons.
|
||||
*/
|
||||
QList<QMimeType> QMimeDatabase::allMimeTypes() const
|
||||
QList<MimeType> MimeDatabase::allMimeTypes() const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
@@ -818,7 +816,7 @@ QList<QMimeType> QMimeDatabase::allMimeTypes() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\enum QMimeDatabase::MatchMode
|
||||
\enum MimeDatabase::MatchMode
|
||||
|
||||
This enum specifies how matching a file to a MIME type is performed.
|
||||
|
||||
@@ -829,4 +827,4 @@ QList<QMimeType> QMimeDatabase::allMimeTypes() const
|
||||
\value MatchContent The file content is used to look for a match
|
||||
*/
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
@@ -38,32 +38,33 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMEDATABASE_H
|
||||
#define QMIMEDATABASE_H
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qmimetype.h>
|
||||
#include "mimetype.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
#include <utils/utils_global.h>
|
||||
|
||||
#include <QtCore/qstringlist.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QByteArray;
|
||||
class QFileInfo;
|
||||
class QIODevice;
|
||||
class QUrl;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QMimeDatabasePrivate;
|
||||
class Q_CORE_EXPORT QMimeDatabase
|
||||
namespace Utils {
|
||||
|
||||
class MimeDatabasePrivate;
|
||||
class QTCREATOR_UTILS_EXPORT MimeDatabase
|
||||
{
|
||||
Q_DISABLE_COPY(QMimeDatabase)
|
||||
Q_DISABLE_COPY(MimeDatabase)
|
||||
|
||||
public:
|
||||
QMimeDatabase();
|
||||
~QMimeDatabase();
|
||||
MimeDatabase();
|
||||
~MimeDatabase();
|
||||
|
||||
QMimeType mimeTypeForName(const QString &nameOrAlias) const;
|
||||
MimeType mimeTypeForName(const QString &nameOrAlias) const;
|
||||
|
||||
enum MatchMode {
|
||||
MatchDefault = 0x0,
|
||||
@@ -71,25 +72,23 @@ public:
|
||||
MatchContent = 0x2
|
||||
};
|
||||
|
||||
QMimeType mimeTypeForFile(const QString &fileName, MatchMode mode = MatchDefault) const;
|
||||
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode = MatchDefault) const;
|
||||
QList<QMimeType> mimeTypesForFileName(const QString &fileName) const;
|
||||
MimeType mimeTypeForFile(const QString &fileName, MatchMode mode = MatchDefault) const;
|
||||
MimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode = MatchDefault) const;
|
||||
QList<MimeType> mimeTypesForFileName(const QString &fileName) const;
|
||||
|
||||
QMimeType mimeTypeForData(const QByteArray &data) const;
|
||||
QMimeType mimeTypeForData(QIODevice *device) const;
|
||||
MimeType mimeTypeForData(const QByteArray &data) const;
|
||||
MimeType mimeTypeForData(QIODevice *device) const;
|
||||
|
||||
QMimeType mimeTypeForUrl(const QUrl &url) const;
|
||||
QMimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const;
|
||||
QMimeType mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const;
|
||||
MimeType mimeTypeForUrl(const QUrl &url) const;
|
||||
MimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const;
|
||||
MimeType mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const;
|
||||
|
||||
QString suffixForFileName(const QString &fileName) const;
|
||||
|
||||
QList<QMimeType> allMimeTypes() const;
|
||||
QList<MimeType> allMimeTypes() const;
|
||||
|
||||
private:
|
||||
QMimeDatabasePrivate *d;
|
||||
MimeDatabasePrivate *d;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QMIMEDATABASE_H
|
||||
} // namespace Utils
|
||||
|
@@ -38,8 +38,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMEDATABASE_P_H
|
||||
#define QMIMEDATABASE_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -52,12 +51,10 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qmimetype.h"
|
||||
#include "mimetype.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
|
||||
#include "qmimetype_p.h"
|
||||
#include "qmimeglobpattern_p.h"
|
||||
#include "mimeglobpattern_p.h"
|
||||
#include "mimetype_p.h"
|
||||
|
||||
#include <QtCore/qelapsedtimer.h>
|
||||
#include <QtCore/qlist.h>
|
||||
@@ -67,45 +64,48 @@ QT_REQUIRE_CONFIG(mimetype);
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIODevice;
|
||||
class QMimeDatabase;
|
||||
class QMimeProviderBase;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QMimeDatabasePrivate
|
||||
namespace Utils {
|
||||
|
||||
class MimeDatabase;
|
||||
class MimeProviderBase;
|
||||
|
||||
class MimeDatabasePrivate
|
||||
{
|
||||
public:
|
||||
Q_DISABLE_COPY_MOVE(QMimeDatabasePrivate)
|
||||
Q_DISABLE_COPY_MOVE(MimeDatabasePrivate)
|
||||
|
||||
QMimeDatabasePrivate();
|
||||
~QMimeDatabasePrivate();
|
||||
MimeDatabasePrivate();
|
||||
~MimeDatabasePrivate();
|
||||
|
||||
static QMimeDatabasePrivate *instance();
|
||||
static MimeDatabasePrivate *instance();
|
||||
|
||||
inline QString defaultMimeType() const { return m_defaultMimeType; }
|
||||
|
||||
bool inherits(const QString &mime, const QString &parent);
|
||||
|
||||
QList<QMimeType> allMimeTypes();
|
||||
QList<MimeType> allMimeTypes();
|
||||
|
||||
QString resolveAlias(const QString &nameOrAlias);
|
||||
QStringList parents(const QString &mimeName);
|
||||
QMimeType mimeTypeForName(const QString &nameOrAlias);
|
||||
QMimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device, int *priorityPtr);
|
||||
QMimeType findByData(const QByteArray &data, int *priorityPtr);
|
||||
MimeType mimeTypeForName(const QString &nameOrAlias);
|
||||
MimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device, int *priorityPtr);
|
||||
MimeType findByData(const QByteArray &data, int *priorityPtr);
|
||||
QStringList mimeTypeForFileName(const QString &fileName);
|
||||
QMimeGlobMatchResult findByFileName(const QString &fileName);
|
||||
MimeGlobMatchResult findByFileName(const QString &fileName);
|
||||
|
||||
// API for QMimeType. Takes care of locking the mutex.
|
||||
void loadMimeTypePrivate(QMimeTypePrivate &mimePrivate);
|
||||
void loadGenericIcon(QMimeTypePrivate &mimePrivate);
|
||||
void loadIcon(QMimeTypePrivate &mimePrivate);
|
||||
// API for MimeType. Takes care of locking the mutex.
|
||||
void loadMimeTypePrivate(MimeTypePrivate &mimePrivate);
|
||||
void loadGenericIcon(MimeTypePrivate &mimePrivate);
|
||||
void loadIcon(MimeTypePrivate &mimePrivate);
|
||||
QStringList mimeParents(const QString &mimeName);
|
||||
QStringList listAliases(const QString &mimeName);
|
||||
bool mimeInherits(const QString &mime, const QString &parent);
|
||||
|
||||
private:
|
||||
using Providers = std::vector<std::unique_ptr<QMimeProviderBase>>;
|
||||
using Providers = std::vector<std::unique_ptr<MimeProviderBase>>;
|
||||
const Providers &providers();
|
||||
bool shouldCheck();
|
||||
void loadProviders();
|
||||
@@ -118,6 +118,4 @@ public:
|
||||
QMutex mutex;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QMIMEDATABASE_P_H
|
||||
} // namespace Utils
|
||||
|
@@ -37,7 +37,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmimeglobpattern_p.h"
|
||||
#include "mimeglobpattern_p.h"
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
#include <QRegularExpression>
|
||||
@@ -45,18 +45,18 @@
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\class QMimeGlobMatchResult
|
||||
\class MimeGlobMatchResult
|
||||
\inmodule QtCore
|
||||
\brief The QMimeGlobMatchResult class accumulates results from glob matching.
|
||||
\brief The MimeGlobMatchResult class accumulates results from glob matching.
|
||||
|
||||
Handles glob weights, and preferring longer matches over shorter matches.
|
||||
*/
|
||||
|
||||
void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength)
|
||||
void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength)
|
||||
{
|
||||
if (m_allMatchingMimeTypes.contains(mimeType))
|
||||
return;
|
||||
@@ -91,7 +91,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
|
||||
}
|
||||
}
|
||||
|
||||
QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(const QString &pattern) const
|
||||
MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &pattern) const
|
||||
{
|
||||
const int patternLength = pattern.length();
|
||||
if (!patternLength)
|
||||
@@ -127,14 +127,14 @@ QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(const QString
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\class QMimeGlobPattern
|
||||
\class MimeGlobPattern
|
||||
\inmodule QtCore
|
||||
\brief The QMimeGlobPattern class contains the glob pattern for file names for MIME type matching.
|
||||
\brief The MimeGlobPattern class contains the glob pattern for file names for MIME type matching.
|
||||
|
||||
\sa QMimeType, QMimeDatabase, QMimeMagicRuleMatcher, QMimeMagicRule
|
||||
\sa MimeType, MimeDatabase, MimeMagicRuleMatcher, MimeMagicRule
|
||||
*/
|
||||
|
||||
bool QMimeGlobPattern::matchFileName(const QString &inputFileName) const
|
||||
bool MimeGlobPattern::matchFileName(const QString &inputFileName) const
|
||||
{
|
||||
// "Applications MUST match globs case-insensitively, except when the case-sensitive
|
||||
// attribute is set to true."
|
||||
@@ -219,7 +219,7 @@ static bool isFastPattern(const QString &pattern)
|
||||
;
|
||||
}
|
||||
|
||||
void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob)
|
||||
void MimeAllGlobPatterns::addGlob(const MimeGlobPattern &glob)
|
||||
{
|
||||
const QString &pattern = glob.pattern();
|
||||
Q_ASSERT(!pattern.isEmpty());
|
||||
@@ -245,7 +245,7 @@ void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob)
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeAllGlobPatterns::removeMimeType(const QString &mimeType)
|
||||
void MimeAllGlobPatterns::removeMimeType(const QString &mimeType)
|
||||
{
|
||||
for (auto &x : m_fastPatterns)
|
||||
x.removeAll(mimeType);
|
||||
@@ -253,14 +253,14 @@ void QMimeAllGlobPatterns::removeMimeType(const QString &mimeType)
|
||||
m_lowWeightGlobs.removeMimeType(mimeType);
|
||||
}
|
||||
|
||||
void QMimeGlobPatternList::match(QMimeGlobMatchResult &result,
|
||||
void MimeGlobPatternList::match(MimeGlobMatchResult &result,
|
||||
const QString &fileName) const
|
||||
{
|
||||
|
||||
QMimeGlobPatternList::const_iterator it = this->constBegin();
|
||||
const QMimeGlobPatternList::const_iterator endIt = this->constEnd();
|
||||
MimeGlobPatternList::const_iterator it = this->constBegin();
|
||||
const MimeGlobPatternList::const_iterator endIt = this->constEnd();
|
||||
for (; it != endIt; ++it) {
|
||||
const QMimeGlobPattern &glob = *it;
|
||||
const MimeGlobPattern &glob = *it;
|
||||
if (glob.matchFileName(fileName)) {
|
||||
const QString pattern = glob.pattern();
|
||||
const int suffixLen = isSimplePattern(pattern) ? pattern.length() - 2 : 0;
|
||||
@@ -269,7 +269,7 @@ void QMimeGlobPatternList::match(QMimeGlobMatchResult &result,
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QMimeGlobMatchResult &result) const
|
||||
void MimeAllGlobPatterns::matchingGlobs(const QString &fileName, MimeGlobMatchResult &result) const
|
||||
{
|
||||
// First try the high weight matches (>50), if any.
|
||||
m_highWeightGlobs.match(result, fileName);
|
||||
@@ -294,11 +294,11 @@ void QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QMimeGlobMatch
|
||||
m_lowWeightGlobs.match(result, fileName);
|
||||
}
|
||||
|
||||
void QMimeAllGlobPatterns::clear()
|
||||
void MimeAllGlobPatterns::clear()
|
||||
{
|
||||
m_fastPatterns.clear();
|
||||
m_highWeightGlobs.clear();
|
||||
m_lowWeightGlobs.clear();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
@@ -37,8 +37,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMEGLOBPATTERN_P_H
|
||||
#define QMIMEGLOBPATTERN_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -51,16 +50,12 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qhash.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
struct QMimeGlobMatchResult
|
||||
struct MimeGlobMatchResult
|
||||
{
|
||||
void addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength = 0);
|
||||
|
||||
@@ -71,14 +66,14 @@ struct QMimeGlobMatchResult
|
||||
int m_knownSuffixLength = 0;
|
||||
};
|
||||
|
||||
class QMimeGlobPattern
|
||||
class MimeGlobPattern
|
||||
{
|
||||
public:
|
||||
static const unsigned MaxWeight = 100;
|
||||
static const unsigned DefaultWeight = 50;
|
||||
static const unsigned MinWeight = 1;
|
||||
|
||||
explicit QMimeGlobPattern(const QString &thePattern, const QString &theMimeType, unsigned theWeight = DefaultWeight, Qt::CaseSensitivity s = Qt::CaseInsensitive) :
|
||||
explicit MimeGlobPattern(const QString &thePattern, const QString &theMimeType, unsigned theWeight = DefaultWeight, Qt::CaseSensitivity s = Qt::CaseInsensitive) :
|
||||
m_pattern(s == Qt::CaseInsensitive ? thePattern.toLower() : thePattern),
|
||||
m_mimeType(theMimeType),
|
||||
m_weight(theWeight),
|
||||
@@ -87,7 +82,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void swap(QMimeGlobPattern &other) noexcept
|
||||
void swap(MimeGlobPattern &other) noexcept
|
||||
{
|
||||
qSwap(m_pattern, other.m_pattern);
|
||||
qSwap(m_mimeType, other.m_mimeType);
|
||||
@@ -120,9 +115,8 @@ private:
|
||||
Qt::CaseSensitivity m_caseSensitivity;
|
||||
PatternType m_patternType;
|
||||
};
|
||||
Q_DECLARE_SHARED(QMimeGlobPattern)
|
||||
|
||||
class QMimeGlobPatternList : public QList<QMimeGlobPattern>
|
||||
class MimeGlobPatternList : public QList<MimeGlobPattern>
|
||||
{
|
||||
public:
|
||||
bool hasPattern(const QString &mimeType, const QString &pattern) const
|
||||
@@ -140,13 +134,13 @@ public:
|
||||
*/
|
||||
void removeMimeType(const QString &mimeType)
|
||||
{
|
||||
auto isMimeTypeEqual = [&mimeType](const QMimeGlobPattern &pattern) {
|
||||
auto isMimeTypeEqual = [&mimeType](const MimeGlobPattern &pattern) {
|
||||
return pattern.mimeType() == mimeType;
|
||||
};
|
||||
removeIf(isMimeTypeEqual);
|
||||
}
|
||||
|
||||
void match(QMimeGlobMatchResult &result, const QString &fileName) const;
|
||||
void match(MimeGlobMatchResult &result, const QString &fileName) const;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -156,21 +150,21 @@ public:
|
||||
2) a linear list of high-weight globs
|
||||
3) a linear list of low-weight globs
|
||||
*/
|
||||
class QMimeAllGlobPatterns
|
||||
class MimeAllGlobPatterns
|
||||
{
|
||||
public:
|
||||
typedef QHash<QString, QStringList> PatternsMap; // MIME type -> patterns
|
||||
|
||||
void addGlob(const QMimeGlobPattern &glob);
|
||||
void addGlob(const MimeGlobPattern &glob);
|
||||
void removeMimeType(const QString &mimeType);
|
||||
void matchingGlobs(const QString &fileName, QMimeGlobMatchResult &result) const;
|
||||
void matchingGlobs(const QString &fileName, MimeGlobMatchResult &result) const;
|
||||
void clear();
|
||||
|
||||
PatternsMap m_fastPatterns; // example: "doc" -> "application/msword", "text/plain"
|
||||
QMimeGlobPatternList m_highWeightGlobs;
|
||||
QMimeGlobPatternList m_lowWeightGlobs; // <= 50, including the non-fast 50 patterns
|
||||
MimeGlobPatternList m_highWeightGlobs;
|
||||
MimeGlobPatternList m_lowWeightGlobs; // <= 50, including the non-fast 50 patterns
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
||||
#endif // QMIMEGLOBPATTERN_P_H
|
||||
Q_DECLARE_SHARED(Utils::MimeGlobPattern)
|
||||
|
@@ -37,17 +37,14 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "mimemagicrule_p.h"
|
||||
|
||||
#define QT_NO_CAST_FROM_ASCII
|
||||
|
||||
#include "qmimemagicrule_p.h"
|
||||
|
||||
#include "qmimetypeparser_p.h"
|
||||
#include "mimetypeparser_p.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QDebug>
|
||||
#include <qendian.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
// in the same order as Type!
|
||||
static const char magicRuleTypes_string[] =
|
||||
@@ -66,7 +63,7 @@ static const int magicRuleTypes_indices[] = {
|
||||
0, 8, 15, 22, 29, 35, 41, 50, 59, 64, 0
|
||||
};
|
||||
|
||||
QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName)
|
||||
MimeMagicRule::Type MimeMagicRule::type(const QByteArray &theTypeName)
|
||||
{
|
||||
for (int i = String; i <= Byte; ++i) {
|
||||
if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i])
|
||||
@@ -75,12 +72,12 @@ QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName)
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType)
|
||||
QByteArray MimeMagicRule::typeName(MimeMagicRule::Type theType)
|
||||
{
|
||||
return magicRuleTypes_string + magicRuleTypes_indices[theType];
|
||||
}
|
||||
|
||||
bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const
|
||||
bool MimeMagicRule::operator==(const MimeMagicRule &other) const
|
||||
{
|
||||
return m_type == other.m_type &&
|
||||
m_value == other.m_value &&
|
||||
@@ -94,7 +91,7 @@ bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const
|
||||
}
|
||||
|
||||
// Used by both providers
|
||||
bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength,
|
||||
bool MimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength,
|
||||
int valueLength, const char *valueData, const char *mask)
|
||||
{
|
||||
// Size of searched data.
|
||||
@@ -143,14 +140,14 @@ bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int range
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QMimeMagicRule::matchString(const QByteArray &data) const
|
||||
bool MimeMagicRule::matchString(const QByteArray &data) const
|
||||
{
|
||||
const int rangeLength = m_endPos - m_startPos + 1;
|
||||
return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());
|
||||
return MimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool QMimeMagicRule::matchNumber(const QByteArray &data) const
|
||||
bool MimeMagicRule::matchNumber(const QByteArray &data) const
|
||||
{
|
||||
const T value(m_number);
|
||||
const T mask(m_numberMask);
|
||||
@@ -221,12 +218,12 @@ static inline QByteArray makePattern(const QByteArray &value)
|
||||
// <match value="must be converted with BinHex" type="string" offset="11"/>
|
||||
// <match value="0x9501" type="big16" offset="0:64"/>
|
||||
|
||||
QMimeMagicRule::QMimeMagicRule(const QString &type,
|
||||
MimeMagicRule::MimeMagicRule(const QString &type,
|
||||
const QByteArray &value,
|
||||
const QString &offsets,
|
||||
const QByteArray &mask,
|
||||
QString *errorString)
|
||||
: m_type(QMimeMagicRule::type(type.toLatin1())),
|
||||
: m_type(MimeMagicRule::type(type.toLatin1())),
|
||||
m_value(value),
|
||||
m_mask(mask),
|
||||
m_matchFunction(nullptr)
|
||||
@@ -238,8 +235,8 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
|
||||
const int colonIndex = offsets.indexOf(QLatin1Char(':'));
|
||||
const QStringView startPosStr = QStringView{offsets}.mid(0, colonIndex); // \ These decay to returning 'offsets'
|
||||
const QStringView endPosStr = QStringView{offsets}.mid(colonIndex + 1);// / unchanged when colonIndex == -1
|
||||
if (Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
|
||||
Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
|
||||
if (Q_UNLIKELY(!MimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
|
||||
Q_UNLIKELY(!MimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
|
||||
m_type = Invalid;
|
||||
return;
|
||||
}
|
||||
@@ -287,13 +284,13 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
|
||||
m_mask.fill(char(-1), m_pattern.size());
|
||||
}
|
||||
m_mask.squeeze();
|
||||
m_matchFunction = &QMimeMagicRule::matchString;
|
||||
m_matchFunction = &MimeMagicRule::matchString;
|
||||
break;
|
||||
case Byte:
|
||||
if (m_number <= quint8(-1)) {
|
||||
if (m_numberMask == 0)
|
||||
m_numberMask = quint8(-1);
|
||||
m_matchFunction = &QMimeMagicRule::matchNumber<quint8>;
|
||||
m_matchFunction = &MimeMagicRule::matchNumber<quint8>;
|
||||
}
|
||||
break;
|
||||
case Big16:
|
||||
@@ -308,7 +305,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
|
||||
if (m_number <= quint16(-1)) {
|
||||
if (m_numberMask == 0)
|
||||
m_numberMask = quint16(-1);
|
||||
m_matchFunction = &QMimeMagicRule::matchNumber<quint16>;
|
||||
m_matchFunction = &MimeMagicRule::matchNumber<quint16>;
|
||||
}
|
||||
break;
|
||||
case Big32:
|
||||
@@ -320,14 +317,14 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
|
||||
case Host32:
|
||||
if (m_numberMask == 0)
|
||||
m_numberMask = quint32(-1);
|
||||
m_matchFunction = &QMimeMagicRule::matchNumber<quint32>;
|
||||
m_matchFunction = &MimeMagicRule::matchNumber<quint32>;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray QMimeMagicRule::mask() const
|
||||
QByteArray MimeMagicRule::mask() const
|
||||
{
|
||||
QByteArray result = m_mask;
|
||||
if (m_type == String) {
|
||||
@@ -337,7 +334,7 @@ QByteArray QMimeMagicRule::mask() const
|
||||
return result;
|
||||
}
|
||||
|
||||
bool QMimeMagicRule::matches(const QByteArray &data) const
|
||||
bool MimeMagicRule::matches(const QByteArray &data) const
|
||||
{
|
||||
const bool ok = m_matchFunction && (this->*m_matchFunction)(data);
|
||||
if (!ok)
|
||||
@@ -349,7 +346,7 @@ bool QMimeMagicRule::matches(const QByteArray &data) const
|
||||
|
||||
//qDebug() << "Checking" << m_subMatches.count() << "sub-rules";
|
||||
// Check that one of the submatches matches too
|
||||
for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ;
|
||||
for ( QList<MimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ;
|
||||
it != end ; ++it ) {
|
||||
if ((*it).matches(data)) {
|
||||
// One of the hierarchies matched -> mimetype recognized.
|
||||
@@ -361,4 +358,4 @@ bool QMimeMagicRule::matches(const QByteArray &data) const
|
||||
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
@@ -37,8 +37,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMEMAGICRULE_P_H
|
||||
#define QMIMEMAGICRULE_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -51,25 +50,21 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qscopedpointer.h>
|
||||
#include <QtCore/qlist.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
class QMimeMagicRule
|
||||
class MimeMagicRule
|
||||
{
|
||||
public:
|
||||
enum Type { Invalid = 0, String, Host16, Host32, Big16, Big32, Little16, Little32, Byte };
|
||||
|
||||
QMimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets,
|
||||
MimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets,
|
||||
const QByteArray &mask, QString *errorString);
|
||||
|
||||
void swap(QMimeMagicRule &other) noexcept
|
||||
void swap(MimeMagicRule &other) noexcept
|
||||
{
|
||||
qSwap(m_type, other.m_type);
|
||||
qSwap(m_value, other.m_value);
|
||||
@@ -82,7 +77,7 @@ public:
|
||||
qSwap(m_matchFunction, other.m_matchFunction);
|
||||
}
|
||||
|
||||
bool operator==(const QMimeMagicRule &other) const;
|
||||
bool operator==(const MimeMagicRule &other) const;
|
||||
|
||||
Type type() const { return m_type; }
|
||||
QByteArray value() const { return m_value; }
|
||||
@@ -94,7 +89,7 @@ public:
|
||||
|
||||
bool matches(const QByteArray &data) const;
|
||||
|
||||
QList<QMimeMagicRule> m_subMatches;
|
||||
QList<MimeMagicRule> m_subMatches;
|
||||
|
||||
static Type type(const QByteArray &type);
|
||||
static QByteArray typeName(Type type);
|
||||
@@ -112,7 +107,7 @@ private:
|
||||
quint32 m_number;
|
||||
quint32 m_numberMask;
|
||||
|
||||
typedef bool (QMimeMagicRule::*MatchFunction)(const QByteArray &data) const;
|
||||
typedef bool (MimeMagicRule::*MatchFunction)(const QByteArray &data) const;
|
||||
MatchFunction m_matchFunction;
|
||||
|
||||
private:
|
||||
@@ -121,8 +116,7 @@ private:
|
||||
template <typename T>
|
||||
bool matchNumber(const QByteArray &data) const;
|
||||
};
|
||||
Q_DECLARE_SHARED(QMimeMagicRule)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
||||
#endif // QMIMEMAGICRULE_H
|
||||
Q_DECLARE_SHARED(Utils::MimeMagicRule)
|
||||
|
@@ -37,59 +37,57 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#define QT_NO_CAST_FROM_ASCII
|
||||
#include "mimemagicrulematcher_p.h"
|
||||
|
||||
#include "qmimemagicrulematcher_p.h"
|
||||
#include "mimetype_p.h"
|
||||
|
||||
#include "qmimetype_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\class QMimeMagicRuleMatcher
|
||||
\class MimeMagicRuleMatcher
|
||||
\inmodule QtCore
|
||||
|
||||
\brief The QMimeMagicRuleMatcher class checks a number of rules based on operator "or".
|
||||
\brief The MimeMagicRuleMatcher class checks a number of rules based on operator "or".
|
||||
|
||||
It is used for rules parsed from XML files.
|
||||
|
||||
\sa QMimeType, QMimeDatabase, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
|
||||
\sa QMimeTypeParserBase, MimeTypeParser
|
||||
\sa MimeType, MimeDatabase, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
|
||||
\sa MimeTypeParserBase, MimeTypeParser
|
||||
*/
|
||||
|
||||
QMimeMagicRuleMatcher::QMimeMagicRuleMatcher(const QString &mime, unsigned thePriority) :
|
||||
MimeMagicRuleMatcher::MimeMagicRuleMatcher(const QString &mime, unsigned thePriority) :
|
||||
m_list(),
|
||||
m_priority(thePriority),
|
||||
m_mimetype(mime)
|
||||
{
|
||||
}
|
||||
|
||||
bool QMimeMagicRuleMatcher::operator==(const QMimeMagicRuleMatcher &other) const
|
||||
bool MimeMagicRuleMatcher::operator==(const MimeMagicRuleMatcher &other) const
|
||||
{
|
||||
return m_list == other.m_list &&
|
||||
m_priority == other.m_priority;
|
||||
}
|
||||
|
||||
void QMimeMagicRuleMatcher::addRule(const QMimeMagicRule &rule)
|
||||
void MimeMagicRuleMatcher::addRule(const MimeMagicRule &rule)
|
||||
{
|
||||
m_list.append(rule);
|
||||
}
|
||||
|
||||
void QMimeMagicRuleMatcher::addRules(const QList<QMimeMagicRule> &rules)
|
||||
void MimeMagicRuleMatcher::addRules(const QList<MimeMagicRule> &rules)
|
||||
{
|
||||
m_list.append(rules);
|
||||
}
|
||||
|
||||
QList<QMimeMagicRule> QMimeMagicRuleMatcher::magicRules() const
|
||||
QList<MimeMagicRule> MimeMagicRuleMatcher::magicRules() const
|
||||
{
|
||||
return m_list;
|
||||
}
|
||||
|
||||
// Check for a match on contents of a file
|
||||
bool QMimeMagicRuleMatcher::matches(const QByteArray &data) const
|
||||
bool MimeMagicRuleMatcher::matches(const QByteArray &data) const
|
||||
{
|
||||
for (const QMimeMagicRule &magicRule : m_list) {
|
||||
for (const MimeMagicRule &magicRule : m_list) {
|
||||
if (magicRule.matches(data))
|
||||
return true;
|
||||
}
|
||||
@@ -98,9 +96,9 @@ bool QMimeMagicRuleMatcher::matches(const QByteArray &data) const
|
||||
}
|
||||
|
||||
// Return a priority value from 1..100
|
||||
unsigned QMimeMagicRuleMatcher::priority() const
|
||||
unsigned MimeMagicRuleMatcher::priority() const
|
||||
{
|
||||
return m_priority;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
@@ -37,8 +37,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMEMAGICRULEMATCHER_P_H
|
||||
#define QMIMEMAGICRULEMATCHER_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -51,33 +50,31 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qmimemagicrule_p.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
#include "mimemagicrule_p.h"
|
||||
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qstring.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
class QMimeMagicRuleMatcher
|
||||
class MimeMagicRuleMatcher
|
||||
{
|
||||
public:
|
||||
explicit QMimeMagicRuleMatcher(const QString &mime, unsigned priority = 65535);
|
||||
explicit MimeMagicRuleMatcher(const QString &mime, unsigned priority = 65535);
|
||||
|
||||
void swap(QMimeMagicRuleMatcher &other) noexcept
|
||||
void swap(MimeMagicRuleMatcher &other) noexcept
|
||||
{
|
||||
qSwap(m_list, other.m_list);
|
||||
qSwap(m_priority, other.m_priority);
|
||||
qSwap(m_mimetype, other.m_mimetype);
|
||||
}
|
||||
|
||||
bool operator==(const QMimeMagicRuleMatcher &other) const;
|
||||
bool operator==(const MimeMagicRuleMatcher &other) const;
|
||||
|
||||
void addRule(const QMimeMagicRule &rule);
|
||||
void addRules(const QList<QMimeMagicRule> &rules);
|
||||
QList<QMimeMagicRule> magicRules() const;
|
||||
void addRule(const MimeMagicRule &rule);
|
||||
void addRules(const QList<MimeMagicRule> &rules);
|
||||
QList<MimeMagicRule> magicRules() const;
|
||||
|
||||
bool matches(const QByteArray &data) const;
|
||||
|
||||
@@ -86,12 +83,11 @@ public:
|
||||
QString mimetype() const { return m_mimetype; }
|
||||
|
||||
private:
|
||||
QList<QMimeMagicRule> m_list;
|
||||
QList<MimeMagicRule> m_list;
|
||||
unsigned m_priority;
|
||||
QString m_mimetype;
|
||||
};
|
||||
Q_DECLARE_SHARED(QMimeMagicRuleMatcher)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
||||
#endif // QMIMEMAGICRULEMATCHER_P_H
|
||||
Q_DECLARE_SHARED(Utils::MimeMagicRuleMatcher)
|
||||
|
@@ -39,12 +39,12 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmimeprovider_p.h"
|
||||
#include "mimeprovider_p.h"
|
||||
|
||||
#include "mimetypeparser_p.h"
|
||||
#include "mimemagicrulematcher_p.h"
|
||||
|
||||
#include "qmimetypeparser_p.h"
|
||||
#include <qstandardpaths.h>
|
||||
#include "qmimemagicrulematcher_p.h"
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
#include <QBuffer>
|
||||
#include <QDir>
|
||||
@@ -54,7 +54,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QtEndian>
|
||||
|
||||
#if QT_CONFIG(mimetype_database)
|
||||
#if 0 // QT_CONFIG(mimetype_database)
|
||||
# if defined(Q_CC_MSVC)
|
||||
# pragma section(".qtmimedatabase", read, shared)
|
||||
__declspec(allocate(".qtmimedatabase")) __declspec(align(4096))
|
||||
@@ -82,21 +82,21 @@ __attribute__((section(".qtmimedatabase"), aligned(4096)))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
QMimeProviderBase::QMimeProviderBase(QMimeDatabasePrivate *db, const QString &directory)
|
||||
MimeProviderBase::MimeProviderBase(MimeDatabasePrivate *db, const QString &directory)
|
||||
: m_db(db), m_directory(directory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QMimeBinaryProvider::QMimeBinaryProvider(QMimeDatabasePrivate *db, const QString &directory)
|
||||
: QMimeProviderBase(db, directory), m_mimetypeListLoaded(false)
|
||||
MimeBinaryProvider::MimeBinaryProvider(MimeDatabasePrivate *db, const QString &directory)
|
||||
: MimeProviderBase(db, directory), m_mimetypeListLoaded(false)
|
||||
{
|
||||
ensureLoaded();
|
||||
}
|
||||
|
||||
struct QMimeBinaryProvider::CacheFile
|
||||
struct MimeBinaryProvider::CacheFile
|
||||
{
|
||||
CacheFile(const QString &fileName);
|
||||
~CacheFile();
|
||||
@@ -123,17 +123,17 @@ struct QMimeBinaryProvider::CacheFile
|
||||
bool m_valid;
|
||||
};
|
||||
|
||||
QMimeBinaryProvider::CacheFile::CacheFile(const QString &fileName)
|
||||
MimeBinaryProvider::CacheFile::CacheFile(const QString &fileName)
|
||||
: file(fileName), m_valid(false)
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
QMimeBinaryProvider::CacheFile::~CacheFile()
|
||||
MimeBinaryProvider::CacheFile::~CacheFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::CacheFile::load()
|
||||
bool MimeBinaryProvider::CacheFile::load()
|
||||
{
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
@@ -147,7 +147,7 @@ bool QMimeBinaryProvider::CacheFile::load()
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::CacheFile::reload()
|
||||
bool MimeBinaryProvider::CacheFile::reload()
|
||||
{
|
||||
m_valid = false;
|
||||
if (file.isOpen()) {
|
||||
@@ -157,17 +157,17 @@ bool QMimeBinaryProvider::CacheFile::reload()
|
||||
return load();
|
||||
}
|
||||
|
||||
QMimeBinaryProvider::~QMimeBinaryProvider()
|
||||
MimeBinaryProvider::~MimeBinaryProvider()
|
||||
{
|
||||
delete m_cacheFile;
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::isValid()
|
||||
bool MimeBinaryProvider::isValid()
|
||||
{
|
||||
return m_cacheFile != nullptr;
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::isInternalDatabase() const
|
||||
bool MimeBinaryProvider::isInternalDatabase() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ enum {
|
||||
PosGenericIconsListOffset = 36
|
||||
};
|
||||
|
||||
bool QMimeBinaryProvider::checkCacheChanged()
|
||||
bool MimeBinaryProvider::checkCacheChanged()
|
||||
{
|
||||
QFileInfo fileInfo(m_cacheFile->file);
|
||||
if (fileInfo.lastModified() > m_cacheFile->m_mtime) {
|
||||
@@ -197,7 +197,7 @@ bool QMimeBinaryProvider::checkCacheChanged()
|
||||
return false;
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::ensureLoaded()
|
||||
void MimeBinaryProvider::ensureLoaded()
|
||||
{
|
||||
if (!m_cacheFile) {
|
||||
const QString cacheFileName = m_directory + QLatin1String("/mime.cache");
|
||||
@@ -218,28 +218,28 @@ void QMimeBinaryProvider::ensureLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
static QMimeType mimeTypeForNameUnchecked(const QString &name)
|
||||
static MimeType mimeTypeForNameUnchecked(const QString &name)
|
||||
{
|
||||
QMimeTypePrivate data;
|
||||
MimeTypePrivate data;
|
||||
data.name = name;
|
||||
data.fromCache = true;
|
||||
// The rest is retrieved on demand.
|
||||
// comment and globPatterns: in loadMimeTypePrivate
|
||||
// iconName: in loadIcon
|
||||
// genericIconName: in loadGenericIcon
|
||||
return QMimeType(data);
|
||||
return MimeType(data);
|
||||
}
|
||||
|
||||
QMimeType QMimeBinaryProvider::mimeTypeForName(const QString &name)
|
||||
MimeType MimeBinaryProvider::mimeTypeForName(const QString &name)
|
||||
{
|
||||
if (!m_mimetypeListLoaded)
|
||||
loadMimeTypeList();
|
||||
if (!m_mimetypeNames.contains(name))
|
||||
return QMimeType(); // unknown mimetype
|
||||
return MimeType(); // unknown mimetype
|
||||
return mimeTypeForNameUnchecked(name);
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::addFileNameMatches(const QString &fileName, QMimeGlobMatchResult &result)
|
||||
void MimeBinaryProvider::addFileNameMatches(const QString &fileName, MimeGlobMatchResult &result)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
@@ -261,7 +261,7 @@ void QMimeBinaryProvider::addFileNameMatches(const QString &fileName, QMimeGlobM
|
||||
matchGlobList(result, m_cacheFile, m_cacheFile->getUint32(PosGlobListOffset), fileName);
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName)
|
||||
void MimeBinaryProvider::matchGlobList(MimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName)
|
||||
{
|
||||
const int numGlobs = cacheFile->getUint32(off);
|
||||
//qDebug() << "Loading" << numGlobs << "globs from" << cacheFile->file.fileName() << "at offset" << cacheFile->globListOffset;
|
||||
@@ -276,14 +276,14 @@ void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile
|
||||
|
||||
const char *mimeType = cacheFile->getCharStar(mimeTypeOffset);
|
||||
//qDebug() << pattern << mimeType << weight << caseSensitive;
|
||||
QMimeGlobPattern glob(pattern, QString() /*unused*/, weight, qtCaseSensitive);
|
||||
MimeGlobPattern glob(pattern, QString() /*unused*/, weight, qtCaseSensitive);
|
||||
|
||||
if (glob.matchFileName(fileName))
|
||||
result.addMatch(QLatin1String(mimeType), weight, pattern);
|
||||
}
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBinaryProvider::CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck)
|
||||
bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result, MimeBinaryProvider::CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck)
|
||||
{
|
||||
QChar fileChar = fileName[charPos];
|
||||
int min = 0;
|
||||
@@ -327,7 +327,7 @@ bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBin
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data)
|
||||
bool MimeBinaryProvider::matchMagicRule(MimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data)
|
||||
{
|
||||
const char *dataPtr = data.constData();
|
||||
const int dataSize = data.size();
|
||||
@@ -341,7 +341,7 @@ bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFi
|
||||
const int maskOffset = cacheFile->getUint32(off + 20);
|
||||
const char *mask = maskOffset ? cacheFile->getCharStar(maskOffset) : nullptr;
|
||||
|
||||
if (!QMimeMagicRule::matchSubstring(dataPtr, dataSize, rangeStart, rangeLength, valueLength, cacheFile->getCharStar(valueOffset), mask))
|
||||
if (!MimeMagicRule::matchSubstring(dataPtr, dataSize, rangeStart, rangeLength, valueLength, cacheFile->getCharStar(valueOffset), mask))
|
||||
continue;
|
||||
|
||||
const int numChildren = cacheFile->getUint32(off + 24);
|
||||
@@ -355,7 +355,7 @@ bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFi
|
||||
return false;
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr, QMimeType &candidate)
|
||||
void MimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr, MimeType &candidate)
|
||||
{
|
||||
const int magicListOffset = m_cacheFile->getUint32(PosMagicListOffset);
|
||||
const int numMatches = m_cacheFile->getUint32(magicListOffset);
|
||||
@@ -378,7 +378,7 @@ void QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr,
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::addParents(const QString &mime, QStringList &result)
|
||||
void MimeBinaryProvider::addParents(const QString &mime, QStringList &result)
|
||||
{
|
||||
const QByteArray mimeStr = mime.toLatin1();
|
||||
const int parentListOffset = m_cacheFile->getUint32(PosParentListOffset);
|
||||
@@ -411,7 +411,7 @@ void QMimeBinaryProvider::addParents(const QString &mime, QStringList &result)
|
||||
}
|
||||
}
|
||||
|
||||
QString QMimeBinaryProvider::resolveAlias(const QString &name)
|
||||
QString MimeBinaryProvider::resolveAlias(const QString &name)
|
||||
{
|
||||
const QByteArray input = name.toLatin1();
|
||||
const int aliasListOffset = m_cacheFile->getUint32(PosAliasListOffset);
|
||||
@@ -437,7 +437,7 @@ QString QMimeBinaryProvider::resolveAlias(const QString &name)
|
||||
return QString();
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::addAliases(const QString &name, QStringList &result)
|
||||
void MimeBinaryProvider::addAliases(const QString &name, QStringList &result)
|
||||
{
|
||||
const QByteArray input = name.toLatin1();
|
||||
const int aliasListOffset = m_cacheFile->getUint32(PosAliasListOffset);
|
||||
@@ -457,7 +457,7 @@ void QMimeBinaryProvider::addAliases(const QString &name, QStringList &result)
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::loadMimeTypeList()
|
||||
void MimeBinaryProvider::loadMimeTypeList()
|
||||
{
|
||||
if (!m_mimetypeListLoaded) {
|
||||
m_mimetypeListLoaded = true;
|
||||
@@ -476,7 +476,7 @@ void QMimeBinaryProvider::loadMimeTypeList()
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::addAllMimeTypes(QList<QMimeType> &result)
|
||||
void MimeBinaryProvider::addAllMimeTypes(QList<MimeType> &result)
|
||||
{
|
||||
loadMimeTypeList();
|
||||
if (result.isEmpty()) {
|
||||
@@ -485,13 +485,13 @@ void QMimeBinaryProvider::addAllMimeTypes(QList<QMimeType> &result)
|
||||
result.append(mimeTypeForNameUnchecked(name));
|
||||
} else {
|
||||
for (const QString &name : qAsConst(m_mimetypeNames))
|
||||
if (std::find_if(result.constBegin(), result.constEnd(), [name](const QMimeType &mime) -> bool { return mime.name() == name; })
|
||||
if (std::find_if(result.constBegin(), result.constEnd(), [name](const MimeType &mime) -> bool { return mime.name() == name; })
|
||||
== result.constEnd())
|
||||
result.append(mimeTypeForNameUnchecked(name));
|
||||
}
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
|
||||
bool MimeBinaryProvider::loadMimeTypePrivate(MimeTypePrivate &data)
|
||||
{
|
||||
#ifdef QT_NO_XMLSTREAMREADER
|
||||
Q_UNUSED(data);
|
||||
@@ -573,7 +573,7 @@ bool QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
|
||||
}
|
||||
|
||||
// Binary search in the icons or generic-icons list
|
||||
QLatin1String QMimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime)
|
||||
QLatin1String MimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime)
|
||||
{
|
||||
const int iconsListOffset = cacheFile->getUint32(posListOffset);
|
||||
const int numIcons = cacheFile->getUint32(iconsListOffset);
|
||||
@@ -597,7 +597,7 @@ QLatin1String QMimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posList
|
||||
return QLatin1String();
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::loadIcon(QMimeTypePrivate &data)
|
||||
void MimeBinaryProvider::loadIcon(MimeTypePrivate &data)
|
||||
{
|
||||
const QByteArray inputMime = data.name.toLatin1();
|
||||
const QLatin1String icon = iconForMime(m_cacheFile, PosIconsListOffset, inputMime);
|
||||
@@ -606,7 +606,7 @@ void QMimeBinaryProvider::loadIcon(QMimeTypePrivate &data)
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeBinaryProvider::loadGenericIcon(QMimeTypePrivate &data)
|
||||
void MimeBinaryProvider::loadGenericIcon(MimeTypePrivate &data)
|
||||
{
|
||||
const QByteArray inputMime = data.name.toLatin1();
|
||||
const QLatin1String icon = iconForMime(m_cacheFile, PosGenericIconsListOffset, inputMime);
|
||||
@@ -617,7 +617,7 @@ void QMimeBinaryProvider::loadGenericIcon(QMimeTypePrivate &data)
|
||||
|
||||
////
|
||||
|
||||
#if QT_CONFIG(mimetype_database)
|
||||
#if 0 //QT_CONFIG(mimetype_database)
|
||||
static QString internalMimeFileName()
|
||||
{
|
||||
return QStringLiteral("<internal MIME data>");
|
||||
@@ -664,54 +664,54 @@ QMimeXMLProvider::QMimeXMLProvider(QMimeDatabasePrivate *db, InternalDatabaseEnu
|
||||
#else // !QT_CONFIG(mimetype_database)
|
||||
// never called in release mode, but some debug builds may need
|
||||
// this to be defined.
|
||||
QMimeXMLProvider::QMimeXMLProvider(QMimeDatabasePrivate *db, InternalDatabaseEnum)
|
||||
: QMimeProviderBase(db, QString())
|
||||
MimeXMLProvider::MimeXMLProvider(MimeDatabasePrivate *db, InternalDatabaseEnum)
|
||||
: MimeProviderBase(db, QString())
|
||||
{
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
#endif // QT_CONFIG(mimetype_database)
|
||||
|
||||
QMimeXMLProvider::QMimeXMLProvider(QMimeDatabasePrivate *db, const QString &directory)
|
||||
: QMimeProviderBase(db, directory)
|
||||
MimeXMLProvider::MimeXMLProvider(MimeDatabasePrivate *db, const QString &directory)
|
||||
: MimeProviderBase(db, directory)
|
||||
{
|
||||
ensureLoaded();
|
||||
}
|
||||
|
||||
QMimeXMLProvider::~QMimeXMLProvider()
|
||||
MimeXMLProvider::~MimeXMLProvider()
|
||||
{
|
||||
}
|
||||
|
||||
bool QMimeXMLProvider::isValid()
|
||||
bool MimeXMLProvider::isValid()
|
||||
{
|
||||
// If you change this method, adjust the logic in QMimeDatabasePrivate::loadProviders,
|
||||
// which assumes isValid==false is only possible in QMimeBinaryProvider.
|
||||
// If you change this method, adjust the logic in MimeDatabasePrivate::loadProviders,
|
||||
// which assumes isValid==false is only possible in MimeBinaryProvider.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QMimeXMLProvider::isInternalDatabase() const
|
||||
bool MimeXMLProvider::isInternalDatabase() const
|
||||
{
|
||||
#if QT_CONFIG(mimetype_database)
|
||||
#if 0 //QT_CONFIG(mimetype_database)
|
||||
return m_directory == internalMimeFileName();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
QMimeType QMimeXMLProvider::mimeTypeForName(const QString &name)
|
||||
MimeType MimeXMLProvider::mimeTypeForName(const QString &name)
|
||||
{
|
||||
return m_nameMimeTypeMap.value(name);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addFileNameMatches(const QString &fileName, QMimeGlobMatchResult &result)
|
||||
void MimeXMLProvider::addFileNameMatches(const QString &fileName, MimeGlobMatchResult &result)
|
||||
{
|
||||
m_mimeTypeGlobs.matchingGlobs(fileName, result);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr, QMimeType &candidate)
|
||||
void MimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr, MimeType &candidate)
|
||||
{
|
||||
QString candidateName;
|
||||
bool foundOne = false;
|
||||
for (const QMimeMagicRuleMatcher &matcher : qAsConst(m_magicMatchers)) {
|
||||
for (const MimeMagicRuleMatcher &matcher : qAsConst(m_magicMatchers)) {
|
||||
if (matcher.matches(data)) {
|
||||
const int priority = matcher.priority();
|
||||
if (priority > *accuracyPtr) {
|
||||
@@ -725,7 +725,7 @@ void QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr, QMi
|
||||
candidate = mimeTypeForName(candidateName);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::ensureLoaded()
|
||||
void MimeXMLProvider::ensureLoaded()
|
||||
{
|
||||
QStringList allFiles;
|
||||
const QString packageDir = m_directory + QStringLiteral("/packages");
|
||||
@@ -751,14 +751,14 @@ void QMimeXMLProvider::ensureLoaded()
|
||||
load(file);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::load(const QString &fileName)
|
||||
void MimeXMLProvider::load(const QString &fileName)
|
||||
{
|
||||
QString errorMessage;
|
||||
if (!load(fileName, &errorMessage))
|
||||
qWarning("QMimeDatabase: Error loading %ls\n%ls", qUtf16Printable(fileName), qUtf16Printable(errorMessage));
|
||||
qWarning("MimeDatabase: Error loading %ls\n%ls", qUtf16Printable(fileName), qUtf16Printable(errorMessage));
|
||||
}
|
||||
|
||||
bool QMimeXMLProvider::load(const QString &fileName, QString *errorMessage)
|
||||
bool MimeXMLProvider::load(const QString &fileName, QString *errorMessage)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
@@ -770,35 +770,35 @@ bool QMimeXMLProvider::load(const QString &fileName, QString *errorMessage)
|
||||
if (errorMessage)
|
||||
errorMessage->clear();
|
||||
|
||||
QMimeTypeParser parser(*this);
|
||||
MimeTypeParser parser(*this);
|
||||
return parser.parse(&file, fileName, errorMessage);
|
||||
}
|
||||
|
||||
#if QT_CONFIG(mimetype_database)
|
||||
void QMimeXMLProvider::load(const char *data, qsizetype len)
|
||||
#if 0 //QT_CONFIG(mimetype_database)
|
||||
void MimeXMLProvider::load(const char *data, qsizetype len)
|
||||
{
|
||||
QBuffer buffer;
|
||||
buffer.setData(QByteArray::fromRawData(data, len));
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
QString errorMessage;
|
||||
QMimeTypeParser parser(*this);
|
||||
MimeTypeParser parser(*this);
|
||||
if (!parser.parse(&buffer, internalMimeFileName(), &errorMessage))
|
||||
qWarning("QMimeDatabase: Error loading internal MIME data\n%s", qPrintable(errorMessage));
|
||||
qWarning("MimeDatabase: Error loading internal MIME data\n%s", qPrintable(errorMessage));
|
||||
}
|
||||
#endif
|
||||
|
||||
void QMimeXMLProvider::addGlobPattern(const QMimeGlobPattern &glob)
|
||||
void MimeXMLProvider::addGlobPattern(const MimeGlobPattern &glob)
|
||||
{
|
||||
m_mimeTypeGlobs.addGlob(glob);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addMimeType(const QMimeType &mt)
|
||||
void MimeXMLProvider::addMimeType(const MimeType &mt)
|
||||
{
|
||||
Q_ASSERT(!mt.d.data()->fromCache);
|
||||
m_nameMimeTypeMap.insert(mt.name(), mt);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addParents(const QString &mime, QStringList &result)
|
||||
void MimeXMLProvider::addParents(const QString &mime, QStringList &result)
|
||||
{
|
||||
for (const QString &parent : m_parents.value(mime)) {
|
||||
if (!result.contains(parent))
|
||||
@@ -806,12 +806,12 @@ void QMimeXMLProvider::addParents(const QString &mime, QStringList &result)
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addParent(const QString &child, const QString &parent)
|
||||
void MimeXMLProvider::addParent(const QString &child, const QString &parent)
|
||||
{
|
||||
m_parents[child].append(parent);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addAliases(const QString &name, QStringList &result)
|
||||
void MimeXMLProvider::addAliases(const QString &name, QStringList &result)
|
||||
{
|
||||
// Iterate through the whole hash. This method is rarely used.
|
||||
for (auto it = m_aliases.constBegin(), end = m_aliases.constEnd() ; it != end ; ++it) {
|
||||
@@ -823,33 +823,33 @@ void QMimeXMLProvider::addAliases(const QString &name, QStringList &result)
|
||||
|
||||
}
|
||||
|
||||
QString QMimeXMLProvider::resolveAlias(const QString &name)
|
||||
QString MimeXMLProvider::resolveAlias(const QString &name)
|
||||
{
|
||||
return m_aliases.value(name);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addAlias(const QString &alias, const QString &name)
|
||||
void MimeXMLProvider::addAlias(const QString &alias, const QString &name)
|
||||
{
|
||||
m_aliases.insert(alias, name);
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addAllMimeTypes(QList<QMimeType> &result)
|
||||
void MimeXMLProvider::addAllMimeTypes(QList<MimeType> &result)
|
||||
{
|
||||
if (result.isEmpty()) { // fast path
|
||||
result = m_nameMimeTypeMap.values();
|
||||
} else {
|
||||
for (auto it = m_nameMimeTypeMap.constBegin(), end = m_nameMimeTypeMap.constEnd() ; it != end ; ++it) {
|
||||
const QString newMime = it.key();
|
||||
if (std::find_if(result.constBegin(), result.constEnd(), [newMime](const QMimeType &mime) -> bool { return mime.name() == newMime; })
|
||||
if (std::find_if(result.constBegin(), result.constEnd(), [newMime](const MimeType &mime) -> bool { return mime.name() == newMime; })
|
||||
== result.constEnd())
|
||||
result.append(it.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher)
|
||||
void MimeXMLProvider::addMagicMatcher(const MimeMagicRuleMatcher &matcher)
|
||||
{
|
||||
m_magicMatchers.append(matcher);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
@@ -38,8 +38,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMEPROVIDER_P_H
|
||||
#define QMIMEPROVIDER_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -52,72 +51,70 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qmimedatabase_p.h"
|
||||
#include "mimedatabase_p.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
|
||||
#include "qmimeglobpattern_p.h"
|
||||
#include "mimeglobpattern_p.h"
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtCore/qset.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
class QMimeMagicRuleMatcher;
|
||||
class MimeMagicRuleMatcher;
|
||||
|
||||
class QMimeProviderBase
|
||||
class MimeProviderBase
|
||||
{
|
||||
public:
|
||||
QMimeProviderBase(QMimeDatabasePrivate *db, const QString &directory);
|
||||
virtual ~QMimeProviderBase() {}
|
||||
MimeProviderBase(MimeDatabasePrivate *db, const QString &directory);
|
||||
virtual ~MimeProviderBase() {}
|
||||
|
||||
virtual bool isValid() = 0;
|
||||
virtual bool isInternalDatabase() const = 0;
|
||||
virtual QMimeType mimeTypeForName(const QString &name) = 0;
|
||||
virtual void addFileNameMatches(const QString &fileName, QMimeGlobMatchResult &result) = 0;
|
||||
virtual MimeType mimeTypeForName(const QString &name) = 0;
|
||||
virtual void addFileNameMatches(const QString &fileName, MimeGlobMatchResult &result) = 0;
|
||||
virtual void addParents(const QString &mime, QStringList &result) = 0;
|
||||
virtual QString resolveAlias(const QString &name) = 0;
|
||||
virtual void addAliases(const QString &name, QStringList &result) = 0;
|
||||
virtual void findByMagic(const QByteArray &data, int *accuracyPtr, QMimeType &candidate) = 0;
|
||||
virtual void addAllMimeTypes(QList<QMimeType> &result) = 0;
|
||||
virtual bool loadMimeTypePrivate(QMimeTypePrivate &) { return false; }
|
||||
virtual void loadIcon(QMimeTypePrivate &) {}
|
||||
virtual void loadGenericIcon(QMimeTypePrivate &) {}
|
||||
virtual void findByMagic(const QByteArray &data, int *accuracyPtr, MimeType &candidate) = 0;
|
||||
virtual void addAllMimeTypes(QList<MimeType> &result) = 0;
|
||||
virtual bool loadMimeTypePrivate(MimeTypePrivate &) { return false; }
|
||||
virtual void loadIcon(MimeTypePrivate &) {}
|
||||
virtual void loadGenericIcon(MimeTypePrivate &) {}
|
||||
virtual void ensureLoaded() {}
|
||||
|
||||
QString directory() const { return m_directory; }
|
||||
|
||||
QMimeDatabasePrivate *m_db;
|
||||
MimeDatabasePrivate *m_db;
|
||||
QString m_directory;
|
||||
};
|
||||
|
||||
/*
|
||||
Parses the files 'mime.cache' and 'types' on demand
|
||||
*/
|
||||
class QMimeBinaryProvider : public QMimeProviderBase
|
||||
class MimeBinaryProvider : public MimeProviderBase
|
||||
{
|
||||
public:
|
||||
QMimeBinaryProvider(QMimeDatabasePrivate *db, const QString &directory);
|
||||
virtual ~QMimeBinaryProvider();
|
||||
MimeBinaryProvider(MimeDatabasePrivate *db, const QString &directory);
|
||||
virtual ~MimeBinaryProvider();
|
||||
|
||||
bool isValid() override;
|
||||
bool isInternalDatabase() const override;
|
||||
QMimeType mimeTypeForName(const QString &name) override;
|
||||
void addFileNameMatches(const QString &fileName, QMimeGlobMatchResult &result) override;
|
||||
MimeType mimeTypeForName(const QString &name) override;
|
||||
void addFileNameMatches(const QString &fileName, MimeGlobMatchResult &result) override;
|
||||
void addParents(const QString &mime, QStringList &result) override;
|
||||
QString resolveAlias(const QString &name) override;
|
||||
void addAliases(const QString &name, QStringList &result) override;
|
||||
void findByMagic(const QByteArray &data, int *accuracyPtr, QMimeType &candidate) override;
|
||||
void addAllMimeTypes(QList<QMimeType> &result) override;
|
||||
bool loadMimeTypePrivate(QMimeTypePrivate &) override;
|
||||
void loadIcon(QMimeTypePrivate &) override;
|
||||
void loadGenericIcon(QMimeTypePrivate &) override;
|
||||
void findByMagic(const QByteArray &data, int *accuracyPtr, MimeType &candidate) override;
|
||||
void addAllMimeTypes(QList<MimeType> &result) override;
|
||||
bool loadMimeTypePrivate(MimeTypePrivate &) override;
|
||||
void loadIcon(MimeTypePrivate &) override;
|
||||
void loadGenericIcon(MimeTypePrivate &) override;
|
||||
void ensureLoaded() override;
|
||||
|
||||
private:
|
||||
struct CacheFile;
|
||||
|
||||
void matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int offset, const QString &fileName);
|
||||
bool matchSuffixTree(QMimeGlobMatchResult &result, CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck);
|
||||
void matchGlobList(MimeGlobMatchResult &result, CacheFile *cacheFile, int offset, const QString &fileName);
|
||||
bool matchSuffixTree(MimeGlobMatchResult &result, CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck);
|
||||
bool matchMagicRule(CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data);
|
||||
QLatin1String iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime);
|
||||
void loadMimeTypeList();
|
||||
@@ -138,44 +135,44 @@ private:
|
||||
/*
|
||||
Parses the raw XML files (slower)
|
||||
*/
|
||||
class QMimeXMLProvider : public QMimeProviderBase
|
||||
class MimeXMLProvider : public MimeProviderBase
|
||||
{
|
||||
public:
|
||||
enum InternalDatabaseEnum { InternalDatabase };
|
||||
#if QT_CONFIG(mimetype_database)
|
||||
#if 0 // QT_CONFIG(mimetype_database)
|
||||
enum : bool { InternalDatabaseAvailable = true };
|
||||
#else
|
||||
enum : bool { InternalDatabaseAvailable = false };
|
||||
#endif
|
||||
QMimeXMLProvider(QMimeDatabasePrivate *db, InternalDatabaseEnum);
|
||||
QMimeXMLProvider(QMimeDatabasePrivate *db, const QString &directory);
|
||||
~QMimeXMLProvider();
|
||||
MimeXMLProvider(MimeDatabasePrivate *db, InternalDatabaseEnum);
|
||||
MimeXMLProvider(MimeDatabasePrivate *db, const QString &directory);
|
||||
~MimeXMLProvider();
|
||||
|
||||
bool isValid() override;
|
||||
bool isInternalDatabase() const override;
|
||||
QMimeType mimeTypeForName(const QString &name) override;
|
||||
void addFileNameMatches(const QString &fileName, QMimeGlobMatchResult &result) override;
|
||||
MimeType mimeTypeForName(const QString &name) override;
|
||||
void addFileNameMatches(const QString &fileName, MimeGlobMatchResult &result) override;
|
||||
void addParents(const QString &mime, QStringList &result) override;
|
||||
QString resolveAlias(const QString &name) override;
|
||||
void addAliases(const QString &name, QStringList &result) override;
|
||||
void findByMagic(const QByteArray &data, int *accuracyPtr, QMimeType &candidate) override;
|
||||
void addAllMimeTypes(QList<QMimeType> &result) override;
|
||||
void findByMagic(const QByteArray &data, int *accuracyPtr, MimeType &candidate) override;
|
||||
void addAllMimeTypes(QList<MimeType> &result) override;
|
||||
void ensureLoaded() override;
|
||||
|
||||
bool load(const QString &fileName, QString *errorMessage);
|
||||
|
||||
// Called by the mimetype xml parser
|
||||
void addMimeType(const QMimeType &mt);
|
||||
void addGlobPattern(const QMimeGlobPattern &glob);
|
||||
void addMimeType(const MimeType &mt);
|
||||
void addGlobPattern(const MimeGlobPattern &glob);
|
||||
void addParent(const QString &child, const QString &parent);
|
||||
void addAlias(const QString &alias, const QString &name);
|
||||
void addMagicMatcher(const QMimeMagicRuleMatcher &matcher);
|
||||
void addMagicMatcher(const MimeMagicRuleMatcher &matcher);
|
||||
|
||||
private:
|
||||
void load(const QString &fileName);
|
||||
void load(const char *data, qsizetype len);
|
||||
|
||||
typedef QHash<QString, QMimeType> NameMimeTypeMap;
|
||||
typedef QHash<QString, MimeType> NameMimeTypeMap;
|
||||
NameMimeTypeMap m_nameMimeTypeMap;
|
||||
|
||||
typedef QHash<QString, QString> AliasHash;
|
||||
@@ -183,12 +180,10 @@ private:
|
||||
|
||||
typedef QHash<QString, QStringList> ParentsHash;
|
||||
ParentsHash m_parents;
|
||||
QMimeAllGlobPatterns m_mimeTypeGlobs;
|
||||
MimeAllGlobPatterns m_mimeTypeGlobs;
|
||||
|
||||
QList<QMimeMagicRuleMatcher> m_magicMatchers;
|
||||
QList<MimeMagicRuleMatcher> m_magicMatchers;
|
||||
QStringList m_allFiles;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QMIMEPROVIDER_P_H
|
||||
} // namespace Utils
|
||||
|
@@ -38,13 +38,13 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmimetype.h"
|
||||
#include "mimetype.h"
|
||||
|
||||
#include "qmimetype_p.h"
|
||||
#include "qmimedatabase_p.h"
|
||||
#include "qmimeprovider_p.h"
|
||||
#include "mimetype_p.h"
|
||||
#include "mimedatabase_p.h"
|
||||
#include "mimeprovider_p.h"
|
||||
|
||||
#include "qmimeglobpattern_p.h"
|
||||
#include "mimeglobpattern_p.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QLocale>
|
||||
@@ -52,13 +52,13 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
QMimeTypePrivate::QMimeTypePrivate()
|
||||
MimeTypePrivate::MimeTypePrivate()
|
||||
: loaded(false), fromCache(false)
|
||||
{}
|
||||
|
||||
QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other)
|
||||
MimeTypePrivate::MimeTypePrivate(const MimeType &other)
|
||||
: loaded(other.d->loaded),
|
||||
name(other.d->name),
|
||||
localeComments(other.d->localeComments),
|
||||
@@ -67,7 +67,7 @@ QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other)
|
||||
globPatterns(other.d->globPatterns)
|
||||
{}
|
||||
|
||||
void QMimeTypePrivate::clear()
|
||||
void MimeTypePrivate::clear()
|
||||
{
|
||||
name.clear();
|
||||
localeComments.clear();
|
||||
@@ -76,16 +76,16 @@ void QMimeTypePrivate::clear()
|
||||
globPatterns.clear();
|
||||
}
|
||||
|
||||
void QMimeTypePrivate::addGlobPattern(const QString &pattern)
|
||||
void MimeTypePrivate::addGlobPattern(const QString &pattern)
|
||||
{
|
||||
globPatterns.append(pattern);
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QMimeType
|
||||
\class MimeType
|
||||
\inmodule QtCore
|
||||
\ingroup shared
|
||||
\brief The QMimeType class describes types of file or data, represented by a MIME type string.
|
||||
\brief The MimeType class describes types of file or data, represented by a MIME type string.
|
||||
|
||||
\since 5.0
|
||||
|
||||
@@ -96,48 +96,48 @@ void QMimeTypePrivate::addGlobPattern(const QString &pattern)
|
||||
|
||||
Determining the MIME type of a file can be useful to make sure your
|
||||
application supports it. It is also useful in file-manager-like applications
|
||||
or widgets, in order to display an appropriate \l {QMimeType::iconName}{icon} for the file, or even
|
||||
the descriptive \l {QMimeType::comment()}{comment} in detailed views.
|
||||
or widgets, in order to display an appropriate \l {MimeType::iconName}{icon} for the file, or even
|
||||
the descriptive \l {MimeType::comment()}{comment} in detailed views.
|
||||
|
||||
To check if a file has the expected MIME type, you should use inherits()
|
||||
rather than a simple string comparison based on the name(). This is because
|
||||
MIME types can inherit from each other: for instance a C source file is
|
||||
a specific type of plain text file, so text/x-csrc inherits text/plain.
|
||||
|
||||
\sa QMimeDatabase, {MIME Type Browser Example}
|
||||
\sa MimeDatabase, {MIME Type Browser Example}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMimeType &QMimeType::operator=(QMimeType &&other)
|
||||
\fn MimeType &MimeType::operator=(MimeType &&other)
|
||||
|
||||
Move-assigns \a other to this QMimeType instance.
|
||||
Move-assigns \a other to this MimeType instance.
|
||||
|
||||
\since 5.2
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMimeType::QMimeType();
|
||||
Constructs this QMimeType object initialized with default property values that indicate an invalid MIME type.
|
||||
\fn MimeType::MimeType();
|
||||
Constructs this MimeType object initialized with default property values that indicate an invalid MIME type.
|
||||
*/
|
||||
QMimeType::QMimeType() :
|
||||
d(new QMimeTypePrivate())
|
||||
MimeType::MimeType() :
|
||||
d(new MimeTypePrivate())
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMimeType::QMimeType(const QMimeType &other);
|
||||
Constructs this QMimeType object as a copy of \a other.
|
||||
\fn MimeType::MimeType(const MimeType &other);
|
||||
Constructs this MimeType object as a copy of \a other.
|
||||
*/
|
||||
QMimeType::QMimeType(const QMimeType &other) :
|
||||
MimeType::MimeType(const MimeType &other) :
|
||||
d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMimeType &QMimeType::operator=(const QMimeType &other);
|
||||
Assigns the data of \a other to this QMimeType object, and returns a reference to this object.
|
||||
\fn MimeType &MimeType::operator=(const MimeType &other);
|
||||
Assigns the data of \a other to this MimeType object, and returns a reference to this object.
|
||||
*/
|
||||
QMimeType &QMimeType::operator=(const QMimeType &other)
|
||||
MimeType &MimeType::operator=(const MimeType &other)
|
||||
{
|
||||
if (d != other.d)
|
||||
d = other.d;
|
||||
@@ -145,18 +145,18 @@ QMimeType &QMimeType::operator=(const QMimeType &other)
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMimeType::QMimeType(const QMimeTypePrivate &dd);
|
||||
Assigns the data of the QMimeTypePrivate \a dd to this QMimeType object, and returns a reference to this object.
|
||||
\fn MimeType::MimeType(const MimeTypePrivate &dd);
|
||||
Assigns the data of the MimeTypePrivate \a dd to this MimeType object, and returns a reference to this object.
|
||||
\internal
|
||||
*/
|
||||
QMimeType::QMimeType(const QMimeTypePrivate &dd) :
|
||||
d(new QMimeTypePrivate(dd))
|
||||
MimeType::MimeType(const MimeTypePrivate &dd) :
|
||||
d(new MimeTypePrivate(dd))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void QMimeType::swap(QMimeType &other);
|
||||
Swaps QMimeType \a other with this QMimeType object.
|
||||
\fn void MimeType::swap(MimeType &other);
|
||||
Swaps MimeType \a other with this MimeType object.
|
||||
|
||||
This operation is very fast and never fails.
|
||||
|
||||
@@ -167,83 +167,83 @@ QMimeType::QMimeType(const QMimeTypePrivate &dd) :
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMimeType::~QMimeType();
|
||||
Destroys the QMimeType object, and releases the d pointer.
|
||||
\fn MimeType::~MimeType();
|
||||
Destroys the MimeType object, and releases the d pointer.
|
||||
*/
|
||||
QMimeType::~QMimeType()
|
||||
MimeType::~MimeType()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QMimeType::operator==(const QMimeType &other) const;
|
||||
Returns \c true if \a other equals this QMimeType object, otherwise returns \c false.
|
||||
\fn bool MimeType::operator==(const MimeType &other) const;
|
||||
Returns \c true if \a other equals this MimeType object, otherwise returns \c false.
|
||||
The name is the unique identifier for a mimetype, so two mimetypes with
|
||||
the same name, are equal.
|
||||
*/
|
||||
bool QMimeType::operator==(const QMimeType &other) const
|
||||
bool MimeType::operator==(const MimeType &other) const
|
||||
{
|
||||
return d == other.d || d->name == other.d->name;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.6
|
||||
\relates QMimeType
|
||||
\relates MimeType
|
||||
|
||||
Returns the hash value for \a key, using
|
||||
\a seed to seed the calculation.
|
||||
*/
|
||||
size_t qHash(const QMimeType &key, size_t seed) noexcept
|
||||
size_t qHash(const MimeType &key, size_t seed) noexcept
|
||||
{
|
||||
return qHash(key.d->name, seed);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QMimeType::operator!=(const QMimeType &other) const;
|
||||
Returns \c true if \a other does not equal this QMimeType object, otherwise returns \c false.
|
||||
\fn bool MimeType::operator!=(const MimeType &other) const;
|
||||
Returns \c true if \a other does not equal this MimeType object, otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\property QMimeType::valid
|
||||
\brief \c true if the QMimeType object contains valid data, \c false otherwise
|
||||
\property MimeType::valid
|
||||
\brief \c true if the MimeType object contains valid data, \c false otherwise
|
||||
|
||||
A valid MIME type has a non-empty name().
|
||||
The invalid MIME type is the default-constructed QMimeType.
|
||||
The invalid MIME type is the default-constructed MimeType.
|
||||
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
bool QMimeType::isValid() const
|
||||
bool MimeType::isValid() const
|
||||
{
|
||||
return !d->name.isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::isDefault
|
||||
\property MimeType::isDefault
|
||||
\brief \c true if this MIME type is the default MIME type which
|
||||
applies to all files: application/octet-stream.
|
||||
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
bool QMimeType::isDefault() const
|
||||
bool MimeType::isDefault() const
|
||||
{
|
||||
return d->name == QMimeDatabasePrivate::instance()->defaultMimeType();
|
||||
return d->name == MimeDatabasePrivate::instance()->defaultMimeType();
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::name
|
||||
\property MimeType::name
|
||||
\brief the name of the MIME type
|
||||
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QString QMimeType::name() const
|
||||
QString MimeType::name() const
|
||||
{
|
||||
return d->name;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::comment
|
||||
\property MimeType::comment
|
||||
\brief the description of the MIME type to be displayed on user interfaces
|
||||
|
||||
The default language (QLocale().name()) is used to select the appropriate translation.
|
||||
@@ -251,9 +251,9 @@ QString QMimeType::name() const
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QString QMimeType::comment() const
|
||||
QString MimeType::comment() const
|
||||
{
|
||||
QMimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<QMimeTypePrivate&>(*d));
|
||||
MimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<MimeTypePrivate&>(*d));
|
||||
|
||||
QStringList languageList;
|
||||
languageList << QLocale().name();
|
||||
@@ -279,7 +279,7 @@ QString QMimeType::comment() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::genericIconName
|
||||
\property MimeType::genericIconName
|
||||
\brief the file name of a generic icon that represents the MIME type
|
||||
|
||||
This should be used if the icon returned by iconName() cannot be found on
|
||||
@@ -292,9 +292,9 @@ QString QMimeType::comment() const
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QString QMimeType::genericIconName() const
|
||||
QString MimeType::genericIconName() const
|
||||
{
|
||||
QMimeDatabasePrivate::instance()->loadGenericIcon(const_cast<QMimeTypePrivate&>(*d));
|
||||
MimeDatabasePrivate::instance()->loadGenericIcon(const_cast<MimeTypePrivate&>(*d));
|
||||
if (d->genericIconName.isEmpty()) {
|
||||
// From the spec:
|
||||
// If the generic icon name is empty (not specified by the mimetype definition)
|
||||
@@ -320,7 +320,7 @@ static QString make_default_icon_name_from_mimetype_name(QString iconName)
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::iconName
|
||||
\property MimeType::iconName
|
||||
\brief the file name of an icon image that represents the MIME type
|
||||
|
||||
The icon name can be given to QIcon::fromTheme() in order to load the icon.
|
||||
@@ -328,9 +328,9 @@ static QString make_default_icon_name_from_mimetype_name(QString iconName)
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QString QMimeType::iconName() const
|
||||
QString MimeType::iconName() const
|
||||
{
|
||||
QMimeDatabasePrivate::instance()->loadIcon(const_cast<QMimeTypePrivate&>(*d));
|
||||
MimeDatabasePrivate::instance()->loadIcon(const_cast<MimeTypePrivate&>(*d));
|
||||
if (d->iconName.isEmpty()) {
|
||||
return make_default_icon_name_from_mimetype_name(name());
|
||||
}
|
||||
@@ -338,20 +338,20 @@ QString QMimeType::iconName() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::globPatterns
|
||||
\property MimeType::globPatterns
|
||||
\brief the list of glob matching patterns
|
||||
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QStringList QMimeType::globPatterns() const
|
||||
QStringList MimeType::globPatterns() const
|
||||
{
|
||||
QMimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<QMimeTypePrivate&>(*d));
|
||||
MimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<MimeTypePrivate&>(*d));
|
||||
return d->globPatterns;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::parentMimeTypes
|
||||
\property MimeType::parentMimeTypes
|
||||
\brief the names of parent MIME types
|
||||
|
||||
A type is a subclass of another type if any instance of the first type is
|
||||
@@ -368,14 +368,14 @@ QStringList QMimeType::globPatterns() const
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QStringList QMimeType::parentMimeTypes() const
|
||||
QStringList MimeType::parentMimeTypes() const
|
||||
{
|
||||
return QMimeDatabasePrivate::instance()->mimeParents(d->name);
|
||||
return MimeDatabasePrivate::instance()->mimeParents(d->name);
|
||||
}
|
||||
|
||||
static void collectParentMimeTypes(const QString &mime, QStringList &allParents)
|
||||
{
|
||||
const QStringList parents = QMimeDatabasePrivate::instance()->mimeParents(mime);
|
||||
const QStringList parents = MimeDatabasePrivate::instance()->mimeParents(mime);
|
||||
for (const QString &parent : parents) {
|
||||
// I would use QSet, but since order matters I better not
|
||||
if (!allParents.contains(parent))
|
||||
@@ -388,7 +388,7 @@ static void collectParentMimeTypes(const QString &mime, QStringList &allParents)
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::allAncestors
|
||||
\property MimeType::allAncestors
|
||||
\brief the names of direct and indirect parent MIME types
|
||||
|
||||
Return all the parent mimetypes of this mimetype, direct and indirect.
|
||||
@@ -403,7 +403,7 @@ static void collectParentMimeTypes(const QString &mime, QStringList &allParents)
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QStringList QMimeType::allAncestors() const
|
||||
QStringList MimeType::allAncestors() const
|
||||
{
|
||||
QStringList allParents;
|
||||
collectParentMimeTypes(d->name, allParents);
|
||||
@@ -411,13 +411,13 @@ QStringList QMimeType::allAncestors() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::aliases
|
||||
\property MimeType::aliases
|
||||
\brief the list of aliases of this mimetype
|
||||
|
||||
For instance, for text/csv, the returned list would be:
|
||||
text/x-csv, text/x-comma-separated-values.
|
||||
|
||||
Note that all QMimeType instances refer to proper mimetypes,
|
||||
Note that all MimeType instances refer to proper mimetypes,
|
||||
never to aliases directly.
|
||||
|
||||
The order of the aliases in the list is undefined.
|
||||
@@ -425,13 +425,13 @@ QStringList QMimeType::allAncestors() const
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QStringList QMimeType::aliases() const
|
||||
QStringList MimeType::aliases() const
|
||||
{
|
||||
return QMimeDatabasePrivate::instance()->listAliases(d->name);
|
||||
return MimeDatabasePrivate::instance()->listAliases(d->name);
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::suffixes
|
||||
\property MimeType::suffixes
|
||||
\brief the known suffixes for the MIME type
|
||||
|
||||
No leading dot is included, so for instance this would return "jpg", "jpeg" for image/jpeg.
|
||||
@@ -439,9 +439,9 @@ QStringList QMimeType::aliases() const
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QStringList QMimeType::suffixes() const
|
||||
QStringList MimeType::suffixes() const
|
||||
{
|
||||
QMimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<QMimeTypePrivate&>(*d));
|
||||
MimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<MimeTypePrivate&>(*d));
|
||||
|
||||
QStringList result;
|
||||
for (const QString &pattern : qAsConst(d->globPatterns)) {
|
||||
@@ -458,7 +458,7 @@ QStringList QMimeType::suffixes() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::preferredSuffix
|
||||
\property MimeType::preferredSuffix
|
||||
\brief the preferred suffix for the MIME type
|
||||
|
||||
No leading dot is included, so for instance this would return "pdf" for application/pdf.
|
||||
@@ -467,7 +467,7 @@ QStringList QMimeType::suffixes() const
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QString QMimeType::preferredSuffix() const
|
||||
QString MimeType::preferredSuffix() const
|
||||
{
|
||||
if (isDefault()) // workaround for unwanted *.bin suffix for octet-stream, https://bugs.freedesktop.org/show_bug.cgi?id=101667, fixed upstream in 1.10
|
||||
return QString();
|
||||
@@ -476,15 +476,15 @@ QString QMimeType::preferredSuffix() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QMimeType::filterString
|
||||
\property MimeType::filterString
|
||||
\brief a filter string usable for a file dialog
|
||||
|
||||
While this property was introduced in 5.10, the
|
||||
corresponding accessor method has always been there.
|
||||
*/
|
||||
QString QMimeType::filterString() const
|
||||
QString MimeType::filterString() const
|
||||
{
|
||||
QMimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<QMimeTypePrivate&>(*d));
|
||||
MimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<MimeTypePrivate&>(*d));
|
||||
QString filter;
|
||||
|
||||
if (!d->globPatterns.empty()) {
|
||||
@@ -501,33 +501,33 @@ QString QMimeType::filterString() const
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QMimeType::inherits(const QString &mimeTypeName) const;
|
||||
\fn bool MimeType::inherits(const QString &mimeTypeName) const;
|
||||
Returns \c true if this mimetype is \a mimeTypeName,
|
||||
or inherits \a mimeTypeName (see parentMimeTypes()),
|
||||
or \a mimeTypeName is an alias for this mimetype.
|
||||
|
||||
This method has been made invokable from QML since 5.10.
|
||||
*/
|
||||
bool QMimeType::inherits(const QString &mimeTypeName) const
|
||||
bool MimeType::inherits(const QString &mimeTypeName) const
|
||||
{
|
||||
if (d->name == mimeTypeName)
|
||||
return true;
|
||||
return QMimeDatabasePrivate::instance()->mimeInherits(d->name, mimeTypeName);
|
||||
return MimeDatabasePrivate::instance()->mimeInherits(d->name, mimeTypeName);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug debug, const QMimeType &mime)
|
||||
QDebug operator<<(QDebug debug, const Utils::MimeType &mime)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
if (!mime.isValid()) {
|
||||
debug.nospace() << "QMimeType(invalid)";
|
||||
debug.nospace() << "MimeType(invalid)";
|
||||
} else {
|
||||
debug.nospace() << "QMimeType(" << mime.name() << ")";
|
||||
debug.nospace() << "MimeType(" << mime.name() << ")";
|
||||
}
|
||||
return debug;
|
||||
}
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qmimetype.cpp"
|
||||
#include "moc_mimetype.cpp"
|
||||
|
@@ -38,26 +38,23 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMETYPE_H
|
||||
#define QMIMETYPE_H
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
#include <utils/utils_global.h>
|
||||
|
||||
#include <QtCore/qobjectdefs.h>
|
||||
#include <QtCore/qshareddata.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
class QMimeTypePrivate;
|
||||
class QMimeType;
|
||||
class MimeTypePrivate;
|
||||
class MimeType;
|
||||
|
||||
Q_CORE_EXPORT size_t qHash(const QMimeType &key, size_t seed = 0) noexcept;
|
||||
QTCREATOR_UTILS_EXPORT size_t qHash(const MimeType &key, size_t seed = 0) noexcept;
|
||||
|
||||
class Q_CORE_EXPORT QMimeType
|
||||
class QTCREATOR_UTILS_EXPORT MimeType
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(bool valid READ isValid CONSTANT)
|
||||
@@ -75,20 +72,20 @@ class Q_CORE_EXPORT QMimeType
|
||||
Q_PROPERTY(QString filterString READ filterString CONSTANT)
|
||||
|
||||
public:
|
||||
QMimeType();
|
||||
QMimeType(const QMimeType &other);
|
||||
QMimeType &operator=(const QMimeType &other);
|
||||
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMimeType)
|
||||
void swap(QMimeType &other) noexcept
|
||||
MimeType();
|
||||
MimeType(const MimeType &other);
|
||||
MimeType &operator=(const MimeType &other);
|
||||
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(MimeType)
|
||||
void swap(MimeType &other) noexcept
|
||||
{
|
||||
d.swap(other.d);
|
||||
}
|
||||
explicit QMimeType(const QMimeTypePrivate &dd);
|
||||
~QMimeType();
|
||||
explicit MimeType(const MimeTypePrivate &dd);
|
||||
~MimeType();
|
||||
|
||||
bool operator==(const QMimeType &other) const;
|
||||
bool operator==(const MimeType &other) const;
|
||||
|
||||
inline bool operator!=(const QMimeType &other) const
|
||||
inline bool operator!=(const MimeType &other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
@@ -113,24 +110,23 @@ public:
|
||||
QString filterString() const;
|
||||
|
||||
protected:
|
||||
friend class QMimeTypeParserBase;
|
||||
friend class MimeTypeParserBase;
|
||||
friend class MimeTypeMapEntry;
|
||||
friend class QMimeDatabasePrivate;
|
||||
friend class QMimeXMLProvider;
|
||||
friend class QMimeBinaryProvider;
|
||||
friend class QMimeTypePrivate;
|
||||
friend Q_CORE_EXPORT size_t qHash(const QMimeType &key, size_t seed) noexcept;
|
||||
friend class MimeDatabasePrivate;
|
||||
friend class MimeXMLProvider;
|
||||
friend class MimeBinaryProvider;
|
||||
friend class MimeTypePrivate;
|
||||
friend QTCREATOR_UTILS_EXPORT size_t qHash(const MimeType &key, size_t seed) noexcept;
|
||||
|
||||
QExplicitlySharedDataPointer<QMimeTypePrivate> d;
|
||||
QExplicitlySharedDataPointer<MimeTypePrivate> d;
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QMimeType)
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
class QDebug;
|
||||
Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMimeType &mime);
|
||||
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const Utils::MimeType &mime);
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QMIMETYPE_H
|
||||
Q_DECLARE_SHARED(Utils::MimeType)
|
||||
|
@@ -37,8 +37,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMIMETYPE_P_H
|
||||
#define QMIMETYPE_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -51,23 +50,20 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
#include "qmimetype.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
#include "mimetype.h"
|
||||
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
class Q_AUTOTEST_EXPORT QMimeTypePrivate : public QSharedData
|
||||
class MimeTypePrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
typedef QHash<QString, QString> LocaleHash;
|
||||
|
||||
QMimeTypePrivate();
|
||||
explicit QMimeTypePrivate(const QMimeType &other);
|
||||
MimeTypePrivate();
|
||||
explicit MimeTypePrivate(const MimeType &other);
|
||||
|
||||
void clear();
|
||||
|
||||
@@ -82,8 +78,9 @@ public:
|
||||
QStringList globPatterns;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
||||
#if 0
|
||||
#define QMIMETYPE_BUILDER_FROM_RVALUE_REFS \
|
||||
QT_BEGIN_NAMESPACE \
|
||||
static QMimeType buildQMimeType ( \
|
||||
@@ -102,5 +99,4 @@ QT_END_NAMESPACE
|
||||
return QMimeType(qMimeTypeData); \
|
||||
} \
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QMIMETYPE_P_H
|
||||
#endif
|
||||
|
@@ -37,12 +37,10 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#define QT_NO_CAST_FROM_ASCII
|
||||
#include "mimetypeparser_p.h"
|
||||
|
||||
#include "qmimetypeparser_p.h"
|
||||
|
||||
#include "qmimetype_p.h"
|
||||
#include "qmimemagicrulematcher_p.h"
|
||||
#include "mimetype_p.h"
|
||||
#include "mimemagicrulematcher_p.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDebug>
|
||||
@@ -51,7 +49,7 @@
|
||||
#include <QtCore/QXmlStreamWriter>
|
||||
#include <QtCore/QStack>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Utils {
|
||||
|
||||
// XML tags in MIME files
|
||||
static const char mimeInfoTagC[] = "mime-info";
|
||||
@@ -80,35 +78,35 @@ static const char matchOffsetAttributeC[] = "offset";
|
||||
static const char matchMaskAttributeC[] = "mask";
|
||||
|
||||
/*!
|
||||
\class QMimeTypeParser
|
||||
\class MimeTypeParser
|
||||
\inmodule QtCore
|
||||
\internal
|
||||
\brief The QMimeTypeParser class parses MIME types, and builds a MIME database hierarchy by adding to QMimeDatabase.
|
||||
\brief The MimeTypeParser class parses MIME types, and builds a MIME database hierarchy by adding to MimeDatabase.
|
||||
|
||||
Populates QMimeDataBase
|
||||
Populates MimeDataBase
|
||||
|
||||
\sa QMimeDatabase, QMimeMagicRuleMatcher, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
|
||||
\sa QMimeTypeParser
|
||||
\sa MimeDatabase, MimeMagicRuleMatcher, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
|
||||
\sa MimeTypeParser
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMimeTypeParserBase
|
||||
\class MimeTypeParserBase
|
||||
\inmodule QtCore
|
||||
\internal
|
||||
\brief The QMimeTypeParserBase class parses for a sequence of <mime-type> in a generic way.
|
||||
\brief The MimeTypeParserBase class parses for a sequence of <mime-type> in a generic way.
|
||||
|
||||
Calls abstract handler function process for QMimeType it finds.
|
||||
Calls abstract handler function process for MimeType it finds.
|
||||
|
||||
\sa QMimeDatabase, QMimeMagicRuleMatcher, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
|
||||
\sa QMimeTypeParser
|
||||
\sa MimeDatabase, MimeMagicRuleMatcher, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
|
||||
\sa MimeTypeParser
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual bool QMimeTypeParserBase::process(const QMimeType &t, QString *errorMessage) = 0;
|
||||
\fn virtual bool MimeTypeParserBase::process(const MimeType &t, QString *errorMessage) = 0;
|
||||
Overwrite to process the sequence of parsed data
|
||||
*/
|
||||
|
||||
QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState currentState, QStringView startElement)
|
||||
MimeTypeParserBase::ParseState MimeTypeParserBase::nextState(ParseState currentState, QStringView startElement)
|
||||
{
|
||||
switch (currentState) {
|
||||
case ParseBeginning:
|
||||
@@ -161,7 +159,7 @@ QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState curren
|
||||
}
|
||||
|
||||
// Parse int number from an (attribute) string
|
||||
bool QMimeTypeParserBase::parseNumber(QStringView n, int *target, QString *errorMessage)
|
||||
bool MimeTypeParserBase::parseNumber(QStringView n, int *target, QString *errorMessage)
|
||||
{
|
||||
bool ok;
|
||||
*target = n.toInt(&ok);
|
||||
@@ -177,7 +175,7 @@ bool QMimeTypeParserBase::parseNumber(QStringView n, int *target, QString *error
|
||||
struct CreateMagicMatchRuleResult
|
||||
{
|
||||
QString errorMessage; // must be first
|
||||
QMimeMagicRule rule;
|
||||
MimeMagicRule rule;
|
||||
|
||||
CreateMagicMatchRuleResult(QStringView type, QStringView value, QStringView offsets, QStringView mask)
|
||||
: errorMessage(), rule(type.toString(), value.toUtf8(), offsets.toString(), mask.toLatin1(), &errorMessage)
|
||||
@@ -196,7 +194,7 @@ static CreateMagicMatchRuleResult createMagicMatchRule(const QXmlStreamAttribute
|
||||
}
|
||||
#endif
|
||||
|
||||
bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage)
|
||||
bool MimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage)
|
||||
{
|
||||
#ifdef QT_NO_XMLSTREAMREADER
|
||||
Q_UNUSED(dev);
|
||||
@@ -204,11 +202,11 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
|
||||
*errorMessage = QString::fromLatin1("QXmlStreamReader is not available, cannot parse '%1'.").arg(fileName);
|
||||
return false;
|
||||
#else
|
||||
QMimeTypePrivate data;
|
||||
MimeTypePrivate data;
|
||||
data.loaded = true;
|
||||
int priority = 50;
|
||||
QStack<QMimeMagicRule *> currentRules; // stack for the nesting of rules
|
||||
QList<QMimeMagicRule> rules; // toplevel rules
|
||||
QStack<MimeMagicRule *> currentRules; // stack for the nesting of rules
|
||||
QList<MimeMagicRule> rules; // toplevel rules
|
||||
QXmlStreamReader reader(dev);
|
||||
ParseState ps = ParseBeginning;
|
||||
while (!reader.atEnd()) {
|
||||
@@ -238,13 +236,13 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
|
||||
const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)) == QLatin1String("true");
|
||||
|
||||
if (weight == 0)
|
||||
weight = QMimeGlobPattern::DefaultWeight;
|
||||
weight = MimeGlobPattern::DefaultWeight;
|
||||
|
||||
Q_ASSERT(!data.name.isEmpty());
|
||||
const QMimeGlobPattern glob(pattern, data.name, weight, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
const MimeGlobPattern glob(pattern, data.name, weight, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
if (!process(glob, errorMessage)) // for actual glob matching
|
||||
return false;
|
||||
data.addGlobPattern(pattern); // just for QMimeType::globPatterns()
|
||||
data.addGlobPattern(pattern); // just for MimeType::globPatterns()
|
||||
}
|
||||
break;
|
||||
case ParseGlobDeleteAll:
|
||||
@@ -286,9 +284,9 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
|
||||
case ParseMagicMatchRule: {
|
||||
auto result = createMagicMatchRule(atts);
|
||||
if (Q_UNLIKELY(!result.rule.isValid()))
|
||||
qWarning("QMimeDatabase: Error parsing %ls\n%ls",
|
||||
qWarning("MimeDatabase: Error parsing %ls\n%ls",
|
||||
qUtf16Printable(fileName), qUtf16Printable(result.errorMessage));
|
||||
QList<QMimeMagicRule> *ruleList;
|
||||
QList<MimeMagicRule> *ruleList;
|
||||
if (currentRules.isEmpty())
|
||||
ruleList = &rules;
|
||||
else // nest this rule into the proper parent
|
||||
@@ -311,7 +309,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
|
||||
{
|
||||
const auto elementName = reader.name();
|
||||
if (elementName == QLatin1String(mimeTypeTagC)) {
|
||||
if (!process(QMimeType(data), errorMessage))
|
||||
if (!process(MimeType(data), errorMessage))
|
||||
return false;
|
||||
data.clear();
|
||||
} else if (elementName == QLatin1String(matchTagC)) {
|
||||
@@ -321,7 +319,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
|
||||
} else if (elementName == QLatin1String(magicTagC)) {
|
||||
//qDebug() << "MAGIC ended, we got" << rules.count() << "rules, with prio" << priority;
|
||||
// Finished a <magic> sequence
|
||||
QMimeMagicRuleMatcher ruleMatcher(data.name, priority);
|
||||
MimeMagicRuleMatcher ruleMatcher(data.name, priority);
|
||||
ruleMatcher.addRules(rules);
|
||||
processMagicMatcher(ruleMatcher);
|
||||
rules.clear();
|
||||
@@ -347,4 +345,4 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
|
||||
#endif //QT_NO_XMLSTREAMREADER
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
} // namespace Utils
|
||||
|
@@ -37,9 +37,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef QMIMETYPEPARSER_P_H
|
||||
#define QMIMETYPEPARSER_P_H
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -52,34 +50,34 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qmimedatabase_p.h"
|
||||
#include "mimedatabase_p.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(mimetype);
|
||||
|
||||
#include "qmimeprovider_p.h"
|
||||
#include "mimeprovider_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIODevice;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QMimeTypeParserBase
|
||||
namespace Utils {
|
||||
|
||||
class MimeTypeParserBase
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QMimeTypeParserBase)
|
||||
Q_DISABLE_COPY_MOVE(MimeTypeParserBase)
|
||||
|
||||
public:
|
||||
QMimeTypeParserBase() {}
|
||||
virtual ~QMimeTypeParserBase() {}
|
||||
MimeTypeParserBase() {}
|
||||
virtual ~MimeTypeParserBase() {}
|
||||
|
||||
bool parse(QIODevice *dev, const QString &fileName, QString *errorMessage);
|
||||
|
||||
static bool parseNumber(QStringView n, int *target, QString *errorMessage);
|
||||
|
||||
protected:
|
||||
virtual bool process(const QMimeType &t, QString *errorMessage) = 0;
|
||||
virtual bool process(const QMimeGlobPattern &t, QString *errorMessage) = 0;
|
||||
virtual bool process(const MimeType &t, QString *errorMessage) = 0;
|
||||
virtual bool process(const MimeGlobPattern &t, QString *errorMessage) = 0;
|
||||
virtual void processParent(const QString &child, const QString &parent) = 0;
|
||||
virtual void processAlias(const QString &alias, const QString &name) = 0;
|
||||
virtual void processMagicMatcher(const QMimeMagicRuleMatcher &matcher) = 0;
|
||||
virtual void processMagicMatcher(const MimeMagicRuleMatcher &matcher) = 0;
|
||||
|
||||
private:
|
||||
enum ParseState {
|
||||
@@ -103,16 +101,16 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class QMimeTypeParser : public QMimeTypeParserBase
|
||||
class MimeTypeParser : public MimeTypeParserBase
|
||||
{
|
||||
public:
|
||||
explicit QMimeTypeParser(QMimeXMLProvider &provider) : m_provider(provider) {}
|
||||
explicit MimeTypeParser(MimeXMLProvider &provider) : m_provider(provider) {}
|
||||
|
||||
protected:
|
||||
inline bool process(const QMimeType &t, QString *) override
|
||||
inline bool process(const MimeType &t, QString *) override
|
||||
{ m_provider.addMimeType(t); return true; }
|
||||
|
||||
inline bool process(const QMimeGlobPattern &glob, QString *) override
|
||||
inline bool process(const MimeGlobPattern &glob, QString *) override
|
||||
{ m_provider.addGlobPattern(glob); return true; }
|
||||
|
||||
inline void processParent(const QString &child, const QString &parent) override
|
||||
@@ -121,13 +119,11 @@ protected:
|
||||
inline void processAlias(const QString &alias, const QString &name) override
|
||||
{ m_provider.addAlias(alias, name); }
|
||||
|
||||
inline void processMagicMatcher(const QMimeMagicRuleMatcher &matcher) override
|
||||
inline void processMagicMatcher(const MimeMagicRuleMatcher &matcher) override
|
||||
{ m_provider.addMagicMatcher(matcher); }
|
||||
|
||||
private:
|
||||
QMimeXMLProvider &m_provider;
|
||||
MimeXMLProvider &m_provider;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // MIMETYPEPARSER_P_H
|
||||
} // namespace Utils
|
||||
|
Reference in New Issue
Block a user