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

Commit 97fd954

Browse files
committed
Merge branch 'jb48087' into 'master'
[settings-vpn] Remove obsoleted signal from use. Contributes to JB#48087 See merge request mer-core/nemo-qml-plugin-systemsettings!128
2 parents 2b7582e + 8f57939 commit 97fd954

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/settingsvpnmodel.cpp

Lines changed: 27 additions & 24 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
@@ -71,7 +79,6 @@ SettingsVpnModel::SettingsVpnModel(QObject* parent)
7179
connect(manager, &VpnManager::connectionAdded, this, &SettingsVpnModel::connectionAdded, Qt::UniqueConnection);
7280
connect(manager, &VpnManager::connectionRemoved, this, &SettingsVpnModel::connectionRemoved, Qt::UniqueConnection);
7381
connect(manager, &VpnManager::connectionsRefreshed, this, &SettingsVpnModel::connectionsRefreshed, Qt::UniqueConnection);
74-
connect(manager, &VpnManager::connectionsClearingAll, this, &SettingsVpnModel::connectionsClearingAll, Qt::UniqueConnection);
7582
}
7683

7784
SettingsVpnModel::~SettingsVpnModel()
@@ -321,25 +328,22 @@ void SettingsVpnModel::connectionRemoved(const QString &path)
321328
}
322329
}
323330

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-
334331
void SettingsVpnModel::connectionsRefreshed()
335332
{
336333
qCDebug(lcVpnLog) << "VPN connections refreshed";
337334
QVector<VpnConnection*> connections = vpnManager()->connections();
335+
336+
// Check to see if the best state has changed
337+
VpnConnection::ConnectionState maxState = VpnConnection::Idle;
338338
for (VpnConnection *conn : connections) {
339339
connect(conn, &VpnConnection::nameChanged, this, &SettingsVpnModel::updatedConnectionPosition, Qt::UniqueConnection);
340340
connect(conn, &VpnConnection::connectedChanged, this, &SettingsVpnModel::connectedChanged, Qt::UniqueConnection);
341341
connect(conn, &VpnConnection::stateChanged, this, &SettingsVpnModel::stateChanged, Qt::UniqueConnection);
342+
343+
maxState = getMaxState(conn->state(), maxState);
342344
}
345+
346+
updateBestState(maxState);
343347
}
344348

345349
void SettingsVpnModel::stateChanged()
@@ -349,17 +353,8 @@ void SettingsVpnModel::stateChanged()
349353
emit connectionStateChanged(conn->path(), conn->state());
350354

351355
// 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);
363358
}
364359

365360
// ==========================================================================
@@ -841,3 +836,11 @@ QVariantMap SettingsVpnModel::processOpenVpnProvisioningFile(QFile &provisioning
841836

842837
return rv;
843838
}
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ 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);
104105
void connectionRemoved(const QString &path);
105-
void connectionsClearingAll();
106106
void connectionsRefreshed();
107107
void updatedConnectionPosition();
108108
void connectedChanged();

0 commit comments

Comments
 (0)