Port away from deprecated KPluginLoader

wilder-5.24
Nicolas Fella 5 years ago
parent 712ffec5bf
commit 225e4aae2c
  1. 20
      components/shellprivate/interactiveconsole/interactiveconsole.cpp
  2. 22
      dataengines/geolocation/geolocation.cpp
  3. 40
      kcms/kfontinst/apps/Viewer.cpp
  4. 3
      kcms/style/kcmstyle.cpp
  5. 4
      startkde/kcminit/main.cpp

@ -28,7 +28,6 @@
#include <KConfigGroup>
#include <KMessageBox>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KSharedConfig>
#include <KShell>
#include <KStandardAction>
@ -117,22 +116,15 @@ InteractiveConsole::InteractiveConsole(QWidget *parent)
editorLayout->addWidget(toolBar);
auto tryLoadingKatePart = [=]() {
KTextEditor::Document *result = nullptr;
KPluginLoader loader(QStringLiteral("kf5/parts/katepart"));
auto tryLoadingKatePart = [=]() -> KTextEditor::Document * {
const auto loadResult = KPluginFactory::instantiatePlugin<KTextEditor::Document>(KPluginMetaData(QStringLiteral("kf5/parts/katepart")), this);
KPluginFactory *factory = loader.factory();
if (!factory) {
qWarning() << "Error loading katepart plugin:" << loader.errorString();
return result;
if (!loadResult) {
qWarning() << "Error loading katepart plugin:" << loadResult.errorString;
return nullptr;
}
result = factory->create<KTextEditor::Document>(widget);
if (!result) {
qWarning() << "Error creating katepart object";
return result;
}
KTextEditor::Document *result = loadResult.plugin;
result->setHighlightingMode(QStringLiteral("JavaScript/PlasmaDesktop"));

@ -8,7 +8,6 @@
#include <limits.h>
#include <KPluginLoader>
#include <KPluginMetaData>
#include <NetworkManagerQt/Manager>
#include <QDebug>
@ -36,18 +35,17 @@ Geolocation::Geolocation(QObject *parent, const QVariantList &args)
void Geolocation::init()
{
// TODO: should this be delayed even further, e.g. when the source is requested?
const QVector<KPluginMetaData> offers = KPluginLoader::findPlugins("plasma/geolocationprovider");
const QVector<KPluginMetaData> offers = KPluginMetaData::findPlugins("plasma/geolocationprovider");
for (const auto &metaData : offers) {
KPluginLoader loader(metaData.fileName());
if (KPluginFactory *factory = loader.factory()) {
if (auto plugin = factory->create<GeolocationProvider>(this)) {
m_plugins << plugin;
plugin->init(&m_data, &m_accuracy);
connect(plugin, &GeolocationProvider::updated, this, &Geolocation::pluginUpdated);
connect(plugin, &GeolocationProvider::availabilityChanged, this, &Geolocation::pluginAvailabilityChanged);
} else {
qDebug() << "Failed to load GeolocationProvider:" << metaData.fileName();
}
auto result = KPluginFactory::instantiatePlugin<GeolocationProvider>(metaData, this);
if (result) {
GeolocationProvider *plugin = result.plugin;
m_plugins << plugin;
plugin->init(&m_data, &m_accuracy);
connect(plugin, &GeolocationProvider::updated, this, &Geolocation::pluginUpdated);
connect(plugin, &GeolocationProvider::availabilityChanged, this, &Geolocation::pluginAvailabilityChanged);
} else {
qDebug() << "Failed to load GeolocationProvider:" << metaData.fileName() << result.errorString;
}
}
}

@ -12,7 +12,6 @@
#include <KDBusService>
#include <KParts/BrowserExtension>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KSharedConfig>
#include <KShortcutsDialog>
#include <KStandardAction>
@ -27,32 +26,31 @@ namespace KFI
{
CViewer::CViewer()
{
KPluginLoader loader("kf5/parts/kfontviewpart");
KPluginFactory *factory = loader.factory();
const auto result = KPluginFactory::instantiatePlugin<KParts::ReadOnlyPart>(KPluginMetaData(QStringLiteral("kf5/parts/kfontviewpart")), this);
if (factory) {
itsPreview = factory->create<KParts::ReadOnlyPart>(this);
actionCollection()->addAction(KStandardAction::Open, this, SLOT(fileOpen()));
actionCollection()->addAction(KStandardAction::Quit, this, SLOT(close()));
actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(configureKeys()));
itsPrintAct = actionCollection()->addAction(KStandardAction::Print, itsPreview, SLOT(print()));
if (!result) {
qWarning() << "Error loading kfontviewpart:" << result.errorString;
exit(1);
}
itsPrintAct->setEnabled(false);
itsPreview = result.plugin;
if (itsPreview->browserExtension()) {
connect(itsPreview->browserExtension(), &KParts::BrowserExtension::enableAction, this, &CViewer::enableAction);
}
actionCollection()->addAction(KStandardAction::Open, this, SLOT(fileOpen()));
actionCollection()->addAction(KStandardAction::Quit, this, SLOT(close()));
actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(configureKeys()));
itsPrintAct = actionCollection()->addAction(KStandardAction::Print, itsPreview, SLOT(print()));
setCentralWidget(itsPreview->widget());
createGUI(itsPreview);
itsPrintAct->setEnabled(false);
setAutoSaveSettings();
applyMainWindowSettings(KSharedConfig::openConfig()->group("MainWindow"));
} else {
qWarning() << "Error loading kfontviewpart:" << loader.errorString();
exit(1);
if (itsPreview->browserExtension()) {
connect(itsPreview->browserExtension(), &KParts::BrowserExtension::enableAction, this, &CViewer::enableAction);
}
setCentralWidget(itsPreview->widget());
createGUI(itsPreview);
setAutoSaveSettings();
applyMainWindowSettings(KSharedConfig::openConfig()->group("MainWindow"));
}
void CViewer::fileOpen()

@ -24,7 +24,6 @@
#include <KConfigGroup>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KToolBar>
#include <QDBusPendingCallWatcher>
@ -171,7 +170,7 @@ void KCMStyle::configure(const QString &title, const QString &styleName, QQuickI
return;
}
QLibrary library(KPluginLoader::findPlugin(configPage));
QLibrary library(QPluginLoader(configPage).fileName());
if (!library.load()) {
qWarning() << "Failed to load style config page" << configPage << library.errorString();
emit showErrorMessage(i18n("There was an error loading the configuration dialog for this style."));

@ -59,9 +59,9 @@ bool KCMInit::runModule(const QString &libName, KService::Ptr service)
} else
kcminit = KCMINIT_PREFIX + libName;
QString path = KPluginLoader::findPlugin(libName);
QString path = QPluginLoader(libName).fileName();
if (path.isEmpty()) {
path = KPluginLoader::findPlugin(QStringLiteral("kcms/") + libName);
path = QPluginLoader(QStringLiteral("kcms/") + libName).fileName();
}
if (path.isEmpty()) {

Loading…
Cancel
Save