summaryrefslogtreecommitdiffstats
path: root/network/wirednetworkmodel.cpp
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2019-06-17 19:39:23 +0200
committerraquel medina <raquel.medina@konsulko.com>2019-06-18 11:20:43 +0000
commite89c4886888a322a21cf7c89c1ee2864dbb4e815 (patch)
tree1f943c3afd60bf56f79d4e28803ffe1aca55f654 /network/wirednetworkmodel.cpp
parent9d896c9c8f5622370362091f38bbc5d1f4189901 (diff)
network: add wired adapter & model
-Add WiredAdapter implementation -Add WiredNetworkModel implementation Bug-AGL: SPEC-2293 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: Ibed93ae3a3cca1bc8e7a23c872c7ab3b8271e586
Diffstat (limited to 'network/wirednetworkmodel.cpp')
-rw-r--r--network/wirednetworkmodel.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/network/wirednetworkmodel.cpp b/network/wirednetworkmodel.cpp
new file mode 100644
index 0000000..d14bce4
--- /dev/null
+++ b/network/wirednetworkmodel.cpp
@@ -0,0 +1,57 @@
+#include "wirednetworkmodel.h"
+#include "connectionprofile.h"
+#include <QDebug>
+
+WiredNetworkModel::WiredNetworkModel(QObject *parent)
+ : AbstractNetworkModel(parent)
+{
+}
+
+QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() >= m_networks.count())
+ return QVariant();
+
+ const ConnectionProfile *network = m_networks[index.row()];
+
+ switch (role) {
+ case AddressRole:
+ return network->address();
+ case SecurityRole:
+ return network->security();
+ case ServiceRole:
+ return network->service();
+ case StateRole:
+ return network->state();
+ }
+
+ return QVariant();
+}
+
+QHash<int, QByteArray> WiredNetworkModel::roleNames() const {
+ QHash<int, QByteArray> roles;
+ roles[AddressRole] = "address";
+ roles[SecurityRole] = "security";
+ roles[ServiceRole] = "service";
+ roles[StateRole] = "sstate";
+
+ return roles;
+}
+
+void WiredNetworkModel::updateProperties(QString service, QJsonObject properties)
+{
+ ConnectionProfile *network;
+
+ // FIXME: add role parameter to emits
+ if ((network = getNetwork(service))) {
+ if (properties.contains("ipv4")) {
+ QString address = properties.value("ipv4").toObject().value("address").toString();
+ network->setAddress(address);
+ emit dataChanged(indexOf(network), indexOf(network));
+ }
+ if (properties.contains("state")) {
+ network->setState(properties.value("state").toString());
+ emit dataChanged(indexOf(network), indexOf(network));
+ }
+ }
+}