Index: autotests/settings/CMakeLists.txt =================================================================== --- autotests/settings/CMakeLists.txt +++ autotests/settings/CMakeLists.txt @@ -21,8 +21,10 @@ olpcmeshsettingtest pppsettingtest pppoesettingtest + proxysettingtest serialsettingtest tunsettingtest + usersettingtest vlansettingtest vxlansettingtest vpnsettingtest Index: autotests/settings/proxysettingtest.h =================================================================== --- /dev/null +++ autotests/settings/proxysettingtest.h @@ -0,0 +1,36 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_PROXY_SETTING_TEST_H +#define NETWORKMANAGERQT_PROXY_SETTING_TEST_H + +#include + +class ProxySettingTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSetting_data(); + void testSetting(); +}; + +#endif // NETWORKMANAGERQT_PROXY_SETTING_TEST_H + Index: autotests/settings/proxysettingtest.cpp =================================================================== --- /dev/null +++ autotests/settings/proxysettingtest.cpp @@ -0,0 +1,70 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "proxysettingtest.h" + +#include "settings/proxysetting.h" + +#include + +#include + +void ProxySettingTest::testSetting_data() +{ + QTest::addColumn("browserOnly"); + QTest::addColumn("method"); + QTest::addColumn("pacScript"); + QTest::addColumn("pacUrl"); + + QTest::newRow("setting1") + << false // browserOnly + << (quint32)1 // method + << QString("script") // pacScript + << QString("url"); // pacUrl +} + +void ProxySettingTest::testSetting() +{ + QFETCH(bool, browserOnly); + QFETCH(quint32, method); + QFETCH(QString, pacScript); + QFETCH(QString, pacUrl); + + QVariantMap map; + + map.insert(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY), browserOnly); + map.insert(QLatin1String(NM_SETTING_PROXY_METHOD), method); + map.insert(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT), pacScript); + map.insert(QLatin1String(NM_SETTING_PROXY_PAC_URL), pacUrl); + + NetworkManager::ProxySetting setting; + setting.fromMap(map); + + QVariantMap map1 = setting.toMap(); + + // Will fail if set some default values, because they are skipped in toMap() method + QVariantMap::const_iterator it = map.constBegin(); + while (it != map.constEnd()) { + QCOMPARE(it.value(), map1.value(it.key())); + ++it; + } +} + +QTEST_MAIN(ProxySettingTest) \ No newline at end of file Index: autotests/settings/usersettingtest.h =================================================================== --- /dev/null +++ autotests/settings/usersettingtest.h @@ -0,0 +1,35 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_USER_SETTING_TEST_H +#define NETWORKMANAGERQT_USER_SETTING_TEST_H + +#include + +class UserSettingTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSetting_data(); + void testSetting(); +}; + +#endif // NETWORKMANAGERQT_USER_SETTING_TEST_H Index: autotests/settings/usersettingtest.cpp =================================================================== --- /dev/null +++ autotests/settings/usersettingtest.cpp @@ -0,0 +1,63 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "usersettingtest.h" + +#include "settings/usersetting.h" + +#include + +#include + +void UserSettingTest::testSetting_data() +{ + QTest::addColumn("data"); + + NMStringMap data; + data.insert("dat", "abc"); + + QTest::newRow("setting1") + << data; // data +} + +void UserSettingTest::testSetting() +{ + QFETCH(NMStringMap, data); + + QVariantMap map; + + map.insert(QLatin1String(NM_SETTING_USER_DATA), QVariant::fromValue(data)); + + NetworkManager::UserSetting setting; + setting.fromMap(map); + + QVariantMap map1 = setting.toMap(); + + NMStringMap stringMap1 = map.value(QLatin1String(NM_SETTING_USER_DATA)).value(); + NMStringMap stringMap2 = map1.value(QLatin1String(NM_SETTING_USER_DATA)).value(); + + NMStringMap::const_iterator it = stringMap1.constBegin(); + while (it != stringMap1.constEnd()) { + QCOMPARE(it.value(), stringMap2.value(it.key())); + ++it; + } +} + +QTEST_MAIN(UserSettingTest) \ No newline at end of file Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -66,6 +66,7 @@ settings/olpcmeshsetting.cpp settings/pppsetting.cpp settings/pppoesetting.cpp + settings/proxysetting.cpp settings/setting.cpp settings/serialsetting.cpp settings/security8021xsetting.cpp @@ -79,6 +80,7 @@ settings/teamsetting.cpp settings/genericsetting.cpp settings/tunsetting.cpp + settings/usersetting.cpp settings/vxlansetting.cpp ) Index: src/settings/iptunnelsetting.cpp =================================================================== --- src/settings/iptunnelsetting.cpp +++ src/settings/iptunnelsetting.cpp @@ -32,7 +32,7 @@ , mode(IpTunnelSetting::Unknown) , pathMtuDiscovery(true) , encapsulationLimit(0) - , flags(IpTunnelSetting::Unknown) + , flags(IpTunnelSetting::None) , flowLabel(0) , mtu(0) , tos(0) Index: src/settings/proxysetting.h =================================================================== --- src/settings/proxysetting.h +++ src/settings/proxysetting.h @@ -32,13 +32,18 @@ class ProxySettingPrivate; /** - * Represents generic setting + * Represents proxy setting */ class NETWORKMANAGERQT_EXPORT ProxySetting : public Setting { public: typedef QSharedPointer Ptr; typedef QList List; + enum Mode + { + None = NM_SETTING_PROXY_METHOD_NONE, + Auto = NM_SETTING_PROXY_METHOD_AUTO + }; ProxySetting(); explicit ProxySetting(const Ptr &other); @@ -49,8 +54,8 @@ void setBrowserOnly(bool browserOnly); bool browserOnly() const; - void setMethod(quint32 method); - quint32 method() const; + void setMethod(Mode method); + Mode method() const; void setPacScript(const QString &script); QString pacScript() const; Index: src/settings/proxysetting.cpp =================================================================== --- src/settings/proxysetting.cpp +++ src/settings/proxysetting.cpp @@ -23,10 +23,19 @@ #include +#if NM_CHECK_VERSION(1, 16, 0) +#define NM_SETTING_PROXY_SETTING_NAME "proxy" +#define NM_SETTING_PROXY_BROWSER_ONLY "browser-only" +#define NM_SETTING_PROXY_METHOD "method" +#define NM_SETTING_PROXY_PAC_SCRIPT "pac-script" +#define NM_SETTING_PROXY_PAC_URL "pac-url" +#endif + + NetworkManager::ProxySettingPrivate::ProxySettingPrivate() : name(NM_SETTING_PROXY_SETTING_NAME) , browserOnly(true) - , method(0) + , method(ProxySetting::None) { } NetworkManager::ProxySetting::ProxySetting() @@ -70,14 +79,14 @@ return d->browserOnly; } -void NetworkManager::ProxySetting::setMethod(quint32 method) +void NetworkManager::ProxySetting::setMethod(NetworkManager::ProxySetting::Mode method) { Q_D(ProxySetting); d->method = method; } -quint32 NetworkManager::ProxySetting::method() const +NetworkManager::ProxySetting::Mode NetworkManager::ProxySetting::method() const { Q_D(const ProxySetting); @@ -119,7 +128,7 @@ } if (setting.contains(QLatin1String(NM_SETTING_PROXY_METHOD))) { - setMethod(setting.value(QLatin1String(NM_SETTING_PROXY_METHOD)).toUInt()); + setMethod((Mode)setting.value(QLatin1String(NM_SETTING_PROXY_METHOD)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT))) { @@ -138,7 +147,7 @@ setting.insert(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY), browserOnly()); if (method() > 0) { - setting.insert(QLatin1String(NM_SETTING_PROXY_METHOD), method()); + setting.insert(QLatin1String(NM_SETTING_PROXY_METHOD), (int)method()); } if (!pacScript().isEmpty()) { Index: src/settings/proxysetting_p.h =================================================================== --- src/settings/proxysetting_p.h +++ src/settings/proxysetting_p.h @@ -34,7 +34,7 @@ QString name; bool browserOnly; - quint32 method; + NetworkManager::ProxySetting::Mode method; QString pacScript; QString pacUrl; }; Index: src/settings/setting.h =================================================================== --- src/settings/setting.h +++ src/settings/setting.h @@ -73,7 +73,9 @@ Generic, Tun, Vxlan, - IpTunnel + IpTunnel, + Proxy, + User }; enum SecretFlagType { Index: src/settings/setting.cpp =================================================================== --- src/settings/setting.cpp +++ src/settings/setting.cpp @@ -121,6 +121,12 @@ case IpTunnel: typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME); break; + case Proxy: + typeString = QLatin1String(NM_SETTING_PROXY_SETTING_NAME); + break; + case User: + typeString = QLatin1String(NM_SETTING_USER_SETTING_NAME); + break; case NetworkManager::Setting::Generic: typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME); break; @@ -179,6 +185,10 @@ type = IpTunnel; } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { type = Generic; + } else if (typeString == QLatin1String(NM_SETTING_USER_SETTING_NAME)) { + type = User; + } else if (typeString == QLatin1String(NM_SETTING_PROXY_SETTING_NAME)) { + type = Proxy; } return type; Index: src/settings/usersetting.h =================================================================== --- src/settings/usersetting.h +++ src/settings/usersetting.h @@ -32,7 +32,7 @@ class UserSettingPrivate; /** - * Represents generic setting + * Represents user setting */ class NETWORKMANAGERQT_EXPORT UserSetting : public Setting { @@ -50,8 +50,6 @@ void setData(const NMStringMap &data); NMStringMap data() const; - - void fromMap(const QVariantMap &setting) override; QVariantMap toMap() const override; Index: src/settings/usersetting.cpp =================================================================== --- src/settings/usersetting.cpp +++ src/settings/usersetting.cpp @@ -23,8 +23,13 @@ #include +#if NM_CHECK_VERSION(1, 8, 0) +#define NM_SETTING_USER_SETTING_NAME "user" +#define NM_SETTING_USER_DATA "data" +#endif + NetworkManager::UserSettingPrivate::UserSettingPrivate() - : name(NM_SETTING_IP_TUNNEL_SETTING_NAME) + : name(NM_SETTING_USER_SETTING_NAME) { } NetworkManager::UserSetting::UserSetting() Index: src/settings/usersetting_p.h =================================================================== --- /dev/null +++ src/settings/usersetting_p.h @@ -0,0 +1,42 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_USER_SETTING_P_H +#define NETWORKMANAGERQT_USER_SETTING_P_H + +#include + +namespace NetworkManager +{ + +class UserSettingPrivate +{ +public: + UserSettingPrivate(); + + QString name; + + NMStringMap data; +}; + +} + +#endif // NETWORKMANAGERQT_USER_SETTING_P_H +