- Author
- Renchi Raju
This is the class that will help host applications to load plugins.
The host application must create an instance of the plugin loader, and call the method loadPlugins() to get the plugins loaded. To ensure that plugins are correctly removed from menus and toolbars when loaded and unloaded after constructions, the application must connect to either the signals plug() / unplug() or the signal replug(). These signals are emitted when a plugin is to be inserted into the menus.
If your application is using XMLGUI, the easiest way to get the plugins inserted into the menus is by adding an item in the ui.rc file looking list this: <ActionList name="image_actions"/>
Then plugin plugins into menus could be done with code similar to this from KPhotoAlbum:
void slotReplug() {
unplugActionList( QString::fromLatin1("file_actions") );
unplugActionList( QString::fromLatin1("image_actions") );
unplugActionList( QString::fromLatin1("tool_actions") );
QPtrList<KAction> fileActions;
QPtrList<KAction> imageActions;
QPtrList<KAction> toolsActions;
for( KIPI::PluginLoader::PluginList::Iterator it = list.begin(); it != list.end(); ++it ) {
if ( !plugin || !(*it)->shouldLoad )
continue;
QPtrList<KAction>* popup = 0;
popup = &imageActions;
popup = &fileActions;
popup = &toolsActions;
if ( popup ) {
KActionPtrList actions = plugin->
actions();
for( KActionPtrList::Iterator it = actions.begin(); it != actions.end(); ++it ) {
popup->append( *it );
}
}
else {
kdDebug() << "No menu found\n";
}
}
plugActionList( QString::fromLatin1("file_actions"), fileActions );
plugActionList( QString::fromLatin1("image_actions"), imageActions );
plugActionList( QString::fromLatin1("tool_actions"), toolsActions );
}
QValueList< Info * > PluginList
Definition pluginloader.h:81
KActionCollection * actionCollection(QWidget *parent=0)
Definition plugin.cpp:60
virtual void setup(QWidget *widget)=0
Definition plugin.cpp:84
virtual Category category(KAction *action) const =0
KActionPtrList actions(QWidget *parent=0)
Definition plugin.cpp:76
@ IMAGESPLUGIN
Definition plugin.h:49
@ EXPORTPLUGIN
Definition plugin.h:53
@ IMPORTPLUGIN
Definition plugin.h:52
@ TOOLSPLUGIN
Definition plugin.h:51
To configure which plugins should be loaded, simply call PluginLoader::configWidget(), and insert the widget into your normal configuration dialog.