[Kde-bindings] KDE/kdebindings/ruby/plasma

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Apr 17 13:53:46 UTC 2008


SVN commit 798103 by rdale:

* Added a Plasma Data Engine for querying SPARQL endpoints, and returning
  the results passed to setData() as two strings and a Qt::Variant - the 
  source name, a variable name from the query, followed by a Qt::Variant 
  containing a Soprano::Node as the value of the result. 
* The example data engine queries DBPedia for details of the albums for an
  artist given the artists name. 
* So the source might be 'The Velvet Underground', and the results will be
  all the albums they have released with album name, dbpedia resource urn
  for the album, and date released. The album name appears both as the source
  name and an attribute of the source too.
* Enhanced the engineexplorer to work with Qt::Variants containing 
  Soprano::Nodes

CCMAIL: kde-bindings at kde.org


 M  +15 -0     ChangeLog  
 M  +1 -0      examples/dataengines/CMakeLists.txt  
 A             examples/dataengines/dbpedia_albums (directory)  
 A             examples/dataengines/dbpedia_albums/CMakeLists.txt  
 A             examples/dataengines/dbpedia_albums/dbpedia_albums_engine.rb  
 A             examples/dataengines/dbpedia_albums/plasma-dataengine-dbpedia-albums.desktop  
 M  +0 -5      src/kdehandlers.cpp  
 M  +98 -5     src/plasma.cpp  
 M  +12 -1     tools/engineexplorer/engineexplorer.rb  


--- trunk/KDE/kdebindings/ruby/plasma/ChangeLog #798102:798103
@@ -1,3 +1,18 @@
+2008-04-17  Richard Dale  <richard.j.dale at gmail.com>
+
+	* Added a Plasma Data Engine for querying SPARQL endpoints, and returning
+	  the results passed to setData() as two strings and a Qt::Variant - the 
+	  source name, a variable name from the query, followed by a Qt::Variant 
+	  containing a Soprano::Node as the value of the result. 
+	* The example data engine queries DBPedia for details of the albums for an
+	  artist given the artists name. 
+	* So the source might be 'The Velvet Underground', and the results will be
+	  all the albums they have released with album name, dbpedia resource urn
+	  for the album, and date released. The album name appears both as the source
+	  name and an attribute of the source too.
+	* Enhanced the engineexplorer to work with Qt::Variants containing 
+	  Soprano::Nodes
+
 2008-04-14  Richard Dale  <richard.j.dale at gmail.com>
 
 	* Added a Ruby version of the time data engine called 'ruby-time'
--- trunk/KDE/kdebindings/ruby/plasma/examples/dataengines/CMakeLists.txt #798102:798103
@@ -1,2 +1,3 @@
+add_subdirectory(dbpedia_albums)
 add_subdirectory(time)
 
--- trunk/KDE/kdebindings/ruby/plasma/src/kdehandlers.cpp #798102:798103
@@ -48,7 +48,6 @@
 #include <kio/copyjob.h>
 #include <plasma/packagestructure.h>
 #include <plasma/containment.h>
-#include <plasma/widgets/signalplotter.h>
 #include <plasma/searchmatch.h>
 #include <plasma/applet.h>
 #include <plasma/abstractrunner.h>
@@ -659,9 +658,7 @@
 DEF_VALUELIST_MARSHALLER( KUserGroupList, QList<KUserGroup>, KUserGroup )
 DEF_VALUELIST_MARSHALLER( KUrlList, QList<KUrl>, KUrl )
 DEF_VALUELIST_MARSHALLER( KPluginInfoList, QList<KPluginInfo>, KPluginInfo )
-DEF_VALUELIST_MARSHALLER( PlasmaPlotColorList, QList<Plasma::PlotColor>, Plasma::PlotColor )
 
