#include "networkcreator.h" #include "ui_networkcreator.h" #include NetworkCreator::NetworkCreator(QWidget *parent) : QDialog(parent), ui(new Ui::NetworkCreator) { ui->setupUi(this); ui->connectionTypeComboBox->addItems(QStringList() << tr("Ethernet") << tr("WiFi")); connect(ui->okButton, &QPushButton::clicked, this, &NetworkCreator::onOkButtonClicked); connect(ui->cancelButton, &QPushButton::clicked, this, &NetworkCreator::onCancelButtonClicked); } NetworkCreator::~NetworkCreator() { delete ui; } void NetworkCreator::onOkButtonClicked() { NetworkManager::ConnectionSettings::Ptr connSettings; NetworkManager::WiredSetting::Ptr wiredSetting; NetworkManager::WirelessSetting::Ptr wirelessSetting; switch(ui->connectionTypeComboBox->currentIndex()) { case 0: // Ethernet connSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wired)); wiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); wiredSetting->setAutoNegotiate(true); break; case 1: // WiFi connSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless)); wirelessSetting = connSettings->setting(NetworkManager::Setting::Wireless).dynamicCast(); wirelessSetting->setSsid(QString("test").toUtf8()); break; } connSettings->setId(ui->connectionNameLineEdit->text()); connSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); NMVariantMapMap settingsMap = connSettings->toMap(); if (!wiredSetting.isNull()) { settingsMap.insert("802-3-ethernet", wiredSetting->toMap()); } else if (!wirelessSetting.isNull()) { settingsMap.insert("802-11-wireless", wirelessSetting->toMap()); } QDBusPendingReply<> reply = NetworkManager::addConnection(settingsMap); auto watcher = new QDBusPendingCallWatcher(reply); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &NetworkCreator::createReplyFinished); } void NetworkCreator::onCancelButtonClicked() { this->done(0); } void NetworkCreator::createReplyFinished() { this->done(0); }