[SailfishDevel] Detect network state & react on it

Dylan Van Assche dylan.van.assche at protonmail.com
Sun Oct 9 13:26:44 UTC 2016

Hi Slava,

Thank you for your response! With these links I can indeed figure out the current state of the network connection in Python by reading those files.
Now I just need to figure out how I can add it to Sailfinder without a lot of rewriting.

Kind regards,
Dylan Van Assche

-------- Original Message --------
Subject: Re: [SailfishDevel] Detect network state & react on it
Local Time: October 8, 2016 12:02 PM
UTC Time: October 8, 2016 10:02 AM
From: slava.monich at jolla.com
To: Dylan Van Assche <dylan.van.assche at protonmail.com>, Sailfish OS Developers <devel at lists.sailfishos.org>

Hi Dylan,

From QML, the easiest way is probably to monitor /run/state/providers/connman/Internet/NetworkState and /run/state/providers/connman/Internet/NetworkType with ContextProperty object. Google for "qml contextkit contextproperty" to find some examples. That way, statefs monitors connman state for you and you monitor statefs.

You can achieve the same result by directly monitoring the connman state over D-Bus. Then libconnman-qt is your friend. It's a C++ library with a QML plugin (MeeGo.Connman). That requires a bit more code but takes statefs out of the picture.

There are also Qt network configuration APIs but those are even more complicated and not all of those might work the way you would expect them to work. But this is the most platform-independent API in case if that is important for you (probably not). Internally it also talks to connman.

Connection selector has a D-Bus API which is easy enough to figure out with dbus-monitor. However it's not an official API and it's more or less guaranteed to change over time and break your app. Think twice before starting to use it.


On 08/10/16 11:59, Dylan Van Assche wrote:

Hi Sailors,

For my app Sailfinder I have received a bug report about the network connection. When switching between mobile data & WiFi the app misbehaves.

I want to detect the current network state to avoid thsi problem. I thought of several possibilities:

Ping everytime to my website before doing other requests (expensive, better not).
- Use MCE module which expose the network states in a file (that's what I found on the sailfishos.org website, no more extra information). This option is the one I want to try :)


And if network isn't available I want to show the network connection dialog but I haven't find any information about it. Can someone help me with it? If possible, in a Harbour way since Sailfinder is also available in the Jolla Store.

Kind regards,
Dylan Van Assche
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20161009/c1068823/attachment.html>

More information about the Devel mailing list