Commit 6d22ea88 authored by Jan Grulich's avatar Jan Grulich

Merge remote-tracking branch 'plasma-mobile/master'

parents 0ccf86e0 8b14b10a
.gitignore
*.directory
*~
.*.sw[p,o]
......@@ -6,3 +7,5 @@ tags
.swp.*
.kdev4/
*.kdev4
CMakeLists.txt.user
*.qmlc
......@@ -95,6 +95,7 @@ add_subdirectory(kded)
add_subdirectory(kcm)
add_subdirectory(libs)
add_subdirectory(vpn)
add_subdirectory(mobile)
# Enable unit testing
if (BUILD_TESTING)
......
plasma_install_bundled_package(. org.kde.plasma.networkmanagement)
plasma_install_package(. org.kde.plasma.networkmanagement)
......@@ -5,6 +5,7 @@ set(plasmanm_internal_SRCS
models/creatableconnectionsmodel.cpp
models/editorproxymodel.cpp
models/kcmidentitymodel.cpp
models/mobileproxymodel.cpp
models/networkitemslist.cpp
models/networkmodel.cpp
models/networkmodelitem.cpp
......
......@@ -33,6 +33,7 @@
#include "editorproxymodel.h"
#include "kcmidentitymodel.h"
#include "networkmodel.h"
#include "mobileproxymodel.h"
#include "handler.h"
#include "enums.h"
......@@ -63,4 +64,6 @@ void QmlPlugins::registerTypes(const char* uri)
qmlRegisterType<KcmIdentityModel>(uri, 0, 2, "KcmIdentityModel");
// @uri org.kde.plasma.networkmanagement.CreatableConnectionsModel
qmlRegisterType<CreatableConnectionsModel>(uri, 0, 2, "CreatableConnectionsModel");
// @uri org.kde.plasma.networkmanagement.MobileProxyModel
qmlRegisterType<MobileProxyModel>(uri, 0, 2, "MobileProxyModel");
}
......@@ -29,12 +29,14 @@
#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Setting>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/Utils>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/GsmSetting>
#include <NetworkManagerQt/WiredSetting>
#include <NetworkManagerQt/WirelessSetting>
#include <NetworkManagerQt/ActiveConnection>
#include <NetworkManagerQt/Ipv4Setting>
#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/Manager>
......@@ -518,3 +520,4 @@ void Handler::unlockRequiredChanged(MMModemLock modemLock)
}
}
#endif
......@@ -24,6 +24,8 @@
#include <QDBusInterface>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/ConnectionSettings>
#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/GenericTypes>
#endif
......@@ -84,6 +86,7 @@ public Q_SLOTS:
void enableAirplaneMode(bool enable);
void enableNetworking(bool enable);
void enableWireless(bool enable);
void enableWwan(bool enable);
/**
......@@ -118,6 +121,7 @@ private:
QMap<QString, bool> m_bluetoothAdapters;
void enableBluetooth(bool enable);
};
#endif // PLASMA_NM_HANDLER_H
......@@ -28,7 +28,7 @@
class Q_DECL_EXPORT AppletProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
public:
explicit AppletProxyModel(QObject *parent = nullptr);
~AppletProxyModel() override;
......
/*
* Mobile proxy model - model for displaying netwoks in mobile kcm
* Copyright 2017 Martin Kacej <m.kacej@atlas.sk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "mobileproxymodel.h"
#include "networkmodel.h"
#include "networkmodelitem.h"
#include "uiutils.h"
MobileProxyModel::MobileProxyModel(QObject* parent)
: QSortFilterProxyModel(parent)
{
setDynamicSortFilter(true);
sort(0, Qt::DescendingOrder);
}
MobileProxyModel::~MobileProxyModel()
{
}
void MobileProxyModel::setShowSavedMode(bool mode){
m_showSavedMode = mode;
emit showSavedModeChanged(mode);
invalidate();
}
bool MobileProxyModel::showSavedMode() const{
return m_showSavedMode;
}
bool MobileProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
// slaves are always filtered-out
const bool isSlave = sourceModel()->data(index, NetworkModel::SlaveRole).toBool();
if (isSlave) {
return false;
}
const NetworkManager::ConnectionSettings::ConnectionType type = (NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(index, NetworkModel::TypeRole).toUInt();
if (type == NetworkManager::ConnectionSettings::Wireless) {
NetworkModelItem::ItemType itemType = (NetworkModelItem::ItemType)sourceModel()->data(index, NetworkModel::ItemTypeRole).toUInt();
if (showSavedMode()) {
return itemType == NetworkModelItem::UnavailableConnection;
} else {
if (sourceModel()->data(index,NetworkModel::SignalRole).toUInt() == 0)
return false; // if signal is 0 yet we still have connection, it means local access point -> we dont want to show that
return itemType >= NetworkModelItem::AvailableConnection;
}
}
return false;
}
bool MobileProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
{
const bool leftAvailable = (NetworkModelItem::ItemType)sourceModel()->data(left, NetworkModel::ItemTypeRole).toUInt() != NetworkModelItem::UnavailableConnection;
const bool leftConnected = sourceModel()->data(left, NetworkModel::ConnectionStateRole).toUInt() == NetworkManager::ActiveConnection::Activated;
const int leftConnectionState = sourceModel()->data(left, NetworkModel::ConnectionStateRole).toUInt();
const QString leftName = sourceModel()->data(left, NetworkModel::NameRole).toString();
const QString leftUuid = sourceModel()->data(left, NetworkModel::UuidRole).toString();
const int leftSignal = sourceModel()->data(left, NetworkModel::SignalRole).toInt();
const QDateTime leftDate = sourceModel()->data(left, NetworkModel::TimeStampRole).toDateTime();
const bool rightAvailable = (NetworkModelItem::ItemType)sourceModel()->data(right, NetworkModel::ItemTypeRole).toUInt() != NetworkModelItem::UnavailableConnection;
const bool rightConnected = sourceModel()->data(right, NetworkModel::ConnectionStateRole).toUInt() == NetworkManager::ActiveConnection::Activated;
const int rightConnectionState = sourceModel()->data(right, NetworkModel::ConnectionStateRole).toUInt();
const QString rightName = sourceModel()->data(right, NetworkModel::NameRole).toString();
const QString rightUuid = sourceModel()->data(right, NetworkModel::UuidRole).toString();
const int rightSignal = sourceModel()->data(right, NetworkModel::SignalRole).toInt();
const QDateTime rightDate = sourceModel()->data(right, NetworkModel::TimeStampRole).toDateTime();
if (leftAvailable < rightAvailable) {
return true;
} else if (leftAvailable > rightAvailable) {
return false;
}
if (leftConnected < rightConnected) {
return true;
} else if (leftConnected > rightConnected) {
return false;
}
if (leftConnectionState > rightConnectionState) {
return true;
} else if (leftConnectionState < rightConnectionState) {
return false;
}
if (leftUuid.isEmpty() && !rightUuid.isEmpty()) {
return true;
} else if (!leftUuid.isEmpty() && rightUuid.isEmpty()) {
return false;
}
if (leftDate > rightDate) {
return false;
} else if (leftDate < rightDate) {
return true;
}
if (leftSignal < rightSignal) {
return true;
} else if (leftSignal > rightSignal) {
return false;
}
if (QString::localeAwareCompare(leftName, rightName) > 0) {
return true;
} else {
return false;
}
}
/*
* Mobile proxy model - model for displaying netwoks in mobile kcm
* Copyright 2017 Martin Kacej <m.kacej@atlas.sk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PLASMA_NM_MOBILE_PROXY_MODEL_H
#define PLASMA_NM_MOBILE_PROXY_MODEL_H
#include <QSortFilterProxyModel>
class Q_DECL_EXPORT MobileProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
Q_PROPERTY(bool showSavedMode READ showSavedMode WRITE setShowSavedMode NOTIFY showSavedModeChanged)
public:
explicit MobileProxyModel(QObject* parent = 0);
virtual ~MobileProxyModel();
void setShowSavedMode(bool mode);
bool showSavedMode() const;
signals:
void showSavedModeChanged(bool mode);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const Q_DECL_OVERRIDE;
bool lessThan(const QModelIndex& left, const QModelIndex& right) const Q_DECL_OVERRIDE;
private:
bool m_showSavedMode;
};
#endif // PLASMA_NM_MOBILE_PROXY_MODEL_H
if (KF5ModemManagerQt_FOUND)
add_subdirectory(broadband)
endif()
add_subdirectory(wifi)
project (kcm_mobile_broadband)
set (mobilebroadbandsettings_SRCS mobilebroadbandsettings.cpp)
add_library(kcm_mobile_broadband MODULE ${mobilebroadbandsettings_SRCS})
target_link_libraries(kcm_mobile_broadband
Qt5::DBus
Qt5::Gui
Qt5::Quick
Qt5::Qml
KF5::Plasma
KF5::I18n
KF5::QuickAddons
KF5::NetworkManagerQt
KF5::ModemManagerQt
)
kcoreaddons_desktop_to_json(kcm_mobile_broadband "mobilebroadbandsettings.desktop")
install(FILES mobilebroadbandsettings.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install(TARGETS kcm_mobile_broadband DESTINATION ${PLUGIN_INSTALL_DIR}/kcms)
kpackage_install_package(package kcm_mobile_broadband kcms)
/*
* Copyright 2018 Martin Kacej <m.kacej@atlas.sk>
*
* 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.
*/
#include "mobilebroadbandsettings.h"
#include <KPluginFactory>
#include <KLocalizedString>
#include <KAboutData>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/GsmSetting>
#include <NetworkManagerQt/CdmaSetting>
#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/Manager>
#include <ModemManagerQt/GenericTypes>
#include <ModemManagerQt/ModemDevice>
#endif
K_PLUGIN_FACTORY_WITH_JSON(MobileBroadbandSettingsFactory, "mobilebroadbandsettings.json", registerPlugin<MobileBroadbandSettings>();)
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);
about->addAuthor(i18n("Martin Kacej"), QString(), "m.kacej@atlas.sk");
setAboutData(about);
ModemManager::scanDevices();
this->getModemDevice();
this->setupMobileNetwork();
}
MobileBroadbandSettings::~MobileBroadbandSettings()
{
}
bool MobileBroadbandSettings::mobileDataActive()
{
return m_mobileDataActive;
}
void MobileBroadbandSettings::setMobileDataActive(bool active)
{
m_mobileDataActive = active;
emit mobileDataActiveChanged(m_mobileDataActive);
}
QString MobileBroadbandSettings::getModemDevice()
{
ModemManager::ModemDevice::List list = ModemManager::modemDevices();
if (list.length() == 0)
return QString();
ModemManager::ModemDevice::Ptr device;
foreach (const ModemManager::ModemDevice::Ptr &md, list) {
ModemManager::Modem::Ptr m = md->modemInterface();
if (!m->isEnabled())
continue;
// TODO powerState ???
if (m->state() <= MM_MODEM_STATE_REGISTERED)
continue; // needs inspection
if (m->accessTechnologies() <= MM_MODEM_ACCESS_TECHNOLOGY_GSM)
continue;
if (m->currentCapabilities() <= MM_MODEM_CAPABILITY_GSM_UMTS)
continue;
device = md;
}
if (device) {
qWarning() << device->uni() << device->modemInterface()->uni();
return device->uni();
}
return QString();
}
void MobileBroadbandSettings::setupMobileNetwork()
{
ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(getModemDevice());
if (!modem)
return;
if (modem->bearers().count() == 0) {
qWarning() << "No bearers in modem found";
} else {
foreach (const ModemManager::Bearer::Ptr &p, modem->bearers()) {
qWarning() << p->properties();
}
}
}
QString MobileBroadbandSettings::getAPN()
{
return "some.ap.placeholder.com";
}
#include "mobilebroadbandsettings.moc"
[Desktop Entry]
Name=Mobile broadband
Comment=Mobile broadband setting
Icon=smartphone
Exec=plasma-settings -m kcm_mobile_broadband
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kcm_mobile_broadband
X-KDE-ParentApp=kcontrol
X-KDE-FormFactors=handset,tablet,mediacenter
X-KDE-System-Settings-Parent-Category=network
X-KDE-Weight=70
X-KDE-Keywords=mobile,data,network
Categories=Qt;KDE;X-KDE-settings-system;
/*
* Copyright 2018 Martin Kacej <m.kacej@atlas.sk>
*
* 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.
*/
#ifndef MOBILEBROADBANDSETTINGS_H
#define MOBILEBROADBANDSETTINGS_H
#include <KQuickAddons/ConfigModule>
class MobileBroadbandSettings : public KQuickAddons::ConfigModule
{
Q_OBJECT
Q_PROPERTY(bool mobileDataActive READ mobileDataActive WRITE setMobileDataActive NOTIFY mobileDataActiveChanged)
public:
MobileBroadbandSettings(QObject *parent, const QVariantList &args);
virtual ~MobileBroadbandSettings();
bool mobileDataActive();
void setMobileDataActive(bool active);
Q_SIGNAL void mobileDataActiveChanged(bool active);
Q_INVOKABLE QString getModemDevice();
void setupMobileNetwork();
Q_INVOKABLE QString getAPN();
private:
bool m_mobileDataActive;
};
#endif // MOBILEBROADBANDSETTINGS_H
/*
* Copyright 2018 Martin Kacej <m.kacej@atlas.sk>
*
* 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")
}
}
}
/*
* Copyright 2018 Martin Kacej <m.kacej@atlas.sk>
*
* 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 org.kde.plasma.networkmanagement 0.2 as PlasmaNM
import org.kde.kirigami 2.2 as Kirigami
Kirigami.ApplicationItem {
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
}
PlasmaNM.AvailableDevices {
id: availableDevices
}
PlasmaNM.EnabledConnections {
id: enabledConnections
onWwanEnabledChanged: {
mobileDataCheckbox.checked = mobileDataCheckbox.enabled && enabled
}
onWwanHwEnabledChanged: {
mobileDataCheckbox.enabled = enabled && availableDevices.modemDeviceAvailable
}
}
}
[Desktop Entry]
Name=Mobile Broadband
Comment=Mobile broadband setting