[Kde-imaging] New KIPI plugins category identification based on KAction detection.

Jesper K. Pedersen blackie at blackie.dk
Tue Jun 15 21:41:17 CEST 2004


Why not remove the KIPI::Category KIPI::Plugin::category() const
and only keep
KIPI::Category KIPI::Plugin::category( KAction* action )
In case a plugin has the same category for all its plugins, it will simply 
ignore the action paramter:

KIPI::Category MyPlugin::category( KAction* /*action*/ ) {
  return IMAGEPLUGIN;
}

That makes the host application code much simpler, plus removes the need for 
the KIPI::UNDEFINEDPLUGIN

Or am I missing something?

Cheers
Jesper.

On Tuesday 15 June 2004 19:43, Caulier Gilles wrote:
| Hi all,
|
| In according with Jersper, I have implemented a new plugins category
| detection based on KAction declared in the plugins.
|
| A new method is available for the plugins  implementation :
|
| KIPI::Category KIPI::Plugin::category( KAction* action )
|
| It must be re-implemented in your plugins for to define to the host
| application the category associate with the KAction declared in the
| plugins.
|
| In this case, the standard plugins category detection method :
|
| KIPI::Category KIPI::Plugin::category() const
|
| don't must re-implemented in the plugin. This base method return now a new
| value name UNDEFINEDPLUGIN.
|
| A plugin category detection method based on KAction is very easy to use for
| a best integration of KAction the the host application menus, especialy
| when a plugin have more than one plugin part embeded in the same module,
| like RAWConverter plugin (single and batch).
|
| This plugin return the category value by this fonction :
|
| KIPI::Category Plugin_RawConverter::category( KAction* action )
| {
|     if ( action == singleAction_ )
|        return KIPI::TOOLSPLUGIN;
|     else if ( action == batchAction_ )
|        return KIPI::BATCHPLUGIN;
|     else
|        return KIPI::UNDEFINEDPLUGIN;
| }
|
| Digikam use now this category detection method and the KIPI plugins
| integration is available in digikamapp.cpp :
|
| void DigikamApp::slotKipiPluginPlug()
| {
|     unplugActionList( QString::fromLatin1("file_actions_export") );
|     unplugActionList( QString::fromLatin1("file_actions_import") );
|     unplugActionList( QString::fromLatin1("image_actions") );
|     unplugActionList( QString::fromLatin1("tool_actions") );
|     unplugActionList( QString::fromLatin1("batch_actions") );
|     unplugActionList( QString::fromLatin1("album_actions") );
|
|     m_kipiImageActions.clear();
|     m_kipiFileActionsExport.clear();
|     m_kipiFileActionsImport.clear();
|     m_kipiToolsActions.clear();
|     m_kipiBatchActions.clear();
|     m_kipiAlbumActions.clear();
|
|     KIPI::PluginLoader::PluginList list = KipiPluginLoader_->pluginList();
|
|     for( KIPI::PluginLoader::PluginList::Iterator it = list.begin() ; it !=
| list.end() ; ++it )
|         {
|         KIPI::Plugin* plugin = (*it)->plugin;
|
|         if ( !plugin || !(*it)->shouldLoad )
|             continue;
|
|         plugin->setup( this );
|         QPtrList<KAction>* popup = 0;
|
|         // Plugin category identification using standard method.
|
|         if ( plugin->category() == KIPI::IMAGESPLUGIN )
|             popup = &m_kipiImageActions;
|
|         else if ( plugin->category() == KIPI::EXPORTPLUGIN )
|             popup = &m_kipiFileActionsExport;
|
|         else if ( plugin->category() == KIPI::IMPORTPLUGIN )
|             popup = &m_kipiFileActionsImport;
|
|         else if ( plugin->category() == KIPI::TOOLSPLUGIN )
|             popup = &m_kipiToolsActions;
|
|         else if ( plugin->category() == KIPI::BATCHPLUGIN )
|             popup = &m_kipiBatchActions;
|
|         else if ( plugin->category() == KIPI::COLLECTIONSPLUGIN )
|             popup = &m_kipiAlbumActions;
|
|         else if ( plugin->category() == KIPI::UNDEFINEDPLUGIN )
|             {
|             // Plugin category identification using KAction method based.
|
|             KActionPtrList actions = plugin->actions();
|
|             for( KActionPtrList::Iterator it2 = actions.begin(); it2 !=
| actions.end(); ++it2 )
|                 {
|                 if ( plugin->category(*it2) == KIPI::IMAGESPLUGIN )
|                    popup = &m_kipiImageActions;
|
|                 else if ( plugin->category(*it2) == KIPI::EXPORTPLUGIN )
|                    popup = &m_kipiFileActionsExport;
|
|                 else if ( plugin->category(*it2) == KIPI::IMPORTPLUGIN )
|                    popup = &m_kipiFileActionsImport;
|
|                 else if ( plugin->category(*it2) == KIPI::TOOLSPLUGIN )
|                    popup = &m_kipiToolsActions;
|
|                 else if ( plugin->category(*it2) == KIPI::BATCHPLUGIN )
|                    popup = &m_kipiBatchActions;
|
|                 else if ( plugin->category(*it2) == KIPI::COLLECTIONSPLUGIN
| ) popup = &m_kipiAlbumActions;
|
|                 // Plug the KIPI plugins actions in according with the
| KAction method.
|
|                 if ( popup )
|                    {
|                    popup->append( *it2 );
|                    }
|                 else
|                    {
|                    kdDebug() << "No menu found for a plugin (by KAction
| identification method)!!!" << endl;
|                    }
|                 }
|
|             continue;
|             }
|
|         // Plug the KIPI plugins actions in according with the standard
| method.
|
|         if ( popup )
|             {
|             KActionPtrList actions = plugin->actions();
|
|             for( KActionPtrList::Iterator it3 = actions.begin(); it3 !=
| actions.end(); ++it3 )
|                 {
|                 popup->append( *it3 );
|                 }
|             }
|         else
|             {
|             kdDebug() << "No menu found for a plugin (by standard
| identification method)!!!" << endl;
|             }
|
|         plugin->actionCollection()->readShortcutSettings();
|         }
|
|     // Create GUI menu in according with plugins.
|
|     plugActionList( QString::fromLatin1("file_actions_export"),
| m_kipiFileActionsExport );
|     plugActionList( QString::fromLatin1("file_actions_import"),
| m_kipiFileActionsImport );
|     plugActionList( QString::fromLatin1("image_actions"),
| m_kipiImageActions );
|     plugActionList( QString::fromLatin1("tool_actions"), m_kipiToolsActions
| ); plugActionList( QString::fromLatin1("batch_actions"),
| m_kipiBatchActions );
|     plugActionList( QString::fromLatin1("album_actions"),
| m_kipiAlbumActions );
| }
|
| This implementation work fine and is ready for all future plugins
| implementations. You can use that for Kimdaba, Gwenview, and Showimg
| program.
|
| Let's me hear your remarks and comments (:=)))
|
| regards
|
| Gilles Caulier


More information about the Kde-imaging mailing list