Commit 2954f00c authored by Martin Kacej's avatar Martin Kacej

connection editor refactored

parent 918ce976
......@@ -537,32 +537,20 @@ QVariantMap Handler::getActiveConnectionInfo(const QString &connection)
void Handler::addConnectionFromQML(const QVariantMap &QMLmap)
{
if(!QMLmap.isEmpty()){
NMVariantMapMap map;
QString id; // add UUID
for (QVariantMap::const_iterator iter = QMLmap.begin(); iter != QMLmap.end(); ++iter) {
if (iter.key() == QLatin1String("connection")) {
QVariantMap connectionMap = iter.value().toMap();
id = connectionMap.value("id").toString();
if (!connectionMap.contains(QLatin1String("uuid"))) {
connectionMap.insert(QLatin1String("uuid"), NetworkManager::ConnectionSettings::createNewUuid());
}
map.insert(QLatin1String("connection"), connectionMap);
} else {
map.insert(iter.key(), iter.value().toMap());
}
}
// add SSID
for (QVariantMap::const_iterator iter = QMLmap.begin(); iter != QMLmap.end(); ++iter) {
if (iter.key() == QLatin1String("802-11-wireless")) {
QVariantMap wirelessnMap = iter.value().toMap();
if (!wirelessnMap.contains(QLatin1String("uuid"))) {
wirelessnMap.insert(QLatin1String("ssid"), id.toUtf8());
}
map.insert(QLatin1String("802-11-wireless"), wirelessnMap);
}
}
// if settings are manual, convert dns to uint32
if (!QMLmap.isEmpty()) {
NetworkManager::WirelessSetting::Ptr wirelessSettings = NetworkManager::WirelessSetting::Ptr(new NetworkManager::WirelessSetting());
wirelessSettings->setSsid(QMLmap.value(QLatin1String("id")).toString().toUtf8());
wirelessSettings->setMode(NetworkManager::WirelessSetting::Infrastructure);
// TODO manual IP config
NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless));
connectionSettings->setId(QMLmap.value(QLatin1String("id")).toString());
connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
NMVariantMapMap map = connectionSettings->toMap();
map.insert("802-11-wireless",wirelessSettings->toMap());
qWarning() << map;
/* if settings are manual, convert dns to uint32
for (QVariantMap::const_iterator iter = QMLmap.begin(); iter != QMLmap.end(); ++iter) {
if (iter.key() == QLatin1String("ipv4")) {
QVariantMap ipv4Map = iter.value().toMap();
......@@ -575,9 +563,7 @@ void Handler::addConnectionFromQML(const QVariantMap &QMLmap)
}
map.insert(QLatin1String("ipv4"), ipv4Map);
}
}
qWarning() << map;
}*/
this->addConnection(map);
}
}
......
......@@ -28,7 +28,6 @@ Kirigami.ScrollablePage{
property var details
property var str: 0
property var connection : ({})
property var wirelessSettings: ({})
property var enabledSaving: (editorIpSection.enabledSave && editorSecuritySection.enabledSave && ssidField.text)
title: i18n("Connection Editor")
......@@ -65,7 +64,7 @@ Kirigami.ScrollablePage{
actions {
left: Kirigami.Action {
text: "save"
iconName: "dialog-ok"
enabled: enabledSaving
onTriggered: {
save()
......@@ -73,7 +72,7 @@ Kirigami.ScrollablePage{
}
}
right: Kirigami.Action {
iconName: "cancel"
iconName: "dialog-cancel"
onTriggered: {
applicationWindow().pageStack.pop()
}
......@@ -83,14 +82,10 @@ Kirigami.ScrollablePage{
function save() {
var m = ({});
connection = editorIpSection.ipmap
connection["id"] = ssidField.text
connection["type"] = "802-11-wireless"
wirelessSettings["mode"] = "infrastructure"
m["connection"] = connection
m["ipv4"] = editorIpSection.ipmap
m["802-11-wireless"] = wirelessSettings
handler.addConnectionFromQML(m)
connection["mode"] = "infrastructure"
handler.addConnectionFromQML(connection)
console.info('Connection saved '+ connection["id"])
}
}
......@@ -129,7 +129,8 @@ ColumnLayout {
target: ipmain;
ipmap : {
"method": "manual",
"address-data": [{"address": address, "prefix": prefix}],
"address": address,
"prefix": prefix,
"gateway": gateway,
"dns": dns
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment