summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/mimetypes/qmimeprovider.cpp30
-rw-r--r--src/corelib/mimetypes/qmimeprovider_p.h3
-rw-r--r--src/corelib/mimetypes/qmimetype.cpp16
-rw-r--r--src/corelib/mimetypes/qmimetype.h1
4 files changed, 50 insertions, 0 deletions
diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp
index 91ef7efede..78cfc469f5 100644
--- a/src/corelib/mimetypes/qmimeprovider.cpp
+++ b/src/corelib/mimetypes/qmimeprovider.cpp
@@ -494,6 +494,29 @@ QString QMimeBinaryProvider::resolveAlias(const QString &name)
return name;
}
+QStringList QMimeBinaryProvider::listAliases(const QString &name)
+{
+ checkCache();
+ QStringList result;
+ const QByteArray input = name.toLatin1();
+ foreach (CacheFile *cacheFile, m_cacheFiles) {
+ const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset);
+ const int numEntries = cacheFile->getUint32(aliasListOffset);
+ for (int pos = 0; pos < numEntries; ++pos) {
+ const int off = aliasListOffset + 4 + 8 * pos;
+ const int mimeOffset = cacheFile->getUint32(off + 4);
+ const char *mimeType = cacheFile->getCharStar(mimeOffset);
+
+ if (input == mimeType) {
+ const int aliasOffset = cacheFile->getUint32(off);
+ const char *alias = cacheFile->getCharStar(aliasOffset);
+ result.append(QString::fromLatin1(alias));
+ }
+ }
+ }
+ return result;
+}
+
void QMimeBinaryProvider::loadMimeTypeList()
{
if (!m_mimetypeListLoaded) {
@@ -815,6 +838,13 @@ void QMimeXMLProvider::addParent(const QString &child, const QString &parent)
m_parents[child].append(parent);
}
+QStringList QMimeXMLProvider::listAliases(const QString &name)
+{
+ ensureLoaded();
+ // Iterate through the whole hash. This method is rarely used.
+ return m_aliases.keys(name);
+}
+
QString QMimeXMLProvider::resolveAlias(const QString &name)
{
ensureLoaded();
diff --git a/src/corelib/mimetypes/qmimeprovider_p.h b/src/corelib/mimetypes/qmimeprovider_p.h
index dd35f3c341..8727820ce4 100644
--- a/src/corelib/mimetypes/qmimeprovider_p.h
+++ b/src/corelib/mimetypes/qmimeprovider_p.h
@@ -61,6 +61,7 @@ public:
virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix) = 0;
virtual QStringList parents(const QString &mime) = 0;
virtual QString resolveAlias(const QString &name) = 0;
+ virtual QStringList listAliases(const QString &name) = 0;
virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr) = 0;
virtual QList<QMimeType> allMimeTypes() = 0;
virtual void loadMimeTypePrivate(QMimeTypePrivate &) {}
@@ -87,6 +88,7 @@ public:
virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix);
virtual QStringList parents(const QString &mime);
virtual QString resolveAlias(const QString &name);
+ virtual QStringList listAliases(const QString &name);
virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr);
virtual QList<QMimeType> allMimeTypes();
virtual void loadMimeTypePrivate(QMimeTypePrivate &);
@@ -128,6 +130,7 @@ public:
virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix);
virtual QStringList parents(const QString &mime);
virtual QString resolveAlias(const QString &name);
+ virtual QStringList listAliases(const QString &name);
virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr);
virtual QList<QMimeType> allMimeTypes();
diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp
index 9be613924e..80510bc914 100644
--- a/src/corelib/mimetypes/qmimetype.cpp
+++ b/src/corelib/mimetypes/qmimetype.cpp
@@ -350,6 +350,22 @@ QStringList QMimeType::allAncestors() const
}
/*!
+ Return 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,
+ never to aliases directly.
+
+ The order of the aliases in the list is undefined.
+*/
+QStringList QMimeType::aliases() const
+{
+ return QMimeDatabasePrivate::instance()->provider()->listAliases(d->name);
+}
+
+/*!
Returns the known suffixes for the MIME type.
No leading dot is included, so for instance this would return "jpg", "jpeg" for image/jpeg.
*/
diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h
index e77a7a08a7..150a799d40 100644
--- a/src/corelib/mimetypes/qmimetype.h
+++ b/src/corelib/mimetypes/qmimetype.h
@@ -90,6 +90,7 @@ public:
QStringList globPatterns() const;
QStringList parentMimeTypes() const;
QStringList allAncestors() const;
+ QStringList aliases() const;
QStringList suffixes() const;
QString preferredSuffix() const;