diff options
Diffstat (limited to 'src')
225 files changed, 11281 insertions, 2463 deletions
diff --git a/src/bluetoothsettings/bluetoothdevice.cpp b/src/bluetoothsettings/bluetoothdevice.cpp new file mode 100644 index 0000000..65a7422 --- /dev/null +++ b/src/bluetoothsettings/bluetoothdevice.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <discoverymodel.h> +#include "bluetoothdevice.h" +#include "bluez/bluetoothdevice_p.h" + +BluetoothDevice::BluetoothDevice(QObject *parent) : QObject(parent) + ,m_localDevice(new QBluetoothLocalDevice(this)) + ,m_deviceModel(new DiscoveryModel(this)) + ,m_powered(false) + ,m_scanning(true) +{ + m_powered = m_localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff; + + connect(m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &BluetoothDevice::deviceStateChanged); + connect(m_localDevice, &QBluetoothLocalDevice::deviceConnected, this, &BluetoothDevice::deviceConnected); + connect(m_localDevice, &QBluetoothLocalDevice::deviceDisconnected, this, &BluetoothDevice::deviceDisconnected); + connect(m_deviceModel, &DiscoveryModel::scanFinished, this, &BluetoothDevice::scanFinished); + + if (m_powered) { + m_deviceModel->scanDevices(); + } + +} + +void BluetoothDevice::deviceStateChanged(QBluetoothLocalDevice::HostMode state) +{ + m_powered = state != QBluetoothLocalDevice::HostPoweredOff; + emit poweredChanged(); +} + +bool BluetoothDevice::powered() const +{ + return m_powered; +} + +void BluetoothDevice::setPowered(const bool& aPowered) +{ + if (aPowered) { + m_localDevice->powerOn(); + } + else { + m_localDevice->setHostMode(QBluetoothLocalDevice::HostPoweredOff); + } +} + +QObject* BluetoothDevice::deviceModel() const +{ + return static_cast<QObject*>(m_deviceModel); +} + +void BluetoothDevice::scanFinished() +{ + m_scanning = false; + emit scanningChanged(); + updateConnectionStatuses(); +} + +bool BluetoothDevice::scanning() const +{ + return m_scanning; +} + +void BluetoothDevice::setScanning(const bool& aScan) +{ + if (m_scanning && !aScan) { + //TODO m_deviceModel->cancel(); + } + else if (aScan && !m_scanning) { + m_deviceModel->scanDevices(); + m_scanning = true; + emit scanningChanged(); + } +} + +void BluetoothDevice::updateConnectionStatuses() +{ + QList<QBluetoothAddress> connectedDevices = + m_localDevice->connectedDevices(); + + foreach (QBluetoothAddress addr, connectedDevices) { + m_deviceModel->setConnected(addr.toString(), true); + } +} + +void BluetoothDevice::requestPairing(const QString& address) +{ + QBluetoothAddress addr(address); + m_localDevice->requestPairing(addr, QBluetoothLocalDevice::Paired); + connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayConfirmation, this, &BluetoothDevice::pairingDisplayConfirmation); + + connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, this, &BluetoothDevice::pairingDisplayPinCode); + + connect(m_localDevice, &QBluetoothLocalDevice::pairingFinished, this, &BluetoothDevice::pairingFinished); +} + +void BluetoothDevice::requestConnect(const QString &address) +{ + QScopedPointer<BluetoothDevicePrivate> connectionHandler(new BluetoothDevicePrivate(address)); + connectionHandler->connectDevice(); +} + +void BluetoothDevice::requestDisconnect(const QString& address) +{ + QScopedPointer<BluetoothDevicePrivate> connectionHandler(new BluetoothDevicePrivate(address)); + connectionHandler->disconnectDevice(); +} + +void BluetoothDevice::pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin) +{ + Q_UNUSED(address); + Q_UNUSED(pin); +} + +void BluetoothDevice::pairingDisplayPinCode(const QBluetoothAddress & address, QString pin) +{ + Q_UNUSED(address); + Q_UNUSED(pin); +} + +void BluetoothDevice::pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing) +{ + if (pairing == QBluetoothLocalDevice::Paired) { + requestConnect(address.toString()); + } +} + +void BluetoothDevice::deviceConnected(const QBluetoothAddress & address) +{ + m_deviceModel->setConnected(address.toString(), true); +} + +void BluetoothDevice::deviceDisconnected(const QBluetoothAddress & address) +{ + m_deviceModel->setConnected(address.toString(), false); +} diff --git a/src/bluetoothsettings/bluetoothdevice.h b/src/bluetoothsettings/bluetoothdevice.h new file mode 100644 index 0000000..30bd3a4 --- /dev/null +++ b/src/bluetoothsettings/bluetoothdevice.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BLUETOOTHDEVICE_H +#define BLUETOOTHDEVICE_H + +#include <QObject> +#include <QBluetoothLocalDevice> + +class DiscoveryModel; + +class Q_DECL_EXPORT BluetoothDevice : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool scanning READ scanning WRITE setScanning NOTIFY scanningChanged) + Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) + Q_PROPERTY(QObject* deviceModel READ deviceModel CONSTANT) +public: + explicit BluetoothDevice(QObject *parent = 0); + bool powered() const; + void setPowered(const bool& aPowered); + QObject* deviceModel() const; + bool scanning() const; + void setScanning(const bool& aScan); + Q_INVOKABLE void requestPairing(const QString& address); + Q_INVOKABLE void requestConnect(const QString& address); + Q_INVOKABLE void requestDisconnect(const QString& address); +signals: + void poweredChanged(); + void scanningChanged(); + +public slots: + void deviceStateChanged(QBluetoothLocalDevice::HostMode state); + void scanFinished(); + //These are not yet signaled + //See bug https://bugreports.qt.io/browse/QTBUG-38401 + void pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin); + void pairingDisplayPinCode(const QBluetoothAddress & address, QString pin); + void pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing); + void deviceConnected(const QBluetoothAddress & address); + void deviceDisconnected(const QBluetoothAddress & address); + +private: + void updateConnectionStatuses(); + +private: + QBluetoothLocalDevice* m_localDevice; + DiscoveryModel *m_deviceModel; + bool m_powered; + bool m_scanning; +}; + +#endif // BLUETOOTHDEVICE_H diff --git a/src/bluetoothsettings/bluetoothsettings.pro b/src/bluetoothsettings/bluetoothsettings.pro new file mode 100644 index 0000000..cb98ccb --- /dev/null +++ b/src/bluetoothsettings/bluetoothsettings.pro @@ -0,0 +1,19 @@ +load(qt_build_config) + +TARGET = QtBluetoothSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT += core bluetooth + +MODULE = bluetoothsettings +load(qt_module) + +include(bluez/bluez.pri) + +HEADERS += \ + bluetoothdevice.h \ + discoverymodel.h + +SOURCES += bluetoothdevice.cpp \ + discoverymodel.cpp diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp new file mode 100644 index 0000000..5badc74 --- /dev/null +++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "bluetoothdevice_p.h" +#include "datatypes.h" +#include "objectmanager_interface.cpp" +#include "moc_objectmanager_interface.cpp" +#include "device1_interface.h" + + +BluetoothDevicePrivate::BluetoothDevicePrivate(const QString& address, QObject *parent) + :QObject(parent) + ,m_address(address) +{ + +} + +OrgBluezDevice1Interface* BluetoothDevicePrivate::findDevice() +{ + OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"), + QStringLiteral("/"), + QDBusConnection::systemBus()); + QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects(); + reply.waitForFinished(); + if (reply.isError()) { + qWarning() << "Failed to get objects"; + return NULL; + } + + ManagedObjectList managedObjectList = reply.value(); + for (ManagedObjectList::const_iterator it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) { + const QDBusObjectPath &path = it.key(); + + const InterfaceList &ifaceList = it.value(); + for (InterfaceList::const_iterator jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) { + const QString &iface = jt.key(); + const QVariantMap &ifaceValues = jt.value(); + if (iface == QStringLiteral("org.bluez.Device1")) { + if (ifaceValues[QStringLiteral("Address")] == m_address) { + OrgBluezDevice1Interface *devIf = new OrgBluezDevice1Interface(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus()); + return devIf; + } + } + } + } + return NULL; +} + +void BluetoothDevicePrivate::connectDevice() +{ + OrgBluezDevice1Interface *dev = findDevice(); + if (dev) { + dev->Connect(); + dev->deleteLater(); + } +} + +void BluetoothDevicePrivate::disconnectDevice() +{ + OrgBluezDevice1Interface *dev = findDevice(); + if (dev) { + dev->Disconnect(); + dev->deleteLater(); + } +} diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.h b/src/bluetoothsettings/bluez/bluetoothdevice_p.h new file mode 100644 index 0000000..1c28161 --- /dev/null +++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utils module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BLUETOOTHDEVICE__P_H +#define BLUETOOTHDEVICE__P_H + +#include <QObject> + +class OrgBluezDevice1Interface; + +class BluetoothDevicePrivate : public QObject +{ +public: + explicit BluetoothDevicePrivate(const QString& address, QObject *parent=0); + void connectDevice(); + void disconnectDevice(); + +private: + OrgBluezDevice1Interface* findDevice(); + QString m_address; +}; + +#endif // BLUETOOTHDEVICE__P_H diff --git a/src/bluetoothsettings/bluez/bluez.pri b/src/bluetoothsettings/bluez/bluez.pri new file mode 100644 index 0000000..ea4929c --- /dev/null +++ b/src/bluetoothsettings/bluez/bluez.pri @@ -0,0 +1,15 @@ +QT += core dbus + +INCLUDEPATH += $${PWD} +INCLUDEPATH += $${PWD}/bluez + +DBUS_INTERFACES = \ + $${PWD}/objectmanager.xml \ + $${PWD}/device1.xml \ + +HEADERS += \ + $$PWD/bluetoothdevice_p.h \ + $$PWD/datatypes.h + +SOURCES += \ + $$PWD/bluetoothdevice_p.cpp diff --git a/src/bluetoothsettings/bluez/datatypes.h b/src/bluetoothsettings/bluez/datatypes.h new file mode 100644 index 0000000..b794c47 --- /dev/null +++ b/src/bluetoothsettings/bluez/datatypes.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utils module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DATATYPES_H +#define DATATYPES_H + +#include <QObject> +#include <QtDBus> +#include <QMap> +#include <QVariantMap> +#include <QtDBus/QDBusObjectPath> +#include <QtCore/QMetaType> + +typedef QMap<QString, QVariantMap> InterfaceList; +typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList; + +Q_DECLARE_METATYPE(InterfaceList) +Q_DECLARE_METATYPE(ManagedObjectList) + + +#endif // DATATYPES_H diff --git a/src/bluetoothsettings/bluez/device1.xml b/src/bluetoothsettings/bluez/device1.xml new file mode 100644 index 0000000..5b16992 --- /dev/null +++ b/src/bluetoothsettings/bluez/device1.xml @@ -0,0 +1,31 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="org.bluez.Device1"> + <method name="Disconnect"></method> + <method name="Connect"></method> + <method name="ConnectProfile"> + <arg name="UUID" type="s" direction="in"/> + </method> + <method name="DisconnectProfile"> + <arg name="UUID" type="s" direction="in"/> + </method> + <method name="Pair"></method> + <method name="CancelPairing"></method> + <property name="Address" type="s" access="read"></property> + <property name="Name" type="s" access="read"></property> + <property name="Alias" type="s" access="readwrite"></property> + <property name="Appearance" type="q" access="read"></property> + <property name="Icon" type="s" access="read"></property> + <property name="Paired" type="b" access="read"></property> + <property name="Trusted" type="b" access="readwrite"></property> + <property name="Blocked" type="b" access="readwrite"></property> + <property name="LegacyPairing" type="b" access="read"></property> + <property name="RSSI" type="n" access="read"></property> + <property name="Connected" type="b" access="read"></property> + <property name="UUIDs" type="as" access="read"></property> + <property name="Modalias" type="s" access="read"></property> + <property name="Adapter" type="o" access="read"></property> + </interface> +</node> + diff --git a/src/bluetoothsettings/bluez/objectmanager.xml b/src/bluetoothsettings/bluez/objectmanager.xml new file mode 100644 index 0000000..e52d6fe --- /dev/null +++ b/src/bluetoothsettings/bluez/objectmanager.xml @@ -0,0 +1,20 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="org.freedesktop.DBus.ObjectManager"> + <method name="GetManagedObjects"> + <arg type="a{oa{sa{sv}}}" name="object_paths_interfaces_and_properties" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ManagedObjectList"/> + </method> + <signal name="InterfacesAdded"> + <arg type="o" name="object_path"/> + <arg type="a{sa{sv}}" name="interfaces_and_properties"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InterfaceList"/> + </signal> + <signal name="InterfacesRemoved"> + <arg type="o" name="object_path"/> + <arg type="as" name="interfaces"/> + </signal> + </interface> +</node> + diff --git a/src/bluetoothsettings/discoverymodel.cpp b/src/bluetoothsettings/discoverymodel.cpp new file mode 100644 index 0000000..1a9410b --- /dev/null +++ b/src/bluetoothsettings/discoverymodel.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QBluetoothAddress> +#include "discoverymodel.h" + +BtDeviceItem::BtDeviceItem(const QBluetoothDeviceInfo& bt, QObject *parent) + : QObject(parent) + ,m_name(bt.name()) + ,m_address(bt.address().toString()) + ,m_connected(false) +{ + m_type = getDeviceType(bt.majorDeviceClass(), bt.minorDeviceClass()); +} + +QString BtDeviceItem::name() const +{ + return m_name; +} + +QString BtDeviceItem::address() const +{ + return m_address; +} + +bool BtDeviceItem::connected() const +{ + return m_connected; +} + +void BtDeviceItem::setConnected(bool aConnected) +{ + m_connected = aConnected; + emit connectedChanged(); +} + +BtDeviceItem::DeviceType BtDeviceItem::type() const +{ + return m_type; +} + +BtDeviceItem::DeviceType BtDeviceItem::getDeviceType(const QBluetoothDeviceInfo::MajorDeviceClass major, const quint8 minor) const +{ + switch (major) { + case QBluetoothDeviceInfo::ComputerDevice: + return getComputerDeviceType(minor); + break; + case QBluetoothDeviceInfo::PhoneDevice: + return getPhoneDeviceType(minor); + break; + case QBluetoothDeviceInfo::AudioVideoDevice: + return getAudioDeviceType(minor); + break; + case QBluetoothDeviceInfo::PeripheralDevice: + return getPeripheralDeviceType(minor); + break; + case QBluetoothDeviceInfo::ImagingDevice: + return getImagingDeviceType(minor); + break; + default: + return GenericDevice; + } + return GenericDevice; +} + +BtDeviceItem::DeviceType BtDeviceItem::getComputerDeviceType(const quint8 minor) const +{ + Q_UNUSED(minor); + return Computer; +} + +BtDeviceItem::DeviceType BtDeviceItem::getAudioDeviceType(const quint8 minor) const +{ + switch (minor) { + case QBluetoothDeviceInfo::Microphone: + return Microphone; + break; + case QBluetoothDeviceInfo::WearableHeadsetDevice: + case QBluetoothDeviceInfo::Headphones: + return Headphones; + break; + case QBluetoothDeviceInfo::Camcorder: + case QBluetoothDeviceInfo::VideoCamera: + return Camcorder; + break; + default: + return GenericDevice; + break; + } +} + +BtDeviceItem::DeviceType BtDeviceItem::getPeripheralDeviceType(const quint8 minor) const +{ + switch (minor) { + case QBluetoothDeviceInfo::KeyboardPeripheral: + return Keyboard; + break; + case QBluetoothDeviceInfo::PointingDevicePeripheral: + return Mouse; + break; + default: + return GenericDevice; + break; + } +} + +BtDeviceItem::DeviceType BtDeviceItem::getImagingDeviceType(const quint8 minor) const +{ + switch (minor) { + case QBluetoothDeviceInfo::ImageCamera: + return Camera; + break; + default: + return GenericDevice; + break; + } +} + +BtDeviceItem::DeviceType BtDeviceItem::getPhoneDeviceType(const quint8 minor) const +{ + Q_UNUSED(minor); + return Phone; +} + + +DiscoveryModel::DiscoveryModel(QObject *parent) + : QAbstractListModel(parent) + ,m_discoveryAgent(new QBluetoothDeviceDiscoveryAgent(this)) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Address, "address"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(Type, "type"); + m_roleNames.insert(Connected, "connected"); + + connect(m_discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), + this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); + + connect(m_discoveryAgent, SIGNAL(finished()), + this, SIGNAL(scanFinished())); + +} + +void DiscoveryModel::deviceDiscovered(const QBluetoothDeviceInfo &device) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + BtDeviceItem *item = new BtDeviceItem(device); + m_items.append(item); + endInsertRows(); +} + +DiscoveryModel::~DiscoveryModel() +{ + +} + +void DiscoveryModel::scanDevices() +{ + m_discoveryAgent->start(); +} + +QHash<int, QByteArray> DiscoveryModel::roleNames() const +{ + return m_roleNames; +} + +int DiscoveryModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant DiscoveryModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + BtDeviceItem *item = m_items[index.row()]; + + switch (role) { + case DiscoveryModel::Name: + return item->name(); + break; + case DiscoveryModel::Address: + return item->address(); + break; + case DiscoveryModel::Type: + return item->type(); + break; + case DiscoveryModel::Connected: + return item->connected(); + default: + return QVariant(); + } +} + +void DiscoveryModel::setConnected(const QString &aAddress, bool connected) +{ + bool found = false; + int i = 0; + QVector<int> role; + role.append(DiscoveryModel::Connected); + foreach (BtDeviceItem *item, m_items) { + if (item->address() == aAddress) { + item->setConnected(connected); + found = true; + break; + } + i++; + } + + if (found) + emit dataChanged(index(i, 0), index(i, 0), role); +} diff --git a/src/bluetoothsettings/discoverymodel.h b/src/bluetoothsettings/discoverymodel.h new file mode 100644 index 0000000..e939450 --- /dev/null +++ b/src/bluetoothsettings/discoverymodel.h @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DISCOVERYMODEL_H +#define DISCOVERYMODEL_H + + +#include <QObject> +#include <QAbstractListModel> +#include <QBluetoothDeviceInfo> +#include <QBluetoothDeviceDiscoveryAgent> + +class Q_DECL_EXPORT BtDeviceItem : public QObject +{ + Q_OBJECT + Q_ENUMS(DeviceType) + Q_PROPERTY(QString address READ address CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) + Q_PROPERTY(DeviceType type READ type CONSTANT) +public: + explicit BtDeviceItem(const QBluetoothDeviceInfo& id, QObject *parent=0); + //The list of device type we want to show the icon + enum DeviceType { + Phone, + Computer, + Mouse, + Keyboard, + Headphones, + Microphone, + Camera, + Camcorder, + Clock, + HealthDevice, + GenericDevice=1000 + }; + QString name() const; + QString address() const; + DeviceType type() const; + bool connected() const; + void setConnected(bool aConnected); + +signals: + void connectedChanged(); + +protected: + DeviceType getDeviceType(const QBluetoothDeviceInfo::MajorDeviceClass major, + const quint8 minor) const; + DeviceType getComputerDeviceType(const quint8 minor) const; + DeviceType getAudioDeviceType(const quint8 minor) const; + DeviceType getPeripheralDeviceType(const quint8 minor) const; + DeviceType getImagingDeviceType(const quint8 minor) const; + DeviceType getHealthDeviceType(const quint8 minor) const; + DeviceType getPhoneDeviceType(const quint8 minor) const; + +private: + QString m_name; + QString m_address; + bool m_connected; + DeviceType m_type; +}; + +class Q_DECL_EXPORT DiscoveryModel : public QAbstractListModel +{ + Q_OBJECT + Q_ENUMS(DeviceType) +public: + explicit DiscoveryModel(QObject *parent=0); + virtual ~DiscoveryModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + void setConnected(const QString& aAddress, bool connected); + void scanDevices(); + + enum Roles { + Name = Qt::UserRole, + Address, + Type, + Connected + }; + +signals: + void scanFinished(); + +private slots: + void deviceDiscovered(const QBluetoothDeviceInfo &device); +private: + QList<BtDeviceItem*> m_items; + QHash<int, QByteArray> m_roleNames; + QBluetoothDeviceDiscoveryAgent *m_discoveryAgent; +}; +#endif // DISCOVERYMODEL_H diff --git a/src/displaysettings/displaysettings.cpp b/src/displaysettings/displaysettings.cpp new file mode 100644 index 0000000..8066993 --- /dev/null +++ b/src/displaysettings/displaysettings.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "displaysettings.h" +#include "displaysettings_p.h" + +DisplaySettings::DisplaySettings(QObject *parent) + : QObject(parent) + ,d_ptr(new DisplaySettingsPrivate(this)) +{ +} + +DisplaySettings::~DisplaySettings() +{ +} + + +/*! + * Sets the display brightness (i.e. the intensity of the backlight) + * to \a value. A value of 255 requests maximum brightness, while 0 requests + * minimum (typically, the backlight turned off). + * + * Returns true on success. + */ +bool DisplaySettings::setDisplayBrightness(int v) +{ + Q_D(DisplaySettings); + return d->setDisplayBrightness(v); +} + + +/*! + * Returns the current backlight intensity. + * \sa setDisplayBrightness + */ +int DisplaySettings::displayBrightness() +{ + Q_D(DisplaySettings); + return d->displayBrightness(); +} + + +int DisplaySettings::physicalScreenSizeInch() const +{ + Q_D(const DisplaySettings); + return d->physicalScreenSizeInch(); +} + +void DisplaySettings::setPhysicalScreenSizeInch(int inches) +{ + Q_D(DisplaySettings); + d->setPhysicalScreenSizeInch(inches); +} + +bool DisplaySettings::physicalScreenSizeOverride() const +{ + Q_D(const DisplaySettings); + return d->physicalScreenSizeOverride(); +} + +void DisplaySettings::setPhysicalScreenSizeOverride(bool enable) +{ + Q_D(DisplaySettings); + d->setPhysicalScreenSizeOverride(enable); +} diff --git a/src/displaysettings/displaysettings.h b/src/displaysettings/displaysettings.h new file mode 100644 index 0000000..fc8fe74 --- /dev/null +++ b/src/displaysettings/displaysettings.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DISPLAYSETTINGS_H +#define DISPLAYSETTINGS_H + +#include <qobject.h> + +class DisplaySettingsPrivate; + +class Q_DECL_EXPORT DisplaySettings : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int displayBrightness READ displayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged) + Q_PROPERTY(int physicalScreenSizeInch READ physicalScreenSizeInch WRITE setPhysicalScreenSizeInch NOTIFY physicalScreenSizeInchChanged) + Q_PROPERTY(bool physicalScreenSizeOverride READ physicalScreenSizeOverride WRITE setPhysicalScreenSizeOverride NOTIFY physicalScreenSizeOverrideChanged) + +public: + DisplaySettings(QObject *parent = 0); + ~DisplaySettings(); + + int displayBrightness(); + int physicalScreenSizeInch() const; + bool physicalScreenSizeOverride() const; + +public Q_SLOTS: + bool setDisplayBrightness(int value); + void setPhysicalScreenSizeInch(int inches); + void setPhysicalScreenSizeOverride(bool enable); + +signals: + void displayBrightnessChanged(int newValue); + void physicalScreenSizeInchChanged(int newInches); + void physicalScreenSizeOverrideChanged(bool newValue); + +protected: + DisplaySettingsPrivate *d_ptr; + + Q_DISABLE_COPY(DisplaySettings) + Q_DECLARE_PRIVATE(DisplaySettings) +}; + +#endif // DISPLAYSETTINGS_H diff --git a/src/displaysettings/displaysettings.pro b/src/displaysettings/displaysettings.pro new file mode 100644 index 0000000..c03168d --- /dev/null +++ b/src/displaysettings/displaysettings.pro @@ -0,0 +1,17 @@ +load(qt_build_config) + +TARGET = QtDisplaySettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core + +MODULE = displaysettings +load(qt_module) + +SOURCES += displaysettings.cpp \ + displaysettings_p.cpp + +HEADERS += displaysettings.h \ + displaysettings_p.h + diff --git a/src/displaysettings/displaysettings_p.cpp b/src/displaysettings/displaysettings_p.cpp new file mode 100644 index 0000000..0aca580 --- /dev/null +++ b/src/displaysettings/displaysettings_p.cpp @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtMath> +#include <QDirIterator> +#include "displaysettings_p.h" + +DisplaySettingsPrivate::DisplaySettingsPrivate(DisplaySettings *qq) + :q_ptr(qq) + ,m_brightness(255) + ,m_lightDevicesInitialized(false) + ,m_physScreenSize(new PhysicalScreenSize(qq)) +{ + +} + +void DisplaySettingsPrivate::initLightDevices() +{ + if (m_lightDevicesInitialized) + return; + QDirIterator it(QStringLiteral("/sys/class/backlight")); + while (it.hasNext()) { + LightDevice ld; + ld.deviceFile = it.next() + QStringLiteral("/brightness"); + QFile maxFile(it.filePath() + QStringLiteral("/max_brightness")); + if (!maxFile.open(QIODevice::ReadOnly)) + continue; + bool ok = false; + ld.maxValue = maxFile.read(10).simplified().toUInt(&ok); + if (!ok || !ld.maxValue) + continue; + QFile valFile(ld.deviceFile); + if (!valFile.open(QIODevice::ReadOnly)) + continue; + ok = false; + uint val = valFile.read(10).simplified().toUInt(&ok); + if (!ok) + continue; + // map max->max as that is a common case, otherwise choose a reasonable value + ld.value = (val == ld.maxValue) ? 255 : (val * 256)/(ld.maxValue+1); + ld.name = it.fileName(); + m_lightDevices.append(ld); + } + if (!m_lightDevices.isEmpty()) + m_brightness = m_lightDevices.at(0).value; + m_lightDevicesInitialized = true; +} + + +bool DisplaySettingsPrivate::setDisplayBrightness(int v) +{ + Q_Q(DisplaySettings); + quint8 value = qBound(0, v, 255); + initLightDevices(); + for (int i = 0; i < m_lightDevices.size(); i++) { + LightDevice &ld = m_lightDevices[i]; + QFile devFile(ld.deviceFile); + if (!devFile.open(QIODevice::WriteOnly)) + continue; + // Maps only 0 to 0, since 0 often means "off"; other values are degrees of "on". + uint newVal = value ? 1 + ((value * ld.maxValue) / 256) : 0; + devFile.write(QByteArray::number(newVal)); + ld.value = value; + } + m_brightness = value; + return true; +} + +int DisplaySettingsPrivate::displayBrightness() +{ + initLightDevices(); + return m_brightness; +} + +int DisplaySettingsPrivate::physicalScreenSizeInch() const +{ + return m_physScreenSize->size(); +} + +void DisplaySettingsPrivate::setPhysicalScreenSizeInch(int inches) +{ + Q_Q(DisplaySettings); + if (m_physScreenSize->size() != inches) { + m_physScreenSize->setSize(inches); + emit q->physicalScreenSizeInchChanged(inches); + } +} + +bool DisplaySettingsPrivate::physicalScreenSizeOverride() const +{ + return m_physScreenSize->enabled(); +} + +void DisplaySettingsPrivate::setPhysicalScreenSizeOverride(bool enable) +{ + Q_Q(DisplaySettings); + if (m_physScreenSize->enabled() != enable) { + m_physScreenSize->setEnabled(enable); + emit q->physicalScreenSizeOverrideChanged(enable); + } +} + +PhysicalScreenSize::PhysicalScreenSize(QObject *parent) + : QObject(parent) + ,physScreenSizeEnabled(false), physScreenSizeInch(7) +{ + physWriteTimer.setSingleShot(true); + physWriteTimer.setInterval(1000); + QObject::connect(&physWriteTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); + + read(QStringLiteral("/etc/appcontroller.conf")); + read(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf")); +} + +PhysicalScreenSize::~PhysicalScreenSize() +{ + +} + +void PhysicalScreenSize::read(const QString &filename) +{ + QFile f(filename); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + int physScreenWidth = 154, physScreenHeight = 90; + int found = 0; + while (!f.atEnd()) { + QByteArray line = f.readLine().trimmed(); + if (line.startsWith(QByteArrayLiteral("env="))) { + QByteArrayList values = line.split('='); + if (values.count() == 3) { + bool ok; + if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_WIDTH")) { + int val = values[2].toInt(&ok); + if (ok) { + ++found; + physScreenWidth = val; + } + } else if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_HEIGHT")) { + int val = values[2].toInt(&ok); + if (ok) { + ++found; + physScreenHeight = val; + } + } + } + } + } + if (found == 2) + physScreenSizeEnabled = true; + + const qreal diagMM = qSqrt(physScreenWidth * physScreenWidth + physScreenHeight * physScreenHeight); + physScreenSizeInch = qRound(diagMM / 25.4); +} + +void PhysicalScreenSize::onTimeout() +{ + write(); +} + +void PhysicalScreenSize::write(bool includePhysSize) +{ + QDir(QStringLiteral("/var/lib")).mkpath(QStringLiteral("b2qt/appcontroller.conf.d")); + write(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf"), includePhysSize); +} + +void PhysicalScreenSize::write(const QString &filename, bool includePhysSize) +{ + QFile f(filename); + + QByteArrayList lines; + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + while (!f.atEnd()) { + QByteArray line = f.readLine().trimmed(); + if (!line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=")) + && !line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_HEIGHT="))) + lines.append(line); + } + f.close(); + } + + if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) + return; + + const qreal diagMM = physScreenSizeInch * 25.4; + // Assume 16:9 aspect ratio + const int physScreenHeight = qRound(diagMM / 1.975); + const int physScreenWidth = qRound(physScreenHeight * 1.777); + + foreach (const QByteArray &line, lines) + f.write(line + QByteArrayLiteral("\n")); + + if (includePhysSize) + f.write(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=") + QByteArray::number(physScreenWidth) + + QByteArrayLiteral("\nenv=QT_QPA_EGLFS_PHYSICAL_HEIGHT=") + QByteArray::number(physScreenHeight) + + QByteArrayLiteral("\n")); +} + +void PhysicalScreenSize::setSize(int inches) +{ + physScreenSizeInch = inches; + physWriteTimer.start(); +} + +bool PhysicalScreenSize::enabled() const +{ + return physScreenSizeEnabled; +} + +void PhysicalScreenSize::setEnabled(bool enable) +{ + physScreenSizeEnabled = enable; + // Rewrite appcontroller.conf with or without the physical width/height lines. + write(enable); +} diff --git a/src/displaysettings/displaysettings_p.h b/src/displaysettings/displaysettings_p.h new file mode 100644 index 0000000..149b9c7 --- /dev/null +++ b/src/displaysettings/displaysettings_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DISPLAYSETTINGSPRIVATE_H +#define DISPLAYSETTINGSPRIVATE_H + +#include <QTimer> +#include "displaysettings.h" + +class PhysicalScreenSize : public QObject +{ + Q_OBJECT + +public: + explicit PhysicalScreenSize(QObject *parent=0); + virtual ~PhysicalScreenSize(); + + void setSize(int inches); + int size() const { return physScreenSizeInch; } + bool enabled() const; + void setEnabled(bool enable); + +private slots: + void onTimeout(); + +private: + void read(const QString &filename); + void write(bool includePhysSize = true); + void write(const QString &filename, bool includePhysSize = true); + + bool physScreenSizeEnabled; + int physScreenSizeInch; + QTimer physWriteTimer; +}; + +class LightDevice +{ +public: + QString name; + QString deviceFile; + quint8 value; + uint maxValue; +}; + +class DisplaySettingsPrivate +{ + Q_DECLARE_PUBLIC(DisplaySettings) +public: + DisplaySettingsPrivate(DisplaySettings* qq); + int displayBrightness(); + int physicalScreenSizeInch() const; + bool physicalScreenSizeOverride() const; + + bool setDisplayBrightness(int value); + void setPhysicalScreenSizeInch(int inches); + void setPhysicalScreenSizeOverride(bool enable); +private: + void initLightDevices(); + DisplaySettings *q_ptr; + int m_brightness; + int m_screenSizeInch; + bool m_sizeOverride; + QList<LightDevice> m_lightDevices; + bool m_lightDevicesInitialized; + PhysicalScreenSize *m_physScreenSize; +}; + +#endif // DISPLAYSETTINGSPRIVATE_H diff --git a/src/imports/bluetoothsettings/bluetoothsettings.pro b/src/imports/bluetoothsettings/bluetoothsettings.pro new file mode 100644 index 0000000..3475ffa --- /dev/null +++ b/src/imports/bluetoothsettings/bluetoothsettings.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml bluetooth bluetoothsettings +uri = com.theqtcompany.settings.bluetooth + +TARGET = btsettingsplugin + +pluginfiles.files += \ + qmldir \ + +SOURCES += plugin.cpp + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/bluetoothsettings/plugin.cpp b/src/imports/bluetoothsettings/plugin.cpp new file mode 100644 index 0000000..20f5b28 --- /dev/null +++ b/src/imports/bluetoothsettings/plugin.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> +#include <QQmlEngine> +#include <QQmlContext> + +#include "bluetoothdevice.h" +#include "discoverymodel.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class BluetoothSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.bluetooth")); + qmlRegisterUncreatableType<BtDeviceItem>(uri, 1, 0, "BtDeviceItem", "Cannot be instantiated directly."); + qmlRegisterSingletonType<BluetoothDevice>(uri, 1, 0, "BtDevice", &instance<BluetoothDevice>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/bluetoothsettings/qmldir b/src/imports/bluetoothsettings/qmldir new file mode 100644 index 0000000..f63b52f --- /dev/null +++ b/src/imports/bluetoothsettings/qmldir @@ -0,0 +1,2 @@ +module com.theqtcompany.settings.bluetooth +plugin btsettingsplugin diff --git a/src/imports/displaysettings/displaysettings.pro b/src/imports/displaysettings/displaysettings.pro new file mode 100644 index 0000000..4c581f4 --- /dev/null +++ b/src/imports/displaysettings/displaysettings.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml displaysettings + +uri = com.theqtcompany.settings.display + +TARGET = qmldisplaysettingsplugin + +SOURCES += plugin.cpp \ + +pluginfiles.files += \ + qmldir \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/displaysettings/plugin.cpp b/src/imports/displaysettings/plugin.cpp new file mode 100644 index 0000000..92c0171 --- /dev/null +++ b/src/imports/displaysettings/plugin.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <QQmlEngine> +#include <qcoreapplication.h> +#include "displaysettings.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class GeneralSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterType(QUrl("qrc:/Display.qml"), uri, 1, 0, "Display"); + qmlRegisterSingletonType<DisplaySettings>(uri, 1, 0, "DisplaySettings", &instance<DisplaySettings>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/displaysettings/qmldir b/src/imports/displaysettings/qmldir new file mode 100644 index 0000000..4f8a3db --- /dev/null +++ b/src/imports/displaysettings/qmldir @@ -0,0 +1,2 @@ +module com.theqtcompany.settings.display +plugin qmldisplaysettingsplugin diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 0b5a551..f34be18 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,2 +1,7 @@ TEMPLATE = subdirs -SUBDIRS += utils wifi +SUBDIRS += networksettings \ + bluetoothsettings \ + localesettings \ + timedatesettings \ + localdevice \ + displaysettings diff --git a/src/imports/localdevice/localdevice.pro b/src/imports/localdevice/localdevice.pro new file mode 100644 index 0000000..dfcbcf9 --- /dev/null +++ b/src/imports/localdevice/localdevice.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +CONFIG += plugin +TARGET = localdeviceplugin +uri = com.theqtcompany.localdevice + +QT += qml localdevice + +pluginfiles.files += \ + qmldir \ + +SOURCES += plugin.cpp + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/localdevice/plugin.cpp b/src/imports/localdevice/plugin.cpp new file mode 100644 index 0000000..b69d9b4 --- /dev/null +++ b/src/imports/localdevice/plugin.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use the contact form at +** http://www.qt.io +** +** This file is part of Qt Enterprise Embedded. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** the contact form at http://www.qt.io +** +****************************************************************************/ +#include <qlocaldevice.h> +#include <QtQml> + +/*! + \qmlmodule com.theqtcompany.localdevice 1.0 + \title Qt Local Device QML Module + \ingroup qtee-qmlmodules + \brief A collection of the local device related utility functions, accessible from QML. +*/ + +/*! + \page b2qt-addon-utils.html + \title Qt Local Device Module + \ingroup qtee-modules + \brief A collection of the local device realted utility functions, accessible from QML. + + Provides utility functions for controlling an embedded + device, such as device shutdown/reboot. + + Import the module as follows: + + \badcode + import com.theqtcompany.localdevice 1.0 + \endcode + + This will give you access to the singleton QML type LocalDevice. + + \note Some functions are currently only implemented for one of + the platforms. + + \section1 QML Types + + \annotatedlist utils-qmltypes +*/ + +/*! + \qmltype LocalDevice + \inqmlmodule com.theqtcompany.localdevice + \ingroup utils-qmltypes + \brief Singleton QML type providing access to utility functions. + + LocalDevice QML type is the interface to various utility + functions. + + There is no need to create an instance of this object. To use it, + simply import the \c {LocalDevice} module: + + \qml + com.theqtcompany.localdevice + + \endqml + + \note Some functions are currently only implemented for one of + the platforms. +*/ + +/*! + \qmlmethod LocalDevice::reboot() + + Reboots the system. Does not return. + + \sa powerOff() +*/ + +/*! + \qmlmethod LocalDevice::powerOff() + + Shuts down the system. Does not return. + + \sa reboot() +*/ + +static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + QLocalDevice *api = new QLocalDevice(); + + return api; +} + +class B2QtUtilsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + B2QtUtilsPlugin() + { + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "com.theqtcompany.localdevice"); + qmlRegisterSingletonType<QLocalDevice>(uri, 1, 0, "LocalDevice", module_api_factory); + } +}; + +#include "plugin.moc" diff --git a/src/imports/utils/plugins.qmltypes b/src/imports/localdevice/plugins.qmltypes index 88acb66..88acb66 100644 --- a/src/imports/utils/plugins.qmltypes +++ b/src/imports/localdevice/plugins.qmltypes diff --git a/src/imports/localdevice/qmldir b/src/imports/localdevice/qmldir new file mode 100644 index 0000000..ae1b1c5 --- /dev/null +++ b/src/imports/localdevice/qmldir @@ -0,0 +1,3 @@ +module com.theqtcompany.localdevice +plugin localdeviceplugin +typeinfo plugins.qmltypes diff --git a/src/imports/localesettings/locale.xml b/src/imports/localesettings/locale.xml new file mode 100644 index 0000000..b722456 --- /dev/null +++ b/src/imports/localesettings/locale.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> +<node> + <interface name="org.freedesktop.locale1"> + <property name="Locale" type="as" access="read"/> + <method name="SetLocale"> + <arg name="locale" type="as" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + </interface> +</node> + diff --git a/src/imports/localesettings/localesettings.pro b/src/imports/localesettings/localesettings.pro new file mode 100644 index 0000000..891e4f8 --- /dev/null +++ b/src/imports/localesettings/localesettings.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml localesettings + +uri = com.theqtcompany.settings.locale + +TARGET = localesettingsplugin + +SOURCES += plugin.cpp + +pluginfiles.files += \ + qmldir \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/localesettings/plugin.cpp b/src/imports/localesettings/plugin.cpp new file mode 100644 index 0000000..1c2bcca --- /dev/null +++ b/src/imports/localesettings/plugin.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> +#include <QQmlEngine> +#include <QQmlContext> + +#include <systemlocale.h> +#include "localefiltermodel.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class LanguageSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterSingletonType<SystemLocale>(uri, 1, 0, "LocaleManager", &instance<SystemLocale>); + qmlRegisterSingletonType<LocaleFilterModel>(uri, 1, 0, "LocaleFilter", &instance<LocaleFilterModel>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/localesettings/qmldir b/src/imports/localesettings/qmldir new file mode 100644 index 0000000..3c59bb0 --- /dev/null +++ b/src/imports/localesettings/qmldir @@ -0,0 +1,2 @@ +module com.theqtcompany.settings.locale +plugin localesettingsplugin diff --git a/src/imports/networksettings/networksettings.pro b/src/imports/networksettings/networksettings.pro new file mode 100644 index 0000000..45228c5 --- /dev/null +++ b/src/imports/networksettings/networksettings.pro @@ -0,0 +1,34 @@ +TEMPLATE = lib +TARGET = networksettingsplugin +QT += qml quick networksettings +CONFIG += qt plugin + +uri = com.theqtcompany.settings.network + +SOURCES += \ + plugin.cpp \ + +HEADERS += \ + plugin.h \ + +DISTFILES = qmldir + +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { + copy_qmldir.target = $$OUT_PWD/qmldir + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + QMAKE_EXTRA_TARGETS += copy_qmldir + PRE_TARGETDEPS += $$copy_qmldir.target +} + +qmldir.files = qmldir + +pluginfiles.files += \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +pluginfiles.path = $$installPath +qmldir.path = $$installPath +target.path = $$installPath +INSTALLS += target qmldir pluginfiles + diff --git a/src/imports/networksettings/plugin.cpp b/src/imports/networksettings/plugin.cpp new file mode 100644 index 0000000..ab81e31 --- /dev/null +++ b/src/imports/networksettings/plugin.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "plugin.h" +#include <qnetworksettings.h> +#include <qnetworksettingsmanager.h> +#include <qnetworksettingsservice.h> +#include <qnetworksettingsuseragent.h> + +#include <qqml.h> +#include <QQmlEngine> +#include <QQmlContext> + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +void NetworksettingspluginPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.network")); + qmlRegisterUncreatableType<QNetworkSettingsService>(uri, 1, 0, "NetworkService", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsIPv4>(uri, 1, 0, "NetworkSettingsIPv4", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsIPv6>(uri, 1, 0, "NetworkSettingsIPv6", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsProxy>(uri, 1, 0, "NetworkSettingsProxy", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsType>(uri, 1, 0, "NetworkSettingsType", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsState>(uri, 1, 0, "NetworkSettingsState", "Cannot be instantiated directly."); + + qmlRegisterSingletonType<QNetworkSettingsManager>(uri, 1, 0, "NetworkSettingsManager", &instance<QNetworkSettingsManager>); + qmlRegisterSingletonType<QNetworkSettingsUserAgent>(uri, 1, 0, "NetworkSettingsUserAgent", &instance<QNetworkSettingsUserAgent>); +} diff --git a/src/imports/networksettings/plugin.h b/src/imports/networksettings/plugin.h new file mode 100644 index 0000000..40e02e2 --- /dev/null +++ b/src/imports/networksettings/plugin.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef NETWORKSETTINGSPLUGIN_PLUGIN_H +#define NETWORKSETTINGSPLUGIN_PLUGIN_H + +#include <QQmlExtensionPlugin> + +class NetworksettingspluginPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri); +}; + +#endif // NETWORKSETTINGSPLUGIN_PLUGIN_H + diff --git a/src/imports/networksettings/qmldir b/src/imports/networksettings/qmldir new file mode 100644 index 0000000..7774745 --- /dev/null +++ b/src/imports/networksettings/qmldir @@ -0,0 +1,3 @@ +module com.theqtcompany.settings.network +plugin networksettingsplugin + diff --git a/src/imports/timedatesettings/plugin.cpp b/src/imports/timedatesettings/plugin.cpp new file mode 100644 index 0000000..0f67699 --- /dev/null +++ b/src/imports/timedatesettings/plugin.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> +#include <QQmlEngine> +#include <QQmlContext> + +#include <systemtime.h> +#include "timezonefiltermodel.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class TimeDateSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterSingletonType<SystemTime>(uri, 1, 0, "TimeManager", &instance<SystemTime>); + qmlRegisterSingletonType<TimezoneFilterModel>(uri, 1, 0, "TimezonesFilter", &instance<TimezoneFilterModel>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/timedatesettings/qmldir b/src/imports/timedatesettings/qmldir new file mode 100644 index 0000000..3fc8fec --- /dev/null +++ b/src/imports/timedatesettings/qmldir @@ -0,0 +1,2 @@ +module com.theqtcompany.settings.timedate +plugin qmltimedatesettingsplugin diff --git a/src/imports/timedatesettings/timedatesettings.pro b/src/imports/timedatesettings/timedatesettings.pro new file mode 100644 index 0000000..ec86d4e --- /dev/null +++ b/src/imports/timedatesettings/timedatesettings.pro @@ -0,0 +1,19 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml timedatesettings + +uri = com.theqtcompany.settings.timedate + +DESTDIR = imports/TimeDate +TARGET = qmltimedatesettingsplugin + +SOURCES += plugin.cpp + +pluginfiles.files += qmldir + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles + diff --git a/src/imports/utils/plugin.cpp b/src/imports/utils/plugin.cpp deleted file mode 100644 index a4f8810..0000000 --- a/src/imports/utils/plugin.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include <b2qtdevice.h> -#include <QtQml> - -/*! - \qmlmodule B2Qt.Utils 1.0 - \title B2Qt Utils QML Module - \ingroup qtee-qmlmodules - \brief A collection of utility functions, accessible from QML. -*/ - -/*! - \page b2qt-addon-utils.html - \title B2Qt Utils Module - \ingroup qtee-modules - \brief A collection of utility functions, accessible from QML. - - Provides various utility functions for controlling an embedded - device, such as display brightness, IP address and hostname, and - device shutdown/reboot. - - Import the module as follows: - - \badcode - import B2Qt.Utils 1.0 - \endcode - - This will give you access to the singleton QML type B2QtDevice. - - \note Some functions are currently only implemented for one of - the platforms. - - \section1 QML Types - - \annotatedlist utils-qmltypes -*/ - -/*! - \qmltype B2QtDevice - \inqmlmodule B2Qt.Utils - \ingroup utils-qmltypes - \brief Singleton QML type providing access to utility functions. - - B2QtDevice QML type is the interface to various utility - functions. - - There is no need to create an instance of this object. To use it, - simply import the \c {B2Qt.Utils} module: - - \qml - import B2Qt.Utils 1.0 - - Text { - text: qsTr("IP Address:") + B2QtDevice.ipAddress - } - \endqml - - \note Some functions are currently only implemented for one of - the platforms. -*/ - -/*! - \qmlmethod B2Qt.Utils::B2QtDevice::reboot() - - Reboots the system. Does not return. - - \sa powerOff() -*/ - -/*! - \qmlmethod B2Qt.Utils::B2QtDevice::powerOff() - - Shuts down the system. Does not return. - - \sa reboot() -*/ - -/*! - \qmlproperty int B2Qt.Utils::B2QtDevice::masterVolume - - This property holds the master volume of the device. - The volume can range from \c 0 to \c 100 and is linear. - Changing the master volume will affect all audio streams. - - \note Currently implemented only for \B2QA. -*/ - -/*! - \qmlproperty int B2Qt.Utils::B2QtDevice::displayBrightness - This property holds the display brightness (the intensity of the backlight). - The value is in the range from \c 0 to \c 255, where 255 is the maximum - brightness, and 0 is the minimum (typically, the backlight is turned off). - - \note Currently implemented only for \B2QA. -*/ - -/*! - \qmlproperty string B2Qt.Utils::B2QtDevice::ipAddress - \readonly - - This property holds the current IP address(es) of the device - for all active network interfaces. If multiple IP addresses are defined, - this property holds a comma-separated list. The localhost (loopback) - IP addresses are omitted. - - \sa hostname -*/ - -/*! - \qmlproperty string B2Qt.Utils::B2QtDevice::hostname - - This property holds the current hostname of the device. - - \sa ipAddress -*/ - -static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - B2QtDevice *api = new B2QtDevice(); - - return api; -} - -class B2QtUtilsPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") - -public: - B2QtUtilsPlugin() - { - } - - void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == "B2Qt.Utils"); - qmlRegisterSingletonType<B2QtDevice>(uri, 1, 0, "B2QtDevice", module_api_factory); - } -}; - -#include "plugin.moc" diff --git a/src/imports/utils/qmldir b/src/imports/utils/qmldir deleted file mode 100644 index e5e0b31..0000000 --- a/src/imports/utils/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -module B2Qt.Utils -plugin b2qtutilsplugin -typeinfo plugins.qmltypes diff --git a/src/imports/utils/utils.pro b/src/imports/utils/utils.pro deleted file mode 100644 index a580643..0000000 --- a/src/imports/utils/utils.pro +++ /dev/null @@ -1,10 +0,0 @@ -CXX_MODULE = qml -TARGET = b2qtutilsplugin -TARGETPATH = B2Qt/Utils -IMPORT_VERSION = 1.0 - -QT += qml b2qtutils - -SOURCES += plugin.cpp - -load(qml_plugin) diff --git a/src/imports/wifi/pluginmain.cpp b/src/imports/wifi/pluginmain.cpp deleted file mode 100644 index b498b66..0000000 --- a/src/imports/wifi/pluginmain.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include <B2QtWifi/QWifiManager> -#include <B2QtWifi/QWifiDevice> -#include <B2QtWifi/QWifiConfiguration> - -#include <QtQml> - -QT_BEGIN_NAMESPACE - -/*! - \qmlmodule B2Qt.Wifi 1.0 - \title B2Qt Wifi QML Module - \ingroup qtee-qmlmodules - \brief A module for managing wireless network connectivity. - -*/ - -/*! - \page b2qt-addon-wifi.html - \title B2Qt Wifi Module - \ingroup qtee-modules - \brief A module for managing wireless network connectivity. - - B2Qt.Wifi provides QML types and C++ classes for: - - \list - \li Wifi backend handling - \li Retrieval of information from Wifi network access points - \li Wifi connection handling - \li System's network interface configuration - \li Other tasks that allow the device to access network - \endlist - - \section1 Writing the Code - - Depending on what fits best with the application, you can choose to use - either C++ or QML for accessing Wifi functionality. If the majority of the - user interface is written in QML, it is recommended that you use the QML - types, which provide a simpler and declarative way to handle Wifi networks. - - \list - \li \l{Getting Started with B2Qt.Wifi in QML} - \li \l{Getting Started with B2Qt.Wifi in C++} - \endlist - - \section1 API Reference - - \section2 QML Types - - \annotatedlist wifi-qmltypes - - \section2 C++ Classes - - \annotatedlist wifi-cppclasses -*/ - -/*! - \module B2Qt.Wifi.Cpp 1.0 - \title B2Qt Wifi C++ Module - \ingroup qtee-cppmodules - \brief A module for managing wireless network connectivity. -*/ - -/*! - \qmltype WifiManager - \inqmlmodule B2Qt.Wifi - \ingroup wifi-qmltypes - \brief Main interface to the Wifi functionality. - - WifiManager is a singleton type that is a central point for handling Wifi functionality - related tasks. You can use WifiManager's API to control the Wifi backend, scan surroundings for - Wifi access points and connect a device to a wireless network. - - When scanning for networks, WifiManager packs the results in a list-based data model which can - be used with Qt's Model/View classes. Information about the Wifi networks is supplied via the model's - interface, accessed with the following roles: - - \list - \li \e ssid - informal (human) name of a Wifi network (string) - \li \e bssid - basic service set identification of a network, used to uniquely identify BSS (string) - \li \e signalStrength - strength of a Wifi signal represented as percentage (0-100) (int) - \li \e supportsWPA - holds whether network access point supports WPA security protocol (bool) - \li \e supportsWPA2 - holds whether network access point supports WPA2 security protocol (bool) - \li \e supportsWEP - holds whether network access point supports WEP security protocol (bool) - \li \e supportsWPS - holds whether network access point supports WPS security protocol (bool) - \endlist - */ - -/*! - \qmlproperty enumeration WifiManager::NetworkState - \readonly - - This property holds the current state of the network connection. - - \list - \li \e WifiManager.Disconnected - Not connected to any network - \li \e WifiManager.Authenticating - Verifying password with the network provider - \li \e WifiManager.HandshakeFailed - Incorrect password provided - \li \e WifiManager.ObtainingIPAddress - Requesting IP address from DHCP server - \li \e WifiManager.DhcpRequestFailed - Could not retrieve IP address - \li \e WifiManager.Connected - Ready to process network requests - \endlist -*/ - -/*! - \qmlproperty enumeration WifiManager::BackendState - \readonly - - This property holds the current state of the Wifi backend. - - \list - \li \e WifiManager.Initializing - Wireless supplicant is starting up - \li \e WifiManager.Running - Supplicant is initialized and ready to process commands - \li \e WifiManager.Terminating - Shutting down wireless supplicant - \li \e WifiManager.NotRunning - Wireless supplicant process is not running - \endlist -*/ - -/*! - \qmlsignal WifiManager::networkStateChanged(NetworkState networkState) - - This signal is emitted whenever changes in a network state occur. The network name for - which the NetworkState change events are send can be obtained from currentSSID. - - \sa NetworkState, currentSSID -*/ - -/*! - \qmlsignal WifiManager::backendStateChanged(BackendState backendState) - - This signal is emitted whenever changes in a backend state occur. - - \sa start, stop -*/ - -/*! - \qmlsignal WifiManager::currentSSIDChanged(string currentSSID) - - This signal is emitted when switching between different Wifi networks. - - \sa start, stop -*/ - -/*! - \qmlsignal WifiManager::scanningChanged(bool scanning) - - This signal is emitted when device starts or stops to scan for available Wifi networks. - - \sa scanning -*/ - -/*! - \qmlsignal WifiManager::lastErrorChanged(string error) - - This signal is emitted if some internal process has failed, \a error contains - a message on what has failed. - - \sa connect -*/ - -/*! - \qmlproperty model WifiManager::networks - \readonly - - This property holds a list-based data model of networks that can be sensed by a device. - Model can be used with Qt's Model/View classes like ListView. Data in the model is updated - every 5 seconds if scanning is enabled. - - \sa scanning -*/ - -/*! - \qmlproperty string WifiManager::currentSSID - \readonly - - This property holds a network name of last selected network, the network for - which the NetworkState change events are sent. Property can contain an empty - string when no active network connection exists. -*/ - -/*! - \qmlmethod WifiManager::start() - - Start the Wifi backend. This function returns immediately, the BackendState - change events are delivered asynchronously. - - \sa stop, BackendState -*/ - -/*! - \qmlmethod WifiManager::stop() - - Stop the Wifi backend and if connected to any network shut down the network connection. - This function returns immediately, the BackendState change events are delivered asynchronously. - - \sa start, BackendState -*/ - -/*! - \qmlproperty bool WifiManager::scanning - - This property holds whether or not the backend is scanning for Wifi networks. To - preserve battery energy, set this property to false when scanning is not required. - When enabled, new readings are taken every 5 seconds. - - For scanning to work, first you need to initialize the Wifi backend. - - \sa start -*/ - -/*! - \qmlproperty string WifiManager::lastError - \readonly - - This property holds an error message if some internal process has failed. - - \sa connect -*/ - -/*! - \qmlmethod bool WifiManager::connect(WifiConfiguration config) - - Connect a device to a network using the \a config network configuration. - This method returns \a true if the network with provoded configuration could be - successfully added by the backend or \a false on failure, to obtain an error message - read lastError property. - - \sa disconnect, NetworkState, lastError -*/ - -/*! - \qmlmethod WifiManager::disconnect() - - Disconnect from currently connected network connection. - - \sa connect, NetworkState -*/ - -/*! - \qmltype WifiDevice - \inqmlmodule B2Qt.Wifi - \ingroup wifi-qmltypes - \brief Represents a physical device. - - Use this element to query if a device is Wifi capable, before attempting - to use the functionality of WifiManager. - - \qml - import B2Qt.Wifi 1.0 - - GroupBox { - id: wifiOptions - title: "Wifi" - visible: false - - Component.onCompleted: { - if (WifiDevice.wifiSupported()) { - var component = Qt.createComponent("WifiGroupBoxContent.qml") - var wifi = component.createObject(wifiOptions.contentItem) - if (wifi) - wifiOptions.visible = true - } else { - print("Wifi functionality not available on this device.") - } - } - } - \endqml -*/ - -/*! - \qmlmethod bool WifiDevice::wifiSupported() - - Returns \a true if a device is Wifi capable - Wifi driver and firmware has been - successfully loaded by the system, otherwise returns \a false. -*/ - -/*! - \qmltype WifiConfiguration - \inqmlmodule B2Qt.Wifi - \ingroup wifi-qmltypes - \brief Used to define a network configuration. - - WifiConfiguration object represents a single network configuration. Use this object - to configure a properties of your network, for example what passphrase and security - protocol to use. WifiManager's connect() function takes this object and connects a - device to a network that matches the provided configuration. -*/ - -/*! - \qmlproperty string WifiConfiguration::ssid - - This property holds informal (human) name of a Wifi network. -*/ - -/*! - \qmlproperty string WifiConfiguration::passphrase - - This property holds the passphrase to use for authenticating with a network. -*/ - -/*! - \qmlproperty string WifiConfiguration::protocol - - This property holds the security protocols to use for Wifi connection. - WPA is used by default if property is not set, supported values are: WPA, WPA2, WEP, WPS. -*/ - -/*! - \qmlproperty bool WifiConfiguration::ssidHidden - - If a Wifi access point does not broadcast its SSID, setting this property - to \c true ensures that the Wifi backend can detect the specified network. - - By default this property is set to \c false. -*/ - -static QObject *globalWifiDevice(QQmlEngine *, QJSEngine *) -{ - return new QWifiDevice; -} - -static QObject *globalWifiManager(QQmlEngine *, QJSEngine *) -{ - return QWifiManager::instance(); -} - -class QWifiPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") - -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("B2Qt.Wifi")); - - qmlRegisterType<QAbstractListModel>(); - qmlRegisterSingletonType<QWifiManager>(uri, 1, 0, "WifiManager", globalWifiManager); - qmlRegisterSingletonType<QWifiDevice>(uri, 1, 0, "WifiDevice", globalWifiDevice); - qmlRegisterType<QWifiConfiguration>(uri, 1, 0, "WifiConfiguration"); - } -}; - -QT_END_NAMESPACE - -#include "pluginmain.moc" diff --git a/src/imports/wifi/plugins.qmltypes b/src/imports/wifi/plugins.qmltypes deleted file mode 100644 index c59d12c..0000000 --- a/src/imports/wifi/plugins.qmltypes +++ /dev/null @@ -1,90 +0,0 @@ -import QtQuick.tooling 1.1
-
-// This file describes the plugin-supplied types contained in the library.
-// It is used for QML tooling purposes only.
-//
-// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable B2Qt.Wifi 1.0 /system/qml/B2Qt/Wifi/'
-
-Module {
- Component {
- name: "QWifiConfiguration"
- prototype: "QObject"
- exports: ["B2Qt.Wifi/WifiConfiguration 1.0"]
- exportMetaObjectRevisions: [0]
- Property { name: "ssid"; type: "string" }
- Property { name: "passphrase"; type: "string" }
- Property { name: "protocol"; type: "string" }
- }
- Component {
- name: "QWifiDevice"
- prototype: "QObject"
- exports: ["B2Qt.Wifi/WifiDevice 1.0"]
- isCreatable: false
- isSingleton: true
- exportMetaObjectRevisions: [0]
- Method { name: "wifiSupported"; type: "bool" }
- }
- Component {
- name: "QWifiManager"
- prototype: "QObject"
- exports: ["B2Qt.Wifi/WifiManager 1.0"]
- isCreatable: false
- isSingleton: true
- exportMetaObjectRevisions: [0]
- Enum {
- name: "NetworkState"
- values: {
- "Disconnected": 0,
- "Authenticating": 1,
- "HandshakeFailed": 2,
- "ObtainingIPAddress": 3,
- "DhcpRequestFailed": 4,
- "Connected": 5
- }
- }
- Enum {
- name: "BackendState"
- values: {
- "Initializing": 0,
- "Running": 1,
- "Terminating": 2,
- "NotRunning": 3
- }
- }
- Property { name: "networkState"; type: "NetworkState"; isReadonly: true }
- Property { name: "backendState"; type: "BackendState"; isReadonly: true }
- Property { name: "scanning"; type: "bool" }
- Property { name: "currentSSID"; type: "string"; isReadonly: true }
- Property { name: "lastError"; type: "string"; isReadonly: true }
- Property { name: "networks"; type: "QAbstractListModel"; isReadonly: true; isPointer: true }
- Signal {
- name: "scanningChanged"
- Parameter { name: "scanning"; type: "bool" }
- }
- Signal {
- name: "networkStateChanged"
- Parameter { name: "networkState"; type: "NetworkState" }
- }
- Signal {
- name: "backendStateChanged"
- Parameter { name: "backendState"; type: "BackendState" }
- }
- Signal {
- name: "currentSSIDChanged"
- Parameter { name: "currentSSID"; type: "string" }
- }
- Signal {
- name: "lastErrorChanged"
- Parameter { name: "error"; type: "string" }
- }
- Method { name: "start" }
- Method { name: "stop" }
- Method {
- name: "connect"
- type: "bool"
- Parameter { name: "config"; type: "QWifiConfiguration"; isPointer: true }
- }
- Method { name: "disconnect" }
- }
-}
diff --git a/src/imports/wifi/qmldir b/src/imports/wifi/qmldir deleted file mode 100644 index 7e99b56..0000000 --- a/src/imports/wifi/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -module B2Qt.Wifi -plugin b2qtwifiplugin -typeinfo plugins.qmltypes diff --git a/src/imports/wifi/wifi.pro b/src/imports/wifi/wifi.pro deleted file mode 100644 index b130587..0000000 --- a/src/imports/wifi/wifi.pro +++ /dev/null @@ -1,12 +0,0 @@ -CXX_MODULE = qml -TARGET = b2qtwifiplugin -TARGETPATH = B2Qt/Wifi -IMPORT_VERSION = 1.0 - -QT += qml b2qtwifi - -SOURCES += pluginmain.cpp - -OTHER_FILES += qmldir - -load(qml_plugin) diff --git a/src/localdevice/localdevice.pro b/src/localdevice/localdevice.pro new file mode 100644 index 0000000..e6e5bc9 --- /dev/null +++ b/src/localdevice/localdevice.pro @@ -0,0 +1,16 @@ +load(qt_build_config) + +TARGET = QtLocalDevice +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core + +MODULE = localdevice +load(qt_module) + +HEADERS += \ + $$PWD/qlocaldevice.h + +SOURCES += \ + $$PWD/qlocaldevice.cpp diff --git a/src/localdevice/qlocaldevice.cpp b/src/localdevice/qlocaldevice.cpp new file mode 100644 index 0000000..86893fd --- /dev/null +++ b/src/localdevice/qlocaldevice.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use the contact form at +** http://www.qt.io +** +** This file is part of Qt Enterprise Embedded. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** the contact form at http://www.qt.io +** +****************************************************************************/ +#include "qlocaldevice.h" +#include <unistd.h> +#include <sys/reboot.h> + + +QLocalDevice::QLocalDevice(QObject *parent) + : QObject(parent) +{ +} + +QLocalDevice::~QLocalDevice() +{ +} + +/*! + * Reboots the system. Does not return. + * + * \sa powerOff() + */ +void QLocalDevice::reboot() +{ + sync(); + ::reboot(RB_AUTOBOOT); + qWarning("reboot returned"); +} + + +/*! + * Shuts down the system. Does not return. + * + * \sa reboot() + */ +void QLocalDevice::powerOff() +{ + sync(); + ::reboot(RB_POWER_OFF); + qWarning("powerOff returned"); +} + diff --git a/src/wifi/qwifinetwork.cpp b/src/localdevice/qlocaldevice.h index eb2b669..cf289c8 100644 --- a/src/wifi/qwifinetwork.cpp +++ b/src/localdevice/qlocaldevice.h @@ -16,33 +16,22 @@ ** the contact form at http://www.qt.io ** ****************************************************************************/ -#include "qwifinetwork_p.h" +#ifndef QLOCALDEVICE_H +#define QLOCALDEVICE_H -QT_BEGIN_NAMESPACE +#include <qobject.h> -QWifiNetwork::QWifiNetwork(QObject *parent) - : QObject(parent) - , m_isOutOfRange(false) +class Q_DECL_EXPORT QLocalDevice : public QObject { -} + Q_OBJECT -QWifiNetwork::~QWifiNetwork() -{ -} - -void QWifiNetwork::setSsid(const QString &ssid) -{ - m_ssid = ssid; -} +public: + QLocalDevice(QObject *parent = 0); + ~QLocalDevice(); -void QWifiNetwork::setSignalStrength(int strength) -{ - m_signalStrength = strength; -} - -void QWifiNetwork::setOutOfRange(bool outOfRange) -{ - m_isOutOfRange = outOfRange; -} +public Q_SLOTS: + void reboot(); + void powerOff(); +}; -QT_END_NAMESPACE +#endif // QLOCALDEVICE_H diff --git a/src/localesettings/locale.xml b/src/localesettings/locale.xml new file mode 100644 index 0000000..b722456 --- /dev/null +++ b/src/localesettings/locale.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> +<node> + <interface name="org.freedesktop.locale1"> + <property name="Locale" type="as" access="read"/> + <method name="SetLocale"> + <arg name="locale" type="as" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + </interface> +</node> + diff --git a/src/localesettings/localefiltermodel.cpp b/src/localesettings/localefiltermodel.cpp new file mode 100644 index 0000000..e13d49b --- /dev/null +++ b/src/localesettings/localefiltermodel.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "localemodel.h" +#include "localefiltermodel.h" + +LocaleFilterModel::LocaleFilterModel(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &LocaleFilterModel::filterChanged, this, &LocaleFilterModel::invalidate); + LocaleModel *localeModel = new LocaleModel(this); + setSourceModel(localeModel); +} + +LocaleFilterModel::~LocaleFilterModel() +{ + +} + +QString LocaleFilterModel::filter() const +{ + return m_filter; +} + +void LocaleFilterModel::setFilter(const QString& aFilter) +{ + m_filter = aFilter; + emit filterChanged(); +} + +bool LocaleFilterModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + bool ret = false; + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + QVariant nameRole = index.data(LocaleModel::Country); + if (nameRole.isValid()) + { + QString name = nameRole.toString(); + if (name.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + } + } + return ret; +} + +QVariant LocaleFilterModel::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant nameRole = mapped.data(LocaleModel::Code); + if (nameRole.isValid()) + { + return nameRole; + } + } + return QVariant(); +} + diff --git a/src/localesettings/localefiltermodel.h b/src/localesettings/localefiltermodel.h new file mode 100644 index 0000000..d63adb9 --- /dev/null +++ b/src/localesettings/localefiltermodel.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALEFILTERMODEL_H +#define LOCALEFILTERMODEL_H + +#include <QSortFilterProxyModel> + +class Q_DECL_EXPORT LocaleFilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) +public: + explicit LocaleFilterModel(QObject* parent); + virtual ~LocaleFilterModel(); + bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; + QString filter() const; + void setFilter(const QString& aFilter); + Q_INVOKABLE QVariant itemFromRow(const int row) const; +signals: + void filterChanged(); +private: + QString m_filter; + +}; + +#endif // LOCALEFILTERMODEL_H diff --git a/src/localesettings/localemodel.cpp b/src/localesettings/localemodel.cpp new file mode 100644 index 0000000..f1f50da --- /dev/null +++ b/src/localesettings/localemodel.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QLocale> +#include <QFuture> +#include <QFutureWatcher> +#include <QThread> +#include <QtConcurrent/QtConcurrentRun> +#include "localemodel.h" + + +LocaleItem::LocaleItem(const QLocale& locale, QObject *parent) + :QObject(parent) +{ + m_code = locale.name(); + m_country = locale.nativeCountryName(); + if (m_country.isEmpty()) { + m_country = locale.countryToString(locale.country()); + } + + m_language = locale.nativeLanguageName(); + if (m_language.isEmpty()) { + m_language = locale.languageToString(locale.language()); + } +} + +QString LocaleItem::language() const +{ + return m_language; +} + +QString LocaleItem::country() const +{ + return m_country; +} + +QString LocaleItem::code() const +{ + return m_code; +} + +LocaleModel::LocaleModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Country, "country"); + m_roleNames.insert(Language, "language"); + m_roleNames.insert(Code, "code"); + + QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this); + QFuture<void> future = QtConcurrent::run(LocaleModel::generateModel, this); + watcher->setFuture(future); + connect(watcher, SIGNAL(finished()), this, SLOT(modelReady())); +} + +void LocaleModel::modelReady() +{ + beginResetModel(); + sort(0); + endResetModel(); +} + +void LocaleModel::generateModel(LocaleModel* model) +{ + QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); + + for (const QLocale &locale : allLocales) { + if (locale.name() != QStringLiteral("C")) { + LocaleItem *l = new LocaleItem(locale); + l->moveToThread(model->thread()); + QMetaObject::invokeMethod(model, "addNewItem", Q_ARG( QObject*, qobject_cast<QObject*>(l))); + } + } +} + +void LocaleModel::addNewItem(QObject *item) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + LocaleItem* newItem = qobject_cast<LocaleItem*>(item); + if (newItem) + m_items.append(newItem); + endInsertRows(); +} + +LocaleModel::~LocaleModel() +{ + qDeleteAll(m_items); +} + +QHash<int, QByteArray> LocaleModel::roleNames() const +{ + return m_roleNames; +} + +int LocaleModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant LocaleModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + LocaleItem *item = m_items[index.row()]; + + switch (role) { + case Qt::UserRole: + return QVariant::fromValue(static_cast<QObject*>(item)); + break; + case Country: + return item->country(); + break; + case Language: + return item->language(); + break; + case Code: + return item->code(); + break; + default: + return QVariant(); + } +} + +bool LocaleModel::variantLessThan(const LocaleItem* v1, const LocaleItem* v2) +{ + return v1->language() < v2->language(); +} + +void LocaleModel::sort(int column, Qt::SortOrder order) +{ + Q_UNUSED(column); + Q_UNUSED(order); + std::sort(m_items.begin(), m_items.end(), LocaleModel::variantLessThan); +} diff --git a/src/localesettings/localemodel.h b/src/localesettings/localemodel.h new file mode 100644 index 0000000..a1525b8 --- /dev/null +++ b/src/localesettings/localemodel.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALEMODEL_H +#define LOCALEMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <QLocale> +#include <QMutex> + +class LocaleItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString code READ code CONSTANT) + Q_PROPERTY(QString country READ country CONSTANT) + Q_PROPERTY(QString language READ language CONSTANT) +public: + explicit LocaleItem(const QLocale &locale, QObject *parent=0); + QString country() const; + QString language() const; + QString code() const; + +private: + QString m_country; + QString m_language; + QString m_code; +}; + +class Q_DECL_EXPORT LocaleModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit LocaleModel(QObject *parent=0); + virtual ~LocaleModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + void sort(int column, Qt::SortOrder order=Qt::AscendingOrder); + static bool variantLessThan(const LocaleItem* v1, const LocaleItem* v2); + + enum Roles { + Language = Qt::UserRole + 1, + Country, + Code + }; + + static void generateModel(LocaleModel* model); + +signals: + void addItem(LocaleItem* item); + +private slots: + void addNewItem(QObject* item); + void modelReady(); + +private: + QList<LocaleItem*> m_items; + QHash<int, QByteArray> m_roleNames; +}; +#endif // LOCALEMODEL_H diff --git a/src/localesettings/localesettings.pro b/src/localesettings/localesettings.pro new file mode 100644 index 0000000..808477d --- /dev/null +++ b/src/localesettings/localesettings.pro @@ -0,0 +1,22 @@ +load(qt_build_config) + +TARGET = QtLocaleSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core dbus + +MODULE = localesettings +load(qt_module) + +DBUS_INTERFACES = locale.xml + +HEADERS = \ + systemlocale.h \ + systemlocale_p.h \ + localemodel.h \ + localefiltermodel.h +SOURCES += systemlocale.cpp \ + localemodel.cpp \ + localefiltermodel.cpp + diff --git a/src/localesettings/systemlocale.cpp b/src/localesettings/systemlocale.cpp new file mode 100644 index 0000000..21a1105 --- /dev/null +++ b/src/localesettings/systemlocale.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QLocale> +#include "systemlocale.h" +#include "systemlocale_p.h" + +SystemLocale::SystemLocale(QObject *parent) + :QObject(parent) + ,d_ptr(new SystemLocalePrivate(this)) +{ +} + +QString SystemLocale::locale() const +{ + Q_D(const SystemLocale); + return d->locale(); +} + +void SystemLocale::setLocale(const QString& aLocale) +{ + Q_D(SystemLocale); + d->setLocale(aLocale); + emit localeChanged(); +} diff --git a/src/localesettings/systemlocale.h b/src/localesettings/systemlocale.h new file mode 100644 index 0000000..9472e9c --- /dev/null +++ b/src/localesettings/systemlocale.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALE_H +#define LOCALE_H + +#include <QObject> + +class SystemLocalePrivate; + +class Q_DECL_EXPORT SystemLocale : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged) +public: + explicit SystemLocale(QObject *parent = 0); + QString locale() const; + void setLocale(const QString& aLocale); +signals: + void localeChanged(); +public slots: + +protected: + SystemLocalePrivate *d_ptr; + + Q_DISABLE_COPY(SystemLocale) + Q_DECLARE_PRIVATE(SystemLocale) +}; + +#endif // LOCALE_H diff --git a/src/localesettings/systemlocale_p.h b/src/localesettings/systemlocale_p.h new file mode 100644 index 0000000..0f3e6df --- /dev/null +++ b/src/localesettings/systemlocale_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALE_P_H +#define LOCALE_P_H + +#include "systemlocale.h" +#include "locale_interface.h" + +class SystemLocalePrivate +{ + Q_DECLARE_PUBLIC(SystemLocale) +public: + SystemLocalePrivate(SystemLocale *qq) + :q_ptr(qq) + { + m_localeInterface = new OrgFreedesktopLocale1Interface(QStringLiteral("org.freedesktop.locale1"), + QStringLiteral("/org/freedesktop/locale1"), + QDBusConnection::systemBus(), qq); + + QStringList locale = m_localeInterface->locale(); + foreach (QString l, locale) { + QStringList nameValue = l.split('='); + if (nameValue.length() == 2) + m_localeCache[nameValue.at(0)] = nameValue.at(1); + } + } + + QString locale() const { + return m_localeCache[QStringLiteral("LANG")]; + } + + void setLocale(const QString& aLocale) { + m_localeCache[QStringLiteral("LANG")] = aLocale; + updateLocale(); + } + + void updateLocale() { + QStringList newLocale; + QMap<QString, QString>::iterator i; + for (i = m_localeCache.begin(); i != m_localeCache.end(); ++i) { + QString val = i.key() + "=" + i.value(); + newLocale.append(val); + } + m_localeInterface->SetLocale(newLocale, true); + } + + +private: + QMap<QString, QString> m_localeCache; + OrgFreedesktopLocale1Interface *m_localeInterface; + SystemLocale *q_ptr; +}; + +#endif // LOCALE_P_H diff --git a/src/networksettings/connman.pri b/src/networksettings/connman.pri new file mode 100644 index 0000000..957f2f0 --- /dev/null +++ b/src/networksettings/connman.pri @@ -0,0 +1,22 @@ +QT += core network dbus + +INCLUDEPATH += $${PWD}/connman + +DBUS_INTERFACES = \ + connman/connman_manager.xml \ + connman/connman_service.xml \ + connman/connman_technology.xml + +SOURCES += \ + $$PWD/connman/qnetworksettingsinterface_p.cpp \ + $$PWD/connman/qnetworksettingsservice_p.cpp \ + $$PWD/connman/qnetworksettingsuseragent_p.cpp \ + $$PWD/connman/qnetworksettingsmanager_p.cpp \ + $$PWD/connman/connmancommon.cpp + +HEADERS += \ + $$PWD/connman/qnetworksettingsinterface_p.h \ + $$PWD/connman/qnetworksettingsservice_p.h \ + $$PWD/connman/qnetworksettingsuseragent_p.h \ + $$PWD/connman/qnetworksettingsmanager_p.h \ + $$PWD/connman/connmancommon.h diff --git a/src/networksettings/connman/connman_manager.xml b/src/networksettings/connman/connman_manager.xml new file mode 100644 index 0000000..5c52b27 --- /dev/null +++ b/src/networksettings/connman/connman_manager.xml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Manager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Manager"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="GetTechnologies" tp:name-for-bindings="Get_Technologies"> + <arg name="technologies" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapList"/> + </method> + + <method name="GetServices" tp:name-for-bindings="Get_Services"> + <arg name="services" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapList"/> + </method> + + <method name="GetSavedServices" tp:name-for-bindings="Get_Saved_Services"> + <arg name="services" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapList"/> + </method> + + <method name="RemoveSavedService" tp:name-for-bindings="Remove_Saved_Services"> + <arg name="identifier" type="s" direction="in"/> + </method> + + <method name="RegisterAgent" tp:name-for-bindings="Register_Agent"> + <arg name="path" type="o"/> + </method> + + <method name="UnregisterAgent" tp:name-for-bindings="Unregister_Agent"> + <arg name="path" type="o"/> + </method> + + <method name="RegisterCounter" tp:name-for-bindings="Register_Counter"> + <arg name="path" type="o"/> + <arg name="accuracy" type="u"/> + <arg name="period" type="u"/> + </method> + + <method name="UnregisterCounter" tp:name-for-bindings="Unregister_Counter"> + <arg name="path" type="o"/> + </method> + + <method name="ResetCounters" tp:name-for-bindings="Reset_Counters"> + <arg name="type" type="s"/> + </method> + + <method name="CreateSession" tp:name-for-bindings="Create_Session"> + <arg name="settings" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="notifier" type="o"/> + <arg name="session" type="o" direction="out"/> + </method> + + <method name="DestroySession" tp:name-for-bindings="Destroy_Session"> + <arg name="session" type="o"/> + </method> + + <method name="RequestPrivateNetwork" tp:name-for-bindings="Request_Private_Network"> + <arg name="options" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="path" type="o" direction="out"/> + <arg name="dict" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> + <arg name="fd" type="i" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + </method> + + <method name="ReleasePrivateNetwork" tp:name-for-bindings="Release_Private_Network"> + <arg name="path" type="o"/> + </method> + + <signal name="NetworkTypeAdded" tp:name-for-bindings="NetworkType_Added"> + <arg name="technology" type="o"/> + <arg name="properties" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + </signal> + + <signal name="NetworkTypeRemoved" tp:name-for-bindings="NetworkType_Removed"> + <arg name="technology" type="o"/> + </signal> + + <signal name="ServicesChanged" tp:name-for-bindings="Services_Changed"> + <arg name="changed" type="a(oa{sv})"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanMapList"/> + <arg name="removed" type="ao"/> + </signal> + + <signal name="SavedServicesChanged" tp:name-for-bindings="SavedServices_Changed"> + <arg name="changed" type="a(oa{sv})"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanMapList"/> + </signal> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/networksettings/connman/connman_service.xml b/src/networksettings/connman/connman_service.xml new file mode 100644 index 0000000..c41aca4 --- /dev/null +++ b/src/networksettings/connman/connman_service.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Service"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="ClearProperty" tp:name-for-bindings="Clear_Property"> + <arg name="name" type="s" /> + </method> + + <method name="Connect" tp:name-for-bindings="Connect" /> + + <method name="Disconnect" tp:name-for-bindings="Disconnect" /> + + <method name="Remove" tp:name-for-bindings="Remove" /> + + <method name="MoveBefore" tp:name-for-bindings="Move_Before"> + <arg name="service" type="o"/> + </method> + + <method name="MoveAfter" tp:name-for-bindings="Move_After"> + <arg name="service" type="o"/> + </method> + + <method name="ResetCounters" tp:name-for-bindings="Reset_Counters" /> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/networksettings/connman/connman_technology.xml b/src/networksettings/connman/connman_technology.xml new file mode 100644 index 0000000..08d780f --- /dev/null +++ b/src/networksettings/connman/connman_technology.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Technology"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="Scan" tp:name-for-bindings="Scan"/> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/networksettings/connman/connmancommon.cpp b/src/networksettings/connman/connmancommon.cpp new file mode 100644 index 0000000..94a1fa1 --- /dev/null +++ b/src/networksettings/connman/connmancommon.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "connmancommon.h" + +//Conversion operations for datatypes +const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj) +{ + argument.beginStructure(); + argument >> obj.objectPath >> obj.propertyMap; + argument.endStructure(); + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj) +{ + argument.beginStructure(); + argument << obj.objectPath << obj.propertyMap; + argument.endStructure(); + return argument; +} + +const QString &operator>>(const QString &argument, QNetworkSettingsType &obj) +{ + if (argument == AttributeEthernet) { + obj.setType(QNetworkSettingsType::Wired); + } + else if (argument == AttributeWifi) { + obj.setType(QNetworkSettingsType::Wifi); + } + else { + obj.setType(QNetworkSettingsType::Unknown); + } + + return argument; +} + +const QString &operator>>(const QString &argument, QNetworkSettingsState &obj) +{ + if (argument == AttributeIdle) { + obj.setState(QNetworkSettingsState::Idle); + } + else if (argument == AttributeFailure) { + obj.setState(QNetworkSettingsState::Failure); + } + else if (argument == AttributeAssociation) { + obj.setState(QNetworkSettingsState::Association); + } + else if (argument == AttributeConfiguration) { + obj.setState(QNetworkSettingsState::Configuration); + } + else if (argument == AttributeReady) { + obj.setState(QNetworkSettingsState::Ready); + } + else if (argument == AttributeDisconnect) { + obj.setState(QNetworkSettingsState::Disconnect); + } + else if (argument == AttributeOneline) { + obj.setState(QNetworkSettingsState::Online); + } + else { + obj.setState(QNetworkSettingsState::Undefined); + } + return argument; +} diff --git a/src/networksettings/connman/connmancommon.h b/src/networksettings/connman/connmancommon.h new file mode 100644 index 0000000..16850ea --- /dev/null +++ b/src/networksettings/connman/connmancommon.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CONNMANCOMMON_H +#define CONNMANCOMMON_H + +#include <QtCore/QMetaType> +#include <QtDBus> +#include <qnetworksettings.h> + +#define AgentPath "/ConnmanAgent" +#define PropertyState QStringLiteral("State") +#define PropertyName QStringLiteral("Name") +#define PropertyType QStringLiteral("Type") +#define PropertyConnected QStringLiteral("Connected") +#define PropertyPowered QStringLiteral("Powered") + +#define AttributeWifi QStringLiteral("wifi") +#define AttributeEthernet QStringLiteral("ethernet") +#define AttributeIdle QStringLiteral("idle") +#define AttributeFailure QStringLiteral("failure") +#define AttributeAssociation QStringLiteral("association") +#define AttributeConfiguration QStringLiteral("configuration") +#define AttributeReady QStringLiteral("ready") +#define AttributeDisconnect QStringLiteral("disconnect") +#define AttributeOneline QStringLiteral("online") + +struct ConnmanMap { + QDBusObjectPath objectPath; + QVariantMap propertyMap; +}; + +QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj); +const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj); + +const QString &operator>>(const QString &argument, QNetworkSettingsType &obj); +const QString &operator>>(const QString &argument, QNetworkSettingsState &obj); + +typedef QList<ConnmanMap> ConnmanMapList; + +Q_DECLARE_METATYPE( ConnmanMap ) +Q_DECLARE_METATYPE( ConnmanMapList ) + + +#endif // CONNMANCOMMON_H diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.cpp b/src/networksettings/connman/qnetworksettingsinterface_p.cpp new file mode 100644 index 0000000..dda05be --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsinterface_p.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsinterface.h" +#include "connman_technology_interface.h" +#include "connmancommon.h" + +QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) + : QObject(parent) + ,q_ptr(parent) +{ + +} + +void QNetworkSettingsInterfacePrivate::initialize(const QString& path, const QVariantMap& properties) +{ + m_technology = new NetConnmanTechnologyInterface(QStringLiteral("net.connman"), path, + QDBusConnection::systemBus(), this); + connect(m_technology, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(updateProperty(QString,QDBusVariant))); + + updateProperty(PropertyName, properties[PropertyName]); + updateProperty(PropertyType, properties[PropertyType]); + updateProperty(PropertyConnected, properties[PropertyConnected]); + updateProperty(PropertyPowered, properties[PropertyPowered]); +} + +void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const QDBusVariant &value) +{ + updateProperty(name, value.variant()); +} + +void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const QVariant &value) +{ + Q_Q(QNetworkSettingsInterface); + if (name == PropertyName) { + m_name = qdbus_cast<QString>(value); + } + else if (name == PropertyType) { + qdbus_cast<QString>(value) >> m_type; + emit q->typeChanged(); + } + else if (name == PropertyConnected) { + bool connected = qdbus_cast<bool>(value); + if (connected) + m_state.setState(QNetworkSettingsState::Online); + else + m_state.setState(QNetworkSettingsState::Disconnect); + emit q->stateChanged(); + } + else if (name == PropertyPowered) { + m_powered = qdbus_cast<bool>(value); + emit q->poweredChanged(); + } +} + +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +{ + Q_Q(QNetworkSettingsInterface); + m_state.setState(aState); + emit q->stateChanged(); +} + +void QNetworkSettingsInterfacePrivate::setPowered(const bool aPowered) +{ + m_technology->SetProperty(PropertyPowered, QDBusVariant(QVariant(aPowered))); +} + +void QNetworkSettingsInterfacePrivate::scan() +{ + m_technology->Scan(); +} diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.h b/src/networksettings/connman/qnetworksettingsinterface_p.h new file mode 100644 index 0000000..6e1d5ca --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsinterface_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEPRIVATE_H +#define QNETWORKSETTINGSINTERFACEPRIVATE_H + +#include <QObject> +#include <QtDBus> +#include "qnetworksettings.h" +#include "qnetworksettingsinterface.h" + +class NetConnmanTechnologyInterface; + +class QNetworkSettingsInterfacePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsInterface) +public: + explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); + void initialize(const QString& path, const QVariantMap& properties); + void setPowered(const bool power); + void setState(QNetworkSettingsState::States aState); + void scan(); + +public slots: + void updateProperty(const QString &name, const QDBusVariant &value); +protected: + void updateProperty(const QString &name, const QVariant &value); + +protected: + NetConnmanTechnologyInterface *m_technology; + QString m_name; + QNetworkSettingsType m_type; + QNetworkSettingsState m_state; + bool m_powered; + QNetworkSettingsInterface *q_ptr; +}; + + +class ConnmanSettingsInterface : public QNetworkSettingsInterface +{ + Q_OBJECT +public: + ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent=0) + :QNetworkSettingsInterface(parent) + { + if (d_ptr) + d_ptr->initialize(path, properties); + } + + void setState(QNetworkSettingsState::States aState) { + Q_D(QNetworkSettingsInterface); + d->setState(aState); + } + + virtual ~ConnmanSettingsInterface() { + + } +}; +#endif // QNETWORKSETTINGSINTERFACEPRIVATE_H diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/networksettings/connman/qnetworksettingsmanager_p.cpp new file mode 100644 index 0000000..64b4341 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsmanager_p.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsmanager_p.h" +#include "connman_manager_interface.cpp" +#include "moc_connman_manager_interface.cpp" +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsservicemodel.h" + +QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent) + :QObject(parent) + ,q_ptr(parent) +{ + m_serviceModel = new QNetworkSettingsServiceModel(this); + m_serviceFilter = new QNetworkSettingsServiceFilter(this); + m_serviceFilter->setSourceModel(m_serviceModel); + m_manager = new NetConnmanManagerInterface(QStringLiteral("net.connman"), QStringLiteral("/"), + QDBusConnection::systemBus(), this); + + if (m_manager->isValid()) { + //List technologies + QDBusPendingReply<ConnmanMapList> reply = m_manager->GetTechnologies(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(getTechnologiesFinished(QDBusPendingCallWatcher*))); + + reply = m_manager->GetServices(); + watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(getServicesFinished(QDBusPendingCallWatcher*))); + + connect(m_manager, &NetConnmanManagerInterface::ServicesChanged, this, &QNetworkSettingsManagerPrivate::servicesChanged); + + m_manager->RegisterAgent(QDBusObjectPath(AgentPath)); + } + else { + delete m_manager; + m_manager = NULL; + } +} + +void QNetworkSettingsManagerPrivate::requestInput(const QString& service, const QString& type) +{ + Q_UNUSED(type); + foreach (QNetworkSettingsService* servicePtr, m_serviceModel->getModel()) { + if (servicePtr->id() == service) + emit servicePtr->showCrendentialInput(); + } +} + +void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher *watcher) +{ + Q_Q(QNetworkSettingsManager); + QDBusPendingReply<ConnmanMapList> reply = *watcher; + watcher->deleteLater(); + if (reply.isError()) + return; + + foreach (const ConnmanMap &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()); + } + } + } + emit q->servicesChanged(); +} + +void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWatcher *watcher) +{ + Q_Q(QNetworkSettingsManager); + + QDBusPendingReply<ConnmanMapList> reply = *watcher; + watcher->deleteLater(); + if (reply.isError()) + return; + + foreach (const ConnmanMap &object, reply.value()) { + ConnmanSettingsInterface *item = new ConnmanSettingsInterface(object.objectPath.path(), object.propertyMap, this); + + if (item->type() == QNetworkSettingsType::Wired) { + m_interfaceModel.insert(0, item); + } + else if (item->type() == QNetworkSettingsType::Wifi) { + m_interfaceModel.append(item); + } + emit q->interfacesChanged(); + } +} + +void QNetworkSettingsManagerPrivate::servicesChanged(ConnmanMapList changed, const QList<QDBusObjectPath> &removed) +{ + foreach (QDBusObjectPath path, removed) { + QList<QNetworkSettingsService*> serviceList = m_serviceModel->getModel(); + QMutableListIterator<QNetworkSettingsService*> i(serviceList); + while (i.hasNext()) { + if (i.next()->id() == path.path()) + i.remove(); + } + } + + QStringList newServices; + foreach (ConnmanMap map, changed) { + bool found = false; + foreach (QNetworkSettingsService* service, m_serviceModel->getModel()) { + if (service->id() == map.objectPath.path()) { + found =true; + break; + } + } + if (!found) + newServices.append(map.objectPath.path()); + } + foreach (QString newService, newServices) { + QNetworkSettingsService *service = new QNetworkSettingsService(newService, this); + m_serviceModel->append(service); + } +} + +void QNetworkSettingsManagerPrivate::setUserAgent(QNetworkSettingsUserAgent *agent) +{ + Q_UNUSED(agent); +} diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.h b/src/networksettings/connman/qnetworksettingsmanager_p.h new file mode 100644 index 0000000..3176c98 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsmanager_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGERPRIVATE_H +#define QNETWORKSETTINGSMANAGERPRIVATE_H + +#include <QObject> +#include <QtDBus> +#include "connmancommon.h" +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsinterfacemodel.h" + +class NetConnmanManagerInterface; +class QNetworkSettingsServiceModel; +class QNetworkSettingsServiceFilter; + +class QNetworkSettingsManagerPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsManager) +public: + explicit QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent); + QNetworkSettingsManager *q_ptr; + void setUserAgent(QNetworkSettingsUserAgent *agent); + +public slots: + void getServicesFinished(QDBusPendingCallWatcher *watcher); + void getTechnologiesFinished(QDBusPendingCallWatcher *watcher); + void requestInput(const QString& service, const QString& type); + void servicesChanged(ConnmanMapList changed, const QList<QDBusObjectPath> &removed); + +protected: + QNetworkSettingsInterfaceModel m_interfaceModel; + QNetworkSettingsServiceModel *m_serviceModel; + QNetworkSettingsServiceFilter *m_serviceFilter; +private: + NetConnmanManagerInterface *m_manager; +}; + +#endif // QNETWORKSETTINGSMANAGERPRIVATE_H diff --git a/src/networksettings/connman/qnetworksettingsservice_p.cpp b/src/networksettings/connman/qnetworksettingsservice_p.cpp new file mode 100644 index 0000000..b4e33a3 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsservice_p.cpp @@ -0,0 +1,402 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservice_p.h" +#include "connman_service_interface.h" +#include "connmancommon.h" + +const QString PropertyIPv4(QStringLiteral("IPv4")); +const QString PropertyQNetworkSettingsIPv4(QStringLiteral("IPv4.Configuration")); +const QString PropertyIPv6(QStringLiteral("IPv6")); +const QString PropertyQNetworkSettingsIPv6(QStringLiteral("IPv6.Configuration")); +const QString PropertyNameservers(QStringLiteral("Nameservers")); +const QString PropertyNameserversConfig(QStringLiteral("Nameservers.Configuration")); +const QString PropertyDomains(QStringLiteral("Domains")); +const QString PropertyDomainsConfig(QStringLiteral("Domains.Configuration")); +const QString PropertyProxy(QStringLiteral("Proxy")); +const QString PropertyQNetworkSettingsProxy(QStringLiteral("Proxy.Configuration")); +const QString PropertyAddress(QStringLiteral("Address")); +const QString PropertyNetMask(QStringLiteral("Netmask")); +const QString PropertyGateway(QStringLiteral("Gateway")); +const QString PropertyPrefixLength(QStringLiteral("PrefixLength")); +const QString PropertyMethod(QStringLiteral("Method")); +const QString PropertyPrivacy(QStringLiteral("Privacy")); +const QString PropertyUrl(QStringLiteral("Url")); +const QString PropertyServers(QStringLiteral("Servers")); +const QString PropertyExcludes(QStringLiteral("Excludes")); +const QString PropertyStrength(QStringLiteral("Strength")); +const QString PropertySecurity(QStringLiteral("Security")); + +const QString AttributeAuto(QStringLiteral("auto")); +const QString AttributeDhcp(QStringLiteral("dhcp")); +const QString AttributeManual(QStringLiteral("manual")); +const QString AttributeOff(QStringLiteral("off")); +const QString AttributeDisabled(QStringLiteral("disabled")); +const QString AttributeEnabled(QStringLiteral("enabled")); +const QString AttributePreferred(QStringLiteral("preferred")); +const QString AttributeDirect(QStringLiteral("direct")); +const QString AttributeNone(QStringLiteral("none")); +const QString AttributeWep(QStringLiteral("wep")); +const QString AttributePsk(QStringLiteral("psk")); +const QString AttributeIeee(QStringLiteral("ieee8021x")); +const QString AttributeWps(QStringLiteral("wps")); +const QString AttributeInvalidKey(QStringLiteral("invalid-key")); + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsIPv4 &obj) +{ + obj.setAddress(argument[PropertyAddress].toString()); + obj.setMask(argument[PropertyNetMask].toString()); + obj.setGateway(argument[PropertyGateway].toString()); + + QString method = argument[PropertyMethod].toString(); + + if (method == AttributeDhcp) { + obj.setMethod(QNetworkSettingsIPv4::Dhcp); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsIPv4::Manual); + } + else if (method == AttributeOff) { + obj.setMethod(QNetworkSettingsIPv4::Off); + } + else { + obj.setMethod(QNetworkSettingsIPv4::Off); + } + return argument; +} + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsIPv4 &obj) +{ + argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); + + argument.insert(PropertyNetMask, QVariant::fromValue(obj.mask())); + + argument.insert(PropertyGateway, QVariant::fromValue(obj.gateway())); + + QString method; + switch (obj.method()) { + case QNetworkSettingsIPv4::Dhcp: + method = AttributeDhcp; + break; + case QNetworkSettingsIPv4::Manual: + method = AttributeManual; + break; + case QNetworkSettingsIPv4::Off: + method = AttributeOff; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + return argument; +} + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsIPv6 &obj) +{ + obj.setAddress(argument[PropertyAddress].toString()); + obj.setGateway(argument[PropertyGateway].toString()); + obj.setPrefixLength(argument[PropertyPrefixLength].toInt()); + QString method = argument[PropertyMethod].toString(); + if (method == AttributeAuto) { + obj.setMethod(QNetworkSettingsIPv6::Auto); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsIPv6::Manual); + } + else if (method == AttributeOff) { + obj.setMethod(QNetworkSettingsIPv6::Off); + } + QString privacy = argument[PropertyPrivacy].toString(); + + if (privacy == AttributeDisabled) { + obj.setPrivacy(QNetworkSettingsIPv6::Disabled); + } + else if (privacy == AttributeEnabled) { + obj.setPrivacy(QNetworkSettingsIPv6::Enabled); + } + else if (privacy == AttributePreferred) { + obj.setPrivacy(QNetworkSettingsIPv6::Preferred); + } + return argument; +} + + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsIPv6 &obj) +{ + argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); + argument.insert(PropertyGateway, QVariant::fromValue(obj.address())); + argument.insert(PropertyPrefixLength, QVariant::fromValue(obj.prefixLength())); + + QString method; + switch (obj.method()) { + case QNetworkSettingsIPv6::Auto: + method = AttributeAuto; + break; + case QNetworkSettingsIPv6::Manual: + method = AttributeManual; + break; + case QNetworkSettingsIPv6::Off: + method = AttributeOff; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + + QString privacy; + switch (obj.privacy()) { + case QNetworkSettingsIPv6::Disabled: + method = AttributeDisabled; + break; + case QNetworkSettingsIPv6::Enabled: + method = AttributeEnabled; + break; + case QNetworkSettingsIPv6::Preferred: + method = AttributePreferred; + break; + default: + break; + } + argument.insert(PropertyPrivacy, QVariant::fromValue(privacy)); + + return argument; +} + + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsProxy &obj) +{ + QString method = argument[PropertyMethod].toString(); + if (method == AttributeDirect) { + obj.setMethod(QNetworkSettingsProxy::Direct); + } + else if (method == AttributeAuto) { + obj.setMethod(QNetworkSettingsProxy::Auto); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsProxy::Manual); + } + + QString urlStr = argument[PropertyUrl].toString(); + obj.setUrl(QUrl(urlStr)); + + obj.setServers(argument[PropertyServers].toStringList()); + obj.setExcludes(argument[PropertyExcludes].toStringList()); + + return argument; +} + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsProxy &obj) +{ + QString method; + switch (obj.method()) { + case QNetworkSettingsProxy::Direct: + method = AttributeDirect; + break; + case QNetworkSettingsProxy::Auto: + method = AttributeAuto; + break; + case QNetworkSettingsProxy::Manual: + method = AttributeManual; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + argument.insert(PropertyUrl, QVariant::fromValue(obj.url().toString())); + argument.insert(PropertyServers, QVariant::fromValue(obj.servers())); + argument.insert(PropertyServers, QVariant::fromValue(obj.excludes())); + + return argument; +} + +QNetworkSettingsServicePrivate::QNetworkSettingsServicePrivate(const QString& id, QNetworkSettingsService *parent) : + QObject(parent) + ,q_ptr(parent) + ,m_id(id) +{ + qDBusRegisterMetaType<ConnmanMap>(); + qDBusRegisterMetaType<ConnmanMapList>(); + + m_service = new NetConnmanServiceInterface(QStringLiteral("net.connman"), m_id, + QDBusConnection::systemBus(), this); + + connect(m_service, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(updateProperty(QString,QDBusVariant))); + + QDBusPendingReply<QVariantMap> reply = m_service->GetProperties(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(propertiesUpdated(QDBusPendingCallWatcher*))); +} + +void QNetworkSettingsServicePrivate::setupIpv6Config() +{ + QVariantMap param; + param << m_ipv6config; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsIPv6, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupNameserversConfig() +{ + QVariant param = QVariant::fromValue(m_nameserverConfig.stringList()); + if (m_service) + m_service->SetProperty(PropertyNameserversConfig, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupDomainsConfig() +{ + QVariant param = QVariant::fromValue(m_domainsConfig.stringList()); + if (m_service) + m_service->SetProperty(PropertyDomainsConfig, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupQNetworkSettingsProxy() +{ + QVariantMap param; + param << m_proxyConfig; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsProxy, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupIpv4Config() +{ + QVariantMap param; + param << m_ipv4config; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsIPv4, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::connectService() +{ + if (m_service) { + m_service->Connect(); + } +} + +void QNetworkSettingsServicePrivate::disconnectService() +{ + if (m_service) + m_service->Disconnect(); + +} + +void QNetworkSettingsServicePrivate::propertiesUpdated(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply<QVariantMap> reply = *call; + call->deleteLater(); + + if (!reply.isError()) + setupConfiguration(reply.value()); +} + +void QNetworkSettingsServicePrivate::updateProperty(const QString &name, const QDBusVariant &value) +{ + updateProperty(name, value.variant()); +} + +void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QVariant& val) +{ + Q_Q(QNetworkSettingsService); + + if (key == PropertyIPv4) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_ipv4config; + emit q->ipv4Changed(); + } + else if (key == PropertyIPv6) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_ipv6config; + emit q->ipv6Changed(); + } + else if (key == PropertyNameservers) { + QStringList value = qdbus_cast<QStringList>(val); + m_nameserverConfig.setStringList(value); + emit q->nameserversChanged(); + } + else if (key == PropertyDomains) { + QStringList value = qdbus_cast<QStringList>(val); + m_domainsConfig.setStringList(value); + emit q->domainsChanged(); + } + else if (key == PropertyProxy) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_proxyConfig; + emit q->proxyChanged(); + } + else if (key == PropertyState) { + QString value = qdbus_cast<QString>(val); + value >> m_state; + emit q->stateChanged(); + } + else if (key == PropertyName) { + m_name = qdbus_cast<QString>(val); + emit q->nameChanged(); + } + else if (key == PropertyType) { + QString value = qdbus_cast<QString>(val); + value >> m_type; + } + else if (key == PropertyStrength) { + m_wifiConfig.setSignalStrength(val.toInt()); + } + else if (key == PropertySecurity) { + QStringList value = qdbus_cast<QStringList>(val); + foreach (const QString str, value) { + if (str == AttributeNone || str == AttributeWps) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::None); + } + else if (str == AttributeWep) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + } + else if (str == AttributePsk) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + } + else if (str == AttributeIeee) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + } + } + } +} + +void QNetworkSettingsServicePrivate::setupConfiguration(const QVariantMap &properties) +{ + QVariantMap::const_iterator it = properties.constBegin(), end = properties.constEnd(); + for ( ; it != end; ++it) { + updateProperty(it.key(), it.value()); + } +} + diff --git a/src/networksettings/connman/qnetworksettingsservice_p.h b/src/networksettings/connman/qnetworksettingsservice_p.h new file mode 100644 index 0000000..39a04bd --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsservice_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEPRIVATE_H +#define QNETWORKSETTINGSSERVICEPRIVATE_H + +#include <QtDBus> +#include "qnetworksettingsservice.h" +#include "qnetworksettings.h" + +class NetConnmanServiceInterface; + +class QNetworkSettingsServicePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsService) +public: + QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent=0); + + QNetworkSettingsService *q_ptr; +private slots: + void propertiesUpdated(QDBusPendingCallWatcher *call); + void updateProperty(const QString &name, const QDBusVariant &value); + +private: + void setupConfiguration(const QVariantMap &properties); + void updateProperty(const QString& key, const QVariant& value); + +protected: + void setAutoConnect(const bool autoconnect); + void setupIpv4Config(); + void setupIpv6Config(); + void setupNameserversConfig(); + void setupDomainsConfig(); + void setupQNetworkSettingsProxy(); + void connectService(); + void disconnectService(); + + QString m_id; + QString m_name; + QNetworkSettingsState m_state; + QNetworkSettingsIPv4 m_ipv4config; + QNetworkSettingsIPv6 m_ipv6config; + QNetworkSettingsAddressModel m_domainsConfig; + QNetworkSettingsAddressModel m_nameserverConfig; + QNetworkSettingsProxy m_proxyConfig; + QNetworkSettingsWireless m_wifiConfig; + QNetworkSettingsType m_type; + NetConnmanServiceInterface *m_service; +}; + +#endif // QNETWORKSETTINGSSERVICEPRIVATE_H diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp new file mode 100644 index 0000000..514745e --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent_p.h" +#include "connmancommon.h" + +const QString PropertyPassphrase(QStringLiteral("Passphrase")); + +QNetworkSettingsUserAgentPrivate::QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent) + :QDBusAbstractAdaptor(parent) + ,q_ptr(parent) + ,m_pendingReply(false) +{ + + setAutoRelaySignals(true); + QMetaObject::invokeMethod(this, "registerAgent", Qt::QueuedConnection); +} + +void QNetworkSettingsUserAgentPrivate::cancel() +{ + // handle method call net.connman.Agent.Cancel + m_pendingReply = false; + QMetaObject::invokeMethod(parent(), "Cancel"); +} + +void QNetworkSettingsUserAgentPrivate::release() +{ + // handle method call net.connman.Agent.Release + QMetaObject::invokeMethod(parent(), "Release"); +} + +void QNetworkSettingsUserAgentPrivate::ReportError(const QDBusObjectPath &path, const QString ¶m) +{ + Q_Q(QNetworkSettingsUserAgent); + Q_UNUSED(path); + Q_UNUSED(param); + emit q->error(); +} + +void QNetworkSettingsUserAgentPrivate::registerAgent() +{ + Q_Q(QNetworkSettingsUserAgent); + QDBusConnection::systemBus().registerObject(QStringLiteral(AgentPath), q); +} + +QVariantMap QNetworkSettingsUserAgentPrivate::RequestInput(const QDBusObjectPath &path, const QVariantMap ¶ms, const QDBusMessage &msg) +{ + Q_Q(QNetworkSettingsUserAgent); + Q_UNUSED(path); + Q_UNUSED(params); + msg.setDelayedReply(true); + m_reply = msg.createReply(); + m_pendingReply = true; + emit q->showUserCredentialsInput(); + return QVariantMap(); +} + +void QNetworkSettingsUserAgentPrivate::setUserCredentials(const QString& username, + const QString& password) +{ + m_username = username; + m_passphrase = password; + QVariantMap response; + response[PropertyName] = m_username; + response[PropertyPassphrase] = m_passphrase; + m_reply << response; + m_pendingReply = false; + QDBusConnection::systemBus().send(m_reply); +} diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.h b/src/networksettings/connman/qnetworksettingsuseragent_p.h new file mode 100644 index 0000000..efde5b5 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENTPRIVATE_H +#define QNETWORKSETTINGSUSERAGENTPRIVATE_H + +#include <QtCore/QObject> +#include <QtDBus/QtDBus> +#include "qnetworksettingsuseragent.h" + +QT_BEGIN_NAMESPACE +class QByteArray; +template<class T> class QList; +template<class Key, class Value> class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +const QString AgentPath(QStringLiteral("/ConnmanAgent")); + +class QNetworkSettingsUserAgentPrivate : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.connman.Agent") + Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) +public: + QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent=0); + void setUserCredentials(const QString& aUsername, const QString& aPassword); + void cancel(); + void release(); +public Q_SLOTS: // Dbus methods + void ReportError(const QDBusObjectPath &path, const QString ¶m); + QVariantMap RequestInput(const QDBusObjectPath &path, const QVariantMap ¶ms, + const QDBusMessage &message); + void registerAgent(); +private: + QNetworkSettingsUserAgent *q_ptr; + QDBusMessage m_reply; + bool m_pendingReply; + QString m_passphrase; + QString m_username; +}; + +#endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H diff --git a/src/networksettings/networksettings.pro b/src/networksettings/networksettings.pro new file mode 100644 index 0000000..9ae1bb3 --- /dev/null +++ b/src/networksettings/networksettings.pro @@ -0,0 +1,37 @@ +load(qt_build_config) + +TARGET = QtNetworkSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core network + +MODULE = networksettings +load(qt_module) + +wpasupplicant { + include(wpasupplicant.pri) +} +else { + include(connman.pri) +} + +# Input +SOURCES += \ + qnetworksettingsinterfacemodel.cpp \ + qnetworksettingsmanager.cpp \ + qnetworksettingsaddressmodel.cpp \ + qnetworksettingsservicemodel.cpp \ + qnetworksettingsservice.cpp \ + qnetworksettingsuseragent.cpp \ + qnetworksettingsinterface.cpp \ + +HEADERS += \ + qnetworksettingsinterfacemodel.h \ + qnetworksettings.h \ + qnetworksettingsmanager.h \ + qnetworksettingsaddressmodel.h \ + qnetworksettingsservicemodel.h \ + qnetworksettingsservice.h \ + qnetworksettingsuseragent.h \ + qnetworksettingsinterface.h \ diff --git a/src/networksettings/qnetworksettings.h b/src/networksettings/qnetworksettings.h new file mode 100644 index 0000000..839d5a9 --- /dev/null +++ b/src/networksettings/qnetworksettings.h @@ -0,0 +1,411 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGS_H +#define QNETWORKSETTINGS_H + +#include <QObject> +#include <QUrl> +#include <QVariantMap> +#include "qnetworksettingsaddressmodel.h" + +class Q_DECL_EXPORT QNetworkSettingsState : public QObject +{ + Q_OBJECT + Q_ENUMS(States) + Q_PROPERTY(States state READ state WRITE setState NOTIFY stateChanged) + +public: + enum States {Idle, Failure, Association, Configuration, Ready, Disconnect, Online, Undefined}; + + explicit QNetworkSettingsState(States state, QObject *parent = 0) + : QObject(parent) + { + m_state = state; + } + + explicit QNetworkSettingsState(QObject *parent = 0) + : QObject(parent) + { + m_state = Undefined; + } + + States state() const { + return m_state; + } + + void setState(const States state) { + m_state = state; + emit stateChanged(); + } + +signals: + void stateChanged(); + +private: + States m_state; +}; + +class Q_DECL_EXPORT QNetworkSettingsType : public QObject +{ + Q_OBJECT + Q_ENUMS(Types) + Q_PROPERTY(Types type READ type WRITE setType NOTIFY typeChanged) + +public: + enum Types { + Wired, + Wifi, + Bluetooth, + Unknown + }; + + explicit QNetworkSettingsType(Types type, QObject *parent = 0) + : QObject(parent) + { + m_type = type; + } + + explicit QNetworkSettingsType(QObject *parent = 0) + : QObject(parent) + { + m_type = Unknown; + } + + + Types type() const { + return m_type; + } + + void setType(const Types type) { + m_type = type; + emit typeChanged(); + } + +signals: + void typeChanged(); + +private: + Types m_type; +}; + +class Q_DECL_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(QString mask READ mask WRITE setMask NOTIFY maskChanged) + +public: + explicit QNetworkSettingsIPv4(QObject *parent = 0) + : QObject(parent) + { + + } + + enum MethodType {Dhcp, Manual, Off}; + + QString address() const { + return m_address; + } + void setAddress(const QString& adderess) { + m_address = adderess; + emit addressChanged(); + } + + QString gateway() const { + return m_gateway; + } + + void setGateway(const QString& gateway) { + m_gateway = gateway; + emit gatewayChanged(); + } + + MethodType method() const { + return m_method; + } + + void setMethod(const MethodType method) { + m_method = method; + emit methodChanged(); + } + + QString mask() const { + return m_mask; + } + + void setMask(const QString& mask) { + m_mask = mask; + emit maskChanged(); + } + +signals: + void addressChanged(); + void gatewayChanged(); + void methodChanged(); + void maskChanged(); + +private: + QString m_address; + QString m_gateway; + MethodType m_method; + QString m_mask; +}; + + +class Q_DECL_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(int prefixLength READ prefixLength WRITE setPrefixLength NOTIFY prefixLengthChanged) + +public: + explicit QNetworkSettingsIPv6(QObject *parent = 0) + : QObject(parent) + { + + } + + enum MethodType {Auto, Manual, Off}; + enum PrivacyType {Disabled, Enabled, Preferred}; + + QString address() const { + return m_address; + } + void setAddress(const QString& adderess) { + m_address = adderess; + emit addressChanged(); + } + + QString gateway() const { + return m_gateway; + } + + void setGateway(const QString& gateway) { + m_gateway = gateway; + emit gatewayChanged(); + } + + MethodType method() const { + return m_method; + } + + void setMethod(const MethodType method) { + m_method = method; + emit methodChanged(); + } + + PrivacyType privacy() const { + return m_privacy; + } + + void setPrivacy(const PrivacyType privacy) { + m_privacy = privacy; + emit privacyChanged(); + } + + int prefixLength() const { + return m_prefixLength; + } + + void setPrefixLength(const int& prefixLength) { + m_prefixLength = prefixLength; + emit prefixLengthChanged(); + } + +signals: + void addressChanged(); + void gatewayChanged(); + void methodChanged(); + void privacyChanged(); + void prefixLengthChanged(); + +private: + QString m_address; + QString m_gateway; + MethodType m_method; + PrivacyType m_privacy; + int m_prefixLength; +}; + +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) + { + + } + + enum MethodType {Direct, Auto, Manual}; + + QUrl url() const { + return m_url; + } + + void setUrl(const QUrl& url) { + m_url = url; + emit urlChanged(); + } + + QAbstractItemModel* servers(void) { + return &m_servers; + } + + void setServers(const QStringList& servers) { + m_servers.setStringList(servers); + 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); + emit excludesChanged(); + } + + MethodType method(void) const { + return m_method; + } + + void setMethod(const MethodType& method) { + m_method = method; + emit methodChanged(); + } + +signals: + void urlChanged(); + void serversChanged(); + void excludesChanged(); + void methodChanged(); +private: + QUrl m_url; + QNetworkSettingsAddressModel m_servers; + QNetworkSettingsAddressModel m_excludes; + MethodType m_method; +}; + +class Q_DECL_EXPORT QNetworkSettingsWireless : public QObject +{ + Q_OBJECT + 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 = 0) : + QObject(parent) { + } + + 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; + emit hiddenChanged(); + } + + int signalStrength() const { + return m_signalStrength; + } + + void setSignalStrength(const int signalStrength) { + m_signalStrength = signalStrength; + 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; + emit outOfRangeChanged(); + } + + bool outOfRange() const { + return m_isOutOfRange; + } + +signals: + void hiddenChanged(); + void signalStrengthChanged(); + void passwordChanged(); + void outOfRangeChanged(); +private: + quint16 m_securityFlags; + bool m_hidden; + int m_signalStrength; + bool m_isOutOfRange; +}; +#endif //QNETWORKSETTINGS_H diff --git a/src/networksettings/qnetworksettingsaddressmodel.cpp b/src/networksettings/qnetworksettingsaddressmodel.cpp new file mode 100644 index 0000000..b70278b --- /dev/null +++ b/src/networksettings/qnetworksettingsaddressmodel.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsaddressmodel.h" + +QNetworkSettingsAddressModel::QNetworkSettingsAddressModel(QObject *parent) + :QStringListModel(parent) +{ +} + +QNetworkSettingsAddressModel::QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent) + :QStringListModel(parent) +{ + setStringList(strings); +} + +void QNetworkSettingsAddressModel::setStringList(const QStringList &addresses) +{ + m_addresses = addresses; + QStringListModel::setStringList(m_addresses); + emit countChanged(); +} + +void QNetworkSettingsAddressModel::append(const QString& address) +{ + int row = rowCount(); + + bool succeed = insertRows(row, 1); + if (succeed) + succeed = setData(index(row), QVariant::fromValue(address)); + + Q_ASSERT(succeed == true); + + emit countChanged(); +} + +void QNetworkSettingsAddressModel::remove(int index) +{ + removeRows(index, 1); + emit countChanged(); +} + +int QNetworkSettingsAddressModel::count() const +{ + return rowCount(); +} + +void QNetworkSettingsAddressModel::resetChanges() +{ + QStringListModel::setStringList(m_addresses); +} diff --git a/src/networksettings/qnetworksettingsaddressmodel.h b/src/networksettings/qnetworksettingsaddressmodel.h new file mode 100644 index 0000000..429443a --- /dev/null +++ b/src/networksettings/qnetworksettingsaddressmodel.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSADDRESSMODEL_H +#define QNETWORKSETTINGSADDRESSMODEL_H + +#include <QStringListModel> + +class Q_DECL_EXPORT QNetworkSettingsAddressModel : public QStringListModel +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) +public: + explicit QNetworkSettingsAddressModel(QObject *parent = 0); + explicit QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent = 0); + Q_INVOKABLE void append(const QString& address); + Q_INVOKABLE void remove(int index); + Q_INVOKABLE void resetChanges(); + void setStringList(const QStringList &addresses); + int count() const; + +signals: + void countChanged(); +private: + QStringList m_addresses; +}; + +#endif // QNETWORKSETTINGSADDRESSMODEL_H diff --git a/src/networksettings/qnetworksettingsinterface.cpp b/src/networksettings/qnetworksettingsinterface.cpp new file mode 100644 index 0000000..893311a --- /dev/null +++ b/src/networksettings/qnetworksettingsinterface.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettings.h" + +QNetworkSettingsInterface::QNetworkSettingsInterface(QObject *parent) : + QObject(parent) + ,d_ptr(new QNetworkSettingsInterfacePrivate(this)) +{ + +} + +QString QNetworkSettingsInterface::name() const +{ + Q_D(const QNetworkSettingsInterface); + return d->m_name; +} + +QNetworkSettingsState::States QNetworkSettingsInterface::state() +{ + Q_D(QNetworkSettingsInterface); + return d->m_state.state(); +} + +QNetworkSettingsType::Types QNetworkSettingsInterface::type() +{ + Q_D(QNetworkSettingsInterface); + return d->m_type.type(); +} + +bool QNetworkSettingsInterface::powered() const +{ + Q_D(const QNetworkSettingsInterface); + return d->m_powered; +} + +void QNetworkSettingsInterface::setPowered(const bool powered) +{ + Q_D(QNetworkSettingsInterface); + d->setPowered(powered); +} + +void QNetworkSettingsInterface::scanServices() +{ + Q_D(QNetworkSettingsInterface); + d->scan(); +} diff --git a/src/networksettings/qnetworksettingsinterface.h b/src/networksettings/qnetworksettingsinterface.h new file mode 100644 index 0000000..cf52ae3 --- /dev/null +++ b/src/networksettings/qnetworksettingsinterface.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSETTINGSINTERFACE_H +#define QNETWORKSETTINGSINTERFACE_H + +#include <QObject> +#include "qnetworksettings.h" + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsInterfacePrivate) + +class Q_DECL_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(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) + +public: + explicit QNetworkSettingsInterface(QObject* parent=0); + QString name() const; + QNetworkSettingsState::States state(); + QNetworkSettingsType::Types type(); + bool powered() const; + void setPowered(const bool powered); + Q_INVOKABLE void scanServices(); + +signals: + void nameChanged(); + void stateChanged(); + void typeChanged(); + void poweredChanged(); + +protected: + friend class NetworksInterfaceModel; + QNetworkSettingsInterfacePrivate *d_ptr; + + Q_DISABLE_COPY(QNetworkSettingsInterface) + Q_DECLARE_PRIVATE(QNetworkSettingsInterface) +}; + +#endif // QNETWORKSETTINGSINTERFACE_H diff --git a/src/networksettings/qnetworksettingsinterfacemodel.cpp b/src/networksettings/qnetworksettingsinterfacemodel.cpp new file mode 100644 index 0000000..b25787d --- /dev/null +++ b/src/networksettings/qnetworksettingsinterfacemodel.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsinterface.h" + +QNetworkSettingsInterfaceModel::QNetworkSettingsInterfaceModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Type, "type"); + m_roleNames.insert(Status, "status"); + m_roleNames.insert(Name, "name"); +} + +QHash<int, QByteArray> QNetworkSettingsInterfaceModel::roleNames() const +{ + return m_roleNames; +} + + +int QNetworkSettingsInterfaceModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant QNetworkSettingsInterfaceModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + QNetworkSettingsInterface *item = m_items[index.row()]; + if (role == Qt::UserRole) { + return QVariant::fromValue(static_cast<QObject*>(item)); + } + + switch (role) { + case Type: + return item->type(); + break; + case Name: + return item->name(); + break; + case Status: + return item->state(); + break; + default: + return QStringLiteral(""); + } + +} + +void QNetworkSettingsInterfaceModel::append(QNetworkSettingsInterface* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_items.append(item); + endInsertRows(); +} + +void QNetworkSettingsInterfaceModel::insert(int row, QNetworkSettingsInterface* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), row, row); + m_items.insert(row, item); + endInsertRows(); +} + +void QNetworkSettingsInterfaceModel::remove(int row) +{ + beginRemoveRows(QModelIndex(), row, row); + m_items.removeFirst(); + endRemoveRows(); +} + +QList<QNetworkSettingsInterface*> QNetworkSettingsInterfaceModel::getModel() +{ + return m_items; +} diff --git a/src/networksettings/qnetworksettingsinterfacemodel.h b/src/networksettings/qnetworksettingsinterfacemodel.h new file mode 100644 index 0000000..fb7be45 --- /dev/null +++ b/src/networksettings/qnetworksettingsinterfacemodel.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEMODEL_H +#define QNETWORKSETTINGSINTERFACEMODEL_H + +#include <QAbstractListModel> +#include "qnetworksettings.h" + +class QNetworkSettingsInterface; + +class Q_DECL_EXPORT QNetworkSettingsInterfaceModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit QNetworkSettingsInterfaceModel(QObject *parent=0); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + void append(QNetworkSettingsInterface* networkInterface); + void insert(int row, QNetworkSettingsInterface* networkInterface); + void remove(int row); + QList<QNetworkSettingsInterface*> getModel(); + + enum Roles { + Type = Qt::UserRole + 1, + Status, + Name + }; + +private: + QList<QNetworkSettingsInterface*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +#endif // QNETWORKSETTINGSINTERFACEMODEL_H diff --git a/src/networksettings/qnetworksettingsmanager.cpp b/src/networksettings/qnetworksettingsmanager.cpp new file mode 100644 index 0000000..095d1a0 --- /dev/null +++ b/src/networksettings/qnetworksettingsmanager.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsservice.h" +#include "qnetworksettingsservicemodel.h" +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsmanager_p.h" +#include <QStringListModel> + +QNetworkSettingsManager::QNetworkSettingsManager(QObject *parent) : + QObject(parent) + ,d_ptr(new QNetworkSettingsManagerPrivate(this)) +{ +} + +QAbstractItemModel* QNetworkSettingsManager::services() +{ + Q_D(QNetworkSettingsManager); + return d->m_serviceFilter; +} + +QAbstractItemModel* QNetworkSettingsManager::interfaces() +{ + Q_D(QNetworkSettingsManager); + return &d->m_interfaceModel; +} + +QNetworkSettingsService* QNetworkSettingsManager::getService(const QString& name, const int type) +{ + Q_D(QNetworkSettingsManager); + + foreach (QNetworkSettingsService* service, d->m_serviceModel->getModel()) { + if (service->name() == name && service->type() == type) { + return service; + } + } + return NULL; +} + +void QNetworkSettingsManager::setUserAgent(QNetworkSettingsUserAgent *agent) +{ + Q_D(QNetworkSettingsManager); + d->setUserAgent(agent); +} diff --git a/src/networksettings/qnetworksettingsmanager.h b/src/networksettings/qnetworksettingsmanager.h new file mode 100644 index 0000000..00980f4 --- /dev/null +++ b/src/networksettings/qnetworksettingsmanager.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGER_H +#define QNETWORKSETTINGSMANAGER_H + +#include "qnetworksettings.h" +#include <QObject> +#include <QStringListModel> + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsManagerPrivate) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsService) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsUserAgent) + +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) +public: + explicit QNetworkSettingsManager(QObject* parent = 0); + QAbstractItemModel* services(); + QAbstractItemModel* interfaces(); + void setUserAgent(QNetworkSettingsUserAgent *agent); + + Q_INVOKABLE QNetworkSettingsService* getService(const QString& name, const int type); + +Q_SIGNALS: + void servicesChanged(); + void interfacesChanged(); + +protected: + QNetworkSettingsManagerPrivate *d_ptr; + +private: + Q_DISABLE_COPY(QNetworkSettingsManager) + Q_DECLARE_PRIVATE(QNetworkSettingsManager) +}; + +#endif // QNETWORKSETTINGSMANAGER_H diff --git a/src/networksettings/qnetworksettingsservice.cpp b/src/networksettings/qnetworksettingsservice.cpp new file mode 100644 index 0000000..727c929 --- /dev/null +++ b/src/networksettings/qnetworksettingsservice.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworksettingsservice.h" +#include "qnetworksettingsservice_p.h" + +QNetworkSettingsService::QNetworkSettingsService(const QString& aServiceId, QObject* parent) : + QObject(parent) + ,d_ptr(new QNetworkSettingsServicePrivate(aServiceId, this)) +{ + +} + +QString QNetworkSettingsService::id() const +{ + Q_D(const QNetworkSettingsService); + return d->m_id; +} + +QString QNetworkSettingsService::name() const +{ + Q_D(const QNetworkSettingsService); + return d->m_name; +} + +void QNetworkSettingsService::setAutoConnect(const bool autoconnect) +{ + Q_UNUSED(autoconnect); +} + +QNetworkSettingsState::States QNetworkSettingsService::state() +{ + Q_D(QNetworkSettingsService); + return d->m_state.state(); +} + +QNetworkSettingsType::Types QNetworkSettingsService::type() +{ + Q_D(QNetworkSettingsService); + return d->m_type.type(); +} + +QNetworkSettingsIPv4* QNetworkSettingsService::ipv4() +{ + Q_D(QNetworkSettingsService); + return &d->m_ipv4config; +} + +QNetworkSettingsIPv6* QNetworkSettingsService::ipv6() +{ + Q_D(QNetworkSettingsService); + return &d->m_ipv6config; +} + +QNetworkSettingsProxy* QNetworkSettingsService::proxy() +{ + Q_D(QNetworkSettingsService); + return &d->m_proxyConfig; +} + +QNetworkSettingsWireless* QNetworkSettingsService::wirelessConfig() +{ + Q_D(QNetworkSettingsService); + return &d->m_wifiConfig; +} + +QAbstractItemModel* QNetworkSettingsService::domains() +{ + Q_D(QNetworkSettingsService); + return &d->m_domainsConfig; +} + +QAbstractItemModel* QNetworkSettingsService::nameservers() +{ + Q_D(QNetworkSettingsService); + return &d->m_nameserverConfig; +} + +void QNetworkSettingsService::setupIpv4Config() +{ + Q_D(QNetworkSettingsService); + d->setupIpv4Config(); +} + +void QNetworkSettingsService::setupIpv6Config() +{ + Q_D(QNetworkSettingsService); + d->setupIpv6Config(); +} + +void QNetworkSettingsService::setupNameserversConfig() +{ + Q_D(QNetworkSettingsService); + d->setupNameserversConfig(); +} + +void QNetworkSettingsService::setupDomainsConfig() +{ + Q_D(QNetworkSettingsService); + d->setupDomainsConfig(); +} + +void QNetworkSettingsService::setupNetworkSettingsProxy() +{ + Q_D(QNetworkSettingsService); + d->setupQNetworkSettingsProxy(); +} + +void QNetworkSettingsService::connectService() +{ + Q_D(QNetworkSettingsService); + d->connectService(); +} + +void QNetworkSettingsService::disconnectService() +{ + Q_D(QNetworkSettingsService); + d->disconnectService(); +} diff --git a/src/networksettings/qnetworksettingsservice.h b/src/networksettings/qnetworksettingsservice.h new file mode 100644 index 0000000..aa0be2c --- /dev/null +++ b/src/networksettings/qnetworksettingsservice.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICE_H +#define QNETWORKSETTINGSSERVICE_H + +#include <QObject> +#include "qnetworksettings.h" + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServicePrivate) + +class Q_DECL_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(QNetworkSettingsIPv4* ipv4 READ ipv4 NOTIFY ipv4Changed) + Q_PROPERTY(QNetworkSettingsIPv6* ipv6 READ ipv6 NOTIFY ipv6Changed) + Q_PROPERTY(QNetworkSettingsProxy* proxy READ proxy NOTIFY proxyChanged) + Q_PROPERTY(QNetworkSettingsWireless* wirelessConfig READ wirelessConfig NOTIFY wirelessChanged) + Q_PROPERTY(QAbstractItemModel* domains READ domains NOTIFY domainsChanged) + Q_PROPERTY(QAbstractItemModel* nameservers READ nameservers NOTIFY nameserversChanged) +public: + explicit QNetworkSettingsService(const QString& aServiceId, QObject* parent = 0); + + QString id() const; + QString name() const; + QNetworkSettingsState::States state(); + QNetworkSettingsType::Types type(); + QNetworkSettingsIPv4* ipv4(); + QNetworkSettingsIPv6* ipv6(); + QNetworkSettingsProxy* proxy(); + QAbstractItemModel* domains(); + QAbstractItemModel* nameservers(); + QNetworkSettingsWireless* wirelessConfig(); + + Q_INVOKABLE void setAutoConnect(const bool autoconnect); + Q_INVOKABLE void setupIpv4Config(); + Q_INVOKABLE void setupIpv6Config(); + Q_INVOKABLE void setupNameserversConfig(); + Q_INVOKABLE void setupDomainsConfig(); + Q_INVOKABLE void setupNetworkSettingsProxy(); + //Wireless config + Q_INVOKABLE void connectService(); + Q_INVOKABLE void disconnectService(); +Q_SIGNALS: + void nameChanged(); + void stateChanged(); + void typeChanged(); + void proxyChanged(); + void ipv4Changed(); + void ipv6Changed(); + void domainsChanged(); + void nameserversChanged(); + void wirelessChanged(); + void showCrendentialInput(); +protected: + QNetworkSettingsServicePrivate *d_ptr; + + Q_DISABLE_COPY(QNetworkSettingsService) + Q_DECLARE_PRIVATE(QNetworkSettingsService) +}; + +#endif // QNETWORKSETTINGSSERVICE_H diff --git a/src/networksettings/qnetworksettingsservicemodel.cpp b/src/networksettings/qnetworksettingsservicemodel.cpp new file mode 100644 index 0000000..af84a3e --- /dev/null +++ b/src/networksettings/qnetworksettingsservicemodel.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservicemodel.h" +#include "qnetworksettings.h" + +QNetworkSettingsServiceModel::QNetworkSettingsServiceModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(SignalStrength, "signalStrength"); + m_roleNames.insert(Connected, "connected"); +} + +QNetworkSettingsServiceModel::~QNetworkSettingsServiceModel() +{ + +} + +QHash<int, QByteArray> QNetworkSettingsServiceModel::roleNames() const +{ + return m_roleNames; +} + + +int QNetworkSettingsServiceModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant QNetworkSettingsServiceModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + QNetworkSettingsService *item = m_items[index.row()]; + if (role == Qt::UserRole) { + return QVariant::fromValue(static_cast<QObject*>(item)); + } + else if (role == Name) { + return item->name(); + } + else if (role == SignalStrength) { + return item->wirelessConfig()->signalStrength(); + } + else if (role == Connected) { + return item->state() == QNetworkSettingsState::Online || item->state() == QNetworkSettingsState::Ready; + } + return QVariant(); +} + +void QNetworkSettingsServiceModel::append(QNetworkSettingsService* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_items.append(item); + endInsertRows(); +} + +void QNetworkSettingsServiceModel::insert(int row, QNetworkSettingsService* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), row, row); + m_items.insert(row, item); + endInsertRows(); +} + +void QNetworkSettingsServiceModel::remove(int row) +{ + beginRemoveRows(QModelIndex(), row, row); + m_items.removeAt(row); + endRemoveRows(); +} + +void QNetworkSettingsServiceModel::updated(int row) +{ + dataChanged(createIndex(row, 0), createIndex(row, 0)); +} + +QList<QNetworkSettingsService*> QNetworkSettingsServiceModel::getModel() +{ + return m_items; +} + +//Filter model + +QNetworkSettingsServiceFilter::QNetworkSettingsServiceFilter(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &QNetworkSettingsServiceFilter::typeChanged, this, &QNetworkSettingsServiceFilter::invalidate); +} + +QNetworkSettingsServiceFilter::~QNetworkSettingsServiceFilter() +{ + +} + +QNetworkSettingsType::Types QNetworkSettingsServiceFilter::type() const +{ + return m_type; +} + +void QNetworkSettingsServiceFilter::setType(const QNetworkSettingsType::Types type) +{ + m_type = type; + emit typeChanged(); +} + +bool QNetworkSettingsServiceFilter::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + if (index.isValid()) + { + QObject * obj = qvariant_cast<QObject *>(index.data(Qt::UserRole)); + QNetworkSettingsService * service = qobject_cast<QNetworkSettingsService *>(obj); + if (service->type() == m_type) + return true; + } + } + } + return false; +} + +QVariant QNetworkSettingsServiceFilter::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant serviceItem = mapped.data(Qt::UserRole); + if (serviceItem.isValid()) + { + return serviceItem; + } + } + return QVariant::fromValue(QStringLiteral("")); +} + diff --git a/src/networksettings/qnetworksettingsservicemodel.h b/src/networksettings/qnetworksettingsservicemodel.h new file mode 100644 index 0000000..566018d --- /dev/null +++ b/src/networksettings/qnetworksettingsservicemodel.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEMODEL_H +#define QNETWORKSETTINGSSERVICEMODEL_H + +#include <QSortFilterProxyModel> +#include "qnetworksettings.h" +#include "qnetworksettingsservice.h" + +class Q_DECL_EXPORT QNetworkSettingsServiceModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit QNetworkSettingsServiceModel(QObject *parent=0); + virtual ~QNetworkSettingsServiceModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + void append(QNetworkSettingsService* networkService); + void insert(int row, QNetworkSettingsService* networkInterface); + void remove(int row); + void updated(int row); + QList<QNetworkSettingsService*> getModel(); + + enum Roles { + Type = Qt::UserRole + 1, + Name, + SignalStrength, + Connected + }; + +private: + QList<QNetworkSettingsService*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +class QNetworkSettingsServiceFilter : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QNetworkSettingsType::Types type READ type WRITE setType NOTIFY typeChanged) +public: + explicit QNetworkSettingsServiceFilter(QObject* parent=0); + 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; +signals: + void typeChanged(); +private: + QNetworkSettingsType::Types m_type; +}; + +#endif // QNETWORKSETTINGSSERVICEMODEL_H diff --git a/src/networksettings/qnetworksettingsuseragent.cpp b/src/networksettings/qnetworksettingsuseragent.cpp new file mode 100644 index 0000000..f1b0590 --- /dev/null +++ b/src/networksettings/qnetworksettingsuseragent.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent.h" +#include "qnetworksettingsuseragent_p.h" + +QNetworkSettingsUserAgent::QNetworkSettingsUserAgent(QObject *parent) + :QObject(parent) + ,d_ptr(new QNetworkSettingsUserAgentPrivate(this)) +{ +} + +void QNetworkSettingsUserAgent::setUserCredentials(const QString& username, const QString& passphrase) +{ + Q_D(QNetworkSettingsUserAgent); + d->setUserCredentials(username, passphrase); +} + +void QNetworkSettingsUserAgent::cancelInput() +{ + Q_D(QNetworkSettingsUserAgent); + d->cancel(); +} + +QString QNetworkSettingsUserAgent::passPhrase() const +{ + Q_D(const QNetworkSettingsUserAgent); + return d->m_passphrase; +} + +QString QNetworkSettingsUserAgent::userName() const +{ + Q_D(const QNetworkSettingsUserAgent); + return d->m_username; +} diff --git a/src/networksettings/qnetworksettingsuseragent.h b/src/networksettings/qnetworksettingsuseragent.h new file mode 100644 index 0000000..c0e0b2f --- /dev/null +++ b/src/networksettings/qnetworksettingsuseragent.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENT_H +#define QNETWORKSETTINGSUSERAGENT_H + +#include <QObject> + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsUserAgentPrivate) + +class Q_DECL_EXPORT QNetworkSettingsUserAgent : public QObject +{ + Q_OBJECT +public: + explicit QNetworkSettingsUserAgent(QObject *parent = 0); + Q_INVOKABLE void setUserCredentials(const QString& username, const QString& passphrase); + Q_INVOKABLE void cancelInput(); + QString passPhrase() const; + QString userName() const; + +signals: + void showUserCredentialsInput(); + void error(); + void ready(bool cancel); +private: + QNetworkSettingsUserAgentPrivate *d_ptr; + + Q_DISABLE_COPY(QNetworkSettingsUserAgent) + Q_DECLARE_PRIVATE(QNetworkSettingsUserAgent) +}; +#endif // QNETWORKSETTINGSUSERAGENT_H diff --git a/src/networksettings/wpasupplicant.pri b/src/networksettings/wpasupplicant.pri new file mode 100644 index 0000000..db89315 --- /dev/null +++ b/src/networksettings/wpasupplicant.pri @@ -0,0 +1,28 @@ +QT += core network + +INCLUDEPATH += $${PWD}/wpasupplicant + +HEADERS += \ + $$PWD/wpasupplicant/qnetworksettingsinterface_p.h \ + $$PWD/wpasupplicant/qnetworksettingsmanager_p.h \ + $$PWD/wpasupplicant/qwifisupplicant_p.h \ + $$PWD/wpasupplicant/qwificontroller_p.h \ + $$PWD/wpasupplicant/qnetworksettingsservice_p.h \ + $$PWD/wpasupplicant/qnetworksettingsuseragent_p.h \ + $$PWD/wpasupplicant/qwifidevice.h + +SOURCES += \ + $$PWD/wpasupplicant/qnetworksettingsinterface_p.cpp \ + $$PWD/wpasupplicant/qnetworksettingsmanager_p.cpp \ + $$[QT_SYSROOT]/usr/include/wpa-supplicant/wpa_ctrl.c \ + $$[QT_SYSROOT]/usr/include/wpa-supplicant/os_unix.c \ + $$PWD/wpasupplicant/qwifisupplicant.cpp \ + $$PWD/wpasupplicant/qwificontroller.cpp \ + $$PWD/wpasupplicant/qnetworksettingsservice_p.cpp \ + $$PWD/wpasupplicant/qnetworksettingsuseragent_p.cpp \ + $$PWD/wpasupplicant/qwifidevice.cpp + +DEFINES += \ + CONFIG_CTRL_IFACE \ + CONFIG_CTRL_IFACE_UNIX + diff --git a/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.cpp new file mode 100644 index 0000000..7370421 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.cpp @@ -0,0 +1,71 @@ + +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsmanager_p.h" +#include "qwifidevice.h" + +QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) + :QObject(parent) + ,q_ptr(parent) +{ + m_name = QWifiDevice::wifiInterfaceName(); + m_type.setType(QNetworkSettingsType::Wifi); + m_powered = true; //We don't really know +} + +void QNetworkSettingsInterfacePrivate::setManager(QNetworkSettingsManagerPrivate *manager) +{ + m_manager = manager; +} + +void QNetworkSettingsInterfacePrivate::setPowered(const bool power) +{ + //Not supported + Q_UNUSED(power); +} + +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +{ + Q_Q(QNetworkSettingsInterface); + m_state.setState(aState); + emit q->stateChanged(); +} + +void QNetworkSettingsInterfacePrivate::scan() +{ + m_manager->call(QStringLiteral("SCAN")); +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.h b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.h new file mode 100644 index 0000000..d8964c3 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEPRIVATE_H +#define QNETWORKSETTINGSINTERFACEPRIVATE_H + +#include <QObject> +#include "qnetworksettings.h" +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsmanager_p.h" + +class QNetworkSettingsInterfacePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsInterface) +public: + explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); + void initialize(const QString& path, const QVariantMap& properties); + void setPowered(const bool power); + void setState(QNetworkSettingsState::States aState); + void setManager(QNetworkSettingsManagerPrivate *manager); + void scan(); + +signals: + +protected: + QString m_name; + QNetworkSettingsType m_type; + QNetworkSettingsState m_state; + bool m_powered; + QNetworkSettingsManagerPrivate *m_manager; //not owned + QNetworkSettingsInterface *q_ptr; +}; + +class WpaSupplicantSettingsInterface : public QNetworkSettingsInterface +{ + Q_OBJECT +public: + WpaSupplicantSettingsInterface(QNetworkSettingsManagerPrivate* manager) + :QNetworkSettingsInterface(manager) + { + Q_D(QNetworkSettingsInterface); + d->setManager(manager); + } + + void setState(QNetworkSettingsState::States aState) { + Q_D(QNetworkSettingsInterface); + d->setState(aState); + } + + virtual ~WpaSupplicantSettingsInterface() { + } +}; + +#endif // QNETWORKSETTINGSINTERFACEPRIVATE_H + diff --git a/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.cpp new file mode 100644 index 0000000..17a1f2f --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.cpp @@ -0,0 +1,433 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QProcess> +#include "qnetworksettingsmanager_p.h" +#include "qwificontroller_p.h" +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsservice_p.h" +#include "qnetworksettingsuseragent.h" +#include "qwifisupplicant_p.h" + +QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent) + :QObject(parent) + ,q_ptr(parent) +{ + m_serviceFilter.setSourceModel(&m_serviceModel); + m_wifiController = new QWifiController(this); + m_wifiController->asyncCall(QWifiController::InitializeBackend); + + QObject::connect(m_wifiController, &QWifiController::backendStateChanged, + this, &QNetworkSettingsManagerPrivate::handleBackendStateChanged); + QObject::connect(m_wifiController, &QWifiController::dhcpRequestFinished, + this, &QNetworkSettingsManagerPrivate::handleDhcpRequestFinished); + + QObject::connect(m_wifiController, &QWifiController::raiseError, this, &QNetworkSettingsManagerPrivate::updateLastError); + m_wifiController->start(); + + updateWifiState(); +} + +QNetworkSettingsManagerPrivate::~QNetworkSettingsManagerPrivate() +{ + m_wifiController->asyncCall(QWifiController::ExitEventLoop); + m_wifiController->wait(); + delete m_wifiController; +} + +bool QNetworkSettingsManagerPrivate::event(QEvent *event) +{ + switch ((int) event->type()) { + case WIFI_SCAN_RESULTS: + parseScanResults(call(QStringLiteral("SCAN_RESULTS"))); + return true; + case WIFI_CONNECTED: + handleConnected(); + return true; + case WIFI_DISCONNECTED: + handleDisconneced(); + return true; + case WIFI_AUTHENTICATING: + handleAuthenticating(static_cast<QWifiEvent *>(event)); + return true; + case WIFI_HANDSHAKE_FAILED: + updateNetworkState(QNetworkSettingsState::Failure); + return true; + } + return QObject::event(event); +} + +void QNetworkSettingsManagerPrivate::connectNetwork(const QString& ssid) +{ + if (m_backendState != QWifiController::Running) { + qCWarning(B2QT_WIFI) << "start wifi backend before calling connect()"; + return; + } + + call(QStringLiteral("DISABLE_NETWORK all")); + m_currentSSID = ssid; + emit m_agent->showUserCredentialsInput(); +} + +void QNetworkSettingsManagerPrivate::userInteractionReady(bool cancel) +{ + if (cancel) { + m_currentSSID = ""; + return; + } + bool networkKnown = false; + QString id; + const QStringList configuredNetworks = call(QStringLiteral("LIST_NETWORKS")).split('\n'); + for (int i = 1; i < configuredNetworks.length(); ++i) { + const QStringList networkFields = configuredNetworks.at(i).split('\t'); + const QString ssid = QWifiSupplicant::decodeSsid(networkFields.at(1)); + if (ssid == m_currentSSID) { + id = networkFields.at(0); + networkKnown = true; + break; + } + } + + if (!networkKnown) { + bool ok; + id = call(QStringLiteral("ADD_NETWORK")); + id.toInt(&ok); + if (!ok) { + updateLastError(QStringLiteral("failed to add network")); + return; + } + } + + bool ok = true; + QChar q = QLatin1Char('"'); + QString setNetworkCommand = QLatin1String("SET_NETWORK ") + id; + if (!networkKnown) { + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" ssid ") + q + m_currentSSID + q); + } + + QString key_mgmt; + WpaSupplicantService *service = networkForSSID(m_currentSSID); + if (!service) { + return; + } + QString psk = m_agent->passPhrase(); + + // --------------------- configure network ------------------------------ + // ref: http://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf + // ref: https://www.freebsd.org/cgi/man.cgi?wpa_supplicant.conf + // ---------------------------------------------------------------------- + if (service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::WPA) || + service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::WPA2)) { + // ### TODO - password length has limits (see IEEE 802.11), we need to check + // for those limits here. Supplicant gives only a meaningless "fail" message. + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" psk ") + q + psk + q); + key_mgmt = QLatin1String("WPA-PSK"); + } else if (service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::WEP)) { + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" wep_key0 ") + q + psk + q); + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" auth_alg OPEN SHARED")); + key_mgmt = QLatin1String("NONE"); + } else if (service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::None)) { + // open network + key_mgmt = QLatin1String("NONE"); + } + + if (service->wirelessConfig()->hidden()) + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" scan_ssid 1")); + + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" key_mgmt ") + key_mgmt); + if (!ok) { + if (!networkKnown) + call(QLatin1String("REMOVE_NETWORK ") + id); + updateLastError(QLatin1String("failed to set properties on network: ") + id); + return; + } + + call(QLatin1String("SELECT_NETWORK ") + id); + call(QStringLiteral("RECONNECT")); +} + +void QNetworkSettingsManagerPrivate::disconnectNetwork() +{ + call(QStringLiteral("DISCONNECT")); + m_wifiController->asyncCall(QWifiController::StopDhcp); +} + +void QNetworkSettingsManagerPrivate::handleBackendStateChanged(QWifiController::BackendState backendState) +{ + switch (backendState) { + case QWifiController::NotRunning: + updateNetworkState(QNetworkSettingsState::Disconnect); + break; + default: + break; + } + updateBackendState(backendState); +} + +void QNetworkSettingsManagerPrivate::handleDhcpRequestFinished(const QString &status) +{ + qCDebug(B2QT_WIFI) << "handleDhcpRequestFinished: " << status << " for " << m_currentSSID; + if (status == QLatin1String("success")) { + updateNetworkState(QNetworkSettingsState::Online); + call(QStringLiteral("SAVE_CONFIG")); + } else { + updateNetworkState(QNetworkSettingsState::Failure); + } +} + +void QNetworkSettingsManagerPrivate::setUserAgent(QNetworkSettingsUserAgent *agent) +{ + m_agent = agent; + connect(m_agent, &QNetworkSettingsUserAgent::ready, this, &QNetworkSettingsManagerPrivate::userInteractionReady); +} + +void QNetworkSettingsManagerPrivate::setCurrentSSID(const QString &ssid) +{ + qCDebug(B2QT_WIFI) << "current SSID: " << m_currentSSID << " -> " << ssid; + if (m_currentSSID == ssid) + return; + + m_currentSSID = ssid; +} + +void QNetworkSettingsManagerPrivate::handleAuthenticating(QWifiEvent *event) +{ + QString data = event->data().trimmed(); + QString ssid = data.mid(data.indexOf(QLatin1String("SSID")) + 6); + ssid = ssid.left(ssid.lastIndexOf(QLatin1Char('\''))); + + setCurrentSSID(QWifiSupplicant::decodeSsid(ssid)); + updateNetworkState(QNetworkSettingsState::Association); +} + +void QNetworkSettingsManagerPrivate::handleConnected() +{ + qCDebug(B2QT_WIFI) << "connected network: " << m_currentSSID; + updateNetworkState(QNetworkSettingsState::Ready); + m_wifiController->asyncCall(QWifiController::AcquireIPAddress); +} + +void QNetworkSettingsManagerPrivate::handleDisconneced() +{ + updateNetworkState(QNetworkSettingsState::Disconnect); +} + +void QNetworkSettingsManagerPrivate::updateNetworkState(QNetworkSettingsState::States networkState) +{ + //Update interface + if (!m_interfaceModel.getModel().isEmpty()) { + WpaSupplicantSettingsInterface* interface = qobject_cast<WpaSupplicantSettingsInterface*>(m_interfaceModel.getModel().first()); + if (interface && interface->state() != networkState) { + interface->setState(networkState); + } + } + + //Update service state + WpaSupplicantService *service = networkForSSID(m_currentSSID); + if (service) { + service->setState(networkState); + } +} + +void QNetworkSettingsManagerPrivate::updateBackendState(QWifiController::BackendState backendState) +{ + if (m_backendState == backendState) + return; + + m_backendState = backendState; + + if (m_backendState == QWifiController::Running && m_interfaceModel.getModel().isEmpty()) { + WpaSupplicantSettingsInterface *interface = new WpaSupplicantSettingsInterface(this); + m_interfaceModel.append(interface); + } else if (m_backendState == QWifiController::NotRunning && m_interfaceModel.getModel().size() > 0){ + m_interfaceModel.remove(0); + } +} + +void QNetworkSettingsManagerPrivate::updateWifiState() +{ + QProcess ps; + ps.start(QStringLiteral("ps")); + if (!ps.waitForStarted()) { + updateLastError(ps.program() + QLatin1String(": ") + ps.errorString()); + return; + } + + ps.waitForFinished(); + bool supplicantRunning = ps.readAll().contains("wpa_supplicant"); + if (supplicantRunning && m_wifiController->resetSupplicantSocket()) + m_backendState = QWifiController::Running; +} + +QString QNetworkSettingsManagerPrivate::call(const QString &command) +{ + if (m_backendState != QWifiController::Running) + return QString(); + + QByteArray reply; + bool success = m_wifiController->supplicant()->sendCommand(command, &reply); + if (!success) { + qCDebug(B2QT_WIFI) << "call to supplicant failed"; + return QString(); + } + + return QLatin1String(reply.trimmed()); +} + +bool QNetworkSettingsManagerPrivate::checkedCall(const QString &command) +{ + return call(command).toUpper() == QLatin1String("OK"); +} + +void QNetworkSettingsManagerPrivate::updateLastError(const QString &error) +{ + qCWarning(B2QT_WIFI) << error; + if (!m_interfaceModel.getModel().isEmpty()) { + WpaSupplicantSettingsInterface* interface = qobject_cast<WpaSupplicantSettingsInterface*>(m_interfaceModel.getModel().first()); + if (interface) { + interface->setState(QNetworkSettingsState::Failure); + } + } +} + +WpaSupplicantService* QNetworkSettingsManagerPrivate::networkForSSID(const QString& ssid) +{ + int pos = 0; + return networkForSSID(ssid, pos); +} + +WpaSupplicantService* QNetworkSettingsManagerPrivate::networkForSSID(const QString& ssid, int& pos) +{ + QList<QNetworkSettingsService*> services = m_serviceModel.getModel(); + pos = 0; + foreach (QNetworkSettingsService *service, services) { + if (service->name() == ssid) { + return qobject_cast<WpaSupplicantService*>(service); + } + pos++; + } + pos = -1; + return NULL; +} + +WpaSupplicantService* QNetworkSettingsManagerPrivate::outOfRangeListContains(const QString& ssid) +{ + QList<QNetworkSettingsService*> services = m_outOfRangeServiceModel.getModel(); + foreach (QNetworkSettingsService *service, services) { + if (service->name() == ssid) { + return qobject_cast<WpaSupplicantService*>(service); + } + } + return NULL; +} + +void QNetworkSettingsManagerPrivate::parseScanResults(const QString &results) +{ + QStringList lines = results.split('\n'); + QSet<QString> sensibleNetworks; + + for (int i = 1; i < lines.size(); ++i) { + QStringList info = lines.at(i).split('\t'); + if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) + continue; + int pos = 0; + + QString ssid = QWifiSupplicant::decodeSsid(info.at(4)); + if (ssid.isEmpty()) + continue; + + sensibleNetworks.insert(ssid); + WpaSupplicantService *knownNetwork = networkForSSID(ssid, pos); + + if (!knownNetwork) { + knownNetwork = outOfRangeListContains(ssid); + m_outOfRangeServiceModel.getModel().removeOne(knownNetwork); + } + + int signalStrength = info.at(2).trimmed().toInt(); + if (signalStrength < 0) { + // signal is reported in dBm, rough conversion: best = -40, worst = -100 + int val = qAbs(qMax(-100, qMin(signalStrength, -40)) + 40); // clamp and normalize to 0 + signalStrength = 100 - (int) ((100.0 * (double) val) / 60.0); + } else if (signalStrength > 100) { + qCWarning(B2QT_WIFI) << "unexpected value for a signal level: " << signalStrength; + } + + if (!knownNetwork) { + WpaSupplicantService *network = new WpaSupplicantService(this); + network->setId(info.at(0)); + network->setFlags(info.at(3)); + network->wirelessConfig()->setSignalStrength(signalStrength); + network->setName(ssid); + m_serviceModel.append(network); + } else { + if (knownNetwork->wirelessConfig()->outOfRange()) { + // known network has come back into a range + knownNetwork->wirelessConfig()->setOutOfRange(false); + m_serviceModel.append(knownNetwork); + pos = m_serviceModel.getModel().size() - 1; + } + // ssids are the same, compare bssids.. + if (knownNetwork->id() == info.at(0)) { + // same access point, simply update the signal strength + knownNetwork->wirelessConfig()->setSignalStrength(signalStrength); + knownNetwork->wirelessConfig()->setOutOfRange(false); + m_serviceModel.updated(pos); + } else if (knownNetwork->wirelessConfig()->signalStrength() < signalStrength) { + // replace with a stronger access point within the same network + knownNetwork->wirelessConfig()->setOutOfRange(false); + knownNetwork->setId(info.at(0)); + knownNetwork->setFlags(info.at(3)); + knownNetwork->wirelessConfig()->setSignalStrength(signalStrength); + knownNetwork->setName(ssid); + m_serviceModel.updated(pos); + } + } + } + // remove out-of-range networks from the data model + QList<QNetworkSettingsService*> networks; + for (int i = 0; i < networks.size();) { + if (!sensibleNetworks.contains(networks.at(i)->name())) { + WpaSupplicantService *n = qobject_cast<WpaSupplicantService*>(networks.at(i)); + m_serviceModel.remove(i); + if (n) { + n->wirelessConfig()->setOutOfRange(true); + m_outOfRangeServiceModel.append(n); + } + } else { + ++i; + } + } +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h new file mode 100644 index 0000000..fa20fb4 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGERPRIVATE_H +#define QNETWORKSETTINGSMANAGERPRIVATE_H + +#include <QObject> +#include "qnetworksettings.h" +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsservicemodel.h" +#include "qwificontroller_p.h" + +class WpaSupplicantService; + +class QNetworkSettingsManagerPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsManager) +public: + explicit QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent); + virtual ~QNetworkSettingsManagerPrivate(); + QNetworkSettingsManager *q_ptr; + void setUserAgent(QNetworkSettingsUserAgent *agent); + void connectNetwork(const QString& ssid); + void disconnectNetwork(); + QString call(const QString &command); + bool checkedCall(const QString &command); +protected: + bool event(QEvent *event); + +private slots: + void handleBackendStateChanged(QWifiController::BackendState backendState); + void handleDhcpRequestFinished(const QString &status); + void userInteractionReady(bool cancel); + void updateLastError(const QString &error); +private: + void setCurrentSSID(const QString &ssid); + void handleConnected(); + void handleDisconneced(); + void handleAuthenticating(QWifiEvent *event); + void updateNetworkState(QNetworkSettingsState::States networkState); + void updateBackendState(QWifiController::BackendState backendState); + void updateWifiState(); + void parseScanResults(const QString &results); + WpaSupplicantService* networkForSSID(const QString& ssid); + WpaSupplicantService* networkForSSID(const QString& ssid, int& pos); + WpaSupplicantService* outOfRangeListContains(const QString& ssid); + + QNetworkSettingsInterfaceModel m_interfaceModel; + QNetworkSettingsServiceModel m_serviceModel; + QNetworkSettingsServiceModel m_outOfRangeServiceModel; + QNetworkSettingsServiceFilter m_serviceFilter; + QWifiController *m_wifiController; + QNetworkSettingsUserAgent *m_agent; //Not owned + + QWifiController::BackendState m_backendState; + QString m_currentSSID; +}; + + +#endif // QNETWORKSETTINGSMANAGERPRIVATE_H diff --git a/src/networksettings/wpasupplicant/qnetworksettingsservice_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.cpp new file mode 100644 index 0000000..b5d4545 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservice_p.h" +#include "qnetworksettingsmanager_p.h" + +QNetworkSettingsServicePrivate::QNetworkSettingsServicePrivate(const QString& bssid, QNetworkSettingsService *parent) : + QObject(parent) + ,q_ptr(parent) + ,m_id(bssid) +{ + m_type.setType(QNetworkSettingsType::Wifi); +} + +void QNetworkSettingsServicePrivate::setManager(QNetworkSettingsManagerPrivate *manager) +{ + m_manager = manager; +} + +void QNetworkSettingsServicePrivate::connectService() +{ + m_manager->connectNetwork(m_name); +} + +void QNetworkSettingsServicePrivate::disconnectService() +{ + m_manager->disconnectNetwork(); +} + +void QNetworkSettingsServicePrivate::setupIpv6Config() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupNameserversConfig() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupDomainsConfig() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupQNetworkSettingsProxy() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupIpv4Config() +{ + //Not supported +} + +WpaSupplicantService::WpaSupplicantService(QNetworkSettingsManagerPrivate* manager, QObject* parent) + :QNetworkSettingsService("", parent) +{ + Q_D(QNetworkSettingsService); + d->setManager(manager); +} + +void WpaSupplicantService::setId(const QString& aId) +{ + Q_D(QNetworkSettingsService); + d->m_id = aId; +} + +void WpaSupplicantService::setName(const QString& aName) +{ + Q_D(QNetworkSettingsService); + d->m_name = aName; + emit nameChanged(); +} + +void WpaSupplicantService::setFlags(const QString& aFlags) +{ + Q_D(QNetworkSettingsService); + + if (aFlags.contains("WPA-")) { + d->m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + } + if (aFlags.contains("WPA2-")) { + d->m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + } + if (aFlags.contains("WEP-")) { + d->m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + } +} + +void WpaSupplicantService::setState(QNetworkSettingsState::States aState) +{ + Q_D(QNetworkSettingsService); + d->m_state.setState(aState); + emit stateChanged(); +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h new file mode 100644 index 0000000..12cc193 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEPRIVATE_H +#define QNETWORKSETTINGSSERVICEPRIVATE_H + +#include <QObject> +#include "qnetworksettings.h" +#include "qnetworksettingsservice.h" + +class QNetworkSettingsManagerPrivate; + +class QNetworkSettingsServicePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsService) +public: + QNetworkSettingsServicePrivate(const QString& aServiceId, QNetworkSettingsService *parent=0); + void setManager(QNetworkSettingsManagerPrivate *manager); + QNetworkSettingsService *q_ptr; + + void setAutoConnect(const bool autoconnect); + void setupIpv4Config(); + void setupIpv6Config(); + void setupNameserversConfig(); + void setupDomainsConfig(); + void setupQNetworkSettingsProxy(); + void connectService(); + void disconnectService(); + + QString m_id; + QString m_name; + QNetworkSettingsState m_state; + QNetworkSettingsIPv4 m_ipv4config; + QNetworkSettingsIPv6 m_ipv6config; + QNetworkSettingsAddressModel m_domainsConfig; + QNetworkSettingsAddressModel m_nameserverConfig; + QNetworkSettingsProxy m_proxyConfig; + QNetworkSettingsWireless m_wifiConfig; + QNetworkSettingsType m_type; + QNetworkSettingsManagerPrivate *m_manager; //Not owned +}; + +class WpaSupplicantService : public QNetworkSettingsService +{ + Q_OBJECT +public: + explicit WpaSupplicantService(QNetworkSettingsManagerPrivate* manager, QObject* parent=0); + void setId(const QString& aId); + void setName(const QString& aName); + void setFlags(const QString& aFlags); + void setState(QNetworkSettingsState::States aState); +}; + +#endif // QNETWORKSETTINGSSERVICEPRIVATE_H diff --git a/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.cpp new file mode 100644 index 0000000..4e636c0 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent_p.h" + +QNetworkSettingsUserAgentPrivate::QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent* parent) + :QObject(parent) + ,q_ptr(parent) +{ + +} + +void QNetworkSettingsUserAgentPrivate::setUserCredentials(const QString& aUsername, const QString& aPassword) +{ + Q_Q(QNetworkSettingsUserAgent); + m_passphrase = aPassword; + m_username = aUsername; + emit q->ready(false); +} + +void QNetworkSettingsUserAgentPrivate::cancel() +{ + Q_Q(QNetworkSettingsUserAgent); + emit q->ready(true); +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.h b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.h new file mode 100644 index 0000000..fc717dc --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENTPRIVATE_H +#define QNETWORKSETTINGSUSERAGENTPRIVATE_H + +#include <QObject> +#include "qnetworksettingsuseragent.h" + +class QNetworkSettingsUserAgentPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) +public: + explicit QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent* parent); + virtual ~QNetworkSettingsUserAgentPrivate() {} + void setUserCredentials(const QString& aUsername, const QString& aPassword); + void cancel(); + QString m_passphrase; + QString m_username; + QNetworkSettingsUserAgent *q_ptr; +}; + +#endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H diff --git a/src/wifi/qwificontroller.cpp b/src/networksettings/wpasupplicant/qwificontroller.cpp index f5ed741..8e6cfff 100644 --- a/src/wifi/qwificontroller.cpp +++ b/src/networksettings/wpasupplicant/qwificontroller.cpp @@ -17,7 +17,7 @@ ** ****************************************************************************/ #include "qwificontroller_p.h" -#include "qwifimanager_p.h" +#include "qnetworksettingsmanager_p.h" #include "qwifisupplicant_p.h" #include "qwifidevice.h" @@ -69,8 +69,9 @@ public: event = new QWifiEvent(WIFI_HANDSHAKE_FAILED); } - if (event) - QCoreApplication::postEvent(m_controller->wifiManager(), event); + if (event) { + QCoreApplication::postEvent(m_controller->manager(), event); + } } } } @@ -80,15 +81,15 @@ private: }; -QWifiController::QWifiController(QWifiManager *manager, QWifiManagerPrivate *managerPrivate) : +QWifiController::QWifiController(QNetworkSettingsManagerPrivate *manager) : m_manager(manager), - m_managerPrivate(managerPrivate), m_exitEventThread(false), m_interface(QWifiDevice::wifiInterfaceName()), m_eventThread(new QWifiEventThread(this)), - m_supplicant(new QWifiSupplicant(this, m_managerPrivate)) + m_supplicant(new QWifiSupplicant(this)) { - qRegisterMetaType<QWifiManager::BackendState>("QWifiManager::BackendState"); + qRegisterMetaType<QWifiController::BackendState>("BackendState"); + connect(m_supplicant, &QWifiSupplicant::raiseError, this, &QWifiController::raiseError); } QWifiController::~QWifiController() @@ -137,7 +138,7 @@ void QWifiController::asyncCall(Method method) void QWifiController::initializeBackend() { qCDebug(B2QT_WIFI) << "initializing wifi backend"; - emit backendStateChanged(QWifiManager::Initializing); + emit backendStateChanged(QWifiController::Initializing); QProcess rfkill; rfkill.start(QStringLiteral("rfkill"), @@ -148,7 +149,7 @@ void QWifiController::initializeBackend() ifconfig.start(QStringLiteral("ifconfig"), QStringList() << QLatin1String(m_interface) << QStringLiteral("up")); if (!ifconfig.waitForStarted()) { - m_managerPrivate->updateLastError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); + emit raiseError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); return; } @@ -156,13 +157,13 @@ void QWifiController::initializeBackend() bool initFailed = false; QByteArray error = ifconfig.readAllStandardError(); if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("failed to bring up wifi interface: " + error)); + emit raiseError(QLatin1String("failed to bring up wifi interface: " + error)); initFailed = true; } if (!initFailed && resetSupplicantSocket()) - emit backendStateChanged(QWifiManager::Running); + emit backendStateChanged(QWifiController::Running); else - emit backendStateChanged(QWifiManager::NotRunning); + emit backendStateChanged(QWifiController::NotRunning); } bool QWifiController::resetSupplicantSocket() @@ -183,7 +184,7 @@ bool QWifiController::resetSupplicantSocket() void QWifiController::terminateBackend() { qCDebug(B2QT_WIFI) << "terminating wifi backend"; - emit backendStateChanged(QWifiManager::Terminating); + emit backendStateChanged(QWifiController::Terminating); exitWifiEventThread(); m_supplicant->stopSupplicant(); @@ -193,17 +194,17 @@ void QWifiController::terminateBackend() ifconfig.start(QStringLiteral("ifconfig"), QStringList() << QLatin1String(m_interface) << QStringLiteral("down")); if (!ifconfig.waitForStarted()) { - m_managerPrivate->updateLastError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); + emit raiseError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); return; } ifconfig.waitForFinished(); QByteArray error = ifconfig.readAllStandardError(); if (!error.isEmpty()) - m_managerPrivate->updateLastError(QLatin1String("failed to bring down wifi interface: " + error)); + emit raiseError(QLatin1String("failed to bring down wifi interface: " + error)); stopDhcp(); - emit backendStateChanged(QWifiManager::NotRunning); + emit backendStateChanged(QWifiController::NotRunning); } void QWifiController::startWifiEventThread() @@ -216,7 +217,7 @@ void QWifiController::exitWifiEventThread() { if (m_eventThread->isRunning()) { m_exitEventThread = true; - m_managerPrivate->call(QStringLiteral("SCAN")); + m_manager->call(QStringLiteral("SCAN")); if (!m_eventThread->wait(8000)) qCWarning(B2QT_WIFI, "timed out waiting for wifi event thread to exit"); } @@ -255,7 +256,7 @@ void QWifiController::acquireIPAddress() QProcess udhcpc; udhcpc.start(QStringLiteral("udhcpc"), args); if (!udhcpc.waitForStarted()) { - m_managerPrivate->updateLastError(udhcpc.program() + QLatin1String(": ") + udhcpc.errorString()); + emit raiseError(udhcpc.program() + QLatin1String(": ") + udhcpc.errorString()); emit dhcpRequestFinished(QLatin1String("failed")); return; } @@ -264,7 +265,7 @@ void QWifiController::acquireIPAddress() QByteArray error = udhcpc.readAllStandardError(); QString status = QLatin1String("success"); if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("udhcpc failed: " + error)); + emit raiseError(QLatin1String("udhcpc failed: " + error)); status = QLatin1String("failed"); } else { if (udhcpc.readAllStandardOutput().contains("No lease")) diff --git a/src/wifi/qwificontroller_p.h b/src/networksettings/wpasupplicant/qwificontroller_p.h index 45751fa..902bc6e 100644 --- a/src/wifi/qwificontroller_p.h +++ b/src/networksettings/wpasupplicant/qwificontroller_p.h @@ -19,8 +19,6 @@ #ifndef QWIFICONTROLLER_H #define QWIFICONTROLLER_H -#include "qwifimanager.h" - #include <QtCore/QEvent> #include <QtCore/QVector> #include <QtCore/QThread> @@ -38,10 +36,9 @@ const QEvent::Type WIFI_HANDSHAKE_FAILED = (QEvent::Type) (QEvent::User + 2003); const QEvent::Type WIFI_AUTHENTICATING = (QEvent::Type) (QEvent::User + 2004); const QEvent::Type WIFI_DISCONNECTED = (QEvent::Type) (QEvent::User + 2005); -class QWifiManager; -class QWifiManagerPrivate; class QWifiEventThread; class QWifiSupplicant; +class QNetworkSettingsManagerPrivate; class QWifiEvent : public QEvent { @@ -60,6 +57,7 @@ private: class QWifiController : public QThread { Q_OBJECT + Q_ENUMS(BackendState) public: enum Method { InitializeBackend, @@ -69,11 +67,18 @@ public: ExitEventLoop }; - explicit QWifiController(QWifiManager *manager, QWifiManagerPrivate *managerPrivate); + enum BackendState { + Initializing, + Running, + Terminating, + NotRunning + }; + + explicit QWifiController(QNetworkSettingsManagerPrivate *manager); ~QWifiController(); void asyncCall(Method method); - QWifiManager *wifiManager() const { return m_manager; } + QNetworkSettingsManagerPrivate *manager() const { return m_manager; } bool isWifiThreadExitRequested() const { return m_exitEventThread; } void startWifiEventThread(); void acquireIPAddress(); @@ -82,8 +87,9 @@ public: QWifiSupplicant *supplicant() const { return m_supplicant; } signals: - void backendStateChanged(QWifiManager::BackendState backendState); + void backendStateChanged(BackendState backendState); void dhcpRequestFinished(const QString &status); + void raiseError(const QString &error); protected: void run(); @@ -93,8 +99,7 @@ protected: void killDhcpProcess(const QString &path) const; private: - QWifiManager *m_manager; - QWifiManagerPrivate *const m_managerPrivate; + QNetworkSettingsManagerPrivate *m_manager; //not owned bool m_exitEventThread; QByteArray m_interface; QVector<Method> m_methods; @@ -104,6 +109,8 @@ private: QWifiSupplicant *m_supplicant; }; +Q_DECLARE_METATYPE(QWifiController::BackendState) + QT_END_NAMESPACE #endif // QWIFICONTROLLER_H diff --git a/src/wifi/qwifidevice.cpp b/src/networksettings/wpasupplicant/qwifidevice.cpp index a6812e7..a6812e7 100644 --- a/src/wifi/qwifidevice.cpp +++ b/src/networksettings/wpasupplicant/qwifidevice.cpp diff --git a/src/wifi/qwifidevice.h b/src/networksettings/wpasupplicant/qwifidevice.h index 80b4891..80b4891 100644 --- a/src/wifi/qwifidevice.h +++ b/src/networksettings/wpasupplicant/qwifidevice.h diff --git a/src/wifi/qwifisupplicant.cpp b/src/networksettings/wpasupplicant/qwifisupplicant.cpp index d87ac80..779475e 100644 --- a/src/wifi/qwifisupplicant.cpp +++ b/src/networksettings/wpasupplicant/qwifisupplicant.cpp @@ -18,11 +18,11 @@ ****************************************************************************/ #include "qwifisupplicant_p.h" #include "qwifidevice.h" -#include "qwifimanager_p.h" #include <poll.h> #include <unistd.h> #include <sys/socket.h> +#include <errno.h> #include <QtCore/QFile> #include <QtCore/QProcess> @@ -34,17 +34,16 @@ Q_LOGGING_CATEGORY(B2QT_WIFI_VERBOSE, "qt.b2qt.wifi.verbose") #define CONFIG_FILE "/etc/wpa_supplicant.qtwifi.conf" #define CONTROL_INTERFACE_PATH "/var/run/wpa_supplicant/" -QWifiSupplicant::QWifiSupplicant(QObject *parent, QWifiManagerPrivate *managerPrivate) : +QWifiSupplicant::QWifiSupplicant(QObject *parent) : QObject(parent), ctrl_conn(0), monitor_conn(0), - interface(QWifiDevice::wifiInterfaceName()), - m_managerPrivate(managerPrivate) + interface(QWifiDevice::wifiInterfaceName()) { createSupplicantConfig(); } -void QWifiSupplicant::createSupplicantConfig() const +void QWifiSupplicant::createSupplicantConfig() { QFile supplicantConfig(QLatin1String(CONFIG_FILE)); if (supplicantConfig.exists()) @@ -55,7 +54,7 @@ void QWifiSupplicant::createSupplicantConfig() const "ctrl_interface_group=0\n" "update_config=1\n"); } else { - m_managerPrivate->updateLastError(QLatin1String("failed to create wpa_supplicant configuration file.")); + emit raiseError(QLatin1String("failed to create wpa_supplicant configuration file.")); } } @@ -76,13 +75,13 @@ bool QWifiSupplicant::startSupplicant() startStopDaemon.setProcessChannelMode(QProcess::MergedChannels); startStopDaemon.start(QStringLiteral("start-stop-daemon"), arg); if (!startStopDaemon.waitForStarted()) { - m_managerPrivate->updateLastError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); + emit raiseError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); return false; } startStopDaemon.waitForFinished(); // if the interface socket exists then wpa-supplicant was invoked successfully if (!QFile(QLatin1String(CONTROL_INTERFACE_PATH + interface)).exists()) { - m_managerPrivate->updateLastError(QLatin1String("failed to invoke wpa_supplicant: " + emit raiseError(QLatin1String("failed to invoke wpa_supplicant: " + startStopDaemon.readAll())); return false; } @@ -103,13 +102,13 @@ bool QWifiSupplicant::stopSupplicant() QProcess startStopDaemon; startStopDaemon.start(QStringLiteral("start-stop-daemon"), arg); if (!startStopDaemon.waitForStarted()) { - m_managerPrivate->updateLastError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); + emit raiseError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); return false; } startStopDaemon.waitForFinished(); QByteArray error = startStopDaemon.readAllStandardError(); if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("failed to stop a wpa_supplicant process" + error)); + emit raiseError(QLatin1String("failed to stop a wpa_supplicant process" + error)); return false; } @@ -165,7 +164,7 @@ bool QWifiSupplicant::connectToSupplicant() } if (!connected) - m_managerPrivate->updateLastError(QLatin1String("failed to connect to wpa_supplicant")); + emit raiseError(QLatin1String("failed to connect to wpa_supplicant")); return connected; } diff --git a/src/wifi/qwifisupplicant_p.h b/src/networksettings/wpasupplicant/qwifisupplicant_p.h index 0a6a964..13855c0 100644 --- a/src/wifi/qwifisupplicant_p.h +++ b/src/networksettings/wpasupplicant/qwifisupplicant_p.h @@ -36,9 +36,9 @@ class QWifiSupplicant : public QObject { Q_OBJECT public: - explicit QWifiSupplicant(QObject *parent, QWifiManagerPrivate *managerPrivate); + explicit QWifiSupplicant(QObject *parent); - void createSupplicantConfig() const; + void createSupplicantConfig(); bool startSupplicant(); bool stopSupplicant(); bool connectToSupplicant(); @@ -47,6 +47,9 @@ public: bool sendCommand(const QString &command, QByteArray *reply); static QString decodeSsid(const QString &encoded); +signals: + void raiseError(const QString& error); + protected: int receiveEvent(char *reply, size_t *reply_len); @@ -55,7 +58,6 @@ private: wpa_ctrl *monitor_conn; int exit_sockets[2]; QByteArray interface; - QWifiManagerPrivate *const m_managerPrivate; }; QT_END_NAMESPACE diff --git a/src/settingsui/bluetooth/Bluetooth.qml b/src/settingsui/bluetooth/Bluetooth.qml new file mode 100644 index 0000000..2bffe5b --- /dev/null +++ b/src/settingsui/bluetooth/Bluetooth.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.bluetooth 1.0 + +Item { + id: root + property string title: qsTr("Bluetooth Settings") + + ColumnLayout { + anchors.margins: 20 + anchors.fill: parent + id: content + spacing: 20 + + GroupBox { + id: groupBox + width: parent.width + title: qsTr("Bluetooth status") + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + + RowLayout { + spacing: 10 + Label { + id: off + text: qsTr("Off") + } + Switch { + checked: BtDevice.powered + onCheckedChanged: BtDevice.powered = checked + } + Label { + text: qsTr("On") + } + } + } + Discovery { + id: discovery + visible: BtDevice.powered + Layout.fillWidth: true + Layout.fillHeight: true + } + } +} diff --git a/src/settingsui/bluetooth/Discovery.qml b/src/settingsui/bluetooth/Discovery.qml new file mode 100644 index 0000000..9c1b674 --- /dev/null +++ b/src/settingsui/bluetooth/Discovery.qml @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.bluetooth 1.0 + +Item { + id: top + + GroupBox { + id: groupBox + title: qsTr("Devices") + anchors.fill: parent + + ListView { + id: mainList + anchors.fill: parent + opacity: BtDevice.scanning ? .5 : 1.0 + interactive: !BtDevice.scanning + clip: true + model: BtDevice.deviceModel + + function getIcon(deviceType) { + switch (deviceType) { + case BtDeviceItem.Computer: + return "../icons/Laptop_qt_1x.png" + case BtDeviceItem.Headphones: + return "../icons/Headphones_qt_1x.png" + case BtDeviceItem.Microphone: + return "../icons/Microphone_qt_1x.png" + case BtDeviceItem.Mouse: + return "../icons/Mouse_qt_1x.png" + case BtDeviceItem.Keyboard: + return "../icons/Keyboard_qt_1x.png" + default: + return "../icons/Bluetooth_qt_1x.png" + } + } + + delegate: Item { + id: btDelegate + width: parent.width + height: expanded || connected ? column.height + 10 : bttext.height + 10 + property bool expanded: false; + + MouseArea { + anchors.fill: parent + onClicked: { + if (!connected) + btDelegate.expanded = !btDelegate.expanded + } + } + Image { + id: bticon + anchors.left: parent.left + anchors.top: parent.top + anchors.topMargin: 4 + source: mainList.getIcon(type) + } + Column { + id: column + anchors.left: bticon.right + anchors.leftMargin: 10 + anchors.right: connectButton.left + anchors.rightMargin: 10 + + Label { + id: bttext + text: name + } + Label { + id: details + opacity: btDelegate.expanded || connected ? 1 : 0.0 + text: address + Behavior on opacity { NumberAnimation { duration: 200} } + } + } + Button { + id: connectButton + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + visible: (expanded || connected) && !BtDevice.scanning + text: connected ? qsTr("Disconnect") : qsTr("Connect") + onClicked : connected ? BtDevice.requestDisconnect(address) : BtDevice.requestPairing(address); + } + Behavior on height { NumberAnimation { duration: 200} } + } + focus: true + } + } + BusyIndicator { + anchors.centerIn: parent + running: BtDevice.scanning + } +} diff --git a/src/settingsui/common/CustomTableView.qml b/src/settingsui/common/CustomTableView.qml new file mode 100644 index 0000000..6073683 --- /dev/null +++ b/src/settingsui/common/CustomTableView.qml @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 + +ColumnLayout { + id: root + spacing: 0 + Layout.fillHeight: true + Layout.fillWidth: true + + property var headerTexts: [] + property var roleNames: [] + property alias model: listView.model + signal clicked(int index) + + Rectangle { + height: 40 + Layout.fillWidth: true + color: "#80c342" + + Row { + anchors.fill: parent + anchors.leftMargin: 10 + spacing: 10 + + Repeater { + model: root.headerTexts.length + Text { + width: parent.width / root.headerTexts.length + text: root.headerTexts[index] + color: "white" + font.bold: true + anchors.verticalCenter: parent.verticalCenter + } + } + } + } + ListView { + id: listView + Layout.fillHeight: true + Layout.fillWidth: true + clip: true + + Rectangle { + anchors.fill: parent + border.color: "#bdbebf" + border.width: 1 + color: "transparent" + } + + ScrollBar.vertical: ScrollBar {} + + delegate: Rectangle { + width: parent.width + height: 30 + color: index % 2 ? "#e3e3e3" : "white" + property var delegateData: modelData + + Row { + anchors.fill: parent + anchors.leftMargin: 10 + spacing: 10 + + Repeater { + model: root.roleNames.length + + Text { + width: parent.width / root.roleNames.length + text: delegateData[root.roleNames[index]] + anchors.verticalCenter: parent.verticalCenter + antialiasing: false + smooth: false + renderType: listView.moving ? Text.NativeRendering : Text.QtRendering + } + } + } + MouseArea { + anchors.fill: parent + onClicked: root.clicked(index) + } + } + } +} diff --git a/src/settingsui/common/HandwritingModeButton.qml b/src/settingsui/common/HandwritingModeButton.qml new file mode 100644 index 0000000..0dfe775 --- /dev/null +++ b/src/settingsui/common/HandwritingModeButton.qml @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Item { + id: handwritingModeButton + state: "unavailable" + property bool floating + property bool flipable + readonly property real __minWidthHeight: Math.min(width, height) + + signal clicked() + signal doubleClicked() + + Flipable { + id: flipableImage + anchors.fill: parent + + property bool flipped + + front: Image { + sourceSize.width: handwritingModeButton.__minWidthHeight + sourceSize.height: handwritingModeButton.__minWidthHeight + smooth: false + source: "qrc:/icons/FloatingButton_Unavailable.png" + } + + back: Image { + id: buttonImage + sourceSize.width: handwritingModeButton.__minWidthHeight + sourceSize.height: handwritingModeButton.__minWidthHeight + smooth: false + source: "qrc:/icons/FloatingButton_Available.png" + } + + states: State { + PropertyChanges { target: rotation; angle: 180 } + when: flipableImage.flipped + } + + transform: Rotation { + id: rotation + origin.x: flipableImage.width / 2 + origin.y: flipableImage.height / 2 + axis { x: 0; y: 1; z: 0 } + angle: 0 + } + + transitions: Transition { + enabled: handwritingModeButton.flipable + NumberAnimation { target: rotation; property: "angle"; duration: 400 } + } + } + + states: [ + State { + name: "available" + PropertyChanges { target: flipableImage; flipped: true } + }, + State { + name: "active" + PropertyChanges { target: flipableImage; flipped: true } + PropertyChanges { target: buttonImage; source: "qrc:/icons/FloatingButton_Active.png" } + } + ] + + function snapHorizontal() { + if (!floating) + return + if (mouseArea.drag.maximumX > mouseArea.drag.minimumX) { + if (x + 20 >= mouseArea.drag.maximumX) { + anchors.left = undefined + anchors.right = parent.right + } else if (x - 20 <= mouseArea.drag.minimumX) { + anchors.right = undefined + anchors.left = parent.left + } + } + } + + function snapVertical() { + if (!floating) + return + if (mouseArea.drag.maximumY > mouseArea.drag.minimumY) { + if (y + 20 >= mouseArea.drag.maximumY) { + anchors.top = undefined + anchors.bottom = parent.bottom + } else if (y - 20 <= mouseArea.drag.minimumY) { + anchors.bottom = undefined + anchors.top = parent.top + } + } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + drag { + target: handwritingModeButton.floating ? handwritingModeButton : undefined + axis: Drag.XAxis | Drag.YAxis + minimumX: 0 + maximumX: handwritingModeButton.parent.width - handwritingModeButton.width + onMaximumXChanged: !mouseArea.drag.active && handwritingModeButton.snapHorizontal() + minimumY: 0 + maximumY: handwritingModeButton.parent.height - handwritingModeButton.height + onMaximumYChanged: !mouseArea.drag.active && handwritingModeButton.snapVertical() + } + onPressed: { + if (!handwritingModeButton.floating) + return + handwritingModeButton.anchors.left = undefined + handwritingModeButton.anchors.top = undefined + handwritingModeButton.anchors.right = undefined + handwritingModeButton.anchors.bottom = undefined + } + onReleased: { + handwritingModeButton.snapHorizontal() + handwritingModeButton.snapVertical() + } + onClicked: { + handwritingModeButton.snapHorizontal() + handwritingModeButton.snapVertical() + clickTimer.restart() + } + onDoubleClicked: { + clickTimer.stop() + handwritingModeButton.snapHorizontal() + handwritingModeButton.snapVertical() + handwritingModeButton.doubleClicked() + } + Timer { + id: clickTimer + interval: Qt.styleHints ? Qt.styleHints.mouseDoubleClickInterval / 3 : 0 + repeat: false + onTriggered: handwritingModeButton.clicked() + } + } +} diff --git a/src/settingsui/deployment.pri b/src/settingsui/deployment.pri new file mode 100644 index 0000000..5441b63 --- /dev/null +++ b/src/settingsui/deployment.pri @@ -0,0 +1,27 @@ +android-no-sdk { + target.path = /data/user/qt + export(target.path) + INSTALLS += target +} else:android { + x86 { + target.path = /libs/x86 + } else: armeabi-v7a { + target.path = /libs/armeabi-v7a + } else { + target.path = /libs/armeabi + } + export(target.path) + INSTALLS += target +} else:unix { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/src/settingsui/display/Display.qml b/src/settingsui/display/Display.qml new file mode 100644 index 0000000..69be8f3 --- /dev/null +++ b/src/settingsui/display/Display.qml @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.display 1.0 + +Item { + id: root + property string title: qsTr("Display Settings") + property int titleWidth: width * 0.382 + + GroupBox { + title: qsTr("Display Settings") + anchors.margins: 20 + anchors.left: parent.left + anchors.top: parent.top + anchors.right:parent.right + + ColumnLayout { + anchors.fill: parent + + RowLayout { + width: parent.width + spacing: 10 + + Label { + text: qsTr("Brightness:") + Layout.preferredWidth: root.titleWidth + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + } + Slider { + id: brightnessSlider + value: DisplaySettings.displayBrightness + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true + from: 0 + to: 255 + } + } + Binding { + target: DisplaySettings + property: "displayBrightness" + value: brightnessSlider.position * brightnessSlider.to + } + GridLayout { + columns: 2 + rows: 3 + rowSpacing: 10 + + Label { + text: qsTr("Physical screen size:") + Layout.preferredWidth: root.titleWidth + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + wrapMode: Label.WordWrap + } + RadioButton { + text: qsTr("Default") + checked: !DisplaySettings.physicalScreenSizeOverride + } + RadioButton { + id: custom + Layout.column: 1 + Layout.row: 1 + text: qsTr("Custom") + checked: DisplaySettings.physicalScreenSizeOverride + onCheckedChanged: DisplaySettings.physicalScreenSizeOverride = checked + } + GroupBox { + title: qsTr("Size (in inches): %1").arg(DisplaySettings.physicalScreenSizeInch) + Layout.column: 1 + Layout.row: 2 + Layout.fillWidth: true + visible: custom.checked + + RowLayout { + spacing: 10 + width: parent.width + + Label { + text: sizeSlider.from + Layout.alignment: Qt.AlignVCenter + } + Slider { + id: sizeSlider + value: DisplaySettings.physicalScreenSizeInch + Layout.fillWidth: true + stepSize: 1 + from: 4 + to: 60 + onPositionChanged: DisplaySettings.physicalScreenSizeInch = sizeSlider.from + Math.floor(sizeSlider.position * (sizeSlider.to - sizeSlider.from)) + } + Label { + text: sizeSlider.to + Layout.alignment: Qt.AlignVCenter | Qt.AlignRight + } + } + } + } + } + } +} diff --git a/src/settingsui/icons.qrc b/src/settingsui/icons.qrc new file mode 100644 index 0000000..29d0e1a --- /dev/null +++ b/src/settingsui/icons.qrc @@ -0,0 +1,21 @@ +<RCC> + <qresource prefix="/"> + <file>icons/Audio_qt_6x.png</file> + <file>icons/Chevron-left_black_1x.png</file> + <file>icons/Power_black_1x.png</file> + <file>icons/Display_qt_6x.png</file> + <file>icons/Clock_qt_6x.png</file> + <file>icons/Flag_qt_6x.png</file> + <file>icons/World_qt_6x.png</file> + <file>icons/Bluetooth_qt_6x.png</file> + <file>icons/Bluetooth_qt_1x.png</file> + <file>icons/Headphones_qt_1x.png</file> + <file>icons/Keyboard_qt_1x.png</file> + <file>icons/Laptop_qt_1x.png</file> + <file>icons/Microphone_qt_1x.png</file> + <file>icons/Mouse_qt_1x.png</file> + <file>icons/FloatingButton_Active.png</file> + <file>icons/FloatingButton_Available.png</file> + <file>icons/FloatingButton_Unavailable.png</file> + </qresource> +</RCC> diff --git a/src/settingsui/icons/Alert_yellow_1x.png b/src/settingsui/icons/Alert_yellow_1x.png Binary files differnew file mode 100644 index 0000000..2306ff6 --- /dev/null +++ b/src/settingsui/icons/Alert_yellow_1x.png diff --git a/src/settingsui/icons/Audio_qt_6x.png b/src/settingsui/icons/Audio_qt_6x.png Binary files differnew file mode 100644 index 0000000..8251129 --- /dev/null +++ b/src/settingsui/icons/Audio_qt_6x.png diff --git a/src/settingsui/icons/Bluetooth_qt_1x.png b/src/settingsui/icons/Bluetooth_qt_1x.png Binary files differnew file mode 100644 index 0000000..af6968d --- /dev/null +++ b/src/settingsui/icons/Bluetooth_qt_1x.png diff --git a/src/settingsui/icons/Bluetooth_qt_6x.png b/src/settingsui/icons/Bluetooth_qt_6x.png Binary files differnew file mode 100644 index 0000000..55e4fb1 --- /dev/null +++ b/src/settingsui/icons/Bluetooth_qt_6x.png diff --git a/src/settingsui/icons/Camcorder_qt_1x.png b/src/settingsui/icons/Camcorder_qt_1x.png Binary files differnew file mode 100644 index 0000000..7ffb2c8 --- /dev/null +++ b/src/settingsui/icons/Camcorder_qt_1x.png diff --git a/src/settingsui/icons/Camera_qt_1x.png b/src/settingsui/icons/Camera_qt_1x.png Binary files differnew file mode 100644 index 0000000..b84e53a --- /dev/null +++ b/src/settingsui/icons/Camera_qt_1x.png diff --git a/src/settingsui/icons/Chevron-left_black_1x.png b/src/settingsui/icons/Chevron-left_black_1x.png Binary files differnew file mode 100644 index 0000000..225176b --- /dev/null +++ b/src/settingsui/icons/Chevron-left_black_1x.png diff --git a/src/settingsui/icons/Clock_qt_1x.png b/src/settingsui/icons/Clock_qt_1x.png Binary files differnew file mode 100644 index 0000000..ee58f95 --- /dev/null +++ b/src/settingsui/icons/Clock_qt_1x.png diff --git a/src/settingsui/icons/Clock_qt_6x.png b/src/settingsui/icons/Clock_qt_6x.png Binary files differnew file mode 100644 index 0000000..aba8b60 --- /dev/null +++ b/src/settingsui/icons/Clock_qt_6x.png diff --git a/src/settingsui/icons/Display_qt_6x.png b/src/settingsui/icons/Display_qt_6x.png Binary files differnew file mode 100644 index 0000000..e45c45c --- /dev/null +++ b/src/settingsui/icons/Display_qt_6x.png diff --git a/src/settingsui/icons/Flag_qt_6x.png b/src/settingsui/icons/Flag_qt_6x.png Binary files differnew file mode 100644 index 0000000..f549ebd --- /dev/null +++ b/src/settingsui/icons/Flag_qt_6x.png diff --git a/src/settingsui/icons/FloatingButton_Active.png b/src/settingsui/icons/FloatingButton_Active.png Binary files differnew file mode 100755 index 0000000..9b55146 --- /dev/null +++ b/src/settingsui/icons/FloatingButton_Active.png diff --git a/src/settingsui/icons/FloatingButton_Available.png b/src/settingsui/icons/FloatingButton_Available.png Binary files differnew file mode 100755 index 0000000..1479881 --- /dev/null +++ b/src/settingsui/icons/FloatingButton_Available.png diff --git a/src/settingsui/icons/FloatingButton_Unavailable.png b/src/settingsui/icons/FloatingButton_Unavailable.png Binary files differnew file mode 100755 index 0000000..33aa87d --- /dev/null +++ b/src/settingsui/icons/FloatingButton_Unavailable.png diff --git a/src/settingsui/icons/Headphones_qt_1x.png b/src/settingsui/icons/Headphones_qt_1x.png Binary files differnew file mode 100644 index 0000000..82b04e7 --- /dev/null +++ b/src/settingsui/icons/Headphones_qt_1x.png diff --git a/src/settingsui/icons/Heartbeat_qt_1x.png b/src/settingsui/icons/Heartbeat_qt_1x.png Binary files differnew file mode 100644 index 0000000..16a94bc --- /dev/null +++ b/src/settingsui/icons/Heartbeat_qt_1x.png diff --git a/src/settingsui/icons/Keyboard_qt_1x.png b/src/settingsui/icons/Keyboard_qt_1x.png Binary files differnew file mode 100644 index 0000000..cc6417d --- /dev/null +++ b/src/settingsui/icons/Keyboard_qt_1x.png diff --git a/src/settingsui/icons/Laptop_qt_1x.png b/src/settingsui/icons/Laptop_qt_1x.png Binary files differnew file mode 100644 index 0000000..2924015 --- /dev/null +++ b/src/settingsui/icons/Laptop_qt_1x.png diff --git a/src/settingsui/icons/Microphone_qt_1x.png b/src/settingsui/icons/Microphone_qt_1x.png Binary files differnew file mode 100644 index 0000000..f76a963 --- /dev/null +++ b/src/settingsui/icons/Microphone_qt_1x.png diff --git a/src/settingsui/icons/MobilePhone_qt_1x.png b/src/settingsui/icons/MobilePhone_qt_1x.png Binary files differnew file mode 100644 index 0000000..363d667 --- /dev/null +++ b/src/settingsui/icons/MobilePhone_qt_1x.png diff --git a/src/settingsui/icons/Mouse_qt_1x.png b/src/settingsui/icons/Mouse_qt_1x.png Binary files differnew file mode 100644 index 0000000..24d057d --- /dev/null +++ b/src/settingsui/icons/Mouse_qt_1x.png diff --git a/src/settingsui/icons/Power_black_1x.png b/src/settingsui/icons/Power_black_1x.png Binary files differnew file mode 100644 index 0000000..cca0fe8 --- /dev/null +++ b/src/settingsui/icons/Power_black_1x.png diff --git a/src/settingsui/icons/Tablet_qt_1x.png b/src/settingsui/icons/Tablet_qt_1x.png Binary files differnew file mode 100644 index 0000000..e218184 --- /dev/null +++ b/src/settingsui/icons/Tablet_qt_1x.png diff --git a/src/settingsui/icons/Volume_down_qt_1x.png b/src/settingsui/icons/Volume_down_qt_1x.png Binary files differnew file mode 100644 index 0000000..2068819 --- /dev/null +++ b/src/settingsui/icons/Volume_down_qt_1x.png diff --git a/src/settingsui/icons/Volume_mute_qt_1x.png b/src/settingsui/icons/Volume_mute_qt_1x.png Binary files differnew file mode 100644 index 0000000..1a41927 --- /dev/null +++ b/src/settingsui/icons/Volume_mute_qt_1x.png diff --git a/src/settingsui/icons/Volume_up_qt_1x.png b/src/settingsui/icons/Volume_up_qt_1x.png Binary files differnew file mode 100644 index 0000000..45a8b61 --- /dev/null +++ b/src/settingsui/icons/Volume_up_qt_1x.png diff --git a/src/settingsui/icons/WifiAnim_black_2x.png b/src/settingsui/icons/WifiAnim_black_2x.png Binary files differnew file mode 100644 index 0000000..76c850d --- /dev/null +++ b/src/settingsui/icons/WifiAnim_black_2x.png diff --git a/src/settingsui/icons/Wifi_lightgray_2x.png b/src/settingsui/icons/Wifi_lightgray_2x.png Binary files differnew file mode 100644 index 0000000..3e6183a --- /dev/null +++ b/src/settingsui/icons/Wifi_lightgray_2x.png diff --git a/src/settingsui/icons/World_qt_6x.png b/src/settingsui/icons/World_qt_6x.png Binary files differnew file mode 100644 index 0000000..9024031 --- /dev/null +++ b/src/settingsui/icons/World_qt_6x.png diff --git a/src/settingsui/icons/generate_icons.sh b/src/settingsui/icons/generate_icons.sh new file mode 100755 index 0000000..55867b8 --- /dev/null +++ b/src/settingsui/icons/generate_icons.sh @@ -0,0 +1,27 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash +# +# This script resizes and sets correct brand colors for the icons in ref folder +# + +./scripts/cimages.sh ./ref/*.png +./scripts/cimage.sh ./ref/extra/Alert.png red +./scripts/cimage.sh ./ref/extra/Alert.png yellow +./scripts/rimages.sh *.png diff --git a/src/settingsui/icons/ref/Audio.png b/src/settingsui/icons/ref/Audio.png Binary files differnew file mode 100644 index 0000000..8434f0a --- /dev/null +++ b/src/settingsui/icons/ref/Audio.png diff --git a/src/settingsui/icons/ref/Back.png b/src/settingsui/icons/ref/Back.png Binary files differnew file mode 100644 index 0000000..9029fd0 --- /dev/null +++ b/src/settingsui/icons/ref/Back.png diff --git a/src/settingsui/icons/ref/Bluetooth.png b/src/settingsui/icons/ref/Bluetooth.png Binary files differnew file mode 100644 index 0000000..e7c80a9 --- /dev/null +++ b/src/settingsui/icons/ref/Bluetooth.png diff --git a/src/settingsui/icons/ref/Camcorder.png b/src/settingsui/icons/ref/Camcorder.png Binary files differnew file mode 100644 index 0000000..8c317a2 --- /dev/null +++ b/src/settingsui/icons/ref/Camcorder.png diff --git a/src/settingsui/icons/ref/Camera.png b/src/settingsui/icons/ref/Camera.png Binary files differnew file mode 100644 index 0000000..c71ab25 --- /dev/null +++ b/src/settingsui/icons/ref/Camera.png diff --git a/src/settingsui/icons/ref/Chevron-left.png b/src/settingsui/icons/ref/Chevron-left.png Binary files differnew file mode 100644 index 0000000..95006f4 --- /dev/null +++ b/src/settingsui/icons/ref/Chevron-left.png diff --git a/src/settingsui/icons/ref/Chevron-right.png b/src/settingsui/icons/ref/Chevron-right.png Binary files differnew file mode 100644 index 0000000..2860e9a --- /dev/null +++ b/src/settingsui/icons/ref/Chevron-right.png diff --git a/src/settingsui/icons/ref/Circle-x.png b/src/settingsui/icons/ref/Circle-x.png Binary files differnew file mode 100644 index 0000000..2bbfa97 --- /dev/null +++ b/src/settingsui/icons/ref/Circle-x.png diff --git a/src/settingsui/icons/ref/Clock.png b/src/settingsui/icons/ref/Clock.png Binary files differnew file mode 100644 index 0000000..1dae63e --- /dev/null +++ b/src/settingsui/icons/ref/Clock.png diff --git a/src/settingsui/icons/ref/Cogs.png b/src/settingsui/icons/ref/Cogs.png Binary files differnew file mode 100644 index 0000000..feaae50 --- /dev/null +++ b/src/settingsui/icons/ref/Cogs.png diff --git a/src/settingsui/icons/ref/Connections.png b/src/settingsui/icons/ref/Connections.png Binary files differnew file mode 100644 index 0000000..b042d3c --- /dev/null +++ b/src/settingsui/icons/ref/Connections.png diff --git a/src/settingsui/icons/ref/Display.png b/src/settingsui/icons/ref/Display.png Binary files differnew file mode 100644 index 0000000..cf1251a --- /dev/null +++ b/src/settingsui/icons/ref/Display.png diff --git a/src/settingsui/icons/ref/Flag.png b/src/settingsui/icons/ref/Flag.png Binary files differnew file mode 100644 index 0000000..485ed48 --- /dev/null +++ b/src/settingsui/icons/ref/Flag.png diff --git a/src/settingsui/icons/ref/Headphones.png b/src/settingsui/icons/ref/Headphones.png Binary files differnew file mode 100644 index 0000000..9e5c483 --- /dev/null +++ b/src/settingsui/icons/ref/Headphones.png diff --git a/src/settingsui/icons/ref/Heartbeat.png b/src/settingsui/icons/ref/Heartbeat.png Binary files differnew file mode 100644 index 0000000..168135e --- /dev/null +++ b/src/settingsui/icons/ref/Heartbeat.png diff --git a/src/settingsui/icons/ref/Keyboard.png b/src/settingsui/icons/ref/Keyboard.png Binary files differnew file mode 100644 index 0000000..c814e8e --- /dev/null +++ b/src/settingsui/icons/ref/Keyboard.png diff --git a/src/settingsui/icons/ref/Laptop.png b/src/settingsui/icons/ref/Laptop.png Binary files differnew file mode 100644 index 0000000..465bb54 --- /dev/null +++ b/src/settingsui/icons/ref/Laptop.png diff --git a/src/settingsui/icons/ref/Lock.png b/src/settingsui/icons/ref/Lock.png Binary files differnew file mode 100644 index 0000000..6afb6ac --- /dev/null +++ b/src/settingsui/icons/ref/Lock.png diff --git a/src/settingsui/icons/ref/Microphone.png b/src/settingsui/icons/ref/Microphone.png Binary files differnew file mode 100644 index 0000000..63cb500 --- /dev/null +++ b/src/settingsui/icons/ref/Microphone.png diff --git a/src/settingsui/icons/ref/MobilePhone.png b/src/settingsui/icons/ref/MobilePhone.png Binary files differnew file mode 100644 index 0000000..b186c09 --- /dev/null +++ b/src/settingsui/icons/ref/MobilePhone.png diff --git a/src/settingsui/icons/ref/Mouse.png b/src/settingsui/icons/ref/Mouse.png Binary files differnew file mode 100644 index 0000000..146305b --- /dev/null +++ b/src/settingsui/icons/ref/Mouse.png diff --git a/src/settingsui/icons/ref/Plus.png b/src/settingsui/icons/ref/Plus.png Binary files differnew file mode 100644 index 0000000..391fe94 --- /dev/null +++ b/src/settingsui/icons/ref/Plus.png diff --git a/src/settingsui/icons/ref/Power.png b/src/settingsui/icons/ref/Power.png Binary files differnew file mode 100644 index 0000000..b54a084 --- /dev/null +++ b/src/settingsui/icons/ref/Power.png diff --git a/src/settingsui/icons/ref/Settings.png b/src/settingsui/icons/ref/Settings.png Binary files differnew file mode 100644 index 0000000..d8b255c --- /dev/null +++ b/src/settingsui/icons/ref/Settings.png diff --git a/src/settingsui/icons/ref/Tablet.png b/src/settingsui/icons/ref/Tablet.png Binary files differnew file mode 100644 index 0000000..71b0065 --- /dev/null +++ b/src/settingsui/icons/ref/Tablet.png diff --git a/src/settingsui/icons/ref/Volume_down.png b/src/settingsui/icons/ref/Volume_down.png Binary files differnew file mode 100644 index 0000000..0773b1d --- /dev/null +++ b/src/settingsui/icons/ref/Volume_down.png diff --git a/src/settingsui/icons/ref/Volume_mute.png b/src/settingsui/icons/ref/Volume_mute.png Binary files differnew file mode 100644 index 0000000..36ab384 --- /dev/null +++ b/src/settingsui/icons/ref/Volume_mute.png diff --git a/src/settingsui/icons/ref/Volume_up.png b/src/settingsui/icons/ref/Volume_up.png Binary files differnew file mode 100644 index 0000000..61eebbd --- /dev/null +++ b/src/settingsui/icons/ref/Volume_up.png diff --git a/src/settingsui/icons/ref/Wifi.png b/src/settingsui/icons/ref/Wifi.png Binary files differnew file mode 100644 index 0000000..5d1e0d9 --- /dev/null +++ b/src/settingsui/icons/ref/Wifi.png diff --git a/src/settingsui/icons/ref/Wifi1.png b/src/settingsui/icons/ref/Wifi1.png Binary files differnew file mode 100644 index 0000000..f1b1489 --- /dev/null +++ b/src/settingsui/icons/ref/Wifi1.png diff --git a/src/settingsui/icons/ref/Wifi2.png b/src/settingsui/icons/ref/Wifi2.png Binary files differnew file mode 100644 index 0000000..a22b472 --- /dev/null +++ b/src/settingsui/icons/ref/Wifi2.png diff --git a/src/settingsui/icons/ref/Wifi3.png b/src/settingsui/icons/ref/Wifi3.png Binary files differnew file mode 100644 index 0000000..76d412b --- /dev/null +++ b/src/settingsui/icons/ref/Wifi3.png diff --git a/src/settingsui/icons/ref/Wifi4.png b/src/settingsui/icons/ref/Wifi4.png Binary files differnew file mode 100644 index 0000000..5d1e0d9 --- /dev/null +++ b/src/settingsui/icons/ref/Wifi4.png diff --git a/src/settingsui/icons/ref/WifiAnim.png b/src/settingsui/icons/ref/WifiAnim.png Binary files differnew file mode 100644 index 0000000..0694f63 --- /dev/null +++ b/src/settingsui/icons/ref/WifiAnim.png diff --git a/src/settingsui/icons/ref/World.png b/src/settingsui/icons/ref/World.png Binary files differnew file mode 100644 index 0000000..cf6eaf0 --- /dev/null +++ b/src/settingsui/icons/ref/World.png diff --git a/src/settingsui/icons/ref/Wrench.png b/src/settingsui/icons/ref/Wrench.png Binary files differnew file mode 100644 index 0000000..5b6e1c6 --- /dev/null +++ b/src/settingsui/icons/ref/Wrench.png diff --git a/src/settingsui/icons/ref/extra/Alert.png b/src/settingsui/icons/ref/extra/Alert.png Binary files differnew file mode 100644 index 0000000..80914fc --- /dev/null +++ b/src/settingsui/icons/ref/extra/Alert.png diff --git a/src/settingsui/icons/scripts/cimage.sh b/src/settingsui/icons/scripts/cimage.sh new file mode 100755 index 0000000..ae73622 --- /dev/null +++ b/src/settingsui/icons/scripts/cimage.sh @@ -0,0 +1,45 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash + +fullfile=$1 +filename=$(basename "$fullfile") +extension="${filename##*.}" +filename="${filename%.*}" + +color=$2 +if [ "$color" = "qt" ]; then + fill='rgb(128,195,66)' +elif [ "$color" = "black" ]; then + fill='rgb(32,40,42)' +elif [ "$color" = "white" ]; then + fill='rgb(255,255,255)' +elif [ "$color" = "lightgray" ]; then + fill='rgb(214,214,214)' +elif [ "$color" = "red" ]; then + fill='rgb(228,30,37)' +elif [ "$color" = "yellow" ]; then + fill='rgb(250,206,32)' +else + fill="black" +fi + +separator="_" + +convert $fullfile -fuzz 100% -fill $fill -opaque black $filename$separator$color.$extension diff --git a/src/settingsui/icons/scripts/cimages.sh b/src/settingsui/icons/scripts/cimages.sh new file mode 100755 index 0000000..94ac1cd --- /dev/null +++ b/src/settingsui/icons/scripts/cimages.sh @@ -0,0 +1,28 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash + +for dir in "$@" +do + echo "$dir" + scripts/cimage.sh $dir qt + scripts/cimage.sh $dir black + scripts/cimage.sh $dir white + scripts/cimage.sh $dir lightgray +done diff --git a/src/settingsui/icons/scripts/rimage.sh b/src/settingsui/icons/scripts/rimage.sh new file mode 100755 index 0000000..d98088f --- /dev/null +++ b/src/settingsui/icons/scripts/rimage.sh @@ -0,0 +1,37 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash +fullfile=$1 +filename=$(basename "$fullfile") +extension="${filename##*.}" +filename="${filename%.*}" + +postix="_1x" +convert $fullfile -resize x16 $filename$postix.$extension +postix="_2x" +convert $fullfile -resize x32 $filename$postix.$extension +postix="_3x" +convert $fullfile -resize x48 $filename$postix.$extension +postix="_4x" +convert $fullfile -resize x64 $filename$postix.$extension +postix="_5x" +convert $fullfile -resize x80 $filename$postix.$extension +postix="_6x" +convert $fullfile -resize x96 $filename$postix.$extension + diff --git a/src/settingsui/icons/scripts/rimages.sh b/src/settingsui/icons/scripts/rimages.sh new file mode 100755 index 0000000..7b76da8 --- /dev/null +++ b/src/settingsui/icons/scripts/rimages.sh @@ -0,0 +1,25 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash + +for dir in "$@" +do + echo "$dir" + scripts/rimage.sh $dir +done diff --git a/src/settingsui/locale/Language.qml b/src/settingsui/locale/Language.qml new file mode 100644 index 0000000..bdcfbef --- /dev/null +++ b/src/settingsui/locale/Language.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.locale 1.0 +import QtQml 2.2 + +Item { + id: root + property string title: qsTr("Language and Region") + + GroupBox { + id: groupBox + title: qsTr("Regional Format") + anchors.left: parent.left + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: 20 + property var currentRegion: Qt.locale(LocaleManager.locale) + + ColumnLayout { + width: parent.width + + Component { + id: regionSelect + RegionSelect {} + } + GroupBox { + width: parent.width + title: { + if (groupBox.currentRegion.name === "C" || groupBox.currentRegion.name === "POSIX") { + return qsTr("Default"); + } + else if (groupBox.currentRegion.name !== "") { + return qsTr("%L1/%L2").arg(groupBox.currentRegion.nativeLanguageName).arg(groupBox.currentRegion.nativeCountryName) + } + else { + return qsTr("Region not set"); + } + } + ColumnLayout { + spacing: 10 + Layout.fillWidth: true + width: parent.width + + Label { + text: Date().toLocaleString(groupBox.currentRegion) + } + Label { + text: Number(2343.34).toLocaleString(groupBox.currentRegion) + } + Label { + text: Number(41334.34).toLocaleCurrencyString(groupBox.currentRegion) + } + } + } + Button { + text: qsTr("Change region") + onClicked: stackView.push(regionSelect) + } + } + } +} diff --git a/src/settingsui/locale/RegionSelect.qml b/src/settingsui/locale/RegionSelect.qml new file mode 100644 index 0000000..9282177 --- /dev/null +++ b/src/settingsui/locale/RegionSelect.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.locale 1.0 +import "../common" + +Item { + id: root + property string title: qsTr("Select language") + + Component.onCompleted: country.text = LocaleFilter.filter + + ColumnLayout { + id: content + anchors.fill: parent + anchors.margins: 20 + spacing: 10 + RowLayout { + spacing: 10 + + Label { + text: qsTr("Search region: ") + Layout.alignment: Qt.AlignVCenter + } + TextField { + id: country + text: "" + onTextChanged: LocaleFilter.filter = country.text + Layout.alignment: Qt.AlignVCenter + } + } + CustomTableView { + headerTexts: [qsTr("Language"), qsTr("Country")] + roleNames: ["language", "country"] + model: LocaleFilter + onClicked: { + var val = model.itemFromRow(index); + if (val !== "") { + LocaleManager.locale = val; + stackView.pop(); + } + } + } + } +} diff --git a/src/settingsui/main.cpp b/src/settingsui/main.cpp new file mode 100644 index 0000000..9b26327 --- /dev/null +++ b/src/settingsui/main.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the FOO 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 <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/src/settingsui/main.qml b/src/settingsui/main.qml new file mode 100644 index 0000000..1ed1138 --- /dev/null +++ b/src/settingsui/main.qml @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the FOO 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$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import Qt.labs.settings 1.0 +import QtQuick.XmlListModel 2.0 +import QtQuick.Enterprise.VirtualKeyboard 2.0 +import com.theqtcompany.localdevice 1.0 +import "common" + +ApplicationWindow { + id: root + title: qsTr("Device settings") + width: 800 + height: 600 + visible: true + property var service + + header: ToolBar { + id: titlebar + property string title: "" + + RowLayout { + spacing: 20 + anchors.fill: parent + + ToolButton { + label: Image { + source: "../icons/Chevron-left_black_1x.png" + anchors.centerIn: parent + } + visible: stackView.depth > 1 + onClicked: stackView.pop(); + } + Label { + id: titleText + font.pixelSize: 20 + text: stackView.currentItem.title + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + anchors.centerIn: parent + } + ToolButton { + label: Image { + source: "../icons/Power_black_1x.png" + anchors.centerIn: parent + } + anchors.right: parent.right + + visible: stackView.depth === 1 + onClicked: menu.open(); + + Menu { + id: menu + x: parent.width - width + + MenuItem { + text: qsTr("Reboot") + onTriggered: LocalDevice.reboot() + } + MenuItem { + text: qsTr("Shutdown") + onTriggered: LocalDevice.powerOff() + } + } + } + } + } + StackView { + id: stackView + initialItem: mainView + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + + Behavior on anchors.topMargin { NumberAnimation { duration: 250; easing.type: Easing.InOutQuad }} + + Component { + id: mainView + + Item { + property string title: qsTr("Device Settings") + + XmlListModel { + id: xmlModel + source: "settingsview.xml" + query: "/xml/settings/item" + XmlRole { name: "title"; query: "title/string()"} + XmlRole { name: "icon"; query: "icon/string()"} + XmlRole { name: "view"; query: "view/string()"} + XmlRole { name: "path"; query: "path/string()"} + } + GridView { + id: grid + anchors.fill: parent + anchors.margins: 40 + cellHeight: 133 + spacing + cellWidth: 117 + spacing + model: xmlModel + property int spacing: 20 + delegate: MouseArea { + width: grid.cellWidth - grid.spacing + height: grid.cellHeight - grid.spacing + + Rectangle { + anchors.fill: parent + color: "#d6d6d6" + radius: 5 + visible: pressed + } + Column { + anchors.fill: parent + anchors.topMargin: 10 + Image { + id: image + source: icon + anchors.horizontalCenter: parent.horizontalCenter + width: grid.cellWidth + fillMode: Image.PreserveAspectFit + } + Label { + text: title + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: grid.cellHeight * .1 + } + } + onClicked: { + var component = Qt.createComponent(path + '/' +view+'.qml'); + stackView.push(component.createObject(stackView)); + titlebar.title = title + } + } + } + } + } + } + + property var inputItem: InputContext.inputItem + + HandwritingInputPanel { + + id: handwritingInputPanel + anchors.fill: parent + inputPanel: inputPanel + + Rectangle { + z: -1 + anchors.fill: parent + color: "black" + opacity: 0.10 + } + + onAvailableChanged: { + if (!available) + inputPanel.ensureVisible() + } + } + Item { + visible: handwritingInputPanel.enabled && Qt.inputMethod.visible + anchors { left: parent.left; top: parent.top; right: parent.right; bottom: inputPanel.top; } + + HandwritingModeButton { + id: handwritingModeButton + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: 10 + floating: true + flipable: true + width: 76 + height: width + state: handwritingInputPanel.state + onClicked: handwritingInputPanel.active = !handwritingInputPanel.active + onDoubleClicked: handwritingInputPanel.available = !handwritingInputPanel.available + } + } + InputPanel { + id: inputPanel + y: active ? parent.height - inputPanel.height : parent.height + anchors.left: parent.left + anchors.right: parent.right + + Behavior on y { NumberAnimation {duration: 250; easing.type: Easing.InOutQuad}} + + property var inputItem: InputContext.inputItem + + onInputItemChanged: { + if (handwritingInputPanel.available) + return; + + if (inputItem) { + ensureVisible() + } + } + + onActiveChanged: { + if (!active) { + stackView.anchors.topMargin = 0 + + if (!handwritingInputPanel.available && inputItem) + inputItem.focus = false + } + } + + function ensureVisible() { + var mapped = inputItem.mapToItem(handwritingInputPanel, 0,0) + if (mapped.y > (handwritingInputPanel.height-inputPanel.height-40)) { + stackView.anchors.topMargin = -inputPanel.height + } + } + } +} diff --git a/src/settingsui/network/AddressListEntry.qml b/src/settingsui/network/AddressListEntry.qml new file mode 100644 index 0000000..45c161f --- /dev/null +++ b/src/settingsui/network/AddressListEntry.qml @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 + +RowLayout { + id: root + spacing: 10 + property alias model: repeater.model + property bool modified: false + property alias title: label.text + + Label { + id: label + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignTop + Layout.topMargin: 10 + } + ColumnLayout { + spacing: 10 + Layout.fillWidth: true + + Repeater { + id: repeater + visible: count > 0 + RowLayout { + spacing: 10 + TextField { + text: edit + Layout.fillWidth: true + onEditingFinished: { + root.modified = true; + edit = text; + } + } + Button { + Layout.preferredWidth: height + text: "-" + visible: repeater.count > 0 + onClicked: { + root.modified = true; + root.model.remove(index); + } + } + Button { + Layout.preferredWidth: height + visible: index === repeater.count - 1 + text: "+" + onClicked: root.model.append("") + + Layout.alignment: Qt.AlignRight + } + } + } + RowLayout { + visible: repeater.count === 0 + spacing: 10 + TextField { + id: nameServerEntryItem + Layout.fillWidth: true + text: "" + onAccepted: root.model.append(text) + } + Button { + Layout.preferredWidth: height + text: "+" + onClicked: nameServerEntryItem.accepted() + } + } + } +} diff --git a/src/settingsui/network/ComboBoxEntry.qml b/src/settingsui/network/ComboBoxEntry.qml new file mode 100644 index 0000000..791f2d5 --- /dev/null +++ b/src/settingsui/network/ComboBoxEntry.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 + +RowLayout { + id: root + spacing: 10 + width: parent.width + + property alias title: label.text + property alias currentIndex: cb.currentIndex + property alias delegate: cb.delegate + property alias textRole: cb.textRole + property alias model: cb.model + property int titleWidth: -1 + + Label { + id: label + Layout.preferredWidth: root.titleWidth + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignVCenter + } + ComboBox { + id: cb + textRole: "text" + Layout.fillWidth: true + } +} diff --git a/src/settingsui/network/EditWiredSettings.qml b/src/settingsui/network/EditWiredSettings.qml new file mode 100644 index 0000000..48a6abb --- /dev/null +++ b/src/settingsui/network/EditWiredSettings.qml @@ -0,0 +1,372 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + id: root + property string title: qsTr("Ethernet Settings") + property var service: undefined + property bool ipv4Changed: false + property bool ipv6Changed: false + property bool nameserversChanged: false + property bool domainsChanged: false + property bool proxyChanged: false + + Component.onDestruction: { + //Clear all unsaved changes from models + service.proxy.excludes.resetChanges(); + service.nameservers.resetChanges(); + service.domains.resetChanges(); + } + + Component.onCompleted: titlebar.title = service.name; + + Flickable { + anchors.fill: parent + anchors.top: saveButton.bottom + anchors.margins: 20 + contentHeight: content.height + contentWidth: width + + Column { + id: content + width: parent.width + spacing: 10 + property int titleWidth: width * 0.382 + property int groupWidth: width - saveButton.width - 10 + + //IPv4 Config + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("IPv4") + + ColumnLayout { + anchors.fill: parent + + ComboBoxEntry { + title: qsTr("Connection method:") + titleWidth: content.titleWidth + model: ListModel { + id: methodsModel + + ListElement { + text: "DHCP" + method: NetworkSettingsIPv4.Dhcp + } + ListElement { + text: "Manual" + method: NetworkSettingsIPv4.Manual + } + ListElement { + text: "Off" + method: NetworkSettingsIPv4.Off + } + } + Component.onCompleted: currentIndex = service.ipv4.method + onCurrentIndexChanged: { + ipv4Changed = true; + service.ipv4.method = model.get(currentIndex).method; + } + } + + GridLayout { + columnSpacing: 10 + rows: 3 + columns: 2 + visible: service.ipv4.method !== NetworkSettingsIPv4.Off + width: parent.width + + Label { + text: qsTr("Address:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Address + text: service.ipv4.address + onTextChanged: ipv4Changed = true; + onAccepted: if (text.length > 0) service.ipv4.address = text + enabled: service.ipv4.method === NetworkSettingsIPv4.Manual + } + Label { + text: qsTr("Mask:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Mask + text: service.ipv4.mask + onTextChanged: ipv4Changed = true; + onAccepted: if (text.length > 0) service.ipv4.mask = text + enabled: service.ipv4.method === NetworkSettingsIPv4.Manual + } + Label { + text: qsTr("Router:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Gateway + text: service.ipv4.gateway + onTextChanged: ipv4Changed = true + onAccepted: if (text.length > 0) service.ipv4.gateway = text + enabled: service.ipv4.method === NetworkSettingsIPv4.Manual + } + } + } + } + + //IPv6 Config + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("IPv6") + + ColumnLayout { + anchors.fill: parent + + ComboBoxEntry { + title: qsTr("Connection method:") + titleWidth: content.titleWidth + model: ListModel { + id: ipv6methodsmodel + + ListElement { + text: qsTr("Auto") + method: NetworkSettingsIPv6.Auto + } + ListElement { + text: qsTr("Manual") + method: NetworkSettingsIPv6.Manual + } + ListElement { + text: qsTr("Off") + method: NetworkSettingsIPv6.Off + } + } + + Component.onCompleted: currentIndex = service.ipv6.method + + onCurrentIndexChanged: { + ipv6Changed = true; + service.ipv6.method = model.get(currentIndex).method; + } + } + GridLayout { + columnSpacing: 10 + rows: 3 + columns: 2 + visible: service.ipv6.method !== NetworkSettingsIPv6.Off + + Label { + text: qsTr("Address:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6Address + text: service.ipv6.address + Layout.fillWidth: true + onTextChanged: ipv6Changed = true; + onAccepted: if (text.length > 0) service.ipv6.address = text + enabled: service.ipv6.method === NetworkSettingsIPv6.Manual + } + Label { + text: qsTr("Router:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6Gateway + text: service.ipv6.gateway + Layout.fillWidth: true + onTextChanged: ipv6Changed = true; + onAccepted: if (text.length > 0) service.ipv4.gateway = text + enabled: service.ipv6.method === NetworkSettingsIPv6.Manual + } + Label { + text: qsTr("Prefix length:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6PrefixLength + text: service.ipv6.prefixLength + Layout.fillWidth: true + validator: IntValidator { bottom: 0; top: 255 } + onTextChanged: ipv6Changed = true + onAccepted: if (text.length > 0) service.ipv6.prefixLength = parseInt(text) + enabled: service.ipv6.method === NetworkSettingsIPv6.Manual + } + } + } + } + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Name servers") + + ColumnLayout { + anchors.fill: parent + AddressListEntry { + title: qsTr("Address:") + model: service.nameservers + modified: nameserversChanged + } + } + } + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Domains") + + ColumnLayout { + anchors.fill: parent + AddressListEntry { + title: qsTr("Address:") + model: service.domains + modified: domainsChanged + } + } + } + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Proxy Settings") + + ColumnLayout { + id: proxyLayout + width: parent.width + + ComboBoxEntry { + title: qsTr("Configuration:") + titleWidth: content.titleWidth + model: ListModel { + id: proxyMethodModel + + ListElement { + text: qsTr("Direct") + method: NetworkSettingsProxy.Direct + } + ListElement { + text: qsTr("Auto") + method: NetworkSettingsProxy.Auto + } + ListElement { + text: qsTr("Manual") + method: NetworkSettingsProxy.Manual + } + } + Component.onCompleted: currentIndex = service.proxy.method + + onCurrentIndexChanged: { + proxyChanged = true; + service.proxy.method = model.get(currentIndex).method; + } + } + RowLayout { + spacing: 10 + visible: service.proxy.method !== NetworkSettingsProxy.Direct + + Label { + text: service.proxy.method === NetworkSettingsProxy.Manual ? qsTr("Proxy address:") : qsTr("Configuration URL:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignVCenter + elide: Label.ElideRight + } + TextField { + id: proxyUrl + text: service.proxy.url + Layout.fillWidth: true + onTextChanged: proxyChanged = true; + onAccepted: service.proxy.url = text; + } + } + AddressListEntry { + model: service.proxy.excludes + modified: proxyChanged + title: qsTr("No proxy for:") + visible: service.proxy.method === NetworkSettingsProxy.Manual + } + } + } + } + } + Button { + id: saveButton + anchors.right: parent.right + anchors.top: parent.top + anchors.margins: 20 + text: qsTr("Save") + + onClicked: { + if (ipv4Changed) { + ipv4Address.accepted(); + ipv4Mask.accepted(); + ipv4Gateway.accepted(); + service.setupIpv4Config(); + } + + if (ipv6Changed) { + ipv6Address.accepted(); + ipv6Gateway.accepted(); + ipv6PrefixLength.accepted(); + service.setupIpv6Config(); + } + + if (nameserversChanged) { + service.setupNameserversConfig(); + } + + if (domainsChanged) { + service.setupDomainsConfig(); + } + + if (proxyChanged) { + proxyUrl.accepted(); + service.setupNetworkSettingsProxy(); + } + stackView.pop(); + } + } +} diff --git a/src/settingsui/network/IpAddressTextField.qml b/src/settingsui/network/IpAddressTextField.qml new file mode 100644 index 0000000..e7e90ab --- /dev/null +++ b/src/settingsui/network/IpAddressTextField.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 + +TextField { + Layout.fillWidth: true + validator: RegExpValidator { regExp: /^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/ } +} diff --git a/src/settingsui/network/NetworkDetails.qml b/src/settingsui/network/NetworkDetails.qml new file mode 100644 index 0000000..3e71be0 --- /dev/null +++ b/src/settingsui/network/NetworkDetails.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 + +Loader { + id: root + property var selectedInterface:undefined + anchors.fill: parent +} diff --git a/src/settingsui/network/NetworkSettings.qml b/src/settingsui/network/NetworkSettings.qml new file mode 100644 index 0000000..4fb1c0f --- /dev/null +++ b/src/settingsui/network/NetworkSettings.qml @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + property string title: qsTr("Network Settings") + GroupBox { + id: networkSelect + anchors.rightMargin: parent.width * 0.618 + anchors.leftMargin: 20 + anchors.topMargin: 20 + anchors.bottomMargin: 20 + anchors.fill: parent + title: qsTr("Select Connection") + + function stateToStr(serviceState) { + switch (serviceState) { + case NetworkService.Idle: + return qsTr("Idle"); + case NetworkService.Failure: + return qsTr("Failure"); + case NetworkService.Association: + return qsTr("Association"); + case NetworkService.Configuration: + return qsTr("Configuration"); + case NetworkService.Ready: + return qsTr("Ready"); + case NetworkService.Disconnect: + return qsTr("Disconnect"); + case NetworkService.Online: + return qsTr("Online"); + default: + return qsTr("Undefined"); + } + } + ColumnLayout { + width: parent.width + + Repeater { + model: NetworkSettingsManager.interfaces + + RadioButton { + id: btn + Layout.fillWidth: true + implicitHeight: 54 + checkable: true + + label: Rectangle { + color: checked ? "#80c342" : "white" + border.color: "#bdbebf" + border.width: 1 + anchors.fill: parent + + Row { + anchors.fill: parent + spacing: 10 + + Image { + id: typeId + height: parent.height + width: height + } + Column { + height: parent.height * .7 + spacing: 0 + anchors.verticalCenter: parent.verticalCenter + Label { + text: name + } + Label { + text: networkSelect.stateToStr(modelData.state) + font.pixelSize: 12 + } + } + } + } + + onCheckedChanged: { + if (checked) { + networkDetails.selectedInterface = modelData + networkDetails.selectedInterface.scanServices() + if (type === NetworkSettingsType.Wired) { + networkDetails.source = "WiredSettings.qml"; + } + else if (type === NetworkSettingsType.Wifi) { + networkDetails.source = "WifiSettings.qml"; + } + } + } + } + } + } + } + + NetworkDetails { + id: networkDetails + anchors.leftMargin: networkSelect.width + 40 + anchors.topMargin: 20 + anchors.rightMargin: 20 + anchors.bottomMargin: 20 + anchors.fill: parent + } +} diff --git a/src/settingsui/network/WifiSelectorDelegate.qml b/src/settingsui/network/WifiSelectorDelegate.qml new file mode 100644 index 0000000..17ec931 --- /dev/null +++ b/src/settingsui/network/WifiSelectorDelegate.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.network 1.0 + +ItemDelegate { + id: root + autoExclusive: true + checkable: true + property bool connect: modelData["connected"] + width: parent.width + contentItem: Item { + width: root.width + + Label { + id: text + leftPadding: root.indicator.width + root.spacing + anchors.left: parent.left + anchors.top:parent.top + anchors.right: signalMonitor.left + anchors.bottom:parent.bottom + elide: Text.ElideRight + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + text:modelData["name"] + } + WifiSignalMonitor { + id: signalMonitor + anchors.right: parent.right + height: parent.height + width: height + } + } +} diff --git a/src/settingsui/network/WifiSettings.qml b/src/settingsui/network/WifiSettings.qml new file mode 100644 index 0000000..8ad1517 --- /dev/null +++ b/src/settingsui/network/WifiSettings.qml @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + id: root + anchors.fill: parent + Component.onCompleted: NetworkSettingsManager.services.type = NetworkSettingsType.Wifi; + + GroupBox { + id: content + title: qsTr("Wireless Settings") + anchors.fill: parent + + ColumnLayout { + spacing: 20 + width: parent.width + + RowLayout { + spacing: 10 + id: enableSwitch + width: parent.width + + Label { + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + text: selectedInterface.powered ? qsTr("Wi-Fi OFF") : qsTr("Wi-Fi ON") + } + Switch { + checked: selectedInterface.powered + onCheckedChanged: selectedInterface.powered = checked + } + } + RowLayout { + spacing: 10 + width: parent.width + + 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) model.itemFromRow(currentIndex).connectService(); + + delegate: WifiSelectorDelegate { + onConnectChanged: if (connect) networkSelection.currentIndex = networkSelection.find(modelData.name) + } + } + } + GroupBox { + id: connectView + title: qsTr("Enter a password") + visible: false + Layout.fillWidth: true + ColumnLayout { + width: parent.width + + RowLayout { + id: errorView + visible: text.text !== "" + spacing: 10 + property alias text: text.text + + Image { + source: "Alert_yellow_1x.png" + Layout.alignment: Qt.AlignVCenter + } + Text { + id: text + color: "#face20" + text: "" + Layout.alignment: Qt.AlignVCenter + } + } + 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 + width: parent.width + + 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 + } + } + RowLayout { + spacing: 10 + + Button { + text: qsTr("Connect") + onClicked: { + connectView.visible = false + NetworkSettingsUserAgent.setUserCredentials("", password.text) + } + } + Button { + text: qsTr("Cancel") + onClicked: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; + } + } + } + Connections { + target: NetworkSettingsUserAgent + onShowUserCredentialsInput : { + connectView.visible = true + } + onError: { + errorView.visible = true + connectView.visible = true + } + } + } +} diff --git a/src/settingsui/network/WifiSignalMonitor.qml b/src/settingsui/network/WifiSignalMonitor.qml new file mode 100644 index 0000000..40a0837 --- /dev/null +++ b/src/settingsui/network/WifiSignalMonitor.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Item { + id: root + property bool scanning: false + property int signalStrength: 100 + property bool connected: false + + onSignalStrengthChanged: { + sprite.visible = true; + + if (signalStrength < 10) { + sprite.visible = false; + } + else if (signalStrength < 30) { + sprite.currentFrame = 0; + } + else if (signalStrength < 60) { + sprite.currentFrame = 1; + } + else if (signalStrength < 80) { + sprite.currentFrame = 2; + } + else if (signalStrength <= 100) { + sprite.currentFrame = 3; + } + } + + Image { + id: sprite + property int currentFrame: 0 + anchors.fill: parent + source: "Wifi_lightgray_2x.png" + clip: true + + Timer { + id: scanningTimer + running: scanning + interval: 250 + repeat: true + onTriggered: { + if (sprite.currentFrame < 4) + sprite.currentFrame++ + else + sprite.currentFrame = 0 + } + } + + Image { + height: parent.height + width: parent.width * 4 + source: "WifiAnim_black_2x.png" + x: -parent.currentFrame * width / 4 + } + } +} diff --git a/src/settingsui/network/WiredSettings.qml b/src/settingsui/network/WiredSettings.qml new file mode 100644 index 0000000..9359484 --- /dev/null +++ b/src/settingsui/network/WiredSettings.qml @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + id: root + anchors.fill: parent + property bool editMode: false + property var service: null + property string title: qsTr("Network"); + + Component.onCompleted: { + NetworkSettingsManager.services.type = NetworkSettingsType.Wired; + root.service = NetworkSettingsManager.services.itemFromRow(0); + ipv4Method.currentIndex = service.ipv4.method + } + + GroupBox { + title: qsTr("Ethernet Connection") + anchors.fill: parent + + Column { + spacing: 10 + width: parent.width + + ComboBoxEntry { + id: ipv4Method + title: qsTr("Connection method:") + model: ListModel { + id: methodsModel + + ListElement { + text: "DHCP" + method: NetworkSettingsIPv4.Dhcp + } + ListElement { + text: "Manual" + method: NetworkSettingsIPv4.Manual + } + ListElement { + text: "Off" + method: NetworkSettingsIPv4.Off + } + } + + Component.onCompleted: currentIndex = service.ipv4.method + onCurrentIndexChanged: { + if (model.get(currentIndex).method !== NetworkSettingsIPv4.Dhcp) { + service.ipv4.method = model.get(currentIndex).method; + editMode = true; + } + else if (service){ + //Enable DHCP + if (service.ipv4.method !== model.get(currentIndex).method) { + service.ipv4.method = model.get(currentIndex).method; + service.setupIpv4Config(); + } + editMode = false; + } + } + } + GridLayout { + columns: 2 + rows: 4 + width: parent.width + visible: service.ipv4.method !== NetworkSettingsIPv4.Off + + Label { + text: qsTr("IP Address: ") + width: parent.width * .3 + } + IpAddressTextField { + id: ipv4Address + text: service.ipv4.address + enabled: editMode + onAccepted: if (text.length > 0) service.ipv4.address = text + } + Label { + text: qsTr("Mask: ") + } + IpAddressTextField { + id: ipv4Mask + text: service.ipv4.mask + enabled: editMode + onAccepted: if (text.length > 0) service.ipv4.mask = text + } + Label { + text: qsTr("Router: ") + } + IpAddressTextField { + id: ipv4Gateway + text: service.ipv4.gateway + enabled: editMode + onAccepted: if (text.length > 0) service.ipv4.gateway = text + } + Label { + text: qsTr("DNS server: ") + } + Row { + spacing: 10 + Repeater { + model: service.nameservers + + Label { + text: display + } + } + } + } + Row { + spacing: 10 + Button { + text: qsTr("Save") + visible: editMode + + onClicked: { + ipv4Address.accepted(); + ipv4Mask.accepted(); + ipv4Gateway.accepted(); + service.setupIpv4Config(); + editMode = false; + } + } + Button { + text: qsTr("Cancel") + visible: editMode + onClicked: { + editMode = false; + ipv4Method.currentIndex = service.ipv4.method + } + } + } + Button { + text: qsTr("Edit") + visible: !editMode + onClicked: stackView.push(Qt.resolvedUrl("EditWiredSettings.qml"), {service: root.service}); + } + } + } +} diff --git a/src/settingsui/qml.qrc b/src/settingsui/qml.qrc new file mode 100644 index 0000000..cd5d5af --- /dev/null +++ b/src/settingsui/qml.qrc @@ -0,0 +1,28 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>settingsview.xml</file> + <file>network/EditWiredSettings.qml</file> + <file>network/IpAddressTextField.qml</file> + <file>network/NetworkDetails.qml</file> + <file>network/NetworkSettings.qml</file> + <file>network/WifiSelectorDelegate.qml</file> + <file>network/WifiSettings.qml</file> + <file>network/WifiSignalMonitor.qml</file> + <file>network/WiredSettings.qml</file> + <file>bluetooth/Bluetooth.qml</file> + <file>bluetooth/Discovery.qml</file> + <file>display/Display.qml</file> + <file>locale/RegionSelect.qml</file> + <file>locale/Language.qml</file> + <file>timedate/AnalogClock.qml</file> + <file>timedate/TimeDate.qml</file> + <file>timedate/TimezonesView.qml</file> + <file>network/AddressListEntry.qml</file> + <file>network/ComboBoxEntry.qml</file> + <file>timedate/CustomCalendar.qml</file> + <file>common/CustomTableView.qml</file> + <file>common/HandwritingModeButton.qml</file> + <file>timedate/ClockHand.qml</file> + </qresource> +</RCC> diff --git a/src/settingsui/settingsui.pro b/src/settingsui/settingsui.pro new file mode 100644 index 0000000..026d911 --- /dev/null +++ b/src/settingsui/settingsui.pro @@ -0,0 +1,17 @@ +TEMPLATE = app + +QT += qml quick +SOURCES += main.cpp + +RESOURCES += \ + qml.qrc \ + icons.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) + +DISTFILES += \ + settingsview.xml diff --git a/src/settingsui/settingsview.xml b/src/settingsui/settingsview.xml new file mode 100644 index 0000000..4f3b52e --- /dev/null +++ b/src/settingsui/settingsview.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<xml> + <settings> + <item> + <title>Network</title> + <view>NetworkSettings</view> + <path>network</path> + <icon>../icons/World_qt_6x.png</icon> + </item> + <item> + <title>Display</title> + <view>Display</view> + <path>display</path> + <icon>../icons/Display_qt_6x.png</icon> + </item> + <item> + <title>Date and Time</title> + <view>TimeDate</view> + <path>timedate</path> + <icon>../icons/Clock_qt_6x.png</icon> + </item> + <item> + <title>Language</title> + <view>Language</view> + <path>locale</path> + <icon>../icons/Flag_qt_6x.png</icon> + </item> + <item> + <title>Bluetooth</title> + <view>Bluetooth</view> + <path>bluetooth</path> + <icon>../icons/Bluetooth_qt_6x.png</icon> + </item> + </settings> +</xml> diff --git a/src/settingsui/timedate/AnalogClock.qml b/src/settingsui/timedate/AnalogClock.qml new file mode 100644 index 0000000..ff43347 --- /dev/null +++ b/src/settingsui/timedate/AnalogClock.qml @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.timedate 1.0 + +Item { + property var currentTime: TimeManager.time + property var newTime: new Date + property bool editMode: false + property alias handPressed: mouseArea.pressed + + onEditModeChanged: if (editMode) newTime = new Date + + Rectangle { + border.color: "#bdbebf" + border.width: 1 + color: "white" + anchors.fill: parent + + Connections { + target: TimeManager + onTimeChanged: if (!mouseArea.pressed) newTime.setSeconds(currentTime.getSeconds()) + onTimeZoneChanged: Date.timeZoneUpdated() + } + Label { + id: timeLabel + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 10 + anchors.top: parent.top + text: currentTime.toTimeString() + } + Rectangle { + id: root + anchors.fill: parent + anchors.margins: 40 + color: "white" + border.color: editMode ? "#d6d6d6" : "#5caa15" + border.width: Math.round(root.width * 0.120) + radius: parent.width / 2 + property int handOffset: Math.round(root.width * 0.040) + antialiasing: true + + MouseArea { + id: mouseArea + anchors.fill: parent + enabled: editMode + property var handleItem: undefined + + function findHandle(item, point) { + if (item.objectName === "handle") { + var mapped = mouseArea.mapToItem(item, point.x, point.y) + if (item.contains(mapped)) { + return item.parent; + } + } + + for (var i=0; i < item.children.length; i++) { + var ret = findHandle(item.children[i], point) + if (ret) + return ret; + } + return undefined; + } + + onPressed: { + handleItem = findHandle(root, Qt.point(mouse.x, mouse.y)) + currentTime.setSeconds(0); + currentTime.setMilliseconds(0); + newTime.setSeconds(0); + newTime.setMilliseconds(0); + } + + onReleased: { + handleItem = undefined + } + + onPositionChanged: { + if (!handleItem) + return; + + var angle = (90 + Math.atan2((mouse.y-mouseArea.height/2), (mouse.x-mouseArea.width/2))*180/Math.PI) + + if (handleItem.angle < 60 && handleItem.angle > 0 && angle <= 0) { + + if (handleItem === hours) { + hours.pm = !hours.pm + } else { + var a = hours.angle - 30 + if (a > 360) a -= 360 + hours.angle = a + } + + } else if (handleItem.angle > 300 && handleItem.angle < 360 && angle >= 0) { + + if (handleItem === hours) { + hours.pm = !hours.pm + } else { + var a = hours.angle + 30 + if (a < 0) a += 360 + hours.angle = a + } + } + + if (angle < 0) { + angle += 360 + } else if (angle > 360) { + angle -= 360 + } + + handleItem.angle = angle + + var newhours = Math.floor(hours.angle / 30); + if (hours.pm) + newhours += 12 + + newTime.setHours(newhours); + newTime.setMinutes(Math.round(minutes.angle / 6)); + + newTime.setSeconds(0); + newTime.setMilliseconds(0); + + TimeManager.time = newTime; + } + } + ClockHand { + id: minutes + value: currentTime.getMinutes() * 6 + } + ClockHand { + id: hours + height: root.height / 2 * 0.4 + root.handOffset + value: (currentTime.getHours() * 30) + (currentTime.getMinutes() * 0.5) + property bool pm: false + } + ClockHand { + id: seconds + visible: !editMode + color: "#46a2da" + width: root.width * 0.0128 + height: root.height / 2 * 0.74 + value: currentTime.getSeconds() * 6 + } + } + } +} diff --git a/src/settingsui/timedate/ClockHand.qml b/src/settingsui/timedate/ClockHand.qml new file mode 100644 index 0000000..a25a3af --- /dev/null +++ b/src/settingsui/timedate/ClockHand.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Rectangle { + id: hand + objectName: "hand" + x: root.height / 2 - width / 2 + y: root.height / 2 - height + root.handOffset + color: editMode ? "#d6d6d6" : "#5caa15" + width: root.width * 0.080 + height: root.height / 2 * 0.65 + root.handOffset + antialiasing: true + property alias angle: handRotation.angle + property alias value: angleBinding.value + transform: Rotation { + id: handRotation + origin.x: Math.round(hand.width / 2) + origin.y: Math.round(hand.height - root.handOffset) + Behavior on angle { + enabled: !mouseArea.pressed + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + + Binding on angle { + id: angleBinding + when: !mouseArea.pressed + } + } + Item { + objectName: "handle" + anchors.verticalCenter: parent.top + anchors.horizontalCenter: parent.horizontalCenter + height: parent.width * 3 + width: parent.width * 3 + visible: editMode + Rectangle { + anchors.fill: parent + anchors.margins: parent.width * .1 + radius: width / 2 + color: "#5caa15" + } + } +} diff --git a/src/settingsui/timedate/CustomCalendar.qml b/src/settingsui/timedate/CustomCalendar.qml new file mode 100644 index 0000000..09d4e3e --- /dev/null +++ b/src/settingsui/timedate/CustomCalendar.qml @@ -0,0 +1,221 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import Qt.labs.calendar 1.0 +import QtQml 2.2 +import com.theqtcompany.settings.timedate 1.0 + +Rectangle { + id: root + border.color: "#bdbebf" + border.width: 1 + color: "white" + height: cal.height + + function updateDate() { + var date = new Date() + grid.month = date.getMonth() + grid.date = date.getDate() + grid.year = date.getFullYear() + } + + ColumnLayout { + id: cal + width: root.width + spacing: 10 + enabled: !automatic.checked + + RowLayout { + spacing: 0 + Layout.alignment: Qt.AlignTop + + Button { + id: previousMonth + Layout.preferredWidth: height + visible: enabled + label: Rectangle { + anchors.fill: parent + color: "#d6d6d6" + + Image { + anchors.centerIn: parent + source: "../icons/Chevron-left_black_1x.png" + } + } + onClicked: { + if (grid.month === Calendar.January) { + grid.year-- + grid.month = Calendar.December + return; + } + grid.month-- + } + } + Rectangle { + Layout.fillWidth: true + color: enabled ? "#d6d6d6" : "#80c342" + height: previousMonth.height + + Label { + id: title + text: Qt.locale().monthName(grid.month, Locale.LongFormat) + " " + grid.year + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + Button { + id: nextMonth + Layout.preferredWidth: height + visible: enabled + label: Rectangle { + anchors.fill: parent + color: "#d6d6d6" + + Image { + anchors.centerIn: parent + source: "../icons/Chevron-left_black_1x.png" + mirror: true + } + } + onClicked: { + if (grid.month === Calendar.December) { + grid.year++ + grid.month = Calendar.January + } + grid.month++ + } + } + } + DayOfWeekRow { + locale: grid.locale + Layout.column: 1 + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + delegate: Text { + text: model.narrowName.charAt(0) + font.bold: true + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + MonthGrid { + id: grid + Layout.alignment: Qt.AlignTop + Layout.fillWidth: true + property int date: -1 + property Item currentItem: null + delegate: Label { + id: gridDelegate + objectName: "gridDelegate" + text: delegateDay + opacity: model.month === grid.month ? 1 : .2 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.bold: delegateDay === grid.date && delegateMonth === grid.month + color: delegateDay === grid.date && delegateMonth === grid.month && enabled ? "white" : "black" + property int delegateDay: model.day + property int delegateMonth: model.month + } + Component.onCompleted: updateDate() + + Rectangle { + z: -1 + id: highlight + x: grid.currentItem ? grid.currentItem.x + grid.currentItem.width / 2 - width / 2: 0 + y: grid.currentItem ? grid.currentItem.y + grid.currentItem.height / 2- height / 2: 0 + width: grid.currentItem ? grid.currentItem.width : 0 + visible: grid.currentItem + height: width + color: enabled? "#80c342" : "#d6d6d6" + radius: width / 2 + } + + onMonthChanged: updateHighlightPosition() + onYearChanged: updateHighlightPosition() + onDateChanged: updateHighlightPosition() + + function updateHighlightPosition() { + var date = new Date() + + date.setFullYear(grid.year) + date.setMonth(grid.month) + date.setDate(grid.date) + + var index = grid.source.indexOf(date) + var delegate = grid.contentItem.children[index] + + if (delegate) + grid.currentItem = delegate + } + + MouseArea { + anchors.fill: parent + + onClicked: { + var item = grid.contentItem.childAt(mouse.x, mouse.y) + + if (item) { + if (item.objectName !== "gridDelegate") + item = grid.contentItem.children[0] + + if (!item) + return; + + grid.currentItem = item + grid.date = item.delegateDay + grid.month = item.delegateMonth + + var currentTime = TimeManager.time; + var newDate = new Date(); + + newDate.setFullYear(grid.year) + newDate.setMonth(grid.month) + newDate.setDate(grid.date) + newDate.setHours(currentTime.getHours()); + newDate.setMinutes(currentTime.getMinutes()); + newDate.setSeconds(currentTime.getSeconds()); + TimeManager.time = newDate; + } + } + } + } + } +} diff --git a/src/settingsui/timedate/TimeDate.qml b/src/settingsui/timedate/TimeDate.qml new file mode 100644 index 0000000..cc46b78 --- /dev/null +++ b/src/settingsui/timedate/TimeDate.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.timedate 1.0 + +Item { + id: root + property string title: qsTr("Time and Date settings") + + Flickable { + id: flickable + anchors.margins: 20 + anchors.fill: parent + contentHeight: content.height + contentWidth: width + interactive: !clock.handPressed + + ColumnLayout { + id: content + spacing: 20 + width: parent.width + + GroupBox { + width: parent.width + title: qsTr("Time Settings") + Layout.fillWidth: true + + ColumnLayout { + spacing: 10 + width: parent.width + Layout.fillWidth: true + + RadioButton { + id: automatic + text: qsTr("Automatic time set") + checked: TimeManager.ntp + onCheckedChanged: if (checked) updateTimer.restart() + + Timer { + id: updateTimer + interval: 300 + onTriggered: calendar.updateDate() + } + } + RadioButton { + id: custom + text: qsTr("Manual") + checked: !TimeManager.ntp + onCheckedChanged: TimeManager.ntp = !checked + } + RowLayout + { + id: layout + spacing: 10 + + CustomCalendar { + id: calendar + width: height + } + AnalogClock { + id: clock + height: calendar.height + width: height + editMode: !automatic.checked + } + } + Component { + id: zoneselect + TimezonesView { } + } + } + } + GroupBox { + title: qsTr("Timezone Settings") + Layout.fillWidth: true + width: parent.width + visible: true + + RowLayout { + spacing: 10 + Label { + text: TimeManager.timeZone + Layout.alignment: Qt.AlignVCenter + } + Button { + text: qsTr("Change") + onClicked : stackView.push(zoneselect) + } + } + } + } + } +} diff --git a/src/settingsui/timedate/TimezonesView.qml b/src/settingsui/timedate/TimezonesView.qml new file mode 100644 index 0000000..16ac10e --- /dev/null +++ b/src/settingsui/timedate/TimezonesView.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import Qt.labs.controls 1.0 +import Qt.labs.controls.material 1.0 +import Qt.labs.controls.universal 1.0 +import com.theqtcompany.settings.timedate 1.0 +import "../common" + +Item { + id: root + property string title: qsTr("Timezone settings") + Component.onCompleted: timezone.text = TimezonesFilter.filter + + ColumnLayout { + id: content + anchors.fill: parent + anchors.margins: 20 + spacing: 10 + + RowLayout { + spacing: 10 + + Label { + text: qsTr("Search area: ") + Layout.alignment: Qt.AlignVCenter + } + TextField { + id: timezone + text: "" + onTextChanged: TimezonesFilter.filter = timezone.text + Layout.alignment: Qt.AlignVCenter + } + } + CustomTableView { + headerTexts: [qsTr("Timezone"), qsTr("Country")] + roleNames: ["id", "country"] + model: TimezonesFilter + onClicked: { + var val = model.itemFromRow(index); + if (val !== "") { + TimeManager.timeZone = val; + stackView.pop(); + } + } + } + } +} diff --git a/src/src.pro b/src/src.pro index ebe58b5..1cbf0ed 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,7 +1,12 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS += \ - utils \ - wifi \ + networksettings \ + bluetoothsettings \ + localesettings \ + displaysettings \ + timedatesettings \ + localdevice \ + settingsui \ imports \ doc diff --git a/src/timedatesettings/systemtime.cpp b/src/timedatesettings/systemtime.cpp new file mode 100644 index 0000000..c84b036 --- /dev/null +++ b/src/timedatesettings/systemtime.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "systemtime.h" +#include "systemtime_p.h" + +SystemTime::SystemTime(QObject *parent) : + QObject(parent) + ,d_ptr(new SystemTimePrivate(this)) +{ + QTimer *secTimer = new QTimer(this); + connect(secTimer, &QTimer::timeout, this, &SystemTime::timeChanged); + secTimer->setInterval(1001); + secTimer->setSingleShot(false); + secTimer->start(); +} + +bool SystemTime::ntp() const +{ + const Q_D(SystemTime); + return d->ntp(); +} + +void SystemTime::setNtp(const bool aNtp) +{ + Q_D(SystemTime); + d->setNtp(aNtp); +} + +void SystemTime::setTime(const QDateTime& aTime) +{ + Q_D(SystemTime); + d->setTime(aTime.toMSecsSinceEpoch()*1000); + emit timeChanged(); +} + +QString SystemTime::timeZone() const +{ + Q_D(const SystemTime); + return d->timeZone(); +} + +void SystemTime::setTimeZone(const QString& aTimeZone) +{ + Q_D(SystemTime); + d->setTimeZone(aTimeZone); + emit timeZoneChanged(); +} + +QDateTime SystemTime::time() const +{ + return QDateTime::currentDateTime(); +} diff --git a/src/timedatesettings/systemtime.h b/src/timedatesettings/systemtime.h new file mode 100644 index 0000000..2f61ab5 --- /dev/null +++ b/src/timedatesettings/systemtime.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SYSTEMTIME_H +#define SYSTEMTIME_H + +#include <QObject> +#include <QTime> + +class SystemTimePrivate; + +class Q_DECL_EXPORT SystemTime : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged) + 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 = 0); + bool ntp() const; + void setNtp(const bool aNtp); + void setTime(const QDateTime& aTime); + QString timeZone() const; + QDateTime time() const; + void setTimeZone(const QString& aTimeZone); + +signals: + void timeZoneChanged(); + void ntpChanged(); + void timeChanged(); + +public slots: + +protected: + SystemTimePrivate *d_ptr; + + Q_DISABLE_COPY(SystemTime) + Q_DECLARE_PRIVATE(SystemTime) +}; + +#endif // SYSTEMTIME_H diff --git a/src/timedatesettings/systemtime_p.h b/src/timedatesettings/systemtime_p.h new file mode 100644 index 0000000..5722259 --- /dev/null +++ b/src/timedatesettings/systemtime_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SYSTEMTIME_P_H +#define SYSTEMTIME_P_H + +#include "systemtime.h" +#include "timedated_interface.h" + +class SystemTimePrivate +{ + Q_DECLARE_PUBLIC(SystemTime) +public: + SystemTimePrivate(SystemTime *qq) + :q_ptr(qq) + { + m_timeInterface = new OrgFreedesktopTimedate1Interface(QStringLiteral("org.freedesktop.timedate1"), + QStringLiteral("/org/freedesktop/timedate1"), + QDBusConnection::systemBus(), qq); + + } + + bool ntp() const { + if (m_timeInterface) + return m_timeInterface->nTP(); + return false; + } + + void setNtp(bool val) { + if (m_timeInterface) + m_timeInterface->SetNTP(val, true); + } + + QString timeZone() const { + if (m_timeInterface) + return m_timeInterface->timezone(); + return QString(); + } + + void setTimeZone(const QString& aTimeZone) { + if (m_timeInterface) + m_timeInterface->SetTimezone(aTimeZone, true); + } + + void setTime(qlonglong usecsSinceEpoch) { + if (m_timeInterface) + m_timeInterface->SetTime(usecsSinceEpoch, false, true); + } + +private: + OrgFreedesktopTimedate1Interface *m_timeInterface; + SystemTime *q_ptr; +}; + + +#endif // SYSTEMTIME_P_H diff --git a/src/timedatesettings/timedated.xml b/src/timedatesettings/timedated.xml new file mode 100644 index 0000000..95bafb8 --- /dev/null +++ b/src/timedatesettings/timedated.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> +<node> + <interface name="org.freedesktop.timedate1"> + <property name="Timezone" type="s" access="read"/> + <property name="LocalRTC" type="b" access="read"/> + <property name="CanNTP" type="b" access="read"/> + <property name="NTP" type="b" access="read"/> + <method name="SetTime"> + <arg name="usec_utc" type="x" direction="in"/> + <arg name="relative" type="b" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + <method name="SetTimezone"> + <arg name="timezone" type="s" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + <method name="SetLocalRTC"> + <arg name="local_rtc" type="b" direction="in"/> + <arg name="fix_system" type="b" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + <method name="SetNTP"> + <arg name="use_ntp" type="b" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + </interface> +</node> + + diff --git a/src/timedatesettings/timedateplugin.pro b/src/timedatesettings/timedateplugin.pro new file mode 100644 index 0000000..d82529d --- /dev/null +++ b/src/timedatesettings/timedateplugin.pro @@ -0,0 +1,42 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml dbus + +uri = com.theqtcompany.settings.timedate + +DBUS_INTERFACES = timedated.xml + +DESTDIR = imports/TimeDate +TARGET = qmltimedatesettingsplugin + +SOURCES += plugin.cpp \ + systemtime.cpp \ + timezonemodel.cpp \ + timezonefiltermodel.cpp + +pluginfiles.files += \ + qmldir + + +pluginfiles.files += \ + AnalogClock.qml \ + TimeDate.qml \ + TimezonesView.qml \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles + + +RESOURCES += \ + icons.qrc + +HEADERS += \ + systemtime.h \ + systemtime_p.h \ + timezonemodel.h \ + timezonefiltermodel.h + + diff --git a/src/timedatesettings/timedatesettings.pro b/src/timedatesettings/timedatesettings.pro new file mode 100644 index 0000000..6f3f4e9 --- /dev/null +++ b/src/timedatesettings/timedatesettings.pro @@ -0,0 +1,23 @@ +load(qt_build_config) + +TARGET = QtTimeDateSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core dbus + +MODULE = timedatesettings +load(qt_module) + +DBUS_INTERFACES = timedated.xml + +SOURCES += systemtime.cpp \ + timezonemodel.cpp \ + timezonefiltermodel.cpp + +HEADERS += \ + systemtime.h \ + systemtime_p.h \ + timezonemodel.h \ + timezonefiltermodel.h + diff --git a/src/timedatesettings/timezonefiltermodel.cpp b/src/timedatesettings/timezonefiltermodel.cpp new file mode 100644 index 0000000..472ec9f --- /dev/null +++ b/src/timedatesettings/timezonefiltermodel.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "timezonemodel.h" +#include "timezonefiltermodel.h" + +TimezoneFilterModel::TimezoneFilterModel(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &TimezoneFilterModel::filterChanged, this, &TimezoneFilterModel::invalidate); + TimezoneModel* timezoneModel = new TimezoneModel(this); + setSourceModel(timezoneModel); +} + +TimezoneFilterModel::~TimezoneFilterModel() +{ + +} + +QString TimezoneFilterModel::filter() const +{ + return m_filter; +} + +void TimezoneFilterModel::setFilter(const QString& aFilter) +{ + m_filter = aFilter; + emit filterChanged(); +} + +bool TimezoneFilterModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + bool ret = false; + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + QVariant nameRole = index.data(TimezoneModel::Name); + if (nameRole.isValid()) + { + QString name = nameRole.toString(); + if (name.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + QVariant countryRole = index.data(TimezoneModel::Country); + if (ret == false && countryRole.isValid()) + { + QString country = countryRole.toString(); + if (country.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + } + } + return ret; +} + +QVariant TimezoneFilterModel::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant nameRole = mapped.data(TimezoneModel::Name); + if (nameRole.isValid()) + { + return nameRole; + } + } + return QVariant(); +} + diff --git a/src/timedatesettings/timezonefiltermodel.h b/src/timedatesettings/timezonefiltermodel.h new file mode 100644 index 0000000..62c65c9 --- /dev/null +++ b/src/timedatesettings/timezonefiltermodel.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TIMEZONEFILTERMODEL_H +#define TIMEZONEFILTERMODEL_H + +#include <QSortFilterProxyModel> + +class Q_DECL_EXPORT TimezoneFilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) +public: + explicit TimezoneFilterModel(QObject* parent); + virtual ~TimezoneFilterModel(); + bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; + QString filter() const; + void setFilter(const QString& aFilter); + Q_INVOKABLE QVariant itemFromRow(const int row) const; +signals: + void filterChanged(); +private: + QString m_filter; + +}; + +#endif // TIMEZONEFILTERMODEL_H diff --git a/src/timedatesettings/timezonemodel.cpp b/src/timedatesettings/timezonemodel.cpp new file mode 100644 index 0000000..cca90eb --- /dev/null +++ b/src/timedatesettings/timezonemodel.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QLocale> +#include <QFuture> +#include <QThread> +#include <QtConcurrent/QtConcurrentRun> +#include "timezonemodel.h" + +TimezoneItem::TimezoneItem(const QByteArray& id, QObject *parent) + :QObject(parent) +{ + QTimeZone tz = QTimeZone(id); + m_name = tz.displayName(QTimeZone::StandardTime); + m_country = QLocale::countryToString(tz.country()); + m_id = QString::fromUtf8(id); +} + +QString TimezoneItem::name() const +{ + return m_name; +} + +QString TimezoneItem::country() const +{ + return m_country; +} + +QString TimezoneItem::id() const +{ + return m_id; +} + +TimezoneModel::TimezoneModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Country, "country"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(Id, "id"); + + QFuture<void> t1 = QtConcurrent::run(TimezoneModel::generateModel, this); +} + +void TimezoneModel::generateModel(TimezoneModel* model) +{ + QList<QByteArray> ids = QTimeZone::availableTimeZoneIds(); + foreach (QByteArray id, ids) { + TimezoneItem *zone = new TimezoneItem(id); + zone->moveToThread(model->thread()); + QMetaObject::invokeMethod(model, "addNewItem", Q_ARG( QObject*, qobject_cast<QObject*>(zone))); + } +} + +void TimezoneModel::addNewItem(QObject* item) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + TimezoneItem* newItem = qobject_cast<TimezoneItem*>(item); + if (newItem) + m_items.append(newItem); + endInsertRows(); +} + +TimezoneModel::~TimezoneModel() +{ + qDeleteAll(m_items); +} + +QHash<int, QByteArray> TimezoneModel::roleNames() const +{ + return m_roleNames; +} + + +int TimezoneModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant TimezoneModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + TimezoneItem *item = m_items[index.row()]; + + switch (role) { + case Qt::UserRole: + return QVariant::fromValue(static_cast<QObject*>(item)); + break; + case Name: + return item->id(); + break; + case Country: + return item->country(); + break; + case Id: + return item->id(); + break; + case Qt::DisplayRole: + return item->id(); + break; + default: + return QVariant(); + } +} diff --git a/src/timedatesettings/timezonemodel.h b/src/timedatesettings/timezonemodel.h new file mode 100644 index 0000000..a57be04 --- /dev/null +++ b/src/timedatesettings/timezonemodel.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TIMEZONEMODEL_H +#define TIMEZONEMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <QTimeZone> +#include <QMutex> + +class TimezoneItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString country READ country CONSTANT) +public: + explicit TimezoneItem(const QByteArray& id, QObject *parent=0); + QString name() const; + QString country() const; + QString id() const; + +private: + QString m_name; + QString m_country; + QString m_id; +}; + +class Q_DECL_EXPORT TimezoneModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit TimezoneModel(QObject *parent=0); + virtual ~TimezoneModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + enum Roles { + Name = Qt::UserRole + 1, + Country, + Id + }; + + static void generateModel(TimezoneModel* model); + +private slots: + void addNewItem(QObject* item); + +private: + QList<TimezoneItem*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +#endif // TIMEZONEMODEL_H diff --git a/src/utils/b2qtdevice.cpp b/src/utils/b2qtdevice.cpp deleted file mode 100644 index 85006f8..0000000 --- a/src/utils/b2qtdevice.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "b2qtdevice.h" -#include <unistd.h> -#include <QDebug> -#include <math.h> -#include <sys/reboot.h> -#include <QNetworkInterface> -#include <QHostInfo> -#include <QFile> -#include <QDirIterator> -#include <QTimer> -#include <QtCore/qmath.h> - -// When we can't query directly, at least remember what we have set it to -static quint8 knownBrightness = 255; - -B2QtDevice::B2QtDevice(QObject *parent) - : QObject(parent) -{ -} - -B2QtDevice::~B2QtDevice() -{ -} - -/*! - * Reboots the system. Does not return. - * - * \sa powerOff() - */ -void B2QtDevice::reboot() -{ - sync(); - ::reboot(RB_AUTOBOOT); - qWarning("reboot returned"); -} - - -/*! - * Shuts down the system. Does not return. - * - * \sa reboot() - */ -void B2QtDevice::powerOff() -{ - sync(); - ::reboot(RB_POWER_OFF); - qWarning("powerOff returned"); -} - - -class LightDevice -{ -public: - QString name; - QString deviceFile; - quint8 value; - uint maxValue; -}; - -static QList<LightDevice> lightDevices; -static bool lightDevicesInitialized = false; - -static void initLightDevices() -{ - if (lightDevicesInitialized) - return; - QDirIterator it(QStringLiteral("/sys/class/backlight")); - while (it.hasNext()) { - LightDevice ld; - ld.deviceFile = it.next() + QStringLiteral("/brightness"); - QFile maxFile(it.filePath() + QStringLiteral("/max_brightness")); - if (!maxFile.open(QIODevice::ReadOnly)) - continue; - bool ok = false; - ld.maxValue = maxFile.read(10).simplified().toUInt(&ok); - if (!ok || !ld.maxValue) - continue; - QFile valFile(ld.deviceFile); - if (!valFile.open(QIODevice::ReadOnly)) - continue; - ok = false; - uint val = valFile.read(10).simplified().toUInt(&ok); - if (!ok) - continue; - // map max->max as that is a common case, otherwise choose a reasonable value - ld.value = (val == ld.maxValue) ? 255 : (val * 256)/(ld.maxValue+1); - ld.name = it.fileName(); - lightDevices.append(ld); - } - if (!lightDevices.isEmpty()) - knownBrightness = lightDevices.at(0).value; - lightDevicesInitialized = true; -} - -/*! - * Sets the display brightness (i.e. the intensity of the backlight) - * to \a value. A value of 255 requests maximum brightness, while 0 requests - * minimum (typically, the backlight turned off). - * - * Returns true on success. - */ -bool B2QtDevice::setDisplayBrightness(int v) -{ - quint8 value = qBound(0, v, 255); - initLightDevices(); - for (int i = 0; i < lightDevices.size(); i++) { - LightDevice &ld = lightDevices[i]; - QFile devFile(ld.deviceFile); - if (!devFile.open(QIODevice::WriteOnly)) - continue; - // Maps only 0 to 0, since 0 often means "off"; other values are degrees of "on". - uint newVal = value ? 1 + ((value * ld.maxValue) / 256) : 0; - devFile.write(QByteArray::number(newVal)); - ld.value = value; - } - knownBrightness = value; - return true; -} - - -/*! - * Returns the current backlight intensity. - * \sa setDisplayBrightness - */ -int B2QtDevice::displayBrightness() const -{ - initLightDevices(); - return knownBrightness; -} - - -/*! - * Gets the current IP address(es) of the device - */ -QString B2QtDevice::getIPAddress() const -{ - QStringList addresses; - foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces()) { - QNetworkInterface::InterfaceFlags flags = interface.flags(); - if (flags.testFlag(QNetworkInterface::IsRunning) && !flags.testFlag(QNetworkInterface::IsLoopBack)) { - foreach (const QNetworkAddressEntry &entry, interface.addressEntries()) - addresses.append(entry.ip().toString().split('%').first()); - } - } - return addresses.join(QStringLiteral(", ")); -} - - -/*! - * Gets the current hostname of the device - */ -QString B2QtDevice::hostname() const -{ - QString name; - name = QHostInfo::localHostName(); - return name; -} - - -/*! - * Sets new hostname for the device - */ -bool B2QtDevice::setHostname(const QString &name) -{ - QByteArray lname = name.toLocal8Bit(); - if (::sethostname(lname.constData(), lname.length())) { - qWarning("Could not set system hostname"); - return false; - } - // Also store it for next boot: - QFile file(QStringLiteral("/etc/hostname")); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qWarning("Could not write to /etc/hostname"); - return false; - } - file.write(lname.append('\n')); - file.close(); - - emit hostnameChanged(name); - return true; -} - - -/*! - * Sets the master volume to \a volume. - * The volume can range from 0 to 100 and is linear. - */ -void B2QtDevice::setMasterVolume(int volume) -{ - Q_UNUSED(volume) -} - - -/*! - * Returns the current master volume. - * The volume can range from 0 to 100 and is linear. - */ -int B2QtDevice::masterVolume() const -{ - return 0; -} - - -/*! - * Initializes the audio subsystem, setting the volume to max. - * This is done during system startup, so there is normally no need to call this function from applications. - */ -void B2QtDevice::initAudio() -{ -} - - -class PhysicalScreenSize : public QObject -{ - Q_OBJECT - -public: - PhysicalScreenSize(); - - void setSize(int inches); - int size() const { return physScreenSizeInch; } - bool enabled() const; - void setEnabled(bool enable); - -private slots: - void onTimeout(); - -private: - void read(const QString &filename); - void write(bool includePhysSize = true); - void write(const QString &filename, bool includePhysSize = true); - - bool physScreenSizeEnabled; - int physScreenSizeInch; - QTimer physWriteTimer; -}; - -Q_GLOBAL_STATIC(PhysicalScreenSize, physScreenSize) - -PhysicalScreenSize::PhysicalScreenSize() - : physScreenSizeEnabled(false), physScreenSizeInch(7) -{ - physWriteTimer.setSingleShot(true); - physWriteTimer.setInterval(1000); - QObject::connect(&physWriteTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); - - read(QStringLiteral("/etc/appcontroller.conf")); - read(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf")); -} - -void PhysicalScreenSize::read(const QString &filename) -{ - QFile f(filename); - if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) - return; - - int physScreenWidth = 154, physScreenHeight = 90; - int found = 0; - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); - if (line.startsWith(QByteArrayLiteral("env="))) { - QByteArrayList values = line.split('='); - if (values.count() == 3) { - bool ok; - if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_WIDTH")) { - int val = values[2].toInt(&ok); - if (ok) { - ++found; - physScreenWidth = val; - } - } else if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_HEIGHT")) { - int val = values[2].toInt(&ok); - if (ok) { - ++found; - physScreenHeight = val; - } - } - } - } - } - if (found == 2) - physScreenSizeEnabled = true; - - const qreal diagMM = qSqrt(physScreenWidth * physScreenWidth + physScreenHeight * physScreenHeight); - physScreenSizeInch = qRound(diagMM / 25.4); -} - -void PhysicalScreenSize::onTimeout() -{ - write(); -} - -void PhysicalScreenSize::write(bool includePhysSize) -{ - QDir(QStringLiteral("/var/lib")).mkpath(QStringLiteral("b2qt/appcontroller.conf.d")); - write(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf"), includePhysSize); -} - -void PhysicalScreenSize::write(const QString &filename, bool includePhysSize) -{ - QFile f(filename); - - QByteArrayList lines; - if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); - if (!line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=")) - && !line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_HEIGHT="))) - lines.append(line); - } - f.close(); - } - - if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) - return; - - const qreal diagMM = physScreenSizeInch * 25.4; - // Assume 16:9 aspect ratio - const int physScreenHeight = qRound(diagMM / 1.975); - const int physScreenWidth = qRound(physScreenHeight * 1.777); - - foreach (const QByteArray &line, lines) - f.write(line + QByteArrayLiteral("\n")); - - if (includePhysSize) - f.write(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=") + QByteArray::number(physScreenWidth) - + QByteArrayLiteral("\nenv=QT_QPA_EGLFS_PHYSICAL_HEIGHT=") + QByteArray::number(physScreenHeight) - + QByteArrayLiteral("\n")); -} - -void PhysicalScreenSize::setSize(int inches) -{ - physScreenSizeInch = inches; - physWriteTimer.start(); -} - -bool PhysicalScreenSize::enabled() const -{ - return physScreenSizeEnabled; -} - -void PhysicalScreenSize::setEnabled(bool enable) -{ - physScreenSizeEnabled = enable; - // Rewrite appcontroller.conf with or without the physical width/height lines. - write(enable); -} - -int B2QtDevice::physicalScreenSizeInch() const -{ - return physScreenSize()->size(); -} - -void B2QtDevice::setPhysicalScreenSizeInch(int inches) -{ - if (physScreenSize()->size() != inches) { - physScreenSize()->setSize(inches); - emit physicalScreenSizeInchChanged(inches); - } -} - -bool B2QtDevice::physicalScreenSizeOverride() const -{ - return physScreenSize()->enabled(); -} - -void B2QtDevice::setPhysicalScreenSizeOverride(bool enable) -{ - if (physScreenSize()->enabled() != enable) { - physScreenSize()->setEnabled(enable); - emit physicalScreenSizeOverrideChanged(enable); - } -} - -#include "b2qtdevice.moc" diff --git a/src/utils/b2qtdevice.h b/src/utils/b2qtdevice.h deleted file mode 100644 index 288f62d..0000000 --- a/src/utils/b2qtdevice.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef B2QTDEVICE_H -#define B2QTDEVICE_H - -#include <qobject.h> - -class Q_DECL_EXPORT B2QtDevice : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int displayBrightness READ displayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged) - Q_PROPERTY(QString hostname READ hostname WRITE setHostname NOTIFY hostnameChanged) - Q_PROPERTY(QString ipAddress READ getIPAddress NOTIFY ipAddressChanged) - Q_PROPERTY(int masterVolume READ masterVolume WRITE setMasterVolume NOTIFY masterVolumeChanged) - Q_PROPERTY(int physicalScreenSizeInch READ physicalScreenSizeInch WRITE setPhysicalScreenSizeInch NOTIFY physicalScreenSizeInchChanged) - Q_PROPERTY(bool physicalScreenSizeOverride READ physicalScreenSizeOverride WRITE setPhysicalScreenSizeOverride NOTIFY physicalScreenSizeOverrideChanged) - -public: - B2QtDevice(QObject *parent = 0); - ~B2QtDevice(); - - int displayBrightness() const; - QString hostname() const; - QString getIPAddress() const; - int masterVolume() const; - int physicalScreenSizeInch() const; - bool physicalScreenSizeOverride() const; - - void initAudio(); - -public Q_SLOTS: - void reboot(); - void powerOff(); - - bool setDisplayBrightness(int value); - bool setHostname(const QString &name); - void setMasterVolume(int volume); - void setPhysicalScreenSizeInch(int inches); - void setPhysicalScreenSizeOverride(bool enable); - -signals: - void displayBrightnessChanged(int newValue); - void hostnameChanged(const QString &newName); - void ipAddressChanged(const QString &newAddress); - void masterVolumeChanged(int newVolume); - void physicalScreenSizeInchChanged(int newInches); - void physicalScreenSizeOverrideChanged(bool newValue); -}; - -#endif // B2QTDEVICE_H diff --git a/src/utils/utils.pro b/src/utils/utils.pro deleted file mode 100644 index a9f6041..0000000 --- a/src/utils/utils.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qt_build_config) - -TARGET = B2QtUtils -VERSION = 1.0 -CONFIG += dll warn_on - -QT = core network - -MODULE = b2qtutils -load(qt_module) - -HEADERS += \ - $$PWD/b2qtdevice.h - -SOURCES += \ - $$PWD/b2qtdevice.cpp diff --git a/src/wifi/qwificonfiguration.cpp b/src/wifi/qwificonfiguration.cpp deleted file mode 100644 index b532620..0000000 --- a/src/wifi/qwificonfiguration.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificonfiguration.h" - -QT_BEGIN_NAMESPACE - -class QWifiConfigurationPrivate -{ - Q_DECLARE_PUBLIC(QWifiConfiguration) -public: - QWifiConfigurationPrivate(QWifiConfiguration *config); - - // member variables - QWifiConfiguration *const q_ptr; - QString m_ssid; - QString m_psk; - QString m_protocol; - bool m_ssidHidden; -}; - -QWifiConfigurationPrivate::QWifiConfigurationPrivate(QWifiConfiguration *config) - : q_ptr(config) - , m_ssidHidden(false) -{ -} - -/*! - \class QWifiConfiguration - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Used to define a network configuration. - - QWifiConfiguration object represents a single network configuration. Use it - to configure properties of your network. For example, passphrase, security - protocol to use, and so on. QWifiManager::connect() function uses this - information to find a network that matches the provided configuration, before - establishing a connection. - */ - -/*! - Constructs a configuration object with parent \a parent. -*/ -QWifiConfiguration::QWifiConfiguration(QObject *parent) - : QObject(parent) - , d_ptr(new QWifiConfigurationPrivate(this)) -{ -} - -/*! - Destroys the configuration object. -*/ -QWifiConfiguration::~QWifiConfiguration() -{ - delete d_ptr; -} - -/*! - \property QWifiConfiguration::ssid - \brief a human-readable name of a Wifi network -*/ -QString QWifiConfiguration::ssid() const -{ - Q_D(const QWifiConfiguration); - return d->m_ssid; -} - -void QWifiConfiguration::setSsid(const QString &ssid) -{ - Q_D(QWifiConfiguration); - d->m_ssid = ssid; -} - -/*! - \property QWifiConfiguration::passphrase - \brief a passphrase to use for authenticating access to a network -*/ -QString QWifiConfiguration::passphrase() const -{ - Q_D(const QWifiConfiguration); - return d->m_psk; -} - -void QWifiConfiguration::setPassphrase(const QString &passphrase) -{ - Q_D(QWifiConfiguration); - d->m_psk = passphrase; -} - -/*! - \property QWifiConfiguration::protocol - \brief a security protocol to use for Wifi connection - - WPA is used by default if protocol is not explicitly set. - Supported values are: WPA, WPA2, WEP, WPS. -*/ -QString QWifiConfiguration::protocol() const -{ - Q_D(const QWifiConfiguration); - return d->m_protocol; -} - -void QWifiConfiguration::setProtocol(const QString &protocol) -{ - Q_D(QWifiConfiguration); - d->m_protocol = protocol; -} - -/*! - \property QWifiConfiguration::ssidHidden - \brief Holds whether a Wifi access point broadcasts its SSID - - If a Wifi access point does not broadcast its SSID, setting this - property to \c true ensures that the Wifi backend can detect the - specified network. - - By default this property is set to \c false. -*/ -bool QWifiConfiguration::isSsidHidden() const -{ - Q_D(const QWifiConfiguration); - return d->m_ssidHidden; -} - -void QWifiConfiguration::setSsidHidden(bool hidden) -{ - Q_D(QWifiConfiguration); - d->m_ssidHidden = hidden; -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwificonfiguration.h b/src/wifi/qwificonfiguration.h deleted file mode 100644 index cdeb453..0000000 --- a/src/wifi/qwificonfiguration.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFICONFIGURATION_H -#define QWIFICONFIGURATION_H - -#include <QtCore/QObject> -#include <QtCore/QString> - -class QWifiConfigurationPrivate; - -QT_BEGIN_NAMESPACE - -class Q_DECL_EXPORT QWifiConfiguration : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString ssid READ ssid WRITE setSsid) - Q_PROPERTY(QString passphrase READ passphrase WRITE setPassphrase) - Q_PROPERTY(QString protocol READ protocol WRITE setProtocol) - Q_PROPERTY(bool ssidHidden READ isSsidHidden WRITE setSsidHidden) -public: - explicit QWifiConfiguration(QObject *parent = 0); - virtual ~QWifiConfiguration(); - - void setSsid(const QString &ssid); - QString ssid() const; - void setPassphrase(const QString &passphrase); - QString passphrase() const; - void setProtocol(const QString &protocol); - QString protocol() const; - void setSsidHidden(bool hidden); - bool isSsidHidden() const; - -private: - Q_DISABLE_COPY(QWifiConfiguration) - Q_DECLARE_PRIVATE(QWifiConfiguration) - QWifiConfigurationPrivate *const d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWIFICONFIGURATION_H diff --git a/src/wifi/qwifimanager.cpp b/src/wifi/qwifimanager.cpp deleted file mode 100644 index 0448ec7..0000000 --- a/src/wifi/qwifimanager.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificontroller_p.h" -#include "qwifinetworklistmodel_p.h" -#include "qwifinetwork_p.h" -#include "qwifimanager_p.h" -#include "qwifisupplicant_p.h" - -#include "qwifidevice.h" - -#include <QtCore/QFile> -#include <QtCore/QProcess> - -QT_BEGIN_NAMESPACE - -// must be in the same order as in enum {} definiton -const char *nsText[] = { "Disconnected", "Authenticating", "HandshakeFailed", - "ObtainingIPAddress", "DhcpRequestFailed", "Connected" }; -const char *bsText[] = { "Initializing", "Running", "Terminating", "NotRunning" }; - -QWifiManagerPrivate::QWifiManagerPrivate(QWifiManager *manager) - : q_ptr(manager) - , m_networkListModel(new QWifiNetworkListModel(manager)) - , m_scanTimer(0) - , m_scanning(false) - , m_interface(QWifiDevice::wifiInterfaceName()) - , m_backendState(QWifiManager::NotRunning) - , m_networkState(QWifiManager::Disconnected) -{ - qCDebug(B2QT_WIFI) << "using wifi interface: " << m_interface; -} - -QWifiManagerPrivate::~QWifiManagerPrivate() -{ - delete m_wifiController; -} - -void QWifiManagerPrivate::setCurrentSSID(const QString &ssid) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI) << "current SSID: " << m_currentSSID << " -> " << ssid; - if (m_currentSSID == ssid) - return; - - m_currentSSID = ssid; - emit q->currentSSIDChanged(m_currentSSID); -} - -void QWifiManagerPrivate::handleAuthenticating(QWifiEvent *event) -{ - QString data = event->data().trimmed(); - QString ssid = data.mid(data.indexOf(QLatin1String("SSID")) + 6); - ssid = ssid.left(ssid.lastIndexOf(QLatin1Char('\''))); - - setCurrentSSID(QWifiSupplicant::decodeSsid(ssid)); - updateNetworkState(QWifiManager::Authenticating); -} - -void QWifiManagerPrivate::handleConnected() -{ - qCDebug(B2QT_WIFI) << "connected network: " << m_currentSSID; - updateNetworkState(QWifiManager::ObtainingIPAddress); - m_wifiController->asyncCall(QWifiController::AcquireIPAddress); -} - -void QWifiManagerPrivate::handleDisconneced() -{ - updateNetworkState(QWifiManager::Disconnected); -} - -void QWifiManagerPrivate::updateNetworkState(QWifiManager::NetworkState networkState) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI, "network state: %s -> %s", nsText[m_networkState], nsText[networkState]); - if (m_networkState == networkState) - return; - - m_networkState = networkState; - emit q->networkStateChanged(m_networkState); -} - -void QWifiManagerPrivate::updateBackendState(QWifiManager::BackendState backendState) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI, "backend state: %s -> %s", bsText[m_backendState], bsText[backendState]); - if (m_backendState == backendState) - return; - - m_backendState = backendState; - emit q->backendStateChanged(m_backendState); -} - -void QWifiManagerPrivate::updateWifiState() -{ - QProcess ps; - ps.start(QStringLiteral("ps")); - if (!ps.waitForStarted()) { - updateLastError(ps.program() + QLatin1String(": ") + ps.errorString()); - return; - } - - ps.waitForFinished(); - bool supplicantRunning = ps.readAll().contains("wpa_supplicant"); - if (supplicantRunning && m_wifiController->resetSupplicantSocket()) - m_backendState = QWifiManager::Running; -} - -QString QWifiManagerPrivate::call(const QString &command) -{ - if (m_backendState != QWifiManager::Running) - return QString(); - - QByteArray reply; - bool success = m_wifiController->supplicant()->sendCommand(command, &reply); - if (!success) { - qCDebug(B2QT_WIFI) << "call to supplicant failed"; - return QString(); - } - - return QLatin1String(reply.trimmed()); -} - -bool QWifiManagerPrivate::checkedCall(const QString &command) -{ - return call(command).toUpper() == QLatin1String("OK"); -} - -void QWifiManagerPrivate::updateLastError(const QString &error) -{ - Q_Q(QWifiManager); - qCWarning(B2QT_WIFI) << error; - m_lastError = error; - emit q->lastErrorChanged(m_lastError); -} - -/*! - \class QWifiManager - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Enables an application to be Wifi-capable. - - QWifiManager is a singleton class that handles Wifi-related tasks. You can - use QWifiManager to control the Wifi backend, scan for Wifi access points, - and connect to a wireless network. - - QWifiManager packs the scan results in a list-based data model, which can - be used with Qt's Model/View classes. Information about a Wifi network can - be accessed using the QWifiManager::Roles data roles. -*/ - -/*! - \enum QWifiManager::NetworkState - - Describes current state of the network connection. - - \value Disconnected Not connected to any network - \value Authenticating Verifying password with the network provider - \value HandshakeFailed Incorrect password provided - \value ObtainingIPAddress Requesting IP address from DHCP server - \value DhcpRequestFailed Could not retrieve IP address - \value Connected Ready to process network requests -*/ - -/*! - \enum QWifiManager::BackendState - - Describes current state of the Wifi backend. - - \value Initializing Wireless supplicant is starting up - \value Running Supplicant is initialized and ready to process commands - \value Terminating Shutting down wireless supplicant - \value NotRunning Wireless supplicant process is not running -*/ - -/*! - \enum QWifiManager::Roles - - Data roles supported by the data model returned from QWifiManager::networks() - - \value SSID informal (human) name of a Wifi network (QString) - \value BSSID basic service set identification of a network, used to uniquely identify BSS (QString) - \value SignalStrength strength of a Wifi signal represented as percentage (0-100) (int) - \value WPASupported holds whether network access point supports WPA security protocol (bool) - \value WPA2Supported holds whether network access point supports WPA2 security protocol (bool) - \value WEPSupported holds whether network access point supports WEP security protocol (bool) - \value WPSSupported holds whether network access point supports WPS security protocol (bool) -*/ - -QWifiManager* QWifiManager::m_instance = 0; - -/*! - Returns a singleton instance of QWifiManager. -*/ -QWifiManager* QWifiManager::instance() -{ - if (!m_instance) - m_instance = new QWifiManager(); - return m_instance; -} - -QWifiManager::QWifiManager() - : d_ptr(new QWifiManagerPrivate(this)) -{ - Q_D(QWifiManager); - - if (!QWifiDevice::wifiSupported()) - qCWarning(B2QT_WIFI) << "WifiManager may not work as expected on this device. Use the API provided by QtWifi " - "library to verify if device has support for Wi-Fi before creating an instance of wifi manager"; - - d->m_wifiController = new QWifiController(this, d_ptr); - QObject::connect(d->m_wifiController, &QWifiController::backendStateChanged, - this, &QWifiManager::handleBackendStateChanged); - QObject::connect(d->m_wifiController, &QWifiController::dhcpRequestFinished, - this, &QWifiManager::handleDhcpRequestFinished); - d->m_wifiController->start(); - - d->updateWifiState(); -} - -/*! - Destroys the QWifiManager singleton instance. - */ -QWifiManager::~QWifiManager() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::ExitEventLoop); - d->m_wifiController->wait(); - delete d_ptr; -} - -/*! - \property QWifiManager::networks - \brief a list-based data model of networks - - Returns a list-based data model of networks that can be sensed by a device. - Model can be used with Qt's Model/View classes such as QListView. Data in - the model is updated every 5 seconds if scanning is enabled. - - \sa isScanning() -*/ -QAbstractListModel *QWifiManager::networks() const -{ - Q_D(const QWifiManager); - return d->m_networkListModel; -} - -/*! - \property QWifiManager::currentSSID - \brief a network name of the last selected network - - The network for which the NetworkState change signals are emitted. - Property can contain an empty string when there is no active network - connection. -*/ -QString QWifiManager::currentSSID() const -{ - Q_D(const QWifiManager); - return d->m_currentSSID; -} - -/*! - \property QWifiManager::networkState - \brief the current network state - - Returns the current network state. -*/ -QWifiManager::NetworkState QWifiManager::networkState() const -{ - Q_D(const QWifiManager); - return d->m_networkState; -} - -/*! - \property QWifiManager::backendState - \brief the current backend state. - - Returns the current backend state. -*/ -QWifiManager::BackendState QWifiManager::backendState() const -{ - Q_D(const QWifiManager); - return d->m_backendState; -} - -/*! - Start the Wifi backend. This function returns immediately, the BackendState - change events are delivered asynchronously. - - \sa stop(), BackendState -*/ -void QWifiManager::start() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::InitializeBackend); -} - -/*! - Stop the Wifi backend. Closes the open network connection if any. - This function returns immediately, and the BackendState change events are - delivered asynchronously. - - \sa start(), BackendState -*/ -void QWifiManager::stop() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::TerminateBackend); -} - -/*! - \property QWifiManager::scanning - \brief whether the backend is scanning for Wifi networks. - - Sets whether to scan the environment for Wifi access points. - - To preserve battery energy, set this property to false when scanning is not required. - When enabled, new readings are taken every 5 seconds. - - \note You must initialize the Wifi backend to scan for networks. - - \sa start() -*/ -bool QWifiManager::isScanning() const -{ - Q_D(const QWifiManager); - return d->m_scanning; -} - -void QWifiManager::setScanning(bool scanning) -{ - Q_D(QWifiManager); - if (d->m_scanning == scanning) - return; - - d->m_scanning = scanning; - emit scanningChanged(d->m_scanning); - if (d->m_scanning) { - d->call(QStringLiteral("SCAN")); - // ### TODO expose this with a property - d->m_scanTimer = startTimer(5000); - } else { - killTimer(d->m_scanTimer); - } -} - -/*! - \property QWifiManager::lastError - \brief a QString containing the last error message set by QWifiManager. - - Returns a QString containing the last error message set by QWifiManager. - This helps in diagnosing the internal process failures. - - \sa connect() -*/ -QString QWifiManager::lastError() const -{ - Q_D(const QWifiManager); - return d->m_lastError; -} - -/*! \reimp */ -bool QWifiManager::event(QEvent *event) -{ - Q_D(QWifiManager); - switch ((int) event->type()) { - case WIFI_SCAN_RESULTS: - d->m_networkListModel->parseScanResults(d->call(QStringLiteral("SCAN_RESULTS"))); - return true; - case WIFI_CONNECTED: - d->handleConnected(); - return true; - case WIFI_DISCONNECTED: - d->handleDisconneced(); - return true; - case WIFI_AUTHENTICATING: - d->handleAuthenticating(static_cast<QWifiEvent *>(event)); - return true; - case WIFI_HANDSHAKE_FAILED: - d->updateNetworkState(QWifiManager::HandshakeFailed); - return true; - case QEvent::Timer: { - int tid = static_cast<QTimerEvent *>(event)->timerId(); - if (tid == d->m_scanTimer) { - d->call(QStringLiteral("SCAN")); - return true; - } - break; - } - } - return QObject::event(event); -} - -/*! - Connect a device to a network using the \a config network configuration. - This method returns \c true if the network with the provided configuration - could be successfully added by the backend or \c false on failure. - Use lastError() to obtain the error message on failure. - - \sa disconnect(), NetworkState, lastError() -*/ -bool QWifiManager::connect(QWifiConfiguration *config) -{ - Q_D(QWifiManager); - if (d->m_backendState != Running) { - qCWarning(B2QT_WIFI) << "start wifi backend before calling connect()"; - return false; - } - - d->call(QStringLiteral("DISABLE_NETWORK all")); - d->setCurrentSSID(config->ssid()); - - bool networkKnown = false; - QString id; - const QStringList configuredNetworks = d->call(QStringLiteral("LIST_NETWORKS")).split('\n'); - for (int i = 1; i < configuredNetworks.length(); ++i) { - const QStringList networkFields = configuredNetworks.at(i).split('\t'); - const QString ssid = QWifiSupplicant::decodeSsid(networkFields.at(1)); - if (ssid == d->m_currentSSID) { - id = networkFields.at(0); - networkKnown = true; - break; - } - } - - if (!networkKnown) { - bool ok; - id = d->call(QStringLiteral("ADD_NETWORK")); - id.toInt(&ok); - if (!ok) { - d->updateLastError(QStringLiteral("failed to add network")); - return false; - } - } - - bool ok = true; - QChar q = QLatin1Char('"'); - QString setNetworkCommand = QLatin1String("SET_NETWORK ") + id; - if (!networkKnown) { - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" ssid ") + q + d->m_currentSSID + q); - } - - QString key_mgmt; - QString protocol = config->protocol().toUpper(); - QString psk = config->passphrase(); - - // --------------------- configure network ------------------------------ - // ref: http://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf - // ref: https://www.freebsd.org/cgi/man.cgi?wpa_supplicant.conf - // ---------------------------------------------------------------------- - if (protocol.isEmpty() || protocol.contains(QStringLiteral("WPA"))) { - // ### TODO - password length has limits (see IEEE 802.11), we need to check - // for those limits here. Supplicant gives only a meaningless "fail" message. - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" psk ") + q + psk + q); - key_mgmt = QLatin1String("WPA-PSK"); - } else if (protocol.contains(QStringLiteral("WEP"))) { - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" wep_key0 ") + q + psk + q); - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" auth_alg OPEN SHARED")); - key_mgmt = QLatin1String("NONE"); - } else if (protocol.contains(QStringLiteral("WPS")) && psk.length() == 0) { - // open network - key_mgmt = QLatin1String("NONE"); - } - - if (config->isSsidHidden()) - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" scan_ssid 1")); - - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" key_mgmt ") + key_mgmt); - if (!ok) { - if (!networkKnown) - d->call(QLatin1String("REMOVE_NETWORK ") + id); - d->updateLastError(QLatin1String("failed to set properties on network: ") + id); - return false; - } - - d->call(QLatin1String("SELECT_NETWORK ") + id); - d->call(QStringLiteral("RECONNECT")); - - return true; -} - -/*! - Disconnect from currently connected network connection. - - \sa connect(), networkState() -*/ -void QWifiManager::disconnect() -{ - Q_D(QWifiManager); - d->call(QStringLiteral("DISCONNECT")); - d->m_wifiController->asyncCall(QWifiController::StopDhcp); -} - -void QWifiManager::handleBackendStateChanged(BackendState backendState) -{ - Q_D(QWifiManager); - switch (backendState) { - case NotRunning: - d->updateNetworkState(Disconnected); - break; - default: - break; - } - d->updateBackendState(backendState); -} - -void QWifiManager::handleDhcpRequestFinished(const QString &status) -{ - Q_D(QWifiManager); - qCDebug(B2QT_WIFI) << "handleDhcpRequestFinished: " << status << " for " << d->m_currentSSID; - if (status == QLatin1String("success")) { - d->updateNetworkState(Connected); - d->call(QStringLiteral("SAVE_CONFIG")); - } else { - d->updateNetworkState(DhcpRequestFailed); - } -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifimanager.h b/src/wifi/qwifimanager.h deleted file mode 100644 index 7fc658c..0000000 --- a/src/wifi/qwifimanager.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIMANAGER_H -#define QWIFIMANAGER_H - -#include "qwificonfiguration.h" - -#include <QtCore/QObject> -#include <QtCore/QString> -#include <QtCore/QByteArray> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class QWifiManagerPrivate; -class QAbstractListModel; -class QWifiController; -class QWifiNetworkListModel; - -class Q_DECL_EXPORT QWifiManager : public QObject -{ - Q_OBJECT - Q_ENUMS(NetworkState) - Q_ENUMS(BackendState) - Q_PROPERTY(NetworkState networkState READ networkState NOTIFY networkStateChanged) - Q_PROPERTY(BackendState backendState READ backendState NOTIFY backendStateChanged) - Q_PROPERTY(bool scanning READ isScanning WRITE setScanning NOTIFY scanningChanged) - Q_PROPERTY(QString currentSSID READ currentSSID NOTIFY currentSSIDChanged) - Q_PROPERTY(QString lastError READ lastError NOTIFY lastErrorChanged) - Q_PROPERTY(QAbstractListModel *networks READ networks CONSTANT) -public: - enum NetworkState { - Disconnected, - Authenticating, - HandshakeFailed, - ObtainingIPAddress, - DhcpRequestFailed, - Connected - }; - - enum BackendState { - Initializing, - Running, - Terminating, - NotRunning - }; - - enum Roles { - SSID = Qt::UserRole + 1, - BSSID = Qt::UserRole + 2, - SignalStrength = Qt::UserRole + 3, - WPASupported = Qt::UserRole + 4, - WPA2Supported = Qt::UserRole + 5, - WEPSupported = Qt::UserRole + 6, - WPSSupported = Qt::UserRole + 7 - }; - - static QWifiManager *instance(); - virtual ~QWifiManager(); - - QAbstractListModel *networks() const; - QString currentSSID() const; - bool isScanning() const; - void setScanning(bool scanning); - NetworkState networkState() const; - BackendState backendState() const; - QString lastError() const; - -public slots: - void start(); - void stop(); - bool connect(QWifiConfiguration *config); - void disconnect(); - -signals: - void scanningChanged(bool scanning); - void networkStateChanged(NetworkState networkState); - void backendStateChanged(BackendState backendState); - void currentSSIDChanged(const QString ¤tSSID); - void lastErrorChanged(const QString &error); - -protected: - bool event(QEvent *event); - -private slots: - void handleBackendStateChanged(BackendState backendState); - void handleDhcpRequestFinished(const QString &status); - -private: - QWifiManager(); - static QWifiManager* m_instance; - friend class QWifiController; - Q_DISABLE_COPY(QWifiManager) - Q_DECLARE_PRIVATE(QWifiManager) - QWifiManagerPrivate *const d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWIFIMANAGER_H diff --git a/src/wifi/qwifimanager_p.h b/src/wifi/qwifimanager_p.h deleted file mode 100644 index 5449551..0000000 --- a/src/wifi/qwifimanager_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIMANAGER_P_H -#define QWIFIMANAGER_P_H - -#include "qwifimanager.h" -#include "qwifidevice.h" - -#include <QtCore/QString> - -QT_BEGIN_NAMESPACE - -class QWifiEvent; - -class QWifiManagerPrivate -{ - Q_DECLARE_PUBLIC(QWifiManager) -public: - QWifiManagerPrivate(QWifiManager *manager); - virtual ~QWifiManagerPrivate(); - - // methods - void setCurrentSSID(const QString &ssid); - void handleConnected(); - void handleDisconneced(); - void handleAuthenticating(QWifiEvent *event); - - void updateNetworkState(QWifiManager::NetworkState networkState); - void updateBackendState(QWifiManager::BackendState backendState); - void updateWifiState(); - - QString call(const QString &command); - bool checkedCall(const QString &command); - void updateLastError(const QString &error); - - // member variables - QWifiManager *const q_ptr; - QWifiController *m_wifiController; - QWifiNetworkListModel *m_networkListModel; - - int m_scanTimer; - bool m_scanning; - QByteArray m_interface; - QWifiManager::BackendState m_backendState; - QWifiManager::NetworkState m_networkState; - QString m_currentSSID; - QString m_lastError; -}; - -QT_END_NAMESPACE - -#endif // QWIFIMANAGER_P_H diff --git a/src/wifi/qwifinetwork_p.h b/src/wifi/qwifinetwork_p.h deleted file mode 100644 index db65e2d..0000000 --- a/src/wifi/qwifinetwork_p.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFINETWORK_H -#define QWIFINETWORK_H - -#include <QtCore/QObject> -#include <QtCore/QString> - -QT_BEGIN_NAMESPACE - -class QWifiNetwork : public QObject -{ - Q_OBJECT -public: - explicit QWifiNetwork(QObject *parent = 0); - virtual ~QWifiNetwork(); - - void setBssid(const QString &bssid) { m_bssid = bssid; } - QString bssid() const { return m_bssid; } - void setSsid(const QString &ssid); - QString ssid() const { return m_ssid; } - - void setSignalStrength(int strength); - int signalStrength() const { return m_signalStrength; } - - void setOutOfRange(bool isOutOfRange); - // this could be exposed in QWifiManager::Roles, - // if there is a use case for it, this would require keeping - // the out of range networks in data model, currently they are - // removed from the model. - bool isOutOfRange() const { return m_isOutOfRange; } - - void setFlags(const QString &flags) { m_flags = flags; } - QString flags() const { return m_flags; } - bool supportsWPA2() const { return m_flags.contains(QStringLiteral("WPA2")); } - bool supportsWPA() const { return m_flags.contains(QStringLiteral("WPA")); } - bool supportsWEP() const { return m_flags.contains(QStringLiteral("WEP")); } - bool supportsWPS() const { return m_flags.contains(QStringLiteral("WPS")); } - -private: - QString m_bssid; - QString m_ssid; - int m_signalStrength; - QString m_flags; - bool m_isOutOfRange; -}; - -QT_END_NAMESPACE - -#endif // QWIFINETWORK_H diff --git a/src/wifi/qwifinetworklistmodel.cpp b/src/wifi/qwifinetworklistmodel.cpp deleted file mode 100644 index fa3f7dc..0000000 --- a/src/wifi/qwifinetworklistmodel.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifinetworklistmodel_p.h" -#include "qwifinetwork_p.h" -#include "qwifisupplicant_p.h" - -#include "qwifimanager.h" - -#include <QtCore/QSet> -#include <QtCore/QString> -#include <QtCore/QByteArray> - -QT_BEGIN_NAMESPACE - -QWifiNetworkListModel::QWifiNetworkListModel(QObject *parent) - : QAbstractListModel(parent) -{ -} - -QWifiNetworkListModel::~QWifiNetworkListModel() -{ - qDeleteAll(m_networks); - qDeleteAll(m_outOfRangeNetworks); - m_networks.clear(); - m_outOfRangeNetworks.clear(); -} - -QHash<int, QByteArray> QWifiNetworkListModel::roleNames() const -{ - QHash<int, QByteArray> names; - names.insert(QWifiManager::SSID, "ssid"); - names.insert(QWifiManager::BSSID, "bssid"); - names.insert(QWifiManager::SignalStrength, "signalStrength"); - names.insert(QWifiManager::WPASupported, "supportsWPA"); - names.insert(QWifiManager::WPA2Supported, "supportsWPA2"); - names.insert(QWifiManager::WEPSupported, "supportsWEP"); - names.insert(QWifiManager::WPSSupported, "supportsWPS"); - return names; -} - -QVariant QWifiNetworkListModel::data(const QModelIndex &index, int role) const -{ - QWifiNetwork *n = m_networks.at(index.row()); - - switch (role) { - case QWifiManager::SSID: - return n->ssid(); - break; - case QWifiManager::BSSID: - return n->bssid(); - break; - case QWifiManager::SignalStrength: - return n->signalStrength(); - break; - case QWifiManager::WPASupported: - return n->supportsWPA(); - break; - case QWifiManager::WPA2Supported: - return n->supportsWPA2(); - break; - case QWifiManager::WEPSupported: - return n->supportsWEP(); - break; - case QWifiManager::WPSSupported: - return n->supportsWPS(); - break; - default: - break; - } - - return QVariant(); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QString &ssid) -{ - int pos = 0; // unused - return networkForSSID(ssid, &pos); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QString &ssid, int *pos) -{ - for (int i = 0; i < m_networks.size(); ++i) { - if (m_networks.at(i)->ssid() == ssid) { - if (pos) - *pos = i; - return m_networks.at(i); - } - } - return 0; -} - -QWifiNetwork *QWifiNetworkListModel::outOfRangeListContains(const QString &ssid) -{ - for (int i = 0; i < m_outOfRangeNetworks.length(); ++i) - if (m_outOfRangeNetworks.at(i)->ssid() == ssid) - return m_outOfRangeNetworks.takeAt(i); - return 0; -} - -void QWifiNetworkListModel::parseScanResults(const QString &results) -{ - QStringList lines = results.split('\n'); - QSet<QString> sensibleNetworks; - - for (int i = 1; i < lines.size(); ++i) { - QStringList info = lines.at(i).split('\t'); - if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) - continue; - int pos = 0; - - QString ssid = QWifiSupplicant::decodeSsid(info.at(4)); - if (ssid.isEmpty()) - continue; - - sensibleNetworks.insert(ssid); - QWifiNetwork *knownNetwork = networkForSSID(ssid, &pos); - if (!knownNetwork) - knownNetwork = outOfRangeListContains(ssid); - - int signalStrength = info.at(2).trimmed().toInt(); - if (signalStrength < 0) { - // signal is reported in dBm, rough conversion: best = -40, worst = -100 - int val = qAbs(qMax(-100, qMin(signalStrength, -40)) + 40); // clamp and normalize to 0 - signalStrength = 100 - (int) ((100.0 * (double) val) / 60.0); - } else if (signalStrength > 100) { - qCWarning(B2QT_WIFI) << "unexpected value for a signal level: " << signalStrength; - } - - if (!knownNetwork) { - QWifiNetwork *network = new QWifiNetwork(); - network->setOutOfRange(false); - network->setBssid(info.at(0)); - network->setFlags(info.at(3)); - network->setSignalStrength(signalStrength); - network->setSsid(ssid); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << network; - endInsertRows(); - } else { - if (knownNetwork->isOutOfRange()) { - // known network has come back into a range - knownNetwork->setOutOfRange(false); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << knownNetwork; - endInsertRows(); - pos = m_networks.length() - 1; - } - // ssids are the same, compare bssids.. - if (knownNetwork->bssid() == info.at(0)) { - // same access point, simply update the signal strength - knownNetwork->setSignalStrength(signalStrength); - knownNetwork->setOutOfRange(false); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } else if (knownNetwork->signalStrength() < signalStrength) { - // replace with a stronger access point within the same network - m_networks.at(pos)->setOutOfRange(false); - m_networks.at(pos)->setBssid(info.at(0)); - m_networks.at(pos)->setFlags(info.at(3)); - m_networks.at(pos)->setSignalStrength(signalStrength); - m_networks.at(pos)->setSsid(ssid); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } - } - } - // remove out-of-range networks from the data model - for (int i = 0; i < m_networks.size();) { - if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) { - beginRemoveRows(QModelIndex(), i, i); - QWifiNetwork *n = m_networks.takeAt(i); - n->setOutOfRange(true); - m_outOfRangeNetworks.append(n); - endRemoveRows(); - } else { - ++i; - } - } -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifinetworklistmodel_p.h b/src/wifi/qwifinetworklistmodel_p.h deleted file mode 100644 index 25a2b31..0000000 --- a/src/wifi/qwifinetworklistmodel_p.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFINETWORKLISTMODEL_H -#define QWIFINETWORKLISTMODEL_H - -#include <QtCore/QAbstractListModel> -#include <QtCore/QVariant> -#include <QtCore/QList> -#include <QtCore/QHash> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class QWifiNetwork; - -class QWifiNetworkListModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit QWifiNetworkListModel(QObject *parent = 0); - virtual ~QWifiNetworkListModel(); - - int rowCount(const QModelIndex &) const { return m_networks.size(); } - QVariant data(const QModelIndex &index, int role) const; - QHash<int,QByteArray> roleNames() const; - - void parseScanResults(const QString &data); - QWifiNetwork *networkForSSID(const QString &ssid); - QWifiNetwork *networkForSSID(const QString &ssid, int *pos); - QWifiNetwork *outOfRangeListContains(const QString &ssid); - -private: - QList<QWifiNetwork *> m_networks; - QList<QWifiNetwork *> m_outOfRangeNetworks; -}; - -QT_END_NAMESPACE - -#endif // QWIFINETWORKLISTMODEL_H diff --git a/src/wifi/wifi.pro b/src/wifi/wifi.pro deleted file mode 100644 index faf15f2..0000000 --- a/src/wifi/wifi.pro +++ /dev/null @@ -1,36 +0,0 @@ -load(qt_build_config) - -TARGET = B2QtWifi -VERSION = 1.0 -CONFIG += dll warn_on - -QT += core network - -MODULE = b2qtwifi -load(qt_module) - -HEADERS += \ - $$PWD/qwifimanager.h \ - $$PWD/qwifimanager_p.h \ - $$PWD/qwifinetwork_p.h \ - $$PWD/qwifinetworklistmodel_p.h \ - $$PWD/qwificontroller_p.h \ - $$PWD/qwifidevice.h \ - $$PWD/qwificonfiguration.h \ - $$PWD/qwifisupplicant_p.h - -SOURCES += \ - $$PWD/qwifimanager.cpp \ - $$PWD/qwifinetwork.cpp \ - $$PWD/qwifinetworklistmodel.cpp \ - $$PWD/qwificontroller.cpp \ - $$PWD/qwifidevice.cpp \ - $$PWD/qwificonfiguration.cpp \ - $$PWD/qwifisupplicant.cpp \ - $$[QT_SYSROOT]/usr/include/wpa-supplicant/wpa_ctrl.c \ - $$[QT_SYSROOT]/usr/include/wpa-supplicant/os_unix.c - -DEFINES += \ - CONFIG_CTRL_IFACE \ - CONFIG_CTRL_IFACE_UNIX - |