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/proxysetting.h =================================================================== --- /dev/null +++ src/settings/proxysetting.h @@ -0,0 +1,77 @@ +/* + 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_H +#define NETWORKMANAGERQT_PROXY_SETTING_H + +#include +#include "setting.h" + +#include + +namespace NetworkManager +{ + +class ProxySettingPrivate; + +/** + * Represents generic setting + */ +class NETWORKMANAGERQT_EXPORT ProxySetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + ProxySetting(); + explicit ProxySetting(const Ptr &other); + ~ProxySetting() override; + + QString name() const override; + + void setBrowserOnly(bool browserOnly); + bool browserOnly() const; + + void setMethod(quint32 method); + quint32 method() const; + + void setPacScript(const QString &script); + QString pacScript() const; + + void setPacUrl(const QString &url); + QString pacUrl() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + ProxySettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(ProxySetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const ProxySetting &setting); + +} + +#endif // NETWORKMANAGERQT_PROXY_SETTING_H + Index: src/settings/proxysetting.cpp =================================================================== --- /dev/null +++ src/settings/proxysetting.cpp @@ -0,0 +1,166 @@ +/* + Copyright 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 "proxysetting.h" +#include "proxysetting_p.h" + +#include + +NetworkManager::ProxySettingPrivate::ProxySettingPrivate() + : name(NM_SETTING_PROXY_SETTING_NAME) + , browserOnly(true) + , method(0) +{ } + +NetworkManager::ProxySetting::ProxySetting() + : Setting(Setting::Proxy) + , d_ptr(new ProxySettingPrivate()) +{ } + +NetworkManager::ProxySetting::ProxySetting(const Ptr &other) + : Setting(other) + , d_ptr(new ProxySettingPrivate()) +{ + setBrowserOnly(other->browserOnly()); + setMethod(other->method()); + setPacScript(other->pacScript()); + setPacUrl(other->pacUrl()); +} + +NetworkManager::ProxySetting::~ProxySetting() +{ + delete d_ptr; +} + +QString NetworkManager::ProxySetting::name() const +{ + Q_D(const ProxySetting); + + return d->name; +} + +void NetworkManager::ProxySetting::setBrowserOnly(bool browserOnly) +{ + Q_D(ProxySetting); + + d->browserOnly = browserOnly; +} + +bool NetworkManager::ProxySetting::browserOnly() const +{ + Q_D(const ProxySetting); + + return d->browserOnly; +} + +void NetworkManager::ProxySetting::setMethod(quint32 method) +{ + Q_D(ProxySetting); + + d->method = method; +} + +quint32 NetworkManager::ProxySetting::method() const +{ + Q_D(const ProxySetting); + + return d->method; +} + +void NetworkManager::ProxySetting::setPacScript(const QString &script) +{ + Q_D(ProxySetting); + + d->pacScript = script; +} + +QString NetworkManager::ProxySetting::pacScript() const +{ + Q_D(const ProxySetting); + + return d->pacScript; +} + +void NetworkManager::ProxySetting::setPacUrl(const QString &url) +{ + Q_D(ProxySetting); + + d->pacUrl = url; +} + +QString NetworkManager::ProxySetting::pacUrl() const +{ + Q_D(const ProxySetting); + + return d->pacUrl; +} + +void NetworkManager::ProxySetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY))) { + setBrowserOnly(setting.value(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PROXY_METHOD))) { + setMethod(setting.value(QLatin1String(NM_SETTING_PROXY_METHOD)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT))) { + setPacScript(setting.value(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_URL))) { + setPacUrl(setting.value(QLatin1String(NM_SETTING_PROXY_PAC_URL)).toString()); + } +} + +QVariantMap NetworkManager::ProxySetting::toMap() const +{ + QVariantMap setting; + + setting.insert(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY), browserOnly()); + + if (method() > 0) { + setting.insert(QLatin1String(NM_SETTING_PROXY_METHOD), method()); + } + + if (!pacScript().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT), pacScript()); + } + + if (!pacUrl().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PROXY_PAC_URL), pacUrl()); + } + + return setting; +} + +QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::ProxySetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_PROXY_BROWSER_ONLY << ": " << setting.browserOnly() << '\n'; + dbg.nospace() << NM_SETTING_PROXY_METHOD << ": " << setting.method() << '\n'; + dbg.nospace() << NM_SETTING_PROXY_PAC_SCRIPT << ": " << setting.pacScript() << '\n'; + dbg.nospace() << NM_SETTING_PROXY_PAC_URL << ": " << setting.pacUrl() << '\n'; + + return dbg.maybeSpace(); +} Index: src/settings/proxysetting_p.h =================================================================== --- /dev/null +++ src/settings/proxysetting_p.h @@ -0,0 +1,45 @@ +/* + 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_P_H +#define NETWORKMANAGERQT_PROXY_SETTING_P_H + +#include + +namespace NetworkManager +{ + +class ProxySettingPrivate +{ +public: + ProxySettingPrivate(); + + QString name; + + bool browserOnly; + quint32 method; + QString pacScript; + QString pacUrl; +}; + +} + +#endif // NETWORKMANAGERQT_PROXY_SETTING_P_H + 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 =================================================================== --- /dev/null +++ src/settings/usersetting.h @@ -0,0 +1,71 @@ +/* + 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_H +#define NETWORKMANAGERQT_USER_SETTING_H + +#include +#include "setting.h" + +#include + +namespace NetworkManager +{ + +class UserSettingPrivate; + +/** + * Represents generic setting + */ +class NETWORKMANAGERQT_EXPORT UserSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + UserSetting(); + explicit UserSetting(const Ptr &other); + ~UserSetting() override; + + QString name() const override; + + void addData(const QString &data, const QString &value); + void setData(const NMStringMap &data); + NMStringMap data() const; + + + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + UserSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(UserSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const UserSetting &setting); + +} + +#endif // NETWORKMANAGERQT_USER_SETTING_H + Index: src/settings/usersetting.cpp =================================================================== --- /dev/null +++ src/settings/usersetting.cpp @@ -0,0 +1,102 @@ +/* + Copyright 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 "usersetting.h" +#include "usersetting_p.h" + +#include + +NetworkManager::UserSettingPrivate::UserSettingPrivate() + : name(NM_SETTING_IP_TUNNEL_SETTING_NAME) +{ } + +NetworkManager::UserSetting::UserSetting() + : Setting(Setting::User) + , d_ptr(new UserSettingPrivate()) +{ } + +NetworkManager::UserSetting::UserSetting(const Ptr &other) + : Setting(other) + , d_ptr(new UserSettingPrivate()) +{ + setData(other->data()); +} + +NetworkManager::UserSetting::~UserSetting() +{ + delete d_ptr; +} + +QString NetworkManager::UserSetting::name() const +{ + Q_D(const UserSetting); + + return d->name; +} + +void NetworkManager::UserSetting::addData(const QString &data, const QString &value) +{ + Q_D(UserSetting); + + d->data.insert(data, value); +} + +void NetworkManager::UserSetting::setData(const NMStringMap &data) +{ + Q_D(UserSetting); + + d->data = data; +} + +NMStringMap NetworkManager::UserSetting::data() const +{ + Q_D(const UserSetting); + + return d->data; +} + +void NetworkManager::UserSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_USER_DATA))) { + setData(qdbus_cast(setting.value(QLatin1String(NM_SETTING_USER_DATA)))); + } +} + +QVariantMap NetworkManager::UserSetting::toMap() const +{ + QVariantMap setting; + + if (!data().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_USER_DATA), QVariant::fromValue(data())); + } + + + return setting; +} + +QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::UserSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_USER_DATA << ": " << setting.data() << '\n'; + + return dbg.maybeSpace(); +} 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 +