diff options
author | David Faure <faure@kde.org> | 2012-01-26 17:43:10 +0100 |
---|---|---|
committer | Wolf-Michael Bolle <wolf-michael.bolle@nokia.com> | 2012-01-27 09:42:32 +0100 |
commit | f11c5ee40db566789637319adf71d6cb1867457e (patch) | |
tree | d3bf497334141dd4d25d1d36c1b1b8f393e6c17e | |
parent | 7549e5f88b7533cb09ab03052313e5e6f3c2a7da (diff) |
Document genericIconName() and implement fallback from the spec.
Change-Id: Iaeec6f445f6b15ca937e0283be1f9873d4b82b91
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Wolf-Michael Bolle <wolf-michael.bolle@nokia.com>
-rw-r--r-- | src/mimetypes/qmimetype.cpp | 20 | ||||
-rw-r--r-- | tests/auto/qmimedatabase/tst_qmimedatabase.cpp | 1 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/mimetypes/qmimetype.cpp b/src/mimetypes/qmimetype.cpp index 1431779..0cb5624 100644 --- a/src/mimetypes/qmimetype.cpp +++ b/src/mimetypes/qmimetype.cpp @@ -325,11 +325,29 @@ QString QMimeType::comment(const QString& localeName) const /*! \fn QString QMimeType::genericIconName() const; - \brief Returns the file name of an icon image that represents the MIME type. + \brief Returns 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 + the system. It is used for categories of similar types (like spreadsheets + or archives) that can use a common icon. + The freedesktop.org Icon Naming Specification lists a set of such icon names. + */ QString QMimeType::genericIconName() const { QMimeDatabasePrivate::instance()->provider()->loadGenericIcon(*d); + if (d->genericIconName.isEmpty()) { + // From the spec: + // If the generic icon name is empty (not specified by the mimetype definition) + // then the mimetype is used to generate the generic icon by using the top-level + // media type (e.g. "video" in "video/ogg") and appending "-x-generic" + // (i.e. "video-x-generic" in the previous example). + QString group = name(); + const int slashindex = group.indexOf(QLatin1Char('/')); + if (slashindex != -1) + group = group.left(slashindex); + return group + QLatin1String("-x-generic"); + } return d->genericIconName; } diff --git a/tests/auto/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/qmimedatabase/tst_qmimedatabase.cpp index 041a5b2..98334a6 100644 --- a/tests/auto/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/qmimedatabase/tst_qmimedatabase.cpp @@ -287,6 +287,7 @@ void tst_qmimedatabase::test_icons() QMimeType directory = db.findByFileName(QString::fromLatin1("/")); QCOMPARE(directory.name(), QString::fromLatin1("inode/directory")); QCOMPARE(directory.iconName(), QString::fromLatin1("inode-directory")); + QCOMPARE(directory.genericIconName(), QString::fromLatin1("inode-x-generic")); QMimeType pub = db.findByFileName(QString::fromLatin1("foo.epub")); QCOMPARE(pub.name(), QString::fromLatin1("application/epub+zip")); |