MimeDatabase Class
(Utils::Internal::MimeDatabase)Public Types
enum | MatchMode { MatchDefault, MatchExtension, MatchContent } |
enum | StartupPhase { BeforeInitialize, PluginsLoading, PluginsInitializing, PluginsDelayedInitializing, UpAndRunning } |
Public Functions
MimeDatabase() | |
~MimeDatabase() | |
QList<Utils::MimeType> | allMimeTypes() const |
Utils::MimeType | mimeTypeForData(const QByteArray &data) const |
Utils::MimeType | mimeTypeForData(QIODevice *device) const |
Utils::MimeType | mimeTypeForFile(const QFileInfo &fileInfo, Utils::Internal::MimeDatabase::MatchMode mode = MatchDefault) const |
Utils::MimeType | mimeTypeForFile(const QString &fileName, Utils::Internal::MimeDatabase::MatchMode mode = MatchDefault) const |
Utils::MimeType | mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const |
Utils::MimeType | mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const |
Utils::MimeType | mimeTypeForName(const QString &nameOrAlias) const |
Utils::MimeType | mimeTypeForUrl(const QUrl &url) const |
QList<Utils::MimeType> | mimeTypesForFileName(const QString &fileName) const |
QString | suffixForFileName(const QString &fileName) const |
Static Public Members
void | setStartupPhase(Utils::Internal::MimeDatabase::StartupPhase) |
Member Function Documentation
MimeDatabase::MimeDatabase()
Default constructs an instance of MimeDatabase.
MimeDatabase::~MimeDatabase()
Destroys the instance of MimeDatabase.
QList<Utils::MimeType> MimeDatabase::allMimeTypes() const
Returns the list of all available MIME types.
This can be useful for showing all MIME types to the user, for instance in a MIME type editor. Do not use unless really necessary in other cases though, prefer using the mimeTypeForXxx() methods for performance reasons.
Utils::MimeType MimeDatabase::mimeTypeForData(const QByteArray &data) const
Returns a MIME type for data.
A valid MIME type is always returned. If data doesn't match any known MIME type data, the default MIME type (application/octet-stream) is returned.
Utils::MimeType MimeDatabase::mimeTypeForData(QIODevice *device) const
Returns a MIME type for the data in device.
A valid MIME type is always returned. If the data in device doesn't match any known MIME type data, the default MIME type (application/octet-stream) is returned.
Utils::MimeType MimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, Utils::Internal::MimeDatabase::MatchMode mode = MatchDefault) const
Returns a MIME type for fileInfo.
A valid MIME type is always returned.
The default matching algorithm looks at both the file name and the file contents, if necessary. The file extension has priority over the contents, but the contents will be used if the file extension is unknown, or matches multiple MIME types. If fileInfo is a Unix symbolic link, the file that it refers to will be used instead. If the file doesn't match any known pattern or data, the default MIME type (application/octet-stream) is returned.
When mode is set to MatchExtension, only the file name is used, not the file contents. The file doesn't even have to exist. If the file name doesn't match any known pattern, the default MIME type (application/octet-stream) is returned. If multiple MIME types match this file, the first one (alphabetically) is returned.
When mode is set to MatchContent, and the file is readable, only the file contents are used to determine the MIME type. This is equivalent to calling mimeTypeForData with a QFile as input device.
fileInfo may refer to an absolute or relative path.
See also MimeType::isDefault() and mimeTypeForData().
Utils::MimeType MimeDatabase::mimeTypeForFile(const QString &fileName, Utils::Internal::MimeDatabase::MatchMode mode = MatchDefault) const
Returns a MIME type for the file named fileName using mode.
This is an overloaded function.
Utils::MimeType MimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device) const
Returns a MIME type for the given fileName and device data.
This overload can be useful when the file is remote, and we started to download some of its data in a device. This allows to do full MIME type matching for remote files as well.
If the device is not open, it will be opened by this function, and closed after the MIME type detection is completed.
A valid MIME type is always returned. If device data doesn't match any known MIME type data, the default MIME type (application/octet-stream) is returned.
This method looks at both the file name and the file contents, if necessary. The file extension has priority over the contents, but the contents will be used if the file extension is unknown, or matches multiple MIME types.
Utils::MimeType MimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, const QByteArray &data) const
Returns a MIME type for the given fileName and device data.
This overload can be useful when the file is remote, and we started to download some of its data. This allows to do full MIME type matching for remote files as well.
A valid MIME type is always returned. If data doesn't match any known MIME type data, the default MIME type (application/octet-stream) is returned.
This method looks at both the file name and the file contents, if necessary. The file extension has priority over the contents, but the contents will be used if the file extension is unknown, or matches multiple MIME types.
Utils::MimeType MimeDatabase::mimeTypeForName(const QString &nameOrAlias) const
Utils::MimeType MimeDatabase::mimeTypeForUrl(const QUrl &url) const
Returns a MIME type for url.
If the URL is a local file, this calls mimeTypeForFile.
Otherwise the matching is done based on the file name only, except for schemes where file names don't mean much, like HTTP. This method always returns the default mimetype for HTTP URLs, use QNetworkAccessManager to handle HTTP URLs properly.
A valid MIME type is always returned. If url doesn't match any known MIME type data, the default MIME type (application/octet-stream) is returned.
QList<Utils::MimeType> MimeDatabase::mimeTypesForFileName(const QString &fileName) const
Returns the MIME types for the file name fileName.
If the file name doesn't match any known pattern, an empty list is returned. If multiple MIME types match this file, they are all returned.
This function does not try to open the file. To also use the content when determining the MIME type, use mimeTypeForFile() or mimeTypeForFileNameAndData() instead.
See also mimeTypeForFile().
[static]
void MimeDatabase::setStartupPhase(Utils::Internal::MimeDatabase::StartupPhase)
QString MimeDatabase::suffixForFileName(const QString &fileName) const
Returns the suffix for the file fileName, as known by the MIME database.
This allows to pre-select "tar.bz2" for foo.tar.bz2, but still only "txt" for my.file.with.dots.txt.