Skip to content

Commit

Permalink
Merge branch 'jb48087' into 'master'
Browse files Browse the repository at this point in the history
[settings-vpn] Remove obsoleted signal from use. Contributes to JB#48087

See merge request mer-core/nemo-qml-plugin-systemsettings!128
  • Loading branch information
rainemak committed Nov 27, 2019
2 parents 2b7582e + 8f57939 commit 97fd954
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
51 changes: 27 additions & 24 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 All @@ -71,7 +79,6 @@ SettingsVpnModel::SettingsVpnModel(QObject* parent)
connect(manager, &VpnManager::connectionAdded, this, &SettingsVpnModel::connectionAdded, Qt::UniqueConnection);
connect(manager, &VpnManager::connectionRemoved, this, &SettingsVpnModel::connectionRemoved, Qt::UniqueConnection);
connect(manager, &VpnManager::connectionsRefreshed, this, &SettingsVpnModel::connectionsRefreshed, Qt::UniqueConnection);
connect(manager, &VpnManager::connectionsClearingAll, this, &SettingsVpnModel::connectionsClearingAll, Qt::UniqueConnection);
}

SettingsVpnModel::~SettingsVpnModel()
Expand Down Expand Up @@ -321,25 +328,22 @@ void SettingsVpnModel::connectionRemoved(const QString &path)
}
}

void SettingsVpnModel::connectionsClearingAll()
{
qCDebug(lcVpnLog) << "VPN clearing all connections";
QVector<VpnConnection*> connections = vpnManager()->connections();
for (VpnConnection *conn : connections) {
disconnect(conn, 0, this, 0);
}
}


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 @@ -349,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 @@ -841,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning

return rv;
}

void SettingsVpnModel::updateBestState(VpnConnection::ConnectionState maxState)
{
if (bestState_ != maxState) {
bestState_ = maxState;
emit bestStateChanged();
}
}
2 changes: 1 addition & 1 deletion src/settingsvpnmodel.h
Expand Up @@ -98,11 +98,11 @@ 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);
void connectionRemoved(const QString &path);
void connectionsClearingAll();
void connectionsRefreshed();
void updatedConnectionPosition();
void connectedChanged();
Expand Down

0 comments on commit 97fd954

Please sign in to comment.