39
QVariant AccountsService::getUserProperty(const QString &user, const QString &property)
39
QVariant AccountsServiceDBusAdaptor::getUserProperty(const QString &user, const QString &interface, const QString &property)
41
41
auto iface = getUserInterface(user);
42
42
if (iface != nullptr && iface->isValid()) {
43
auto answer = iface->call("Get", "com.canonical.unity.AccountsService", property);
43
auto answer = iface->call("Get", interface, property);
44
44
if (answer.type() == QDBusMessage::ReplyMessage) {
45
45
return answer.arguments()[0].value<QDBusVariant>().variant();
51
void AccountsService::setUserProperty(const QString &user, const QString &property, const QVariant &value)
51
void AccountsServiceDBusAdaptor::setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value)
53
53
auto iface = getUserInterface(user);
54
54
if (iface != nullptr && iface->isValid()) {
55
55
// The value needs to be carefully wrapped
56
iface->call("Set", "com.canonical.unity.AccountsService", property, QVariant::fromValue(QDBusVariant(value)));
60
QDBusInterface *AccountsService::getUserInterface(const QString &user)
56
iface->call("Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
60
void AccountsServiceDBusAdaptor::propertiesChangedSlot(const QString &interface, const QVariantMap &changed, const QStringList &invalid)
62
// Merge changed and invalidated together
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 = users.constBegin(); i != users.constEnd(); ++i) {
80
if (i.value()->path() == path) {
87
QDBusInterface *AccountsServiceDBusAdaptor::getUserInterface(const QString &user)
62
89
auto iface = users.value(user);
63
90
if (iface == nullptr && accounts_manager->isValid()) {
64
91
auto answer = accounts_manager->call("FindUserByName", user);
65
92
if (answer.type() == QDBusMessage::ReplyMessage) {
93
auto path = answer.arguments()[0].value<QDBusObjectPath>().path();
66
95
iface = new QDBusInterface("org.freedesktop.Accounts",
67
answer.arguments()[0].value<QDBusObjectPath>().path(),
68
97
"org.freedesktop.DBus.Properties",
69
98
accounts_manager->connection(), this);
100
// With its own pre-defined properties, AccountsService is oddly
101
// close-lipped. It won't send out proper DBus.Properties notices,
102
// but it does have one catch-all Changed() signal. So let's
104
iface->connection().connect(
107
"org.freedesktop.Accounts.User",
110
SLOT(maybeChangedSlot()));
112
// But custom properties do send out the right notifications, so
113
// let's still listen there.
114
iface->connection().connect(
117
"org.freedesktop.DBus.Properties",
120
SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
70
122
users.insert(user, iface);