An expedition in the QML realm
By einar
- CommentsAmong the different widgets I use on my desktop, there is a small one which tells me my current public IP address. The reason I’m having it is due to the fact that my own ISP uses a NAT for almost all its customers (don’t ask - long story) and so I need to keep tabs on my current IP, because it may have been blacklisted, and so on.
Up to now I was using this plasmoid written in Python, but the code had several issues and used its own way of getting the public IP. However, I knew Plasma has already a way to give you your IP, that is the _geolocation _DataEngine. I thought of adjusting the current widget to use this engine, but then I thought “What if I make one in QML?”.
It turned out to be a rather easy task, which I accomplished in less than one hour, by reading up some documentation, examples and of course pestering people on IRC. ;)
All I needed to have the IP ready was
PlasmaCore.DataSource {
id: dataSource
dataEngine: "geolocation"
connectedSources: ['location']
interval: 500
onNewData: {
if (sourceName == 'location') {
ipAddr.text = data.ip
}
}
where ipAddr
was a Text element.
And that’s how is the final result (mimicking the other widget I took it from):
![Plasmoid in action]({{ site.url }}/images/2014/01/ip-monitor.png)
There are still a number of issues, for example getting the right size when started, and ensuring it’s not resized to a too little size. But I was surprised that it was so easy.
Interested parties can grab it by cloning and installing:
git clone https://git.dennogumi.org/kde/ip-address-viewer
plasmapkg -i ip-address-viewer/
Suggestions on code quality are welcome.