From 1ece0621d70c16f216e78fcdd3b7bf466735102d Mon Sep 17 00:00:00 2001 From: reionwong Date: Mon, 15 Nov 2021 23:38:26 +0800 Subject: [PATCH] Improve Bluetooth --- bluez/CMakeLists.txt | 2 + bluez/applet/bluetoothagent.cpp | 179 ++++++++++++++++++++++++ bluez/applet/bluetoothagent.h | 43 ++++++ bluez/applet/bluetoothmanager.cpp | 181 +++++++++++++++++++++++++ bluez/applet/bluetoothmanager.h | 64 +++++++++ bluez/applet/devicesproxymodel.cpp | 61 ++++++++- bluez/applet/devicesproxymodel.h | 19 ++- bluez/bluezqtextensionplugin.cpp | 5 + networkmanagement/networkmodel.cpp | 10 ++ networkmanagement/networkmodel.h | 6 +- networkmanagement/networkmodelitem.cpp | 31 +++++ networkmanagement/networkmodelitem.h | 13 ++ 12 files changed, 605 insertions(+), 9 deletions(-) create mode 100644 bluez/applet/bluetoothagent.cpp create mode 100644 bluez/applet/bluetoothagent.h create mode 100644 bluez/applet/bluetoothmanager.cpp create mode 100644 bluez/applet/bluetoothmanager.h diff --git a/bluez/CMakeLists.txt b/bluez/CMakeLists.txt index ca7881d..c9054c4 100644 --- a/bluez/CMakeLists.txt +++ b/bluez/CMakeLists.txt @@ -8,6 +8,8 @@ set(bluezqtextensionplugin_SRCS declarativedevicesmodel.cpp bluezqtextensionplugin.cpp applet/devicesproxymodel.cpp + applet/bluetoothagent.cpp + applet/bluetoothmanager.cpp ) add_library(cutefishbluez_qmlplugins SHARED ${bluezqtextensionplugin_SRCS}) diff --git a/bluez/applet/bluetoothagent.cpp b/bluez/applet/bluetoothagent.cpp new file mode 100644 index 0000000..e40181f --- /dev/null +++ b/bluez/applet/bluetoothagent.cpp @@ -0,0 +1,179 @@ +/* + * SPDX-FileCopyrightText: 2010 Alex Fiestas + * SPDX-FileCopyrightText: 2010 UFO Coders + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "bluetoothagent.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +static int cRandom() +{ + static QThreadStorage initialized_threads; + if (!initialized_threads.localData()) { + unsigned int seed; + initialized_threads.setLocalData(true); + QFile urandom(QStringLiteral("/dev/urandom")); + bool opened = urandom.open(QIODevice::ReadOnly | QIODevice::Unbuffered); + if (!opened || urandom.read(reinterpret_cast(&seed), sizeof(seed)) != sizeof(seed)) { + // silence warnings about use of deprecated qsrand()/qrand() + // Porting to QRandomGenerator::global() instead might result in no new seed set for the generator behind qrand() + // which then might affect other places indirectly relying on this. + // So just keeping the old calls here, as this method is also deprecated and will disappear together with qsrand/qrand. + QT_WARNING_PUSH + QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") + QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") + // No /dev/urandom... try something else. + qsrand(getpid()); + seed = qrand() ^ time(nullptr) ^ reinterpret_cast(QThread::currentThread()); + } + qsrand(seed); + } + return qrand(); + QT_WARNING_POP +} + +BluetoothAgent::BluetoothAgent(QObject *parent) + : BluezQt::Agent(parent) + , m_fromDatabase(false) +{ +} + +QString BluetoothAgent::pin() +{ + return m_pin; +} + +void BluetoothAgent::setPin(const QString &pin) +{ + m_pin = pin; + m_fromDatabase = false; +} + +bool BluetoothAgent::isFromDatabase() +{ + return m_fromDatabase; +} + +QString BluetoothAgent::getPin(BluezQt::DevicePtr device) +{ + m_fromDatabase = false; + m_pin = QString::number(cRandom()); + m_pin = m_pin.left(6); + + const QString &xmlPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("pin-code-database.xml")); + + QFile file(xmlPath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Can't open the pin-code-database.xml"; + return m_pin; + } + + QXmlStreamReader xml(&file); + + QString deviceType = BluezQt::Device::typeToString(device->type()); + if (deviceType == QLatin1String("audiovideo")) { + deviceType = QStringLiteral("audio"); + } + + while (!xml.atEnd()) { + xml.readNext(); + if (xml.name() != QLatin1String("device")) { + continue; + } + QXmlStreamAttributes attr = xml.attributes(); + + if (attr.count() == 0) { + continue; + } + + if (attr.hasAttribute(QLatin1String("type")) && attr.value(QLatin1String("type")) != QLatin1String("any")) { + if (deviceType != attr.value(QLatin1String("type")).toString()) { + continue; + } + } + + if (attr.hasAttribute(QLatin1String("oui"))) { + if (!device->address().startsWith(attr.value(QLatin1String("oui")).toString())) { + continue; + } + } + + if (attr.hasAttribute(QLatin1String("name"))) { + if (device->name() != attr.value(QLatin1String("name")).toString()) { + continue; + } + } + + m_pin = attr.value(QLatin1String("pin")).toString(); + m_fromDatabase = true; + if (m_pin.startsWith(QLatin1String("max:"))) { + m_fromDatabase = false; + int num = m_pin.rightRef(m_pin.length() - 4).toInt(); + m_pin = QString::number(cRandom()).left(num); + } + + qDebug() << "PIN: " << m_pin; + return m_pin; + } + + return m_pin; +} + +QDBusObjectPath BluetoothAgent::objectPath() const +{ + return QDBusObjectPath(QStringLiteral("/agent")); +} + +void BluetoothAgent::requestPinCode(BluezQt::DevicePtr device, const BluezQt::Request &req) +{ + qDebug() << "AGENT-RequestPinCode" << device->ubi(); + + Q_EMIT pinRequested(m_pin); + req.accept(m_pin); +} + +void BluetoothAgent::displayPinCode(BluezQt::DevicePtr device, const QString &pinCode) +{ + qDebug() << "AGENT-DisplayPinCode" << device->ubi() << pinCode; + + Q_EMIT pinRequested(pinCode); +} + +void BluetoothAgent::requestPasskey(BluezQt::DevicePtr device, const BluezQt::Request &req) +{ + qDebug() << "AGENT-RequestPasskey" << device->ubi(); + + Q_EMIT pinRequested(m_pin); + req.accept(m_pin.toUInt()); +} + +void BluetoothAgent::displayPasskey(BluezQt::DevicePtr device, const QString &passkey, const QString &entered) +{ + Q_UNUSED(entered); + + qDebug() << "AGENT-DisplayPasskey" << device->ubi() << passkey; + + Q_EMIT pinRequested(passkey); +} + +void BluetoothAgent::requestConfirmation(BluezQt::DevicePtr device, const QString &passkey, const BluezQt::Request<> &req) +{ + + qDebug() << "AGENT-RequestConfirmation " << device->ubi() << passkey; + + Q_EMIT confirmationRequested(passkey, req); +} diff --git a/bluez/applet/bluetoothagent.h b/bluez/applet/bluetoothagent.h new file mode 100644 index 0000000..0f88f4e --- /dev/null +++ b/bluez/applet/bluetoothagent.h @@ -0,0 +1,43 @@ +/* + * SPDX-FileCopyrightText: 2010 Alex Fiestas + * SPDX-FileCopyrightText: 2010 UFO Coders + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BLUETOOTHAGENT_H +#define BLUETOOTHAGENT_H + +#include + +class BluetoothAgent : public BluezQt::Agent +{ + Q_OBJECT + +public: + explicit BluetoothAgent(QObject *parent = nullptr); + + QString pin(); + void setPin(const QString &pin); + + bool isFromDatabase(); + QString getPin(BluezQt::DevicePtr device); + + QDBusObjectPath objectPath() const override; + + void requestPinCode(BluezQt::DevicePtr device, const BluezQt::Request &req) override; + void displayPinCode(BluezQt::DevicePtr device, const QString &pinCode) override; + void requestPasskey(BluezQt::DevicePtr device, const BluezQt::Request &req) override; + void displayPasskey(BluezQt::DevicePtr device, const QString &passkey, const QString &entered) override; + void requestConfirmation(BluezQt::DevicePtr device, const QString &passkey, const BluezQt::Request<> &req) override; + +Q_SIGNALS: + void pinRequested(const QString &pin); + void confirmationRequested(const QString &passkey, const BluezQt::Request<> &req); + +private: + bool m_fromDatabase; + QString m_pin; +}; + +#endif // BluetoothAgent_H diff --git a/bluez/applet/bluetoothmanager.cpp b/bluez/applet/bluetoothmanager.cpp new file mode 100644 index 0000000..6627e3b --- /dev/null +++ b/bluez/applet/bluetoothmanager.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bluetoothmanager.h" +#include + +#include +#include +#include +#include +#include + +BluetoothManager::BluetoothManager(QObject *parent) + : QObject(parent) + , m_agent(new BluetoothAgent(this)) +{ + m_manager = new BluezQt::Manager(this); + BluezQt::InitManagerJob *initJob = m_manager->init(); + initJob->start(); + connect(initJob, &BluezQt::InitManagerJob::result, this, &BluetoothManager::onInitJobResult); + + connect(m_agent, &BluetoothAgent::confirmationRequested, this, &BluetoothManager::confirmationRequested); + + connect(m_manager, &BluezQt::Manager::bluetoothBlockedChanged, this, [=] (bool blocked) { + if (!blocked) { + BluezQt::AdapterPtr adaptor = m_manager->adapters().first(); + if (adaptor) { + if (!adaptor->isDiscoverable()) { + adaptor->setDiscoverable(true); + } + } + } + }); +} + +BluetoothManager::~BluetoothManager() +{ + m_manager->unregisterAgent(m_agent); + + delete m_agent; + delete m_manager; +} + +void BluetoothManager::setName(const QString &name) +{ + BluezQt::AdapterPtr adaptor = m_manager->usableAdapter(); + adaptor->setName(name); +} + +void BluetoothManager::connectToDevice(const QString address) +{ + BluezQt::AdapterPtr adaptor = m_manager->usableAdapter(); + BluezQt::DevicePtr device = adaptor->deviceForAddress(address); + qDebug() << "hello: " << address << device->name(); + m_device = device; + device->setTrusted(true); + BluezQt::PendingCall *call = m_device->connectToDevice(); + connect(call, &BluezQt::PendingCall::finished, this, &BluetoothManager::connectFinished); +// connect(m_device.data(), &BluezQt::Device::connectedChanged, this, &Bluetooth::connectedStateChanged); +} + +void BluetoothManager::requestParingConnection(const QString address) +{ + BluezQt::AdapterPtr adaptor = m_manager->usableAdapter(); + BluezQt::DevicePtr device = adaptor->deviceForAddress(address); + m_device = device; +// m_address = address; + BluezQt::PendingCall *pairCall = m_device->pair(); + connect(pairCall, &BluezQt::PendingCall::finished, this, &BluetoothManager::pairingFinished); +} + +void BluetoothManager::confirmMatchButton(const bool match) +{ + if (match){ + m_req.accept(); + } else{ + m_req.reject(); + } +} + +void BluetoothManager::deviceDisconnect(const QString address) +{ + stopMediaPlayer(address); + BluezQt::AdapterPtr adaptor = m_manager->usableAdapter(); + BluezQt::DevicePtr device = adaptor->deviceForAddress(address); + BluezQt::PendingCall *pairCall = device->disconnectFromDevice(); + // connect(pairCall, &BluezQt::PendingCall::finished, this, &Bluetooth::disconnectFromDeviceFinished); +} + +void BluetoothManager::deviceRemoved(const QString address) +{ + stopMediaPlayer(address); + BluezQt::AdapterPtr adaptor = m_manager->usableAdapter(); + BluezQt::DevicePtr device = adaptor->deviceForAddress(address); + BluezQt::PendingCall *removeCall = adaptor->removeDevice(device); + // connect(removeCall, &BluezQt::PendingCall::finished, this, &BluetoothManager::removeDeviceFinished); +} + +void BluetoothManager::stopMediaPlayer(const QString address) +{ + BluezQt::AdapterPtr adaptor = m_manager->usableAdapter(); + BluezQt::DevicePtr device = adaptor->deviceForAddress(address); + BluezQt::MediaPlayerPtr mediaPlayer = device->mediaPlayer(); + + if (mediaPlayer){ + mediaPlayer->stop(); + } +} + +void BluetoothManager::onInitJobResult(BluezQt::InitManagerJob *job) +{ + if (job->error()) { + qDebug() << "Init Bluetooth error"; + return; + } + + // Make sure to register agent when bluetoothd starts + operationalChanged(m_manager->isOperational()); + connect(m_manager, &BluezQt::Manager::operationalChanged, this, &BluetoothManager::operationalChanged); + + m_adapter = m_manager->usableAdapter(); + if (m_adapter) { + setName("CutefishOS"); + + if (!m_adapter->isDiscoverable()) + m_adapter->startDiscovery(); + } +} + +void BluetoothManager::operationalChanged(bool operational) +{ + if (operational) { + m_manager->registerAgent(m_agent); + } else { + // Attempt to start bluetoothd + BluezQt::Manager::startService(); + } +} + +void BluetoothManager::confirmationRequested(const QString &passkey, const BluezQt::Request<> &req) +{ + m_req = req; + Q_EMIT showPairDialog(m_device->name(), passkey); +} + +void BluetoothManager::pairingFinished(BluezQt::PendingCall *call) +{ + qDebug() << call->error() << call->errorText(); + if (!call->error()) { + // Success + } else { + if (call->error() == 98) { + // showPairDialog + } else { + emit pairFailed(m_device->name(), m_device->type()); + } + } +} + +void BluetoothManager::connectFinished(BluezQt::PendingCall *call) +{ + if (call->error()) { + emit connectFailed(m_device->name(), m_device->type()); + } +} diff --git a/bluez/applet/bluetoothmanager.h b/bluez/applet/bluetoothmanager.h new file mode 100644 index 0000000..25d6563 --- /dev/null +++ b/bluez/applet/bluetoothmanager.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BLUETOOTHMANAGER_H +#define BLUETOOTHMANAGER_H + +#include +#include +#include "bluetoothagent.h" + +class BluetoothManager : public QObject +{ + Q_OBJECT + +public: + explicit BluetoothManager(QObject *parent = nullptr); + ~BluetoothManager(); + + Q_INVOKABLE void setName(const QString &name); + Q_INVOKABLE void connectToDevice(const QString address); + Q_INVOKABLE void requestParingConnection(const QString address); + Q_INVOKABLE void confirmMatchButton(const bool match); + Q_INVOKABLE void deviceDisconnect(const QString address); + Q_INVOKABLE void deviceRemoved(const QString address); + Q_INVOKABLE void stopMediaPlayer(const QString address); + +signals: + void showPairDialog(const QString name, const QString pin); + void pairFailed(const QString name, const int deviceType); + void connectFailed(const QString name, const int deviceType); + +private slots: + void onInitJobResult(BluezQt::InitManagerJob *job); + void operationalChanged(bool operational); + void confirmationRequested(const QString &passkey, const BluezQt::Request<> &req); + void pairingFinished(BluezQt::PendingCall *call); + void connectFinished(BluezQt::PendingCall *call); + +private: + BluezQt::Manager *m_manager; + BluetoothAgent *m_agent; + BluezQt::AdapterPtr m_adapter; + BluezQt::DevicePtr m_device; + BluezQt::Request<> m_req; + QString m_name; +}; + +#endif // BLUETOOTHMANAGER_H diff --git a/bluez/applet/devicesproxymodel.cpp b/bluez/applet/devicesproxymodel.cpp index d2c9564..47deeb8 100644 --- a/bluez/applet/devicesproxymodel.cpp +++ b/bluez/applet/devicesproxymodel.cpp @@ -8,12 +8,24 @@ #include #include +#include DevicesProxyModel::DevicesProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { setDynamicSortFilter(true); sort(0, Qt::DescendingOrder); + + m_manager = new BluezQt::Manager(this); + connect(m_manager, &BluezQt::Manager::bluetoothBlockedChanged, this, &DevicesProxyModel::bluetoothBlockedChanged); +} + +void DevicesProxyModel::bluetoothBlockedChanged(bool blocked) +{ + if (blocked){ + m_connectedName = ""; + emit connectedNameChanged(m_connectedName); + } } QHash DevicesProxyModel::roleNames() const @@ -28,10 +40,15 @@ QVariant DevicesProxyModel::data(const QModelIndex &index, int role) const { switch (role) { case SectionRole: - if (index.data(BluezQt::DevicesModel::ConnectedRole).toBool()) { - return QStringLiteral("Connected"); + // if (index.data(BluezQt::DevicesModel::ConnectedRole).toBool()) { + // return QStringLiteral("Connected"); + // } + // return QStringLiteral("Available"); + + if (index.data(BluezQt::DevicesModel::PairedRole).toBool()) { + return QStringLiteral("My devices"); } - return QStringLiteral("Available"); + return QStringLiteral("Other devices"); case DeviceFullNameRole: if (duplicateIndexAddress(index)) { @@ -52,12 +69,21 @@ QVariant DevicesProxyModel::data(const QModelIndex &index, int role) const bool DevicesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { - bool leftConnected = left.data(BluezQt::DevicesModel::ConnectedRole).toBool(); - bool rightConnected = right.data(BluezQt::DevicesModel::ConnectedRole).toBool(); + bool leftPaired = left.data(BluezQt::DevicesModel::PairedRole).toBool(); + bool rightPaired = right.data(BluezQt::DevicesModel::PairedRole).toBool(); - if (leftConnected < rightConnected) { + if (leftPaired < rightPaired) { return true; - } else if (leftConnected > rightConnected) { + } else if (leftPaired > rightPaired) { + return false; + } + + qint16 leftRssi = left.data(BluezQt::DevicesModel::RssiRole).toInt(); + qint16 rightRssi = right.data(BluezQt::DevicesModel::RssiRole).toInt(); + + if (!leftPaired && leftRssi < rightRssi) { + return true; + } else if (!leftPaired && leftRssi > rightRssi) { return false; } @@ -98,6 +124,27 @@ bool DevicesProxyModel::filterAcceptsRow(int source_row, const QModelIndex &sour { const QModelIndex index = sourceModel()->index(source_row, 0, source_parent); + if (index.data(BluezQt::DevicesModel::ConnectedRole).toBool() && index.data(BluezQt::DevicesModel::PairedRole).toBool()){ + m_connectedName = index.data(BluezQt::DevicesModel::NameRole).toString(); + m_connectedAdress = index.data(BluezQt::DevicesModel::AddressRole).toString(); + emit connectedNameChanged(m_connectedName); + emit connectedAdressChanged(m_connectedAdress); + } + + if (index.data(BluezQt::DevicesModel::TypeRole).toInt() == 18){ + return false; + } + + if (index.data(BluezQt::DevicesModel::NameRole).toString().replace("-","") == + index.data(BluezQt::DevicesModel::AddressRole).toString().replace(":","")) { + return false; + } + + if (!index.data(BluezQt::DevicesModel::PairedRole).toBool() + && index.data(BluezQt::DevicesModel::RssiRole).toInt() == -32768) { + return false; + } + return index.data(BluezQt::DevicesModel::AdapterPoweredRole).toBool() && index.data(BluezQt::DevicesModel::AdapterPairableRole).toBool(); } diff --git a/bluez/applet/devicesproxymodel.h b/bluez/applet/devicesproxymodel.h index b8c0173..0c6373a 100644 --- a/bluez/applet/devicesproxymodel.h +++ b/bluez/applet/devicesproxymodel.h @@ -13,11 +13,13 @@ class DevicesProxyModel : public QSortFilterProxyModel { Q_OBJECT + Q_PROPERTY(QString connectedName READ connectedName NOTIFY connectedNameChanged) + Q_PROPERTY(QString connectedAdress READ connectedAdress NOTIFY connectedAdressChanged) public: enum AdditionalRoles { SectionRole = BluezQt::DevicesModel::LastRole + 10, - DeviceFullNameRole = BluezQt::DevicesModel::LastRole + 11, + DeviceFullNameRole = BluezQt::DevicesModel::LastRole + 11 }; explicit DevicesProxyModel(QObject *parent = nullptr); @@ -29,8 +31,23 @@ public: Q_INVOKABLE QString adapterHciString(const QString &ubi) const; + QString connectedName(){ return m_connectedName; }; + QString connectedAdress(){ return m_connectedAdress; }; + +signals: + void connectedNameChanged(const QString connectedName) const; + void connectedAdressChanged(const QString connectedAddress) const; + +private Q_SLOTS: + void bluetoothBlockedChanged(bool blocked); + private: bool duplicateIndexAddress(const QModelIndex &idx) const; + + mutable QString m_connectedName = ""; + mutable QString m_connectedAdress = ""; + + BluezQt::Manager *m_manager; }; #endif // DEVICESPROXYMODEL_H diff --git a/bluez/bluezqtextensionplugin.cpp b/bluez/bluezqtextensionplugin.cpp index a7693f1..6ebd260 100644 --- a/bluez/bluezqtextensionplugin.cpp +++ b/bluez/bluezqtextensionplugin.cpp @@ -16,6 +16,8 @@ #include "declarativemediaplayer.h" #include "applet/devicesproxymodel.h" +#include "applet/bluetoothmanager.h" +#include "applet/bluetoothagent.h" #include #include @@ -68,6 +70,9 @@ void BluezQtExtensionPlugin::registerTypes(const char *uri) qmlRegisterSingletonType(uri, 1, 0, "Manager", manager_singleton); qmlRegisterType(uri, 1, 0, "DevicesModelPrivate"); + qmlRegisterType(uri, 1, 0, "BluetoothAgent"); + qmlRegisterType(uri, 1, 0, "BluetoothManager"); + qmlRegisterUncreatableType(uri, 1, 0, "Adapter", QStringLiteral("Adapter cannot be created")); // qmlRegisterUncreatableType(uri, 1, 0, "Battery", QStringLiteral("Battery cannot be created")); qmlRegisterUncreatableType(uri, 1, 0, "Device", QStringLiteral("Device cannot be created")); diff --git a/networkmanagement/networkmodel.cpp b/networkmanagement/networkmodel.cpp index 6d5ade3..6fd282a 100644 --- a/networkmanagement/networkmodel.cpp +++ b/networkmanagement/networkmodel.cpp @@ -107,6 +107,12 @@ QVariant NetworkModel::data(const QModelIndex &index, int role) const return item->rxBytes(); case TxBytesRole: return item->txBytes(); + case IpAddressRole: + return item->ipAddress(); + case RouterRole: + return item->router(); + case GateWayRole: + return item->gateway(); default: break; } @@ -153,6 +159,10 @@ QHash NetworkModel::roleNames() const roles[RxBytesRole] = "rxBytes"; roles[TxBytesRole] = "txBytes"; + roles[IpAddressRole] = "ipAddress"; + roles[RouterRole] = "router"; + roles[GateWayRole] = "gateWay"; + return roles; } diff --git a/networkmanagement/networkmodel.h b/networkmanagement/networkmodel.h index 2a4b364..d3405c7 100644 --- a/networkmanagement/networkmodel.h +++ b/networkmanagement/networkmodel.h @@ -75,7 +75,11 @@ public: VpnState, VpnType, RxBytesRole, - TxBytesRole + TxBytesRole, + + IpAddressRole, + RouterRole, + GateWayRole, }; Q_ENUMS(ItemRole) diff --git a/networkmanagement/networkmodelitem.cpp b/networkmanagement/networkmodelitem.cpp index f154b00..18c0862 100644 --- a/networkmanagement/networkmodelitem.cpp +++ b/networkmanagement/networkmodelitem.cpp @@ -503,6 +503,37 @@ void NetworkModelItem::setTxBytes(qulonglong bytes) } } +QString NetworkModelItem::ipAddress() const +{ + updateDetails(); + return m_ipAdress; +} + +void NetworkModelItem::setIpAddress(const QString address) +{ + m_ipAdress = address; +} + +QString NetworkModelItem::router() const +{ + return m_router; +} + +void NetworkModelItem::setRouter(const QString router) +{ + m_router = router; +} + +QString NetworkModelItem::gateway() +{ + return m_gateway; +} + +void NetworkModelItem::setGateway(const QString gateWay) +{ + m_gateway = gateWay; +} + bool NetworkModelItem::operator==(const NetworkModelItem *item) const { if (!item->uuid().isEmpty() && !uuid().isEmpty()) { diff --git a/networkmanagement/networkmodelitem.h b/networkmanagement/networkmodelitem.h index d9431aa..9d2a263 100644 --- a/networkmanagement/networkmodelitem.h +++ b/networkmanagement/networkmodelitem.h @@ -117,6 +117,15 @@ public: qulonglong txBytes() const; void setTxBytes(qulonglong bytes); + QString ipAddress() const; + void setIpAddress(const QString address); + + QString router() const; + void setRouter(const QString router); + + QString gateway(); + void setGateway(const QString gateWay); + bool operator==(const NetworkModelItem *item) const; QVector changedRoles() const { return m_changedRoles; } @@ -155,6 +164,10 @@ private: qulonglong m_txBytes; QString m_icon; QVector m_changedRoles; + + mutable QString m_ipAdress; + mutable QString m_router; + mutable QString m_gateway; }; #endif // NETWORKMODELITEM_H