From 4221fd2f9e5b72090fe5c2c5f19aa16ab8bf68b8 Mon Sep 17 00:00:00 2001 From: Raquel Medina Date: Mon, 9 Sep 2019 00:35:55 +0200 Subject: wired: add hooks for addressing configuration - Add new roles to provide UI clients with the active configuration (values obtained from the stack: agl-service-network binding + connman). - Add Q_INVOKABLE methods to feed new values from the UI client. SPEC-2676 Signed-off-by: Raquel Medina Change-Id: Id239ddc549ec8471d44d56f7631d4e9e3efda798 --- network/wirednetworkmodel.cpp | 55 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'network/wirednetworkmodel.cpp') diff --git a/network/wirednetworkmodel.cpp b/network/wirednetworkmodel.cpp index 01a50fb..0d1209e 100644 --- a/network/wirednetworkmodel.cpp +++ b/network/wirednetworkmodel.cpp @@ -8,6 +8,40 @@ WiredNetworkModel::WiredNetworkModel(QObject *parent) { } +QVariantList WiredNetworkModel::readCurrentRouteConfig(const QModelIndex &index) const +{ + QVariantList ret; + + if (!index.isValid()) + return ret; + + if (index.row() < 0 || index.row() >= this->m_networks.count()) + return ret; + + const ConnectionProfile *network = this->m_networks[index.row()]; + ret.append(network->addrmethod()); + ret.append(network->address()); + ret.append(network->netmask()); + ret.append(network->gateway()); + return ret; +} + +QVariantList WiredNetworkModel::readCurrentNameServerConfig(const QModelIndex &index) const +{ + QVariantList ret; + + if (!index.isValid()) + return ret; + + if (index.row() < 0 || index.row() >= this->m_networks.count()) + return ret; + + const ConnectionProfile *network = this->m_networks[index.row()]; + ret.append(network->nsmethod()); + ret.append(network->nameservers()); + return ret; +} + QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const { QVariant ret; @@ -29,6 +63,10 @@ QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const return network->service(); case StateRole: return network->state(); + case RouteRole: + return readCurrentRouteConfig(index); + case NameServerRole: + return readCurrentNameServerConfig(index); } return ret; @@ -40,6 +78,8 @@ QHash WiredNetworkModel::roleNames() const { roles[SecurityRole] = "security"; roles[ServiceRole] = "service"; roles[StateRole] = "sstate"; + roles[RouteRole] = "sroute"; + roles[NameServerRole] = "nservers"; return roles; } @@ -51,9 +91,20 @@ void WiredNetworkModel::updateProperties(QString service, QJsonObject properties if ((network = getNetwork(service))) { if (properties.contains("ipv4")) { - QString address = properties.value("ipv4").toObject().value("address").toString(); - network->setAddress(address); + QJsonObject ipv4obj = properties.value("ipv4").toObject(); + network->setAddress(ipv4obj.value("address").toString()); + network->setNetmask(ipv4obj.value("netmask").toString()); + network->setGateway(ipv4obj.value("gateway").toString()); + network->setAddrMethod(ipv4obj.value("method").toString()); vroles.push_back(AddressRole); + vroles.push_back(RouteRole); + } + if (properties.contains("nameservers")) { + QString nservers = properties.value("nameservers").toString(); + network->setNameservers(nservers); + (network->addrmethod() == "dhcp")? network->setNSMethod("auto") : + network->setNSMethod("manual"); + vroles.push_back(NameServerRole); } if (properties.contains("state")) { network->setState(properties.value("state").toString()); -- cgit 1.2.3-korg