diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 01:04:17 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 01:04:17 +0000 |
commit | c3b707c026782768bd8c0e6ae6b574fe8a36802d (patch) | |
tree | 5ca6782031b1546c788290cc0b95524369ff01ea /kmyfirewall/core/kmfpluginfactory.cpp | |
download | kmyfirewall-c3b707c026782768bd8c0e6ae6b574fe8a36802d.tar.gz kmyfirewall-c3b707c026782768bd8c0e6ae6b574fe8a36802d.zip |
Added old abandoned KDE3 version of kmyfirewall
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmyfirewall@1091559 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmyfirewall/core/kmfpluginfactory.cpp')
-rw-r--r-- | kmyfirewall/core/kmfpluginfactory.cpp | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/kmyfirewall/core/kmfpluginfactory.cpp b/kmyfirewall/core/kmfpluginfactory.cpp new file mode 100644 index 0000000..089c334 --- /dev/null +++ b/kmyfirewall/core/kmfpluginfactory.cpp @@ -0,0 +1,224 @@ +// +// C++ Implementation: kmfpluginfactory +// +// Description: +// +// +// Author: Christian Hubinger <chubinger@irrsinnig.org>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// License: GPL +// +#include "kmfpluginfactory.h" + +// QT includes +#include <qobject.h> + + +// KDE includes +#include <kparts/part.h> +#include <kparts/plugin.h> +#include <kparts/factory.h> +#include <kmessagebox.h> +#include <kdebug.h> +#include <ktrader.h> +#include <klibloader.h> +#include <klocale.h> +#include <kapplication.h> +// project includes +#include "kmfcompilerinterface.h" +#include "kmfruleoptioneditinterface.h" +#include "kmfruletargetoptioneditinterface.h" +#include "kmfinstallerinterface.h" +#include "kmftarget.h" +#include "kmftargetconfig.h" +#include "kmferror.h" +#include "kmfconfig.h" + +namespace KMF { + +KMFPluginFactory::KMFPluginFactory() {} +KMFPluginFactory::~KMFPluginFactory() {} + + +KParts::ReadWritePart* KMFPluginFactory::KMFMainView( KParts::MainWindow* parent, KMFError* err ) { + err->setErrType( KMFError::OK ); + QString libName; + if ( KMFConfig::useGenericInterface() ) { + kdDebug() << "Loading generic GUI" << endl; + libName = "libkmfgenericinterfacepart"; + } else { + kdDebug() << "Loading iptables GUI" << endl; + libName = "libkmfipteditorpart"; + } + + KLibFactory * factory = KLibLoader::self() ->factory( libName.latin1() ); + if ( factory ) { + KParts::ReadWritePart * m_ruleeditpart = static_cast<KParts::ReadWritePart *>( factory->create( parent, + libName.latin1() , "KParts::ReadWritePart" ) ); + + if ( m_ruleeditpart ) { + return m_ruleeditpart; + } + err->setErrType( KMFError::FATAL ); + err->setErrMsg( i18n( "Could not cast plugin to type: KParts::ReadWritePart." ) ); + return 0; + } else { + err->setErrType( KMFError::FATAL ); + err->setErrMsg( i18n( "Could not find %1 in the library search path." ).arg( libName ) ); + return 0; + } + err->setErrType( KMFError::FATAL ); + err->setErrMsg( i18n( "Could not find libkmfgenericinterfacepart in the library search path." ) ); + return 0; +} + + + + + + + +QValueList<KMFCompilerInterface*>* KMFPluginFactory::CompilersForInstaller( const QString& osName ) { + QValueList<KMFCompilerInterface*> *list = new QValueList<KMFCompilerInterface*>(); + kdDebug() << "Query: KMyFirewall/Compiler [X-KMyFirewall-Platform] == '" << osName.lower() << "'" << endl; + KTrader::OfferList offers = KTrader::self()->query( "KMyFirewall/Compiler", "[X-KMyFirewall-Platform] == '" + osName.lower() + "'"); + KTrader::OfferList::iterator it; + if ( offers.empty() ) { + kdDebug() << "NO MATCHING PLUGIN FOUND - KMyFirewall/Compiler" << endl; + } + for ( it = offers.begin(); it != offers.end(); ++it ) { + KService::Ptr ptr = *it; + KLibFactory *factory = KLibLoader::self()->factory( ptr->library().local8Bit().data() ); + kdDebug() << KLibLoader::self()->lastErrorMessage() << endl; + + if ( !factory ) { + kdDebug() << "Couldn't load plugin: " << ptr->name() << endl; + } + + if ( KMFCompilerInterface *part = dynamic_cast<KMFCompilerInterface*> ( factory->create( 0 , "KMFCompilerInterface") ) ) { + list->append ( part ); + + } + } + return list; +} + +QPtrList<KMFRuleOptionEditInterface>* KMFPluginFactory::KMFRuleOptionEditors( QObject *parent ){ + QPtrList<KMFRuleOptionEditInterface> *list = new QPtrList<KMFRuleOptionEditInterface>; + KTrader::OfferList offers = KTrader::self()->query( "KMyFirewall/RuleOptionEdit"); + kdDebug() << "Query performed" << endl; + + KTrader::OfferList::iterator it; + for ( it = offers.begin(); it != offers.end(); ++it ) { + KService::Ptr ptr = *it; + kdDebug() << "Found KMFRuleOptionEdit Plugin: " << ptr->name() << "\nLibrary: "<< ptr->library().local8Bit().data() <<endl; + KLibFactory *factory = KLibLoader::self()->factory( ptr->library().local8Bit().data() ); + kdDebug() << "KLibLoader::self()->lastErrorMessage() " << KLibLoader::self()->lastErrorMessage() << endl; + if ( !factory ) { + kdDebug() << "Couldn't load plugin: " << ptr->name() << endl; + } + if ( KMFRuleOptionEditInterface *part = dynamic_cast<KMFRuleOptionEditInterface*> ( factory->create( parent , "KMFRuleOptionEditInterface") ) ) { + if ( ! part ) { + KMessageBox::error(0, "Couldn't load plugin"); + } + list->append( part ); + kdDebug() << "Initialiesed Plugin." << endl; + } + } + return list; +} + +QPtrList<KMFRuleTargetOptionEditInterface>* KMFPluginFactory::KMFRuleTargetOptionEditors( QObject *parent ) { + QPtrList<KMFRuleTargetOptionEditInterface> *list = new QPtrList<KMFRuleTargetOptionEditInterface>; + KTrader::OfferList offers = KTrader::self()->query( "KMyFirewall/RuleTargetOptionEdit"); + kdDebug() << "Query performed" << endl; + + KTrader::OfferList::iterator it; + for ( it = offers.begin(); it != offers.end(); ++it ) { + KService::Ptr ptr = *it; + kdDebug() << "Found KMFRuleTargetOptionEdit Plugin: " << ptr->name() << "\nLibrary: "<< ptr->library().local8Bit().data() <<endl; + KLibFactory *factory = KLibLoader::self()->factory( ptr->library().local8Bit().data() ); + kdDebug() << "KLibLoader::self()->lastErrorMessage(): " << KLibLoader::self()->lastErrorMessage() << endl; + if ( !factory ) { + kdDebug() << "Couldn't load plugin: " << ptr->name() << endl; + } + if ( KMFRuleTargetOptionEditInterface *part = dynamic_cast<KMFRuleTargetOptionEditInterface*> ( factory->create( parent , "KMFRuleTargetOptionEditInterface") ) ) { + if ( ! part ) { + KMessageBox::error(0, "Couldn't load plugin"); + } + list->append( part ); + kdDebug() << "Initialiesed Plugin." << endl; + } + } + return list; +} + +KMFInstallerInterface* KMFPluginFactory::KMFInstaller( KMFTarget* target ) { + + KTrader::OfferList offers = KTrader::self()->query( "KMyFirewall/Installer", " [X-KMyFirewall-Platform] == '"+ target->config()->oS().lower() +"'" ); + kdDebug() << "Query performed" << endl; + KService::Ptr ptr = offers.first(); + KTrader::OfferList::iterator it; + if ( offers.empty() ) { + kdDebug() << "NO MATCHING PLUGIN FOUND" << endl; + return 0; + } + kdDebug() << "KMFPluginFactory found Plugin: " << ptr->name() << "\nLibrary: "<< ptr->library().local8Bit().data() <<endl; + KLibFactory *factory = KLibLoader::self()->factory( ptr->library().local8Bit().data() ); + kdDebug() << "KLibLoader::self()->lastErrorMessage(): " << KLibLoader::self()->lastErrorMessage() << endl; + + if ( !factory ) { + kdDebug() << "Couldn't load plugin: " << ptr->name() << endl; + return 0; + } + if ( KMFInstallerInterface *part = dynamic_cast<KMFInstallerInterface*> ( factory->create( KApplication::kApplication() , "KMFInstallerInterface") ) + ) { + if ( ! part ) { + KMessageBox::error(0, "Couldn't load plugin"); + return 0; + } +// kdDebug() << "Returning KMFInstallerInterface" << endl; + return part; + } + kdDebug() << "Returning 0-Pointer" << endl; + return 0; +} + +KMFCompilerInterface* KMFPluginFactory::KMFCompiler( KMFTarget* target ) { + kdDebug() << "KMFCompilerInterface* KMFGenericDoc::compiler()" << endl; + kdDebug() << "Start query" << endl; + KTrader::OfferList offers = KTrader::self()->query( "KMyFirewall/Compiler", "[X-KMyFirewall-Language] == '" + target->config()->backend().lower() +"' and [X-KMyFirewall-Platform] == '" + target->config()->oS().lower() + "'" ); + kdDebug() << "Query performed" << endl; + KService::Ptr ptr = offers.first(); + KTrader::OfferList::iterator it; + if ( offers.empty() ) { + KMessageBox::error(0, i18n("<qt><b>Could not find a matching compiler plugin.</b></qt>") ); + kdDebug() << "NO MATCHING PLUGIN FOUND" << endl; + return 0; + } + kdDebug() << "KMFGenericDoc found Plugin: " << ptr->name() << "\nLibrary: "<< ptr->library().local8Bit().data() <<endl; + KLibFactory *factory = KLibLoader::self()->factory( ptr->library().local8Bit().data() ); + kdDebug() << "KLibLoader::self()->lastErrorMessage(): " << KLibLoader::self()->lastErrorMessage() << endl; + + if ( !factory ) { + KMessageBox::error( 0, i18n("<qt><b>Compiler plugin could not be loaded.</b></qt>") ); + kdDebug() << "Couldn't load plugin: " << ptr->name() << endl; + return 0; + } + + if ( KMFCompilerInterface *part = dynamic_cast<KMFCompilerInterface*> ( factory->create( KApplication::kApplication() , "KMFCompilerInterface" ) ) ) { + kdDebug() << "Returning Compiler Plugin." << endl; + return part; + } + return 0; +} + + +} + + + + + |