Commit 8f579391 authored by Raine Makelainen's avatar Raine Makelainen

[settings-vpn] Update VPN best state also when connections are refreshed. Fixes JB#48254

parent 4c72f54b
......@@ -49,8 +49,16 @@ const auto legacyDefaultDomain(QStringLiteral("merproject.org"));
int numericValue(VpnConnection::ConnectionState state)
{
return (state == VpnConnection::Ready ? 3 :
(state == VpnConnection::Configuration ? 2 :
(state == VpnConnection::Failure ? 1 : 0)));
(state == VpnConnection::Configuration ? 2 : 0));
}
VpnConnection::ConnectionState getMaxState(VpnConnection::ConnectionState newState, VpnConnection::ConnectionState oldState)
{
if (numericValue(newState) > numericValue(oldState)) {
return newState;
}
return oldState;
}
} // end anonymous namespace
......@@ -324,11 +332,18 @@ void SettingsVpnModel::connectionsRefreshed()
{
qCDebug(lcVpnLog) << "VPN connections refreshed";
QVector<VpnConnection*> connections = vpnManager()->connections();
// Check to see if the best state has changed
VpnConnection::ConnectionState maxState = VpnConnection::Idle;
for (VpnConnection *conn : connections) {
connect(conn, &VpnConnection::nameChanged, this, &SettingsVpnModel::updatedConnectionPosition, Qt::UniqueConnection);
connect(conn, &VpnConnection::connectedChanged, this, &SettingsVpnModel::connectedChanged, Qt::UniqueConnection);
connect(conn, &VpnConnection::stateChanged, this, &SettingsVpnModel::stateChanged, Qt::UniqueConnection);
maxState = getMaxState(conn->state(), maxState);
}
updateBestState(maxState);
}
void SettingsVpnModel::stateChanged()
......@@ -338,17 +353,8 @@ void SettingsVpnModel::stateChanged()
emit connectionStateChanged(conn->path(), conn->state());
// Check to see if the best state has changed
VpnConnection::ConnectionState maxState = VpnConnection::Idle;
for (VpnConnection *conn : connections()) {
VpnConnection::ConnectionState state(conn->state());
if (numericValue(state) > numericValue(maxState)) {
maxState = state;
}
}
if (bestState_ != maxState) {
bestState_ = maxState;
emit bestStateChanged();
}
VpnConnection::ConnectionState maxState = getMaxState(conn->state(), VpnConnection::Idle);
updateBestState(maxState);
}
// ==========================================================================
......@@ -830,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning
return rv;
}
void SettingsVpnModel::updateBestState(VpnConnection::ConnectionState maxState)
{
if (bestState_ != maxState) {
bestState_ = maxState;
emit bestStateChanged();
}
}
......@@ -98,6 +98,7 @@ private:
virtual void orderConnections(QVector<VpnConnection*> &connections) override;
bool compareConnections(const VpnConnection *i, const VpnConnection *j);
QVariantMap processOpenVpnProvisioningFile(QFile &provisioningFile);
void updateBestState(VpnConnection::ConnectionState maxState);
private Q_SLOTS:
void connectionAdded(const QString &path);
......
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