-
 template <class Value, const char *ValueSTR >
 void marshall_Hash(Marshall *m) {
 	switch(m->action()) {
@@ -793,8 +790,6 @@
     { "QList<Plasma::Containment*>&", marshall_PlasmaContainmentList },
     { "QList<Plasma::SearchMatch*>", marshall_PlasmaSearchMatchList },
     { "QList<Plasma::SearchMatch*>&", marshall_PlasmaSearchMatchList },
-    { "QList<Plasma::PlotColor>", marshall_PlasmaPlotColorList },
-    { "QList<Plasma::PlotColor>&", marshall_PlasmaPlotColorList },
     { "QList<Plasma::Applet::List>", marshall_PlasmaAppletList },
     { "QList<Plasma::AbstractRunner::List>", marshall_PlasmaAbstractRunnerList },
     { "KFileItemList", marshall_KFileItemList },
--- trunk/KDE/kdebindings/ruby/plasma/src/plasma.cpp #798102:798103
@@ -19,12 +19,12 @@
 #include <qstringlist.h>
 #include <qmap.h>
 #include <qdatastream.h>
+#include <QtDBus/qdbusmetatype.h>
 
-// #include <kdeversion.h>
-// #include <kapplication.h>
-// #include <kurl.h>
-// #include <kconfigskeleton.h>
-// #include <kio/global.h>
+#include <soprano/node.h>
+#include <soprano/statement.h>
+#include <soprano/bindingset.h>
+
 #include <plasma/applet.h>
 
 #include <ruby.h>
@@ -48,6 +48,94 @@
 static VALUE kde_internal_module;
 Marshall::HandlerFn getMarshallFn(const SmokeType &type);
 
+/* 
+ * These QDBusArgument operators are copied from kdesupport/soprano/server/dbus/dbusoperators.cpp
+ */
+Q_DECLARE_METATYPE(Soprano::Statement)
+Q_DECLARE_METATYPE(Soprano::Node)
+Q_DECLARE_METATYPE(Soprano::BindingSet)
+
+QDBusArgument& operator<<( QDBusArgument& arg, const Soprano::Node& node )
+{
+    arg.beginStructure();
+    arg << ( int )node.type() << node.toString() << node.language() << node.dataType().toString();
+    arg.endStructure();
+    return arg;
+}
+
+const QDBusArgument& operator>>( const QDBusArgument& arg, Soprano::Node& node )
+{
+    arg.beginStructure();
+    int type;
+    QString value, language, dataTypeUri;
+    arg >> type >> value >> language >> dataTypeUri;
+    if ( type == Soprano::Node::LiteralNode ) {
+        node = Soprano::Node( Soprano::LiteralValue::fromString( value, dataTypeUri ), language );
+    }
+    else if ( type == Soprano::Node::ResourceNode ) {
+        node = Soprano::Node( QUrl( value ) );
+    }
+    else if ( type == Soprano::Node::BlankNode ) {
+        node = Soprano::Node( value );
+    }
+    else {
+        node = Soprano::Node();
+    }
+    arg.endStructure();
+    return arg;
+}
+
+QDBusArgument& operator<<( QDBusArgument& arg, const Soprano::Statement& statement )
+{
+    arg.beginStructure();
+    arg << statement.subject() << statement.predicate() << statement.object() << statement.context();
+    arg.endStructure();
+    return arg;
+}
+
+const QDBusArgument& operator>>( const QDBusArgument& arg, Soprano::Statement& statement )
+{
+    arg.beginStructure();
+    Soprano::Node subject, predicate, object, context;
+    arg >> subject >> predicate >> object >> context;
+    statement = Soprano::Statement( subject, predicate, object, context );
+    arg.endStructure();
+    return arg;
+}
+
+QDBusArgument& operator<<( QDBusArgument& arg, const Soprano::BindingSet& set )
+{
+    arg.beginStructure();
+    arg.beginMap( QVariant::String, qMetaTypeId<Soprano::Node>() );
+    QStringList names = set.bindingNames();
+    for ( int i = 0; i < names.count(); ++i ) {
+        arg.beginMapEntry();
+        arg << names[i] << set[ names[i] ];
+        arg.endMapEntry();
+    }
+    arg.endMap();
+    arg.endStructure();
+    return arg;
+}
+
+const QDBusArgument& operator>>( const QDBusArgument& arg, Soprano::BindingSet& set )
+{
+    arg.beginStructure();
+    arg.beginMap();
+    while ( !arg.atEnd() ) {
+        QString name;
+        Soprano::Node val;
+        arg.beginMapEntry();
+        arg >> name >> val;
+        arg.endMapEntry();
+        set.insert( name, val );
+    }
+
+    arg.endMap();
+    arg.endStructure();
+    return arg;
+}
+
 extern "C" {
 extern Q_DECL_EXPORT void Init_plasma_applet();
 extern void Init_qtruby4();
@@ -95,8 +183,13 @@
 	
     kde_internal_module = rb_define_module_under(kde_module, "Internal");
 
+	(void) qDBusRegisterMetaType<Soprano::Statement>();
+	(void) qDBusRegisterMetaType<Soprano::Node>();
+	(void) qDBusRegisterMetaType<Soprano::BindingSet>();
+
 	rb_require("KDE/plasma.rb");
 	rb_require("KDE/korundum4.rb");
+	rb_require("KDE/soprano.rb");
 }
 
 }
--- trunk/KDE/kdebindings/ruby/plasma/tools/engineexplorer/engineexplorer.rb #798102:798103
@@ -196,7 +196,18 @@
       point = value.toPoint
       return "(%d, %d)" % [point.x, point.y]
     else
-      return "<unknown>"
+      if value.typeName == "Soprano::Node"
+        node = qVariantValue(Soprano::Node, value)
+        if node.literal?
+          return node.literal.variant.value.inspect
+        elsif node.resource?
+          return node.uri.toString
+        else
+          return node.inspect
+        end
+      else
+        return "<unknown>"
+      end
     end
   end
 



More information about the Kde-bindings mailing list