I wrote an applet that makes an API call every 10 minutes, but I want it to show a message if the computer is offline. This means I need to get the network status within QML. I thought a DataEngine might be available, but there isn't.
I read the code for plasma-nm and found this solution hack:
import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
PlasmaNM.NetworkStatus {
id: networkStatus
}
PlasmaComponents3.Label {
visible: networkStatus.networkStatus != "Connected"
text: i18n("Network disconnected")
}
But I think comparing strings is a terrible way because I don't know what will happen in other locales.
Is there a better way?
6 Comments
carlschwan@lemmy.kde.social · 2 pts · 3y
Did you try:
This use an enum and should be a lot more robust
fkfd@lemmy.ml · 1 pts · 3y
It seems
networkStatusdoesn't provide aconnectivityattribute andPlasmaNM.NetworkManagerdoesn't have aFulleither:lecris@lemmy.kde.social · 2 pts · 3y
What about checking via dbus?
fkfd@lemmy.ml · 1 pts · 3y
that would be ideal! but I can't seem to find a way to do it natively without some C++ library like this one?
lecris@lemmy.kde.social · 2 pts · 3y
I need to setup notifications here. I am not familiar with how qml works, but can't ituse qt native integration, like the one documented in the kde page
Brochetudo@feddit.de · 1 pts · 3y
You should list the properties of the object you are dealing with. Perhaps there are some unknown functions/properties that may do what you want