Commit 4634aa6e authored by Jan Grulich's avatar Jan Grulich

Add option to allow managing virtual connections

If this option is enabled, users will see virtual connections in applet
and in the connection editor and they will be able to create new virtual
connections as well. This option is disabled by default as we don't want
regular users to be bothered by this.

BUG:376664
parent 24bd1664
......@@ -10,6 +10,10 @@
<label>If true request PIN code as soon as modem is detected.</label>
<default>true</default>
</entry>
<entry name="manageVirtualConnections" type="Bool">
<label>If true plasma-nm will be able to show and configure virtual connections.</label>
<default>false</default>
</entry>
</group>
</kcfg>
......@@ -30,6 +30,7 @@ Item {
signal configurationChanged
property alias cfg_unlockModemOnDetection: unlockModem.checked
property alias cfg_manageVirtualConnections: manageVirtualConnections.checked
Layouts.ColumnLayout {
id: mainColumn
......@@ -42,5 +43,14 @@ Item {
generalPage.configurationChanged()
}
}
Controls.CheckBox {
id: manageVirtualConnections
Layouts.Layout.fillWidth: true
text: i18n("Show and configure virtual connections")
onClicked: {
generalPage.configurationChanged()
}
}
}
}
......@@ -81,5 +81,6 @@ Item {
PlasmaNM.Configuration {
unlockModemOnDetection: plasmoid.configuration.unlockModemOnDetection
manageVirtualConnections: plasmoid.configuration.manageVirtualConnections
}
}
......@@ -10,6 +10,7 @@ set(plasmanm_internal_SRCS
models/networkmodel.cpp
models/networkmodelitem.cpp
configuration.cpp
debug.cpp
handler.cpp
uiutils.cpp
......
......@@ -23,33 +23,46 @@
#include <KConfigGroup>
#include <KSharedConfig>
Configuration::Configuration(QObject *parent)
: QObject(parent)
bool Configuration::unlockModemOnDetection()
{
KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("plasma-nm"));
KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
return grp.readEntry(QLatin1String("UnlockModemOnDetection"), true);
}
return true;
}
Configuration::~Configuration()
void Configuration::setUnlockModemOnDetection(bool unlock)
{
KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("plasma-nm"));
KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
grp.writeEntry(QLatin1String("UnlockModemOnDetection"), unlock);
}
}
bool Configuration::unlockModemOnDetection() const
bool Configuration::manageVirtualConnections()
{
KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("plasma-nm"));
KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
return grp.readEntry(QLatin1String("UnlockModemOnDetection"), true);
return grp.readEntry(QLatin1String("ManageVirtualConnections"), false);
}
return true;
}
void Configuration::setUnlockModemOnDetection(bool unlock)
void Configuration::setManageVirtualConnections(bool manage)
{
KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("plasma-nm"));
KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
grp.writeEntry(QLatin1String("UnlockModemOnDetection"), unlock);
grp.writeEntry(QLatin1String("ManageVirtualConnections"), manage);
}
}
......@@ -25,16 +25,17 @@
#include <NetworkManagerQt/Manager>
class Configuration : public QObject
class Q_DECL_EXPORT Configuration : public QObject
{
Q_PROPERTY(bool unlockModemOnDetection READ unlockModemOnDetection WRITE setUnlockModemOnDetection)
Q_PROPERTY(bool manageVirtualConnections READ manageVirtualConnections WRITE setManageVirtualConnections)
Q_OBJECT
public:
explicit Configuration(QObject *parent = 0);
virtual ~Configuration();
static bool unlockModemOnDetection();
static void setUnlockModemOnDetection(bool unlock);
bool unlockModemOnDetection() const;
void setUnlockModemOnDetection(bool unlock);
static bool manageVirtualConnections();
static void setManageVirtualConnections(bool manage);
};
#endif // PLAMA_NM_CONFIGURATION_H
......
......@@ -3,7 +3,6 @@ include_directories(${CMAKE_SOURCE_DIR}/libs/models)
set(plasmanm_qml_plugins_SRCS
availabledevices.cpp
connectionicon.cpp
configuration.cpp
enabledconnections.cpp
enums.cpp
networkstatus.cpp
......
......@@ -19,6 +19,7 @@
*/
#include "connectionicon.h"
#include "uiutils.h"
#include <NetworkManagerQt/BluetoothDevice>
#include <NetworkManagerQt/Connection>
......@@ -278,21 +279,7 @@ void ConnectionIcon::setStates()
}
if (!vpnConnection) {
#if NM_CHECK_VERSION(0, 9, 10)
if (activeConnection->state() == NetworkManager::ActiveConnection::Activating &&
activeConnection->type() != NetworkManager::ConnectionSettings::Bond &&
activeConnection->type() != NetworkManager::ConnectionSettings::Bridge &&
activeConnection->type() != NetworkManager::ConnectionSettings::Generic &&
activeConnection->type() != NetworkManager::ConnectionSettings::Infiniband &&
activeConnection->type() != NetworkManager::ConnectionSettings::Team &&
activeConnection->type() != NetworkManager::ConnectionSettings::Vlan) {
#else
if (activeConnection->state() == NetworkManager::ActiveConnection::Activating &&
activeConnection->type() != NetworkManager::ConnectionSettings::Bond &&
activeConnection->type() != NetworkManager::ConnectionSettings::Bridge &&
activeConnection->type() != NetworkManager::ConnectionSettings::Infiniband &&
activeConnection->type() != NetworkManager::ConnectionSettings::Vlan) {
#endif
if (activeConnection->state() == NetworkManager::ActiveConnection::Activating && UiUtils::isConnectionTypeSupported(activeConnection->type())) {
connecting = true;
}
} else {
......
......@@ -169,26 +169,8 @@ void NetworkStatus::changeActiveConnections()
});
Q_FOREACH (const NetworkManager::ActiveConnection::Ptr & active, activeConnectionList) {
#if NM_CHECK_VERSION(0, 9, 10)
if (!active->devices().isEmpty() &&
active->type() != NetworkManager::ConnectionSettings::Bond &&
active->type() != NetworkManager::ConnectionSettings::Bridge &&
active->type() != NetworkManager::ConnectionSettings::Generic &&
active->type() != NetworkManager::ConnectionSettings::Infiniband &&
active->type() != NetworkManager::ConnectionSettings::Team &&
#if NM_CHECK_VERSION(1, 1, 92)
active->type() != NetworkManager::ConnectionSettings::Vlan &&
active->type() != NetworkManager::ConnectionSettings::Tun) {
#else
active->type() != NetworkManager::ConnectionSettings::Vlan) {
#endif
#else
if (!active->devices().isEmpty() &&
active->type() != NetworkManager::ConnectionSettings::Bond &&
active->type() != NetworkManager::ConnectionSettings::Bridge &&
active->type() != NetworkManager::ConnectionSettings::Infiniband &&
active->type() != NetworkManager::ConnectionSettings::Vlan) {
#endif
if (!active->devices().isEmpty() && UiUtils::isConnectionTypeSupported(active->type())) {
NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(active->devices().first());
#if NM_CHECK_VERSION(0, 9, 10)
if (device && device->type() != NetworkManager::Device::Generic && device->type() <= NetworkManager::Device::Team) {
......
......@@ -43,6 +43,7 @@ set(plasmanm_editor_SRCS
simpleipv6addressvalidator.cpp
vpnuiplugin.cpp
../configuration.cpp
../debug.cpp
../uiutils.cpp
)
......
......@@ -20,6 +20,8 @@
#include "creatableconnectionsmodel.h"
#include "configuration.h"
#include <KLocalizedString>
#include <KService>
#include <KServiceTypeTrader>
......@@ -173,6 +175,32 @@ CreatableConnectionsModel::CreatableConnectionsModel(QObject *parent)
QString(), QString(), true); // VpnType and SpecificType are empty
m_list << connectionItem;
if (Configuration::manageVirtualConnections()) {
connectionItem = new CreatableConnectionItem(i18n("Bond"), i18n("Virtual connections"),
i18n("Some bond description"), QStringLiteral("network-wired"),
NetworkManager::ConnectionSettings::Bond,
QString(), QString(), true); // VpnType and SpecificType are empty
m_list << connectionItem;
connectionItem = new CreatableConnectionItem(i18n("Bridge"), i18n("Virtual connections"),
i18n("Some bond description"), QStringLiteral("network-wired"),
NetworkManager::ConnectionSettings::Bridge,
QString(), QString(), true); // VpnType and SpecificType are empty
m_list << connectionItem;
connectionItem = new CreatableConnectionItem(i18n("Team"), i18n("Virtual connections"),
i18n("Some team description"), QStringLiteral("network-wired"),
NetworkManager::ConnectionSettings::Team,
QString(), QString(), true); // VpnType and SpecificType are empty
m_list << connectionItem;
connectionItem = new CreatableConnectionItem(i18n("Vlan"), i18n("Virtual connections"),
i18n("Some vlan description"), QStringLiteral("network-wired"),
NetworkManager::ConnectionSettings::Vlan,
QString(), QString(), true); // VpnType and SpecificType are empty
m_list << connectionItem;
}
KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin");
std::sort(services.begin(), services.end(), [] (const KService::Ptr &left, const KService::Ptr &right)
......
......@@ -22,10 +22,13 @@
// Own
#include "uiutils.h"
#include "configuration.h"
#include "debug.h"
// KDE
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <NetworkManagerQt/BluetoothDevice>
#include <NetworkManagerQt/Manager>
......@@ -110,18 +113,22 @@ UiUtils::SortedConnectionType UiUtils::connectionTypeToSortedType(NetworkManager
bool UiUtils::isConnectionTypeSupported(NetworkManager::ConnectionSettings::ConnectionType type)
{
#if NM_CHECK_VERSION(1, 2, 0)
if (type == NetworkManager::ConnectionSettings::Generic || type == NetworkManager::ConnectionSettings::Tun) {
#else
if (type == NetworkManager::ConnectionSettings::Generic) {
#endif
return false;
}
bool manageVirtualConnections = Configuration::manageVirtualConnections();
if (type == NetworkManager::ConnectionSettings::Bond ||
type == NetworkManager::ConnectionSettings::Bridge ||
type == NetworkManager::ConnectionSettings::Generic ||
type == NetworkManager::ConnectionSettings::Infiniband ||
type == NetworkManager::ConnectionSettings::Team ||
#if NM_CHECK_VERSION(1, 2, 0)
type == NetworkManager::ConnectionSettings::Vlan ||
type == NetworkManager::ConnectionSettings::Tun) {
#else
type == NetworkManager::ConnectionSettings::Vlan) {
#endif
return false;
return manageVirtualConnections;
}
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment