Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[settings-vpn] Update VPN best state also when connections are refres…
…hed. Fixes JB#48254
  • Loading branch information
rainemak committed Nov 27, 2019
1 parent 4c72f54 commit 8f57939
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/settingsvpnmodel.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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);
}

// ==========================================================================
Expand Down Expand Up @@ -830,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning

return rv;
}

void SettingsVpnModel::updateBestState(VpnConnection::ConnectionState maxState)
{
if (bestState_ != maxState) {
bestState_ = maxState;
emit bestStateChanged();
}
}
1 change: 1 addition & 0 deletions src/settingsvpnmodel.h
Expand Up @@ -98,6 +98,7 @@ class SYSTEMSETTINGS_EXPORT SettingsVpnModel : public VpnModel
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);
Expand Down

0 comments on commit 8f57939

Please sign in to comment.