[education/rkward] rkward/agents: Remove deprecated KService::createInstance

Thomas Friedrichsmeier null at kde.org
Sun Apr 17 22:16:12 BST 2022


Git commit 1d89e275a363d08b7608e1d9f89f5ce117a5ee79 by Thomas Friedrichsmeier.
Committed on 17/04/2022 at 21:15.
Pushed by tfry into branch 'master'.

Remove deprecated KService::createInstance

M  +16   -8    rkward/agents/rkprintagent.cpp

https://invent.kde.org/education/rkward/commit/1d89e275a363d08b7608e1d9f89f5ce117a5ee79

diff --git a/rkward/agents/rkprintagent.cpp b/rkward/agents/rkprintagent.cpp
index 50cfa23d..4510a1ed 100644
--- a/rkward/agents/rkprintagent.cpp
+++ b/rkward/agents/rkprintagent.cpp
@@ -10,20 +10,23 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <QFile>
 #include <QTimer>
 #include <QElapsedTimer>
+#include <QUrl>
 
 #include <krun.h>
 #include <kservice.h>
 #include <kmessagebox.h>
 #include <kio_version.h>
 #include <KLocalizedString>
-#include <QUrl>
+#include <KPluginFactory>
+#include <KPluginLoader>
 
 #include "../rkward.h"
 
 #include "../debug.h"
 
 RKPrintAgent::RKPrintAgent(const QString &file, KParts::ReadOnlyPart *provider, bool delete_file) : QObject(), file(file), provider(provider), delete_file(delete_file) {
-	RK_TRACE (APP)
+	RK_TRACE (APP);
+	//provider->widget()->show(); // not very helpful as a preview, unfortunately
 }
 
 RKPrintAgent::~RKPrintAgent () {
@@ -36,12 +39,17 @@ RKPrintAgent::~RKPrintAgent () {
 void RKPrintAgent::printPostscript (const QString &file, bool delete_file) {
 	RK_TRACE (APP)
 
-	KService::Ptr service = KService::serviceByDesktopPath ("okular_part.desktop");
-	if (!service) service = KService::serviceByDesktopPath ("kpdf_part.desktop");
-
-	KParts::ReadOnlyPart *provider = 0;
-	if (service) provider = service->createInstance<KParts::ReadOnlyPart> (0);
-	else RK_DEBUG (APP, DL_WARNING, "No KDE service found for postscript printing");
+	KParts::ReadOnlyPart *provider = nullptr;
+	KService::Ptr service = KService::serviceByDesktopPath("okular_part.desktop");
+	if (!service) service = KService::serviceByDesktopPath("kpdf_part.desktop");
+	if (service) {
+		auto factory = KPluginLoader(service->library()).factory();
+		if (factory) {
+			provider = factory->create<KParts::ReadOnlyPart>(nullptr);
+		}
+	} else {
+		RK_DEBUG (APP, DL_WARNING, "No KDE service found for postscript printing");
+	}
 
 	QAction *printaction = 0;
 	if (provider) {


More information about the rkward-tracker mailing list