summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2019-06-05 12:54:02 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-06-11 15:01:45 +0000
commitb2ecc0352f09343297e2354fecb9c2c9b54d1126 (patch)
treee8908bcc9bb4be4b7b097d92a5e1f6cd733068eb /network
parentd3632244d611435f48f5aeb653f9031ace9a3b20 (diff)
network: rework WifiNetworkModel implementation
Rework WifiNetworkModel implementation to use AbstractNetworkModel and ConnectionProfile classes. Bug-AGL: SPEC-2293 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: I47dc3dc1ef54ae24e176f8ff269b1219f3fcbc6c
Diffstat (limited to 'network')
-rw-r--r--network/CMakeLists.txt4
-rw-r--r--network/networkadapter.cpp3
-rw-r--r--network/wifinetworkmodel.cpp110
-rw-r--r--network/wifinetworkmodel.h50
4 files changed, 14 insertions, 153 deletions
diff --git a/network/CMakeLists.txt b/network/CMakeLists.txt
index 5c15f46..cfefeb0 100644
--- a/network/CMakeLists.txt
+++ b/network/CMakeLists.txt
@@ -1,2 +1,2 @@
-add_headers(network.h networkmessage.h networkadapter.h wifinetworkmodel.h)
-add_sources(network.cpp networkmessage.cpp networkadapter.cpp wifinetworkmodel.cpp)
+add_headers(network.h networkmessage.h networkadapter.h wifinetworkmodel.h abstractnetworkmodel.h connectionprofile.h)
+add_sources(network.cpp networkmessage.cpp networkadapter.cpp wifinetworkmodel.cpp abstractnetworkmodel.cpp connectionprofile.cpp)
diff --git a/network/networkadapter.cpp b/network/networkadapter.cpp
index 2ba3cfc..6cfb9be 100644
--- a/network/networkadapter.cpp
+++ b/network/networkadapter.cpp
@@ -21,6 +21,7 @@
#include "network.h"
#include "networkadapter.h"
#include "wifinetworkmodel.h"
+#include "connectionprofile.h"
WifiAdapter::WifiAdapter(Network *network, QQmlContext *context, QObject *parent) :
QObject(parent),
@@ -93,7 +94,7 @@ bool WifiAdapter::addService(QString id, QJsonObject properties)
if (type != getType())
return false;
- WifiNetwork *network = new WifiNetwork(address, security, id, ssid, state, strength);
+ ConnectionProfile *network = new ConnectionProfile(address, security, id, state, ssid, strength);
m_model->addNetwork(network);
if ((state == "ready") || (state == "online"))
diff --git a/network/wifinetworkmodel.cpp b/network/wifinetworkmodel.cpp
index 2691d6e..71e5298 100644
--- a/network/wifinetworkmodel.cpp
+++ b/network/wifinetworkmodel.cpp
@@ -1,95 +1,10 @@
#include "wifinetworkmodel.h"
+#include "connectionprofile.h"
#include <QDebug>
-WifiNetwork::WifiNetwork(const QString &address,
- const QString &security,
- const QString &service,
- const QString &ssid,
- const QString &state,
- const int &strength)
- : m_address(address), m_security(security), m_service(service),
- m_ssid(ssid), m_state(state), m_strength(strength)
-{
-}
-
-QString WifiNetwork::address() const
-{
- return m_address;
-}
-
-QString WifiNetwork::security() const
-{
- return m_security;
-}
-
-QString WifiNetwork::service() const
-{
- return m_service;
-}
-
-QString WifiNetwork::ssid() const
-{
- return m_ssid;
-}
-
-QString WifiNetwork::state() const
-{
- return m_state;
-}
-
-int WifiNetwork::strength() const
-{
- return m_strength;
-}
-
-void WifiNetwork::setAddress(const QString address)
-{
- m_address = address;
-}
-
-void WifiNetwork::setState(const QString state)
-{
- m_state = state;
-}
-
-void WifiNetwork::setStrength(const int strength)
-{
- m_strength = strength;
-}
-
WifiNetworkModel::WifiNetworkModel(QObject *parent)
- : QAbstractListModel(parent)
-{
-}
-
-void WifiNetworkModel::addNetwork(WifiNetwork *network)
-{
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_networks << network;
- endInsertRows();
-}
-
-void WifiNetworkModel::removeNetwork(WifiNetwork *network)
-{
- int row = m_networks.indexOf(network);
- beginRemoveRows(QModelIndex(), row, row);
- m_networks.removeAt(row);
- endRemoveRows();
- delete network;
-}
-
-void WifiNetworkModel::removeAllNetworks()
+ : AbstractNetworkModel(parent)
{
- beginRemoveRows(QModelIndex(), 0, m_networks.count() - 1);
- qDeleteAll(m_networks.begin(), m_networks.end());
- m_networks.clear();
- endRemoveRows();
-}
-
-int WifiNetworkModel::rowCount(const QModelIndex &parent) const
-{
- Q_UNUSED(parent);
- return m_networks.count();
}
QVariant WifiNetworkModel::data(const QModelIndex &index, int role) const
@@ -97,7 +12,7 @@ QVariant WifiNetworkModel::data(const QModelIndex &index, int role) const
if (index.row() < 0 || index.row() >= m_networks.count())
return QVariant();
- const WifiNetwork *network = m_networks[index.row()];
+ ConnectionProfile *network = m_networks[index.row()];
switch (role) {
case AddressRole:
@@ -129,26 +44,9 @@ QHash<int, QByteArray> WifiNetworkModel::roleNames() const {
return roles;
}
-QModelIndex WifiNetworkModel::indexOf(WifiNetwork *network)
-{
- int row = m_networks.indexOf(network);
-
- return index(row);
-}
-
-WifiNetwork *WifiNetworkModel::getNetwork(QString service)
-{
- for (auto network : m_networks) {
- if (network->service() == service)
- return network;
- }
-
- return nullptr;
-}
-
void WifiNetworkModel::updateProperties(QString service, QJsonObject properties)
{
- WifiNetwork *network;
+ ConnectionProfile *network;
// FIXME: add role parameter to emits
if ((network = getNetwork(service))) {
diff --git a/network/wifinetworkmodel.h b/network/wifinetworkmodel.h
index 0df4459..94cc7f5 100644
--- a/network/wifinetworkmodel.h
+++ b/network/wifinetworkmodel.h
@@ -1,40 +1,9 @@
#ifndef WIFI_NETWORK_MODEL_H
#define WIFI_NETWORK_MODEL_H
-#include <QAbstractListModel>
-#include <QStringList>
-#include <QtQml/QQmlContext>
-#include <QJsonObject>
+#include "abstractnetworkmodel.h"
-class WifiNetwork
-{
- public:
- WifiNetwork(const QString &address,
- const QString &security,
- const QString &service,
- const QString &ssid,
- const QString &state,
- const int &strength);
- QString address() const;
- QString service() const;
- QString ssid() const;
- QString security() const;
- QString state() const;
- int strength() const;
- void setAddress(const QString address);
- void setState(const QString state);
- void setStrength(const int strength);
-
- private:
- QString m_address;
- QString m_security;
- QString m_service;
- QString m_ssid;
- QString m_state;
- int m_strength;
-};
-
-class WifiNetworkModel : public QAbstractListModel
+class WifiNetworkModel : public AbstractNetworkModel
{
Q_OBJECT
@@ -43,20 +12,16 @@ class WifiNetworkModel : public QAbstractListModel
AddressRole = Qt::UserRole + 1,
SecurityRole,
ServiceRole,
- SsidRole,
StateRole,
+ SsidRole,
StrengthRole
};
WifiNetworkModel(QObject *parent = Q_NULLPTR);
- void addNetwork(WifiNetwork *network);
- void removeNetwork(WifiNetwork *network);
- void removeAllNetworks();
- WifiNetwork *getNetwork(QString service);
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- void updateProperties(QString service, QJsonObject properties);
+ QString getType() const override { return "wifi"; }
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ void updateProperties(QString service, QJsonObject properties) override;
signals:
void strengthChanged(int strength);
@@ -64,8 +29,5 @@ class WifiNetworkModel : public QAbstractListModel
protected:
QHash<int, QByteArray> roleNames() const;
- private:
- QList<WifiNetwork *> m_networks;
- QModelIndex indexOf(WifiNetwork *network);
};
#endif // WIFI_NETWORK_MODEL_H