From 23833a6b5423ad12b307d304574e15991205ab8d Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Wed, 11 Feb 2026 23:19:36 -0500 Subject: [PATCH] mmplugin: Remove and port to plasma-nm cellular lib Replace mmplugin with shared plasma-nm cellular library: https://invent.kde.org/plasma/plasma-nm/-/merge_requests/522 --- components/CMakeLists.txt | 1 - components/mmplugin/CMakeLists.txt | 21 - components/mmplugin/profilesettings.cpp | 139 ------ components/mmplugin/profilesettings.h | 75 ---- components/mmplugin/signalindicator.cpp | 405 ------------------ components/mmplugin/signalindicator.h | 88 ---- .../qml/dataproviders/SignalStrengthInfo.qml | 15 +- .../package/contents/ui/EditProfileDialog.qml | 43 +- .../cellular/package/contents/ui/main.qml | 58 ++- quicksettings/mobiledata/contents/ui/main.qml | 24 +- 10 files changed, 90 insertions(+), 779 deletions(-) delete mode 100644 components/mmplugin/CMakeLists.txt delete mode 100644 components/mmplugin/profilesettings.cpp delete mode 100644 components/mmplugin/profilesettings.h delete mode 100644 components/mmplugin/signalindicator.cpp delete mode 100644 components/mmplugin/signalindicator.h diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 7e855bcd..f7af544a 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(waydroidintegrationplugin) add_subdirectory(hapticsplugin) -add_subdirectory(mmplugin) add_subdirectory(mobileshell) add_subdirectory(mobileshellstate) add_subdirectory(quicksettingsplugin) diff --git a/components/mmplugin/CMakeLists.txt b/components/mmplugin/CMakeLists.txt deleted file mode 100644 index 9b739fbb..00000000 --- a/components/mmplugin/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-FileCopyrightText: 2021 Tobias Fella -# SPDX-License-Identifier: GPL-2.0-or-later - -ecm_add_qml_module(ppc-mmqmlplugin URI org.kde.plasma.mm GENERATE_PLUGIN_SOURCE) -target_sources(ppc-mmqmlplugin PRIVATE - signalindicator.cpp - profilesettings.cpp -) - - -target_link_libraries(ppc-mmqmlplugin PRIVATE - Qt::Qml - KF6::ModemManagerQt - KF6::NetworkManagerQt - KF6::CoreAddons - KF6::I18n - QCoro::DBus -) - - -ecm_finalize_qml_module(ppc-mmqmlplugin) diff --git a/components/mmplugin/profilesettings.cpp b/components/mmplugin/profilesettings.cpp deleted file mode 100644 index 09a48099..00000000 --- a/components/mmplugin/profilesettings.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Devin Lin -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "profilesettings.h" - -#include - -ProfileSettings::ProfileSettings(QObject *parent, - const QString &name, - const QString &apn, - const QString &user, - const QString &password, - NetworkManager::GsmSetting::NetworkType networkType, - const QString &connectionUni) - : QObject{parent} - , m_name(name) - , m_apn(apn) - , m_user(user) - , m_password(password) - , m_networkType(networkTypeStr(networkType)) - , m_connectionUni(connectionUni) -{ - setParent(parent); -} - -ProfileSettings::ProfileSettings(QObject *parent, NetworkManager::Setting::Ptr setting, NetworkManager::Connection::Ptr connection) - : QObject{parent} - , m_connectionUni(connection->uuid()) -{ - NetworkManager::GsmSetting::Ptr gsmSetting = setting.staticCast(); - - m_name = connection->name(); - m_apn = gsmSetting->apn(); - m_user = gsmSetting->username(); - m_password = gsmSetting->password(); - m_networkType = networkTypeStr(gsmSetting->networkType()); -} - -QString ProfileSettings::name() const -{ - return m_name; -} - -QString ProfileSettings::apn() const -{ - return m_apn; -} - -void ProfileSettings::setApn(const QString &apn) -{ - if (apn != m_apn) { - m_apn = apn; - Q_EMIT apnChanged(); - } -} - -QString ProfileSettings::user() const -{ - return m_user; -} - -void ProfileSettings::setUser(const QString &user) -{ - if (user != m_user) { - m_user = user; - Q_EMIT userChanged(); - } -} - -QString ProfileSettings::password() const -{ - return m_password; -} - -void ProfileSettings::setPassword(const QString &password) -{ - if (password != m_password) { - m_password = password; - Q_EMIT passwordChanged(); - } -} - -QString ProfileSettings::networkType() const -{ - return m_networkType; -} - -void ProfileSettings::setNetworkType(const QString &networkType) -{ - if (networkType != m_networkType) { - m_networkType = networkType; - Q_EMIT networkTypeChanged(); - } -} - -QString ProfileSettings::connectionUni() const -{ - return m_connectionUni; -} - -QString ProfileSettings::networkTypeStr(NetworkManager::GsmSetting::NetworkType networkType) -{ - if (networkType == NetworkManager::GsmSetting::NetworkType::Any) { - return QStringLiteral("Any"); - } else if (networkType == NetworkManager::GsmSetting::NetworkType::GprsEdgeOnly) { - return QStringLiteral("Only 2G"); - } else if (networkType == NetworkManager::GsmSetting::NetworkType::Only3G) { - return QStringLiteral("Only 3G"); - } else if (networkType == NetworkManager::GsmSetting::NetworkType::Only4GLte) { - return QStringLiteral("Only 4G"); - } else if (networkType == NetworkManager::GsmSetting::NetworkType::Prefer2G) { - return QStringLiteral("2G"); - } else if (networkType == NetworkManager::GsmSetting::NetworkType::Prefer3G) { - return QStringLiteral("3G/2G"); - } else if (networkType == NetworkManager::GsmSetting::NetworkType::Prefer4GLte) { - return QStringLiteral("4G/3G/2G"); - } - return QStringLiteral("Any"); -} - -NetworkManager::GsmSetting::NetworkType ProfileSettings::networkTypeFlag(const QString &networkType) -{ - if (networkType == QStringLiteral("Any")) { - return NetworkManager::GsmSetting::NetworkType::Any; - } else if (networkType == QStringLiteral("Only 2G")) { - return NetworkManager::GsmSetting::NetworkType::GprsEdgeOnly; - } else if (networkType == QStringLiteral("Only 3G")) { - return NetworkManager::GsmSetting::NetworkType::Only3G; - } else if (networkType == QStringLiteral("Only 4G")) { - return NetworkManager::GsmSetting::NetworkType::Only4GLte; - } else if (networkType == QStringLiteral("2G")) { - return NetworkManager::GsmSetting::NetworkType::Prefer2G; - } else if (networkType == QStringLiteral("3G/2G")) { - return NetworkManager::GsmSetting::NetworkType::Prefer3G; - } else if (networkType == QStringLiteral("4G/3G/2G")) { - return NetworkManager::GsmSetting::NetworkType::Prefer4GLte; - } - return NetworkManager::GsmSetting::NetworkType::Any; -} diff --git a/components/mmplugin/profilesettings.h b/components/mmplugin/profilesettings.h deleted file mode 100644 index e0f51418..00000000 --- a/components/mmplugin/profilesettings.h +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-FileCopyrightText: 2021-2023 Devin Lin -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -class ProfileSettings : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(QString apn READ apn WRITE setApn NOTIFY apnChanged) - Q_PROPERTY(QString user READ user WRITE setUser NOTIFY userChanged) - Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) - Q_PROPERTY(QString networkType READ networkType WRITE setNetworkType NOTIFY networkTypeChanged) - Q_PROPERTY(QString connectionUni READ connectionUni NOTIFY connectionUniChanged) - -public: - ProfileSettings(QObject *parent = nullptr) - : QObject{parent} - { - } - ProfileSettings(QObject *parent, - const QString &name, - const QString &apn, - const QString &user, - const QString &password, - NetworkManager::GsmSetting::NetworkType networkType, - const QString &connectionUni); - ProfileSettings(QObject *parent, NetworkManager::Setting::Ptr settings, NetworkManager::Connection::Ptr connection); - - QString name() const; - QString apn() const; - void setApn(const QString &apn); - QString user() const; - void setUser(const QString &user); - QString password() const; - void setPassword(const QString &password); - QString networkType() const; - void setNetworkType(const QString &ipType); - QString connectionUni() const; - - // utilities - static QString networkTypeStr(NetworkManager::GsmSetting::NetworkType networkType); - static NetworkManager::GsmSetting::NetworkType networkTypeFlag(const QString &networkType); - -Q_SIGNALS: - void nameChanged(); - void apnChanged(); - void userChanged(); - void passwordChanged(); - void networkTypeChanged(); - void connectionUniChanged(); - -private: - QString m_name; - QString m_apn; - QString m_user; - QString m_password; - QString m_networkType; - QString m_connectionUni; -}; diff --git a/components/mmplugin/signalindicator.cpp b/components/mmplugin/signalindicator.cpp deleted file mode 100644 index 84023bdf..00000000 --- a/components/mmplugin/signalindicator.cpp +++ /dev/null @@ -1,405 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Tobias Fella -// SPDX-FileCopyrightText: 2022-2023 Devin Lin -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "signalindicator.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include "signalindicator.h" - -SignalIndicator::SignalIndicator(QObject *parent) - : QObject{parent} - , m_nmModem{nullptr} - , m_modemDevice{nullptr} - , m_modem{nullptr} - , m_3gppModem{nullptr} -{ - connect(ModemManager::notifier(), &ModemManager::Notifier::modemAdded, this, &SignalIndicator::updateModemManagerModem); - connect(ModemManager::notifier(), &ModemManager::Notifier::modemRemoved, this, &SignalIndicator::updateModemManagerModem); - - connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &SignalIndicator::mobileDataEnabledChanged); - connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionRemoved, this, &SignalIndicator::mobileDataEnabledChanged); - connect(NetworkManager::notifier(), &NetworkManager::Notifier::activeConnectionAdded, this, &SignalIndicator::mobileDataEnabledChanged); - connect(NetworkManager::notifier(), &NetworkManager::Notifier::activeConnectionRemoved, this, &SignalIndicator::mobileDataEnabledChanged); - connect(NetworkManager::notifier(), &NetworkManager::Notifier::deviceAdded, this, &SignalIndicator::updateNetworkManagerModem); - connect(NetworkManager::notifier(), &NetworkManager::Notifier::deviceRemoved, this, &SignalIndicator::updateNetworkManagerModem); - - updateModemManagerModem(); -} - -int SignalIndicator::strength() const -{ - if (!m_modem) { - return 0; - } - return m_modem->signalQuality().signal; -} - -QString SignalIndicator::name() const -{ - return m_3gppModem ? m_3gppModem->operatorName() : QString(); -} - -bool SignalIndicator::modemAvailable() const -{ - return !m_modem.isNull(); -} - -bool SignalIndicator::simLocked() const -{ - if (!m_modem) { - return false; - } - return m_modem->unlockRequired() == MM_MODEM_LOCK_SIM_PIN; -} - -bool SignalIndicator::simEmpty() const -{ - return !m_modemDevice || !m_modemDevice->sim() || (m_modemDevice->sim()->uni() == QStringLiteral("/")); -} - -bool SignalIndicator::mobileDataSupported() const -{ - return m_nmModem && !simEmpty(); -} - -bool SignalIndicator::mobileDataEnabled() const -{ - // if wwan is globally disabled - if (!NetworkManager::isWwanEnabled()) { - return false; - } - - // no modem -> no mobile data -> report disabled - if (!m_nmModem) { - return false; - } - - // mobile data already activated -> report enabled - if (m_nmModem->state() == NetworkManager::Device::Activated) { - return true; - } - - // autoconnect disabled on the entire modem -> report disabled - if (!m_nmModem->autoconnect()) { - return false; - } - - // at least one connection set to autoconnect -> report enabled - for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { - if (con->settings()->autoconnect()) { - return true; - } - } - - // modem, but no connection, set to autoconnect -> report disabled (#182) - return false; -} - -bool SignalIndicator::needsAPNAdded() const -{ - return m_nmModem && mobileDataSupported() && m_nmModem->availableConnections().count() == 0; -} - -void SignalIndicator::setMobileDataEnabled(bool enabled) -{ - // ensure that wwan is on - if (enabled && !NetworkManager::isWwanEnabled()) { - NetworkManager::setWwanEnabled(true); - } - - if (!m_nmModem) { - return; - } - - if (enabled) { - // enable mobile data... - - m_nmModem->setAutoconnect(true); - - // activate the connection that was last used - QDateTime latestTimestamp; - NetworkManager::Connection::Ptr latestCon; - for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { - QDateTime timestamp = con->settings()->timestamp(); - // if con was not used yet, skip it, otherwise: - // if we have no latestTimestamp yet, con is the latest - // otherwise, compare the timestamps - // in case of a tie, use the first connection that was found - if (!timestamp.isNull() && (latestTimestamp.isNull() || timestamp > latestTimestamp)) { - latestTimestamp = timestamp; - latestCon = con; - } - } - - // if we found the last used connection - if (!latestCon.isNull()) { - // set it to autoconnect and connect it immediately - latestCon->settings()->setAutoconnect(true); - latestCon->update(latestCon->settings()->toMap()); - NetworkManager::activateConnection(latestCon->path(), m_nmModem->uni(), ""); - } - - } else { - // disable mobile data... - - // we do not call NetworkManager::setWwanEnabled(false), because it turns off cellular - - // turn off autoconnect - m_nmModem->setAutoconnect(false); - // we need to also set all connections to not autoconnect (#182) - for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { - con->settings()->setAutoconnect(false); - con->update(con->settings()->toMap()); - } - - // disconnect network - m_nmModem->disconnectInterface(); - } -} - -QString SignalIndicator::activeConnectionUni() const -{ - if (m_nmModem && m_nmModem->activeConnection() && m_nmModem->activeConnection()->connection()) { - return m_nmModem->activeConnection()->connection()->uuid(); - } - return QString(); -} - -QList &SignalIndicator::profileList() -{ - return m_profileList; -} - -void SignalIndicator::refreshProfiles() -{ - m_profileList.clear(); - - if (!m_nmModem) { - Q_EMIT profileListChanged(); - qWarning() << "No NetworkManager modem found, cannot refresh profiles."; - return; - } - - for (auto connection : m_nmModem->availableConnections()) { - for (auto setting : connection->settings()->settings()) { - if (setting.dynamicCast()) { - m_profileList.append(new ProfileSettings(this, setting.dynamicCast(), connection)); - } - } - } - Q_EMIT profileListChanged(); -} - -QCoro::Task SignalIndicator::activateProfile(const QString &connectionUni) -{ - if (!m_nmModem) { - qWarning() << "Cannot activate profile since there is no NetworkManager modem"; - co_return; - } - - qDebug() << QStringLiteral("Activating profile on modem") << m_nmModem->uni() << QStringLiteral("for connection") << connectionUni << "."; - - NetworkManager::Connection::Ptr con; - - // disable autoconnect for all other connections - for (auto connection : m_nmModem->availableConnections()) { - if (connection->uuid() == connectionUni) { - connection->settings()->setAutoconnect(true); - con = connection; - } else { - connection->settings()->setAutoconnect(false); - } - } - - if (!con) { - qDebug() << QStringLiteral("Connection") << connectionUni << QStringLiteral("not found."); - co_return; - } - - // activate connection manually - // despite the documentation saying otherwise, activateConnection seems to need the DBus path, not uuid of the connection - QPointer guard(this); - QDBusReply reply = co_await NetworkManager::activateConnection(con->path(), m_nmModem->uni(), {}); - - if (!guard) { - co_return; - } - - if (!reply.isValid()) { - qWarning() << QStringLiteral("Error activating connection:") << reply.error().message(); - co_return; - } -} - -QCoro::Task SignalIndicator::addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType) -{ - if (!m_nmModem) { - qWarning() << "Cannot add profile since there is no NetworkManager modem"; - co_return; - } - - NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Gsm)}; - settings->setId(name); - settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - settings->setAutoconnect(true); - settings->addToPermissions(KUser().loginName(), QString()); - - NetworkManager::GsmSetting::Ptr gsmSetting = settings->setting(NetworkManager::Setting::Gsm).dynamicCast(); - gsmSetting->setApn(apn); - gsmSetting->setUsername(username); - gsmSetting->setPassword(password); - gsmSetting->setPasswordFlags(password.isEmpty() ? NetworkManager::Setting::NotRequired : NetworkManager::Setting::AgentOwned); - gsmSetting->setNetworkType(ProfileSettings::networkTypeFlag(networkType)); - - gsmSetting->setInitialized(true); - - QPointer guard(this); - QDBusReply reply = co_await NetworkManager::addAndActivateConnection(settings->toMap(), m_nmModem->uni(), {}); - - if (!guard) { - co_return; - } - - if (!reply.isValid()) { - qWarning() << "Error adding connection:" << reply.error().message(); - } else { - qDebug() << "Successfully added a new connection" << name << "with APN" << apn << "."; - } -} - -QCoro::Task SignalIndicator::removeProfile(const QString &connectionUni) -{ - NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni); - if (!con) { - qWarning() << "Could not find connection" << connectionUni << "to update!"; - co_return; - } - - QPointer guard(this); - QDBusPendingReply reply = co_await con->remove(); - - if (!guard) { - co_return; - } - - if (!reply.isValid()) { - qWarning() << "Error removing connection" << reply.error().message(); - } -} - -QCoro::Task SignalIndicator::updateProfile(const QString &connectionUni, - const QString &name, - const QString &apn, - const QString &username, - const QString &password, - const QString &networkType) -{ - NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni); - if (!con) { - qWarning() << "Could not find connection" << connectionUni << "to update!"; - co_return; - } - - NetworkManager::ConnectionSettings::Ptr conSettings = con->settings(); - if (!conSettings) { - qWarning() << "Could not find connection settings for" << connectionUni << "to update!"; - co_return; - } - - conSettings->setId(name); - - NetworkManager::GsmSetting::Ptr gsmSetting = conSettings->setting(NetworkManager::Setting::Gsm).dynamicCast(); - gsmSetting->setApn(apn); - gsmSetting->setUsername(username); - gsmSetting->setPassword(password); - gsmSetting->setPasswordFlags(password.isEmpty() ? NetworkManager::Setting::NotRequired : NetworkManager::Setting::AgentOwned); - gsmSetting->setNetworkType(ProfileSettings::networkTypeFlag(networkType)); - - gsmSetting->setInitialized(true); - - QPointer guard(this); - QDBusPendingReply reply = co_await con->update(conSettings->toMap()); - - if (!guard) { - co_return; - } - - if (!reply.isValid()) { - qWarning() << "Error updating connection settings for" << connectionUni << ":" << reply.error().message() << "."; - } else { - qDebug() << "Successfully updated connection settings" << connectionUni << "."; - } -} - -void SignalIndicator::updateModemManagerModem() -{ - m_modemDevice = nullptr; - m_modem = nullptr; - m_3gppModem = nullptr; - - if (ModemManager::modemDevices().isEmpty()) { - qWarning() << "No modems available"; - return; - } - - // TODO: we assume that there is a single modem for the time being - m_modemDevice = ModemManager::modemDevices()[0]; - m_modem = m_modemDevice->modemInterface(); - m_3gppModem = m_modemDevice->interface(ModemManager::ModemDevice::GsmInterface).objectCast(); - - connect(m_modemDevice->sim().get(), &ModemManager::Sim::simIdentifierChanged, this, &SignalIndicator::simEmptyChanged); - - if (m_modem) { - connect(m_modem.get(), &ModemManager::Modem::signalQualityChanged, this, &SignalIndicator::strengthChanged); - connect(m_modem.get(), &ModemManager::Modem::unlockRequiredChanged, this, &SignalIndicator::simLockedChanged); - } - if (m_3gppModem) { - connect(m_3gppModem.get(), &ModemManager::Modem3gpp::operatorNameChanged, this, &SignalIndicator::nameChanged); - } - - updateNetworkManagerModem(); - - Q_EMIT nameChanged(); - Q_EMIT strengthChanged(); - Q_EMIT modemAvailableChanged(); -} - -void SignalIndicator::updateNetworkManagerModem() -{ - m_nmModem = nullptr; - if (!m_modemDevice) { - return; - } - - // find networkmanager modem - for (NetworkManager::Device::Ptr nmDevice : NetworkManager::networkInterfaces()) { - if (nmDevice->udi() == m_modemDevice->uni()) { - m_nmModem = nmDevice.objectCast(); - - connect(m_nmModem.get(), &NetworkManager::Device::autoconnectChanged, this, &SignalIndicator::mobileDataEnabledChanged); - connect(m_nmModem.get(), &NetworkManager::Device::stateChanged, this, &SignalIndicator::mobileDataEnabledChanged); - connect(m_nmModem.get(), &NetworkManager::Device::availableConnectionAppeared, this, &SignalIndicator::mobileDataEnabledChanged); - connect(m_nmModem.get(), &NetworkManager::Device::availableConnectionDisappeared, this, &SignalIndicator::mobileDataEnabledChanged); - - connect(m_nmModem.data(), &NetworkManager::ModemDevice::availableConnectionChanged, this, &SignalIndicator::refreshProfiles); - connect(m_nmModem.data(), &NetworkManager::ModemDevice::activeConnectionChanged, this, [this]() -> void { - refreshProfiles(); - Q_EMIT activeConnectionUniChanged(); - }); - - refreshProfiles(); - } - } - - Q_EMIT mobileDataSupportedChanged(); - Q_EMIT mobileDataEnabledChanged(); -} diff --git a/components/mmplugin/signalindicator.h b/components/mmplugin/signalindicator.h deleted file mode 100644 index 77af2cda..00000000 --- a/components/mmplugin/signalindicator.h +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Tobias Fella -// SPDX-FileCopyrightText: 2022 Devin Lin -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include - -#include -#include -#include - -#include -#include - -#include "profilesettings.h" - -// We make the assumption that there is only one modem. -class SignalIndicator : public QObject -{ - Q_OBJECT - QML_ELEMENT - QML_SINGLETON - - Q_PROPERTY(int strength READ strength NOTIFY strengthChanged) - Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(bool modemAvailable READ modemAvailable NOTIFY modemAvailableChanged) - Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged) - Q_PROPERTY(bool simEmpty READ simEmpty NOTIFY simEmptyChanged) - - 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) - Q_PROPERTY(QList profiles READ profileList NOTIFY profileListChanged) - Q_PROPERTY(QString activeConnectionUni READ activeConnectionUni NOTIFY activeConnectionUniChanged) - -public: - SignalIndicator(QObject *parent = nullptr); - - int strength() const; - QString name() const; - bool modemAvailable() const; - bool simLocked() const; - bool simEmpty() const; - bool mobileDataSupported() const; - bool mobileDataEnabled() const; - bool needsAPNAdded() const; - QString activeConnectionUni() const; - - void setMobileDataEnabled(bool enabled); - - // connection profiles - QList &profileList(); - void refreshProfiles(); - Q_INVOKABLE QCoro::Task activateProfile(const QString &connectionUni); - Q_INVOKABLE QCoro::Task addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType); - Q_INVOKABLE QCoro::Task removeProfile(const QString &connectionUni); - Q_INVOKABLE QCoro::Task updateProfile(const QString &connectionUni, - const QString &name, - const QString &apn, - const QString &username, - const QString &password, - const QString &networkType); - -Q_SIGNALS: - void strengthChanged(); - void nameChanged(); - void modemAvailableChanged(); - void simLockedChanged(); - void simEmptyChanged(); - void mobileDataSupportedChanged(); - void mobileDataEnabledChanged(); - void profileListChanged(); - void activeConnectionUniChanged(); - -private: - NetworkManager::ModemDevice::Ptr m_nmModem; - ModemManager::ModemDevice::Ptr m_modemDevice; - ModemManager::Modem::Ptr m_modem; - ModemManager::Modem3gpp::Ptr m_3gppModem; - - QList m_profileList; - - void updateModemManagerModem(); - void updateNetworkManagerModem(); -}; diff --git a/components/mobileshell/qml/dataproviders/SignalStrengthInfo.qml b/components/mobileshell/qml/dataproviders/SignalStrengthInfo.qml index 0705ea5e..ebc1b355 100644 --- a/components/mobileshell/qml/dataproviders/SignalStrengthInfo.qml +++ b/components/mobileshell/qml/dataproviders/SignalStrengthInfo.qml @@ -9,13 +9,18 @@ pragma Singleton import QtQuick 2.1 -import org.kde.plasma.mm +import org.kde.plasma.networkmanagement.cellular as Cellular QtObject { - readonly property string icon: "network-mobile-" + Math.floor(SignalIndicator.strength / 20) * 20 + property Cellular.CellularModemList _modemList: Cellular.CellularModemList {} - readonly property string label: SignalIndicator.simLocked ? i18n("SIM Locked") : SignalIndicator.name + readonly property string icon: "network-mobile-" + Math.floor((_modemList.primaryModem ? _modemList.primaryModem.signalStrength : 0) / 20) * 20 - readonly property bool showIndicator: SignalIndicator.modemAvailable + readonly property string label: { + if (!_modemList.primaryModem) return ""; + if (_modemList.primaryModem.simLocked) return i18n("SIM Locked"); + return _modemList.primaryModem.operatorName; + } + + readonly property bool showIndicator: _modemList.modemAvailable } - diff --git a/initialstart/modules/cellular/package/contents/ui/EditProfileDialog.qml b/initialstart/modules/cellular/package/contents/ui/EditProfileDialog.qml index ae366bd4..6b9fb15f 100644 --- a/initialstart/modules/cellular/package/contents/ui/EditProfileDialog.qml +++ b/initialstart/modules/cellular/package/contents/ui/EditProfileDialog.qml @@ -7,22 +7,44 @@ import QtQuick.Controls 2.12 as Controls import org.kde.kirigami 2.19 as Kirigami -import org.kde.plasma.mm as PlasmaMM +import org.kde.plasma.networkmanagement.cellular as Cellular Kirigami.Dialog { id: dialog - title: i18n("Edit APN") + title: editConnectionUni ? i18n("Edit APN") : i18n("Add APN") clip: true - property var profile + property Cellular.CellularModem modem + property string editConnectionUni: "" + + // Look up the profile data from the model when editing + property int _profileIndex: modem && editConnectionUni ? modem.profiles.indexOfConnection(editConnectionUni) : -1 standardButtons: Controls.Dialog.Ok | Controls.Dialog.Cancel + onOpened: { + if (_profileIndex >= 0) { + let idx = modem.profiles.index(_profileIndex, 0); + profileName.text = modem.profiles.data(idx, Cellular.CellularConnectionProfile.ConnectionName) ?? ""; + profileApn.text = modem.profiles.data(idx, Cellular.CellularConnectionProfile.ConnectionAPN) ?? ""; + profileUsername.text = modem.profiles.data(idx, Cellular.CellularConnectionProfile.ConnectionUser) ?? ""; + profilePassword.text = modem.profiles.data(idx, Cellular.CellularConnectionProfile.ConnectionPassword) ?? ""; + let nt = modem.profiles.data(idx, Cellular.CellularConnectionProfile.ConnectionNetworkType) ?? ""; + profileNetworkType.currentIndex = profileNetworkType.indexOfValue(nt); + } else { + profileName.text = ""; + profileApn.text = ""; + profileUsername.text = ""; + profilePassword.text = ""; + profileNetworkType.currentIndex = 0; + } + } + onAccepted: { - if (profile === null) { // create new profile - PlasmaMM.SignalIndicator.addProfile(profileName.text, profileApn.text, profileUsername.text, profilePassword.text, profileNetworkType.value); - } else { // edit existing profile - PlasmaMM.SignalIndicator.updateProfile(profile.connectionUni, profileName.text, profileApn.text, profileUsername.text, profilePassword.text, profileNetworkType.value); + if (!editConnectionUni) { + modem.addProfile(profileName.text, profileApn.text, profileUsername.text, profilePassword.text, profileNetworkType.currentValue); + } else { + modem.updateProfile(editConnectionUni, profileName.text, profileApn.text, profileUsername.text, profilePassword.text, profileNetworkType.currentValue); } } preferredWidth: Kirigami.Units.gridUnit * 20 @@ -36,30 +58,23 @@ Kirigami.Dialog { Controls.TextField { id: profileName Kirigami.FormData.label: i18n("Name") - text: profile !== null ? profile.name : "" } Controls.TextField { id: profileApn Kirigami.FormData.label: i18n("APN") - text: profile != null ? profile.apn : "" } Controls.TextField { id: profileUsername Kirigami.FormData.label: i18n("Username") - text: profile != null ? profile.user : "" } Controls.TextField { id: profilePassword Kirigami.FormData.label: i18n("Password") - text: profile != null ? profile.password : "" } Controls.ComboBox { id: profileNetworkType Kirigami.FormData.label: i18n("Network type") model: [i18n("4G/3G/2G"), i18n("3G/2G"), i18n("2G"), i18n("Only 4G"), i18n("Only 3G"), i18n("Only 2G"), i18n("Any")] - Component.onCompleted: if (profile !== null) { - currentIndex = indexOfValue(profile.networkType); - } } } } diff --git a/initialstart/modules/cellular/package/contents/ui/main.qml b/initialstart/modules/cellular/package/contents/ui/main.qml index ecc1d3c9..89d860db 100644 --- a/initialstart/modules/cellular/package/contents/ui/main.qml +++ b/initialstart/modules/cellular/package/contents/ui/main.qml @@ -7,30 +7,35 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard 1 as FormCard -import org.kde.plasma.mm as PlasmaMM +import org.kde.plasma.networkmanagement.cellular as Cellular import org.kde.plasma.mobileinitialstart.initialstart InitialStartModule { name: i18n("Cellular") - available: PlasmaMM.SignalIndicator.modemAvailable + available: modemList.modemAvailable contentItem: Item { id: root + Cellular.CellularModemList { + id: modemList + } + + property Cellular.CellularModem modem: modemList.primaryModem + readonly property real cardWidth: Math.min(Kirigami.Units.gridUnit * 30, root.width - Kirigami.Units.gridUnit * 2) function toggleMobileData() { - if (PlasmaMM.SignalIndicator.needsAPNAdded || !PlasmaMM.SignalIndicator.mobileDataSupported) { - // open settings if unable to toggle mobile data + if (!root.modem || root.modem.needsAPNAdded || !root.modem.mobileDataSupported) { MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_cellular_network"); } else { - PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled; + root.modem.mobileDataEnabled = !root.modem.mobileDataEnabled; } } EditProfileDialog { id: profileDialog - profile: null + modem: root.modem } ColumnLayout { @@ -51,11 +56,13 @@ InitialStartModule { wrapMode: Text.Wrap horizontalAlignment: Text.AlignHCenter text: { - if (PlasmaMM.SignalIndicator.needsAPNAdded) { + if (!root.modem) { + return i18n("Your device does not have a modem available."); + } else if (root.modem.needsAPNAdded) { return i18n("Please configure your APN below for mobile data, further information will be available with your carrier."); - } else if (PlasmaMM.SignalIndicator.mobileDataSupported) { + } else if (root.modem.mobileDataSupported) { return i18n("You are connected to the mobile network."); - } else if (PlasmaMM.SignalIndicator.simEmpty) { + } else if (root.modem.simEmpty) { return i18n("Please insert a SIM card into your device."); } else { return i18n("Your device does not have a modem available."); @@ -64,16 +71,16 @@ InitialStartModule { } FormCard.FormCard { - visible: PlasmaMM.SignalIndicator.modemAvailable && PlasmaMM.SignalIndicator.mobileDataSupported + visible: root.modem && root.modem.mobileDataSupported maximumWidth: root.cardWidth Layout.alignment: Qt.AlignTop | Qt.AlignHCenter FormCard.FormSwitchDelegate { text: i18n("Mobile Data") - checked: PlasmaMM.SignalIndicator.mobileDataEnabled + checked: root.modem ? root.modem.mobileDataEnabled : false onCheckedChanged: { - if (checked !== PlasmaMM.SignalIndicator.mobileDataEnabled) { + if (root.modem && checked !== root.modem.mobileDataEnabled) { root.toggleMobileData(); } } @@ -81,7 +88,7 @@ InitialStartModule { } FormCard.FormCard { - visible: PlasmaMM.SignalIndicator.modemAvailable && !PlasmaMM.SignalIndicator.simEmpty + visible: root.modem && !root.modem.simEmpty maximumWidth: root.cardWidth Layout.fillHeight: true @@ -95,18 +102,23 @@ InitialStartModule { Layout.fillWidth: true Layout.fillHeight: true - model: PlasmaMM.SignalIndicator.profiles + model: root.modem ? root.modem.profiles : null delegate: FormCard.FormRadioDelegate { + required property int index + required property string connectionName + required property string connectionAPN + required property string connectionUni + width: listView.width - text: modelData.name - description: modelData.apn - checked: modem.activeConnectionUni == modelData.connectionUni + text: connectionName + description: connectionAPN + checked: root.modem && root.modem.activeConnectionUni === connectionUni onCheckedChanged: { - if (checked) { - PlasmaMM.SignalIndicator.activateProfile(modelData.connectionUni); - checked = Qt.binding(() => { return modem.activeConnectionUni == modelData.connectionUni }); + if (checked && root.modem) { + root.modem.activateProfile(connectionUni); + checked = Qt.binding(() => { return root.modem && root.modem.activeConnectionUni === connectionUni }); } } @@ -115,14 +127,14 @@ InitialStartModule { icon.name: "entry-edit" text: i18n("Edit") onClicked: { - profileDialog.profile = modelData; + profileDialog.editConnectionUni = connectionUni; profileDialog.open(); } } ToolButton { icon.name: "delete" text: i18n("Delete") - onClicked: PlasmaMM.SignalIndicator.removeProfile(modelData.connectionUni) + onClicked: root.modem.removeProfile(connectionUni) } } } @@ -132,7 +144,7 @@ InitialStartModule { icon.name: "list-add" text: i18n("Add APN") onClicked: { - profileDialog.profile = null; + profileDialog.editConnectionUni = ""; profileDialog.open(); } } diff --git a/quicksettings/mobiledata/contents/ui/main.qml b/quicksettings/mobiledata/contents/ui/main.qml index 87f2060b..f5fc9ec2 100644 --- a/quicksettings/mobiledata/contents/ui/main.qml +++ b/quicksettings/mobiledata/contents/ui/main.qml @@ -3,21 +3,29 @@ import QtQuick 2.15 -import org.kde.plasma.mm as PlasmaMM +import org.kde.plasma.networkmanagement.cellular as Cellular import org.kde.plasma.private.mobileshell as MobileShell import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS QS.QuickSetting { + id: root + + Cellular.CellularModemList { + id: modemList + } + + property Cellular.CellularModem modem: modemList.primaryModem + text: i18n("Mobile Data") icon: "network-modem" status: { - if (!PlasmaMM.SignalIndicator.modemAvailable) { + if (!modemList.modemAvailable) { return i18n("Not Available"); - } else if (PlasmaMM.SignalIndicator.needsAPNAdded) { + } else if (modem.needsAPNAdded) { return i18n("APN needs to be configured in the settings"); - } else if (PlasmaMM.SignalIndicator.mobileDataSupported) { + } else if (modem.mobileDataSupported) { return enabled ? i18n("On") : i18n("Off"); - } else if (PlasmaMM.SignalIndicator.simEmpty) { + } else if (modem.simEmpty) { return i18n("No SIM inserted"); } else { return i18n("Not Available"); @@ -25,14 +33,14 @@ QS.QuickSetting { } settingsCommand: "plasma-open-settings kcm_cellular_network" - enabled: PlasmaMM.SignalIndicator.mobileDataEnabled + enabled: modem ? modem.mobileDataEnabled : false function toggle() { - if (PlasmaMM.SignalIndicator.needsAPNAdded || !PlasmaMM.SignalIndicator.mobileDataSupported) { + if (!modem || modem.needsAPNAdded || !modem.mobileDataSupported) { // open settings if unable to toggle mobile data MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_cellular_network"); } else { - PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled; + modem.mobileDataEnabled = !modem.mobileDataEnabled; } } }