forked from qt-creator/qt-creator
Mimetypes v3: Add dummies for API that was added for Qt Creator
Change-Id: I6216f3f109893bb40ffa06bc0de10965fa7904e2 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -873,4 +873,50 @@ QList<MimeType> allMimeTypes()
|
||||
return mdb.allMimeTypes();
|
||||
}
|
||||
|
||||
void setMimeStartupPhase(MimeStartupPhase phase)
|
||||
{
|
||||
// auto d = MimeDatabasePrivate::instance();
|
||||
// QMutexLocker locker(&d->mutex);
|
||||
// if (int(phase) != d->m_startupPhase + 1)
|
||||
// qWarning("Unexpected jump in MimedDatabase lifetime from %d to %d", d->m_startupPhase, int(phase));
|
||||
// d->m_startupPhase = int(phase);
|
||||
}
|
||||
|
||||
void addMimeTypes(const QString &fileName, const QByteArray &data)
|
||||
{
|
||||
// auto d = MimeDatabasePrivate::instance();
|
||||
// QMutexLocker locker(&d->mutex);
|
||||
|
||||
// if (d->m_startupPhase >= MimeDatabase::PluginsDelayedInitializing)
|
||||
// qWarning("Adding items from %s to MimeDatabase after initialization time",
|
||||
// qPrintable(fileName));
|
||||
|
||||
// auto xmlProvider = static_cast<MimeXMLProvider *>(d->provider());
|
||||
// xmlProvider->addData(fileName, data);
|
||||
}
|
||||
|
||||
QMap<int, QList<MimeMagicRule> > magicRulesForMimeType(const MimeType &mimeType)
|
||||
{
|
||||
// auto d = MimeDatabasePrivate::instance();
|
||||
// QMutexLocker locker(&d->mutex);
|
||||
// return d->provider()->magicRulesForMimeType(mimeType);
|
||||
return {};
|
||||
}
|
||||
|
||||
void setGlobPatternsForMimeType(const MimeType &mimeType, const QStringList &patterns)
|
||||
{
|
||||
// auto d = MimeDatabasePrivate::instance();
|
||||
// QMutexLocker locker(&d->mutex);
|
||||
// d->provider()->setGlobPatternsForMimeType(mimeType, patterns);
|
||||
}
|
||||
|
||||
void setMagicRulesForMimeType(const MimeType &mimeType, const QMap<int, QList<MimeMagicRule> > &rules)
|
||||
{
|
||||
// auto d = MimeDatabasePrivate::instance();
|
||||
// QMutexLocker locker(&d->mutex);
|
||||
// d->provider()->setMagicRulesForMimeType(mimeType, rules);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -42,6 +42,8 @@
|
||||
|
||||
#include "mimetype.h"
|
||||
|
||||
#include "mimemagicrule_p.h"
|
||||
|
||||
#include <utils/utils_global.h>
|
||||
|
||||
#include <QtCore/qstringlist.h>
|
||||
@@ -73,6 +75,25 @@ QTCREATOR_UTILS_EXPORT QList<MimeType> mimeTypesForFileName(const QString &fileN
|
||||
QTCREATOR_UTILS_EXPORT MimeType mimeTypeForData(const QByteArray &data);
|
||||
QTCREATOR_UTILS_EXPORT QList<MimeType> allMimeTypes();
|
||||
|
||||
// Qt Creator additions
|
||||
// For debugging purposes.
|
||||
enum class MimeStartupPhase {
|
||||
BeforeInitialize,
|
||||
PluginsLoading,
|
||||
PluginsInitializing, // Register up to here.
|
||||
PluginsDelayedInitializing, // Use from here on.
|
||||
UpAndRunning
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT void setMimeStartupPhase(MimeStartupPhase);
|
||||
QTCREATOR_UTILS_EXPORT void addMimeTypes(const QString &id, const QByteArray &data);
|
||||
QTCREATOR_UTILS_EXPORT QMap<int, QList<MimeMagicRule> > magicRulesForMimeType(const MimeType &mimeType); // priority -> rules
|
||||
QTCREATOR_UTILS_EXPORT void setGlobPatternsForMimeType(const MimeType &mimeType, const QStringList &patterns);
|
||||
QTCREATOR_UTILS_EXPORT void setMagicRulesForMimeType(const MimeType &mimeType,
|
||||
const QMap<int, QList<MimeMagicRule> > &rules); // priority -> rules
|
||||
|
||||
// Original
|
||||
|
||||
class MimeDatabasePrivate;
|
||||
class QTCREATOR_UTILS_EXPORT MimeDatabase
|
||||
{
|
||||
|
@@ -214,6 +214,21 @@ static inline QByteArray makePattern(const QByteArray &value)
|
||||
return pattern;
|
||||
}
|
||||
|
||||
MimeMagicRule::MimeMagicRule(const Type &type,
|
||||
const QByteArray &value,
|
||||
int startPos,
|
||||
int endPos,
|
||||
const QByteArray &mask,
|
||||
QString *errorString)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
, m_startPos(startPos)
|
||||
, m_endPos(endPos)
|
||||
, m_mask(mask)
|
||||
{
|
||||
init(errorString);
|
||||
}
|
||||
|
||||
// Evaluate a magic match rule like
|
||||
// <match value="must be converted with BinHex" type="string" offset="11"/>
|
||||
// <match value="0x9501" type="big16" offset="0:64"/>
|
||||
@@ -248,6 +263,11 @@ MimeMagicRule::MimeMagicRule(const QString &type,
|
||||
return;
|
||||
}
|
||||
|
||||
init(errorString);
|
||||
}
|
||||
|
||||
void MimeMagicRule::init(QString *errorString)
|
||||
{
|
||||
if (m_type >= Host16 && m_type <= Byte) {
|
||||
bool ok;
|
||||
m_number = m_value.toUInt(&ok, 0); // autodetect base
|
||||
|
@@ -50,19 +50,24 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <utils/utils_global.h>
|
||||
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qscopedpointer.h>
|
||||
#include <QtCore/qlist.h>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class MimeMagicRule
|
||||
class QTCREATOR_UTILS_EXPORT MimeMagicRule
|
||||
{
|
||||
public:
|
||||
enum Type { Invalid = 0, String, Host16, Host32, Big16, Big32, Little16, Little32, Byte };
|
||||
|
||||
MimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets,
|
||||
const QByteArray &mask, QString *errorString);
|
||||
// added for Qt Creator
|
||||
MimeMagicRule(const Type &type, const QByteArray &value, int startPos, int endPos,
|
||||
const QByteArray &mask = {}, QString *errorString = nullptr);
|
||||
|
||||
void swap(MimeMagicRule &other) noexcept
|
||||
{
|
||||
@@ -97,6 +102,9 @@ public:
|
||||
static bool matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char *valueData, const char *mask);
|
||||
|
||||
private:
|
||||
// added for Qt Creator
|
||||
void init(QString *errorString);
|
||||
|
||||
Type m_type;
|
||||
QByteArray m_value;
|
||||
int m_startPos;
|
||||
|
@@ -515,6 +515,34 @@ bool MimeType::inherits(const QString &mimeTypeName) const
|
||||
return MimeDatabasePrivate::instance()->mimeInherits(d->name, mimeTypeName);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c true if the name or alias of the MIME type matches
|
||||
\a nameOrAlias.
|
||||
*/
|
||||
bool MimeType::matchesName(const QString &nameOrAlias) const
|
||||
{
|
||||
// if (d->name == nameOrAlias)
|
||||
// return true;
|
||||
// return MimeDatabasePrivate::instance()->provider()->resolveAlias(nameOrAlias) == d->name;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the preferred filename suffix for the MIME type to \a suffix.
|
||||
*/
|
||||
void MimeType::setPreferredSuffix(const QString &suffix)
|
||||
{
|
||||
// MimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d);
|
||||
|
||||
// auto it = std::find_if(d->globPatterns.begin(), d->globPatterns.end(),
|
||||
// [suffix](const QString &pattern) {
|
||||
// return suffixFromPattern(pattern) == suffix;
|
||||
// });
|
||||
// if (it != d->globPatterns.end())
|
||||
// d->globPatterns.erase(it);
|
||||
// d->globPatterns.prepend(QLatin1String("*.") + suffix);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
@@ -109,6 +109,10 @@ public:
|
||||
|
||||
QString filterString() const;
|
||||
|
||||
// Qt Creator additions
|
||||
bool matchesName(const QString &nameOrAlias) const;
|
||||
void setPreferredSuffix(const QString &suffix);
|
||||
|
||||
protected:
|
||||
friend class MimeTypeParserBase;
|
||||
friend class MimeTypeMapEntry;
|
||||
|
Reference in New Issue
Block a user