10#include <QtDBus/QDBusConnection>
11#include <QtDBus/QDBusError>
12#include <QtDBus/QDBusInterface>
13#include <QtDBus/QDBusMessage>
14#include <QtDBus/QDBusMetaType>
15#include <QtDBus/QDBusReply>
16#include <QtDBus/QDBusObjectPath>
20#define CONNMAN_DBUS_SERVICE "net.connman"_L1
21#define CONNMAN_DBUS_INTERFACE "net.connman.Manager"
23#define CONNMAN_DBUS_PATH "/"_L1
27using namespace Qt::StringLiterals;
29using ConnmanService = QMap<QString, QVariant>;
30using ConnmanServiceEntry = std::pair<QDBusObjectPath, ConnmanService>;
31using ConnmanServices = QList<ConnmanServiceEntry>;
34constexpr QLatin1StringView propertyChangedKey =
"PropertyChanged"_L1;
35constexpr QLatin1StringView stateKey =
"State"_L1;
36constexpr QLatin1StringView typeKey =
"Type"_L1;
41 QDBusConnection::systemBus(), parent)
52 if (!QDBusAbstractInterface::isValid())
55 qDBusRegisterMetaType<ConnmanServiceEntry>();
56 qDBusRegisterMetaType<ConnmanServices>();
58 QDBusReply<QVariantMap> propertiesReply = call(QDBus::Block,
"GetProperties"_L1);
59 if (!propertiesReply.isValid()) {
60 validDBusConnection =
false;
61 if (propertiesReply.error().type() != QDBusError::AccessDenied) {
62 qWarning(
"Failed to query ConnMan properties: %ls",
63 qUtf16Printable(propertiesReply.error().message()));
67 auto map = propertiesReply.value();
68 m_state = map.value(stateKey).toString();
69 m_type = findServiceType();
71 validDBusConnection = QDBusConnection::systemBus().connect(
73 this, SLOT(propertyChanged(QString,QDBusVariant)));
80 SLOT(propertyChanged(QString,QDBusVariant)));
98void QConnManInterface::propertyChanged(
const QString &name,
const QDBusVariant &value)
100 if (name == stateKey) {
101 m_state = value.variant().toString();
102 backend->onStateChanged(m_state);
104 QString type = findServiceType();
105 if (type != m_type) {
106 m_type = std::move(type);
107 backend->onTypeChanged(m_type);
114 QDBusReply<ConnmanServices> servicesReply = call(QDBus::Block,
"GetServices"_L1);
115 if (!servicesReply.isValid()) {
116 if (servicesReply.error().type() != QDBusError::AccessDenied) {
117 qWarning(
"Failed to query ConnMan services: %ls",
118 qUtf16Printable(servicesReply.error().message()));
125 for (
const auto &[_, service] : servicesReply.value()) {
126 if (service.value(stateKey).toString() == m_state)
127 return service.value(typeKey).toString();
134#include "moc_qconnmanservice.cpp"
static bool connmanAvailable()
void setBackend(QConnManNetworkInformationBackend *ourBackend)
QConnManInterface(QObject *parent=nullptr)
#define CONNMAN_DBUS_INTERFACE_L1
#define CONNMAN_DBUS_INTERFACE
#define CONNMAN_DBUS_PATH
#define CONNMAN_DBUS_SERVICE