Skip to content

Commit

Permalink
[nemo-settings-system] Connect pending disconnect only when disconnec…
Browse files Browse the repository at this point in the history
…ting. Contributes to JB#41460

When trying to connect and there is an active connection, disconnection
is requested and after disconnected succussfully the new vpn
connection is established.
  • Loading branch information
rainemak committed Apr 11, 2018
1 parent 09ed943 commit a5dbc43
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/vpnmodel.cpp
Expand Up @@ -509,18 +509,18 @@ void VpnModel::deleteConnection(const QString &path)

void VpnModel::activateConnection(const QString &path)
{
qCInfo(lcVpnLog) << "Connect" << path;
for (int i = 0, n = count(); i < n; ++i) {
VpnConnection *connection = qobject_cast<VpnConnection *>(get(i));
QString otherPath = connection->path();
if (otherPath != path && !pendingDisconnects_.contains(otherPath) && (connection->state() == VpnModel::Ready ||
connection->state() == VpnModel::Configuration)) {
pendingDisconnects_.insert(otherPath, connection);
deactivateConnection(otherPath);
qCDebug(lcVpnLog) << "Adding pending vpn disconnect" << otherPath << connection->state() << "when connecting to vpn";
}
}

qCDebug(lcVpnLog) << "About to connect has pending:" << !pendingDisconnects_.isEmpty() << pendingDisconnects_.keys();
qCDebug(lcVpnLog) << "About to connect has pending disconnects:" << !pendingDisconnects_.isEmpty() << pendingDisconnects_.keys() << "connecting:" << path;

if (pendingDisconnects_.isEmpty()) {
auto it = connections_.find(path);
Expand Down Expand Up @@ -548,13 +548,15 @@ void VpnModel::activateConnection(const QString &path)

void VpnModel::deactivateConnection(const QString &path)
{
qCInfo(lcVpnLog) << "Disconnect" << path;
auto it = connections_.find(path);
if (it != connections_.end()) {
VpnConnection *connection = this->connection(path);
if (connection && !pendingDisconnects_.contains(path) && (connection->state() == VpnModel::Ready ||
connection->state() == VpnModel::Configuration)) {
qCDebug(lcVpnLog) << "Adding pending vpn disconnect" << path << connection->state() << "when disconnecting from a vpn";
pendingDisconnects_.insert(path, connection);
connect(connection, &VpnConnection::stateChanged, this, &VpnModel::updatePendingDisconnectState, Qt::UniqueConnection);
}

ConnmanVpnConnectionProxy *proxy(*it);
Expand Down Expand Up @@ -737,6 +739,8 @@ void VpnModel::updatePendingDisconnectState()
pendingDisconnects_.remove(pendingDisconnect->path());
qCDebug(lcVpnLog) << "Pending disconnect is idle" << pendingDisconnect->path() << pendingDisconnect->name();

disconnect(pendingDisconnect, &VpnConnection::stateChanged, this, &VpnModel::updatePendingDisconnectState);

if (pendingDisconnects_.isEmpty() && !pendingConnect_.isEmpty()) {
qCDebug(lcVpnLog) << "Will activate vpn" << pendingConnect_;
activateConnection(pendingConnect_);
Expand All @@ -748,7 +752,6 @@ void VpnModel::updatePendingDisconnectState()
VpnConnection *VpnModel::newConnection(const QString &path)
{
VpnConnection *conn = new VpnConnection(path);
connect(conn, &VpnConnection::stateChanged, this, &VpnModel::updatePendingDisconnectState, Qt::UniqueConnection);
appendItem(conn);

// Create a vpn and a connman service proxies for this connection
Expand Down

0 comments on commit a5dbc43

Please sign in to comment.