[Kst] branches/work/kst/pluginify/kst/src/libkstmath
Adam Treat
treat at kde.org
Tue Sep 12 17:36:24 CEST 2006
SVN commit 583542 by treat:
* Consolidate the plugin creation a bit.
M +24 -29 kstdataobject.cpp
M +6 -0 kstdataobject.h
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.cpp #583541:583542
@@ -95,8 +95,25 @@
pluginInfo.clear(); //FIXME?
}
+KstDataObjectPtr KstDataObject::createPlugin( KService::Ptr service )
+{
+ int err = 0;
+ KstDataObject *object =
+ KParts::ComponentFactory::createInstanceFromService<KstDataObject>( service, 0, "",
+ QStringList(), &err );
+ if ( object ) {
+ pluginInfo.insert( service->name(), KstDataObjectPtr( object ) );
+ kdDebug() << "SUCCESS! " << service->name() << endl;
+ }
+ else {
+ kdDebug() << "FAILURE! " << k_funcinfo << " " << service->name() << " error=" << err << endl;
+ kdDebug() << "KLibLoader::lastErrorMessage! " << KLibLoader::self()->lastErrorMessage() << endl;
+ }
+ return object;
+}
+
// Scans for plugins and stores the information for them
-static void scanPlugins() {
+void KstDataObject::scanPlugins() {
KstDebug::self()->log(i18n("Scanning for data-object plugins."));
@@ -104,20 +121,9 @@
KService::List sl = KServiceType::offers("Kst Data Object");
for (KService::List::ConstIterator it = sl.begin(); it != sl.end(); ++it) {
- int err = 0;
- KService::Ptr service = ( *it );
- KstDataObject *object =
- KParts::ComponentFactory::createInstanceFromService<KstDataObject>( service, 0, "",
- QStringList(), &err );
- if ( object ) {
- pluginInfo.insert( service->name(), KstDataObjectPtr( object ) );
- kdDebug() << "SUCCESS! " << service->name() << endl;
+ if ( KstDataObjectPtr object = createPlugin( *it ) ) {
+ pluginInfo.insert( ( *it) ->name(), KstDataObjectPtr( object ) );
}
- else
- {
- kdDebug() << "FAILURE! " << k_funcinfo << " " << service->name() << " error=" << err << endl;
- kdDebug() << "KLibLoader::lastErrorMessage! " << KLibLoader::self()->lastErrorMessage() << endl;
- }
}
}
@@ -140,24 +146,13 @@
{
KService::List sl = KServiceType::offers("Kst Data Object");
for (KService::List::ConstIterator it = sl.begin(); it != sl.end(); ++it) {
- int err = 0;
- KService::Ptr service = ( *it );
- if ( service->name() != name )
+ if ( ( *it )->name() != name ) {
continue;
- KstDataObject *object =
- KParts::ComponentFactory::createInstanceFromService<KstDataObject>( service, 0, "",
- QStringList(), &err );
- object->load( e );
- if ( object ) {
- pluginInfo.insert( service->name(), KstDataObjectPtr( object ) );
- kdDebug() << "SUCCESS! " << service->name() << endl;
}
- else
- {
- kdDebug() << "FAILURE! " << k_funcinfo << " " << service->name() << " error=" << err << endl;
- kdDebug() << "KLibLoader::lastErrorMessage! " << KLibLoader::self()->lastErrorMessage() << endl;
+ else if ( KstDataObjectPtr object = createPlugin( *it ) ) {
+ object->load( e );
+ return object;
}
- return object;
}
return 0;
}
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.h #583541:583542
@@ -25,6 +25,8 @@
#include "kstmatrix.h"
#include "kst_export.h"
+#include <kservicetype.h>
+
typedef KstSharedPtr<KstDataObject> KstDataObjectPtr;
typedef KstObjectList<KstDataObjectPtr> KstDataObjectList;
typedef QMap<KstDataObjectPtr, KstDataObjectPtr> KstDataObjectDataObjectMap;
@@ -126,6 +128,10 @@
QValueList<QPair<QString,QString> > _inputStringLoadQueue;
QValueList<QPair<QString,QString> > _inputMatrixLoadQueue;
KstCurveHintList *_curveHints;
+
+ private:
+ static void scanPlugins();
+ static KstDataObjectPtr createPlugin( KService::Ptr );
};
More information about the Kst
mailing list