[Kst] branches/work/kst/pluginify/kst/src

Adam Treat treat at kde.org
Wed Nov 15 00:26:14 CET 2006


SVN commit 605006 by treat:

* Add a unique key check for basic plugins.
* Refactor kstdataplugin.h so it can be used by non-source
plugins in the future if need be.
* Fix for out of source build.
* Provide a unique desktop file for basic plugins.


 M  +1 -1      kst/Makefile.am  
 M  +151 -41   libkst/kstdataplugin.h  
 M  +19 -13    libkst/kstdatasource.cpp  
 M  +2 -6      libkst/kstdatasource.h  
 M  +12 -0     libkst/kstobject.h  
 M  +1 -1      plugins/crossspectrum/Makefile.am  
 M  +1 -1      plugins/effective_bandwidth/kstobject_effbandwidth.desktop  
 M  +1 -1      plugins/linefit/kstobject_linefit.desktop  
 M  +2 -0      plugins/linefit/linefit.cpp  


--- branches/work/kst/pluginify/kst/src/kst/Makefile.am #605005:605006
@@ -11,7 +11,7 @@
 
 KDE_ICON = kst
 
-services_DATA = kstplugin.desktop kstdatasourceplugin.desktop kstdataobjectplugin.desktop kstfilter.desktop kstextension.desktop
+services_DATA = kstplugin.desktop kstdatasourceplugin.desktop kstdataobjectplugin.desktop kstbasicplugin.desktop kstfilter.desktop kstextension.desktop
 servicesdir = $(kde_servicetypesdir)/kst
 
 apps_DATA = kst.desktop
--- branches/work/kst/pluginify/kst/src/libkst/kstdataplugin.h #605005:605006
@@ -51,6 +51,72 @@
         }
       }
 
+      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");
+      }
+
+      KService::Ptr service;
+
+    protected:
+      void *symbol(const QString& sym) const {
+        if (!loadLibrary()) {
+          return 0L;
+        }
+
+        QString libname = _plugLib;
+        QCString s = QFile::encodeName(sym + "_" + libname.remove(QString("kstobject_")));
+        if (_lib->hasSymbol(s)) {
+          return _lib->symbol(s);
+        }
+        return 0L;
+      }
+
+      bool loadLibrary() const {
+        assert(service);
+        if (_lib) {
+          return true;
+        }
+
+        bool isDataObject = _plugLib.contains(QString("kstobject_"));
+
+        QCString libname = QFile::encodeName((!isDataObject ? QString("kstdata_") : QString()) + _plugLib);
+        _lib = KLibLoader::self()->library(libname);
+        if (!_lib) {
+          KstDebug::self()->log(i18n("Error loading data plugin [%1]: %2").arg(libname).arg(KLibLoader::self()->lastErrorMessage()), KstDebug::Error);
+          return false;
+        }
+
+        if (key() != (isDataObject ? KST_CURRENT_DATAOBJECT_KEY : KST_CURRENT_DATASOURCE_KEY)) {
+          KstDebug::self()->log(i18n("Error loading data plugin [%1]: %2").arg(libname).arg(i18n("Plugin is too old and needs to be recompiled.")), KstDebug::Error);
+          KstDebug::self()->log(i18n("Error loading data plugin key = [%1]: %2").arg(key()).arg(QFile::encodeName("key_" + _plugLib)), 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;
+  };
+
+  class DataSourcePlugin : public Plugin {
+    public:
+      DataSourcePlugin(KService::Ptr svc) : Plugin(svc) {
+      }
+
+      virtual ~DataSourcePlugin() {
+      }
+
       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) {
@@ -89,9 +155,8 @@
 
         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);  
@@ -171,19 +236,6 @@
         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) {
@@ -201,47 +253,105 @@
 
         return 0L;
       }
+  };
 
-      KService::Ptr service;
+#if 0
+  class DataObjectPlugin : public Plugin {
+    public:
+      DataObjectPlugin(KService::Ptr svc) : Plugin(svc) {
+      }
 
-    private:
-      void *symbol(const QString& sym) const {
-        if (!loadLibrary()) {
-          return 0L;
+      virtual ~DataObjectPlugin() {
+      }
+
+      QWidget *configWidget(const QString& name) const {
+        Q_UNUSED(name);
+        return 0L;
+      }
+  };
+
+  class BasicPlugin : public DataObjectPlugin {
+    public:
+      BasicPlugin(KService::Ptr svc) : DataObjectPlugin(svc) {
+      }
+
+      virtual ~BasicPlugin() {
+      }
+
+      QWidget *configWidget(const QString& name) const {
+        Q_UNUSED(name);
+        return 0L;
+      }
+
+      QStringList inputVectorList() const {
+        QStringList (*sym)() = (QStringList(*)())symbol("inputVectorList");
+        if (sym) {
+          return (sym)();
         }
 
-        QCString s = QFile::encodeName(sym + "_" + _plugLib);
-        if (_lib->hasSymbol(s)) {
-          return _lib->symbol(s);
+        return QStringList();
+      }
+
+      QStringList inputScalarList() const {
+        QStringList (*sym)() = (QStringList(*)())symbol("inputScalarList");
+        if (sym) {
+          return (sym)();
         }
-        return 0L;
+
+        return QStringList();
       }
 
-      bool loadLibrary() const {
-        assert(service);
-        if (_lib) {
-          return true;
+      QStringList inputStringList() const {
+        QStringList (*sym)() = (QStringList(*)())symbol("inputStringList");
+        if (sym) {
+          return (sym)();
         }
 
-        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;
+        return QStringList();
+      }
+
+      QStringList outputVectorList() const {
+        QStringList (*sym)() = (QStringList(*)())symbol("outputVectorList");
+        if (sym) {
+          return (sym)();
         }
 
-        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 QStringList();
+      }
+
+      QStringList outputScalarList() const {
+        QStringList (*sym)() = (QStringList(*)())symbol("outputScalarList");
+        if (sym) {
+          return (sym)();
         }
-        return true;
+
+        return QStringList();
       }
 
-      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;
+      QStringList outputStringList() const {
+        QStringList (*sym)() = (QStringList(*)())symbol("outputStringList");
+        if (sym) {
+          return (sym)();
+        }
+
+        return QStringList();
+      }
   };
 
+  class CPlugin : public DataObjectPlugin {
+    public:
+      CPlugin(KService::Ptr svc) : DataObjectPlugin(svc) {
+      }
+
+      virtual ~CPlugin() {
+      }
+
+      QWidget *configWidget(const QString& name) const {
+        Q_UNUSED(name);
+        return 0L;
+      }
+  };
+#endif
+
   typedef QValueList<KstSharedPtr<KST::Plugin> > PluginInfoList;
 }
--- branches/work/kst/pluginify/kst/src/libkst/kstdatasource.cpp #605005:605006
@@ -114,7 +114,7 @@
       }
     }
 
-    KstSharedPtr<KST::Plugin> p = new KST::Plugin(*it);
+    KstSharedPtr<KST::Plugin> p = new KST::DataSourcePlugin(*it);
     tmpList.append(p);
   }
 
@@ -143,7 +143,7 @@
 namespace {
 class PluginSortContainer {
   public:
-    KstSharedPtr<KST::Plugin> plugin;
+    KstSharedPtr<KST::DataSourcePlugin> plugin;
     int match;
     int operator<(const PluginSortContainer& x) const {
       return match > x.match; // yes, this is by design.  biggest go first
@@ -165,21 +165,25 @@
 
   if (!type.isEmpty()) {
     for (KST::PluginInfoList::ConstIterator it = info.begin(); it != info.end(); ++it) {
-      if ((*it)->provides(type)) {
-        PluginSortContainer psc;
-        psc.match = 100;
-        psc.plugin = *it;
-        bestPlugins.append(psc);
-        return bestPlugins;
+      if (KST::DataSourcePlugin *p = kst_cast<KST::DataSourcePlugin>(*it)) {
+        if (p->provides(type)) {
+          PluginSortContainer psc;
+          psc.match = 100;
+          psc.plugin = p;
+          bestPlugins.append(psc);
+          return bestPlugins;
+        }
       }
     }
   }
 
   for (KST::PluginInfoList::ConstIterator it = info.begin(); it != info.end(); ++it) {
     PluginSortContainer psc;
-    if ((psc.match = (*it)->understands(kConfigObject, filename)) > 0) {
-      psc.plugin = *it;
-      bestPlugins.append(psc);
+    if (KST::DataSourcePlugin *p = kst_cast<KST::DataSourcePlugin>(*it)) {
+      if ((psc.match = p->understands(kConfigObject, filename)) > 0) {
+        psc.plugin = p;
+        bestPlugins.append(psc);
+      }
     }
   }
 
@@ -254,8 +258,10 @@
   KST::PluginInfoList info = QDeepCopy<KST::PluginInfoList>(pluginInfo);
 
   for (KST::PluginInfoList::ConstIterator it = info.begin(); it != info.end(); ++it) {
-    if ((*it)->service->property("Name").toString() == plugin) {
-      return (*it)->configWidget(kConfigObject, QString::null);
+    if (KST::DataSourcePlugin *p = kst_cast<KST::DataSourcePlugin>(*it)) {
+      if (p->service->property("Name").toString() == plugin) {
+        return p->configWidget(kConfigObject, QString::null);
+      }
     }
   }
 
--- branches/work/kst/pluginify/kst/src/libkst/kstdatasource.h #605005:605006
@@ -30,12 +30,8 @@
 #include "kstobject.h"
 #include "kst_export.h"
 
-#define KST_CURRENT_DATASOURCE_KEY 0x00000006
-
-#define KST_KEY_DATASOURCE_PLUGIN(x) extern "C" Q_UINT32 key_##x() { return KST_CURRENT_DATASOURCE_KEY; }
-
 namespace KST {
-  class Plugin;
+  class DataSourcePlugin;
 }
 
 struct KstMatrixData {
@@ -216,7 +212,7 @@
     /** The filename.  Populated by the base class constructor.  */
     QString _filename;
 
-    friend class KST::Plugin;
+    friend class KST::DataSourcePlugin;
 
     /** The source type name. */
     QString _source;
--- branches/work/kst/pluginify/kst/src/libkst/kstobject.h #605005:605006
@@ -27,6 +27,18 @@
 #include "kstsharedptr.h"
 #include "rwlock.h"
 
+
+//We define two different keys for datasource VS dataobject plugins
+//so that if the API for one changes, the other doesn't have to be
+//updated also...
+#define KST_CURRENT_DATASOURCE_KEY 0x00000006
+
+#define KST_KEY_DATASOURCE_PLUGIN(x) extern "C" Q_UINT32 key_##x() { return KST_CURRENT_DATASOURCE_KEY; }
+
+#define KST_CURRENT_DATAOBJECT_KEY 0x00000006
+
+#define KST_KEY_DATAOBJECT_PLUGIN(x) extern "C" Q_UINT32 key_##x() { return KST_CURRENT_DATAOBJECT_KEY; }
+
 class KstObjectPrivate;
 
 class KST_EXPORT KstObject : public KstShared, public QObject, public KstRWLock {
--- branches/work/kst/pluginify/kst/src/plugins/crossspectrum/Makefile.am #605005:605006
@@ -1,4 +1,4 @@
-INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/widgets -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstapp  -I$(top_srcdir)/kst/src/libkstmath $(all_includes)
+INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/widgets -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstapp -I$(top_srcdir)/kst/src/libkstmath -I$(top_builddir)/kst -I$(top_builddir)/kst/src/widgets -I$(top_builddir)/kst/src/libkst -I$(top_builddir)/kst/src/libkstapp  -I$(top_builddir)/kst/src/libkstmath $(all_includes)
 
 kde_module_LTLIBRARIES=kstobject_crossspectrum.la
 
--- branches/work/kst/pluginify/kst/src/plugins/effective_bandwidth/kstobject_effbandwidth.desktop #605005:605006
@@ -1,7 +1,7 @@
 [Desktop Entry]
 Encoding=UTF-8
 Type=Service
-ServiceTypes=Kst Data Object
+ServiceTypes=Kst Basic Plugin
 X-KDE-ModuleType=Plugin
 X-KDE-Library=kstobject_effbandwidth
 X-Kst-Plugin-Author=Duncan Hanson
--- branches/work/kst/pluginify/kst/src/plugins/linefit/kstobject_linefit.desktop #605005:605006
@@ -1,7 +1,7 @@
 [Desktop Entry]
 Encoding=UTF-8
 Type=Service
-ServiceTypes=Kst Data Object
+ServiceTypes=Kst Basic Plugin
 X-KDE-ModuleType=Plugin
 X-KDE-Library=kstobject_linefit
 X-Kst-Plugin-Author=George Staikos
--- branches/work/kst/pluginify/kst/src/plugins/linefit/linefit.cpp #605005:605006
@@ -30,6 +30,8 @@
 static const QString& B = KGlobal::staticQString("b");
 static const QString& CHI2 = KGlobal::staticQString("chi^2");
 
+KST_KEY_DATAOBJECT_PLUGIN( linefit )
+
 K_EXPORT_COMPONENT_FACTORY( kstobject_linefit,
     KGenericFactory<LineFit>( "kstobject_linefit" ) )
 


More information about the Kst mailing list