diff options
Diffstat (limited to 'src/networksettings')
30 files changed, 413 insertions, 579 deletions
diff --git a/src/networksettings/CMakeLists.txt b/src/networksettings/CMakeLists.txt index daf0b30..03e43f4 100644 --- a/src/networksettings/CMakeLists.txt +++ b/src/networksettings/CMakeLists.txt @@ -19,6 +19,7 @@ qt_internal_add_module(NetworkSettings qnetworksettingsservice.cpp qnetworksettingsservice.h qnetworksettingsservicemodel.cpp qnetworksettingsservicemodel.h qnetworksettingsuseragent.cpp qnetworksettingsuseragent.h + qnetworksettingsglobal.h DBUS_INTERFACE_SOURCES connman/connman_manager.xml connman/connman_service.xml @@ -27,10 +28,11 @@ qt_internal_add_module(NetworkSettings -iconnmancommon.h # special case INCLUDE_DIRECTORIES connman - LIBRARIES + PUBLIC_LIBRARIES Qt::Core Qt::DBus Qt::Network + GENERATE_CPP_EXPORTS ) file(MAKE_DIRECTORY header_connman) diff --git a/src/networksettings/connman/connman_manager.xml b/src/networksettings/connman/connman_manager.xml index 95bc0cb..ba95e8b 100644 --- a/src/networksettings/connman/connman_manager.xml +++ b/src/networksettings/connman/connman_manager.xml @@ -80,7 +80,7 @@ <signal name="TechnologyAdded" tp:name-for-bindings="Technology_Added"> <arg name="technology" type="o"/> <arg name="properties" type="a{sv}"/> - <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> </signal> <signal name="TechnologyRemoved" tp:name-for-bindings="Technology_Removed"> diff --git a/src/networksettings/connman/connmancommon.cpp b/src/networksettings/connman/connmancommon.cpp index 887af48..a77bb1d 100644 --- a/src/networksettings/connman/connmancommon.cpp +++ b/src/networksettings/connman/connmancommon.cpp @@ -28,6 +28,8 @@ ****************************************************************************/ #include "connmancommon.h" +#include <QtNetworkSettings/qnetworksettings.h> + QT_BEGIN_NAMESPACE //Conversion operations for datatypes diff --git a/src/networksettings/connman/connmancommon.h b/src/networksettings/connman/connmancommon.h index 6b9dd31..3b3cb79 100644 --- a/src/networksettings/connman/connmancommon.h +++ b/src/networksettings/connman/connmancommon.h @@ -31,7 +31,6 @@ #include <QtCore/QMetaType> #include <QtDBus/QtDBus> -#include <QtNetworkSettings/qnetworksettings.h> #define PropertyAgentPath QStringLiteral("/ConnmanAgent") #define PropertyState QStringLiteral("State") @@ -54,6 +53,9 @@ QT_BEGIN_NAMESPACE +class QNetworkSettingsType; +class QNetworkSettingsState; + struct ConnmanMapStruct { QDBusObjectPath objectPath; QVariantMap propertyMap; diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.cpp b/src/networksettings/connman/qnetworksettingsinterface_p.cpp index 5f008ff..eeb2abc 100644 --- a/src/networksettings/connman/qnetworksettingsinterface_p.cpp +++ b/src/networksettings/connman/qnetworksettingsinterface_p.cpp @@ -27,7 +27,6 @@ ** ****************************************************************************/ #include "qnetworksettingsinterface_p.h" -#include "qnetworksettingsinterface.h" #include "connman_technology_interface.h" #include "connmancommon.h" @@ -35,10 +34,9 @@ QT_BEGIN_NAMESPACE QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) : QObject(parent) - , m_technology(Q_NULLPTR) + , m_technology(nullptr) ,q_ptr(parent) { - } void QNetworkSettingsInterfacePrivate::initialize(const QString& path, const QVariantMap& properties) @@ -83,7 +81,7 @@ void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const } } -void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::State aState) { Q_Q(QNetworkSettingsInterface); m_state.setState(aState); diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.h b/src/networksettings/connman/qnetworksettingsinterface_p.h index d85712a..25fbd2d 100644 --- a/src/networksettings/connman/qnetworksettingsinterface_p.h +++ b/src/networksettings/connman/qnetworksettingsinterface_p.h @@ -41,10 +41,11 @@ // #include <QObject> -#include <QtDBus> +#include <QtDBus/QDBusVariant> #include "qnetworksettings.h" #include "qnetworksettingsinterface.h" +// Automatically generated class in global namespace class NetConnmanTechnologyInterface; QT_BEGIN_NAMESPACE @@ -57,11 +58,11 @@ public: explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); void initialize(const QString& path, const QVariantMap& properties); void setPowered(const bool power); - void setState(QNetworkSettingsState::States aState); + void setState(QNetworkSettingsState::State aState); void scan(); QString name() const {return m_name;} - QNetworkSettingsType::Types type() const {return m_type.type();} - QNetworkSettingsState::States state() const {return m_state.state();} + QNetworkSettingsType::Type type() const {return m_type.type();} + QNetworkSettingsState::State state() const {return m_state.state();} bool powered() const {return m_powered;} QString path() const; @@ -84,21 +85,19 @@ class ConnmanSettingsInterface : public QNetworkSettingsInterface { Q_OBJECT public: - ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent = Q_NULLPTR) + ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent = nullptr) :QNetworkSettingsInterface(parent) { if (d_ptr) d_ptr->initialize(path, properties); } - void setState(QNetworkSettingsState::States aState) { + void setState(QNetworkSettingsState::State aState) { Q_D(QNetworkSettingsInterface); d->setState(aState); } - virtual ~ConnmanSettingsInterface() { - - } + virtual ~ConnmanSettingsInterface() {} QString path() const { if (d_ptr) diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/networksettings/connman/qnetworksettingsmanager_p.cpp index 3f594bd..94eec14 100644 --- a/src/networksettings/connman/qnetworksettingsmanager_p.cpp +++ b/src/networksettings/connman/qnetworksettingsmanager_p.cpp @@ -26,10 +26,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include <QFile> -#include <QNetworkInterface> +#include "qnetworksettingsservice.h" #include "qnetworksettingsmanager_p.h" -#include "qnetworksettingsinterface.h" #include "qnetworksettingsinterface_p.h" #include "qnetworksettingsservicemodel.h" #include "qnetworksettingsuseragent.h" @@ -42,14 +40,14 @@ const QString ConnManServiceName(QStringLiteral("net.connman")); QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent) :QObject(parent) ,q_ptr(parent) - , m_interfaceModel(Q_NULLPTR) - , m_serviceModel(Q_NULLPTR) - , m_serviceFilter(Q_NULLPTR) - , m_manager(Q_NULLPTR) - , m_agent(Q_NULLPTR) - , m_serviceWatcher(Q_NULLPTR) - , m_currentWifiConnection(Q_NULLPTR) - , m_currentWiredConnection(Q_NULLPTR) + , m_interfaceModel(nullptr) + , m_serviceModel(nullptr) + , m_serviceFilter(nullptr) + , m_manager(nullptr) + , m_agent(nullptr) + , m_serviceWatcher(nullptr) + , m_currentWifiConnection(nullptr) + , m_currentWiredConnection(nullptr) , m_initialized(false) { qRegisterMetaType<ConnmanMapStruct>("ConnmanMapStruct"); @@ -140,8 +138,7 @@ void QNetworkSettingsManagerPrivate::tryNextConnection() } if (!service) { if (!m_unnamedServicesForSsidConnection.isEmpty()) { - service = *m_unnamedServicesForSsidConnection.begin(); - m_unnamedServicesForSsidConnection.erase(m_unnamedServicesForSsidConnection.begin()); + service = m_unnamedServicesForSsidConnection.take(m_unnamedServicesForSsidConnection.firstKey()); } else { q->clearConnectionState(); } @@ -151,6 +148,26 @@ void QNetworkSettingsManagerPrivate::tryNextConnection() } } +void QNetworkSettingsManagerPrivate::setCurrentWifiConnection(QNetworkSettingsService *connection) +{ + m_currentWifiConnection = connection; +} + +QNetworkSettingsService *QNetworkSettingsManagerPrivate::currentWifiConnection() const +{ + return m_currentWifiConnection.data(); +} + +void QNetworkSettingsManagerPrivate::setCurrentWiredConnection(QNetworkSettingsService *connection) +{ + m_currentWiredConnection = connection; +} + +QNetworkSettingsService *QNetworkSettingsManagerPrivate::currentWiredConnection() const +{ + return m_currentWiredConnection.data(); +} + void QNetworkSettingsManagerPrivate::onConnmanServiceRegistered(const QString &serviceName) { if (serviceName == ConnManServiceName) { @@ -163,31 +180,34 @@ void QNetworkSettingsManagerPrivate::onTechnologyAdded(const QDBusObjectPath &te { Q_Q(QNetworkSettingsManager); - foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) { - ConnmanSettingsInterface* tech = qobject_cast<ConnmanSettingsInterface*>(item); - if (tech->path() != technology.path()) { - ConnmanSettingsInterface *interface = new ConnmanSettingsInterface(technology.path(), properties, this); - interface->scanServices(); - - if (interface->type() == QNetworkSettingsType::Wired) { - m_interfaceModel.insert(0, interface); - } - else if (interface->type() == QNetworkSettingsType::Wifi) { - m_interfaceModel.append(interface); - } - emit q->interfacesChanged(); + for (QNetworkSettingsInterface* item : m_interfaceModel.getModel()) { + ConnmanSettingsInterface* interface = qobject_cast<ConnmanSettingsInterface*>(item); + if (interface->path() == technology.path()) { + return; // we already know the interface/technology } } + + ConnmanSettingsInterface *interface = new ConnmanSettingsInterface(technology.path(), properties, this); + interface->scanServices(); + + if (interface->type() == QNetworkSettingsType::Wired) { + m_interfaceModel.insert(0, interface); + } + else if (interface->type() == QNetworkSettingsType::Wifi) { + m_interfaceModel.append(interface); + } + + emit q->interfacesChanged(); } void QNetworkSettingsManagerPrivate::onTechnologyRemoved(const QDBusObjectPath &technology) { Q_Q(QNetworkSettingsManager); - foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) { + for (QNetworkSettingsInterface* item : m_interfaceModel.getModel()) { ConnmanSettingsInterface* tech = qobject_cast<ConnmanSettingsInterface*>(item); if (tech->path() == technology.path()) { - m_interfaceModel.removeInterface(technology.path()); + m_interfaceModel.removeInterface(tech->name()); emit q->interfacesChanged(); } } @@ -201,7 +221,7 @@ void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher if (reply.isError()) return; - foreach (const ConnmanMapStruct &object, reply.value()) { + for (const ConnmanMapStruct &object : reply.value()) { const QString servicePath = object.objectPath.path(); handleNewService(servicePath); } @@ -216,7 +236,7 @@ void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWat if (reply.isError()) return; - foreach (const ConnmanMapStruct &object, reply.value()) { + for (const ConnmanMapStruct &object : reply.value()) { ConnmanSettingsInterface *item = new ConnmanSettingsInterface(object.objectPath.path(), object.propertyMap, this); item->scanServices(); @@ -232,21 +252,43 @@ void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWat void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList changed, const QList<QDBusObjectPath> &removed) { - foreach (QDBusObjectPath path, removed) { - m_serviceModel->removeService(path.path()); - auto serviceIter = m_unnamedServices.find(path.path()); - if (serviceIter != m_unnamedServices.end()) { - serviceIter.value()->deleteLater(); - m_unnamedServices.erase(serviceIter); - } + Q_Q(QNetworkSettingsManager); + for (const QDBusObjectPath &dpath : removed) { + QString path = dpath.path(); + + if (m_serviceModel->removeService(path)) + emit q->servicesChanged(); + + if (auto service = m_unnamedServices.take(path)) + if (!service->placeholderState()) { + disconnect(service, &QNetworkSettingsService::nameChanged, + this, &QNetworkSettingsManagerPrivate::serviceReady); + disconnect(service, &QNetworkSettingsService::typeChanged, + this, &QNetworkSettingsManagerPrivate::serviceReady); + service->deleteLater(); + } + if (auto service = m_unknownServices.take(path)) + if (!service->placeholderState()) { + disconnect(service, &QNetworkSettingsService::nameChanged, + this, &QNetworkSettingsManagerPrivate::serviceReady); + disconnect(service, &QNetworkSettingsService::typeChanged, + this, &QNetworkSettingsManagerPrivate::serviceReady); + service->deleteLater(); + } + m_unnamedServicesForSsidConnection.remove(path); // do not delete here } QStringList newServices; - foreach (ConnmanMapStruct map, changed) { + for (const ConnmanMapStruct &map : changed) { + QString path = map.objectPath.path(); + + if (m_unknownServices.contains(path) || m_unnamedServices.contains(path)) + continue; + bool found = false; - foreach (QNetworkSettingsService* service, m_serviceModel->getModel()) { - if (service->id() == map.objectPath.path() && service->placeholderState() == false) { - found =true; + for (QNetworkSettingsService* service : m_serviceModel->getModel()) { + if (service->id() == path && service->placeholderState() == false) { + found = true; break; } } @@ -254,7 +296,7 @@ void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList chan newServices.append(map.objectPath.path()); } - foreach (QString newService, newServices) { + for (QString newService : newServices) { handleNewService(newService); } @@ -282,9 +324,20 @@ void QNetworkSettingsManagerPrivate::handleNewService(const QString &servicePath } } else { + bool isUnnamedWifi = false; + //Service name or type not set, wait for update - connect(service, &QNetworkSettingsService::nameChanged, this, &QNetworkSettingsManagerPrivate::serviceReady); - connect(service, &QNetworkSettingsService::typeChanged, this, &QNetworkSettingsManagerPrivate::serviceReady); + if (service->name().isEmpty()) { + connect(service, &QNetworkSettingsService::nameChanged, this, &QNetworkSettingsManagerPrivate::serviceReady); + isUnnamedWifi = (service->type() == QNetworkSettingsType::Wifi); + } + if (service->type() == QNetworkSettingsType::Unknown) + connect(service, &QNetworkSettingsService::typeChanged, this, &QNetworkSettingsManagerPrivate::serviceReady); + + if (isUnnamedWifi) + m_unnamedServices.insert(service->id(), service); + else + m_unknownServices.insert(service->id(), service); } } @@ -299,11 +352,14 @@ void QNetworkSettingsManagerPrivate::serviceReady() QNetworkSettingsService* service = qobject_cast<QNetworkSettingsService*>(sender()); - if (service->type() != QNetworkSettingsType::Unknown - && service->type() == QNetworkSettingsType::Wifi) { + // the type changed from Unknown to Wifi + if ((service->type() == QNetworkSettingsType::Wifi) + && m_unknownServices.contains(service->id())) { + m_unknownServices.remove(service->id()); m_unnamedServices.insert(service->id(), service); } + // we have a name and a length now if (service->name().length() > 0 && service->type() != QNetworkSettingsType::Unknown) { service->disconnect(this); m_unnamedServices.remove(service->id()); @@ -314,7 +370,7 @@ void QNetworkSettingsManagerPrivate::serviceReady() } //Update the interface state accordingly - foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) { + for (QNetworkSettingsInterface* item : m_interfaceModel.getModel()) { ConnmanSettingsInterface* technology = qobject_cast<ConnmanSettingsInterface*>(item); if (technology->name() == service->name() && technology->type() == service->type()) { technology->setState(technology->state()); diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.h b/src/networksettings/connman/qnetworksettingsmanager_p.h index c696cdd..0b0c39b 100644 --- a/src/networksettings/connman/qnetworksettingsmanager_p.h +++ b/src/networksettings/connman/qnetworksettingsmanager_p.h @@ -41,19 +41,22 @@ // #include <QObject> -#include <QtDBus> #include <QMap> +#include <QPointer> +#include <QtDBus/QDBusServiceWatcher> #include "connmancommon.h" #include "qnetworksettingsmanager.h" #include "qnetworksettingsinterfacemodel.h" #include "connman_manager_interface.h" -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServiceModel) -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServiceFilter) -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsService) - QT_BEGIN_NAMESPACE +class QDBusObjectPath; +class QDBusPendingCallWatcher; +class QNetworkSettingsService; +class QNetworkSettingsServiceModel; +class QNetworkSettingsServiceFilter; + class QNetworkSettingsManagerPrivate : public QObject { Q_OBJECT @@ -69,10 +72,10 @@ public: void connectBySsid(const QString &name); void clearConnectionState(); void tryNextConnection(); - void setCurrentWifiConnection(QNetworkSettingsService *connection) {m_currentWifiConnection = connection;} - QNetworkSettingsService* currentWifiConnection() const {return m_currentWifiConnection;} - void setCurrentWiredConnection(QNetworkSettingsService *connection) {m_currentWiredConnection = connection;} - QNetworkSettingsService* currentWiredConnection() const {return m_currentWiredConnection;} + void setCurrentWifiConnection(QNetworkSettingsService *connection); + QNetworkSettingsService* currentWifiConnection() const; + void setCurrentWiredConnection(QNetworkSettingsService *connection); + QNetworkSettingsService* currentWiredConnection() const; public slots: void getServicesFinished(QDBusPendingCallWatcher *watcher); @@ -91,6 +94,7 @@ private: protected: QNetworkSettingsInterfaceModel m_interfaceModel; QNetworkSettingsServiceModel *m_serviceModel; + QMap<QString, QNetworkSettingsService*> m_unknownServices; QMap<QString, QNetworkSettingsService*> m_unnamedServices; QMap<QString, QNetworkSettingsService*> m_unnamedServicesForSsidConnection; QNetworkSettingsServiceFilter *m_serviceFilter; @@ -99,8 +103,8 @@ private: QNetworkSettingsUserAgent *m_agent; QDBusServiceWatcher *m_serviceWatcher; QString m_currentSsid; - QNetworkSettingsService *m_currentWifiConnection; - QNetworkSettingsService *m_currentWiredConnection; + QPointer<QNetworkSettingsService> m_currentWifiConnection; + QPointer<QNetworkSettingsService> m_currentWiredConnection; bool m_initialized; }; diff --git a/src/networksettings/connman/qnetworksettingsservice_p.cpp b/src/networksettings/connman/qnetworksettingsservice_p.cpp index 2523e81..082b458 100644 --- a/src/networksettings/connman/qnetworksettingsservice_p.cpp +++ b/src/networksettings/connman/qnetworksettingsservice_p.cpp @@ -438,20 +438,22 @@ void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QV } else if (key == PropertySecurity) { QStringList value = qdbus_cast<QStringList>(val); - foreach (const QString str, value) { + QNetworkSettingsWireless::Securities securities; + for (const QString &str : value) { if (str == AttributeNone || str == AttributeWps) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::None); + securities |= QNetworkSettingsWireless::Security::None; } else if (str == AttributeWep) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + securities |= QNetworkSettingsWireless::Security::WEP; } else if (str == AttributePsk) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + securities |=QNetworkSettingsWireless::Security::WPA; } else if (str == AttributeIeee) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + securities |=QNetworkSettingsWireless::Security::WPA2; } } + m_wifiConfig.setSecurity(securities); } else if (key == PropertyAutoConnect) { m_autoConnect = qdbus_cast<bool>(val); diff --git a/src/networksettings/connman/qnetworksettingsservice_p.h b/src/networksettings/connman/qnetworksettingsservice_p.h index 9190e2d..8c798c3 100644 --- a/src/networksettings/connman/qnetworksettingsservice_p.h +++ b/src/networksettings/connman/qnetworksettingsservice_p.h @@ -43,20 +43,19 @@ #include "qnetworksettingsservice.h" #include "qnetworksettings.h" -QT_FORWARD_DECLARE_CLASS(QDBusPendingCallWatcher) -QT_FORWARD_DECLARE_CLASS(QDBusVariant) - // Automatically generated class in global namespace class NetConnmanServiceInterface; QT_BEGIN_NAMESPACE +class QDBusVariant; +class QDBusPendingCallWatcher; class QNetworkSettingsServicePrivate : public QObject { Q_OBJECT Q_DECLARE_PUBLIC(QNetworkSettingsService) public: - QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent = Q_NULLPTR); + QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent = nullptr); QNetworkSettingsService *q_ptr; private slots: diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp index 2c1e399..6ba8be7 100644 --- a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp @@ -26,6 +26,9 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QtDBus/QDBusConnection> + +#include "qnetworksettingsuseragent.h" #include "qnetworksettingsuseragent_p.h" #include "connmancommon.h" diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.h b/src/networksettings/connman/qnetworksettingsuseragent_p.h index b85ddd2..8f356d9 100644 --- a/src/networksettings/connman/qnetworksettingsuseragent_p.h +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.h @@ -41,25 +41,20 @@ // #include <QtCore/QObject> -#include <QtDBus/QtDBus> -#include "qnetworksettingsuseragent.h" +#include <QtDBus/QDBusMessage> +#include <QtDBus/QDBusObjectPath> +#include <QtDBus/QDBusAbstractAdaptor> QT_BEGIN_NAMESPACE -class QByteArray; -template<class T> class QList; -template<class Key, class Value> class QMap; -class QString; -class QVariant; - -const QString AgentPath(QStringLiteral("/ConnmanAgent")); +class QNetworkSettingsUserAgent; class QNetworkSettingsUserAgentPrivate : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "net.connman.Agent") Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) public: - QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent = Q_NULLPTR); + QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent = nullptr); void setPassphrase(const QString &passphrase); QString passphrase() const {return m_passphrase;} void cancel(); @@ -82,3 +77,4 @@ private: QT_END_NAMESPACE #endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H + diff --git a/src/networksettings/networksettingsqml/CMakeLists.txt b/src/networksettings/networksettingsqml/CMakeLists.txt deleted file mode 100644 index db3f58c..0000000 --- a/src/networksettings/networksettingsqml/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -qt_internal_add_qml_module(networksettingsqml - URI "QtDeviceUtilities.NetworkSettings" - VERSION "${CMAKE_PROJECT_VERSION}" - PAST_MAJOR_VERSIONS 1 - PLUGIN_TARGET networksettingsqml - DEPENDENCIES - QtQml - SOURCES - qnetworksettingsforeign.h qnetworksettingsforeign.cpp - LIBRARIES - Qt::Core - Qt::Qml - Qt::NetworkSettings -) diff --git a/src/networksettings/networksettingsqml/qnetworksettingsforeign.cpp b/src/networksettings/networksettingsqml/qnetworksettingsforeign.cpp deleted file mode 100644 index e3d1414..0000000 --- a/src/networksettings/networksettingsqml/qnetworksettingsforeign.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qnetworksettingsforeign.h" - -/*! - \qmlmodule QtDeviceUtilities.NetworkSettings - \ingroup qtdevice-utilities-qml-modules - \ingroup qmlmodules - \title Qt Network Settings QML Types - - \brief Provides singleton QML types for controlling network settings. - - Qt Network Settings QML module provides singleton QML types for controlling - network settings in an embedded device. - - To import and use the module's QML types, use the following statement: - - \badcode - import QtDeviceUtilities.NetworkSettings - \endcode - - \l{Qt Device Utilities WiFi Tutorial} demonstrates how you can use - \l{QtDeviceUtilities.NetworkSettings}{NetworkSettings} for connecting to WiFi. - - \note Some functions may not be available on all of the platforms. - - \section1 QML Types -*/ - -/*! - \qmltype NetworkSettingsManager - \inqmlmodule QtDeviceUtilities.NetworkSettings - \brief A singleton QML type for managing network settings. - - There is no need to create an instance of this object. To use it, - simply import the \c {QtDeviceUtilities.NetworkSettings} module. - - \l{Qt Device Utilities WiFi Tutorial} demonstrates how you can use - \l{NetworkSettingsManager} for connecting to WiFi. -*/ - -/*! - \qmlproperty model NetworkSettingsManager::services - \readonly - - Holds the service model. - - The services list in the model can be controlled with the - \c type property, and NetworkService items can be retrieved - with the \c {itemFromRow(int index)} method. For example, to - select the first available wired network service: - - \code - property var service: null - ... - NetworkSettingsManager.services.type = NetworkSettingsType.Wired; - service = NetworkSettingsManager.services.itemFromRow(0); - \endcode - - Available service types: - - \value NetworkSettingsType.Wired Wired network - \value NetworkSettingsType.Wifi Wifi network - \value NetworkSettingsType.Bluetooth Bluetooth network - \value NetworkSettingsType.Unknown Unknown network type - - \sa NetworkService -*/ - -/*! - \qmlproperty model NetworkSettingsManager::interfaces - \readonly - - Holds the interface model. A delegate in a view that uses - the \e interfaces model can access the NetworkInterface - item with the \e dataModel role. - - \sa NetworkInterface -*/ - -/*! - \qmlmethod NetworkService NetworkSettingsManager::service(string name, int type) - - Returns the service with name \a name and type \a type. - - \sa services -*/ - -/*! - \qmlmethod NetworkInterface NetworkSettingsManager::interface(int type, int instance) - - Returns the interface with type \a type and order number of \a instance - - \sa NetworkInterface -*/ - -/*! - \qmlmethod NetworkSettingsManager::userAgent.setPassphrase(string passphrase) - - Sets the \a passphrase for connecting to a Wifi network. - - This method needs to be called in response to receiving a showUserCredentialsInput() signal. - - \sa userAgent.showUserCredentialsInput() -*/ - -/*! - \qmlsignal NetworkSettingsManager::userAgent.showUserCredentialsInput() - - This signal is emitted when user credentials are required for connecting to a Wifi network. - - \sa userAgent.setPassphrase() -*/ - -/*! - \qmlmethod NetworkSettingsManager::userAgent.cancelInput() - - Cancels the user credentials input request. -*/ - -/*! - \qmlsignal NetworkSettingsManager::userAgent.error() - - This signal is emitted when the connection failed due to invalid user credentials. -*/ diff --git a/src/networksettings/networksettingsqml/qnetworksettingsforeign.h b/src/networksettings/networksettingsqml/qnetworksettingsforeign.h deleted file mode 100644 index b979397..0000000 --- a/src/networksettings/networksettingsqml/qnetworksettingsforeign.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef NETWORKSETTINGSPLUGIN_PLUGIN_H -#define NETWORKSETTINGSPLUGIN_PLUGIN_H - -#include <QtQml/qqml.h> -#include <QtNetworkSettings/qnetworksettings.h> -#include <QtNetworkSettings/qnetworksettingsmanager.h> -#include <QtNetworkSettings/qnetworksettingsservice.h> -#include <QtNetworkSettings/qnetworksettingsuseragent.h> -#include <QtNetworkSettings/qnetworksettingsservicemodel.h> -#include <QtNetworkSettings/qnetworksettingsinterface.h> -#include <QtNetworkSettings/qnetworksettingsinterfacemodel.h> - -Q_DECLARE_METATYPE(QNetworkSettingsUserAgent) -Q_DECLARE_METATYPE(QNetworkSettingsServiceFilter) -Q_DECLARE_METATYPE(QNetworkSettingsInterfaceModel) - -QT_BEGIN_NAMESPACE - -struct NetworkSettingsServiceForeign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsService) - QML_NAMED_ELEMENT(NetworkSettingsService) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -struct NetworkSettingsInterfaceForeign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsInterface) - QML_NAMED_ELEMENT(NetworkSettingsInterface) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -struct NetworkSettingsIPv4Foreign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsIPv4) - QML_NAMED_ELEMENT(NetworkSettingsIPv4) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -struct NetworkSettingsIPv6Foreign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsIPv6) - QML_NAMED_ELEMENT(NetworkSettingsIPv6) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -struct NetworkSettingsProxyForeign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsProxy) - QML_NAMED_ELEMENT(NetworkSettingsProxy) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -struct NetworkSettingsTypeForeign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsType) - QML_NAMED_ELEMENT(NetworkSettingsType) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -struct NetworkSettingsStateForeign -{ - Q_GADGET - QML_FOREIGN(QNetworkSettingsState) - QML_NAMED_ELEMENT(NetworkSettingsState) - QML_UNCREATABLE("Cannot be instantiated directly.") - QML_ADDED_IN_VERSION(1, 0) -}; - -class QNetworkSettingsManagerForeign -{ - Q_GADGET - QML_NAMED_ELEMENT(NetworkSettingsManager) - QML_SINGLETON - QML_ADDED_IN_VERSION(2, 0) -}; - -QT_END_NAMESPACE - -#endif // NETWORKSETTINGSPLUGIN_PLUGIN_H - diff --git a/src/networksettings/qnetworksettings.cpp b/src/networksettings/qnetworksettings.cpp index 79ec2d4..b984835 100644 --- a/src/networksettings/qnetworksettings.cpp +++ b/src/networksettings/qnetworksettings.cpp @@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE */ /*! - \enum QNetworkSettingsState::States + \enum QNetworkSettingsState::State This enum type holds the state of the network interface. @@ -95,21 +95,21 @@ QT_BEGIN_NAMESPACE \property QNetworkSettingsState::state \brief The state of the network interface. - \sa QNetworkSettingsState::States + \sa QNetworkSettingsState::State */ /*! \fn QNetworkSettingsState::stateChanged() This signal is emitted when the state of the network interface changes. - \sa QNetworkSettingsState::States + \sa QNetworkSettingsState::State */ /*! Creates a new network interface state object with the state \a state and the parent \a parent. */ -QNetworkSettingsState::QNetworkSettingsState(States state, QObject *parent) +QNetworkSettingsState::QNetworkSettingsState(State state, QObject *parent) : QObject(parent) , m_state(state) { @@ -127,14 +127,14 @@ QNetworkSettingsState::QNetworkSettingsState(QObject *parent) /*! Returns the network interface state. */ -QNetworkSettingsState::States QNetworkSettingsState::state() const { +QNetworkSettingsState::State QNetworkSettingsState::state() const { return m_state; } /*! Sets the network interface state to \a state. */ -void QNetworkSettingsState::setState(const States state) { +void QNetworkSettingsState::setState(const State state) { m_state = state; emit stateChanged(); } @@ -150,7 +150,7 @@ void QNetworkSettingsState::setState(const States state) { */ /*! - \enum QNetworkSettingsType::Types + \enum QNetworkSettingsType::Type This enum type holds the type of the network interface. @@ -168,21 +168,21 @@ void QNetworkSettingsState::setState(const States state) { \property QNetworkSettingsType::type \brief The type of the network interface. - \sa QNetworkSettingsType::Types + \sa QNetworkSettingsType::Type */ /*! \fn QNetworkSettingsType::typeChanged() This signal is emitted when the type of the network interface changes. - \sa QNetworkSettingsType::Types + \sa QNetworkSettingsType::Type */ /*! Creates a new network interface type object with the type \a type and parent \a parent. */ -QNetworkSettingsType::QNetworkSettingsType(Types type, QObject *parent) +QNetworkSettingsType::QNetworkSettingsType(Type type, QObject *parent) : QObject(parent) , m_type(type) { @@ -201,14 +201,14 @@ QNetworkSettingsType::QNetworkSettingsType(QObject *parent) /*! Returns the network interface type. */ -QNetworkSettingsType::Types QNetworkSettingsType::type() const { +QNetworkSettingsType::Type QNetworkSettingsType::type() const { return m_type; } /*! Sets the network interface type to \a type. */ -void QNetworkSettingsType::setType(const Types type) { +void QNetworkSettingsType::setType(const Type type) { m_type = type; emit typeChanged(); } @@ -222,7 +222,7 @@ void QNetworkSettingsType::setType(const Types type) { */ /*! - \enum QNetworkSettingsIPv4::MethodType + \enum QNetworkSettingsIPv4::Method This enum type holds the method used for IPv4 configuration. @@ -248,7 +248,7 @@ void QNetworkSettingsType::setType(const Types type) { \property QNetworkSettingsIPv4::method \brief Holds the method of IPv4 configuration. - \sa QNetworkSettingsIPv4::MethodType + \sa QNetworkSettingsIPv4::Method */ /*! @@ -282,11 +282,11 @@ void QNetworkSettingsIPv4::setGateway(const QString& gateway) { emit gatewayChanged(); } -QNetworkSettingsIPv4::MethodType QNetworkSettingsIPv4::method() const { +QNetworkSettingsIPv4::Method QNetworkSettingsIPv4::method() const { return m_method; } -void QNetworkSettingsIPv4::setMethod(const MethodType method) { +void QNetworkSettingsIPv4::setMethod(const Method method) { m_method = method; emit methodChanged(); } @@ -309,7 +309,7 @@ void QNetworkSettingsIPv4::setMask(const QString& mask) { */ /*! - \enum QNetworkSettingsIPv6::MethodType + \enum QNetworkSettingsIPv6::Method This enum type holds the method used for IPv6 configuration. @@ -322,7 +322,7 @@ void QNetworkSettingsIPv4::setMask(const QString& mask) { */ /*! - \enum QNetworkSettingsIPv6::PrivacyType + \enum QNetworkSettingsIPv6::Privacy \brief Holds the method of applying the privacy extensions in IPv6. \value Disabled @@ -349,14 +349,14 @@ void QNetworkSettingsIPv4::setMask(const QString& mask) { \property QNetworkSettingsIPv6::method \brief Holds the method of IPv6 configuration. - \sa QNetworkSettingsIPv6::MethodType + \sa QNetworkSettingsIPv6::Method */ /*! \property QNetworkSettingsIPv6::privacy \brief Holds the method of applying privacy extensions for IPv6. - \sa QNetworkSettingsIPv6::PrivacyType + \sa QNetworkSettingsIPv6::Privacy */ /*! @@ -391,20 +391,20 @@ void QNetworkSettingsIPv6::setGateway(const QString& gateway) { emit gatewayChanged(); } -QNetworkSettingsIPv6::MethodType QNetworkSettingsIPv6::method() const { +QNetworkSettingsIPv6::Method QNetworkSettingsIPv6::method() const { return m_method; } -void QNetworkSettingsIPv6::setMethod(const MethodType method) { +void QNetworkSettingsIPv6::setMethod(const Method method) { m_method = method; emit methodChanged(); } -QNetworkSettingsIPv6::PrivacyType QNetworkSettingsIPv6::privacy() const { +QNetworkSettingsIPv6::Privacy QNetworkSettingsIPv6::privacy() const { return m_privacy; } -void QNetworkSettingsIPv6::setPrivacy(const PrivacyType privacy) { +void QNetworkSettingsIPv6::setPrivacy(const Privacy privacy) { m_privacy = privacy; emit privacyChanged(); } @@ -427,7 +427,7 @@ void QNetworkSettingsIPv6::setPrefixLength(const int& prefixLength) { */ /*! - \enum QNetworkSettingsProxy::MethodType + \enum QNetworkSettingsProxy::Method \brief Holds the network proxy configuration method. \value Direct @@ -444,7 +444,7 @@ void QNetworkSettingsIPv6::setPrefixLength(const int& prefixLength) { \property QNetworkSettingsProxy::method \brief Holds the network proxy configuration method. - \sa MethodType + \sa QNetworkSettingsProxy::Method */ /*! @@ -454,7 +454,7 @@ void QNetworkSettingsIPv6::setPrefixLength(const int& prefixLength) { For manual proxy configuration, this property holds the proxy server address. For automatic configuration, it holds the proxy auto-config URL. - \sa MethodType + \sa QNetworkSettingsProxy::Method */ /*! @@ -537,11 +537,11 @@ void QNetworkSettingsProxy::setExcludes(const QStringList& excludes) { emit excludesChanged(); } -QNetworkSettingsProxy::MethodType QNetworkSettingsProxy::method(void) const { +QNetworkSettingsProxy::Method QNetworkSettingsProxy::method(void) const { return m_method; } -void QNetworkSettingsProxy::setMethod(const MethodType& method) { +void QNetworkSettingsProxy::setMethod(const Method& method) { m_method = method; emit methodChanged(); } @@ -554,7 +554,7 @@ void QNetworkSettingsProxy::setMethod(const MethodType& method) { */ /*! - \enum QNetworkSettingsWireless::SecurityFlags + \enum QNetworkSettingsWireless::Security \brief This enum type holds the wireless security protocol used to protect the connection. @@ -599,15 +599,12 @@ QNetworkSettingsWireless::QNetworkSettingsWireless(QObject* parent) /*! Returns whether the Wifi network supports the wireless security - protocols specified in \a security. + protocol specified in \a security. - \sa QNetworkSettingsWireless::SecurityFlags + \sa QNetworkSettingsWireless::Security */ -bool QNetworkSettingsWireless::supportsSecurity(SecurityFlags security) { - if (m_securityFlags & security) { - return true; - } - return false; +bool QNetworkSettingsWireless::supportsSecurity(Security security) { + return m_supportedSecurites.testFlag(security); } bool QNetworkSettingsWireless::hidden() const { @@ -635,14 +632,10 @@ void QNetworkSettingsWireless::setSignalStrength(const int signalStrength) { } /*! - Sets \a security flags. + Sets \a securities flags. */ -void QNetworkSettingsWireless::setSecurity(const SecurityFlags security) { - if (security == None) { - m_securityFlags = None; - } else { - m_securityFlags |= security; - } +void QNetworkSettingsWireless::setSecurity(const Securities securities) { + m_supportedSecurites = securities; } void QNetworkSettingsWireless::setOutOfRange(const bool aOutOfRange) { diff --git a/src/networksettings/qnetworksettings.h b/src/networksettings/qnetworksettings.h index 84f5899..6006149 100644 --- a/src/networksettings/qnetworksettings.h +++ b/src/networksettings/qnetworksettings.h @@ -29,82 +29,96 @@ #ifndef QNETWORKSETTINGS_H #define QNETWORKSETTINGS_H -#include <QObject> -#include <QUrl> -#include <QVariantMap> +#include <QtNetworkSettings/qnetworksettingsglobal.h> + +#include <QtCore/qobject.h> +#include <QtCore/qurl.h> #include <QtNetworkSettings/qnetworksettingsaddressmodel.h> QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsState : public QObject +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsState : public QObject { Q_OBJECT - Q_ENUMS(States) - Q_PROPERTY(States state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged) public: - enum States {Idle, Failure, Association, Configuration, Ready, Disconnect, Online, Undefined}; + enum State { + Idle = 0, + Failure, + Association, + Configuration, + Ready, + Disconnect, + Online, + Undefined + }; + Q_ENUM(State) - explicit QNetworkSettingsState(States state, QObject *parent = Q_NULLPTR); - explicit QNetworkSettingsState(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsState(State state, QObject *parent = nullptr); + explicit QNetworkSettingsState(QObject *parent = nullptr); - States state() const; - void setState(const States state); + State state() const; + void setState(const State state); Q_SIGNALS: void stateChanged(); private: - States m_state; + State m_state; }; -class Q_DECL_EXPORT QNetworkSettingsType : public QObject +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsType : public QObject { Q_OBJECT - Q_ENUMS(Types) - Q_PROPERTY(Types type READ type WRITE setType NOTIFY typeChanged) + Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged) public: - enum Types { - Wired, + enum Type { + Wired = 0, Wifi, Bluetooth, Unknown }; + Q_ENUM(Type) - explicit QNetworkSettingsType(Types type, QObject *parent = Q_NULLPTR); - explicit QNetworkSettingsType(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsType(Type type, QObject *parent = nullptr); + explicit QNetworkSettingsType(QObject *parent = nullptr); - Types type() const; - void setType(const Types type); + Type type() const; + void setType(const Type type); Q_SIGNALS: void typeChanged(); private: - Types m_type; + Type m_type; }; -class Q_DECL_EXPORT QNetworkSettingsIPv4 : public QObject +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsIPv4 : public QObject { Q_OBJECT - Q_ENUMS(MethodType) Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) Q_PROPERTY(QString gateway READ gateway WRITE setGateway NOTIFY gatewayChanged) - Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(Method method READ method WRITE setMethod NOTIFY methodChanged) Q_PROPERTY(QString mask READ mask WRITE setMask NOTIFY maskChanged) public: - explicit QNetworkSettingsIPv4(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsIPv4(QObject *parent = nullptr); - enum MethodType {Dhcp, Manual, Off}; + enum Method { + Dhcp = 0, + Manual, + Off + }; + Q_ENUM(Method) QString address() const; void setAddress(const QString& address); QString gateway() const; void setGateway(const QString& gateway); - MethodType method() const; - void setMethod(const MethodType method); + Method method() const; + void setMethod(const Method method); QString mask() const; void setMask(const QString& mask); @@ -117,35 +131,44 @@ Q_SIGNALS: private: QString m_address; QString m_gateway; - MethodType m_method; + Method m_method; QString m_mask; }; - -class Q_DECL_EXPORT QNetworkSettingsIPv6 : public QObject +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsIPv6 : public QObject { Q_OBJECT - Q_ENUMS(MethodType PrivacyType) Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) Q_PROPERTY(QString gateway READ gateway WRITE setGateway NOTIFY gatewayChanged) - Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) - Q_PROPERTY(PrivacyType privacy READ privacy WRITE setPrivacy NOTIFY privacyChanged) + Q_PROPERTY(Method method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(Privacy privacy READ privacy WRITE setPrivacy NOTIFY privacyChanged) Q_PROPERTY(int prefixLength READ prefixLength WRITE setPrefixLength NOTIFY prefixLengthChanged) public: - explicit QNetworkSettingsIPv6(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsIPv6(QObject *parent = nullptr); - enum MethodType {Auto, Manual, Off}; - enum PrivacyType {Disabled, Enabled, Preferred}; + enum Method { + Auto = 0, + Manual, + Off + }; + Q_ENUM(Method) + + enum Privacy { + Disabled = 0, + Enabled, + Preferred + }; + Q_ENUM(Privacy) QString address() const; void setAddress(const QString& address); QString gateway() const; void setGateway(const QString& gateway); - MethodType method() const; - void setMethod(const MethodType method); - PrivacyType privacy() const; - void setPrivacy(const PrivacyType privacy); + Method method() const; + void setMethod(const Method method); + Privacy privacy() const; + void setPrivacy(const Privacy privacy); int prefixLength() const; void setPrefixLength(const int& prefixLength); @@ -159,23 +182,27 @@ Q_SIGNALS: private: QString m_address; QString m_gateway; - MethodType m_method; - PrivacyType m_privacy; + Method m_method; + Privacy m_privacy; int m_prefixLength; }; -class Q_DECL_EXPORT QNetworkSettingsProxy : public QObject +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsProxy : public QObject { Q_OBJECT - Q_ENUMS(MethodType) Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) Q_PROPERTY(QAbstractItemModel* servers READ servers NOTIFY serversChanged) Q_PROPERTY(QAbstractItemModel* excludes READ excludes NOTIFY excludesChanged) - Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(Method method READ method WRITE setMethod NOTIFY methodChanged) public: - explicit QNetworkSettingsProxy(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsProxy(QObject *parent = nullptr); - enum MethodType {Direct, Auto, Manual}; + enum Method { + Direct = 0, + Auto, + Manual + }; + Q_ENUM(Method) QUrl url() const; void setUrl(const QUrl& url); @@ -185,8 +212,8 @@ public: QAbstractItemModel* excludes(); QStringList excludes() const; void setExcludes(const QStringList& excludes); - MethodType method() const; - void setMethod(const MethodType& method); + Method method() const; + void setMethod(const Method& method); Q_SIGNALS: void urlChanged(); @@ -197,27 +224,32 @@ private: QUrl m_url; QNetworkSettingsAddressModel m_servers; QNetworkSettingsAddressModel m_excludes; - MethodType m_method; + Method m_method; }; -class Q_DECL_EXPORT QNetworkSettingsWireless : public QObject +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsWireless : public QObject { Q_OBJECT - Q_ENUMS(SecurityFlags) Q_PROPERTY(int signalStrength READ signalStrength WRITE setSignalStrength NOTIFY signalStrengthChanged) Q_PROPERTY(bool hidden READ hidden NOTIFY hiddenChanged) Q_PROPERTY(bool isOutOfRange READ outOfRange WRITE setOutOfRange NOTIFY outOfRangeChanged) public: - explicit QNetworkSettingsWireless(QObject* parent = Q_NULLPTR); + explicit QNetworkSettingsWireless(QObject* parent = nullptr); - enum SecurityFlags {None=1, WEP=2, WPA=4, WPA2=8}; + enum class Security { + None = 0x0000, + WEP = 0x0002, + WPA = 0x0004, + WPA2 = 0x0008 + }; + Q_DECLARE_FLAGS(Securities, Security) - Q_INVOKABLE bool supportsSecurity(SecurityFlags security); + Q_INVOKABLE bool supportsSecurity(Security security); bool hidden() const; void setHidden(const bool hidden); int signalStrength() const; void setSignalStrength(const int signalStrength); - void setSecurity(const SecurityFlags security); + void setSecurity(const Securities securities); void setOutOfRange(const bool aOutOfRange); bool outOfRange() const; @@ -227,11 +259,12 @@ Q_SIGNALS: void passwordChanged(); void outOfRangeChanged(); private: - quint16 m_securityFlags; + Securities m_supportedSecurites; bool m_hidden; int m_signalStrength; bool m_isOutOfRange; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkSettingsWireless::Securities) QT_END_NAMESPACE diff --git a/src/networksettings/qnetworksettingsaddressmodel.h b/src/networksettings/qnetworksettingsaddressmodel.h index 3b0ed8d..b08f381 100644 --- a/src/networksettings/qnetworksettingsaddressmodel.h +++ b/src/networksettings/qnetworksettingsaddressmodel.h @@ -29,17 +29,18 @@ #ifndef QNETWORKSETTINGSADDRESSMODEL_H #define QNETWORKSETTINGSADDRESSMODEL_H -#include <QStringListModel> +#include <QtCore/qstringlistmodel.h> +#include <QtNetworkSettings/qnetworksettingsglobal.h> QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsAddressModel : public QStringListModel +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsAddressModel : public QStringListModel { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) public: - explicit QNetworkSettingsAddressModel(QObject *parent = Q_NULLPTR); - explicit QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsAddressModel(QObject *parent = nullptr); + explicit QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent = nullptr); Q_INVOKABLE void append(const QString& address); Q_INVOKABLE void remove(int index); Q_INVOKABLE void resetChanges(); diff --git a/src/networksettings/qnetworksettingsglobal.h b/src/networksettings/qnetworksettingsglobal.h new file mode 100644 index 0000000..c9af207 --- /dev/null +++ b/src/networksettings/qnetworksettingsglobal.h @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSGLOBAL_H +#define QNETWORKSETTINGSGLOBAL_H + +#include <QtNetworkSettings/qtnetworksettingsexports.h> + +#endif // QNETWORKSETTINGSGLOBAL_H diff --git a/src/networksettings/qnetworksettingsinterface.cpp b/src/networksettings/qnetworksettingsinterface.cpp index d885394..9907867 100644 --- a/src/networksettings/qnetworksettingsinterface.cpp +++ b/src/networksettings/qnetworksettingsinterface.cpp @@ -28,7 +28,6 @@ ****************************************************************************/ #include "qnetworksettingsinterface.h" #include "qnetworksettingsinterface_p.h" -#include "qnetworksettings.h" QT_BEGIN_NAMESPACE @@ -49,7 +48,7 @@ QT_BEGIN_NAMESPACE \readonly \brief Holds the state of the network interface. - \sa QNetworkSettingsState::States + \sa QNetworkSettingsState::State */ /*! @@ -68,7 +67,7 @@ QT_BEGIN_NAMESPACE \readonly \brief Holds the type of the network interface. - \sa QNetworkSettingsType::Types + \sa QNetworkSettingsType::Type */ /*! @@ -146,7 +145,7 @@ QString QNetworkSettingsInterface::name() const /*! Returns the state of the network interface. */ -QNetworkSettingsState::States QNetworkSettingsInterface::state() +QNetworkSettingsState::State QNetworkSettingsInterface::state() { Q_D(QNetworkSettingsInterface); return d->state(); @@ -168,7 +167,7 @@ QNetworkSettingsState::States QNetworkSettingsInterface::state() /*! Returns the type of the network interface. */ -QNetworkSettingsType::Types QNetworkSettingsInterface::type() +QNetworkSettingsType::Type QNetworkSettingsInterface::type() { Q_D(QNetworkSettingsInterface); return d->type(); diff --git a/src/networksettings/qnetworksettingsinterface.h b/src/networksettings/qnetworksettingsinterface.h index 20c1187..5fb9636 100644 --- a/src/networksettings/qnetworksettingsinterface.h +++ b/src/networksettings/qnetworksettingsinterface.h @@ -29,25 +29,25 @@ #ifndef QNETWORKSETTINGSINTERFACE_H #define QNETWORKSETTINGSINTERFACE_H -#include <QObject> +#include <QtCore/qobject.h> #include <QtNetworkSettings/qnetworksettings.h> -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsInterfacePrivate) - QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsInterface : public QObject { +class QNetworkSettingsInterfacePrivate; +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsInterface : public QObject +{ Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(QNetworkSettingsState::States state READ state NOTIFY stateChanged) - Q_PROPERTY(QNetworkSettingsType::Types type READ type NOTIFY typeChanged) + Q_PROPERTY(QNetworkSettingsState::State state READ state NOTIFY stateChanged) + Q_PROPERTY(QNetworkSettingsType::Type type READ type NOTIFY typeChanged) Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) public: - explicit QNetworkSettingsInterface(QObject* parent = Q_NULLPTR); + explicit QNetworkSettingsInterface(QObject* parent = nullptr); QString name() const; - QNetworkSettingsState::States state(); - QNetworkSettingsType::Types type(); + QNetworkSettingsState::State state(); + QNetworkSettingsType::Type type(); bool powered() const; void setPowered(const bool powered); Q_INVOKABLE void scanServices(); diff --git a/src/networksettings/qnetworksettingsinterfacemodel.cpp b/src/networksettings/qnetworksettingsinterfacemodel.cpp index 045d3ff..95eff25 100644 --- a/src/networksettings/qnetworksettingsinterfacemodel.cpp +++ b/src/networksettings/qnetworksettingsinterfacemodel.cpp @@ -46,9 +46,9 @@ QT_BEGIN_NAMESPACE \brief This enum type holds information about a network interface. \value Type - Network interface \l{QNetworkSettingsType::Types}{type}. + Network interface \l{QNetworkSettingsType::Type}{type}. \value Status - Network interface \l{QNetworkSettingsState::States}{state}. + Network interface \l{QNetworkSettingsState::State}{state}. \value Name Network interface name. \value Powered @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE QNetworkSettingsInterfaceModel::QNetworkSettingsInterfaceModel(QObject *parent) : QAbstractListModel(parent) { - m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Qt::UserRole, "entry"); m_roleNames.insert(Type, "type"); m_roleNames.insert(Status, "status"); m_roleNames.insert(Name, "name"); @@ -122,12 +122,7 @@ QVariant QNetworkSettingsInterfaceModel::data(const QModelIndex & index, int rol */ void QNetworkSettingsInterfaceModel::append(QNetworkSettingsInterface* item) { - item->setParent(this); - connectStateChanges(item); - - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_items.append(item); - endInsertRows(); + insert(rowCount(), item); } /*! @@ -155,7 +150,7 @@ void QNetworkSettingsInterfaceModel::connectStateChanges(QNetworkSettingsInterfa void QNetworkSettingsInterfaceModel::remove(int row) { beginRemoveRows(QModelIndex(), row, row); - m_items.removeFirst(); + m_items.takeAt(row)->deleteLater(); endRemoveRows(); } @@ -196,7 +191,7 @@ void QNetworkSettingsInterfaceModel::connectionStatusChanged() QNetworkSettingsInterface *s = qobject_cast<QNetworkSettingsInterface*>(sender()); int row = 0; - foreach (QNetworkSettingsInterface* item, m_items) { + for (QNetworkSettingsInterface* item : m_items) { if (item == s) { updated(row); break; @@ -210,7 +205,7 @@ void QNetworkSettingsInterfaceModel::poweredChanged() { QNetworkSettingsInterface *s = qobject_cast<QNetworkSettingsInterface*>(sender()); int row = 0; - foreach (QNetworkSettingsInterface* item, m_items) { + for (QNetworkSettingsInterface* item : m_items) { if (item == s) { updated(row); break; diff --git a/src/networksettings/qnetworksettingsinterfacemodel.h b/src/networksettings/qnetworksettingsinterfacemodel.h index 42d40b6..aa6aa69 100644 --- a/src/networksettings/qnetworksettingsinterfacemodel.h +++ b/src/networksettings/qnetworksettingsinterfacemodel.h @@ -29,19 +29,18 @@ #ifndef QNETWORKSETTINGSINTERFACEMODEL_H #define QNETWORKSETTINGSINTERFACEMODEL_H -#include <QAbstractListModel> -#include <QtNetworkSettings/qnetworksettings.h> +#include <QtCore/QAbstractListModel> +#include <QtNetworkSettings/qnetworksettingsglobal.h> QT_BEGIN_NAMESPACE class QNetworkSettingsInterface; - -class Q_DECL_EXPORT QNetworkSettingsInterfaceModel : public QAbstractListModel +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsInterfaceModel : public QAbstractListModel { Q_OBJECT public: - explicit QNetworkSettingsInterfaceModel(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsInterfaceModel(QObject *parent = nullptr); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const override; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; diff --git a/src/networksettings/qnetworksettingsmanager.cpp b/src/networksettings/qnetworksettingsmanager.cpp index 667004f..7ec82fa 100644 --- a/src/networksettings/qnetworksettingsmanager.cpp +++ b/src/networksettings/qnetworksettingsmanager.cpp @@ -26,6 +26,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "qnetworksettings.h" #include "qnetworksettingsmanager.h" #include "qnetworksettingsservice.h" #include "qnetworksettingsservicemodel.h" @@ -33,7 +34,6 @@ #include "qnetworksettingsinterfacemodel.h" #include "qnetworksettingsmanager_p.h" #include "qnetworksettingsuseragent.h" -#include <QStringListModel> QT_BEGIN_NAMESPACE @@ -82,7 +82,7 @@ QT_BEGIN_NAMESPACE { QList<QNetworkSettingsInterface*> interfaces = manager->interfaces()->getModel(); for (const auto &interface : interfaces) { - if (interface->type() == QNetworkSettingsType::Types::Wifi) { + if (interface->type() == QNetworkSettingsType::Type::Wifi) { if (interface->powered()) { interface->scanServices(); } else { @@ -167,7 +167,7 @@ QNetworkSettingsManager::QNetworkSettingsManager(QObject *parent) : /*! Returns the service model. - \l QNetworkSettingsType::Types + \l QNetworkSettingsType::Type */ QNetworkSettingsServiceFilter *QNetworkSettingsManager::services() { @@ -191,7 +191,7 @@ QNetworkSettingsService* QNetworkSettingsManager::service(const QString& name, i { Q_D(QNetworkSettingsManager); - foreach (QNetworkSettingsService* service, d->serviceModel()->getModel()) { + for (QNetworkSettingsService* service : d->serviceModel()->getModel()) { if (service->name() == name && service->type() == type) { return service; } @@ -299,7 +299,7 @@ QNetworkSettingsInterface* QNetworkSettingsManager::interface(int type, int inst Q_D(QNetworkSettingsManager); int matchingInstance = 0; - foreach (QNetworkSettingsInterface* interface, d->m_interfaceModel.getModel()) { + for (QNetworkSettingsInterface* interface : d->m_interfaceModel.getModel()) { if (interface->type() == type) { if (matchingInstance == instance) { return interface; diff --git a/src/networksettings/qnetworksettingsmanager.h b/src/networksettings/qnetworksettingsmanager.h index 01159dd..9f562d3 100644 --- a/src/networksettings/qnetworksettingsmanager.h +++ b/src/networksettings/qnetworksettingsmanager.h @@ -29,31 +29,30 @@ #ifndef QNETWORKSETTINGSMANAGER_H #define QNETWORKSETTINGSMANAGER_H -#include <QtNetworkSettings/qnetworksettings.h> -#include <QObject> -#include <QStringListModel> -#include <QtNetworkSettings/qnetworksettingsservicemodel.h> -#include <QtNetworkSettings/qnetworksettingsinterfacemodel.h> -#include <QtNetworkSettings/qnetworksettingsuseragent.h> -#include <QtNetworkSettings/qnetworksettingsservice.h> - -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsManagerPrivate) -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsInterface) +#include <QtCore/qobject.h> +#include <QtNetworkSettings/qnetworksettingsglobal.h> QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsManager : public QObject +class QNetworkSettingsService; +class QNetworkSettingsInterface; +class QNetworkSettingsUserAgent; +class QNetworkSettingsServiceFilter; +class QNetworkSettingsInterfaceModel; +class QNetworkSettingsManagerPrivate; +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsManager : public QObject { Q_OBJECT - Q_ENUMS(StateTypes NetworkTypeTypes) Q_PROPERTY(QNetworkSettingsServiceFilter* services READ services NOTIFY servicesChanged) Q_PROPERTY(QNetworkSettingsInterfaceModel* interfaces READ interfaces NOTIFY interfacesChanged) Q_PROPERTY(QNetworkSettingsUserAgent* userAgent READ userAgent CONSTANT) Q_PROPERTY(QNetworkSettingsService* currentWifiConnection READ currentWifiConnection NOTIFY currentWifiConnectionChanged) Q_PROPERTY(QNetworkSettingsService* currentWiredConnection READ currentWiredConnection NOTIFY currentWiredConnectionChanged) + Q_MOC_INCLUDE("qnetworksettingsservicemodel.h") + Q_MOC_INCLUDE("qnetworksettingsuseragent.h") public: - explicit QNetworkSettingsManager(QObject* parent = Q_NULLPTR); + explicit QNetworkSettingsManager(QObject* parent = nullptr); QNetworkSettingsServiceFilter* services(); QNetworkSettingsInterfaceModel* interfaces(); void setUserAgent(QNetworkSettingsUserAgent *agent); @@ -81,7 +80,6 @@ protected: private: Q_DISABLE_COPY(QNetworkSettingsManager) Q_DECLARE_PRIVATE(QNetworkSettingsManager) - }; QT_END_NAMESPACE diff --git a/src/networksettings/qnetworksettingsservice.cpp b/src/networksettings/qnetworksettingsservice.cpp index 0983c0d..ef0773c 100644 --- a/src/networksettings/qnetworksettingsservice.cpp +++ b/src/networksettings/qnetworksettingsservice.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE \readonly \brief Holds the state of this service. - \sa QNetworkSettingsState::States + \sa QNetworkSettingsState::State */ /*! @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE \readonly \brief Holds the type of this service. - \sa QNetworkSettingsType::Types + \sa QNetworkSettingsType::Type */ /*! @@ -195,6 +195,8 @@ QString QNetworkSettingsService::name() const } /*! + \fn void QNetworkSettingsService::setAutoConnect(bool autoconnect) + Sets automatic connections to the network service to \a autoconnect. */ void QNetworkSettingsService::setAutoConnect(const bool autoconnect) @@ -224,9 +226,9 @@ bool QNetworkSettingsService::autoConnect() const /*! Returns the network service state. - \sa QNetworkSettingsState::States + \sa QNetworkSettingsState::State */ -QNetworkSettingsState::States QNetworkSettingsService::state() +QNetworkSettingsState::State QNetworkSettingsService::state() { Q_D(QNetworkSettingsService); return d->m_state.state(); @@ -244,9 +246,9 @@ QNetworkSettingsState::States QNetworkSettingsService::state() /*! Returns the network service type. - \sa QNetworkSettingsType::Types + \sa QNetworkSettingsType::Type */ -QNetworkSettingsType::Types QNetworkSettingsService::type() +QNetworkSettingsType::Type QNetworkSettingsService::type() { Q_D(QNetworkSettingsService); return d->m_type.type(); diff --git a/src/networksettings/qnetworksettingsservice.h b/src/networksettings/qnetworksettingsservice.h index dd9d52a..0b71d50 100644 --- a/src/networksettings/qnetworksettingsservice.h +++ b/src/networksettings/qnetworksettingsservice.h @@ -29,21 +29,19 @@ #ifndef QNETWORKSETTINGSSERVICE_H #define QNETWORKSETTINGSSERVICE_H -#include <QObject> +#include <QtCore/qobject.h> #include <QtNetworkSettings/qnetworksettings.h> -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServicePrivate) - QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsService : public QObject +class QNetworkSettingsServicePrivate; +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsService : public QObject { Q_OBJECT - Q_ENUMS(StateTypes) Q_PROPERTY(QString id READ id CONSTANT) Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(QNetworkSettingsState::States state READ state NOTIFY stateChanged) - Q_PROPERTY(QNetworkSettingsType::Types type READ type NOTIFY typeChanged) + Q_PROPERTY(QNetworkSettingsState::State state READ state NOTIFY stateChanged) + Q_PROPERTY(QNetworkSettingsType::Type type READ type NOTIFY typeChanged) Q_PROPERTY(QNetworkSettingsIPv4* ipv4 READ ipv4 NOTIFY ipv4Changed) Q_PROPERTY(QNetworkSettingsIPv6* ipv6 READ ipv6 NOTIFY ipv6Changed) Q_PROPERTY(QNetworkSettingsProxy* proxy READ proxy NOTIFY proxyChanged) @@ -52,12 +50,12 @@ class Q_DECL_EXPORT QNetworkSettingsService : public QObject Q_PROPERTY(QAbstractItemModel* nameservers READ nameservers NOTIFY nameserversChanged) Q_PROPERTY(bool autoConnect READ autoConnect WRITE setAutoConnect NOTIFY autoConnectChanged) public: - explicit QNetworkSettingsService(const QString& aServiceId, QObject* parent = Q_NULLPTR); + explicit QNetworkSettingsService(const QString& aServiceId, QObject* parent = nullptr); QString id() const; QString name() const; - QNetworkSettingsState::States state(); - QNetworkSettingsType::Types type(); + QNetworkSettingsState::State state(); + QNetworkSettingsType::Type type(); QNetworkSettingsIPv4* ipv4(); QNetworkSettingsIPv6* ipv6(); QNetworkSettingsProxy* proxy(); diff --git a/src/networksettings/qnetworksettingsservicemodel.cpp b/src/networksettings/qnetworksettingsservicemodel.cpp index 115fe35..0927bcc 100644 --- a/src/networksettings/qnetworksettingsservicemodel.cpp +++ b/src/networksettings/qnetworksettingsservicemodel.cpp @@ -27,6 +27,7 @@ ** ****************************************************************************/ #include "qnetworksettingsservicemodel.h" +#include "qnetworksettingsservice.h" #include "qnetworksettings.h" QT_BEGIN_NAMESPACE @@ -49,7 +50,7 @@ QT_BEGIN_NAMESPACE This enum type holds information about the network connection. \value Type - Network \l{QNetworkSettingsType::Types}{type}. + Network \l{QNetworkSettingsType::Type}{type}. \value Name The service set identifier (SSID) of the network. \value SignalStrength @@ -64,7 +65,8 @@ QT_BEGIN_NAMESPACE QNetworkSettingsServiceModel::QNetworkSettingsServiceModel(QObject *parent) : QAbstractListModel(parent) { - m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Qt::UserRole, "entry"); + m_roleNames.insert(Type, "type"); m_roleNames.insert(Name, "name"); m_roleNames.insert(SignalStrength, "signalStrength"); m_roleNames.insert(Connected, "connected"); @@ -107,6 +109,9 @@ QVariant QNetworkSettingsServiceModel::data(const QModelIndex & index, int role) if (role == Qt::UserRole) { return QVariant::fromValue(static_cast<QObject*>(item)); } + else if (role == Type) { + return item->type(); + } else if (role == Name) { return item->name(); } @@ -229,7 +234,7 @@ void QNetworkSettingsServiceModel::updated(int row) QNetworkSettingsService* QNetworkSettingsServiceModel::getByName(const QString& name) { QNetworkSettingsService* ret = nullptr; - foreach (QNetworkSettingsService* item, m_items) { + for (QNetworkSettingsService* item : m_items) { if (item->name() == name) { ret = item; break; @@ -254,7 +259,7 @@ void QNetworkSettingsServiceModel::connectionStatusChanged() QNetworkSettingsService *s = qobject_cast<QNetworkSettingsService*>(sender()); int row = 0; - foreach (QNetworkSettingsService* item, m_items) { + for (QNetworkSettingsService* item : m_items) { if (item == s) { updated(row); break; @@ -271,7 +276,7 @@ void QNetworkSettingsServiceModel::signalStrengthChanged() { QNetworkSettingsWireless *s = qobject_cast<QNetworkSettingsWireless*>(sender()); int row = 0; - foreach (QNetworkSettingsService* item, m_items) { + for (QNetworkSettingsService* item : m_items) { if (item->wirelessConfig() == s) { updated(row); break; @@ -296,7 +301,7 @@ void QNetworkSettingsServiceModel::signalStrengthChanged() \property QNetworkSettingsServiceFilter::type \brief The type of the network. - \l QNetworkSettingsType::Types + \l QNetworkSettingsType::Type */ /*! @@ -318,7 +323,7 @@ void QNetworkSettingsServiceModel::signalStrengthChanged() /*! \qmltype NetworkSettingsServiceFilter - \inqmlmodule QtDeviceutilities.NetworkSettings + \inqmlmodule QtDeviceUtilities.NetworkSettings \abstract */ @@ -351,19 +356,19 @@ QNetworkSettingsServiceFilter::~QNetworkSettingsServiceFilter() /*! Returns the service model. - \l QNetworkSettingsType::Types + \l QNetworkSettingsType::Type */ -QNetworkSettingsType::Types QNetworkSettingsServiceFilter::type() const +QNetworkSettingsType::Type QNetworkSettingsServiceFilter::type() const { return m_type; } /*! - \fn void QNetworkSettingsServiceFilter::setType(QNetworkSettingsType::Types type) + \fn void QNetworkSettingsServiceFilter::setType(QNetworkSettingsType::Type type) Sets the service model to \a type. */ -void QNetworkSettingsServiceFilter::setType(const QNetworkSettingsType::Types type) +void QNetworkSettingsServiceFilter::setType(const QNetworkSettingsType::Type type) { m_type = type; emit typeChanged(); @@ -429,7 +434,7 @@ int QNetworkSettingsServiceFilter::activeRow() const QNetworkSettingsServiceModel* model = qobject_cast<QNetworkSettingsServiceModel*>(sourceModel()); QList<QNetworkSettingsService*> data = model->getModel(); int row = 0; - foreach (QNetworkSettingsService* item, data) { + for (QNetworkSettingsService* item : data) { if (item->type() == m_type && (item->state() == QNetworkSettingsState::Ready || item->state() == QNetworkSettingsState::Online)) { diff --git a/src/networksettings/qnetworksettingsservicemodel.h b/src/networksettings/qnetworksettingsservicemodel.h index 01447f6..b4392d2 100644 --- a/src/networksettings/qnetworksettingsservicemodel.h +++ b/src/networksettings/qnetworksettingsservicemodel.h @@ -29,17 +29,17 @@ #ifndef QNETWORKSETTINGSSERVICEMODEL_H #define QNETWORKSETTINGSSERVICEMODEL_H -#include <QSortFilterProxyModel> +#include <QtCore/qsortfilterproxymodel.h> #include <QtNetworkSettings/qnetworksettings.h> -#include <QtNetworkSettings/qnetworksettingsservice.h> QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsServiceModel : public QAbstractListModel +class QNetworkSettingsService; +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsServiceModel : public QAbstractListModel { Q_OBJECT public: - explicit QNetworkSettingsServiceModel(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsServiceModel(QObject *parent = nullptr); virtual ~QNetworkSettingsServiceModel(); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const override; @@ -74,17 +74,17 @@ private: QHash<int, QByteArray> m_roleNames; }; -class Q_DECL_EXPORT QNetworkSettingsServiceFilter : public QSortFilterProxyModel +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsServiceFilter : public QSortFilterProxyModel { Q_OBJECT - Q_PROPERTY(QNetworkSettingsType::Types type READ type WRITE setType NOTIFY typeChanged) + Q_PROPERTY(QNetworkSettingsType::Type type READ type WRITE setType NOTIFY typeChanged) Q_PROPERTY(bool wiredNetworksAvailable MEMBER m_wiredNetworksAvailable WRITE setWiredNetworksAvailable NOTIFY wiredNetworksAvailableChanged) public: - explicit QNetworkSettingsServiceFilter(QObject* parent = Q_NULLPTR); + explicit QNetworkSettingsServiceFilter(QObject* parent = nullptr); virtual ~QNetworkSettingsServiceFilter(); bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; - QNetworkSettingsType::Types type() const; - void setType(QNetworkSettingsType::Types type); + QNetworkSettingsType::Type type() const; + void setType(QNetworkSettingsType::Type type); Q_INVOKABLE QVariant itemFromRow(const int row) const; Q_INVOKABLE int activeRow() const; void setWiredNetworksAvailable(bool); @@ -92,7 +92,7 @@ Q_SIGNALS: void typeChanged(); void wiredNetworksAvailableChanged(); private: - QNetworkSettingsType::Types m_type; + QNetworkSettingsType::Type m_type; bool m_wiredNetworksAvailable; }; diff --git a/src/networksettings/qnetworksettingsuseragent.h b/src/networksettings/qnetworksettingsuseragent.h index 7b76c15..63964b6 100644 --- a/src/networksettings/qnetworksettingsuseragent.h +++ b/src/networksettings/qnetworksettingsuseragent.h @@ -29,17 +29,17 @@ #ifndef QNETWORKSETTINGSUSERAGENT_H #define QNETWORKSETTINGSUSERAGENT_H -#include <QObject> - -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsUserAgentPrivate) +#include <QtCore/qobject.h> +#include <QtNetworkSettings/qnetworksettingsglobal.h> QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QNetworkSettingsUserAgent : public QObject +class QNetworkSettingsUserAgentPrivate; +class Q_NETWORKSETTINGS_EXPORT QNetworkSettingsUserAgent : public QObject { Q_OBJECT public: - explicit QNetworkSettingsUserAgent(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsUserAgent(QObject *parent = nullptr); Q_INVOKABLE void setPassphrase(const QString &passphrase); Q_INVOKABLE void cancelInput(); QString passphrase() const; |