Plugin: cleanup & coding style fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Plugin.h - class plugin, the base-class and generic interface for all plugins
|
||||
*
|
||||
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -72,12 +72,12 @@ public:
|
||||
PluginTypes type;
|
||||
const PixmapLoader * logo;
|
||||
const char * supportedFileTypes;
|
||||
inline bool supportsFileType( const QString & _ext ) const
|
||||
|
||||
inline bool supportsFileType( const QString& extension ) const
|
||||
{
|
||||
return QString( supportedFileTypes ).
|
||||
split( QChar( ',' ) ).
|
||||
contains( _ext );
|
||||
return QString( supportedFileTypes ).split( QChar( ',' ) ).contains( extension );
|
||||
}
|
||||
|
||||
class EXPORT SubPluginFeatures
|
||||
{
|
||||
public:
|
||||
@@ -101,11 +101,10 @@ public:
|
||||
|
||||
inline bool isValid() const
|
||||
{
|
||||
return desc != NULL &&
|
||||
name != QString::null;
|
||||
return desc != NULL && name.isNull() == false;
|
||||
}
|
||||
|
||||
const Plugin::Descriptor * desc;
|
||||
const Plugin::Descriptor* desc;
|
||||
QString name;
|
||||
AttributeMap attributes;
|
||||
} ;
|
||||
@@ -113,8 +112,8 @@ public:
|
||||
typedef QList<Key> KeyList;
|
||||
|
||||
|
||||
SubPluginFeatures( Plugin::PluginTypes _type ) :
|
||||
m_type( _type )
|
||||
SubPluginFeatures( Plugin::PluginTypes type ) :
|
||||
m_type( type )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -126,8 +125,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual void listSubPluginKeys( const Plugin::Descriptor *,
|
||||
KeyList & ) const
|
||||
virtual void listSubPluginKeys( const Plugin::Descriptor *, KeyList & ) const
|
||||
{
|
||||
}
|
||||
|
||||
@@ -144,15 +142,13 @@ public:
|
||||
typedef QList<Descriptor> DescriptorList;
|
||||
|
||||
// contructor of a plugin
|
||||
Plugin( const Descriptor * _descriptor, Model * _parent );
|
||||
Plugin( const Descriptor* descriptor, Model* parent );
|
||||
virtual ~Plugin();
|
||||
|
||||
// returns display-name out of descriptor
|
||||
virtual QString displayName() const
|
||||
{
|
||||
return Model::displayName().isEmpty() ?
|
||||
m_descriptor->displayName :
|
||||
Model::displayName();
|
||||
return Model::displayName().isEmpty() ? m_descriptor->displayName : Model::displayName();
|
||||
}
|
||||
|
||||
// return plugin-type
|
||||
@@ -162,41 +158,40 @@ public:
|
||||
}
|
||||
|
||||
// return plugin-descriptor for further information
|
||||
inline const Descriptor * descriptor() const
|
||||
inline const Descriptor* descriptor() const
|
||||
{
|
||||
return m_descriptor;
|
||||
}
|
||||
|
||||
// can be called if a file matching supportedFileTypes should be
|
||||
// loaded/processed with the help of this plugin
|
||||
virtual void loadFile( const QString & _file );
|
||||
virtual void loadFile( const QString& file );
|
||||
|
||||
// Called if external source needs to change something but we cannot
|
||||
// reference the class header. Should return null if not key not found.
|
||||
virtual AutomatableModel * childModel( const QString & _modelName );
|
||||
virtual AutomatableModel* childModel( const QString& modelName );
|
||||
|
||||
// returns an instance of a plugin whose name matches to given one
|
||||
// if specified plugin couldn't be loaded, it creates a dummy-plugin
|
||||
static Plugin * instantiate( const QString & _plugin_name,
|
||||
Model * _parent, void * _data );
|
||||
static Plugin * instantiate( const QString& pluginName, Model * parent, void * data );
|
||||
|
||||
// fills given list with descriptors of all available plugins
|
||||
static void getDescriptorsOfAvailPlugins( DescriptorList & _plugin_descs );
|
||||
static void getDescriptorsOfAvailPlugins( DescriptorList& pluginDescriptors );
|
||||
|
||||
// create a view for the model
|
||||
PluginView * createView( QWidget * _parent );
|
||||
PluginView * createView( QWidget* parent );
|
||||
|
||||
|
||||
protected:
|
||||
// create a view for the model
|
||||
virtual PluginView * instantiateView( QWidget * ) = 0;
|
||||
virtual PluginView* instantiateView( QWidget* ) = 0;
|
||||
|
||||
|
||||
private:
|
||||
const Descriptor * m_descriptor;
|
||||
const Descriptor* m_descriptor;
|
||||
|
||||
// pointer to instantiation-function in plugin
|
||||
typedef Plugin * ( * instantiationHook )( Model *, void * );
|
||||
typedef Plugin * ( * InstantiationHook )( Model*, void* );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#ifndef SINGLE_SOURCE_COMPILE
|
||||
|
||||
/*
|
||||
* Plugin.cpp - implementation of plugin-class including plugin-loader
|
||||
*
|
||||
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -55,9 +53,9 @@ static Plugin::Descriptor dummy_plugin_descriptor =
|
||||
|
||||
|
||||
|
||||
Plugin::Plugin( const Descriptor * _descriptor, Model * _parent ) :
|
||||
Plugin::Plugin( const Descriptor * _descriptor, Model * parent ) :
|
||||
JournallingObject(),
|
||||
Model( _parent ),
|
||||
Model( parent ),
|
||||
m_descriptor( _descriptor )
|
||||
{
|
||||
if( m_descriptor == NULL )
|
||||
@@ -92,86 +90,80 @@ AutomatableModel * Plugin::childModel( const QString & )
|
||||
|
||||
|
||||
|
||||
Plugin * Plugin::instantiate( const QString & _plugin_name, Model * _parent,
|
||||
void * _data )
|
||||
Plugin * Plugin::instantiate( const QString & pluginName, Model * parent,
|
||||
void * data )
|
||||
{
|
||||
QLibrary plugin_lib( configManager::inst()->pluginDir() +
|
||||
_plugin_name );
|
||||
if( plugin_lib.load() == false )
|
||||
QLibrary pluginLibrary( configManager::inst()->pluginDir() + pluginName );
|
||||
if( pluginLibrary.load() == false )
|
||||
{
|
||||
if( engine::hasGUI() )
|
||||
{
|
||||
QMessageBox::information( NULL,
|
||||
tr( "Plugin not found" ),
|
||||
tr( "The plugin \"%1\" wasn't found "
|
||||
"or could not be loaded!\n"
|
||||
"Reason: \"%2\"" ).arg( _plugin_name ).
|
||||
arg( plugin_lib.errorString() ),
|
||||
QMessageBox::Ok |
|
||||
QMessageBox::Default );
|
||||
tr( "The plugin \"%1\" wasn't found or could not be loaded!\nReason: \"%2\"" ).
|
||||
arg( pluginName ).arg( pluginLibrary.errorString() ),
|
||||
QMessageBox::Ok | QMessageBox::Default );
|
||||
}
|
||||
return new DummyPlugin();
|
||||
}
|
||||
instantiationHook inst_hook = ( instantiationHook ) plugin_lib.resolve(
|
||||
"lmms_plugin_main" );
|
||||
if( inst_hook == NULL )
|
||||
|
||||
InstantiationHook instantiationHook = ( InstantiationHook ) pluginLibrary.resolve( "lmms_plugin_main" );
|
||||
if( instantiationHook == NULL )
|
||||
{
|
||||
if( engine::hasGUI() )
|
||||
{
|
||||
QMessageBox::information( NULL,
|
||||
tr( "Error while loading plugin" ),
|
||||
tr( "Failed to load plugin \"%1\"!"
|
||||
).arg( _plugin_name ),
|
||||
QMessageBox::Ok |
|
||||
QMessageBox::Default );
|
||||
tr( "Failed to load plugin \"%1\"!").arg( pluginName ),
|
||||
QMessageBox::Ok | QMessageBox::Default );
|
||||
}
|
||||
return new DummyPlugin();
|
||||
}
|
||||
Plugin * inst = inst_hook( _parent, _data );
|
||||
|
||||
Plugin * inst = instantiationHook( parent, data );
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Plugin::getDescriptorsOfAvailPlugins( DescriptorList & _plugin_descs )
|
||||
void Plugin::getDescriptorsOfAvailPlugins( DescriptorList& pluginDescriptors )
|
||||
{
|
||||
QDir directory( configManager::inst()->pluginDir() );
|
||||
#ifdef LMMS_BUILD_WIN32
|
||||
QFileInfoList list = directory.entryInfoList(
|
||||
QStringList( "*.dll" ) );
|
||||
QFileInfoList list = directory.entryInfoList( QStringList( "*.dll" ) );
|
||||
#else
|
||||
QFileInfoList list = directory.entryInfoList(
|
||||
QStringList( "lib*.so" ) );
|
||||
QFileInfoList list = directory.entryInfoList( QStringList( "lib*.so" ) );
|
||||
#endif
|
||||
foreach( const QFileInfo & f, list )
|
||||
foreach( const QFileInfo& f, list )
|
||||
{
|
||||
QLibrary( f.absoluteFilePath() ).load();
|
||||
}
|
||||
|
||||
foreach( const QFileInfo & f, list )
|
||||
foreach( const QFileInfo& f, list )
|
||||
{
|
||||
QLibrary plugin_lib( f.absoluteFilePath() );
|
||||
if( plugin_lib.load() == false ||
|
||||
plugin_lib.resolve( "lmms_plugin_main" ) == NULL )
|
||||
QLibrary pluginLibrary( f.absoluteFilePath() );
|
||||
if( pluginLibrary.load() == false ||
|
||||
pluginLibrary.resolve( "lmms_plugin_main" ) == NULL )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QString desc_name = f.baseName() + "_plugin_descriptor";
|
||||
if( desc_name.left( 3 ) == "lib" )
|
||||
|
||||
QString descriptorName = f.baseName() + "_plugin_descriptor";
|
||||
if( descriptorName.left( 3 ) == "lib" )
|
||||
{
|
||||
desc_name = desc_name.mid( 3 );
|
||||
descriptorName = descriptorName.mid( 3 );
|
||||
}
|
||||
Descriptor * plugin_desc =
|
||||
(Descriptor *) plugin_lib.resolve(
|
||||
desc_name.toUtf8().constData() );
|
||||
if( plugin_desc == NULL )
|
||||
|
||||
Descriptor* pluginDescriptor = (Descriptor *) pluginLibrary.resolve( descriptorName.toUtf8().constData() );
|
||||
if( pluginDescriptor == NULL )
|
||||
{
|
||||
qWarning() << tr( "LMMS plugin %1 does not have a plugin descriptor named %2!" ).
|
||||
arg( f.absoluteFilePath() ).arg( desc_name );
|
||||
arg( f.absoluteFilePath() ).arg( descriptorName );
|
||||
continue;
|
||||
}
|
||||
_plugin_descs.push_back( *plugin_desc );
|
||||
|
||||
pluginDescriptors += *pluginDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -179,9 +171,9 @@ void Plugin::getDescriptorsOfAvailPlugins( DescriptorList & _plugin_descs )
|
||||
|
||||
|
||||
|
||||
PluginView * Plugin::createView( QWidget * _parent )
|
||||
PluginView * Plugin::createView( QWidget * parent )
|
||||
{
|
||||
PluginView * pv = instantiateView( _parent );
|
||||
PluginView * pv = instantiateView( parent );
|
||||
if( pv != NULL )
|
||||
{
|
||||
pv->setModel( this );
|
||||
@@ -225,4 +217,3 @@ QDomElement Plugin::Descriptor::SubPluginFeatures::Key::saveXML(
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user