mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
mmplugin: Use NM autoconnect instead of wwanEnabled for mobile data
Add supported function fix fix fix fix fix fix fix fix cleanup fix fix fix fix
This commit is contained in:
parent
3cb0a38040
commit
0131710c23
3 changed files with 88 additions and 17 deletions
|
|
@ -2,16 +2,13 @@
|
|||
// SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <NetworkManagerQt/GsmSetting>
|
||||
#include <NetworkManagerQt/Manager>
|
||||
|
||||
#include "signalindicator.h"
|
||||
|
||||
SignalIndicator::SignalIndicator()
|
||||
{
|
||||
connect(NetworkManager::notifier(), &NetworkManager::Notifier::wwanEnabledChanged, this, [this](bool) {
|
||||
Q_EMIT wwanEnabledChanged();
|
||||
});
|
||||
|
||||
connect(ModemManager::notifier(), &ModemManager::Notifier::modemAdded, this, &SignalIndicator::updateModem);
|
||||
connect(ModemManager::notifier(), &ModemManager::Notifier::modemRemoved, this, &SignalIndicator::updateModem);
|
||||
updateModem();
|
||||
|
|
@ -43,14 +40,50 @@ bool SignalIndicator::available() const
|
|||
return !ModemManager::modemDevices().isEmpty();
|
||||
}
|
||||
|
||||
bool SignalIndicator::wwanEnabled() const
|
||||
bool SignalIndicator::mobileDataSupported() const
|
||||
{
|
||||
return NetworkManager::isWwanEnabled();
|
||||
return m_nmModem && m_modemDevice->sim();
|
||||
}
|
||||
|
||||
void SignalIndicator::setWwanEnabled(bool wwanEnabled)
|
||||
bool SignalIndicator::mobileDataEnabled() const
|
||||
{
|
||||
NetworkManager::setWwanEnabled(wwanEnabled);
|
||||
if (!m_nmModem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_nmModem->state() == NetworkManager::Device::Activated || m_nmModem->autoconnect();
|
||||
}
|
||||
|
||||
void SignalIndicator::setMobileDataEnabled(bool enabled)
|
||||
{
|
||||
if (!m_nmModem) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_nmModem->setAutoconnect(false);
|
||||
|
||||
// before disconnecting, we ensure the current active connection is set to autoconnect
|
||||
for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) {
|
||||
if (con->uuid() == m_nmModem->activeConnection()->uuid()) {
|
||||
con->settings()->setAutoconnect(true);
|
||||
} else {
|
||||
con->settings()->setAutoconnect(false);
|
||||
}
|
||||
}
|
||||
|
||||
m_nmModem->disconnectInterface().waitForFinished();
|
||||
} else {
|
||||
m_nmModem->setAutoconnect(true);
|
||||
|
||||
// activate the connection that is set to autoconnect
|
||||
for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) {
|
||||
if (con->settings()->autoconnect()) {
|
||||
NetworkManager::activateConnection(con->path(), m_nmModem->uni(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SignalIndicator::updateModem()
|
||||
|
|
@ -59,11 +92,31 @@ void SignalIndicator::updateModem()
|
|||
qWarning() << "No modems available";
|
||||
return;
|
||||
}
|
||||
m_modem = ModemManager::modemDevices()[0]->modemInterface();
|
||||
m_3gppModem = ModemManager::modemDevices()[0]->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
|
||||
Q_EMIT nameChanged();
|
||||
|
||||
// we assume that there is a single modem
|
||||
m_modemDevice = ModemManager::modemDevices()[0];
|
||||
m_modem = m_modemDevice->modemInterface();
|
||||
m_3gppModem = m_modemDevice->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
|
||||
|
||||
// find networkmanager modem
|
||||
for (NetworkManager::Device::Ptr nmDevice : NetworkManager::networkInterfaces()) {
|
||||
if (nmDevice->udi() == m_modemDevice->uni()) {
|
||||
m_nmModem = nmDevice.objectCast<NetworkManager::ModemDevice>();
|
||||
|
||||
connect(m_nmModem.get(), &NetworkManager::Device::autoconnectChanged, this, [this]() {
|
||||
Q_EMIT mobileDataEnabledChanged();
|
||||
});
|
||||
connect(m_nmModem.get(), &NetworkManager::Device::stateChanged, this, [this](auto, auto, auto) {
|
||||
Q_EMIT mobileDataEnabledChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
connect(m_modem.get(), &ModemManager::Modem::signalQualityChanged, this, &SignalIndicator::strengthChanged);
|
||||
connect(m_3gppModem.get(), &ModemManager::Modem3gpp::operatorNameChanged, this, &SignalIndicator::nameChanged);
|
||||
connect(m_modem.get(), &ModemManager::Modem::unlockRequiredChanged, this, &SignalIndicator::simLockedChanged);
|
||||
|
||||
Q_EMIT mobileDataSupportedChanged();
|
||||
Q_EMIT nameChanged();
|
||||
Q_EMIT availableChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
#include <ModemManagerQt/Manager>
|
||||
#include <ModemManagerQt/modem3gpp.h>
|
||||
|
||||
#include <NetworkManagerQt/Connection>
|
||||
#include <NetworkManagerQt/ModemDevice>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
// We make the assumption that there is only one modem.
|
||||
|
|
@ -18,7 +21,8 @@ class SignalIndicator : public QObject
|
|||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
|
||||
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
||||
Q_PROPERTY(bool wwanEnabled READ wwanEnabled WRITE setWwanEnabled NOTIFY wwanEnabledChanged)
|
||||
Q_PROPERTY(bool mobileDataSupported READ mobileDataSupported NOTIFY mobileDataSupportedChanged)
|
||||
Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged)
|
||||
|
||||
public:
|
||||
SignalIndicator();
|
||||
|
|
@ -27,19 +31,24 @@ public:
|
|||
QString name() const;
|
||||
bool simLocked() const;
|
||||
bool available() const;
|
||||
bool wwanEnabled() const;
|
||||
bool mobileDataSupported() const;
|
||||
bool mobileDataEnabled() const;
|
||||
|
||||
void setWwanEnabled(bool wwanEnabled);
|
||||
void setMobileDataEnabled(bool enabled);
|
||||
|
||||
Q_SIGNALS:
|
||||
void strengthChanged();
|
||||
void nameChanged();
|
||||
void simLockedChanged();
|
||||
void availableChanged();
|
||||
void wwanEnabledChanged();
|
||||
void mobileDataSupportedChanged();
|
||||
void mobileDataEnabledChanged();
|
||||
|
||||
private:
|
||||
NetworkManager::ModemDevice::Ptr m_nmModem;
|
||||
ModemManager::ModemDevice::Ptr m_modemDevice;
|
||||
ModemManager::Modem::Ptr m_modem;
|
||||
ModemManager::Modem3gpp::Ptr m_3gppModem;
|
||||
|
||||
void updateModem();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ MobileShell.QuickSettingsModel {
|
|||
enabled: false
|
||||
settingsCommand: "plasma-open-settings"
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
PlasmaNM.Handler {
|
||||
id: nmHandler
|
||||
|
|
@ -49,6 +50,7 @@ MobileShell.QuickSettingsModel {
|
|||
}
|
||||
enabled: enabledConnections.wirelessEnabled
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Bluetooth")
|
||||
icon: "network-bluetooth"
|
||||
|
|
@ -64,15 +66,17 @@ MobileShell.QuickSettingsModel {
|
|||
}
|
||||
enabled: BluezQt.Manager.bluetoothOperational
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Mobile Data")
|
||||
icon: "network-modem"
|
||||
settingsCommand: "plasma-open-settings kcm_mobile_broadband"
|
||||
enabled: PlasmaMM.SignalIndicator.wwanEnabled
|
||||
enabled: PlasmaMM.SignalIndicator.mobileDataEnabled
|
||||
function toggle() {
|
||||
PlasmaMM.SignalIndicator.wwanEnabled = !PlasmaMM.SignalIndicator.wwanEnabled
|
||||
PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled
|
||||
}
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Flashlight")
|
||||
icon: "flashlight-on"
|
||||
|
|
@ -81,11 +85,13 @@ MobileShell.QuickSettingsModel {
|
|||
MobileShell.ShellUtil.toggleTorch()
|
||||
}
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Location")
|
||||
icon: "gps"
|
||||
enabled: false
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Screenshot")
|
||||
status: i18n("Tap to screenshot")
|
||||
|
|
@ -113,6 +119,7 @@ MobileShell.QuickSettingsModel {
|
|||
onTriggered: MobileShell.ShellUtil.takeScreenshot()
|
||||
}
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Auto-rotate")
|
||||
icon: "rotation-allowed"
|
||||
|
|
@ -122,6 +129,7 @@ MobileShell.QuickSettingsModel {
|
|||
MobileShell.ShellUtil.autoRotateEnabled = !enabled
|
||||
}
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Battery")
|
||||
status: i18n("%1%", MobileShell.BatteryProvider.percent)
|
||||
|
|
@ -129,6 +137,7 @@ MobileShell.QuickSettingsModel {
|
|||
enabled: false
|
||||
settingsCommand: "plasma-open-settings kcm_mobile_power"
|
||||
}
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Sound")
|
||||
icon: "audio-speakers-symbolic"
|
||||
|
|
|
|||
Loading…
Reference in a new issue