|
|
|
@ -26,7 +26,7 @@
|
|
|
|
|
#include <QObjectCleanupHandler>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
Q_GLOBAL_STATIC(QObjectCleanupHandler, factorycleanup)
|
|
|
|
|
Q_GLOBAL_STATIC( QObjectCleanupHandler, factorycleanup )
|
|
|
|
|
|
|
|
|
|
extern int kLibraryDebugArea();
|
|
|
|
|
|
|
|
|
@ -34,89 +34,96 @@ namespace Calamares
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
PluginFactory::PluginFactory()
|
|
|
|
|
: d_ptr_p(new PluginFactoryPrivate)
|
|
|
|
|
: d_ptr( new PluginFactoryPrivate )
|
|
|
|
|
{
|
|
|
|
|
Q_D(PluginFactory);
|
|
|
|
|
Q_D( PluginFactory );
|
|
|
|
|
d->q_ptr = this;
|
|
|
|
|
|
|
|
|
|
factorycleanup()->add(this);
|
|
|
|
|
factorycleanup()->add( this );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PluginFactory::PluginFactory(PluginFactoryPrivate &d)
|
|
|
|
|
: d_ptr_p(&d)
|
|
|
|
|
PluginFactory::PluginFactory( PluginFactoryPrivate& d )
|
|
|
|
|
: d_ptr( &d )
|
|
|
|
|
{
|
|
|
|
|
factorycleanup()->add(this);
|
|
|
|
|
factorycleanup()->add( this );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PluginFactory::~PluginFactory()
|
|
|
|
|
{
|
|
|
|
|
delete d_ptr_p;
|
|
|
|
|
delete d_ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PluginFactory::doRegisterPlugin(const QString &keyword, const QMetaObject *metaObject, CreateInstanceFunction instanceFunction)
|
|
|
|
|
void PluginFactory::doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction )
|
|
|
|
|
{
|
|
|
|
|
Q_D(PluginFactory);
|
|
|
|
|
Q_D( PluginFactory );
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(metaObject);
|
|
|
|
|
Q_ASSERT( metaObject );
|
|
|
|
|
|
|
|
|
|
// we allow different interfaces to be registered without keyword
|
|
|
|
|
if (!keyword.isEmpty()) {
|
|
|
|
|
if (d->createInstanceHash.contains(keyword)) {
|
|
|
|
|
if ( !keyword.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
if ( d->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));
|
|
|
|
|
} else {
|
|
|
|
|
const QList<PluginFactoryPrivate::Plugin> clashes(d->createInstanceHash.values(keyword));
|
|
|
|
|
const QMetaObject *superClass = metaObject->superClass();
|
|
|
|
|
if (superClass) {
|
|
|
|
|
for (const PluginFactoryPrivate::Plugin &plugin : clashes) {
|
|
|
|
|
for (const QMetaObject *otherSuper = plugin.first->superClass(); otherSuper;
|
|
|
|
|
otherSuper = otherSuper->superClass()) {
|
|
|
|
|
if (superClass == otherSuper) {
|
|
|
|
|
d->createInstanceHash.insert( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const QList<PluginFactoryPrivate::Plugin> clashes( d->createInstanceHash.values( keyword ) );
|
|
|
|
|
const QMetaObject* superClass = metaObject->superClass();
|
|
|
|
|
if ( superClass )
|
|
|
|
|
{
|
|
|
|
|
for ( const PluginFactoryPrivate::Plugin& plugin : clashes )
|
|
|
|
|
{
|
|
|
|
|
for ( const QMetaObject* otherSuper = plugin.first->superClass(); otherSuper;
|
|
|
|
|
otherSuper = otherSuper->superClass() )
|
|
|
|
|
{
|
|
|
|
|
if ( superClass == otherSuper )
|
|
|
|
|
qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const PluginFactoryPrivate::Plugin &plugin : clashes) {
|
|
|
|
|
for ( const PluginFactoryPrivate::Plugin& plugin : clashes )
|
|
|
|
|
{
|
|
|
|
|
superClass = plugin.first->superClass();
|
|
|
|
|
if (superClass) {
|
|
|
|
|
for (const QMetaObject *otherSuper = metaObject->superClass(); otherSuper;
|
|
|
|
|
otherSuper = otherSuper->superClass()) {
|
|
|
|
|
if (superClass == otherSuper) {
|
|
|
|
|
if ( superClass )
|
|
|
|
|
{
|
|
|
|
|
for ( const QMetaObject* otherSuper = metaObject->superClass(); otherSuper;
|
|
|
|
|
otherSuper = otherSuper->superClass() )
|
|
|
|
|
{
|
|
|
|
|
if ( superClass == otherSuper )
|
|
|
|
|
qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->createInstanceHash.insertMulti(keyword, PluginFactoryPrivate::Plugin(metaObject, instanceFunction));
|
|
|
|
|
d->createInstanceHash.insertMulti( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QObject *PluginFactory::create(const char *iface, QWidget *parentWidget, QObject *parent, const QString &keyword)
|
|
|
|
|
QObject* PluginFactory::create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword )
|
|
|
|
|
{
|
|
|
|
|
Q_D(PluginFactory);
|
|
|
|
|
Q_D( PluginFactory );
|
|
|
|
|
|
|
|
|
|
QObject *obj( nullptr );
|
|
|
|
|
QObject* obj = 0;
|
|
|
|
|
|
|
|
|
|
const QList<PluginFactoryPrivate::Plugin> candidates(d->createInstanceHash.values(keyword));
|
|
|
|
|
const QList<PluginFactoryPrivate::Plugin> candidates( d->createInstanceHash.values( keyword ) );
|
|
|
|
|
// for !keyword.isEmpty() candidates.count() is 0 or 1
|
|
|
|
|
|
|
|
|
|
for (const PluginFactoryPrivate::Plugin &plugin : candidates) {
|
|
|
|
|
for (const QMetaObject *current = plugin.first; current; current = current->superClass()) {
|
|
|
|
|
if (0 == qstrcmp(iface, current->className())) {
|
|
|
|
|
if (obj) {
|
|
|
|
|
for ( const PluginFactoryPrivate::Plugin& plugin : candidates )
|
|
|
|
|
{
|
|
|
|
|
for ( const QMetaObject* current = plugin.first; current; current = current->superClass() )
|
|
|
|
|
{
|
|
|
|
|
if ( 0 == qstrcmp( iface, current->className() ) )
|
|
|
|
|
{
|
|
|
|
|
if ( obj )
|
|
|
|
|
qWarning() << "ambiguous interface requested from a DSO containing more than one plugin";
|
|
|
|
|
}
|
|
|
|
|
obj = plugin.second(parentWidget, parent);
|
|
|
|
|
obj = plugin.second( parentWidget, parent );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj) {
|
|
|
|
|
emit objectCreated(obj);
|
|
|
|
|
}
|
|
|
|
|
if ( obj )
|
|
|
|
|
emit objectCreated( obj );
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|