/* * * $Id: k3bpluginmanager.cpp 619556 2007-01-03 17:38:12Z trueg $ * Copyright (C) 2003 Sebastian Trueg * * This file is part of the K3b project. * Copyright (C) 1998-2007 Sebastian Trueg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * See the file "COPYING" for the exact licensing terms. */ #include "k3bpluginmanager.h" #include "k3bplugin.h" #include "k3bpluginconfigwidget.h" #include #include #include #include #include #include #include #include #include #include #include #include class K3bPluginManager::Private { public: TQPtrList plugins; }; K3bPluginManager::K3bPluginManager( TQObject* parent, const char* name ) : TQObject( parent, name ) { d = new Private(); } K3bPluginManager::~K3bPluginManager() { delete d; } TQStringList K3bPluginManager::groups() const { TQStringList grps; TQPtrList fl; for( TQPtrListIterator it( d->plugins ); it.current(); ++it ) { if( !grps.contains( it.current()->group() ) ) grps.append( it.current()->group() ); } return grps; } TQPtrList K3bPluginManager::plugins( const TQString& group ) const { TQPtrList fl; for( TQPtrListIterator it( d->plugins ); it.current(); ++it ) { if( it.current()->group() == group || group.isEmpty() ) fl.append( it.current() ); } return fl; } void K3bPluginManager::loadPlugin( const TQString& fileName ) { KSimpleConfig c( fileName, true ); c.setGroup( "K3b Plugin" ); TQString libName = c.readEntry( "Lib" ); if( libName.isEmpty() ) { kdDebug() << "(K3bPluginManager) no Lib specified in " << fileName << endl; return; } // read the lib KLibFactory* factory = KLibLoader::self()->factory( libName.latin1() ); if( factory ) { K3bPlugin* plugin = dynamic_cast( factory->create( this ) ); if( plugin ) { // FIXME: improve this versioning stuff if( plugin->pluginSystemVersion() != K3B_PLUGIN_SYSTEM_VERSION ) { delete plugin; kdDebug() << "(K3bPluginManager) plugin system does not fit lib " << libName << endl; } else { plugin->m_pluginInfo = K3bPluginInfo( libName, c.readEntry( "Name" ), c.readEntry( "Author" ), c.readEntry( "Email" ), c.readEntry( "Comment" ), c.readEntry( "Version" ), c.readEntry( "License" ) ); // make sure to only use the latest version of one plugin bool addPlugin = true; for( TQPtrListIterator it( d->plugins ); *it; ++it ) { if( it.current()->pluginInfo().name() == plugin->pluginInfo().name() ) { if( K3bVersion(it.current()->pluginInfo().version()) < K3bVersion(plugin->pluginInfo().version()) ) { K3bPlugin* p = it.current(); d->plugins.removeRef( p ); delete p; } else { addPlugin = false; } break; } } if( addPlugin ) d->plugins.append( plugin ); else delete plugin; } } else kdDebug() << "(K3bPluginManager) lib " << libName << " not a K3b plugin" << endl; } else kdDebug() << "(K3bPluginManager) lib " << libName << " not found" << endl; } void K3bPluginManager::loadAll() { // we simply search the K3b plugin dir for now TQStringList dirs = KGlobal::dirs()->findDirs( "data", "k3b/plugins/" ); for( TQStringList::const_iterator it = dirs.begin(); it != dirs.end(); ++it ) { TQStringList entries = TQDir(*it).entryList( "*.plugin", TQDir::Files ); for( TQStringList::const_iterator it2 = entries.begin(); it2 != entries.end(); ++it2 ) { loadPlugin( *it + *it2 ); } } } int K3bPluginManager::pluginSystemVersion() const { return K3B_PLUGIN_SYSTEM_VERSION; } int K3bPluginManager::execPluginDialog( K3bPlugin* plugin, TQWidget* parent, const char* name ) { KDialogBase dlg( parent, name, true, i18n("Configure plugin %1").tqarg( plugin->pluginInfo().name() ) ); K3bPluginConfigWidget* configWidget = plugin->createConfigWidget( &dlg ); if( configWidget ) { dlg.setMainWidget( configWidget ); connect( &dlg, TQT_SIGNAL(applyClicked()), configWidget, TQT_SLOT(saveConfig()) ); connect( &dlg, TQT_SIGNAL(okClicked()), configWidget, TQT_SLOT(saveConfig()) ); configWidget->loadConfig(); int r = dlg.exec(); delete configWidget; return r; } else { KMessageBox::sorry( parent, i18n("No settings available for plugin %1.").tqarg( plugin->pluginInfo().name() ) ); return 0; } } #include "k3bpluginmanager.moc"