@@ -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
@@ -71,7 +79,6 @@ SettingsVpnModel::SettingsVpnModel(QObject* parent)
71
79
connect (manager, &VpnManager::connectionAdded, this , &SettingsVpnModel::connectionAdded, Qt::UniqueConnection);
72
80
connect (manager, &VpnManager::connectionRemoved, this , &SettingsVpnModel::connectionRemoved, Qt::UniqueConnection);
73
81
connect (manager, &VpnManager::connectionsRefreshed, this , &SettingsVpnModel::connectionsRefreshed, Qt::UniqueConnection);
74
- connect (manager, &VpnManager::connectionsClearingAll, this , &SettingsVpnModel::connectionsClearingAll, Qt::UniqueConnection);
75
82
}
76
83
77
84
SettingsVpnModel::~SettingsVpnModel ()
@@ -321,25 +328,22 @@ void SettingsVpnModel::connectionRemoved(const QString &path)
321
328
}
322
329
}
323
330
324
- void SettingsVpnModel::connectionsClearingAll ()
325
- {
326
- qCDebug (lcVpnLog) << " VPN clearing all connections" ;
327
- QVector<VpnConnection*> connections = vpnManager ()->connections ();
328
- for (VpnConnection *conn : connections) {
329
- disconnect (conn, 0 , this , 0 );
330
- }
331
- }
332
-
333
-
334
331
void SettingsVpnModel::connectionsRefreshed ()
335
332
{
336
333
qCDebug (lcVpnLog) << " VPN connections refreshed" ;
337
334
QVector<VpnConnection*> connections = vpnManager ()->connections ();
335
+
336
+ // Check to see if the best state has changed
337
+ VpnConnection::ConnectionState maxState = VpnConnection::Idle;
338
338
for (VpnConnection *conn : connections) {
339
339
connect (conn, &VpnConnection::nameChanged, this , &SettingsVpnModel::updatedConnectionPosition, Qt::UniqueConnection);
340
340
connect (conn, &VpnConnection::connectedChanged, this , &SettingsVpnModel::connectedChanged, Qt::UniqueConnection);
341
341
connect (conn, &VpnConnection::stateChanged, this , &SettingsVpnModel::stateChanged, Qt::UniqueConnection);
342
+
343
+ maxState = getMaxState (conn->state (), maxState);
342
344
}
345
+
346
+ updateBestState (maxState);
343
347
}
344
348
345
349
void SettingsVpnModel::stateChanged ()
@@ -349,17 +353,8 @@ void SettingsVpnModel::stateChanged()
349
353
emit connectionStateChanged (conn->path (), conn->state ());
350
354
351
355
// Check to see if the best state has changed
352
- VpnConnection::ConnectionState maxState = VpnConnection::Idle;
353
- for (VpnConnection *conn : connections ()) {
354
- VpnConnection::ConnectionState state (conn->state ());
355
- if (numericValue (state) > numericValue (maxState)) {
356
- maxState = state;
357
- }
358
- }
359
- if (bestState_ != maxState) {
360
- bestState_ = maxState;
361
- emit bestStateChanged ();
362
- }
356
+ VpnConnection::ConnectionState maxState = getMaxState (conn->state (), VpnConnection::Idle);
357
+ updateBestState (maxState);
363
358
}
364
359
365
360
// ==========================================================================
@@ -841,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning
841
836
842
837
return rv;
843
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