Warning, file /education/cantor/src/lib/panelpluginhandler.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2010 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #include "panelpluginhandler.h"
0007 using namespace Cantor;
0008 
0009 #include <QDebug>
0010 #include <QDir>
0011 
0012 #include <KPluginFactory>
0013 #include <KPluginMetaData>
0014 #include <KPluginFactory>
0015 
0016 #include "session.h"
0017 #include "backend.h"
0018 
0019 class Cantor::PanelPluginHandlerPrivate
0020 {
0021   public:
0022     QList<Cantor::PanelPlugin*> plugins;
0023 };
0024 
0025 PanelPluginHandler::PanelPluginHandler( QObject* parent ) : QObject(parent) ,
0026                                                             d(new PanelPluginHandlerPrivate)
0027 {
0028     setObjectName(QStringLiteral("PanelPluginHandler"));
0029 }
0030 
0031 PanelPluginHandler::~PanelPluginHandler()
0032 {
0033     delete d;
0034 }
0035 
0036 void PanelPluginHandler::loadPlugins()
0037 {
0038     const QVector<KPluginMetaData> plugins = KPluginMetaData::findPlugins(QStringLiteral("cantor/panels"));
0039 
0040     for (const KPluginMetaData &plugin : plugins) {
0041 
0042         const auto result = KPluginFactory::instantiatePlugin<PanelPlugin>(plugin, QCoreApplication::instance());
0043 
0044         if (!result) {
0045             qDebug() << "Error while loading panel: " << result.errorText;
0046             continue;
0047         }
0048 
0049         PanelPlugin *panel = result.plugin;
0050 
0051         panel->setPluginInfo(plugin);
0052         d->plugins.append(panel);
0053 
0054     }
0055 }
0056 
0057 QList<Cantor::PanelPlugin *> Cantor::PanelPluginHandler::allPlugins()
0058 {
0059     return d->plugins;
0060 }
0061 
0062 QList<PanelPlugin*> PanelPluginHandler::plugins(Session* session)
0063 {
0064     QList<PanelPlugin*> pluginsForSession;
0065 
0066     if (session == nullptr)
0067         return pluginsForSession;
0068 
0069     const auto capabilities = session->backend()->capabilities();
0070     const QStringList& extensions = session->backend()->extensions();
0071 
0072     qDebug()<<"loading panel plugins for session of type "<<session->backend()->name();
0073     for (auto* plugin : d->plugins)
0074     {
0075         bool supported=true;
0076         for (const QString& req : plugin->requiredExtensions()){
0077             // FIXME: That req.isEmpty() is there just because Help Panel has req
0078             // empty, returning FALSE when the comparison must to return TRUE.
0079             supported = supported && (extensions.contains(req) || req.isEmpty());
0080         }
0081 
0082         supported = supported && ( (capabilities & plugin->requiredCapabilities()) == plugin->requiredCapabilities());
0083 
0084         if(supported)
0085         {
0086             qDebug() << "plugin " << plugin->name()<<" is supported, requires extensions " << plugin->requiredExtensions();
0087             pluginsForSession.append(plugin);
0088         }
0089         else
0090             qDebug() << "plugin " << plugin->name() <<" is not supported";
0091     }
0092 
0093     return pluginsForSession;
0094 }
0095 
0096 QList<PanelPlugin*> PanelPluginHandler::activePluginsForSession(Session* session, const PanelStates& previousPluginStates)
0097 {
0098     const auto& plugins = this->plugins(session);
0099     for (auto* plugin : plugins)
0100     {
0101         if(!plugin)
0102         {
0103             qDebug()<<"somethings wrong with plugin inside PanelPluginHandler";
0104             continue;
0105         }
0106 
0107         if (previousPluginStates.contains(plugin->name()))
0108             plugin->restoreState(previousPluginStates[plugin->name()]);
0109         else
0110         {
0111             Cantor::PanelPlugin::State initState;
0112             initState.session = session;
0113             plugin->restoreState(initState);
0114         }
0115     }
0116     return plugins;
0117 }