Skip to content

Commit

Permalink
[service] Adapt JS objects to service properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rojkov committed Dec 12, 2012
1 parent aca9322 commit b1fef4e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion libconnman-qt/networkservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@
#include "networkservice.h"
#include "debug.h"

/*
* JS returns arrays as QVariantList or a(v) in terms of D-Bus,
* but ConnMan requires some properties to be lists of strings
* or a(s) thus this function.
*/
QVariantMap adaptToConnmanProperties(const QVariantMap &map)
{
QVariantMap buffer;
foreach (const QString &key, map.keys()) {
if (map.value(key).type() == QVariant::List) {
QStringList strList;
foreach (const QVariant &value, map.value(key).toList()) {
strList.append(value.toString());
}
buffer.insert(key, strList);
} else {
buffer.insert(key, map.value(key));
}
}
return buffer;
}

const QString NetworkService::Name("Name");
const QString NetworkService::State("State");
const QString NetworkService::Type("Type");
Expand Down Expand Up @@ -193,7 +215,7 @@ void NetworkService::setDomainsConfig(const QStringList &domains)
void NetworkService::setProxyConfig(const QVariantMap &proxy)
{
// QDBusPendingReply<void> reply =
m_service->SetProperty(ProxyConfig, QDBusVariant(QVariant(proxy)));
m_service->SetProperty(ProxyConfig, QDBusVariant(QVariant(adaptToConnmanProperties(proxy))));
}

/* this slot is used for debugging */
Expand Down

0 comments on commit b1fef4e

Please sign in to comment.