[Kst] kdeextragear-2/kst/kst/extensions/js

George Staikos staikos at kde.org
Tue Mar 29 10:04:53 CEST 2005


CVS commit by staikos: 

data source binding - only able to list and load data sources at this point


  A            bind_datasource.cpp   1.1 [GPL (v2+)]
  A            bind_datasource.h   1.1 [GPL (v2+)]
  M +1 -1      Makefile.am   1.11
  M +42 -0     bind_kst.cpp   1.3
  M +2 -0      bind_kst.h   1.3
  M +2 -0      js.cpp   1.13


--- kdeextragear-2/kst/kst/extensions/js/Makefile.am  #1.10:1.11
@@ -12,5 +12,5 @@
 kstextension_js_la_SOURCES=js.cpp jsiface.skel jsiface_impl.cpp \
                         kstbinding.cpp bind_vector.cpp bind_kst.cpp \
-                        bind_scalar.cpp bind_string.cpp
+                        bind_scalar.cpp bind_string.cpp bind_datasource.cpp
 
 

--- kdeextragear-2/kst/kst/extensions/js/bind_kst.cpp  #1.2:1.3
@@ -17,4 +17,5 @@
 
 #include "bind_kst.h"
+#include "bind_datasource.h"
 #include "bind_scalar.h"
 #include "bind_string.h"
@@ -22,4 +23,5 @@
 
 #include <kstdatacollection.h>
+#include <kstversion.h>
 
 #include <kdebug.h>
@@ -56,8 +58,20 @@ static VBindings Bindings[] = {
   { "scalars", &KstBindKst::scalars },
   { "strings", &KstBindKst::strings },
+  { "dataSources", &KstBindKst::dataSources },
   { 0L, 0L }
 };
 
 
+KJS::Value KstBindKst::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
+  if (propertyName.qstring() == "version") {
+    return KJS::String(KSTVERSION);
+  }
+  if (propertyName.qstring() == "scriptVersion") {
+    return KJS::Number(1);
+  }
+  return KstBinding::get(exec, propertyName);
+}
+
+
 KJS::Value KstBindKst::call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args) {
   int id = this->id();
@@ -171,3 +185,31 @@ KJS::Value KstBindKst::strings(KJS::Exec
 
 
+KJS::Value KstBindKst::dataSources(KJS::ExecState *exec, const KJS::List& args) {
+  if (args.size() == 1 && args[0].type() == KJS::StringType) {
+    KST::dataSourceList.lock().readLock();
+    KstDataSourcePtr sp = *KST::dataSourceList.findTag(args[0].toString(exec).qstring());
+    KST::dataSourceList.lock().readUnlock();
+    if (!sp) {
+      KJS::Object eobj = KJS::Error::create(exec, KJS::RangeError);
+      exec->setException(eobj);
+      return KJS::Undefined();
+    }
+
+    return KJS::Object(new KstBindDataSource(exec, sp));
+  }
+
+  KJS::List rc;
+
+  KST::dataSourceList.lock().readLock();
+  for (KstDataSourceList::Iterator i = KST::dataSourceList.begin(); i != KST::dataSourceList.end(); ++i) {
+    (*i)->readLock();
+    rc.append(KJS::String((*i)->tagName()));
+    (*i)->readUnlock();
+  }
+  KST::dataSourceList.lock().readUnlock();
+
+  return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc));
+}
+
+
 // vim: ts=2 sw=2 et

--- kdeextragear-2/kst/kst/extensions/js/bind_kst.h  #1.2:1.3
@@ -32,8 +32,10 @@ class KstBindKst : public KstBinding {
 
     KJS::Value call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args);
+    KJS::Value get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const;
 
     KJS::Value vectors(KJS::ExecState *exec, const KJS::List& args);
     KJS::Value scalars(KJS::ExecState *exec, const KJS::List& args);
     KJS::Value strings(KJS::ExecState *exec, const KJS::List& args);
+    KJS::Value dataSources(KJS::ExecState *exec, const KJS::List& args);
 
   protected:

--- kdeextragear-2/kst/kst/extensions/js/js.cpp  #1.12:1.13
@@ -35,4 +35,5 @@
 #include <kparts/part.h>
 
+#include "bind_datasource.h"
 #include "bind_kst.h"
 #include "bind_scalar.h"
@@ -88,4 +89,5 @@ void KstJS::createBindings() {
   new KstBindScalar(exec, &globalObj);
   new KstBindString(exec, &globalObj);
+  new KstBindDataSource(exec, &globalObj);
   new KstBindKst(exec, &globalObj);
 }




More information about the Kst mailing list