mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
Improve matching of generators
Instead of trying to use the plain text generator for everything, try to find a more specialized one first. BUG: 323213
This commit is contained in:
parent
5d9d98f46f
commit
89e5f17542
|
@ -2262,13 +2262,24 @@ QVector<KPluginMetaData> DocumentPrivate::availableGenerators()
|
|||
|
||||
KPluginMetaData DocumentPrivate::generatorForMimeType(const QMimeType& type, QWidget* widget)
|
||||
{
|
||||
// First try to find an exact match, and then look for more general ones (e. g. the plain text one)
|
||||
// Ideally we would rank these by "closeness", but that might be overdoing it
|
||||
|
||||
const QVector<KPluginMetaData> available = availableGenerators();
|
||||
QVector<KPluginMetaData> offers;
|
||||
QVector<KPluginMetaData> exactMatches;
|
||||
|
||||
QMimeDatabase mimeDatabase;
|
||||
|
||||
for (const KPluginMetaData& md : available)
|
||||
{
|
||||
foreach (const QString& supported, md.mimeTypes())
|
||||
{
|
||||
QMimeType mimeType = mimeDatabase.mimeTypeForName(supported);
|
||||
if (mimeType == type) {
|
||||
exactMatches << md;
|
||||
}
|
||||
|
||||
if (type.inherits(supported))
|
||||
{
|
||||
offers << md;
|
||||
|
@ -2276,6 +2287,11 @@ KPluginMetaData DocumentPrivate::generatorForMimeType(const QMimeType& type, QWi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!exactMatches.isEmpty()) {
|
||||
offers = exactMatches;
|
||||
}
|
||||
|
||||
if (offers.isEmpty())
|
||||
{
|
||||
return KPluginMetaData();
|
||||
|
|
Loading…
Reference in a new issue