Commit 00b60aec authored by Nicolas Fella's avatar Nicolas Fella Committed by Albert Astals Cid
Browse files

[print preview] Load okular part directly

The current code goes through KMimeTypeTrader to find a ps or PDF part.
In both cases it's highly likely that it will be okularpart so we can use that directly.
parent 77269a80
Pipeline #56685 passed with stage
in 10 minutes and 47 seconds
......@@ -21,7 +21,6 @@
#include <QVBoxLayout>
#include <KLocalizedString>
#include <KMimeTypeTrader>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KSharedConfig>
......@@ -78,34 +77,19 @@ void FilePrinterPreviewPrivate::getPart()
qCDebug(OkularUiDebug) << "already got a part";
return;
}
qCDebug(OkularUiDebug) << "querying trader for application/ps service";
KPluginFactory *factory(nullptr);
KService::List offers;
if (filename.endsWith(QStringLiteral(".ps"))) {
/* Explicitly look for the Okular/Ghostview part: no other PostScript
parts are available now; other parts which handles text are not
suitable here (PostScript source code) */
offers = KMimeTypeTrader::self()->query(QStringLiteral("application/postscript"), QStringLiteral("KParts/ReadOnlyPart"), QStringLiteral("[DesktopEntryName] == 'okularghostview'"));
} else {
offers = KMimeTypeTrader::self()->query(QStringLiteral("application/pdf"), QStringLiteral("KParts/ReadOnlyPart"));
}
KService::List::ConstIterator it = offers.constBegin();
while (!factory && it != offers.constEnd()) {
KPluginLoader loader(**it);
factory = loader.factory();
if (!factory) {
qCDebug(OkularUiDebug) << "Loading failed:" << loader.errorString();
}
++it;
KPluginLoader loader(QStringLiteral("okularpart"));
KPluginFactory *factory = loader.factory();
if (!factory) {
qCDebug(OkularUiDebug) << "Loading failed:" << loader.errorString();
return;
}
if (factory) {
qCDebug(OkularUiDebug) << "Trying to create a part";
previewPart = factory->create<KParts::ReadOnlyPart>(q, (QVariantList() << QStringLiteral("Print/Preview")));
if (!previewPart) {
qCDebug(OkularUiDebug) << "Part creation failed";
}
qCDebug(OkularUiDebug) << "Trying to create a part";
previewPart = factory->create<KParts::ReadOnlyPart>(q, (QVariantList() << QStringLiteral("Print/Preview")));
if (!previewPart) {
qCDebug(OkularUiDebug) << "Part creation failed";
}
}
......
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