quicksettings/mobiledata: Add warning if APN is not configured

This commit is contained in:
Devin Lin 2022-09-09 23:37:15 -04:00
parent b51a575bc6
commit 83790daccd
3 changed files with 24 additions and 4 deletions

View file

@ -73,6 +73,11 @@ bool SignalIndicator::mobileDataEnabled() const
return false;
}
bool SignalIndicator::needsAPNAdded() const
{
return m_nmModem && m_nmModem->availableConnections().count() == 0;
}
void SignalIndicator::setMobileDataEnabled(bool enabled)
{
if (!m_nmModem) {

View file

@ -23,6 +23,7 @@ class SignalIndicator : public QObject
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
Q_PROPERTY(bool mobileDataSupported READ mobileDataSupported NOTIFY mobileDataSupportedChanged)
Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged)
Q_PROPERTY(bool needsAPNAdded READ needsAPNAdded NOTIFY mobileDataEnabledChanged)
public:
SignalIndicator();
@ -33,6 +34,7 @@ public:
bool available() const;
bool mobileDataSupported() const;
bool mobileDataEnabled() const;
bool needsAPNAdded() const;
void setMobileDataEnabled(bool enabled);

View file

@ -9,12 +9,25 @@ import org.kde.plasma.private.mobileshell 1.0 as MobileShell
MobileShell.QuickSetting {
text: i18n("Mobile Data")
icon: "network-modem"
status: PlasmaMM.SignalIndicator.mobileDataSupported
? (enabled ? i18n("On") : i18n("Off"))
: i18n("Not Available")
status: {
if (PlasmaMM.SignalIndicator.needsAPNAdded) {
return i18n("APN needs to be configured in the settings");
} else if (PlasmaMM.SignalIndicator.mobileDataSupported) {
return enabled ? i18n("On") : i18n("Off");
} else {
return i18n("Not Available");
}
}
settingsCommand: "plasma-open-settings kcm_mobile_broadband"
enabled: PlasmaMM.SignalIndicator.mobileDataEnabled
function toggle() {
PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled
if (PlasmaMM.SignalIndicator.needsAPNAdded || !PlasmaMM.SignalIndicator.mobileDataSupported) {
// open settings if unable to toggle mobile data
MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_mobile_broadband");
} else {
PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled;
}
}
}