diff options
Diffstat (limited to 'src')
39 files changed, 684 insertions, 459 deletions
diff --git a/src/bluetoothsettings/bluetoothdevice.h b/src/bluetoothsettings/bluetoothdevice.h index 84d1615..8519044 100644 --- a/src/bluetoothsettings/bluetoothdevice.h +++ b/src/bluetoothsettings/bluetoothdevice.h @@ -41,7 +41,7 @@ class Q_DECL_EXPORT BluetoothDevice : public QObject Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) Q_PROPERTY(QObject* deviceModel READ deviceModel CONSTANT) public: - explicit BluetoothDevice(QObject *parent = nullptr); + explicit BluetoothDevice(QObject *parent = Q_NULLPTR); bool powered() const; void setPowered(const bool& aPowered); QObject* deviceModel() const; @@ -50,7 +50,6 @@ public: Q_INVOKABLE void requestPairing(const QString& address); Q_INVOKABLE void requestConnect(const QString& address); Q_INVOKABLE void requestDisconnect(const QString& address); - Q_SIGNALS: void poweredChanged(); void scanningChanged(); diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.h b/src/bluetoothsettings/bluez/bluetoothdevice_p.h index 7c8a78a..84d1382 100644 --- a/src/bluetoothsettings/bluez/bluetoothdevice_p.h +++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.h @@ -36,7 +36,7 @@ class OrgBluezDevice1Interface; class BluetoothDevicePrivate : public QObject { public: - explicit BluetoothDevicePrivate(const QString& address, QObject *parent = nullptr); + explicit BluetoothDevicePrivate(const QString& address, QObject *parent = Q_NULLPTR); void connectDevice(); void disconnectDevice(); diff --git a/src/bluetoothsettings/discoverymodel.h b/src/bluetoothsettings/discoverymodel.h index e32ad9b..12554d7 100644 --- a/src/bluetoothsettings/discoverymodel.h +++ b/src/bluetoothsettings/discoverymodel.h @@ -44,7 +44,7 @@ class Q_DECL_EXPORT BtDeviceItem : public QObject Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) Q_PROPERTY(DeviceType type READ type CONSTANT) public: - explicit BtDeviceItem(const QBluetoothDeviceInfo& id, QObject *parent = nullptr); + explicit BtDeviceItem(const QBluetoothDeviceInfo& id, QObject *parent = Q_NULLPTR); //The list of device type we want to show the icon enum DeviceType { Phone, @@ -90,7 +90,7 @@ class Q_DECL_EXPORT DiscoveryModel : public QAbstractListModel Q_OBJECT Q_ENUMS(DeviceType) public: - explicit DiscoveryModel(QObject *parent = nullptr); + explicit DiscoveryModel(QObject *parent = Q_NULLPTR); virtual ~DiscoveryModel(); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const; @@ -111,7 +111,6 @@ Q_SIGNALS: private Q_SLOTS: void deviceDiscovered(const QBluetoothDeviceInfo &device); - private: QList<BtDeviceItem*> m_items; QHash<int, QByteArray> m_roleNames; diff --git a/src/displaysettings/displaysettings.h b/src/displaysettings/displaysettings.h index c6f4bab..1874357 100644 --- a/src/displaysettings/displaysettings.h +++ b/src/displaysettings/displaysettings.h @@ -42,7 +42,7 @@ class Q_DECL_EXPORT DisplaySettings : public QObject Q_PROPERTY(bool physicalScreenSizeOverride READ physicalScreenSizeOverride WRITE setPhysicalScreenSizeOverride NOTIFY physicalScreenSizeOverrideChanged) public: - DisplaySettings(QObject *parent = nullptr); + DisplaySettings(QObject *parent = Q_NULLPTR); ~DisplaySettings(); int displayBrightness(); diff --git a/src/displaysettings/displaysettings_p.cpp b/src/displaysettings/displaysettings_p.cpp index 7e4cb58..c7bbc9a 100644 --- a/src/displaysettings/displaysettings_p.cpp +++ b/src/displaysettings/displaysettings_p.cpp @@ -74,7 +74,6 @@ void DisplaySettingsPrivate::initLightDevices() bool DisplaySettingsPrivate::setDisplayBrightness(int v) { - Q_Q(DisplaySettings); quint8 value = qBound(0, v, 255); initLightDevices(); for (int i = 0; i < m_lightDevices.size(); i++) { diff --git a/src/displaysettings/displaysettings_p.h b/src/displaysettings/displaysettings_p.h index 48f7048..b1c0e4d 100644 --- a/src/displaysettings/displaysettings_p.h +++ b/src/displaysettings/displaysettings_p.h @@ -37,7 +37,7 @@ class PhysicalScreenSize : public QObject Q_OBJECT public: - explicit PhysicalScreenSize(QObject *parent = nullptr); + explicit PhysicalScreenSize(QObject *parent = Q_NULLPTR); virtual ~PhysicalScreenSize(); void setSize(int inches); diff --git a/src/imports/imports.pro b/src/imports/imports.pro index f34be18..8c10510 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,7 +1,8 @@ TEMPLATE = subdirs SUBDIRS += networksettings \ - bluetoothsettings \ localesettings \ timedatesettings \ localdevice \ displaysettings + +qtHaveModule(bluetooth): SUBDIRS += bluetoothsettings diff --git a/src/imports/networksettings/plugin.cpp b/src/imports/networksettings/plugin.cpp index 245e952..c1dac53 100644 --- a/src/imports/networksettings/plugin.cpp +++ b/src/imports/networksettings/plugin.cpp @@ -31,6 +31,8 @@ #include <qnetworksettingsmanager.h> #include <qnetworksettingsservice.h> #include <qnetworksettingsuseragent.h> +#include <qnetworksettingsservicemodel.h> +#include <qnetworksettingsinterfacemodel.h> #include <qqml.h> #include <QQmlEngine> @@ -44,7 +46,7 @@ \brief Provides singleton QML types for controlling network settings. Provides singleton QML types for controlling network settings in an - embedded device. + embedded device.QAbstractItemModel Import the module as follows: @@ -106,7 +108,7 @@ */ /*! - \qmlmethod NetworkService NetworkSettingsManager::getService(string name, int type) + \qmlmethod NetworkService NetworkSettingsManager::service(string name, int type) Returns the service with name \a name and type \a type. @@ -161,5 +163,8 @@ void NetworksettingspluginPlugin::registerTypes(const char *uri) qmlRegisterUncreatableType<QNetworkSettingsState>(uri, 1, 0, "NetworkSettingsState", "Cannot be instantiated directly."); qRegisterMetaType<QNetworkSettingsUserAgent*>("QNetworkSettingsUserAgent*"); + qRegisterMetaType<QNetworkSettingsServiceFilter*>("QNetworkSettingsServiceFilter*"); + qRegisterMetaType<QNetworkSettingsInterfaceModel*>("QNetworkSettingsInterfaceModel*"); + qmlRegisterSingletonType<QNetworkSettingsManager>(uri, 1, 0, "NetworkSettingsManager", &instance<QNetworkSettingsManager>); } diff --git a/src/localdevice/qlocaldevice.h b/src/localdevice/qlocaldevice.h index 7695866..c9918f0 100644 --- a/src/localdevice/qlocaldevice.h +++ b/src/localdevice/qlocaldevice.h @@ -36,7 +36,7 @@ class Q_DECL_EXPORT QLocalDevice : public QObject Q_OBJECT public: - QLocalDevice(QObject *parent = nullptr); + QLocalDevice(QObject *parent = Q_NULLPTR); ~QLocalDevice(); public Q_SLOTS: diff --git a/src/localesettings/localemodel.h b/src/localesettings/localemodel.h index 61a42c4..4fb00a0 100644 --- a/src/localesettings/localemodel.h +++ b/src/localesettings/localemodel.h @@ -41,7 +41,7 @@ class LocaleItem : public QObject Q_PROPERTY(QString country READ country CONSTANT) Q_PROPERTY(QString language READ language CONSTANT) public: - explicit LocaleItem(const QLocale &locale, QObject *parent = nullptr); + explicit LocaleItem(const QLocale &locale, QObject *parent = Q_NULLPTR); QString country() const; QString language() const; QString code() const; @@ -57,7 +57,7 @@ class Q_DECL_EXPORT LocaleModel : public QAbstractListModel Q_OBJECT public: - explicit LocaleModel(QObject *parent = nullptr); + explicit LocaleModel(QObject *parent = Q_NULLPTR); virtual ~LocaleModel(); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const; diff --git a/src/localesettings/systemlocale.h b/src/localesettings/systemlocale.h index e942974..075d397 100644 --- a/src/localesettings/systemlocale.h +++ b/src/localesettings/systemlocale.h @@ -38,11 +38,12 @@ class Q_DECL_EXPORT SystemLocale : public QObject Q_OBJECT Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged) public: - explicit SystemLocale(QObject *parent = nullptr); + explicit SystemLocale(QObject *parent = Q_NULLPTR); QString locale() const; void setLocale(const QString& aLocale); Q_SIGNALS: void localeChanged(); +public Q_SLOTS: protected: SystemLocalePrivate *d_ptr; diff --git a/src/localesettings/systemlocale_p.h b/src/localesettings/systemlocale_p.h index f5caed9..761c5cd 100644 --- a/src/localesettings/systemlocale_p.h +++ b/src/localesettings/systemlocale_p.h @@ -64,7 +64,7 @@ public: QStringList newLocale; QMap<QString, QString>::iterator i; for (i = m_localeCache.begin(); i != m_localeCache.end(); ++i) { - QString val = i.key() + "=" + i.value(); + QString val = i.key() + QLatin1String("=") + i.value(); newLocale.append(val); } m_localeInterface->SetLocale(newLocale, true); diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.cpp b/src/networksettings/connman/qnetworksettingsinterface_p.cpp index 3525aa7..83ab73a 100644 --- a/src/networksettings/connman/qnetworksettingsinterface_p.cpp +++ b/src/networksettings/connman/qnetworksettingsinterface_p.cpp @@ -33,6 +33,7 @@ QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) : QObject(parent) + , m_technology(Q_NULLPTR) ,q_ptr(parent) { diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.h b/src/networksettings/connman/qnetworksettingsinterface_p.h index 7f5ee7b..eabe610 100644 --- a/src/networksettings/connman/qnetworksettingsinterface_p.h +++ b/src/networksettings/connman/qnetworksettingsinterface_p.h @@ -66,7 +66,7 @@ class ConnmanSettingsInterface : public QNetworkSettingsInterface { Q_OBJECT public: - ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent = nullptr) + ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent = Q_NULLPTR) :QNetworkSettingsInterface(parent) { if (d_ptr) diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/networksettings/connman/qnetworksettingsmanager_p.cpp index 875be9b..22e8005 100644 --- a/src/networksettings/connman/qnetworksettingsmanager_p.cpp +++ b/src/networksettings/connman/qnetworksettingsmanager_p.cpp @@ -37,6 +37,11 @@ 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) { qDBusRegisterMetaType<ConnmanMapStruct>(); qDBusRegisterMetaType<ConnmanMapStructList>(); @@ -54,13 +59,13 @@ QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsM //List technologies QDBusPendingReply<ConnmanMapStructList> reply = m_manager->GetTechnologies(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SLOT(getTechnologiesFinished(QDBusPendingCallWatcher*))); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, &QNetworkSettingsManagerPrivate::getTechnologiesFinished); reply = m_manager->GetServices(); watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SLOT(getServicesFinished(QDBusPendingCallWatcher*))); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, &QNetworkSettingsManagerPrivate::getServicesFinished); connect(m_manager, &NetConnmanManagerInterface::ServicesChanged, this, &QNetworkSettingsManagerPrivate::onServicesChanged); @@ -93,25 +98,7 @@ void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher foreach (const ConnmanMapStruct &object, reply.value()) { const QString servicePath = object.objectPath.path(); - QNetworkSettingsService *service = new QNetworkSettingsService(servicePath, this); - m_serviceModel->append(service); - - //Update status property - QString n = qdbus_cast<QString>(object.propertyMap[PropertyName]); - QString t = qdbus_cast<QString>(object.propertyMap[PropertyType]); - QString s = qdbus_cast<QString>(object.propertyMap[PropertyState]); - - QNetworkSettingsType type; - t >> type; - QNetworkSettingsState state; - s >> state; - - foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) { - ConnmanSettingsInterface* technology = qobject_cast<ConnmanSettingsInterface*>(item); - if (technology->name() == n && technology->type() == type.type()) { - technology->setState(state.state()); - } - } + handleNewService(servicePath); } emit q->servicesChanged(); } @@ -156,9 +143,26 @@ void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList chan if (!found) newServices.append(map.objectPath.path()); } + foreach (QString newService, newServices) { - QNetworkSettingsService *service = new QNetworkSettingsService(newService, this); + handleNewService(newService); + } +} + +void QNetworkSettingsManagerPrivate::handleNewService(const QString &servicePath) +{ + Q_Q(QNetworkSettingsManager); + + QNetworkSettingsService *service = new QNetworkSettingsService(servicePath, this); + + if (service->name().length() > 0 && service->type() != QNetworkSettingsType::Unknown) { m_serviceModel->append(service); + emit q->servicesChanged(); + } + else { + //Service name or type not set, wait for update + connect(service, &QNetworkSettingsService::nameChanged, this, &QNetworkSettingsManagerPrivate::serviceReady); + connect(service, &QNetworkSettingsService::typeChanged, this, &QNetworkSettingsManagerPrivate::serviceReady); } } @@ -166,3 +170,24 @@ void QNetworkSettingsManagerPrivate::setUserAgent(QNetworkSettingsUserAgent *age { m_agent = agent; } + +void QNetworkSettingsManagerPrivate::serviceReady() +{ + Q_Q(QNetworkSettingsManager); + + QNetworkSettingsService* service = qobject_cast<QNetworkSettingsService*>(sender()); + if (service->name().length() > 0 && service->type() != QNetworkSettingsType::Unknown) { + service->disconnect(this); + m_serviceModel->append(service); + emit q->servicesChanged(); + + //Update the interface state accordingly + foreach (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 cb42654..b6e23ab 100644 --- a/src/networksettings/connman/qnetworksettingsmanager_p.h +++ b/src/networksettings/connman/qnetworksettingsmanager_p.h @@ -38,6 +38,7 @@ class NetConnmanManagerInterface; class QNetworkSettingsServiceModel; class QNetworkSettingsServiceFilter; +class QNetworkSettingsService; class QNetworkSettingsManagerPrivate : public QObject { @@ -47,13 +48,15 @@ public: explicit QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent); QNetworkSettingsManager *q_ptr; void setUserAgent(QNetworkSettingsUserAgent *agent); - QNetworkSettingsUserAgent *getUserAgent() {return m_agent;} + QNetworkSettingsUserAgent *userAgent() {return m_agent;} public slots: void getServicesFinished(QDBusPendingCallWatcher *watcher); void getTechnologiesFinished(QDBusPendingCallWatcher *watcher); void requestInput(const QString& service, const QString& type); void onServicesChanged(ConnmanMapStructList changed, const QList<QDBusObjectPath> &removed); - + void serviceReady(); +private: + void handleNewService(const QString& servicePath); protected: QNetworkSettingsInterfaceModel m_interfaceModel; QNetworkSettingsServiceModel *m_serviceModel; diff --git a/src/networksettings/connman/qnetworksettingsservice_p.cpp b/src/networksettings/connman/qnetworksettingsservice_p.cpp index 8a7b2cf..e8aabff 100644 --- a/src/networksettings/connman/qnetworksettingsservice_p.cpp +++ b/src/networksettings/connman/qnetworksettingsservice_p.cpp @@ -362,6 +362,7 @@ void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QV else if (key == PropertyType) { QString value = qdbus_cast<QString>(val); value >> m_type; + emit q->typeChanged(); } else if (key == PropertyStrength) { m_wifiConfig.setSignalStrength(val.toInt()); diff --git a/src/networksettings/connman/qnetworksettingsservice_p.h b/src/networksettings/connman/qnetworksettingsservice_p.h index e9166d7..58adbb9 100644 --- a/src/networksettings/connman/qnetworksettingsservice_p.h +++ b/src/networksettings/connman/qnetworksettingsservice_p.h @@ -29,10 +29,11 @@ #ifndef QNETWORKSETTINGSSERVICEPRIVATE_H #define QNETWORKSETTINGSSERVICEPRIVATE_H -#include <QtDBus> #include "qnetworksettingsservice.h" #include "qnetworksettings.h" +class QDBusPendingCallWatcher; +class QDBusVariant; class NetConnmanServiceInterface; class QNetworkSettingsServicePrivate : public QObject @@ -40,7 +41,7 @@ class QNetworkSettingsServicePrivate : public QObject Q_OBJECT Q_DECLARE_PUBLIC(QNetworkSettingsService) public: - QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent = nullptr); + QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent = Q_NULLPTR); QNetworkSettingsService *q_ptr; private slots: diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.h b/src/networksettings/connman/qnetworksettingsuseragent_p.h index ecce5ae..ff8c1d0 100644 --- a/src/networksettings/connman/qnetworksettingsuseragent_p.h +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.h @@ -50,7 +50,7 @@ class QNetworkSettingsUserAgentPrivate : public QDBusAbstractAdaptor Q_CLASSINFO("D-Bus Interface", "net.connman.Agent") Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) public: - QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent = nullptr); + QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent = Q_NULLPTR); void setUserCredentials(const QString& aUsername, const QString& aPassword); void cancel(); void release(); diff --git a/src/networksettings/networksettings.pro b/src/networksettings/networksettings.pro index 9ae1bb3..db2ce06 100644 --- a/src/networksettings/networksettings.pro +++ b/src/networksettings/networksettings.pro @@ -19,6 +19,7 @@ else { # Input SOURCES += \ qnetworksettingsinterfacemodel.cpp \ + qnetworksettings.cpp \ qnetworksettingsmanager.cpp \ qnetworksettingsaddressmodel.cpp \ qnetworksettingsservicemodel.cpp \ diff --git a/src/networksettings/qnetworksettings.cpp b/src/networksettings/qnetworksettings.cpp new file mode 100644 index 0000000..fae1b7d --- /dev/null +++ b/src/networksettings/qnetworksettings.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#include "qnetworksettings.h" + +QNetworkSettingsState::QNetworkSettingsState(States state, QObject *parent) + : QObject(parent) + , m_state(state) +{ +} + +QNetworkSettingsState::QNetworkSettingsState(QObject *parent) + : QObject(parent) + , m_state(Undefined) +{ +} + +QNetworkSettingsState::States QNetworkSettingsState::state() const { + return m_state; +} + +void QNetworkSettingsState::setState(const States state) { + m_state = state; + emit stateChanged(); +} + +QNetworkSettingsType::QNetworkSettingsType(Types type, QObject *parent) + : QObject(parent) + , m_type(type) +{ + m_type = type; +} + +QNetworkSettingsType::QNetworkSettingsType(QObject *parent) + : QObject(parent) +{ + m_type = Unknown; +} + +QNetworkSettingsType::Types QNetworkSettingsType::type() const { + return m_type; +} + +void QNetworkSettingsType::setType(const Types type) { + m_type = type; + emit typeChanged(); +} + +QNetworkSettingsIPv4::QNetworkSettingsIPv4(QObject *parent) + : QObject(parent) +{ +} + +QString QNetworkSettingsIPv4::address() const { + return m_address; +} +void QNetworkSettingsIPv4::setAddress(const QString& address) { + m_address = address; + emit addressChanged(); +} + +QString QNetworkSettingsIPv4::gateway() const { + return m_gateway; +} + +void QNetworkSettingsIPv4::setGateway(const QString& gateway) { + m_gateway = gateway; + emit gatewayChanged(); +} + +QNetworkSettingsIPv4::MethodType QNetworkSettingsIPv4::method() const { + return m_method; +} + +void QNetworkSettingsIPv4::setMethod(const MethodType method) { + m_method = method; + emit methodChanged(); +} + +QString QNetworkSettingsIPv4::mask() const { + return m_mask; +} + +void QNetworkSettingsIPv4::setMask(const QString& mask) { + m_mask = mask; + emit maskChanged(); +} + +QNetworkSettingsIPv6::QNetworkSettingsIPv6(QObject *parent) + : QObject(parent) +{ +} + +QString QNetworkSettingsIPv6::address() const { + return m_address; +} + +void QNetworkSettingsIPv6::setAddress(const QString& address) { + m_address = address; + emit addressChanged(); +} + +QString QNetworkSettingsIPv6::gateway() const { + return m_gateway; +} + +void QNetworkSettingsIPv6::setGateway(const QString& gateway) { + m_gateway = gateway; + emit gatewayChanged(); +} + +QNetworkSettingsIPv6::MethodType QNetworkSettingsIPv6::method() const { + return m_method; +} + +void QNetworkSettingsIPv6::setMethod(const MethodType method) { + m_method = method; + emit methodChanged(); +} + +QNetworkSettingsIPv6::PrivacyType QNetworkSettingsIPv6::privacy() const { + return m_privacy; +} + +void QNetworkSettingsIPv6::setPrivacy(const PrivacyType privacy) { + m_privacy = privacy; + emit privacyChanged(); +} + +int QNetworkSettingsIPv6::prefixLength() const { + return m_prefixLength; +} + +void QNetworkSettingsIPv6::setPrefixLength(const int& prefixLength) { + m_prefixLength = prefixLength; + emit prefixLengthChanged(); +} + +QNetworkSettingsProxy::QNetworkSettingsProxy(QObject *parent) + : QObject(parent) +{ + +} + +QUrl QNetworkSettingsProxy::url() const { + return m_url; +} + +void QNetworkSettingsProxy::setUrl(const QUrl& url) { + m_url = url; + emit urlChanged(); +} + +QAbstractItemModel* QNetworkSettingsProxy::servers(void) { + return &m_servers; +} + +void QNetworkSettingsProxy::setServers(const QStringList& servers) { + m_servers.setStringList(servers); + emit serversChanged(); +} + +QStringList QNetworkSettingsProxy::servers() const { + return m_servers.stringList(); +} + +QAbstractItemModel* QNetworkSettingsProxy::excludes(void) { + return &m_excludes; +} + +QStringList QNetworkSettingsProxy::excludes() const { + return m_excludes.stringList(); +} + +void QNetworkSettingsProxy::setExcludes(const QStringList& excludes) { + m_excludes.setStringList(excludes); + emit excludesChanged(); +} + +QNetworkSettingsProxy::MethodType QNetworkSettingsProxy::method(void) const { + return m_method; +} + +void QNetworkSettingsProxy::setMethod(const MethodType& method) { + m_method = method; + emit methodChanged(); +} + +QNetworkSettingsWireless::QNetworkSettingsWireless(QObject* parent) + : QObject(parent) { +} + +bool QNetworkSettingsWireless::supportsSecurity(SecurityFlags security) { + if (m_securityFlags & security) { + return true; + } + return false; +} + +bool QNetworkSettingsWireless::hidden() const { + return m_hidden; +} + +void QNetworkSettingsWireless::setHidden(const bool hidden) { + m_hidden = hidden; + emit hiddenChanged(); +} + +int QNetworkSettingsWireless::signalStrength() const { + return m_signalStrength; +} + +void QNetworkSettingsWireless::setSignalStrength(const int signalStrength) { + m_signalStrength = signalStrength; + emit signalStrengthChanged(); +} + +void QNetworkSettingsWireless::setSecurity(const SecurityFlags security) { + if (security == None) { + m_securityFlags = None; + } else { + m_securityFlags |= security; + } +} + +void QNetworkSettingsWireless::setOutOfRange(const bool aOutOfRange) { + m_isOutOfRange = aOutOfRange; + emit outOfRangeChanged(); +} + +bool QNetworkSettingsWireless::outOfRange() const { + return m_isOutOfRange; +} + diff --git a/src/networksettings/qnetworksettings.h b/src/networksettings/qnetworksettings.h index 858e7e9..5323f98 100644 --- a/src/networksettings/qnetworksettings.h +++ b/src/networksettings/qnetworksettings.h @@ -43,26 +43,11 @@ class Q_DECL_EXPORT QNetworkSettingsState : public QObject public: enum States {Idle, Failure, Association, Configuration, Ready, Disconnect, Online, Undefined}; - explicit QNetworkSettingsState(States state, QObject *parent = nullptr) - : QObject(parent) - { - m_state = state; - } - - explicit QNetworkSettingsState(QObject *parent = nullptr) - : QObject(parent) - { - m_state = Undefined; - } - - States state() const { - return m_state; - } - - void setState(const States state) { - m_state = state; - Q_EMIT stateChanged(); - } + explicit QNetworkSettingsState(States state, QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsState(QObject *parent = Q_NULLPTR); + + States state() const; + void setState(const States state); Q_SIGNALS: void stateChanged(); @@ -85,27 +70,11 @@ public: Unknown }; - explicit QNetworkSettingsType(Types type, QObject *parent = nullptr) - : QObject(parent) - { - m_type = type; - } - - explicit QNetworkSettingsType(QObject *parent = nullptr) - : QObject(parent) - { - m_type = Unknown; - } - + explicit QNetworkSettingsType(Types type, QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsType(QObject *parent = Q_NULLPTR); - Types type() const { - return m_type; - } - - void setType(const Types type) { - m_type = type; - Q_EMIT typeChanged(); - } + Types type() const; + void setType(const Types type); Q_SIGNALS: void typeChanged(); @@ -124,48 +93,18 @@ class Q_DECL_EXPORT QNetworkSettingsIPv4 : public QObject Q_PROPERTY(QString mask READ mask WRITE setMask NOTIFY maskChanged) public: - explicit QNetworkSettingsIPv4(QObject *parent = nullptr) - : QObject(parent) - { - - } + explicit QNetworkSettingsIPv4(QObject *parent = Q_NULLPTR); enum MethodType {Dhcp, Manual, Off}; - QString address() const { - return m_address; - } - void setAddress(const QString& adderess) { - m_address = adderess; - Q_EMIT addressChanged(); - } - - QString gateway() const { - return m_gateway; - } - - void setGateway(const QString& gateway) { - m_gateway = gateway; - Q_EMIT gatewayChanged(); - } - - MethodType method() const { - return m_method; - } - - void setMethod(const MethodType method) { - m_method = method; - Q_EMIT methodChanged(); - } - - QString mask() const { - return m_mask; - } - - void setMask(const QString& mask) { - m_mask = mask; - Q_EMIT maskChanged(); - } + QString address() const; + void setAddress(const QString& address); + QString gateway() const; + void setGateway(const QString& gateway); + MethodType method() const; + void setMethod(const MethodType method); + QString mask() const; + void setMask(const QString& mask); Q_SIGNALS: void addressChanged(); @@ -192,58 +131,21 @@ class Q_DECL_EXPORT QNetworkSettingsIPv6 : public QObject Q_PROPERTY(int prefixLength READ prefixLength WRITE setPrefixLength NOTIFY prefixLengthChanged) public: - explicit QNetworkSettingsIPv6(QObject *parent = nullptr) - : QObject(parent) - { - - } + explicit QNetworkSettingsIPv6(QObject *parent = Q_NULLPTR); enum MethodType {Auto, Manual, Off}; enum PrivacyType {Disabled, Enabled, Preferred}; - QString address() const { - return m_address; - } - void setAddress(const QString& adderess) { - m_address = adderess; - Q_EMIT addressChanged(); - } - - QString gateway() const { - return m_gateway; - } - - void setGateway(const QString& gateway) { - m_gateway = gateway; - Q_EMIT gatewayChanged(); - } - - MethodType method() const { - return m_method; - } - - void setMethod(const MethodType method) { - m_method = method; - Q_EMIT methodChanged(); - } - - PrivacyType privacy() const { - return m_privacy; - } - - void setPrivacy(const PrivacyType privacy) { - m_privacy = privacy; - Q_EMIT privacyChanged(); - } - - int prefixLength() const { - return m_prefixLength; - } - - void setPrefixLength(const int& prefixLength) { - m_prefixLength = prefixLength; - Q_EMIT prefixLengthChanged(); - } + 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); + int prefixLength() const; + void setPrefixLength(const int& prefixLength); Q_SIGNALS: void addressChanged(); @@ -264,63 +166,25 @@ class Q_DECL_EXPORT QNetworkSettingsProxy : public QObject { Q_OBJECT Q_ENUMS(MethodType) -public: 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) - - explicit QNetworkSettingsProxy(QObject *parent=NULL) - : QObject(parent) - { - - } +public: + explicit QNetworkSettingsProxy(QObject *parent = Q_NULLPTR); enum MethodType {Direct, Auto, Manual}; - QUrl url() const { - return m_url; - } - - void setUrl(const QUrl& url) { - m_url = url; - Q_EMIT urlChanged(); - } - - QAbstractItemModel* servers(void) { - return &m_servers; - } - - void setServers(const QStringList& servers) { - m_servers.setStringList(servers); - Q_EMIT serversChanged(); - } - - QStringList servers() const { - return m_servers.stringList(); - } - - QAbstractItemModel* excludes(void) { - return &m_excludes; - } - - QStringList excludes() const { - return m_excludes.stringList(); - } - - void setExcludes(const QStringList& excludes) { - m_excludes.setStringList(excludes); - Q_EMIT excludesChanged(); - } - - MethodType method(void) const { - return m_method; - } - - void setMethod(const MethodType& method) { - m_method = method; - Q_EMIT methodChanged(); - } + QUrl url() const; + void setUrl(const QUrl& url); + QAbstractItemModel* servers(); + void setServers(const QStringList& servers); + QStringList servers() const; + QAbstractItemModel* excludes(); + QStringList excludes() const; + void setExcludes(const QStringList& excludes); + MethodType method() const; + void setMethod(const MethodType& method); Q_SIGNALS: void urlChanged(); @@ -337,58 +201,23 @@ private: class Q_DECL_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 = nullptr) : - QObject(parent) { - } + explicit QNetworkSettingsWireless(QObject* parent = Q_NULLPTR); enum SecurityFlags {None=1, WEP=2, WPA=4, WPA2=8}; - Q_INVOKABLE bool supportsSecurity(SecurityFlags security) { - if (m_securityFlags & security) { - return true; - } - return false; - } - - bool hidden() const { - return m_hidden; - } - - void setHidden(const bool hidden) { - m_hidden = hidden; - Q_EMIT hiddenChanged(); - } - - int signalStrength() const { - return m_signalStrength; - } - - void setSignalStrength(const int signalStrength) { - m_signalStrength = signalStrength; - Q_EMIT signalStrengthChanged(); - } - - void setSecurity(const SecurityFlags security) { - if (security == None) { - m_securityFlags = None; - } - else { - m_securityFlags |= security; - } - } - - void setOutOfRange(const bool aOutOfRange) { - m_isOutOfRange = aOutOfRange; - Q_EMIT outOfRangeChanged(); - } - - bool outOfRange() const { - return m_isOutOfRange; - } + Q_INVOKABLE bool supportsSecurity(SecurityFlags security); + bool hidden() const; + void setHidden(const bool hidden); + int signalStrength() const; + void setSignalStrength(const int signalStrength); + void setSecurity(const SecurityFlags security); + void setOutOfRange(const bool aOutOfRange); + bool outOfRange() const; Q_SIGNALS: void hiddenChanged(); diff --git a/src/networksettings/qnetworksettingsaddressmodel.h b/src/networksettings/qnetworksettingsaddressmodel.h index e6ceb16..16d601d 100644 --- a/src/networksettings/qnetworksettingsaddressmodel.h +++ b/src/networksettings/qnetworksettingsaddressmodel.h @@ -36,8 +36,8 @@ class Q_DECL_EXPORT QNetworkSettingsAddressModel : public QStringListModel Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) public: - explicit QNetworkSettingsAddressModel(QObject *parent = nullptr); - explicit QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent = nullptr); + explicit QNetworkSettingsAddressModel(QObject *parent = Q_NULLPTR); + explicit QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent = Q_NULLPTR); Q_INVOKABLE void append(const QString& address); Q_INVOKABLE void remove(int index); Q_INVOKABLE void resetChanges(); diff --git a/src/networksettings/qnetworksettingsinterface.h b/src/networksettings/qnetworksettingsinterface.h index 7531c6f..a87626d 100644 --- a/src/networksettings/qnetworksettingsinterface.h +++ b/src/networksettings/qnetworksettingsinterface.h @@ -42,7 +42,7 @@ class Q_DECL_EXPORT QNetworkSettingsInterface : public QObject { Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) public: - explicit QNetworkSettingsInterface(QObject* parent = nullptr); + explicit QNetworkSettingsInterface(QObject* parent = Q_NULLPTR); QString name() const; QNetworkSettingsState::States state(); QNetworkSettingsType::Types type(); diff --git a/src/networksettings/qnetworksettingsinterfacemodel.h b/src/networksettings/qnetworksettingsinterfacemodel.h index 2be5280..2fc74bc 100644 --- a/src/networksettings/qnetworksettingsinterfacemodel.h +++ b/src/networksettings/qnetworksettingsinterfacemodel.h @@ -39,7 +39,7 @@ class Q_DECL_EXPORT QNetworkSettingsInterfaceModel : public QAbstractListModel Q_OBJECT public: - explicit QNetworkSettingsInterfaceModel(QObject *parent = nullptr); + explicit QNetworkSettingsInterfaceModel(QObject *parent = Q_NULLPTR); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; diff --git a/src/networksettings/qnetworksettingsmanager.cpp b/src/networksettings/qnetworksettingsmanager.cpp index 787a382..caf6057 100644 --- a/src/networksettings/qnetworksettingsmanager.cpp +++ b/src/networksettings/qnetworksettingsmanager.cpp @@ -39,19 +39,19 @@ QNetworkSettingsManager::QNetworkSettingsManager(QObject *parent) : { } -QAbstractItemModel* QNetworkSettingsManager::services() +QNetworkSettingsServiceFilter *QNetworkSettingsManager::services() { Q_D(QNetworkSettingsManager); return d->m_serviceFilter; } -QAbstractItemModel* QNetworkSettingsManager::interfaces() +QNetworkSettingsInterfaceModel *QNetworkSettingsManager::interfaces() { Q_D(QNetworkSettingsManager); return &d->m_interfaceModel; } -QNetworkSettingsService* QNetworkSettingsManager::getService(const QString& name, const int type) +QNetworkSettingsService* QNetworkSettingsManager::service(const QString& name, const int type) { Q_D(QNetworkSettingsManager); @@ -69,8 +69,8 @@ void QNetworkSettingsManager::setUserAgent(QNetworkSettingsUserAgent *agent) d->setUserAgent(agent); } -QNetworkSettingsUserAgent* QNetworkSettingsManager::getUserAgent() +QNetworkSettingsUserAgent* QNetworkSettingsManager::userAgent() { Q_D(QNetworkSettingsManager); - return d->getUserAgent(); + return d->userAgent(); } diff --git a/src/networksettings/qnetworksettingsmanager.h b/src/networksettings/qnetworksettingsmanager.h index 6f80ec0..86a60c4 100644 --- a/src/networksettings/qnetworksettingsmanager.h +++ b/src/networksettings/qnetworksettingsmanager.h @@ -35,24 +35,27 @@ QT_FORWARD_DECLARE_CLASS(QNetworkSettingsManagerPrivate) QT_FORWARD_DECLARE_CLASS(QNetworkSettingsService) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServiceModel) QT_FORWARD_DECLARE_CLASS(QNetworkSettingsUserAgent) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServiceFilter) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsInterfaceModel) class Q_DECL_EXPORT QNetworkSettingsManager : public QObject { Q_OBJECT Q_ENUMS(StateTypes NetworkTypeTypes) - Q_PROPERTY(QAbstractItemModel* services READ services NOTIFY servicesChanged) - Q_PROPERTY(QAbstractItemModel* interfaces READ interfaces NOTIFY interfacesChanged) - Q_PROPERTY(QNetworkSettingsUserAgent* userAgent READ getUserAgent CONSTANT) + Q_PROPERTY(QNetworkSettingsServiceFilter* services READ services NOTIFY servicesChanged) + Q_PROPERTY(QNetworkSettingsInterfaceModel* interfaces READ interfaces NOTIFY interfacesChanged) + Q_PROPERTY(QNetworkSettingsUserAgent* userAgent READ userAgent CONSTANT) public: - explicit QNetworkSettingsManager(QObject* parent = nullptr); - QAbstractItemModel* services(); - QAbstractItemModel* interfaces(); + explicit QNetworkSettingsManager(QObject* parent = Q_NULLPTR); + QNetworkSettingsServiceFilter* services(); + QNetworkSettingsInterfaceModel* interfaces(); void setUserAgent(QNetworkSettingsUserAgent *agent); - QNetworkSettingsUserAgent* getUserAgent(); + QNetworkSettingsUserAgent* userAgent(); - Q_INVOKABLE QNetworkSettingsService* getService(const QString& name, const int type); + Q_INVOKABLE QNetworkSettingsService* service(const QString& name, const int type); Q_SIGNALS: void servicesChanged(); diff --git a/src/networksettings/qnetworksettingsservice.h b/src/networksettings/qnetworksettingsservice.h index 0a37cd7..89973a8 100644 --- a/src/networksettings/qnetworksettingsservice.h +++ b/src/networksettings/qnetworksettingsservice.h @@ -49,7 +49,7 @@ class Q_DECL_EXPORT QNetworkSettingsService : public QObject Q_PROPERTY(QAbstractItemModel* domains READ domains NOTIFY domainsChanged) Q_PROPERTY(QAbstractItemModel* nameservers READ nameservers NOTIFY nameserversChanged) public: - explicit QNetworkSettingsService(const QString& aServiceId, QObject* parent = nullptr); + explicit QNetworkSettingsService(const QString& aServiceId, QObject* parent = Q_NULLPTR); QString id() const; QString name() const; diff --git a/src/networksettings/qnetworksettingsservicemodel.cpp b/src/networksettings/qnetworksettingsservicemodel.cpp index 2755eda..ce8ea86 100644 --- a/src/networksettings/qnetworksettingsservicemodel.cpp +++ b/src/networksettings/qnetworksettingsservicemodel.cpp @@ -78,6 +78,7 @@ QVariant QNetworkSettingsServiceModel::data(const QModelIndex & index, int role) void QNetworkSettingsServiceModel::append(QNetworkSettingsService* item) { item->setParent(this); + connectStateChanges(item); beginResetModel(); m_items.append(item); @@ -87,14 +88,24 @@ void QNetworkSettingsServiceModel::append(QNetworkSettingsService* item) void QNetworkSettingsServiceModel::insert(int row, QNetworkSettingsService* item) { item->setParent(this); - + connectStateChanges(item); beginInsertRows(QModelIndex(), row, row); m_items.insert(row, item); endInsertRows(); } +void QNetworkSettingsServiceModel::connectStateChanges(QNetworkSettingsService* item) +{ + connect(item, &QNetworkSettingsService::stateChanged, this, &QNetworkSettingsServiceModel::connectionStatusChanged); + QNetworkSettingsWireless* wireless = item->wirelessConfig(); + if (wireless) + connect(wireless, &QNetworkSettingsWireless::signalStrengthChanged, this, &QNetworkSettingsServiceModel::signalStrengthChanged); +} + void QNetworkSettingsServiceModel::remove(int row) { + QNetworkSettingsService* item = m_items.at(row); + item->deleteLater(); beginRemoveRows(QModelIndex(), row, row); m_items.removeAt(row); endRemoveRows(); @@ -123,6 +134,34 @@ QList<QNetworkSettingsService*> QNetworkSettingsServiceModel::getModel() return m_items; } +void QNetworkSettingsServiceModel::connectionStatusChanged() +{ + QNetworkSettingsService *s = qobject_cast<QNetworkSettingsService*>(sender()); + + int row = 0; + foreach (QNetworkSettingsService* item, m_items) { + if (item == s) { + updated(row); + break; + } + row++; + } + +} + +void QNetworkSettingsServiceModel::signalStrengthChanged() +{ + QNetworkSettingsWireless *s = qobject_cast<QNetworkSettingsWireless*>(sender()); + int row = 0; + foreach (QNetworkSettingsService* item, m_items) { + if (item->wirelessConfig() == s) { + updated(row); + break; + } + row++; + } +} + //Filter model /*! @@ -200,3 +239,26 @@ QVariant QNetworkSettingsServiceFilter::itemFromRow(const int row) const return QVariant::fromValue(QStringLiteral("")); } +/*! + \qmlmethod int NetworkSettingsServiceFilter::activeRow() + + Returns the connected service index in the model. + Returns negative number if no active connection is available. +*/ +int QNetworkSettingsServiceFilter::activeRow() const +{ + QNetworkSettingsServiceModel* model = qobject_cast<QNetworkSettingsServiceModel*>(sourceModel()); + QList<QNetworkSettingsService*> data = model->getModel(); + int row = 0; + foreach (QNetworkSettingsService* item, data) { + if (item->type() == m_type && + (item->state() == QNetworkSettingsState::Ready || + item->state() == QNetworkSettingsState::Online)) { + QModelIndex idx = model->index(row, 0); + QModelIndex mapped = mapFromSource(idx); + return mapped.row(); + } + row++; + } + return -1; +} diff --git a/src/networksettings/qnetworksettingsservicemodel.h b/src/networksettings/qnetworksettingsservicemodel.h index a540ff5..c158ec4 100644 --- a/src/networksettings/qnetworksettingsservicemodel.h +++ b/src/networksettings/qnetworksettingsservicemodel.h @@ -37,7 +37,7 @@ class Q_DECL_EXPORT QNetworkSettingsServiceModel : public QAbstractListModel { Q_OBJECT public: - explicit QNetworkSettingsServiceModel(QObject *parent = nullptr); + explicit QNetworkSettingsServiceModel(QObject *parent = Q_NULLPTR); virtual ~QNetworkSettingsServiceModel(); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const; @@ -58,22 +58,30 @@ public: Connected }; + +private Q_SLOTS: + void connectionStatusChanged(); + void signalStrengthChanged(); + private: + void connectStateChanges(QNetworkSettingsService* item); + QList<QNetworkSettingsService*> m_items; QHash<int, QByteArray> m_roleNames; }; -class QNetworkSettingsServiceFilter : public QSortFilterProxyModel +class Q_DECL_EXPORT QNetworkSettingsServiceFilter : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(QNetworkSettingsType::Types type READ type WRITE setType NOTIFY typeChanged) public: - explicit QNetworkSettingsServiceFilter(QObject* parent = nullptr); + explicit QNetworkSettingsServiceFilter(QObject* parent = Q_NULLPTR); virtual ~QNetworkSettingsServiceFilter(); bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; QNetworkSettingsType::Types type() const; void setType(QNetworkSettingsType::Types type); Q_INVOKABLE QVariant itemFromRow(const int row) const; + Q_INVOKABLE int activeRow() const; Q_SIGNALS: void typeChanged(); private: diff --git a/src/networksettings/qnetworksettingsuseragent.h b/src/networksettings/qnetworksettingsuseragent.h index e857fec..89b4d18 100644 --- a/src/networksettings/qnetworksettingsuseragent.h +++ b/src/networksettings/qnetworksettingsuseragent.h @@ -37,7 +37,7 @@ class Q_DECL_EXPORT QNetworkSettingsUserAgent : public QObject { Q_OBJECT public: - explicit QNetworkSettingsUserAgent(QObject *parent = nullptr); + explicit QNetworkSettingsUserAgent(QObject *parent = Q_NULLPTR); Q_INVOKABLE void setUserCredentials(const QString& username, const QString& passphrase); Q_INVOKABLE void cancelInput(); QString passPhrase() const; diff --git a/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h index d042ece..ebb4667 100644 --- a/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h +++ b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h @@ -51,7 +51,7 @@ public: void disconnectNetwork(); QString call(const QString &command); bool checkedCall(const QString &command); - QNetworkSettingsUserAgent *getUserAgent() {return m_agent;} + QNetworkSettingsUserAgent *userAgent() {return m_agent;} protected: bool event(QEvent *event); diff --git a/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h index 06fb132..6ed6d5a 100644 --- a/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h +++ b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h @@ -40,7 +40,7 @@ class QNetworkSettingsServicePrivate : public QObject Q_OBJECT Q_DECLARE_PUBLIC(QNetworkSettingsService) public: - QNetworkSettingsServicePrivate(const QString& aServiceId, QNetworkSettingsService *parent = nullptr); + QNetworkSettingsServicePrivate(const QString& aServiceId, QNetworkSettingsService *parent = Q_NULLPTR); void setManager(QNetworkSettingsManagerPrivate *manager); QNetworkSettingsService *q_ptr; @@ -70,7 +70,7 @@ class WpaSupplicantService : public QNetworkSettingsService { Q_OBJECT public: - explicit WpaSupplicantService(QNetworkSettingsManagerPrivate* manager, QObject* parent = nullptr); + explicit WpaSupplicantService(QNetworkSettingsManagerPrivate* manager, QObject* parent = Q_NULLPTR); void setId(const QString& aId); void setName(const QString& aName); void setFlags(const QString& aFlags); diff --git a/src/settingsui/network/ComboBoxEntry.qml b/src/settingsui/network/ComboBoxEntry.qml index 71b997c..91655ed 100644 --- a/src/settingsui/network/ComboBoxEntry.qml +++ b/src/settingsui/network/ComboBoxEntry.qml @@ -42,6 +42,8 @@ RowLayout { property alias model: cb.model property alias count: cb.count property int titleWidth: -1 + signal activated(var index) + signal highlighted(var index) Label { id: label @@ -53,5 +55,7 @@ RowLayout { id: cb textRole: "text" Layout.fillWidth: true + onActivated: root.activated(index) + onHighlightedIndexChanged: root.highlighted(index) } } diff --git a/src/settingsui/network/NetworkSettings.qml b/src/settingsui/network/NetworkSettings.qml index 52ab1af..9385ee1 100644 --- a/src/settingsui/network/NetworkSettings.qml +++ b/src/settingsui/network/NetworkSettings.qml @@ -33,13 +33,15 @@ import QtDeviceUtilities.NetworkSettings 1.0 Item { property string title: qsTr("Network Settings") + GroupBox { id: networkSelect anchors.rightMargin: parent.width * 0.618 + anchors.left: parent.left anchors.leftMargin: 20 + anchors.top: parent.top anchors.topMargin: 20 - anchors.bottomMargin: 20 - anchors.fill: parent + title: qsTr("Select Connection") function stateToStr(serviceState) { diff --git a/src/settingsui/network/WifiSettings.qml b/src/settingsui/network/WifiSettings.qml index 7a0735c..f7cf823 100644 --- a/src/settingsui/network/WifiSettings.qml +++ b/src/settingsui/network/WifiSettings.qml @@ -37,201 +37,219 @@ Item { Component.onCompleted: NetworkSettingsManager.services.type = NetworkSettingsType.Wifi; property bool connecting: false - GroupBox { - id: content - title: qsTr("Wireless Settings") + Flickable { anchors.fill: parent + contentHeight: content.height + contentWidth: width - ColumnLayout { - spacing: 20 + GroupBox { + title: qsTr("Wireless Settings") width: parent.width - RowLayout { - spacing: 10 - id: enableSwitch + ColumnLayout { + id: content + spacing: 20 width: parent.width - Label { - Layout.preferredWidth: root.width * 0.382 - Layout.alignment: Qt.AlignVCenter - horizontalAlignment: Text.AlignRight - text: selectedInterface.powered ? qsTr("Wi-Fi ON") : qsTr("Wi-Fi OFF") - } - Switch { - checked: selectedInterface.powered - onCheckedChanged: { - selectedInterface.powered = checked - root.connecting = false - connectView.visible = false - } - } - } - RowLayout { - spacing: 10 - width: parent.width - - visible: selectedInterface.powered && networkSelection.count > 0 - Label { - Layout.preferredWidth: root.width * 0.382 - text: qsTr("Current network") - horizontalAlignment: Text.AlignRight - Layout.alignment: Qt.AlignVCenter - - } - ComboBoxEntry { - id: networkSelection - model: NetworkSettingsManager.services - - textRole: "name" - Layout.fillWidth: true - onCurrentIndexChanged: { - if (currentIndex >= 0) { - connectView.visible = false + RowLayout { + spacing: 10 + id: enableSwitch + width: parent.width - var service = model.itemFromRow(currentIndex) - if (service) { - root.connecting = true - service.connectService(); - } - } + Label { + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + text: selectedInterface.powered ? qsTr("Wi-Fi ON") : qsTr("Wi-Fi OFF") } - - onCountChanged: { - if (count === 0) { + Switch { + checked: selectedInterface.powered + onCheckedChanged: { + selectedInterface.powered = checked root.connecting = false connectView.visible = false } } + } + RowLayout { + spacing: 10 + width: parent.width + + visible: selectedInterface.powered && networkSelection.count > 0 + Label { + Layout.preferredWidth: root.width * 0.382 + text: qsTr("Current network") + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignVCenter - delegate: WifiSelectorDelegate { - width: networkSelection.width - onConnectChanged: if (connect) networkSelection.currentIndex = index } - } - } + ComboBoxEntry { + id: networkSelection + model: NetworkSettingsManager.services - Row { - id: infoRow - spacing: 10 - width: parent.width - visible: selectedInterface.powered && selectedInterface.state !== NetworkSettingsState.Online && (networkSelection.count == 0 || root.connecting) - Label { - id: scanningText - text: root.connecting ? qsTr("Connecting to the network...") : qsTr("Searching for Wi-Fi networks...") - horizontalAlignment: Text.AlignLeft - } - WifiSignalMonitor { - id: scanningIcon - scanning: true - height: scanningText.height - width: height - } - } + textRole: "name" + Layout.fillWidth: true + onActivated: { + if (index >= 0) { + connectView.visible = false - GroupBox { - id: connectView - title: qsTr("Enter a password") - visible: false - Layout.fillWidth: true - ColumnLayout { - width: parent.width + var service = model.itemFromRow(index) + if (service) { + root.connecting = true + service.connectService(); + } + } + } - RowLayout { - id: errorView - visible: text.text !== "" - spacing: 10 - property alias text: text.text + onCountChanged: { + if (count === 0) { + root.connecting = false + connectView.visible = false + } + } - Image { - source: "../icons/Alert_yellow_1x.png" - Layout.alignment: Qt.AlignVCenter + Component.onCompleted: { + networkSelection.currentIndex = model.activeRow() } - Text { - id: text - color: "#face20" - text: "" - Layout.alignment: Qt.AlignVCenter + + delegate: WifiSelectorDelegate { + width: networkSelection.width + onConnectChanged: if (connect) networkSelection.currentIndex = index } } - RowLayout { - spacing: 10 - visible: false - width: parent.width + } - Label { - text: qsTr("User name:") - horizontalAlignment: Text.AlignRight - Layout.preferredWidth: root.width * 0.382 - Layout.alignment: Qt.AlignVCenter - } - TextField { - text: "" - inputMethodHints: Qt.ImhNoPredictiveText - Layout.alignment: Qt.AlignVCenter - Layout.fillWidth: true + Row { + id: infoRow + spacing: 10 + width: parent.width + visible: selectedInterface.powered && selectedInterface.state !== NetworkSettingsState.Online + Label { + id: scanningText + text: { + if (networkSelection.count == 0) + return qsTr("Searching for Wi-Fi networks...") + else if (root.connecting) + return qsTr("Connecting to the network...") + else + return "" } + horizontalAlignment: Text.AlignLeft + } + WifiSignalMonitor { + id: scanningIcon + scanning: true + visible: scanningText.text !== "" + height: scanningText.height + width: height } - RowLayout { - spacing: 10 + } + + GroupBox { + id: connectView + title: qsTr("Enter a password") + visible: false + Layout.fillWidth: true + ColumnLayout { width: parent.width - Label { - text: qsTr("Password:") - horizontalAlignment: Text.AlignRight - Layout.preferredWidth: root.width * 0.382 - Layout.alignment: Qt.AlignVCenter + RowLayout { + id: errorView + visible: text.text !== "" + spacing: 10 + property alias text: text.text + + Image { + source: "../icons/Alert_yellow_1x.png" + Layout.alignment: Qt.AlignVCenter + } + Text { + id: text + color: "#face20" + text: "" + Layout.alignment: Qt.AlignVCenter + } } - TextField { - id: password - text: "" - echoMode: TextInput.Password - inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase | Qt.ImhSensitiveData - Layout.alignment: Qt.AlignVCenter - Layout.fillWidth: true + RowLayout { + spacing: 10 + visible: false + width: parent.width + + Label { + text: qsTr("User name:") + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + } + TextField { + text: "" + inputMethodHints: Qt.ImhNoPredictiveText + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true + } } - } - RowLayout { - spacing: 10 + RowLayout { + spacing: 10 + width: parent.width - Button { - text: qsTr("Connect") - onClicked: { - connectView.visible = false - NetworkSettingsManager.userAgent.setUserCredentials("", password.text) + Label { + text: qsTr("Password:") + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + } + TextField { + id: password + text: "" + echoMode: TextInput.Password + inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase | Qt.ImhSensitiveData + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true } } - Button { - text: qsTr("Cancel") - onClicked: { - networkSelection.currentIndex = -1 - connectView.visible = false + RowLayout { + spacing: 10 + + Button { + text: qsTr("Connect") + onClicked: { + connectView.visible = false + NetworkSettingsManager.userAgent.setUserCredentials("", password.text) + } + } + Button { + text: qsTr("Cancel") + onClicked: { + networkSelection.currentIndex = -1 + connectView.visible = false + } } } } } - } - Button { - id: disconnect - text: qsTr("Disconnect") - visible: selectedInterface.state === NetworkSettingsState.Online || - selectedInterface.state === NetworkSettingsState.Ready - onClicked: { - console.log("disconnect"); - NetworkSettingsManager.services.itemFromRow(networkSelection.selectedIndex).disconnectService(); - networkSelection.selectedIndex = -1; + Button { + id: disconnect + text: qsTr("Disconnect") + visible: selectedInterface.state === NetworkSettingsState.Online || + selectedInterface.state === NetworkSettingsState.Ready + onClicked: { + NetworkSettingsManager.services.itemFromRow(networkSelection.currentIndex).disconnectService(); + networkSelection.currentIndex = -1; + root.connecting = false + } } } - } - Connections { - target: NetworkSettingsManager.userAgent - onShowUserCredentialsInput : { - connectView.visible = true - root.connecting = false - } - onError: { - errorView.visible = true - connectView.visible = true - root.connecting = false + Connections { + target: NetworkSettingsManager.userAgent + onShowUserCredentialsInput : { + connectView.visible = true + root.connecting = false + } + onError: { + errorView.visible = true + connectView.visible = true + root.connecting = false + } } } } diff --git a/src/src.pro b/src/src.pro index faa9a6d..27a9700 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,8 +1,10 @@ TEMPLATE = subdirs CONFIG += ordered + +qtHaveModule(bluetooth): SUBDIRS += bluetoothsettings + SUBDIRS += \ networksettings \ - bluetoothsettings \ localesettings \ displaysettings \ timedatesettings \ diff --git a/src/timedatesettings/systemtime.h b/src/timedatesettings/systemtime.h index 6003238..f7ad593 100644 --- a/src/timedatesettings/systemtime.h +++ b/src/timedatesettings/systemtime.h @@ -41,7 +41,7 @@ class Q_DECL_EXPORT SystemTime : public QObject Q_PROPERTY(bool ntp READ ntp WRITE setNtp NOTIFY ntpChanged) Q_PROPERTY(QDateTime time READ time WRITE setTime NOTIFY timeChanged) public: - explicit SystemTime(QObject *parent = nullptr); + explicit SystemTime(QObject *parent = Q_NULLPTR); bool ntp() const; void setNtp(const bool aNtp); void setTime(const QDateTime& aTime); @@ -54,6 +54,8 @@ Q_SIGNALS: void ntpChanged(); void timeChanged(); +public Q_SLOTS: + protected: SystemTimePrivate *d_ptr; diff --git a/src/timedatesettings/timezonemodel.h b/src/timedatesettings/timezonemodel.h index e8f15bf..485fd17 100644 --- a/src/timedatesettings/timezonemodel.h +++ b/src/timedatesettings/timezonemodel.h @@ -41,7 +41,7 @@ class TimezoneItem : public QObject Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString country READ country CONSTANT) public: - explicit TimezoneItem(const QByteArray& id, QObject *parent = nullptr); + explicit TimezoneItem(const QByteArray& id, QObject *parent = Q_NULLPTR); QString name() const; QString country() const; QString id() const; @@ -57,7 +57,7 @@ class Q_DECL_EXPORT TimezoneModel : public QAbstractListModel Q_OBJECT public: - explicit TimezoneModel(QObject *parent = nullptr); + explicit TimezoneModel(QObject *parent = Q_NULLPTR); virtual ~TimezoneModel(); // from QAbstractItemModel int rowCount(const QModelIndex & parent = QModelIndex()) const; |