[Kget] KDE/kdenetwork/kget
Urs Wolfer
uwolfer at kde.org
Sat Jan 5 21:04:32 CET 2008
SVN commit 757749 by uwolfer:
Port the KGet plugin system to the KDE standard one.
TransferFactories need now a constructor like this:
MyTransferFactory(QObject *parent, const QVariantList &args);
CCMAIL: kget at kde.org
M +9 -31 core/kget.cpp
M +1 -6 core/kget.h
M +3 -1 core/plugin/plugin.cpp
M +6 -2 core/plugin/plugin.h
M +2 -1 core/plugin/transferfactory.cpp
M +2 -1 core/plugin/transferfactory.h
M +2 -4 kget_export.h
M +2 -1 transfer-plugins/bittorrent/bttransferfactory.cpp
M +2 -2 transfer-plugins/bittorrent/bttransferfactory.h
M +2 -1 transfer-plugins/kio/transferKioFactory.cpp
M +2 -1 transfer-plugins/kio/transferKioFactory.h
M +2 -1 transfer-plugins/metalink/metalinkfactory.cpp
M +2 -1 transfer-plugins/metalink/metalinkfactory.h
M +2 -1 transfer-plugins/multisegmentkio/transfermultisegkiofactory.cpp
M +2 -1 transfer-plugins/multisegmentkio/transfermultisegkiofactory.h
--- trunk/KDE/kdenetwork/kget/core/kget.cpp #757748:757749
@@ -2,6 +2,7 @@
Copyright (C) 2005 Dario Massarin <nekkar at libero.it>
Copyright (C) 2007 Lukas Appelhans <l.appelhans at gmx.de>
+ Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
@@ -562,7 +563,6 @@
TransferTreeModel * KGet::m_transferTreeModel;
TransferTreeSelectionModel * KGet::m_selectionModel;
QList<TransferFactory *> KGet::m_transferFactories;
-QList<KLibrary *> KGet::m_pluginKLibraries;
Scheduler * KGet::m_scheduler = new Scheduler();
MainWindow * KGet::m_mainWindow = 0;
KUiServerJobs * KGet::m_jobManager = new KUiServerJobs();
@@ -582,8 +582,7 @@
KGet::~KGet()
{
- unloadPlugins();
- delete(m_scheduler);
+ delete m_scheduler;
}
void KGet::createTransfer(const KUrl &src, const KUrl &dest, const QString& groupName,
@@ -885,42 +884,21 @@
kDebug(5001) << "Number of factories = " << m_transferFactories.size();
}
-void KGet::unloadPlugins()
+KGetPlugin * KGet::createPluginFromService( const KService::Ptr &service )
{
- QList<KLibrary *>::iterator it = m_pluginKLibraries.begin();
- QList<KLibrary *>::iterator itEnd = m_pluginKLibraries.end();
-
- for(;it!=itEnd;++it)
- {
- (*it)->unload();
- }
- m_transferFactories.clear();
-}
-
-KGetPlugin * KGet::createPluginFromService( const KService::Ptr service )
-{
//try to load the specified library
- KLibrary *lib = new KLibrary(QFile::encodeName(service->library()));
+ KPluginFactory *factory = KPluginLoader(service->library()).factory();
- if (!lib)
+ if (!factory)
{
- KMessageBox::error(0, i18n("<html><p>KLibLoader could not load the plugin:<br/><i>%1</i></p></html>",
+ KMessageBox::error(0, i18n("<html><p>KPluginFactory could not load the plugin:<br/><i>%1</i></p></html>",
service->library()));
- kError(5001) << "KLibLoader could not load the plugin:" << service->library();
+ kError(5001) << "KPluginFactory could not load the plugin:" << service->library();
return 0;
}
+ KGetPlugin * plugin = factory->create< TransferFactory >(0);
- KGetPlugin* (*create_plugin)() = ( KGetPlugin* (*)() ) lib->resolveFunction( "create_plugin" );
-
- if ( !create_plugin )
- {
- kDebug(5001) << "create_plugin == NULL";
- return 0;
- }
-
- m_pluginKLibraries.append(lib);
-
- return create_plugin();
+ return plugin;
}
bool KGet::safeDeleteFile( const KUrl& url )
--- trunk/KDE/kdenetwork/kget/core/kget.h #757748:757749
@@ -29,8 +29,6 @@
class QDomElement;
class QAbstractItemView;
-class KLibrary;
-
class Transfer;
class TransferGroup;
class TransferHandler;
@@ -299,7 +297,7 @@
//Plugin-related functions
static void loadPlugins();
static void unloadPlugins();
- static KGetPlugin * createPluginFromService( const KService::Ptr service );
+ static KGetPlugin * createPluginFromService( const KService::Ptr &service );
/**
@@ -322,9 +320,6 @@
//Lists of available plugins
static QList<TransferFactory *> m_transferFactories;
- //List of KLibrary objects (used to release the plugins from memory)
- static QList<KLibrary *> m_pluginKLibraries;
-
//pointer to the Main window
static MainWindow * m_mainWindow;
--- trunk/KDE/kdenetwork/kget/core/plugin/plugin.cpp #757748:757749
@@ -13,9 +13,11 @@
#include <kdebug.h>
-KGetPlugin::KGetPlugin()
+KGetPlugin::KGetPlugin(QObject *parent, const QVariantList &args)
+ : QObject(parent)
{
kDebug(5001) ;
+ Q_UNUSED(args);
}
KGetPlugin::~KGetPlugin()
--- trunk/KDE/kdenetwork/kget/core/plugin/plugin.h #757748:757749
@@ -45,6 +45,9 @@
#include "kget_export.h"
+#include <QObject>
+#include <QVariantList>
+
/**
* Bump this number whenever the plugin framework gets
* incompatible with older versions
@@ -55,10 +58,11 @@
* @short Base class for kget plugins.
* ...
*/
-class KGET_EXPORT KGetPlugin
+class KGET_EXPORT KGetPlugin : public QObject
{
+ Q_OBJECT
public:
- KGetPlugin();
+ KGetPlugin(QObject *parent, const QVariantList &args);
virtual ~KGetPlugin();
/*
--- trunk/KDE/kdenetwork/kget/core/plugin/transferfactory.cpp #757748:757749
@@ -16,7 +16,8 @@
#include <klocale.h>
#include <kdebug.h>
-TransferFactory::TransferFactory()
+TransferFactory::TransferFactory(QObject *parent, const QVariantList &args)
+ : KGetPlugin(parent, args)
{
}
--- trunk/KDE/kdenetwork/kget/core/plugin/transferfactory.h #757748:757749
@@ -48,8 +48,9 @@
*/
class KGET_EXPORT TransferFactory : public KGetPlugin
{
+ Q_OBJECT
public:
- TransferFactory();
+ TransferFactory(QObject *parent, const QVariantList &args);
virtual Transfer * createTransfer( const KUrl &srcUrl, const KUrl &destUrl,
TransferGroup * parent,
--- trunk/KDE/kdenetwork/kget/kget_export.h #757748:757749
@@ -31,9 +31,7 @@
* }
*/
#define KGET_EXPORT_PLUGIN( classname ) \
- extern "C" { \
- KDE_EXPORT KGetPlugin * create_plugin() { return new classname; } \
- }
+ K_PLUGIN_FACTORY( classname ## Factory, registerPlugin< classname >(); ) \
+ K_EXPORT_PLUGIN( classname ## Factory() )
-
#endif
--- trunk/KDE/kdenetwork/kget/transfer-plugins/bittorrent/bttransferfactory.cpp #757748:757749
@@ -20,7 +20,8 @@
KGET_EXPORT_PLUGIN(BTTransferFactory)
-BTTransferFactory::BTTransferFactory()
+BTTransferFactory::BTTransferFactory(QObject *parent, const QVariantList &args)
+ : TransferFactory(parent, args)
{
}
--- trunk/KDE/kdenetwork/kget/transfer-plugins/bittorrent/bttransferfactory.h #757748:757749
@@ -14,11 +14,11 @@
#include "core/plugin/transferfactory.h"
#include "btsettingswidget.h"
-class BTTransferFactory : public QObject, public TransferFactory
+class BTTransferFactory : public TransferFactory
{
Q_OBJECT
public:
- BTTransferFactory();
+ BTTransferFactory(QObject *parent, const QVariantList &args);
~BTTransferFactory();
Transfer * createTransfer(const KUrl &srcUrl, const KUrl &destUrl, TransferGroup * parent, Scheduler * scheduler, const QDomElement * e = 0);
--- trunk/KDE/kdenetwork/kget/transfer-plugins/kio/transferKioFactory.cpp #757748:757749
@@ -18,7 +18,8 @@
KGET_EXPORT_PLUGIN( TransferKioFactory )
-TransferKioFactory::TransferKioFactory()
+TransferKioFactory::TransferKioFactory(QObject *parent, const QVariantList &args)
+ : TransferFactory(parent, args)
{
}
--- trunk/KDE/kdenetwork/kget/transfer-plugins/kio/transferKioFactory.h #757748:757749
@@ -19,8 +19,9 @@
class TransferKioFactory : public TransferFactory
{
+ Q_OBJECT
public:
- TransferKioFactory();
+ TransferKioFactory(QObject *parent, const QVariantList &args);
~TransferKioFactory();
Transfer * createTransfer( const KUrl &srcUrl, const KUrl &destUrl,
--- trunk/KDE/kdenetwork/kget/transfer-plugins/metalink/metalinkfactory.cpp #757748:757749
@@ -19,7 +19,8 @@
KGET_EXPORT_PLUGIN( metalinkFactory )
-metalinkFactory::metalinkFactory()
+metalinkFactory::metalinkFactory(QObject *parent, const QVariantList &args)
+ : TransferFactory(parent, args)
{
}
--- trunk/KDE/kdenetwork/kget/transfer-plugins/metalink/metalinkfactory.h #757748:757749
@@ -19,8 +19,9 @@
class metalinkFactory : public TransferFactory
{
+ Q_OBJECT
public:
- metalinkFactory();
+ metalinkFactory(QObject *parent, const QVariantList &args);
~metalinkFactory();
Transfer * createTransfer( const KUrl &srcUrl, const KUrl &destUrl,
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/transfermultisegkiofactory.cpp #757748:757749
@@ -21,7 +21,8 @@
KGET_EXPORT_PLUGIN( TransferMultiSegKioFactory )
-TransferMultiSegKioFactory::TransferMultiSegKioFactory()
+TransferMultiSegKioFactory::TransferMultiSegKioFactory(QObject *parent, const QVariantList &args)
+ : TransferFactory(parent, args)
{
}
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/transfermultisegkiofactory.h #757748:757749
@@ -19,8 +19,9 @@
class TransferMultiSegKioFactory : public TransferFactory
{
+ Q_OBJECT
public:
- TransferMultiSegKioFactory();
+ TransferMultiSegKioFactory(QObject *parent, const QVariantList &args);
~TransferMultiSegKioFactory();
Transfer * createTransfer( const KUrl &srcUrl, const KUrl &destUrl,
More information about the Kget
mailing list