forked from qt-creator/qt-creator
MimeType: Add matchesName and setPreferredSuffix
Change-Id: Ieef09fb6d483a6c056f3ae586db30583c634953a Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -47,6 +47,17 @@
|
||||
using namespace Utils;
|
||||
using namespace Utils::Internal;
|
||||
|
||||
static QString suffixFromPattern(const QString &pattern)
|
||||
{
|
||||
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
|
||||
if (pattern.startsWith(QLatin1String("*.")) &&
|
||||
pattern.length() > 2 &&
|
||||
pattern.indexOf(QLatin1Char('*'), 2) < 0 && pattern.indexOf(QLatin1Char('?'), 2) < 0) {
|
||||
return pattern.mid(2);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
MimeTypePrivate::MimeTypePrivate()
|
||||
: loaded(false)
|
||||
{}
|
||||
@@ -378,13 +389,9 @@ QStringList MimeType::suffixes() const
|
||||
|
||||
QStringList result;
|
||||
foreach (const QString &pattern, d->globPatterns) {
|
||||
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
|
||||
if (pattern.startsWith(QLatin1String("*.")) &&
|
||||
pattern.length() > 2 &&
|
||||
pattern.indexOf(QLatin1Char('*'), 2) < 0 && pattern.indexOf(QLatin1Char('?'), 2) < 0) {
|
||||
const QString suffix = pattern.mid(2);
|
||||
const QString suffix = suffixFromPattern(pattern);
|
||||
if (!suffix.isEmpty())
|
||||
result.append(suffix);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -423,6 +430,24 @@ QString MimeType::filterString() const
|
||||
return filter;
|
||||
}
|
||||
|
||||
bool MimeType::matchesName(const QString &nameOrAlias) const
|
||||
{
|
||||
return d->name == nameOrAlias || aliases().contains(nameOrAlias);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool MimeType::inherits(const QString &mimeTypeName) const;
|
||||
Returns \c true if this mimetype is \a mimeTypeName,
|
||||
|
||||
@@ -101,6 +101,10 @@ public:
|
||||
|
||||
QString filterString() const;
|
||||
|
||||
// Qt Creator additions
|
||||
bool matchesName(const QString &nameOrAlias) const;
|
||||
void setPreferredSuffix(const QString &suffix);
|
||||
|
||||
protected:
|
||||
friend class Internal::MimeTypeParserBase;
|
||||
friend class Internal::MimeTypeMapEntry;
|
||||
|
||||
Reference in New Issue
Block a user