Commit d7c559b0 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Clean up plugin loading code

- We do not need to manually check for duplicates
- Improve the error message while at it
- Remove the internal utility-method since the code is super small now
parent fcebbfb2
......@@ -42,50 +42,25 @@ Q_GLOBAL_STATIC(EventsManagerStatic, eventsManagerStatic)
EventsManager::EventsManager()
{
//qDebug();
loadPlugins();
}
EventsManager::~EventsManager()
{
//qDebug();
}
EventsManager *EventsManager::instance()
{
//qDebug();
return &eventsManagerStatic->instance;
}
void EventsManager::loadPlugins()
{
//qDebug();
const QVector<KPluginMetaData> plugins = KPluginMetaData::findPlugins(QStringLiteral("krfb/events"));
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
KPluginMetaData data = i.previous();
// only load plugins once, even if found multiple times!
if (unique.contains(data.name())) {
continue;
}
for (const KPluginMetaData &data : plugins) {
const KPluginFactory::Result<EventsPlugin> result = KPluginFactory::instantiatePlugin<EventsPlugin>(data);
if (result.plugin) {
m_plugins.insert(data.pluginId(), result.plugin);
qCDebug(KRFB) << "Loaded plugin with name " << data.pluginId();
} else {
qCDebug(KRFB) << "unable to load plugin for " << data.fileName();
qCDebug(KRFB) << "unable to load plugin for " << data.fileName() << result.errorString;
}
unique.insert (data.name());
}
}
EventsManager::~EventsManager() = default;
EventsManager *EventsManager::instance()
{
return &eventsManagerStatic->instance;
}
QSharedPointer<EventHandler> EventsManager::eventHandler()
{
QMap<QString, EventsPlugin *>::const_iterator iter = m_plugins.constBegin();
......
......@@ -52,8 +52,6 @@ private:
EventsManager();
void loadPlugins();
QMap<QString, EventsPlugin *> m_plugins;
QList<QWeakPointer<EventHandler> > m_eventHandlers;
};
......
......@@ -41,51 +41,29 @@ Q_GLOBAL_STATIC(FrameBufferManagerStatic, frameBufferManagerStatic)
FrameBufferManager::FrameBufferManager()
{
//qDebug();
loadPlugins();
const QVector<KPluginMetaData> plugins = KPluginMetaData::findPlugins(QStringLiteral("krfb/framebuffer"));
for (const KPluginMetaData &data : plugins) {
const KPluginFactory::Result<FrameBufferPlugin> result = KPluginFactory::instantiatePlugin<FrameBufferPlugin>(data);
if (result.plugin) {
m_plugins.insert(data.pluginId(), result.plugin);
qCDebug(KRFB) << "Loaded plugin with name " << data.pluginId();
} else {
qCDebug(KRFB) << "unable to load plugin for " << data.fileName() << result.errorString;
}
}
}
FrameBufferManager::~FrameBufferManager()
{
//qDebug();
}
FrameBufferManager *FrameBufferManager::instance()
{
//qDebug();
return &frameBufferManagerStatic->instance;
}
void FrameBufferManager::loadPlugins()
{
const QVector<KPluginMetaData> plugins = KPluginMetaData::findPlugins(QStringLiteral("krfb/framebuffer"));
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
const KPluginMetaData &data = i.previous();
// only load plugins once, even if found multiple times!
if (unique.contains(data.name()))
continue;
const KPluginFactory::Result<FrameBufferPlugin> result = KPluginFactory::instantiatePlugin<FrameBufferPlugin>(data);
if (result.plugin) {
m_plugins.insert(data.pluginId(), result.plugin);
qCDebug(KRFB) << "Loaded plugin with name " << data.pluginId();
} else {
qCDebug(KRFB) << "unable to load plugin for " << data.fileName();
}
unique.insert (data.name());
}
}
QSharedPointer<FrameBuffer> FrameBufferManager::frameBuffer(WId id, const QVariantMap &args)
{
//qDebug();
// See if there is still an existing framebuffer to this WId.
if (m_frameBuffers.contains(id)) {
QWeakPointer<FrameBuffer> weakFrameBuffer = m_frameBuffers.value(id);
......
......@@ -52,8 +52,6 @@ private:
FrameBufferManager();
void loadPlugins();
QMap<QString, FrameBufferPlugin *> m_plugins;
QMap<WId, QWeakPointer<FrameBuffer> > m_frameBuffers;
};
......
......@@ -83,14 +83,8 @@ public:
void fillFrameBuffersCombo() {
const QVector<KPluginMetaData> plugins = KPluginMetaData::findPlugins(QStringLiteral("krfb/framebuffer"));
QSet<QString> unique;
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
while (i.hasPrevious()) {
const KPluginMetaData &metadata = i.previous();
if (unique.contains(metadata.pluginId())) continue;
for (const KPluginMetaData &metadata : plugins) {
cb_preferredFrameBufferPlugin->addItem(metadata.pluginId());
unique.insert(metadata.pluginId());
}
}
};
......
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