19 #include "AccountsServiceDBusAdaptor.h"
20 #include <QDBusConnection>
21 #include <QDBusConnectionInterface>
22 #include <QDBusMessage>
23 #include <QDBusVariant>
25 AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
27 m_accountsManager(nullptr),
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::setUserPropertyAsync(
const QString &user,
const QString &interface,
const QString &property,
const QVariant &value)
62 QDBusInterface *iface = getUserInterface(user);
63 if (iface !=
nullptr && iface->isValid()) {
65 iface->asyncCall(
"Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
69 void AccountsServiceDBusAdaptor::propertiesChangedSlot(
const QString &interface,
const QVariantMap &changed,
const QStringList &invalid)
74 combined << changed.keys();
75 combined.removeDuplicates();
77 Q_EMIT propertiesChanged(getUserForPath(message().path()), interface, combined);
80 void AccountsServiceDBusAdaptor::maybeChangedSlot()
82 Q_EMIT maybeChanged(getUserForPath(message().path()));
85 QString AccountsServiceDBusAdaptor::getUserForPath(
const QString &path)
87 QMap<QString, QDBusInterface *>::const_iterator i;
88 for (i = m_users.constBegin(); i != m_users.constEnd(); ++i) {
89 if (i.value()->path() == path) {
96 QDBusInterface *AccountsServiceDBusAdaptor::getUserInterface(
const QString &user)
98 QDBusInterface *iface = m_users.value(user);
99 if (iface ==
nullptr && m_accountsManager->isValid()) {
100 QDBusMessage answer = m_accountsManager->call(
"FindUserByName", user);
101 if (answer.type() == QDBusMessage::ReplyMessage) {
102 QString path = answer.arguments()[0].value<QDBusObjectPath>().path();
104 iface =
new QDBusInterface(
"org.freedesktop.Accounts",
106 "org.freedesktop.DBus.Properties",
107 m_accountsManager->connection(),
this);
113 iface->connection().connect(
116 "org.freedesktop.Accounts.User",
119 SLOT(maybeChangedSlot()));
123 iface->connection().connect(
126 "org.freedesktop.DBus.Properties",
129 SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
131 m_users.insert(user, iface);