how to access data from dataEngine::query in javascript?

Thomas Fjellstrom tfjellstrom at shaw.ca
Tue Jun 29 17:38:47 CEST 2010


On June 29, 2010, Aaron J. Seigo wrote:
> On June 29, 2010, Thomas Fjellstrom wrote:
> > I'm working on a plasmoid which uses a dataengine, and I can't for the
> > life of me figure out how to actually access the data from the return
> > value of:
> > 
> > dataEngine("foo").query("bar")
> 
> this was working, then at some point stopped working and i never figured
> out why. the wrapping of the DataEngine::Data hash is not happening
> properly, but only when called from query(). it needs to be investigated
> further.
> 
> however, you probably don't want to be using query() in the first place
> since it does not work with any asynchronous source ... which includes
> remote widgets.
> 
> try connecting to the source with a callback instead.

Ok. I can probably make that work. Though I don't have a fixed set of 
sources to connect to. Future additions to the data engine may add more 
sources of sources (yeah I know, bad choice of terms, but I'm not sure what 
else to call them). The way I was finding the sources them selves was by 
iterating the list of sources and checking to see if the "type" was 
"source".

It'd be nice if there was some way to just say something like:
getSourcesByProperty("type", "blah");
and have it return only sources with a property called "type" set to "blah".

To explain what I'm doing a little further:

I'm writing a plasmoid that will list hosts on the network, of various 
types. The first host "source" I've implemented in the DataEngine (just so I 
can get to the widget/plasmoid itself) is strictly manual, it has to be 
populated with hostnames and addresses manually. The next one will use 
Zeroconf to find hosts and services on said hosts, and the one after that 
will use libvirt to provide virtual machine info (libvirt also announces 
itself over zeroconf which is handy) With that the widget will support 
events on host status change, as well as allowing a person to /do things/ to 
some hosts, like sending a Wake-On-Lan packet to local hosts (this is why I 
started writing the plasmoid, but I can see using it for keeping track of 
uptime, network latency, and service status for a number of machines and 
virtual machines).

Basically the way the DataEngine is setup right now is each "Host Source" is 
given a single Data Source, with a type of "source", and a QStringList 
"hosts" property listing the hosts owned by this source. After that each 
host that the host source provides is its own source with a number of other 
properties (address, type, mac, name, isUp).

There may be a better way to do this, but I haven't come up with a better 
one yet. I'd like it to be kept fairly dynamic so the plasmoid doesn't have 
to be changed just to add a new host source. Other wise I suppose each 
/type/ of host source could be made an entirely separate data engine. But 
then the plasmoid has to hard code them all. And I'm not fond of hard coding 
things.

I'd appreciate any input you (anyone) might have.

p.s. please excuse the long ramblyness of this mail, been up waay too long.

-- 
Thomas Fjellstrom
tfjellstrom at shaw.ca


More information about the Plasma-devel mailing list