Abstract

This will show you some slightly more advanced techniques for dealing with data engines, and give you a useful plasmoid at the end that you can easily edit to display custom information about what your favourite media player is playing (providing, of course, that your favourite media player is supported by the nowplaying data engine).

It looks complicated, compared to the two previous tutorials, but there is really only one new thing, and that is that we're watching for sources appearing and disappearing.

The nowplaying data engine makes sources appear and disappear as media players come and go. This plasmoid is a little stupid and only ever watches the first source in the list, but that will be enough for us.

The magic is in listening to the sourceAdded and sourceRemoved signals of the data engine. These, unsuprisingly, are emitted when the sources property of the data engine, which lists all known sources, changes. Note that it may be possible to sensibly request sources that are not in the sources property of a data engine - for example, the twitter data engine has a theoretically infinite number of sources available, one for each possible twitter account, and these cannot possibly be listed in the sources property.

You can learn more about using signals and slots in JavaScript in the QtScript documentation. Remember that any property, signal or slot and any method tagged with Q_INVOKABLE (see the Plasma API documentation for which methods this applies to) can be called from JavaScript.

Challenge

Modify plasmoid.dataUpdate to display the information you care about, rather than all the information provided by the nowplaying data engine.