Changeset View
Changeset View
Standalone View
Standalone View
src/extractorcollection.cpp
Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 67 | { | |||
---|---|---|---|---|---|
143 | } | 143 | } | ||
144 | 144 | | |||
145 | return extractors; | 145 | return extractors; | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | QList<Extractor*> ExtractorCollection::fetchExtractors(const QString& mimetype) const | 148 | QList<Extractor*> ExtractorCollection::fetchExtractors(const QString& mimetype) const | ||
149 | { | 149 | { | ||
150 | QList<Extractor*> plugins = d->m_extractors.values(mimetype); | 150 | QList<Extractor*> plugins = d->m_extractors.values(mimetype); | ||
151 | if (plugins.isEmpty()) { | 151 | if (!plugins.isEmpty()) { | ||
152 | return plugins; | ||||
153 | } | ||||
154 | | ||||
155 | // try to find the best matching more generic extractor by mimetype inheritance | ||||
152 | QMimeDatabase db; | 156 | QMimeDatabase db; | ||
153 | auto type = db.mimeTypeForName(mimetype); | 157 | auto type = db.mimeTypeForName(mimetype); | ||
154 | auto it = d->m_extractors.constBegin(); | 158 | const QStringList ancestors = type.allAncestors(); | ||
155 | for (; it != d->m_extractors.constEnd(); ++it) { | 159 | | ||
156 | if (plugins.contains(it.value())) { | 160 | for (auto ancestor : ancestors) { | ||
157 | continue; | 161 | QList<Extractor*> plugins = d->m_extractors.values(ancestor); | ||
158 | } | 162 | if (!plugins.isEmpty()) { | ||
159 | if (type.inherits(it.key())) { | 163 | qCDebug(KFILEMETADATA_LOG) << "Using inherited mimetype" << ancestor << "for" << mimetype; | ||
astippich: nitpick: extra space before "for" | |||||
http://doc.qt.io/qt-5/qdebug.html#setAutoInsertSpaces is true by default. bruns: http://doc.qt.io/qt-5/qdebug.html#setAutoInsertSpaces is true by default. | |||||
astippich: I meant the code, not the output :) | |||||
160 | plugins << it.value(); | 164 | return plugins; | ||
doesn't returning here cause immediate return after the first matching extractor for the mimetype has been found? that doesn't fit to the first paragraph of the summary. astippich: doesn't returning here cause immediate return after the first matching extractor for the… | |||||
Yes, and this is the intended change - best matching. We don't want text/plain if we have a better one. bruns: > doesn't returning here cause immediate return after the first matching extractor for the… | |||||
astippich: That's what I figured, the summary was a little bit misleading. | |||||
161 | } | | |||
162 | } | 165 | } | ||
163 | } | 166 | } | ||
164 | 167 | | |||
165 | return plugins; | 168 | return plugins; | ||
166 | } | 169 | } |
nitpick: extra space before "for"