mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-02 09:48:50 +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-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <NetworkManagerQt/GsmSetting>
|
||||||
#include <NetworkManagerQt/Manager>
|
#include <NetworkManagerQt/Manager>
|
||||||
|
|
||||||
#include "signalindicator.h"
|
#include "signalindicator.h"
|
||||||
|
|
||||||
SignalIndicator::SignalIndicator()
|
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::modemAdded, this, &SignalIndicator::updateModem);
|
||||||
connect(ModemManager::notifier(), &ModemManager::Notifier::modemRemoved, this, &SignalIndicator::updateModem);
|
connect(ModemManager::notifier(), &ModemManager::Notifier::modemRemoved, this, &SignalIndicator::updateModem);
|
||||||
updateModem();
|
updateModem();
|
||||||
|
|
@ -43,14 +40,50 @@ bool SignalIndicator::available() const
|
||||||
return !ModemManager::modemDevices().isEmpty();
|
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()
|
void SignalIndicator::updateModem()
|
||||||
|
|
@ -59,11 +92,31 @@ void SignalIndicator::updateModem()
|
||||||
qWarning() << "No modems available";
|
qWarning() << "No modems available";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_modem = ModemManager::modemDevices()[0]->modemInterface();
|
|
||||||
m_3gppModem = ModemManager::modemDevices()[0]->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
|
// we assume that there is a single modem
|
||||||
Q_EMIT nameChanged();
|
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_modem.get(), &ModemManager::Modem::signalQualityChanged, this, &SignalIndicator::strengthChanged);
|
||||||
connect(m_3gppModem.get(), &ModemManager::Modem3gpp::operatorNameChanged, this, &SignalIndicator::nameChanged);
|
connect(m_3gppModem.get(), &ModemManager::Modem3gpp::operatorNameChanged, this, &SignalIndicator::nameChanged);
|
||||||
connect(m_modem.get(), &ModemManager::Modem::unlockRequiredChanged, this, &SignalIndicator::simLockedChanged);
|
connect(m_modem.get(), &ModemManager::Modem::unlockRequiredChanged, this, &SignalIndicator::simLockedChanged);
|
||||||
|
|
||||||
|
Q_EMIT mobileDataSupportedChanged();
|
||||||
|
Q_EMIT nameChanged();
|
||||||
Q_EMIT availableChanged();
|
Q_EMIT availableChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@
|
||||||
#include <ModemManagerQt/Manager>
|
#include <ModemManagerQt/Manager>
|
||||||
#include <ModemManagerQt/modem3gpp.h>
|
#include <ModemManagerQt/modem3gpp.h>
|
||||||
|
|
||||||
|
#include <NetworkManagerQt/Connection>
|
||||||
|
#include <NetworkManagerQt/ModemDevice>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
// We make the assumption that there is only one modem.
|
// 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(QString name READ name NOTIFY nameChanged)
|
||||||
Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
|
Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
|
||||||
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
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:
|
public:
|
||||||
SignalIndicator();
|
SignalIndicator();
|
||||||
|
|
@ -27,19 +31,24 @@ public:
|
||||||
QString name() const;
|
QString name() const;
|
||||||
bool simLocked() const;
|
bool simLocked() const;
|
||||||
bool available() const;
|
bool available() const;
|
||||||
bool wwanEnabled() const;
|
bool mobileDataSupported() const;
|
||||||
|
bool mobileDataEnabled() const;
|
||||||
|
|
||||||
void setWwanEnabled(bool wwanEnabled);
|
void setMobileDataEnabled(bool enabled);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void strengthChanged();
|
void strengthChanged();
|
||||||
void nameChanged();
|
void nameChanged();
|
||||||
void simLockedChanged();
|
void simLockedChanged();
|
||||||
void availableChanged();
|
void availableChanged();
|
||||||
void wwanEnabledChanged();
|
void mobileDataSupportedChanged();
|
||||||
|
void mobileDataEnabledChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
NetworkManager::ModemDevice::Ptr m_nmModem;
|
||||||
|
ModemManager::ModemDevice::Ptr m_modemDevice;
|
||||||
ModemManager::Modem::Ptr m_modem;
|
ModemManager::Modem::Ptr m_modem;
|
||||||
ModemManager::Modem3gpp::Ptr m_3gppModem;
|
ModemManager::Modem3gpp::Ptr m_3gppModem;
|
||||||
|
|
||||||
void updateModem();
|
void updateModem();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ MobileShell.QuickSettingsModel {
|
||||||
enabled: false
|
enabled: false
|
||||||
settingsCommand: "plasma-open-settings"
|
settingsCommand: "plasma-open-settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
PlasmaNM.Handler {
|
PlasmaNM.Handler {
|
||||||
id: nmHandler
|
id: nmHandler
|
||||||
|
|
@ -49,6 +50,7 @@ MobileShell.QuickSettingsModel {
|
||||||
}
|
}
|
||||||
enabled: enabledConnections.wirelessEnabled
|
enabled: enabledConnections.wirelessEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Bluetooth")
|
text: i18n("Bluetooth")
|
||||||
icon: "network-bluetooth"
|
icon: "network-bluetooth"
|
||||||
|
|
@ -64,15 +66,17 @@ MobileShell.QuickSettingsModel {
|
||||||
}
|
}
|
||||||
enabled: BluezQt.Manager.bluetoothOperational
|
enabled: BluezQt.Manager.bluetoothOperational
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Mobile Data")
|
text: i18n("Mobile Data")
|
||||||
icon: "network-modem"
|
icon: "network-modem"
|
||||||
settingsCommand: "plasma-open-settings kcm_mobile_broadband"
|
settingsCommand: "plasma-open-settings kcm_mobile_broadband"
|
||||||
enabled: PlasmaMM.SignalIndicator.wwanEnabled
|
enabled: PlasmaMM.SignalIndicator.mobileDataEnabled
|
||||||
function toggle() {
|
function toggle() {
|
||||||
PlasmaMM.SignalIndicator.wwanEnabled = !PlasmaMM.SignalIndicator.wwanEnabled
|
PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Flashlight")
|
text: i18n("Flashlight")
|
||||||
icon: "flashlight-on"
|
icon: "flashlight-on"
|
||||||
|
|
@ -81,11 +85,13 @@ MobileShell.QuickSettingsModel {
|
||||||
MobileShell.ShellUtil.toggleTorch()
|
MobileShell.ShellUtil.toggleTorch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Location")
|
text: i18n("Location")
|
||||||
icon: "gps"
|
icon: "gps"
|
||||||
enabled: false
|
enabled: false
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Screenshot")
|
text: i18n("Screenshot")
|
||||||
status: i18n("Tap to screenshot")
|
status: i18n("Tap to screenshot")
|
||||||
|
|
@ -113,6 +119,7 @@ MobileShell.QuickSettingsModel {
|
||||||
onTriggered: MobileShell.ShellUtil.takeScreenshot()
|
onTriggered: MobileShell.ShellUtil.takeScreenshot()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Auto-rotate")
|
text: i18n("Auto-rotate")
|
||||||
icon: "rotation-allowed"
|
icon: "rotation-allowed"
|
||||||
|
|
@ -122,6 +129,7 @@ MobileShell.QuickSettingsModel {
|
||||||
MobileShell.ShellUtil.autoRotateEnabled = !enabled
|
MobileShell.ShellUtil.autoRotateEnabled = !enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Battery")
|
text: i18n("Battery")
|
||||||
status: i18n("%1%", MobileShell.BatteryProvider.percent)
|
status: i18n("%1%", MobileShell.BatteryProvider.percent)
|
||||||
|
|
@ -129,6 +137,7 @@ MobileShell.QuickSettingsModel {
|
||||||
enabled: false
|
enabled: false
|
||||||
settingsCommand: "plasma-open-settings kcm_mobile_power"
|
settingsCommand: "plasma-open-settings kcm_mobile_power"
|
||||||
}
|
}
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Sound")
|
text: i18n("Sound")
|
||||||
icon: "audio-speakers-symbolic"
|
icon: "audio-speakers-symbolic"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue