diff --git a/src/extractionresult.h b/src/extractionresult.h --- a/src/extractionresult.h +++ b/src/extractionresult.h @@ -72,7 +72,10 @@ /** * The input mimetype. This mimetype should correspond with the * mimetypes supported with the relevant plugin when it is being - * passed to the Extractor + * passed to the Extractor, or be a subtype thereof. + * + * \sa ExtractorCollection::fetchExtractors + * \sa ExtractorPlugin::supportedMimeType */ QString inputMimetype() const; @@ -105,7 +108,7 @@ * This function is called by the plugins. * A type is a higher level classification of the file. A file can * have multiple types, but mostly when it does, those types are related. - * Eg - Document and Presenentation. + * Eg - Document and Presentation. * * Please choose one type from the list of available types */ diff --git a/src/extractorplugin.h b/src/extractorplugin.h --- a/src/extractorplugin.h +++ b/src/extractorplugin.h @@ -90,6 +90,23 @@ */ static QStringList contactsFromString(const QString& string); +protected: + /** + * Return the inherited mimetype which the extractor directly supports. + * + * The returned type is one of the types from \c mimetypes(), + * and is one of the ancestors of the the input \p mimetype + * (including \p mimetype itself). + * + * In case the mimetype is not a subtype of the supported types, + * an empty QString() is returned. + * + * \sa ExtractorCollection::fetchExtractors + * \sa QMimeType::allAncestors + * @since 5.57 + */ + QString getSupportedMimeType(const QString& mimetype) const; + private: class Private; Private* d; diff --git a/src/extractorplugin.cpp b/src/extractorplugin.cpp --- a/src/extractorplugin.cpp +++ b/src/extractorplugin.cpp @@ -21,6 +21,7 @@ #include "extractorplugin.h" +#include #include using namespace KFileMetaData; @@ -143,3 +144,22 @@ return list; } + +QString ExtractorPlugin::getSupportedMimeType(const QString& mimetype) const +{ + const QStringList allTypes = mimetypes(); + if (allTypes.contains(mimetype)) { + return mimetype; + } + + QMimeDatabase db; + auto type = db.mimeTypeForName(mimetype); + const QStringList ancestors = type.allAncestors(); + for (auto ancestor : ancestors) { + if (allTypes.contains(ancestor)) { + return ancestor; + } + } + + return QString(); +}