diff --git a/libs/declarative/CMakeLists.txt b/libs/declarative/CMakeLists.txt --- a/libs/declarative/CMakeLists.txt +++ b/libs/declarative/CMakeLists.txt @@ -7,6 +7,8 @@ enums.cpp networkstatus.cpp qmlplugins.cpp + ../editor/mobileproviders.cpp + ../debug.cpp ) add_library(plasmanm_qmlplugins SHARED ${plasmanm_qml_plugins_SRCS}) diff --git a/libs/declarative/qmlplugins.cpp b/libs/declarative/qmlplugins.cpp --- a/libs/declarative/qmlplugins.cpp +++ b/libs/declarative/qmlplugins.cpp @@ -35,6 +35,8 @@ #include "networkmodel.h" #include "mobileproxymodel.h" +#include "../editor/mobileproviders.h" + #include "handler.h" #include "enums.h" @@ -66,4 +68,6 @@ qmlRegisterType(uri, 0, 2, "CreatableConnectionsModel"); // @uri org.kde.plasma.networkmanagement.MobileProxyModel qmlRegisterType(uri, 0, 2, "MobileProxyModel"); + // @uri org.kde.plasma.networkmanagement.MobileProviders + qmlRegisterType(uri, 0, 3, "MobileProviders"); } diff --git a/libs/editor/mobileproviders.h b/libs/editor/mobileproviders.h --- a/libs/editor/mobileproviders.h +++ b/libs/editor/mobileproviders.h @@ -28,27 +28,27 @@ #include -class MobileProviders +class MobileProviders : public QObject { public: static const QString ProvidersFile; enum ErrorCodes { Success, CountryCodesMissing, ProvidersMissing, ProvidersIsNull, ProvidersWrongFormat, ProvidersFormatNotSupported }; - MobileProviders(); + MobileProviders(QObject* parent = 0); ~MobileProviders(); - QStringList getCountryList() const; - QString countryFromLocale() const; - QString getCountryName(const QString & key) const { return mCountries.value(key); } - QStringList getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type); - QStringList getApns(const QString & provider); - QStringList getNetworkIds(const QString & provider); - QVariantMap getApnInfo(const QString & apn); - QVariantMap getCdmaInfo(const QString & provider); - QString getGsmNumber() const { return QString("*99#"); } - QString getCdmaNumber() const { return QString("#777"); } - inline ErrorCodes getError() { return mError; } + Q_INVOKABLE QStringList getCountryList() const; + Q_INVOKABLE QString countryFromLocale() const; + Q_INVOKABLE QString getCountryName(const QString & key) const { return mCountries.value(key); } + Q_INVOKABLE QStringList getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type); + Q_INVOKABLE QStringList getApns(const QString & provider); + Q_INVOKABLE QStringList getNetworkIds(const QString & provider); + Q_INVOKABLE QVariantMap getApnInfo(const QString & apn); + Q_INVOKABLE QVariantMap getCdmaInfo(const QString & provider); + Q_INVOKABLE QString getGsmNumber() const { return QString("*99#"); } + Q_INVOKABLE QString getCdmaNumber() const { return QString("#777"); } + Q_INVOKABLE inline ErrorCodes getError() { return mError; } private: QHash mCountries; diff --git a/libs/editor/mobileproviders.cpp b/libs/editor/mobileproviders.cpp --- a/libs/editor/mobileproviders.cpp +++ b/libs/editor/mobileproviders.cpp @@ -31,7 +31,8 @@ return one.localeAwareCompare(two) < 0; } -MobileProviders::MobileProviders() +MobileProviders::MobileProviders(QObject *parent) + : QObject(parent) { for (int c = 1; c <= QLocale::LastCountry; c++) { const auto country = static_cast(c); diff --git a/mobile/broadband/mobilebroadbandsettings.h b/mobile/broadband/mobilebroadbandsettings.h --- a/mobile/broadband/mobilebroadbandsettings.h +++ b/mobile/broadband/mobilebroadbandsettings.h @@ -36,7 +36,7 @@ Q_SIGNAL void mobileDataActiveChanged(bool active); Q_INVOKABLE QString getModemDevice(); void setupMobileNetwork(); - Q_INVOKABLE QString getAPN(); + Q_INVOKABLE QString getProvider(); private: bool m_mobileDataActive; diff --git a/mobile/broadband/mobilebroadbandsettings.cpp b/mobile/broadband/mobilebroadbandsettings.cpp --- a/mobile/broadband/mobilebroadbandsettings.cpp +++ b/mobile/broadband/mobilebroadbandsettings.cpp @@ -19,26 +19,26 @@ #include "mobilebroadbandsettings.h" -#include -#include #include +#include +#include +#include #include #include -#include #if WITH_MODEMMANAGER_SUPPORT -#include #include +#include #include #endif K_PLUGIN_CLASS_WITH_JSON(MobileBroadbandSettings, "mobilebroadbandsettings.json") -MobileBroadbandSettings::MobileBroadbandSettings(QObject* parent, const QVariantList& args) : KQuickAddons::ConfigModule(parent, args) +MobileBroadbandSettings::MobileBroadbandSettings(QObject *parent, const QVariantList &args) + : KQuickAddons::ConfigModule(parent, args) { - KAboutData* about = new KAboutData("kcm_mobile_broadband", i18n("Configure mobile broadband"), - "0.1", QString(), KAboutLicense::GPL); + KAboutData *about = new KAboutData("kcm_mobile_broadband", i18n("Configure mobile broadband"), "0.1", QString(), KAboutLicense::GPL); about->addAuthor(i18n("Martin Kacej"), QString(), "m.kacej@atlas.sk"); setAboutData(about); ModemManager::scanDevices(); @@ -101,9 +101,18 @@ } } -QString MobileBroadbandSettings::getAPN() +QString MobileBroadbandSettings::getProvider() { - return "some.ap.placeholder.com"; + ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(getModemDevice()); + if (!modem) { + // no modem detected + return ""; + } + if (!modem->sim()) { + // no sim detected + return ""; + } + return modem->sim()->operatorName(); } #include "mobilebroadbandsettings.moc" diff --git a/mobile/broadband/package/contents/ui/MobileSettings.qml b/mobile/broadband/package/contents/ui/MobileSettings.qml deleted file mode 100644 --- a/mobile/broadband/package/contents/ui/MobileSettings.qml +++ /dev/null @@ -1,82 +0,0 @@ - -/* - * Copyright 2018 Martin Kacej - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick 2.6 -import QtQuick.Controls 2.2 as Controls -import QtQuick.Layouts 1.3 -import org.kde.plasma.networkmanagement 0.2 as PlasmaNM -import org.kde.kirigami 2.2 as Kirigami - -Kirigami.Page { - ColumnLayout { - width: parent.width - spacing: Kirigami.Units.gridUnit * 1.5 - RowLayout { - width: parent.width - Controls.Label { - text: i18n("Enable mobile data network") - font.weight: Font.Bold - Layout.fillWidth: true - } - Controls.CheckBox { - id: mobileDataCheckbox - enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable - anchors.rightMargin: Kirigami.Units.gridUnit - } - } - RowLayout { - width: parent.width - enabled: mobileDataCheckbox.checked - Controls.Label { - text: i18n("Enable data roaming") - font.weight: Font.Bold - color: parent.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor - Layout.fillWidth: true - } - Controls.CheckBox { - enabled: parent.enabled - checked: false - anchors.rightMargin: Kirigami.Units.gridUnit - onEnabledChanged: { - if (!enabled) - checked = false - } - } - } - Kirigami.Separator {} - Column { - Controls.Label { - text: i18n("Access point name") - font.weight: Font.Bold - } - Row { - Controls.TextField { - text: kcm.getAPN() - } - Controls.ToolButton { - text: i18n("Edit APN") - } - } - } - Controls.Button { - text: i18n("Data usage") - } - } -} diff --git a/mobile/broadband/package/contents/ui/main.qml b/mobile/broadband/package/contents/ui/main.qml --- a/mobile/broadband/package/contents/ui/main.qml +++ b/mobile/broadband/package/contents/ui/main.qml @@ -1,5 +1,6 @@ /* * Copyright 2018 Martin Kacej + * Copyright 2020 Bhushan Shah * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,19 +20,13 @@ import QtQuick 2.6 import QtQuick.Controls 2.2 as Controls -import org.kde.plasma.networkmanagement 0.2 as PlasmaNM -import org.kde.kirigami 2.2 as Kirigami +import org.kde.plasma.networkmanagement 0.3 as PlasmaNM +import org.kde.kirigami 2.4 as Kirigami +import org.kde.kcm 1.2 -Kirigami.ApplicationItem { +ScrollViewKCM { id: main - objectName: "mobileDataMain" - - pageStack.defaultColumnWidth: Kirigami.Units.gridUnit * 25 - pageStack.initialPage: MobileSettings {} - Kirigami.Theme.colorSet: Kirigami.Theme.Window - - anchors.fill: parent - + PlasmaNM.Handler { id: handler } @@ -51,4 +46,41 @@ mobileDataCheckbox.enabled = enabled && availableDevices.modemDeviceAvailable } } + + PlasmaNM.MobileProviders { + id: mobileProviders + } + + Kirigami.FormLayout { + Controls.CheckBox { + id: mobileDataCheckbox + enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable + Kirigami.FormData.label: i18n("Enable mobile data network") + } + // Non functional for now + /*Controls.CheckBox { + enabled: mobileDataCheckbox.enabled + checked: false + onEnabledChanged: { + if (!enabled) + checked = false + } + Kirigami.FormData.label: i18n("Enable data roaming") + }*/ + Repeater { + enabled: mobileDataCheckbox.enabled + model: mobileProviders.getNetworkIds(kcm.getProvider()) + delegate: Controls.RadioDelegate { + Layout.fillWidth: true + text: modelData + checked: false + onCheckedChanged: { + if (checked) { + qDebug() << "Activating " << modelData; + // activating this provider then: kcm.setupMobileNetwork(model) + } + } + } + } + } }