Merge remote-tracking branch 'origin/simplify-plugin'

This commit is contained in:
Adriaan de Groot 2018-01-24 14:22:35 +01:00
commit b828580464
9 changed files with 46 additions and 103 deletions

View File

@ -41,9 +41,6 @@ public:
, m_queue( queue )
, m_jobIndex( 0 )
{
#ifdef WITH_PYTHON
new CalamaresPython::Helper( this );
#endif
}
void setJobs( const JobList& jobs )

View File

@ -231,7 +231,9 @@ Helper::Helper( QObject* parent )
}
Helper::~Helper()
{}
{
s_instance = nullptr;
}
boost::python::dict

View File

@ -48,7 +48,6 @@ class Helper : public QObject
{
Q_OBJECT
public:
explicit Helper( QObject* parent = nullptr );
virtual ~Helper();
boost::python::dict createCleanNamespace();
@ -57,6 +56,7 @@ public:
private:
friend Helper* Calamares::PythonJob::helper();
explicit Helper( QObject* parent = nullptr );
static Helper* s_instance;
boost::python::object m_mainModule;

View File

@ -322,7 +322,7 @@ PythonJob::exec()
}
if ( !m_description.isEmpty() )
{
cDebug() << "Job" << prettyName() << "(func) ->" << m_description;
cDebug() << "Job description from pretty_name" << prettyName() << "=" << m_description;
emit progress( 0 );
}
}
@ -337,7 +337,7 @@ PythonJob::exec()
auto i_newline = m_description.indexOf('\n');
if ( i_newline > 0 )
m_description.truncate( i_newline );
cDebug() << "Job" << prettyName() << "(doc) ->" << m_description;
cDebug() << "Job description from __doc__" << prettyName() << "=" << m_description;
emit progress( 0 );
}
}
@ -381,8 +381,10 @@ PythonJob::emitProgress( qreal progressValue )
CalamaresPython::Helper*
PythonJob::helper()
{
return CalamaresPython::Helper::s_instance;
auto ptr = CalamaresPython::Helper::s_instance;
if (!ptr)
ptr = new CalamaresPython::Helper;
return ptr;
}

View File

@ -29,47 +29,42 @@
Q_GLOBAL_STATIC( QObjectCleanupHandler, factorycleanup )
extern int kLibraryDebugArea();
namespace Calamares
{
PluginFactory::PluginFactory()
: d_ptr( new PluginFactoryPrivate )
: pd_ptr( new PluginFactoryPrivate )
{
Q_D( PluginFactory );
d->q_ptr = this;
pd_ptr->q_ptr = this;
factorycleanup()->add( this );
}
PluginFactory::PluginFactory( PluginFactoryPrivate& d )
: d_ptr( &d )
: pd_ptr( &d )
{
factorycleanup()->add( this );
}
PluginFactory::~PluginFactory()
{
delete d_ptr;
delete pd_ptr;
}
void PluginFactory::doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction )
{
Q_D( PluginFactory );
Q_ASSERT( metaObject );
// we allow different interfaces to be registered without keyword
if ( !keyword.isEmpty() )
{
if ( d->createInstanceHash.contains( keyword ) )
if ( pd_ptr->createInstanceHash.contains( keyword ) )
qWarning() << "A plugin with the keyword" << keyword << "was already registered. A keyword must be unique!";
d->createInstanceHash.insert( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
pd_ptr->createInstanceHash.insert( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
}
else
{
const QList<PluginFactoryPrivate::Plugin> clashes( d->createInstanceHash.values( keyword ) );
const QList<PluginFactoryPrivate::Plugin> clashes( pd_ptr->createInstanceHash.values( keyword ) );
const QMetaObject* superClass = metaObject->superClass();
if ( superClass )
{
@ -96,17 +91,15 @@ void PluginFactory::doRegisterPlugin( const QString& keyword, const QMetaObject*
}
}
}
d->createInstanceHash.insertMulti( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
pd_ptr->createInstanceHash.insertMulti( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
}
}
QObject* PluginFactory::create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword )
{
Q_D( PluginFactory );
QObject* obj = nullptr;
const QList<PluginFactoryPrivate::Plugin> candidates( d->createInstanceHash.values( keyword ) );
const QList<PluginFactoryPrivate::Plugin> candidates( pd_ptr->createInstanceHash.values( keyword ) );
// for !keyword.isEmpty() candidates.count() is 0 or 1
for ( const PluginFactoryPrivate::Plugin& plugin : candidates )

View File

@ -37,71 +37,6 @@ class PluginFactoryPrivate;
#define CalamaresPluginFactory_iid "io.calamares.PluginFactory"
#define CALAMARES_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY_SKEL(name, baseFactory, ...) \
class name : public Calamares::PluginFactory \
{ \
Q_OBJECT \
Q_INTERFACES(Calamares::PluginFactory) \
__VA_ARGS__ \
public: \
explicit name(); \
~name(); \
private: \
void init(); \
};
#define CALAMARES_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, baseFactory) \
CALAMARES_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY_SKEL(name, baseFactory, Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid))
#define CALAMARES_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, baseFactory, pluginRegistrations) \
name::name() \
{ \
pluginRegistrations \
} \
name::~name() {}
#define CALAMARES_PLUGIN_FACTORY_WITH_BASEFACTORY(name, baseFactory, pluginRegistrations) \
CALAMARES_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, baseFactory) \
CALAMARES_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, baseFactory, pluginRegistrations)
#define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) CALAMARES_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, Calamares::PluginFactory)
#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) CALAMARES_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, Calamares::PluginFactory, pluginRegistrations)
/**
* \relates PluginFactory
*
* Create a PluginFactory subclass and export it as the root plugin object.
*
* \param name The name of the PluginFactory derived class.
*
* \param pluginRegistrations Code to be inserted into the constructor of the
* class. Usually a series of registerPlugin() calls.
*
* Example:
* \code
* #include <PluginFactory.h>
* #include <plugininterface.h>
*
* class MyPlugin : public PluginInterface
* {
* public:
* MyPlugin(QObject *parent, const QVariantList &args)
* : PluginInterface(parent)
* {}
* };
*
* CALAMARES_PLUGIN_FACTORY(MyPluginFactory,
* registerPlugin<MyPlugin>();
* )
*
* #include <myplugin.moc>
* \endcode
*
* \see CALAMARES_PLUGIN_FACTORY_DECLARATION
* \see CALAMARES_PLUGIN_FACTORY_DEFINITION
*/
#define CALAMARES_PLUGIN_FACTORY(name, pluginRegistrations) CALAMARES_PLUGIN_FACTORY_WITH_BASEFACTORY(name, Calamares::PluginFactory, pluginRegistrations)
/**
* \relates PluginFactory
*
@ -113,7 +48,18 @@ class PluginFactoryPrivate;
* \see CALAMARES_PLUGIN_FACTORY
* \see CALAMARES_PLUGIN_FACTORY_DEFINITION
*/
#define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) CALAMARES_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, Calamares::PluginFactory)
#define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) \
class name : public Calamares::PluginFactory \
{ \
Q_OBJECT \
Q_INTERFACES(Calamares::PluginFactory) \
Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid) \
public: \
explicit name(); \
~name(); \
private: \
void init(); \
};
/**
* \relates PluginFactory
@ -128,7 +74,12 @@ class PluginFactoryPrivate;
* \see CALAMARES_PLUGIN_FACTORY
* \see CALAMARES_PLUGIN_FACTORY_DECLARATION
*/
#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) CALAMARES_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, Calamares::PluginFactory, pluginRegistrations)
#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \
name::name() \
{ \
pluginRegistrations \
} \
name::~name() {}
namespace Calamares
{
@ -160,13 +111,11 @@ namespace Calamares
* T(QObject *parent, const QVariantList &args)
* \endcode
*
* You should typically use either CALAMARES_PLUGIN_FACTORY() or
* CALAMARES_PLUGIN_FACTORY_WITH_JSON() in your plugin code to create the factory. The
* typical pattern is
* You should typically use CALAMARES_PLUGIN_FACTORY_DEFINITION() in your plugin code to
* create the factory. The pattern is
*
* \code
* #include <PluginFactory.h>
* #include <plugininterface.h>
* #include "utils/PluginFactory.h"
*
* class MyPlugin : public PluginInterface
* {
@ -176,10 +125,9 @@ namespace Calamares
* {}
* };
*
* CALAMARES_PLUGIN_FACTORY(MyPluginFactory,
* CALAMARES_PLUGIN_FACTORY_DEFINITION(MyPluginFactory,
* registerPlugin<MyPlugin>();
* )
* #include <myplugin.moc>
* \endcode
*
* If you want to load a library use KPluginLoader.
@ -200,7 +148,7 @@ namespace Calamares
class DLLEXPORT PluginFactory : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE( PluginFactory )
friend class PluginFactoryPrivate;
public:
/**
* This constructor creates a factory for a plugin.
@ -301,7 +249,7 @@ protected:
doRegisterPlugin( keyword, &T::staticMetaObject, instanceFunction );
}
PluginFactoryPrivate* const d_ptr;
PluginFactoryPrivate* const pd_ptr;
/**
* This function is called when the factory asked to create an Object.

View File

@ -100,6 +100,7 @@ ViewManager::ViewManager( QObject* parent )
ViewManager::~ViewManager()
{
m_widget->deleteLater();
s_instance = nullptr;
}

View File

@ -123,7 +123,7 @@ signals:
private:
explicit ViewManager( QObject* parent = nullptr );
virtual ~ViewManager();
virtual ~ViewManager() override;
void insertViewStep( int before, ViewStep* step );

View File

@ -42,7 +42,7 @@ class ModuleManager : public QObject
Q_OBJECT
public:
explicit ModuleManager( const QStringList& paths, QObject* parent = nullptr );
virtual ~ModuleManager();
virtual ~ModuleManager() override;
static ModuleManager* instance();