forked from qt-creator/qt-creator
Update mime database from Qt
qtbase/e3cc87c5f49d9bf824d6e667bf3b206470cf3b2d QMimeBinaryProvider: cut out the QMap middle-man Change-Id: I4e3b99774fb1658b43f838de1ae2e0f2e98173ce Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
#include "mimemagicrulematcher_p.h"
|
#include "mimemagicrulematcher_p.h"
|
||||||
|
|
||||||
#include <qstandardpaths.h>
|
#include <qstandardpaths.h>
|
||||||
#include <QMap>
|
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -504,30 +503,24 @@ void MimeBinaryProvider::addAllMimeTypes(QList<MimeType> &result)
|
|||||||
MimeTypePrivate::LocaleHash MimeBinaryProvider::localeComments(const QString &name)
|
MimeTypePrivate::LocaleHash MimeBinaryProvider::localeComments(const QString &name)
|
||||||
{
|
{
|
||||||
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
||||||
if (it != m_mimetypeExtra.constEnd()) {
|
if (it != m_mimetypeExtra.cend())
|
||||||
const MimeTypeExtra &e = it.value();
|
return it->second.localeComments;
|
||||||
return e.localeComments;
|
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MimeBinaryProvider::hasGlobDeleteAll(const QString &name)
|
bool MimeBinaryProvider::hasGlobDeleteAll(const QString &name)
|
||||||
{
|
{
|
||||||
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
||||||
if (it != m_mimetypeExtra.constEnd()) {
|
if (it != m_mimetypeExtra.cend())
|
||||||
const MimeTypeExtra &e = it.value();
|
return it->second.hasGlobDeleteAll;
|
||||||
return e.hasGlobDeleteAll;
|
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MimeBinaryProvider::globPatterns(const QString &name)
|
QStringList MimeBinaryProvider::globPatterns(const QString &name)
|
||||||
{
|
{
|
||||||
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
||||||
if (it != m_mimetypeExtra.constEnd()) {
|
if (it != m_mimetypeExtra.cend())
|
||||||
const MimeTypeExtra &e = it.value();
|
return it->second.globPatterns;
|
||||||
return e.globPatterns;
|
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,8 +528,8 @@ MimeBinaryProvider::MimeTypeExtraMap::const_iterator
|
|||||||
MimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
MimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
||||||
{
|
{
|
||||||
#if QT_CONFIG(xmlstreamreader)
|
#if QT_CONFIG(xmlstreamreader)
|
||||||
auto it = m_mimetypeExtra.constFind(mimeName);
|
auto it = m_mimetypeExtra.find(mimeName);
|
||||||
if (it == m_mimetypeExtra.constEnd()) {
|
if (it == m_mimetypeExtra.cend()) {
|
||||||
// load comment and globPatterns
|
// load comment and globPatterns
|
||||||
|
|
||||||
// shared-mime-info since 1.3 lowercases the xml files
|
// shared-mime-info since 1.3 lowercases the xml files
|
||||||
@@ -546,21 +539,20 @@ MimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
|||||||
|
|
||||||
QFile qfile(mimeFile);
|
QFile qfile(mimeFile);
|
||||||
if (!qfile.open(QFile::ReadOnly))
|
if (!qfile.open(QFile::ReadOnly))
|
||||||
return m_mimetypeExtra.constEnd();
|
return m_mimetypeExtra.cend();
|
||||||
|
|
||||||
auto insertIt = m_mimetypeExtra.insert(mimeName, MimeTypeExtra{});
|
it = m_mimetypeExtra.try_emplace(mimeName).first;
|
||||||
it = insertIt;
|
MimeTypeExtra &extra = it->second;
|
||||||
MimeTypeExtra &extra = insertIt.value();
|
|
||||||
QString mainPattern;
|
QString mainPattern;
|
||||||
|
|
||||||
QXmlStreamReader xml(&qfile);
|
QXmlStreamReader xml(&qfile);
|
||||||
if (xml.readNextStartElement()) {
|
if (xml.readNextStartElement()) {
|
||||||
if (xml.name() != "mime-type"_L1) {
|
if (xml.name() != "mime-type"_L1) {
|
||||||
return m_mimetypeExtra.constEnd();
|
return m_mimetypeExtra.cend();
|
||||||
}
|
}
|
||||||
const auto name = xml.attributes().value("type"_L1);
|
const auto name = xml.attributes().value("type"_L1);
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
return m_mimetypeExtra.constEnd();
|
return m_mimetypeExtra.cend();
|
||||||
if (name.compare(mimeName, Qt::CaseInsensitive))
|
if (name.compare(mimeName, Qt::CaseInsensitive))
|
||||||
qWarning() << "Got name" << name << "in file" << mimeFile << "expected" << mimeName;
|
qWarning() << "Got name" << name << "in file" << mimeFile << "expected" << mimeName;
|
||||||
|
|
||||||
@@ -601,7 +593,7 @@ MimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
|||||||
#else
|
#else
|
||||||
Q_UNUSED(mimeName);
|
Q_UNUSED(mimeName);
|
||||||
qWarning("Cannot load mime type since QXmlStreamReader is not available.");
|
qWarning("Cannot load mime type since QXmlStreamReader is not available.");
|
||||||
return m_mimetypeExtra.constEnd();
|
return m_mimetypeExtra.cend();
|
||||||
#endif // feature xmlstreamreader
|
#endif // feature xmlstreamreader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -145,7 +145,7 @@ private:
|
|||||||
QStringList globPatterns;
|
QStringList globPatterns;
|
||||||
bool hasGlobDeleteAll = false;
|
bool hasGlobDeleteAll = false;
|
||||||
};
|
};
|
||||||
using MimeTypeExtraMap = QMap<QString, MimeTypeExtra>;
|
using MimeTypeExtraMap = std::map<QString, MimeTypeExtra>;
|
||||||
MimeTypeExtraMap m_mimetypeExtra;
|
MimeTypeExtraMap m_mimetypeExtra;
|
||||||
|
|
||||||
MimeTypeExtraMap::const_iterator loadMimeTypeExtra(const QString &mimeName);
|
MimeTypeExtraMap::const_iterator loadMimeTypeExtra(const QString &mimeName);
|
||||||
|
Reference in New Issue
Block a user