1
0
Fork 0
This repository has been archived on 2021-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
dennogumi.org-archive/_posts/2014-01-04-an-expedition-in-the-qml-realm.markdown

58 lines
2.1 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
author: einar
comments: true
date: 2014-01-04 08:03:18+00:00
layout: page
slug: an-expedition-in-the-qml-realm
title: An expedition in the QML realm
wordpress_id: 1270
categories:
- KDE
- Linux
tags:
- KDE
- Linux
- plasma
- QML
---
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](http://kde-apps.org/content/show.php?content=147229) 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
}
}
{% endhighlight %}
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/
{% endhighlight %}
Suggestions on code quality are welcome.