2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-08-10 18:21:42 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
|
2020-08-10 18:21:42 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
2015-09-09 18:42:44 +02:00
|
|
|
* Based on KPluginFactory from KCoreAddons, KDE project
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2007 Bernhard Loos <nhuh.put@web.de>
|
2015-09-09 18:42:44 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2015-09-09 18:42:44 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2015-09-09 18:42:44 +02:00
|
|
|
*/
|
|
|
|
|
2019-04-29 12:12:18 +02:00
|
|
|
#ifndef UTILS_PLUGINFACTORY_H
|
|
|
|
#define UTILS_PLUGINFACTORY_H
|
2015-09-09 18:42:44 +02:00
|
|
|
|
2019-08-23 17:15:51 +02:00
|
|
|
#include <KPluginFactory>
|
2015-09-09 18:42:44 +02:00
|
|
|
|
|
|
|
#define CalamaresPluginFactory_iid "io.calamares.PluginFactory"
|
|
|
|
|
2019-08-12 15:52:59 +02:00
|
|
|
/** @brief Plugin factory for Calamares
|
|
|
|
*
|
|
|
|
* Try to re-use KPluginFactory as much as possible (since the
|
|
|
|
* old code for PluginFactory was a fork of an old version of
|
|
|
|
* exactly that).
|
|
|
|
*
|
|
|
|
* The current createInstance() method passes more arguments
|
|
|
|
* to the job and viewstep constructors than we want; chasing
|
|
|
|
* that change means modifying each Calamares module. This class
|
|
|
|
* implements a version of createInstance() with fewer arguments
|
|
|
|
* and overloads registerPlugin() to use that.
|
|
|
|
*/
|
|
|
|
class CalamaresPluginFactory : public KPluginFactory
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-08-13 20:50:52 +02:00
|
|
|
explicit CalamaresPluginFactory()
|
|
|
|
: KPluginFactory()
|
|
|
|
{
|
|
|
|
}
|
2019-08-12 15:52:59 +02:00
|
|
|
~CalamaresPluginFactory() override;
|
|
|
|
|
|
|
|
/** @brief Create an object from the factory.
|
|
|
|
*
|
|
|
|
* Ignores all the @p args since they are not used. Calls
|
|
|
|
* Calamares constructors for the Jobs and ViewSteps.
|
|
|
|
*/
|
2019-08-13 20:50:52 +02:00
|
|
|
template < class impl, class ParentType >
|
|
|
|
static QObject* createInstance( QWidget* parentWidget, QObject* parent, const QVariantList& args )
|
2019-08-12 15:52:59 +02:00
|
|
|
{
|
2019-08-20 16:05:22 +02:00
|
|
|
Q_UNUSED( parentWidget )
|
|
|
|
Q_UNUSED( args )
|
2019-08-13 20:50:52 +02:00
|
|
|
ParentType* p = nullptr;
|
|
|
|
if ( parent )
|
|
|
|
{
|
|
|
|
p = qobject_cast< ParentType* >( parent );
|
|
|
|
Q_ASSERT( p );
|
2019-08-12 15:52:59 +02:00
|
|
|
}
|
2019-08-13 20:50:52 +02:00
|
|
|
return new impl( p );
|
2019-08-12 15:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief register a plugin
|
|
|
|
*
|
|
|
|
* The Calamares version doesn't accept keywords, and uses
|
|
|
|
* the Calamares createInstance() version which ignores
|
|
|
|
* the QVariantList of arguments.
|
|
|
|
*/
|
2019-08-13 20:50:52 +02:00
|
|
|
template < class T >
|
2019-08-12 15:52:59 +02:00
|
|
|
void registerPlugin()
|
|
|
|
{
|
2019-08-13 20:50:52 +02:00
|
|
|
KPluginFactory::registerPlugin< T >( QString(), &createInstance< T, QObject > );
|
2019-08-12 15:52:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief declare a Calamares Plugin Factory
|
|
|
|
*
|
|
|
|
* This would be defined as K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY,
|
|
|
|
* except that does not actually use the base factory class that is
|
|
|
|
* passed in.
|
|
|
|
*/
|
2019-08-13 20:50:52 +02:00
|
|
|
#define CALAMARES_PLUGIN_FACTORY_DECLARATION( name ) \
|
2019-08-12 15:52:59 +02:00
|
|
|
class name : public CalamaresPluginFactory \
|
|
|
|
{ \
|
|
|
|
Q_OBJECT \
|
2019-08-13 20:50:52 +02:00
|
|
|
Q_INTERFACES( KPluginFactory ) \
|
|
|
|
Q_PLUGIN_METADATA( IID CalamaresPluginFactory_iid ) \
|
2019-08-12 15:52:59 +02:00
|
|
|
public: \
|
|
|
|
explicit name(); \
|
|
|
|
~name(); \
|
|
|
|
};
|
2019-08-13 20:50:52 +02:00
|
|
|
#define CALAMARES_PLUGIN_FACTORY_DEFINITION( name, pluginRegistrations ) \
|
|
|
|
K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY( name, CalamaresPluginFactory, pluginRegistrations )
|
2019-08-12 15:52:59 +02:00
|
|
|
|
2019-04-29 12:12:18 +02:00
|
|
|
#endif
|