From 83790daccd7c04e2a01a2aee6be044fca3a9437b Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 9 Sep 2022 23:37:15 -0400 Subject: [PATCH] quicksettings/mobiledata: Add warning if APN is not configured --- components/mmplugin/signalindicator.cpp | 5 +++++ components/mmplugin/signalindicator.h | 2 ++ quicksettings/mobiledata/contents/ui/main.qml | 21 +++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/components/mmplugin/signalindicator.cpp b/components/mmplugin/signalindicator.cpp index 2afe746c..1a2be040 100644 --- a/components/mmplugin/signalindicator.cpp +++ b/components/mmplugin/signalindicator.cpp @@ -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) { diff --git a/components/mmplugin/signalindicator.h b/components/mmplugin/signalindicator.h index 5988e45d..02b4fccd 100644 --- a/components/mmplugin/signalindicator.h +++ b/components/mmplugin/signalindicator.h @@ -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); diff --git a/quicksettings/mobiledata/contents/ui/main.qml b/quicksettings/mobiledata/contents/ui/main.qml index e6406f0b..1e9819a5 100644 --- a/quicksettings/mobiledata/contents/ui/main.qml +++ b/quicksettings/mobiledata/contents/ui/main.qml @@ -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; + } } }