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?

Link to my code

You are viewing a single thread.
View all comments
1 point

Did you try:

import org.kde.plasma.networkmanagement 0.2 as PlasmaNM

PlasmaNM.NetworkStatus {
    id: networkStatus
}

PlasmaComponents3.Label {
    visible: networkStatus.connectivity !== PlasmaNM.NetworkManager.Full
    text: i18n("Network disconnected")
}

This use an enum and should be a lot more robust

permalink
report
reply
1 point

It seems networkStatus doesn’t provide a connectivity attribute and PlasmaNM.NetworkManager doesn’t have a Full either:

console.log(Object.keys(networkStatus))
qml: [objectName,activeConnections,networkStatus,objectNameChanged,activeConnectionsChanged,networkStatusChanged]
networkStatus.connectivity !== PlasmaNM.NetworkManager.Full
.../contents/ui/main.qml:150: TypeError: Cannot read property 'Full' of undefined
permalink
report
parent
reply

KDE

!kde@lemmy.kde.social

Create post

KDE is an international technology team creating user-friendly free and open source software for desktop and portable computing. KDE’s software runs on GNU/Linux, BSD and other operating systems, including Windows.

Plasma 6 Bugs

If you encounter a bug, proceed to https://bugs.kde.org, check whether it has been reported.

If it hasn’t, report it yourself.

PLEASE THINK CAREFULLY BEFORE POSTING HERE.

Developers do not look for reports on social media, so they will not see it and all it does is clutter up the feed.

Community stats

  • 1.2K

    Monthly active users

  • 855

    Posts

  • 6.4K

    Comments