Commit 8b9cd300 authored by Elvis Angelaccio's avatar Elvis Angelaccio

Fix opening of files whose mimetype inherits from a supported mimetype

Before 16.04 Ark used to be able to open files whose mimetype is not directly
registered with Ark, but inherits from a mimetype that is supported by Ark.
Examples are .odt and .epub files that both inherits from application/zip.

Since we don't use anymore KMimeTypeTrader (since 16.04), we need to manually
do this check while loading our plugins.

BUG: 363717
FIXED-IN: 16.04.2

Differential Revision: D1725
parent 4318ac1b
......@@ -161,6 +161,12 @@ void ArchiveTest::testProperties_data()
} else {
qDebug() << "lrzip executable not found in path. Skipping lrzip test.";
}
QTest::newRow("mimetype child of application/zip")
<< QFINDTESTDATA("data/test.odt")
<< QStringLiteral("test")
<< false << true << false << Archive::Unencrypted
<< QStringLiteral("test");
}
void ArchiveTest::testProperties()
......
......@@ -36,6 +36,7 @@
#include <QEventLoop>
#include <QFile>
#include <QFileInfo>
#include <QMimeDatabase>
#include <KPluginFactory>
#include <KPluginLoader>
......@@ -57,8 +58,24 @@ QVector<KPluginMetaData> Archive::findPluginOffers(const QString& filename, cons
qCDebug(ARK) << "Detected mime" << mimeType;
QVector<KPluginMetaData> offers = KPluginLoader::findPlugins(QStringLiteral("kerfuffle"), [mimeType](const KPluginMetaData& metaData) {
return metaData.serviceTypes().contains(QStringLiteral("Kerfuffle/Plugin")) &&
metaData.mimeTypes().contains(mimeType);
if (!metaData.serviceTypes().contains(QStringLiteral("Kerfuffle/Plugin"))) {
return false;
}
if (metaData.mimeTypes().contains(mimeType)) {
return true;
}
// The mimetype is not directly supported, but it could inherit from a supported one.
if (!supportedMimeTypes().contains(mimeType)) {
foreach (const QString &mime, metaData.mimeTypes()) {
if (QMimeDatabase().mimeTypeForName(mimeType).inherits(mime)) {
return true;
}
}
}
return false;
});
qSort(offers.begin(), offers.end(), comparePlugins);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment