summaryrefslogtreecommitdiffstats
path: root/network/wirednetworkmodel.cpp
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2022-01-28 16:54:55 -0500
committerScott Murray <scott.murray@konsulko.com>2022-01-28 17:00:09 -0500
commit5ef90db242ad29c9772f2237b477c58ef65545c7 (patch)
treef9b7b2e56a0aaec37bb9ef99faa316465613b941 /network/wirednetworkmodel.cpp
parent0fee9bfb0f656b78f34c44542329760be2980892 (diff)
Re-enable network supportmarlin_12.92.0marlin/12.92.012.92.0
Rework network support code to use new connman-glib library instead of the previously disabled agl-service-network API. The only user visible change is that a few extra previously exported header files have been pruned from installation to avoid exposing GLib usage and potentially requiring users needing to build against it. Bug-AGL: SPEC-4182 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Iab8f3c9d04ee603e06b80dfd92ac03d9d52af477
Diffstat (limited to 'network/wirednetworkmodel.cpp')
-rw-r--r--network/wirednetworkmodel.cpp175
1 files changed, 102 insertions, 73 deletions
diff --git a/network/wirednetworkmodel.cpp b/network/wirednetworkmodel.cpp
index 0d1209e..6fc8151 100644
--- a/network/wirednetworkmodel.cpp
+++ b/network/wirednetworkmodel.cpp
@@ -10,108 +10,137 @@ WiredNetworkModel::WiredNetworkModel(QObject *parent)
QVariantList WiredNetworkModel::readCurrentRouteConfig(const QModelIndex &index) const
{
- QVariantList ret;
+ QVariantList ret;
- if (!index.isValid())
- return ret;
+ if (!index.isValid())
+ return ret;
- if (index.row() < 0 || index.row() >= this->m_networks.count())
- 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;
+ 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;
+ QVariantList ret;
- if (!index.isValid())
- return ret;
+ if (!index.isValid())
+ return ret;
- if (index.row() < 0 || index.row() >= this->m_networks.count())
- 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;
+ 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;
+ QVariant ret;
- if (!index.isValid())
- return ret;
+ if (!index.isValid())
+ return ret;
- if (index.row() < 0 || index.row() >= m_networks.count())
- return ret;
+ if (index.row() < 0 || index.row() >= m_networks.count())
+ return ret;
- const ConnectionProfile *network = m_networks[index.row()];
+ const ConnectionProfile *network = m_networks[index.row()];
- switch (role) {
+ switch (role) {
case AddressRole:
- return network->address();
+ return network->address();
case SecurityRole:
- return network->security();
+ return network->security();
case ServiceRole:
- return network->service();
+ return network->service();
case StateRole:
- return network->state();
+ return network->state();
case RouteRole:
- return readCurrentRouteConfig(index);
+ return readCurrentRouteConfig(index);
case NameServerRole:
- return readCurrentNameServerConfig(index);
- }
+ return readCurrentNameServerConfig(index);
+ }
- return ret;
+ return ret;
}
QHash<int, QByteArray> WiredNetworkModel::roleNames() const {
- QHash<int, QByteArray> roles;
- roles[AddressRole] = "address";
- roles[SecurityRole] = "security";
- roles[ServiceRole] = "service";
- roles[StateRole] = "sstate";
- roles[RouteRole] = "sroute";
- roles[NameServerRole] = "nservers";
-
- return roles;
+ QHash<int, QByteArray> roles;
+ roles[AddressRole] = "address";
+ roles[SecurityRole] = "security";
+ roles[ServiceRole] = "service";
+ roles[StateRole] = "sstate";
+ roles[RouteRole] = "sroute";
+ roles[NameServerRole] = "nservers";
+
+ return roles;
}
-void WiredNetworkModel::updateProperties(QString service, QJsonObject properties)
+void WiredNetworkModel::updateProperties(const QString &service, const QVariantMap &properties)
{
- ConnectionProfile *network;
- QVector<int> vroles;
-
- if ((network = getNetwork(service))) {
- if (properties.contains("ipv4")) {
- 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());
- vroles.push_back(StateRole);
- }
- if (!vroles.isEmpty())
- emit dataChanged(indexOf(network), indexOf(network), vroles);
-
- }
+ ConnectionProfile *network;
+ QVector<int> vroles;
+
+ network = getNetwork(service);
+ if (!network)
+ return;
+
+ QString key = "IPv4";
+ if (properties.contains(key)) {
+ QVariantMap ip4_map = properties.value(key).toMap();
+
+ QString address;
+ key = "Address";
+ if (ip4_map.contains(key))
+ address = ip4_map.value(key).toString();
+
+ QString netmask;
+ key = "Netmask";
+ if (ip4_map.contains(key))
+ netmask = ip4_map.value(key).toString();
+
+ QString gateway;
+ key = "Gateway";
+ if (ip4_map.contains(key))
+ gateway = ip4_map.value(key).toString();
+
+ QString method;
+ key = "Method";
+ if (ip4_map.contains(key))
+ method = ip4_map.value(key).toString();
+
+ network->setAddress(address);
+ network->setNetmask(netmask);
+ network->setGateway(gateway);
+ network->setAddrMethod(method);
+ vroles.push_back(AddressRole);
+ vroles.push_back(RouteRole);
+ }
+
+ key = "Nameservers";
+ if (properties.contains(key)) {
+ QString ns = properties.value(key).toString();
+ network->setNameservers(ns);
+ (network->addrmethod() == "dhcp") ? network->setNSMethod("auto") :
+ network->setNSMethod("manual");
+ vroles.push_back(NameServerRole);
+ }
+
+ key = "State";
+ if (properties.contains(key)) {
+ QString state = properties.value(key).toString();
+ network->setState(state);
+ vroles.push_back(StateRole);
+ }
+
+ if (!vroles.isEmpty())
+ emit dataChanged(indexOf(network), indexOf(network), vroles);
}