Skip to content

Commit

Permalink
Merge branch 'jb45606' into 'master'
Browse files Browse the repository at this point in the history
Replace DefaultRoute string use to SplitRouting boolean

See merge request mer-core/libconnman-qt!49
  • Loading branch information
LaakkonenJussi committed Sep 11, 2020
2 parents a0b6b0d + bf420a0 commit 9fec2f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 44 deletions.
51 changes: 13 additions & 38 deletions libconnman-qt/vpnconnection.cpp
Expand Up @@ -52,10 +52,7 @@ namespace {
const QString connmanService = QStringLiteral("net.connman");
const QString connmanVpnService = QStringLiteral("net.connman.vpn");
const QString autoConnectKey = QStringLiteral("AutoConnect");
const QString defaultRouteKey = QStringLiteral("DefaultRoute");
const QString defaultRoutePropertyName = QStringLiteral("defaultRoute");
const QString strTrue = QString("true");
const QString strFalse = QString("false");
const QString splitRoutingKey = QStringLiteral("SplitRouting");

QString vpnServicePath(const QString &connectionPath)
{
Expand All @@ -69,7 +66,7 @@ VpnConnectionPrivate::VpnConnectionPrivate(VpnConnection &qq, const QString &pat
, m_serviceProxy(connmanService, vpnServicePath(path), QDBusConnection::systemBus(), nullptr)
, m_path(path)
, m_autoConnect(false)
, m_defaultRoute(true)
, m_splitRouting(false)
, m_state(VpnConnection::Idle)
, q_ptr(&qq)
{
Expand All @@ -89,16 +86,8 @@ void VpnConnectionPrivate::init()
QDBusMessage message = reply.reply();
QVariantMap properties = MarshalUtils::demarshallArgument<QVariantMap>(message.arguments().value(0));
bool autoConnect = properties.value(autoConnectKey).toBool();
QString str = properties.value(defaultRouteKey).toString();
properties.clear();
properties.insert(autoConnectKey, autoConnect);

// Don't add the value if it is not set. Undefined value is treated being as the default value (true)
if (!str.isEmpty()) {
bool defaultRoute = str == strTrue;
properties.insert(defaultRouteKey, defaultRoute);
}

q->update(MarshalUtils::propertiesToQml(properties));
} else {
qDebug() << "Error :" << m_path << ":" << reply.error().message();
Expand Down Expand Up @@ -168,10 +157,6 @@ void VpnConnection::modifyConnection(const QVariantMap &properties)
updatedProperties.remove(QString("immutable"));
updatedProperties.remove(QString("storeCredentials"));

// Convert defaultRoute bool to string for ConnMan
d->m_defaultRoute = updatedProperties.value(defaultRoutePropertyName).toBool();
updatedProperties.insert(defaultRoutePropertyName, d->m_defaultRoute ? strTrue : strFalse);

// SetProperty supports a single property or an array of properties
d->m_connectionProxy.SetProperty(QString("Properties"),
QDBusVariant(MarshalUtils::propertiesToDBus(updatedProperties)));
Expand Down Expand Up @@ -253,7 +238,7 @@ void VpnConnection::update(const QVariantMap &updateProperties)
d->checkChanged(properties, emissions, "userRoutes", &VpnConnection::userRoutesChanged);
d->checkChanged(properties, emissions, "serverRoutes", &VpnConnection::serverRoutesChanged);

d->updateVariable(properties, emissions, "defaultRoute", &d->m_defaultRoute, &VpnConnection::defaultRouteChanged);
d->updateVariable(properties, emissions, "splitRouting", &d->m_splitRouting, &VpnConnection::splitRoutingChanged);
d->updateVariable(properties, emissions, "autoConnect", &d->m_autoConnect, &VpnConnection::autoConnectChanged);
d->updateVariable(properties, emissions, "state", &d->m_state, &VpnConnection::stateChanged);

Expand Down Expand Up @@ -313,25 +298,22 @@ void VpnConnection::setAutoConnect(bool autoConnect)
}
}

bool VpnConnection::defaultRoute() const
bool VpnConnection::splitRouting() const
{
Q_D(const VpnConnection);

return d->m_defaultRoute;
return d->m_splitRouting;
}

void VpnConnection::setDefaultRoute(bool defaultRoute)
void VpnConnection::setSplitRouting(bool splitRouting)
{
Q_D(VpnConnection);

if (d->m_defaultRoute != defaultRoute) {
d->m_defaultRoute = defaultRoute;
qDebug() << "VPN defaultRoute changed:" << d->m_properties.value("name").toString() << defaultRoute;

QString defaultRouteStr = defaultRoute ? strTrue : strFalse;
d->m_serviceProxy.SetProperty(defaultRouteKey, QDBusVariant(defaultRouteStr));

emit defaultRouteChanged();
if (d->m_splitRouting != splitRouting) {
d->m_splitRouting = splitRouting;
qDebug() << "VPN splitRouting changed:" << d->m_properties.value("name").toString() << splitRouting;
d->m_serviceProxy.SetProperty(splitRoutingKey, QDBusVariant(splitRouting));
emit splitRoutingChanged();
}
}

Expand Down Expand Up @@ -395,15 +377,8 @@ inline void VpnConnectionPrivate::updateVariable(QVariantMap &properties, QQueue
{
QVariantMap::const_iterator it = properties.constFind(name);
if ((it != properties.constEnd()) && (*property != qvariant_cast< T >(it.value()))) {
if (name == defaultRoutePropertyName) {
QString str = it.value().toString();
m_defaultRoute = (str.isEmpty() || str == strTrue);
*property = qvariant_cast< T >(m_defaultRoute);
m_properties.insert(name, QVariant(m_defaultRoute));
} else {
*property = qvariant_cast< T >(it.value());
m_properties.insert(name, it.value());
}
*property = qvariant_cast< T >(it.value());
m_properties.insert(name, it.value());
properties.remove(name);
emissions << changedSignal;
}
Expand Down
8 changes: 4 additions & 4 deletions libconnman-qt/vpnconnection.h
Expand Up @@ -71,7 +71,7 @@ class VpnConnection : public QObject
Q_PROPERTY(QStringList nameservers READ nameservers WRITE setNameservers NOTIFY nameserversChanged)
Q_PROPERTY(QVariant userRoutes READ userRoutes WRITE setUserRoutes NOTIFY userRoutesChanged)
Q_PROPERTY(QVariant serverRoutes READ serverRoutes WRITE setServerRoutes NOTIFY serverRoutesChanged)
Q_PROPERTY(bool defaultRoute READ defaultRoute WRITE setDefaultRoute NOTIFY defaultRouteChanged)
Q_PROPERTY(bool splitRouting READ splitRouting WRITE setSplitRouting NOTIFY splitRoutingChanged)

Q_PROPERTY(QVariantMap properties READ properties WRITE setProperties NOTIFY propertiesChanged)
Q_PROPERTY(QVariantMap providerProperties READ providerProperties WRITE setProviderProperties NOTIFY providerPropertiesChanged)
Expand Down Expand Up @@ -141,8 +141,8 @@ class VpnConnection : public QObject
QVariant serverRoutes() const;
void setServerRoutes(const QVariant &serverRoutes);

bool defaultRoute() const;
void setDefaultRoute(bool defaultRoute);
bool splitRouting() const;
void setSplitRouting(bool splitRouting);

QVariantMap properties() const;
void setProperties(const QVariantMap properties);
Expand All @@ -165,7 +165,7 @@ class VpnConnection : public QObject
void nameserversChanged();
void userRoutesChanged();
void serverRoutesChanged();
void defaultRouteChanged();
void splitRoutingChanged();
void propertiesChanged();
void providerPropertiesChanged();
void connectedChanged();
Expand Down
2 changes: 1 addition & 1 deletion libconnman-qt/vpnconnection_p.h
Expand Up @@ -55,7 +55,7 @@ class VpnConnectionPrivate
NetConnmanServiceInterface m_serviceProxy;
QString m_path;
bool m_autoConnect;
bool m_defaultRoute;
bool m_splitRouting;
VpnConnection::ConnectionState m_state;
QVariantMap m_properties;

Expand Down
2 changes: 1 addition & 1 deletion plugin/plugins.qmltypes
Expand Up @@ -918,7 +918,7 @@ Module {
Property { name: "nameservers"; type: "QStringList" }
Property { name: "userRoutes"; type: "QVariant" }
Property { name: "serverRoutes"; type: "QVariant" }
Property { name: "defaultRoute"; type: "bool" }
Property { name: "splitRouting"; type: "bool" }
Property { name: "properties"; type: "QVariantMap" }
Property { name: "providerProperties"; type: "QVariantMap" }
Property { name: "connected"; type: "bool"; isReadonly: true }
Expand Down

0 comments on commit 9fec2f0

Please sign in to comment.