summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-13 01:23:09 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-13 01:23:09 (GMT)
commit89e5f175426aea6139c118d11e26386f60572c1b (patch)
treec01e3c2129854773bcaa5f3d828f4aa29dec0edd
parent5d9d98f46f67a0eff62e13ef3147acc712ac045d (diff)
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
-rw-r--r--core/document.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/core/document.cpp b/core/document.cpp
index 1ce5543..edef21b 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -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();