diff --git a/autotests/settings/CMakeLists.txt b/autotests/settings/CMakeLists.txt index 5480601..c8c5078 100644 --- a/autotests/settings/CMakeLists.txt +++ b/autotests/settings/CMakeLists.txt @@ -1,34 +1,36 @@ macro(NETWORKMANAGERQT_AUTOTESTS) foreach(_testname ${ARGN}) ecm_add_test(${_testname}.cpp LINK_LIBRARIES Qt5::Test KF5NetworkManagerQt_static) endforeach(_testname) endmacro(NETWORKMANAGERQT_AUTOTESTS) NETWORKMANAGERQT_AUTOTESTS( 8021xsettingtest adslsettingtest bluetoothsettingtest bondsettingtest bridgesettingtest bridgeportsettingtest cdmasettingtest connectionsettingtest gsmsettingtest infinibandsettingtest iptunnelsettingtest ipv4settingtest ipv6settingtest olpcmeshsettingtest pppsettingtest pppoesettingtest + proxysettingtest serialsettingtest tunsettingtest + usersettingtest vlansettingtest vxlansettingtest vpnsettingtest wimaxsettingtest wiredsettingtest wirelesssettingtest wirelesssecuritysettingtest ) diff --git a/autotests/settings/proxysettingtest.cpp b/autotests/settings/proxysettingtest.cpp new file mode 100644 index 0000000..005f86b --- /dev/null +++ b/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) diff --git a/autotests/settings/proxysettingtest.h b/autotests/settings/proxysettingtest.h new file mode 100644 index 0000000..5da5302 --- /dev/null +++ b/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 + diff --git a/autotests/settings/usersettingtest.cpp b/autotests/settings/usersettingtest.cpp new file mode 100644 index 0000000..5966628 --- /dev/null +++ b/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) diff --git a/autotests/settings/usersettingtest.h b/autotests/settings/usersettingtest.h new file mode 100644 index 0000000..aacb476 --- /dev/null +++ b/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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88e33ea..eed7ad2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,278 +1,280 @@ # add_subdirectory(dbus) include_directories( ${NETWORKMANAGER_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/dbus ${CMAKE_CURRENT_SOURCE_DIR}/settings ) set(NetworkManagerQt_PART_SRCS device.cpp accesspoint.cpp activeconnection.cpp adsldevice.cpp bluetoothdevice.cpp bonddevice.cpp bridgedevice.cpp connection.cpp dhcp4config.cpp dhcp6config.cpp devicestatistics.cpp dnsconfiguration.cpp dnsdomain.cpp infinibanddevice.cpp ipaddress.cpp iproute.cpp ipconfig.cpp manager.cpp modemdevice.cpp olpcmeshdevice.cpp secretagent.cpp settings.cpp utils.cpp vlandevice.cpp vpnconnection.cpp vpnplugin.cpp wimaxdevice.cpp wimaxnsp.cpp wireddevice.cpp wirelessdevice.cpp wirelessnetwork.cpp generictypes.cpp genericdevice.cpp gredevice.cpp iptunneldevice.cpp macvlandevice.cpp teamdevice.cpp tundevice.cpp vethdevice.cpp wimaxdevice.cpp wimaxnsp.cpp ) set(NetworkManagerQt_SETTINGS_SRCS settings/adslsetting.cpp settings/bluetoothsetting.cpp settings/bondsetting.cpp settings/bridgesetting.cpp settings/bridgeportsetting.cpp settings/cdmasetting.cpp settings/connectionsettings.cpp settings/gsmsetting.cpp settings/iptunnelsetting.cpp settings/ipv4setting.cpp settings/ipv6setting.cpp settings/infinibandsetting.cpp settings/olpcmeshsetting.cpp settings/pppsetting.cpp settings/pppoesetting.cpp + settings/proxysetting.cpp settings/setting.cpp settings/serialsetting.cpp settings/security8021xsetting.cpp #settings/template.cpp settings/vlansetting.cpp settings/vpnsetting.cpp settings/wimaxsetting.cpp settings/wiredsetting.cpp settings/wirelesssetting.cpp settings/wirelesssecuritysetting.cpp settings/teamsetting.cpp settings/genericsetting.cpp settings/tunsetting.cpp + settings/usersetting.cpp settings/vxlansetting.cpp ) set(DBUS_INTERFACE_SRCS dbus/accesspointinterface.cpp dbus/activeconnectioninterface.cpp dbus/adsldeviceinterface.cpp dbus/agentmanagerinterface.cpp dbus/bluetoothdeviceinterface.cpp dbus/bonddeviceinterface.cpp dbus/bridgedeviceinterface.cpp dbus/connectioninterface.cpp dbus/deviceinterface.cpp dbus/devicestatisticsinterface.cpp dbus/dhcp4configinterface.cpp dbus/dhcp6configinterface.cpp dbus/dnsmanagerinterface.cpp dbus/genericdeviceinterface.cpp dbus/gredeviceinterface.cpp dbus/checkpointinterface.cpp dbus/infinibanddeviceinterface.cpp dbus/iptunneldeviceinterface.cpp dbus/ip4configinterface.cpp dbus/ip6configinterface.cpp dbus/macsecdeviceinterface.cpp dbus/macvlandeviceinterface.cpp dbus/modemdeviceinterface.cpp dbus/networkmanagerinterface.cpp dbus/olpcmeshdeviceinterface.cpp dbus/pppinterface.cpp dbus/secretagentadaptor.cpp dbus/settingsinterface.cpp dbus/teamdeviceinterface.cpp dbus/tundeviceinterface.cpp dbus/vethdeviceinterface.cpp dbus/vlandeviceinterface.cpp dbus/vpnconnectioninterface.cpp dbus/vpnplugininterface.cpp dbus/vxlandeviceinterface.cpp dbus/wimaxdeviceinterface.cpp dbus/wimaxnspinterface.cpp dbus/wireddeviceinterface.cpp dbus/wirelessdeviceinterface.cpp ) add_library(KF5NetworkManagerQt SHARED ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) generate_export_header(KF5NetworkManagerQt EXPORT_FILE_NAME ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h BASE_NAME NetworkManagerQt) add_library(KF5::NetworkManagerQt ALIAS KF5NetworkManagerQt) target_include_directories(KF5NetworkManagerQt INTERFACE "$") # for examples to build target_include_directories(KF5NetworkManagerQt PUBLIC "$") target_link_libraries(KF5NetworkManagerQt PUBLIC Qt5::Core Qt5::Network Qt5::DBus) set_target_properties(KF5NetworkManagerQt PROPERTIES VERSION ${NETWORKMANAGERQT_VERSION_STRING} SOVERSION ${NETWORKMANAGERQT_SOVERSION} EXPORT_NAME NetworkManagerQt ) if (${NETWORKMANAGER_VERSION} VERSION_EQUAL 1.0.0 OR ${NETWORKMANAGER_VERSION} VERSION_GREATER 1.0.0) target_include_directories(KF5NetworkManagerQt PUBLIC ${NM-CORE_INCLUDE_DIRS}) else() target_include_directories(KF5NetworkManagerQt PUBLIC ${NETWORKMANAGER_INCLUDE_DIRS} SYSTEM PUBLIC ${NM-UTIL_INCLUDE_DIRS} ${NM-GLIB_INCLUDE_DIRS}) endif() ########### static lib for tests ############### add_library(KF5NetworkManagerQt_static STATIC ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) set_target_properties(KF5NetworkManagerQt_static PROPERTIES COMPILE_FLAGS -DNMQT_STATIC=1) target_link_libraries(KF5NetworkManagerQt_static PUBLIC Qt5::Core Qt5::Network Qt5::DBus) target_include_directories(KF5NetworkManagerQt_static PUBLIC "$") ecm_generate_headers(NetworkManagerQt_CamelCase_HEADERS HEADER_NAMES AccessPoint ActiveConnection AdslDevice BluetoothDevice BondDevice BridgeDevice Connection Device DeviceStatistics Dhcp4Config Dhcp6Config DnsConfiguration DnsDomain GenericDevice GenericTypes GreDevice InfinibandDevice IpAddress IpConfig IpRoute IpTunnelDevice MacVlanDevice Manager ModemDevice OlpcMeshDevice SecretAgent Settings TeamDevice TunDevice Utils VethDevice VlanDevice VpnConnection VpnPlugin WimaxDevice WimaxNsp WiredDevice WirelessDevice WirelessNetwork REQUIRED_HEADERS NetworkManagerQt_HEADERS PREFIX NetworkManagerQt ) ecm_generate_headers(NetworkManagerQt_SETTINGS_CamelCase_HEADERS HEADER_NAMES AdslSetting BluetoothSetting BondSetting BridgeSetting BridgePortSetting CdmaSetting ConnectionSettings GsmSetting GenericSetting InfinibandSetting IpTunnelSetting Ipv4Setting Ipv6Setting OlpcMeshSetting PppoeSetting PppSetting Security8021xSetting SerialSetting Setting TeamSetting TunSetting VlanSetting VpnSetting WimaxSetting WiredSetting WirelessSecuritySetting WirelessSetting RELATIVE settings REQUIRED_HEADERS NetworkManagerQt_SETTINGS_HEADERS PREFIX NetworkManagerQt ) install(TARGETS KF5NetworkManagerQt EXPORT KF5NetworkManagerQtTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${NetworkManagerQt_CamelCase_HEADERS} ${NetworkManagerQt_SETTINGS_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt/NetworkManagerQt COMPONENT Devel ) install(FILES ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h ${NetworkManagerQt_HEADERS} ${NetworkManagerQt_SETTINGS_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt/networkmanagerqt COMPONENT Devel ) if(BUILD_QCH) ecm_add_qch( KF5NetworkManagerQt_QCH NAME NetworkManagerQt BASE_NAME KF5NetworkManagerQt VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${NetworkManagerQt_HEADERS} ${NetworkManagerQt_SETTINGS_HEADERS} MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" LINK_QCHS Qt5Core_QCH Qt5Network_QCH Qt5DBus_QCH BLANK_MACROS NETWORKMANAGERQT_EXPORT NETWORKMANAGERQT_DEPRECATED NETWORKMANAGERQT_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME NetworkManagerQt LIB_NAME KF5NetworkManagerQt DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/settings/proxysetting.cpp b/src/settings/proxysetting.cpp new file mode 100644 index 0000000..8eb5a1e --- /dev/null +++ b/src/settings/proxysetting.cpp @@ -0,0 +1,175 @@ +/* + 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 + +#if !NM_CHECK_VERSION(1, 6, 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(false) + , method(ProxySetting::None) +{ } + +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(NetworkManager::ProxySetting::Mode method) +{ + Q_D(ProxySetting); + + d->method = method; +} + +NetworkManager::ProxySetting::Mode 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((Mode)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), (int)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(); +} diff --git a/src/settings/proxysetting.h b/src/settings/proxysetting.h new file mode 100644 index 0000000..3132984 --- /dev/null +++ b/src/settings/proxysetting.h @@ -0,0 +1,81 @@ +/* + 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 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); + ~ProxySetting() override; + + QString name() const override; + + void setBrowserOnly(bool browserOnly); + bool browserOnly() const; + + void setMethod(Mode method); + Mode 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 + diff --git a/src/settings/proxysetting_p.h b/src/settings/proxysetting_p.h new file mode 100644 index 0000000..33a1e82 --- /dev/null +++ b/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; + NetworkManager::ProxySetting::Mode method; + QString pacScript; + QString pacUrl; +}; + +} + +#endif // NETWORKMANAGERQT_PROXY_SETTING_P_H + diff --git a/src/settings/setting.cpp b/src/settings/setting.cpp index 22d9c14..49388d6 100644 --- a/src/settings/setting.cpp +++ b/src/settings/setting.cpp @@ -1,286 +1,296 @@ /* Copyright 2012-2013 Jan Grulich 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 "setting.h" #undef signals #include #include #define signals Q_SIGNALS #include namespace NetworkManager { class SettingPrivate { public: SettingPrivate(); Setting::SettingType type; bool initialized; }; QDebug operator <<(QDebug dbg, const Setting &setting) { dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; return dbg.maybeSpace(); } } NetworkManager::SettingPrivate::SettingPrivate(): type(Setting::Wired), initialized(false) { } QString NetworkManager::Setting::typeAsString(NetworkManager::Setting::SettingType type) { QString typeString; switch (type) { case Cdma: typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME); break; case Gsm: typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME); break; case Bluetooth: typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME); break; case Ipv4: typeString = QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME); break; case Ipv6: typeString = QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME); break; case Ppp: typeString = QLatin1String(NM_SETTING_PPP_SETTING_NAME); break; case Pppoe: typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME); break; case Security8021x: typeString = QLatin1String(NM_SETTING_802_1X_SETTING_NAME); break; case Serial: typeString = QLatin1String(NM_SETTING_SERIAL_SETTING_NAME); break; case Vpn: typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME); break; case Wired: typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME); break; case Wireless: typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME); break; case WirelessSecurity: typeString = QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); break; case OlpcMesh: typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME); break; case Vlan: typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME); break; case Wimax: typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME); break; case Bond: typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME); break; case Bridge: typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME); break; case Team: typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME); break; case Vxlan: typeString = QLatin1String(NM_SETTING_VXLAN_SETTING_NAME); break; 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; default: break; } return typeString; } NetworkManager::Setting::SettingType NetworkManager::Setting::typeFromString(const QString &typeString) { SettingType type = Wired; if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) { type = Cdma; } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) { type = Gsm; } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) { type = Bluetooth; } else if (typeString == QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME)) { type = Ipv4; } else if (typeString == QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME)) { type = Ipv6; } else if (typeString == QLatin1String(NM_SETTING_PPP_SETTING_NAME)) { type = Ppp; } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) { type = Pppoe; } else if (typeString == QLatin1String(NM_SETTING_SERIAL_SETTING_NAME)) { type = Serial; } else if (typeString == QLatin1String(NM_SETTING_802_1X_SETTING_NAME)) { type = Security8021x; } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) { type = Vpn; } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) { type = Wired; } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) { type = Wireless; } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) { type = WirelessSecurity; } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) { type = OlpcMesh; } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) { type = Vlan; } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) { type = Wimax; } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) { type = Bond; } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) { type = Bridge; } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) { type = Team; } else if (typeString == QLatin1String(NM_SETTING_VXLAN_SETTING_NAME)) { type = Vxlan; } else if (typeString == QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME)) { 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; } NetworkManager::Setting::Setting(SettingType type) : d_ptr(new SettingPrivate()) { setType(type); } NetworkManager::Setting::Setting(const NetworkManager::Setting::Ptr &setting) : d_ptr(new SettingPrivate()) { setInitialized(!setting->isNull()); setType(setting->type()); } NetworkManager::Setting::~Setting() { delete d_ptr; } void NetworkManager::Setting::fromMap(const QVariantMap &map) { Q_UNUSED(map); } QVariantMap NetworkManager::Setting::toMap() const { return QVariantMap(); } QStringList NetworkManager::Setting::needSecrets(bool requestNew) const { Q_UNUSED(requestNew); return QStringList(); } QString NetworkManager::Setting::name() const { return QString(); } void NetworkManager::Setting::secretsFromMap(const QVariantMap &map) { Q_UNUSED(map); } void NetworkManager::Setting::secretsFromStringMap(const NMStringMap &map) { QVariantMap secretsMap; NMStringMap::ConstIterator i = map.constBegin(); while (i != map.constEnd()) { secretsMap.insert(i.key(), i.value()); ++i; } secretsFromMap(secretsMap); } QVariantMap NetworkManager::Setting::secretsToMap() const { return QVariantMap(); } NMStringMap NetworkManager::Setting::secretsToStringMap() const { NMStringMap ret; QVariantMap secretsMap = secretsToMap(); QVariantMap::ConstIterator i = secretsMap.constBegin(); while (i != secretsMap.constEnd()) { ret.insert(i.key(), i.value().toString()); ++i; } return ret; } void NetworkManager::Setting::setInitialized(bool initialized) { Q_D(Setting); d->initialized = initialized; } bool NetworkManager::Setting::isNull() const { Q_D(const Setting); return !d->initialized; } void NetworkManager::Setting::setType(NetworkManager::Setting::SettingType type) { Q_D(Setting); d->type = type; } NetworkManager::Setting::SettingType NetworkManager::Setting::type() const { Q_D(const Setting); return d->type; } diff --git a/src/settings/setting.h b/src/settings/setting.h index 7f1b397..ee0863e 100644 --- a/src/settings/setting.h +++ b/src/settings/setting.h @@ -1,154 +1,156 @@ /* Copyright 2012-2013 Jan Grulich 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_SETTING_H #define NETWORKMANAGERQT_SETTING_H #include #include "generictypes.h" #undef signals #include #define signals Q_SIGNALS #include #include #include #include namespace NetworkManager { class SettingPrivate; /** * Base class for all kinds of setting */ class NETWORKMANAGERQT_EXPORT Setting { public: typedef QSharedPointer Ptr; typedef QList List; enum SettingType { Adsl, Cdma, Gsm, Infiniband, Ipv4, Ipv6, Ppp, Pppoe, Security8021x, Serial, Vpn, Wired, Wireless, WirelessSecurity, Bluetooth, OlpcMesh, Vlan, Wimax, Bond, Bridge, BridgePort, Team, Generic, Tun, Vxlan, - IpTunnel + IpTunnel, + Proxy, + User }; enum SecretFlagType { None = 0, AgentOwned = 0x01, NotSaved = 0x02, NotRequired = 0x04 }; Q_DECLARE_FLAGS(SecretFlags, SecretFlagType) enum MacAddressRandomization { MacAddressRandomizationDefault = 0, MacAddressRandomizationNever, MacAddressRandomizationAlways }; static QString typeAsString(SettingType type); static SettingType typeFromString(const QString &type); explicit Setting(SettingType type); explicit Setting(const Ptr &setting); virtual ~Setting(); /** * @brief Must be reimplemented, default implementation does nothing */ virtual void fromMap(const QVariantMap &map); /** * @brief Must be reimplemented, default implementationd does nothing */ virtual QVariantMap toMap() const; virtual void secretsFromMap(const QVariantMap &map); /** * @brief secretsFromStringMap is a convenience function * to set the secrets from a map of strings. * @param map to extract secrets from */ virtual void secretsFromStringMap(const NMStringMap &map); virtual QVariantMap secretsToMap() const; /** * @brief secretsToStringMap is a convenience function * to get the secrets to map of strings. * @return string map with current secrets */ virtual NMStringMap secretsToStringMap() const; virtual QStringList needSecrets(bool requestNew = false) const; /** * @brief Must be reimplemented, default implementationd does nothing */ virtual QString name() const; void setInitialized(bool initialized); bool isNull() const; void setType(SettingType type); SettingType type() const; protected: SettingPrivate *d_ptr; private: Q_DECLARE_PRIVATE(Setting) }; Q_DECLARE_OPERATORS_FOR_FLAGS(Setting::SecretFlags) NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Setting &setting); } #endif // NETWORKMANAGERQT_SETTING_H diff --git a/src/settings/usersetting.cpp b/src/settings/usersetting.cpp new file mode 100644 index 0000000..6d984c7 --- /dev/null +++ b/src/settings/usersetting.cpp @@ -0,0 +1,107 @@ +/* + 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 + +#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_USER_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(); +} + diff --git a/src/settings/usersetting.h b/src/settings/usersetting.h new file mode 100644 index 0000000..560aadd --- /dev/null +++ b/src/settings/usersetting.h @@ -0,0 +1,69 @@ +/* + 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 user 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 + diff --git a/src/settings/usersetting_p.h b/src/settings/usersetting_p.h new file mode 100644 index 0000000..232b369 --- /dev/null +++ b/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 +