Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit 8f57939

Browse files
committed
[settings-vpn] Update VPN best state also when connections are refreshed. Fixes JB#48254
1 parent 4c72f54 commit 8f57939

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/settingsvpnmodel.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,16 @@ const auto legacyDefaultDomain(QStringLiteral("merproject.org"));
4949
int numericValue(VpnConnection::ConnectionState state)
5050
{
5151
return (state == VpnConnection::Ready ? 3 :
52-
(state == VpnConnection::Configuration ? 2 :
53-
(state == VpnConnection::Failure ? 1 : 0)));
52+
(state == VpnConnection::Configuration ? 2 : 0));
53+
}
54+
55+
VpnConnection::ConnectionState getMaxState(VpnConnection::ConnectionState newState, VpnConnection::ConnectionState oldState)
56+
{
57+
if (numericValue(newState) > numericValue(oldState)) {
58+
return newState;
59+
}
60+
61+
return oldState;
5462
}
5563

5664
} // end anonymous namespace
@@ -324,11 +332,18 @@ void SettingsVpnModel::connectionsRefreshed()
324332
{
325333
qCDebug(lcVpnLog) << "VPN connections refreshed";
326334
QVector<VpnConnection*> connections = vpnManager()->connections();
335+
336+
// Check to see if the best state has changed
337+
VpnConnection::ConnectionState maxState = VpnConnection::Idle;
327338
for (VpnConnection *conn : connections) {
328339
connect(conn, &VpnConnection::nameChanged, this, &SettingsVpnModel::updatedConnectionPosition, Qt::UniqueConnection);
329340
connect(conn, &VpnConnection::connectedChanged, this, &SettingsVpnModel::connectedChanged, Qt::UniqueConnection);
330341
connect(conn, &VpnConnection::stateChanged, this, &SettingsVpnModel::stateChanged, Qt::UniqueConnection);
342+
343+
maxState = getMaxState(conn->state(), maxState);
331344
}
345+
346+
updateBestState(maxState);
332347
}
333348

334349
void SettingsVpnModel::stateChanged()
@@ -338,17 +353,8 @@ void SettingsVpnModel::stateChanged()
338353
emit connectionStateChanged(conn->path(), conn->state());
339354

340355
// Check to see if the best state has changed
341-
VpnConnection::ConnectionState maxState = VpnConnection::Idle;
342-
for (VpnConnection *conn : connections()) {
343-
VpnConnection::ConnectionState state(conn->state());
344-
if (numericValue(state) > numericValue(maxState)) {
345-
maxState = state;
346-
}
347-
}
348-
if (bestState_ != maxState) {
349-
bestState_ = maxState;
350-
emit bestStateChanged();
351-
}
356+
VpnConnection::ConnectionState maxState = getMaxState(conn->state(), VpnConnection::Idle);
357+
updateBestState(maxState);
352358
}
353359

354360
// ==========================================================================
@@ -830,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning
830836

831837
return rv;
832838
}
839+
840+
void SettingsVpnModel::updateBestState(VpnConnection::ConnectionState maxState)
841+
{
842+
if (bestState_ != maxState) {
843+
bestState_ = maxState;
844+
emit bestStateChanged();
845+
}
846+
}

src/settingsvpnmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class SYSTEMSETTINGS_EXPORT SettingsVpnModel : public VpnModel
9898
virtual void orderConnections(QVector<VpnConnection*> &connections) override;
9999
bool compareConnections(const VpnConnection *i, const VpnConnection *j);
100100
QVariantMap processOpenVpnProvisioningFile(QFile &provisioningFile);
101+
void updateBestState(VpnConnection::ConnectionState maxState);
101102

102103
private Q_SLOTS:
103104
void connectionAdded(const QString &path);

0 commit comments

Comments
 (0)