-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdbusproperty.cpp
41 lines (34 loc) · 1.31 KB
/
dbusproperty.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "dbusproperty.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDBusPendingReply>
DBusProperty::DBusProperty(const QString &service, const QString &path, const QString &interface, const QString &property, QObject *parent)
: QObject(parent)
, m_service(service)
, m_path(path)
, m_interface(interface)
, m_property(property)
{
QDBusConnection::sessionBus().connect(m_service, m_path, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onFdoPropertiesChanged(QString,QVariantMap,QStringList)));
auto message = QDBusMessage::createMethodCall(m_service, m_path, "org.freedesktop.DBus.Properties", "Get");
message << m_interface << m_property;
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ReplyMessage) {
QDBusVariant box = reply.arguments().at(0).value<QDBusVariant>();
m_value = box.variant();
}
}
QVariant DBusProperty::value() const
{
return m_value;
}
void DBusProperty::onFdoPropertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated)
{
Q_UNUSED(interface)
Q_UNUSED(invalidated)
if (changed.contains(m_property)) {
m_value = changed[m_property];
Q_EMIT valueChanged(m_value);
}
}