2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Author: Michael Terry <michael.terry@canonical.com>
19#include "AccountsServiceDBusAdaptor.h"
20#include <QDBusConnection>
21#include <QDBusConnectionInterface>
22#include <QDBusMessage>
23#include <QDBusVariant>
25AccountsServiceDBusAdaptor::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",
39QVariant 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();
51void 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()) {
55 // The value needs to be carefully wrapped
56 iface->call("Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
60void 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);
71void AccountsServiceDBusAdaptor::maybeChangedSlot()
73 Q_EMIT maybeChanged(getUserForPath(message().path()));
76QString 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) {
87QDBusInterface *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);
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)));
122 m_users.insert(user, iface);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list