@@ -49,8 +49,16 @@ const auto legacyDefaultDomain(QStringLiteral("merproject.org"));
49
49
int numericValue (VpnConnection::ConnectionState state)
50
50
{
51
51
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;
54
62
}
55
63
56
64
} // end anonymous namespace
@@ -324,11 +332,18 @@ void SettingsVpnModel::connectionsRefreshed()
324
332
{
325
333
qCDebug (lcVpnLog) << " VPN connections refreshed" ;
326
334
QVector<VpnConnection*> connections = vpnManager ()->connections ();
335
+
336
+ // Check to see if the best state has changed
337
+ VpnConnection::ConnectionState maxState = VpnConnection::Idle;
327
338
for (VpnConnection *conn : connections) {
328
339
connect (conn, &VpnConnection::nameChanged, this , &SettingsVpnModel::updatedConnectionPosition, Qt::UniqueConnection);
329
340
connect (conn, &VpnConnection::connectedChanged, this , &SettingsVpnModel::connectedChanged, Qt::UniqueConnection);
330
341
connect (conn, &VpnConnection::stateChanged, this , &SettingsVpnModel::stateChanged, Qt::UniqueConnection);
342
+
343
+ maxState = getMaxState (conn->state (), maxState);
331
344
}
345
+
346
+ updateBestState (maxState);
332
347
}
333
348
334
349
void SettingsVpnModel::stateChanged ()
@@ -338,17 +353,8 @@ void SettingsVpnModel::stateChanged()
338
353
emit connectionStateChanged (conn->path (), conn->state ());
339
354
340
355
// 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);
352
358
}
353
359
354
360
// ==========================================================================
@@ -830,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning
830
836
831
837
return rv;
832
838
}
839
+
840
+ void SettingsVpnModel::updateBestState (VpnConnection::ConnectionState maxState)
841
+ {
842
+ if (bestState_ != maxState) {
843
+ bestState_ = maxState;
844
+ emit bestStateChanged ();
845
+ }
846
+ }
0 commit comments