[Kst] branches/work/kst/pluginify/kst/src
Adam Treat
treat at kde.org
Tue Sep 5 19:52:29 CEST 2006
SVN commit 581213 by treat:
Add testplugin which inherits KstDataObject. Doesn't do
anything interesting at the moment.
M +1 -1 kst/Makefile.am
A kst/kstdataobjectplugin.desktop
M +1 -0 libkst/Makefile.am
A libkst/kstdataplugin.h [License: GPL (v2+)]
M +1 -214 libkst/kstdatasource.cpp
M +1 -1 libkstmath/kstdataobject.cpp
M +4 -1 libkstmath/kstdataobject.h
M +51 -2 libkstmath/plugincollection.cpp
M +2 -0 libkstmath/plugincollection.h
M +1 -1 plugins/Makefile.am
M +1 -1 plugins/crossspectrum/Makefile.am
A plugins/testplugin (directory)
A plugins/testplugin/Makefile.am
A plugins/testplugin/kstobject_testplugin.desktop
A plugins/testplugin/testplugin.cpp [License: GPL (v2+)]
A plugins/testplugin/testplugin.h [License: GPL (v2+)]
A plugins/testplugin/testplugin.xml
--- branches/work/kst/pluginify/kst/src/kst/Makefile.am #581212:581213
@@ -11,7 +11,7 @@
KDE_ICON = kst
-services_DATA = kstplugin.desktop kstdatasourceplugin.desktop kstfilter.desktop kstextension.desktop
+services_DATA = kstplugin.desktop kstdatasourceplugin.desktop kstdataobjectplugin.desktop kstfilter.desktop kstextension.desktop
servicesdir = $(kde_servicetypesdir)/kst
apps_DATA = kst.desktop
--- branches/work/kst/pluginify/kst/src/libkst/Makefile.am #581212:581213
@@ -61,3 +61,4 @@
if (diff -N kstrevision.h.tmp kstrevision.h >/dev/null 2>&1); \
then rm kstrevision.h.tmp; else mv kstrevision.h.tmp kstrevision.h; fi
+noinst_HEADERS = kstdataplugin.h
--- branches/work/kst/pluginify/kst/src/libkst/kstdatasource.cpp #581212:581213
@@ -35,221 +35,8 @@
#include "kstscalar.h"
#include "stdinsource.h"
+#include "kstdataplugin.h"
-// Eventually this will move to another file but I leave it here until then
-// to avoid confusion between the function plugins and Kst applicaton plugins.
-namespace KST {
- class Plugin : public KstShared {
- public:
- Plugin(KService::Ptr svc) : KstShared(), service(svc), _lib(0L) {
- assert(service);
- _plugLib = service->property("X-Kst-Plugin-Library").toString();
- //kstdDebug() << "Create plugin " << (void*)this << " " << service->property("Name").toString() << endl;
- }
-
- virtual ~Plugin() {
- //kstdDebug() << "Destroy plugin " << (void*)this << " " << service->property("Name").toString() << endl;
- if (_lib) {
- _lib->unload();
- }
- }
-
- KstDataSource *create(KConfig *cfg, const QString& filename, const QString& type = QString::null) const {
- KstDataSource *(*sym)(KConfig*, const QString&, const QString&) = (KstDataSource*(*)(KConfig*, const QString&, const QString&))symbol("create");
- if (sym) {
- //kstdDebug() << "Trying to create " << filename << " type=" << type << " with " << service->property("Name").toString() << endl;
- KstDataSource *ds = (sym)(cfg, filename, type);
- if (ds) {
- ds->_source = service->property("Name").toString();
- }
- //kstdDebug() << (ds ? "SUCCESS" : "FAILED") << endl;
- return ds;
- }
-
- return 0L;
- }
-
- KstDataSource *create(KConfig *cfg, const QString& filename, const QString& type, const QDomElement& e) const {
- KstDataSource *(*sym)(KConfig*, const QString&, const QString&, const QDomElement&) = (KstDataSource*(*)(KConfig*, const QString&, const QString&, const QDomElement&))symbol("load");
- if (sym) {
- //kstdDebug() << "Trying to create " << filename << " type=" << type << " with " << service->property("Name").toString() << endl;
- KstDataSource *ds = (sym)(cfg, filename, type, e);
- if (ds) {
- ds->_source = service->property("Name").toString();
- }
- //kstdDebug() << (ds ? "SUCCESS" : "FAILED") << endl;
- return ds;
- } else {
- KstDataSource *(*sym)(KConfig*, const QString&, const QString&) = (KstDataSource*(*)(KConfig*, const QString&, const QString&))symbol("create");
- if (sym) {
- KstDataSource *ds = (sym)(cfg, filename, type);
- if (ds) {
- ds->_source = service->property("Name").toString();
- }
- return ds;
- }
- }
-
- return 0L;
- }
-
- QStringList matrixList(KConfig *cfg, const QString& filename, const QString& type = QString::null, QString *typeSuggestion = 0L, bool *complete = 0L) const {
-
- QStringList (*sym)(KConfig*, const QString&, const QString&, QString*, bool*) = (QStringList(*)(KConfig*, const QString&, const QString&, QString*, bool*))symbol("matrixList");
- if (sym) {
- return (sym)(cfg, filename, type, typeSuggestion, complete);
- }
- // fallback incase the helper isn't implemented
- // (note: less efficient now)
- KstDataSourcePtr ds = create(cfg, filename, type);
- if (ds) {
- QStringList rc = ds->matrixList();
- if (typeSuggestion) {
- *typeSuggestion = ds->fileType();
- }
- if (complete) {
- *complete = ds->fieldListIsComplete();
- }
- return rc;
- }
- return QStringList();
- }
-
- QStringList fieldList(KConfig *cfg, const QString& filename, const QString& type = QString::null, QString *typeSuggestion = 0L, bool *complete = 0L) const {
- QStringList (*sym)(KConfig*, const QString&, const QString&, QString*, bool*) = (QStringList(*)(KConfig*, const QString&, const QString&, QString*, bool*))symbol("fieldList");
- if (sym) {
- return (sym)(cfg, filename, type, typeSuggestion, complete);
- }
-
- // fallback incase the helper isn't implemented
- // (note: less efficient now)
- KstDataSourcePtr ds = create(cfg, filename, type);
- if (ds) {
- QStringList rc = ds->fieldList();
- if (typeSuggestion) {
- *typeSuggestion = ds->fileType();
- }
- if (complete) {
- *complete = ds->fieldListIsComplete();
- }
- return rc;
- }
-
- return QStringList();
- }
-
- int understands(KConfig *cfg, const QString& filename) const {
- int (*sym)(KConfig*, const QString&) = (int(*)(KConfig*, const QString&))symbol("understands");
- if (sym) {
- //kstdDebug() << "Checking if " << service->property("Name").toString() << " understands " << filename << endl;
- int rc = (sym)(cfg, filename);
- //kstdDebug() << "result: " << rc << endl;
- return rc;
- }
-
- return 0;
- }
-
- bool supportsTime(KConfig *cfg, const QString& filename) const {
- bool (*sym)(KConfig*, const QString&) = (bool(*)(KConfig*, const QString&))symbol("supportsTime");
- if (sym) {
- bool rc = (sym)(cfg, filename);
- return rc;
- }
-
- return false;
- }
-
- bool provides(const QString& type) const {
- return provides().contains(type);
- }
-
- QStringList provides() const {
- QStringList (*sym)() = (QStringList(*)())symbol("provides");
- if (sym) {
- //kstdDebug() << "Checking if " << service->property("Name").toString() << " provides " << type << endl;
- return (sym)();
- }
-
- return QStringList();
- }
-
- Q_UINT32 key() const {
- Q_UINT32 (*sym)() = (Q_UINT32(*)())symbol("key");
- if (sym) {
- return (sym)();
- }
-
- return Q_UINT32();
- }
-
- bool hasConfigWidget() const {
- return 0L != symbol("widget");
- }
-
- KstDataSourceConfigWidget *configWidget(KConfig *cfg, const QString& filename) const {
- QWidget *(*sym)(const QString&) = (QWidget *(*)(const QString&))symbol("widget");
- if (sym) {
- QWidget *rc = (sym)(filename);
- KstDataSourceConfigWidget *cw = dynamic_cast<KstDataSourceConfigWidget*>(rc);
- if (cw) {
- cw->setConfig(cfg);
- return cw;
- }
- if (rc) {
- KstDebug::self()->log(i18n("Error in plugin %1: Configuration widget is of the wrong type.").arg(service->property("Name").toString()), KstDebug::Error);
- delete rc;
- }
- }
-
- return 0L;
- }
-
- KService::Ptr service;
-
- private:
- void *symbol(const QString& sym) const {
- if (!loadLibrary()) {
- return 0L;
- }
-
- QCString s = QFile::encodeName(sym + "_" + _plugLib);
- if (_lib->hasSymbol(s)) {
- return _lib->symbol(s);
- }
- return 0L;
- }
-
- bool loadLibrary() const {
- assert(service);
- if (_lib) {
- return true;
- }
-
- QCString libname = QFile::encodeName(QString("kstdata_") + _plugLib);
- _lib = KLibLoader::self()->library(libname);
- if (!_lib) {
- KstDebug::self()->log(i18n("Error loading data-source plugin [%1]: %2").arg(libname).arg(KLibLoader::self()->lastErrorMessage()), KstDebug::Error);
- return false;
- }
-
- if (key() != KST_CURRENT_DATASOURCE_KEY) {
- KstDebug::self()->log(i18n("Error loading data-source plugin [%1]: %2").arg(libname).arg(i18n("Plugin is too old and needs to be recompiled.")), KstDebug::Error);
- return false;
- }
- return true;
- }
-
- QString _plugLib;
- // mutable so we can lazy load the library, but at the same time
- // use const iterators and provide a nice const interface
- mutable KLibrary *_lib;
- };
-
- typedef QValueList<KstSharedPtr<KST::Plugin> > PluginInfoList;
-}
-
-
static KConfig *kConfigObject = 0L;
static QMap<QString,QString> urlMap;
void KstDataSource::setupOnStartup(KConfig *cfg) {
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.cpp #581212:581213
@@ -33,7 +33,7 @@
//#define LOCKTRACE
-KstDataObject::KstDataObject() : KstObject() {
+KstDataObject::KstDataObject(QObject *parent, const char *name, const QStringList &args) : KstObject() {
//kstdDebug() << "+++ CREATING DATA OBJECT: " << (void*)this << endl;
_curveHints = new KstCurveHintList;
}
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.h #581212:581213
@@ -32,11 +32,14 @@
class KST_EXPORT KstDataObject : public KstObject {
Q_OBJECT
public:
- KstDataObject();
+ KstDataObject(QObject *parent=0, const char *name = "", const QStringList &args = QStringList());
KstDataObject(const QDomElement& e);
KstDataObject(const KstDataObject& object);
virtual ~KstDataObject();
+ virtual QString name() const { return QString::null; }
+ virtual QString xmlFile() const { return QString::null; }
+
virtual UpdateType update(int updateCounter = -1) = 0;
virtual const QString& typeString() const { return _typeString; }
virtual QString propertyString() const = 0;
--- branches/work/kst/pluginify/kst/src/libkstmath/plugincollection.cpp #581212:581213
@@ -25,6 +25,15 @@
#include <klocale.h>
#include <kstandarddirs.h>
+
+#include <kdebug.h>
+
+#include <klibloader.h>
+#include <klocale.h>
+#include <kservicetype.h>
+#include <kstdataobject.h>
+#include <kparts/componentfactory.h>
+
#include <qdir.h>
#include <qregexp.h>
@@ -197,12 +206,12 @@
scanPlugins();
}
+void PluginCollection::scanPlugins() {
-void PluginCollection::scanPlugins() {
QMap<QString,QString> backup = _installedPluginNames;
- bool changed = false;
_installedPlugins.clear();
_installedPluginNames.clear();
+ bool changed = scanDataObjectPlugins();
QStringList dirs = KGlobal::dirs()->resourceDirs("kstplugins");
dirs += KGlobal::dirs()->resourceDirs("kstpluginlib");
@@ -258,7 +267,47 @@
}
}
+// Scans for plugins and stores the information for them in "pluginInfo"
+bool PluginCollection::scanDataObjectPlugins() {
+ KstDebug::self()->log(i18n("Scanning for data-object plugins."));
+
+ QMap<QString,QString> backup = _installedPluginNames;
+ bool changed = false;
+
+ 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 ) {
+ int status = _parser->parseFile( object->xmlFile() );
+ if (status == 0) {
+ // dupe? - prefer earlier installations
+ if (_installedPluginNames.contains(_parser->data()._name)) {
+ continue;
+ }
+ _installedPlugins[object->xmlFile()] = _parser->data();
+ _installedPluginNames[_parser->data()._name] = object->xmlFile();
+ if (!backup.contains(_parser->data()._name)) {
+ emit pluginInstalled(_parser->data()._name);
+ changed = true;
+ } else {
+ backup.remove(_parser->data()._name);
+ }
+ } else {
+ KstDebug::self()->log(i18n("Error [%2] parsing XML file '%1'; skipping.").arg(object->xmlFile()).arg(status), KstDebug::Warning);
+ }
+ }
+ else
+ kdDebug() << "FAILURE! " << k_funcinfo << " " << err << endl;
+
+ }
+ return changed; //changed
+}
+
int PluginCollection::deletePlugin(const QString& xmlfile, const QString& object) {
QString pname = _installedPlugins[xmlfile]._name;
QFile::remove(xmlfile);
--- branches/work/kst/pluginify/kst/src/libkstmath/plugincollection.h #581212:581213
@@ -111,6 +111,8 @@
mutable QMap<QString, QString> _installedPluginNames;
void scanPlugins() ;
void loadPluginsFor(const QString& path);
+
+ bool scanDataObjectPlugins();
};
--- branches/work/kst/pluginify/kst/src/plugins/Makefile.am #581212:581213
@@ -20,5 +20,5 @@
CORRELATION_SUBDIR=correlation
endif
-SUBDIRS=bin linefit periodogram phase statistics chop crossspectrum syncbin $(NOISE_SUBDIR) $(FITS_SUBDIR) $(FITSNONLINEAR_SUBDIR) $(INTERPOLATIONS_SUBDIR) $(PASS_FILTERS_SUBDIR) $(CORRELATION_SUBDIR) $(CONVOLUTION_SUBDIR) cumulative_sum differentiation shift
+SUBDIRS=bin linefit periodogram phase statistics chop crossspectrum syncbin testplugin $(NOISE_SUBDIR) $(FITS_SUBDIR) $(FITSNONLINEAR_SUBDIR) $(INTERPOLATIONS_SUBDIR) $(PASS_FILTERS_SUBDIR) $(CORRELATION_SUBDIR) $(CONVOLUTION_SUBDIR) cumulative_sum differentiation shift
--- branches/work/kst/pluginify/kst/src/plugins/crossspectrum/Makefile.am #581212:581213
@@ -1,5 +1,5 @@
installdir=$(kde_moduledir)/kstplugins
-INCLUDES=-I$(srcdir)/../../../kst $(all_includes)
+INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstmath $(all_includes)
install_LTLIBRARIES = crossspectrum.la
More information about the Kst
mailing list