summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2017-01-11 08:15:33 +0100
committerJan Grulich <[email protected]>2017-01-11 08:15:33 +0100
commit8773885d63b146981584a20b1b06bcf2fcf32b7b (patch)
tree28767a75d75db69f78443b0a59a9299ffef2c52e
parent54f6fd6e985d4cdee0432da152098de735fda0ec (diff)
KCM: Automaticaly select the newly created connection once is added
-rwxr-xr-xkcm/kcm.cpp25
-rwxr-xr-xkcm/kcm.h2
2 files changed, 25 insertions, 2 deletions
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
index 3e4e1c4..5ddf132 100755
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -142,6 +142,8 @@ KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &
}
}
+ connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KCMNetworkmanagement::onConnectionAdded, Qt::UniqueConnection);
+
// Initialize first scan and then scan every 15 seconds
m_handler->requestScan();
@@ -199,6 +201,24 @@ void KCMNetworkmanagement::save()
KCModule::save();
}
+void KCMNetworkmanagement::onConnectionAdded(const QString &connection)
+{
+ if (m_createdConnectionUuid.isEmpty()) {
+ return;
+ }
+
+ NetworkManager::Connection::Ptr newConnection = NetworkManager::findConnection(connection);
+ if (newConnection) {
+ NetworkManager::ConnectionSettings::Ptr connectionSettings = newConnection->settings();
+ if (connectionSettings && connectionSettings->uuid() == m_createdConnectionUuid) {
+ QObject *rootItem = m_quickView->rootObject();
+ loadConnectionSettings(connectionSettings);
+ QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, connectionSettings->id()), Q_ARG(QVariant, newConnection->path()));
+ m_createdConnectionUuid.clear();
+ }
+ }
+}
+
void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared)
{
NetworkManager::ConnectionSettings::ConnectionType type = static_cast<NetworkManager::ConnectionSettings::ConnectionType>(connectionType);
@@ -287,6 +307,7 @@ void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const Q
}
}
// Generate new UUID
+
connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
addConnection(connectionSettings);
}
@@ -353,11 +374,11 @@ void KCMNetworkmanagement::onSelectedConnectionChanged(const QString &connection
void KCMNetworkmanagement::addConnection(const NetworkManager::ConnectionSettings::Ptr &connectionSettings)
{
- resetSelection();
-
QPointer<ConnectionEditorDialog> editor = new ConnectionEditorDialog(connectionSettings);
connect(editor.data(), &ConnectionEditorDialog::accepted,
[connectionSettings, editor, this] () {
+ // We got confirmation so watch this connection and select it once it is created
+ m_createdConnectionUuid = connectionSettings->uuid();
m_handler->addConnection(editor->setting());
});
connect(editor.data(), &ConnectionEditorDialog::finished,
diff --git a/kcm/kcm.h b/kcm/kcm.h
index 659eeaa..adb924c 100755
--- a/kcm/kcm.h
+++ b/kcm/kcm.h
@@ -42,6 +42,7 @@ public Q_SLOTS:
void save() override;
private Q_SLOTS:
+ void onConnectionAdded(const QString &connection);
void onSelectedConnectionChanged(const QString &connectionPath);
void onRequestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared);
void onRequestExportConnection(const QString &connectionPath);
@@ -53,6 +54,7 @@ private:
void importVpn();
QString m_currentConnectionPath;
+ QString m_createdConnectionUuid;
Handler *m_handler;
ConnectionEditorTabWidget *m_tabWidget;
QTimer *m_timer;