Commit e4f037de authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port decoration plugin loading away from KServiceTypeTrader

It is deprecated

Use KPluginMetaData and KPluginFactory instead
parent b71734c0
Pipeline #169784 passed with stage
in 3 minutes and 56 seconds
......@@ -136,7 +136,6 @@ configure_file(korganizer-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/korganizer
ecm_set_disabled_deprecation_versions(QT 5.15.2
KF 5.93.0
KCOREADDONS 5.88.0 #KPluginFactory::registerPlugin
KSERVICE 5.89.0 #KServiceTypeTrader::self
)
......
......@@ -13,7 +13,6 @@
#include <CalendarSupport/IdentityManager>
#include "korganizer_debug.h"
#include <KServiceTypeTrader>
#include <KXMLGUIFactory>
#include <QDBusConnectionInterface>
......@@ -42,30 +41,14 @@ KOCore::~KOCore()
mSelf = nullptr;
}
KService::List KOCore::availablePlugins(const QString &type, int version)
QVector<KPluginMetaData> KOCore::availableCalendarDecorations()
{
QString constraint;
if (version >= 0) {
constraint = QStringLiteral("[X-KDE-PluginInterfaceVersion] == %1").arg(QString::number(version));
}
return KServiceTypeTrader::self()->query(type, constraint);
}
KService::List KOCore::availableCalendarDecorations()
{
return availablePlugins(EventViews::CalendarDecoration::Decoration::serviceType(), EventViews::CalendarDecoration::Decoration::interfaceVersion());
return KPluginMetaData::findPlugins(QStringLiteral("korganizer"));
}
EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration(const KService::Ptr &service)
EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration(const KPluginMetaData &service)
{
KPluginFactory *factory = KPluginFactory::loadFactory(KPluginMetaData(service->library())).plugin;
if (!factory) {
qCDebug(KORGANIZER_LOG) << "Factory creation failed";
return nullptr;
}
return factory->create<EventViews::CalendarDecoration::Decoration>();
return KPluginFactory::instantiatePlugin<EventViews::CalendarDecoration::Decoration>(service).plugin;
}
void KOCore::addXMLGUIClient(QWidget *wdg, KXMLGUIClient *guiclient)
......@@ -99,16 +82,12 @@ EventViews::CalendarDecoration::Decoration::List KOCore::loadCalendarDecorations
const QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
mCalendarDecorations.clear();
const KService::List plugins = availableCalendarDecorations();
KService::List::ConstIterator it;
const KService::List::ConstIterator end(plugins.constEnd());
for (it = plugins.constBegin(); it != end; ++it) {
if ((*it)->hasServiceType(EventViews::CalendarDecoration::Decoration::serviceType())) {
QString name = (*it)->desktopEntryName();
if (selectedPlugins.contains(name)) {
EventViews::CalendarDecoration::Decoration *d = loadCalendarDecoration(*it);
mCalendarDecorations.append(d);
}
const QVector<KPluginMetaData> plugins = availableCalendarDecorations();
for (const auto &plugin : plugins) {
QString name = plugin.pluginId();
if (selectedPlugins.contains(name)) {
EventViews::CalendarDecoration::Decoration *d = loadCalendarDecoration(plugin);
mCalendarDecorations.append(d);
}
}
mCalendarDecorationsLoaded = true;
......
......@@ -14,8 +14,6 @@
#include <EventViews/CalendarDecoration>
#include <KService>
namespace KIdentityManagement
{
class IdentityManager;
......@@ -28,9 +26,9 @@ public:
static KOCore *self();
Q_REQUIRED_RESULT KService::List availableCalendarDecorations();
Q_REQUIRED_RESULT QVector<KPluginMetaData> availableCalendarDecorations();
EventViews::CalendarDecoration::Decoration *loadCalendarDecoration(const KService::Ptr &service);
EventViews::CalendarDecoration::Decoration *loadCalendarDecoration(const KPluginMetaData &service);
EventViews::CalendarDecoration::Decoration::List loadCalendarDecorations();
void addXMLGUIClient(QWidget *, KXMLGUIClient *guiclient);
......@@ -45,7 +43,6 @@ public:
protected:
KOCore();
KService::List availablePlugins(const QString &type, int pluginInterfaceVersion = -1);
private:
static KOCore *mSelf;
......
......@@ -15,7 +15,6 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <KPluginFactory>
#include <KService>
#include <QAction>
#include <QGroupBox>
#include <QHeaderView>
......@@ -28,25 +27,25 @@
class PluginItem : public QTreeWidgetItem
{
public:
PluginItem(QTreeWidget *parent, const KService::Ptr &service)
: QTreeWidgetItem(parent, {service->name()})
PluginItem(QTreeWidget *parent, const KPluginMetaData &service)
: QTreeWidgetItem(parent, {service.name()})
, mService(service)
{
}
PluginItem(QTreeWidgetItem *parent, const KService::Ptr &service)
: QTreeWidgetItem(parent, {service->name()})
PluginItem(QTreeWidgetItem *parent, const KPluginMetaData &service)
: QTreeWidgetItem(parent, {service.name()})
, mService(service)
{
}
KService::Ptr service()
KPluginMetaData service()
{
return mService;
}
private:
const KService::Ptr mService;
const KPluginMetaData mService;
};
Q_DECLARE_METATYPE(PluginItem *)
......@@ -114,7 +113,7 @@ KOPrefsDialogPlugins::~KOPrefsDialogPlugins()
void KOPrefsDialogPlugins::usrReadConfig()
{
mTreeWidget->clear();
KService::List plugins = KOCore::self()->availableCalendarDecorations();
auto plugins = KOCore::self()->availableCalendarDecorations();
EventViews::PrefsPtr viewPrefs = KOPrefs::instance()->eventViewsPreferences();
......@@ -122,27 +121,20 @@ void KOPrefsDialogPlugins::usrReadConfig()
mDecorations = new QTreeWidgetItem(mTreeWidget, QStringList(i18nc("@title:group", "Calendar Decorations")));
KService::List::ConstIterator it;
KService::List::ConstIterator end(plugins.constEnd());
for (const KPluginMetaData &plugin : plugins) {
PluginItem *item = new PluginItem(mDecorations, plugin);
for (it = plugins.constBegin(); it != end; ++it) {
PluginItem *item = nullptr;
if ((*it)->hasServiceType(EventViews::CalendarDecoration::Decoration::serviceType())) {
item = new PluginItem(mDecorations, *it);
} else {
continue;
}
if (selectedPlugins.contains((*it)->desktopEntryName())) {
if (selectedPlugins.contains(plugin.pluginId())) {
item->setCheckState(0, Qt::Checked);
} else {
item->setCheckState(0, Qt::Unchecked);
}
const QVariant variant = (*it)->property(QStringLiteral("X-KDE-KOrganizer-HasSettings"));
const QVariant variant = plugin.value(QStringLiteral("X-KDE-KOrganizer-HasSettings"));
const bool hasSettings = (variant.isValid() && variant.toBool());
if (hasSettings) {
auto but = new QToolButton(mTreeWidget);
auto act = new QAction(but);
const QString decoration = (*it)->desktopEntryName();
const QString decoration = plugin.pluginId();
act->setData(QVariant::fromValue<PluginItem *>(item));
but->setDefaultAction(act);
but->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
......@@ -174,7 +166,7 @@ void KOPrefsDialogPlugins::usrWriteConfig()
for (int j = 0; j < serviceTypeGroup->childCount(); ++j) {
auto item = static_cast<PluginItem *>(serviceTypeGroup->child(j));
if (item->checkState(0) == Qt::Checked) {
selectedPlugins.append(item->service()->desktopEntryName());
selectedPlugins.append(item->service().pluginId());
}
}
}
......@@ -221,7 +213,7 @@ void KOPrefsDialogPlugins::positioningChanged()
return;
}
QString decoration = item->service()->desktopEntryName();
QString decoration = item->service().pluginId();
/*if ( mPositionMonthTop->checkState() == Qt::Checked ) {
if ( !mDecorationsAtMonthViewTop.contains( decoration ) ) {
......@@ -268,19 +260,18 @@ void KOPrefsDialogPlugins::selectionChanged()
return;
}
mDescription->setText(item->service()->comment());
mDescription->setText(item->service().description());
if (item->service()->hasServiceType(EventViews::CalendarDecoration::Decoration::serviceType())) {
bool hasPosition = false;
QString decoration = item->service()->desktopEntryName();
/*if ( mDecorationsAtMonthViewTop.contains( decoration ) ) {
mPositionMonthTop->setChecked( true );
hasPosition = true;
}*/
if (mDecorationsAtAgendaViewTop.contains(decoration)) {
mPositionAgendaTop->setChecked(true);
hasPosition = true;
}
bool hasPosition = false;
QString decoration = item->service().pluginId();
/*if ( mDecorationsAtMonthViewTop.contains( decoration ) ) {
mPositionMonthTop->setChecked( true );
hasPosition = true;
}*/
if (mDecorationsAtAgendaViewTop.contains(decoration)) {
mPositionAgendaTop->setChecked(true);
hasPosition = true;
}
if (mDecorationsAtAgendaViewBottom.contains(decoration)) {
mPositionAgendaBottom->setChecked(true);
hasPosition = true;
......@@ -294,7 +285,6 @@ void KOPrefsDialogPlugins::selectionChanged()
mPositioningGroupBox->setEnabled(item->checkState(0) == Qt::Checked);
mPositioningGroupBox->show();
}
slotWidChanged();
}
......
......@@ -13,8 +13,6 @@
#include <QCommandLineParser>
#include <QDebug>
#include <KService>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
......@@ -23,11 +21,10 @@ int main(int argc, char **argv)
parser.addHelpOption();
parser.process(app);
KService::List::ConstIterator it;
KService::List plugins = KOCore::self()->availableCalendarDecorations();
for (it = plugins.constBegin(); it != plugins.constEnd(); ++it) {
qDebug() << "CalendarDecoration:" << (*it)->desktopEntryName() << "(" << (*it)->name() << ")";
EventViews::CalendarDecoration::Decoration *p = KOCore::self()->loadCalendarDecoration(*it);
const QVector<KPluginMetaData> plugins = KOCore::self()->availableCalendarDecorations();
for (const auto &plugin : plugins) {
qDebug() << "CalendarDecoration:" << plugin.pluginId() << "(" << plugin.name() << ")";
EventViews::CalendarDecoration::Decoration *p = KOCore::self()->loadCalendarDecoration(plugin);
if (!p) {
qDebug() << "Calendar decoration loading failed.";
} else {
......
Supports Markdown
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