19 #include "AccountsServiceDBusAdaptor.h"
20 #include <QDBusConnection>
21 #include <QDBusConnectionInterface>
22 #include <QDBusMessage>
23 #include <QDBusVariant>
25 AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
27 m_accountsManager(NULL),
30 QDBusConnection connection = QDBusConnection::SM_BUSNAME();
31 QDBusConnectionInterface *
interface = connection.interface();
32 interface->startService(
"org.freedesktop.Accounts");
33 m_accountsManager =
new QDBusInterface(
"org.freedesktop.Accounts",
34 "/org/freedesktop/Accounts",
35 "org.freedesktop.Accounts",
39 QVariant AccountsServiceDBusAdaptor::getUserProperty(
const QString &user,
const QString &interface,
const QString &property)
41 QDBusInterface *iface = getUserInterface(user);
42 if (iface !=
nullptr && iface->isValid()) {
43 QDBusMessage answer = iface->call(
"Get", interface, property);
44 if (answer.type() == QDBusMessage::ReplyMessage) {
45 return answer.arguments()[0].value<QDBusVariant>().variant();
51 void AccountsServiceDBusAdaptor::setUserProperty(
const QString &user,
const QString &interface,
const QString &property,
const QVariant &value)
53 QDBusInterface *iface = getUserInterface(user);
54 if (iface !=
nullptr && iface->isValid()) {
56 iface->call(
"Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
60 void AccountsServiceDBusAdaptor::propertiesChangedSlot(
const QString &interface,
const QVariantMap &changed,
const QStringList &invalid)
65 combined << changed.keys();
66 combined.removeDuplicates();
68 Q_EMIT propertiesChanged(getUserForPath(message().path()), interface, combined);
71 void AccountsServiceDBusAdaptor::maybeChangedSlot()
73 Q_EMIT maybeChanged(getUserForPath(message().path()));
76 QString AccountsServiceDBusAdaptor::getUserForPath(
const QString &path)
78 QMap<QString, QDBusInterface *>::const_iterator i;
79 for (i = m_users.constBegin(); i != m_users.constEnd(); ++i) {
80 if (i.value()->path() == path) {
87 QDBusInterface *AccountsServiceDBusAdaptor::getUserInterface(
const QString &user)
89 QDBusInterface *iface = m_users.value(user);
90 if (iface ==
nullptr && m_accountsManager->isValid()) {
91 QDBusMessage answer = m_accountsManager->call(
"FindUserByName", user);
92 if (answer.type() == QDBusMessage::ReplyMessage) {
93 QString path = answer.arguments()[0].value<QDBusObjectPath>().path();
95 iface =
new QDBusInterface(
"org.freedesktop.Accounts",
97 "org.freedesktop.DBus.Properties",
98 m_accountsManager->connection(),
this);
104 iface->connection().connect(
107 "org.freedesktop.Accounts.User",
110 SLOT(maybeChangedSlot()));
114 iface->connection().connect(
117 "org.freedesktop.DBus.Properties",
120 SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
122 m_users.insert(user, iface);