dennogumi/content/post/2014-01-04-an-expedition-in-the-qml-realm.markdown
Luca Beltrame 64b24842b8
All checks were successful
continuous-integration/drone/push Build is passing
Update all posts to not show the header text
2021-01-13 00:05:30 +01:00

2.1 KiB

author categories comments date slug tags title omit_header_text disable_share wordpress_id
einar
KDE
Linux
true 2014-01-04T08:03:18Z an-expedition-in-the-qml-realm
KDE
Linux
plasma
QML
An expedition in the QML realm true true 1270

Among 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

{{< highlight javascript >}}

PlasmaCore.DataSource { id: dataSource dataEngine: "geolocation" connectedSources: ['location'] interval: 500

    onNewData: {
        if (sourceName == 'location') {
            ipAddr.text = data.ip
        }
    }

{{< / highlight >}}

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:

{{< highlight bash >}} git clone https://git.dennogumi.org/kde/ip-address-viewer plasmapkg -i ip-address-viewer/ {{< / highlight >}}

Suggestions on code quality are welcome.