KDE TechBase
  • Page
  • Discussion
  • Edit
  • History
KDE TechBase is a Wiki - You can help! Please contribute! Questions?
Please ask development related questions in the KDE Community Forum.

Development/Tutorials/Plasma/JavaScript/SystemMonitor

< Development | Tutorials | Plasma

This example assumes that you are familiar with previous examples such as NowPlaying (from which this example was adapted).

Following code illustrates how to connect to systemmonitor and how to receive updates from various data sources.

You should have a working plasmoid application from previous examples. Take a copy of the plasmoid and rename it. After this you can replace contents of the contents/code/main.js with following:

layout = new LinearLayout(plasmoid);
 
label = new Label();
layout.addItem(label);
label.text = "No connection";
 
// current values
var systemData = new Array();
 
function printData() {
label.text = "";
for (var name in systemData) {
var data = systemData[name];
label.text = label.text + name + ": ";
for (var elt in data) {
label.text = label.text + " " + data[elt];
}
label.text = label.text + "\n";
}
}
 
plasmoid.dataUpdate = function(name, data) {
systemData[name] = data;
printData();
};
 
smDataEngine = plasmoid.dataEngine("systemmonitor");
 
smDataEngine.sourceRemoved.connect(function(name) {
// unsubscribe
smDataEngine.disconnectSource(name, plasmoid);
});
 
smDataEngine.sourceAdded.connect(function(name) {
if (name.toString().match("^mem/physical")) {
// subscribe
smDataEngine.connectSource(name, plasmoid, 500);
}
});

In smDataEngine.sourceAdded.connect() we give a function to connect to signal. The signal connection function is called by the systemmonitor for each data source. In this example we only connect to physical memory data sources.

After this the plasmoid.dataUpdate() receives updates. Update values are stored into an array. The array is printed on every update.

Note that this example is bit inefficient since we call printData() on every update. One way to optimize is to update label text only when "mem/physical/free" data source is updated.

Retrieved from "http://techbase.kde.org/Development/Tutorials/Plasma/JavaScript/SystemMonitor"

Navigation

  • Home
  • Help
  • Recent changes

Sections

  • Getting started
  • Development
  • Schedules
  • Policies
  • Contribute
  • Projects

Toolbox

  • What links here
  • Related changes
  • Special pages
  • Printable version
  • Permanent link

Personal tools

  • 38.107.191.99
  • Talk for this IP
  • Log in / create account
  • Login with OpenID
Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal