@@ -17,110 +17,88 @@
19#include "AccountsService.h"
19#include "AccountsService.h"
20−#include <QDBusConnection>
20+#include "AccountsServiceDBusAdaptor.h"
21−#include <QDBusConnectionInterface>
21+
22−#include <QDBusMessage>
22+#include <QStringList>
23−#include <QDBusVariant>
25AccountsService::AccountsService(QObject* parent)
24AccountsService::AccountsService(QObject* parent)
26 : QObject(parent),
25 : QObject(parent),
27− accounts_manager(NULL),
26+ m_service(new AccountsServiceDBusAdaptor(this)),
28− users()
27+ m_user(qgetenv("USER"))
30− auto connection = QDBusConnection::SM_BUSNAME();
29+ connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
31− auto interface = connection.interface();
30+ this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
32− interface->startService("org.freedesktop.Accounts");
31+ connect(m_service, SIGNAL(maybeChanged(const QString &)),
33− accounts_manager = new QDBusInterface("org.freedesktop.Accounts",
32+ this, SLOT(maybeChanged(const QString &)));
34− "/org/freedesktop/Accounts",
35− "org.freedesktop.Accounts",
39−QVariant AccountsService::getUserProperty(const QString &user, const QString &interface, const QString &property)
35+QString AccountsService::getUser()
41− auto iface = getUserInterface(user);
37+ return m_user;
42− if (iface != nullptr && iface->isValid()) {
43− auto answer = iface->call("Get", interface, property);
44− if (answer.type() == QDBusMessage::ReplyMessage) {
45− return answer.arguments()[0].value<QDBusVariant>().variant();
51−void AccountsService::setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value)
40+void AccountsService::setUser(const QString &user)
53− auto iface = getUserInterface(user);
42+ m_user = user;
54− if (iface != nullptr && iface->isValid()) {
43+ Q_EMIT userChanged();
55− // The value needs to be carefully wrapped
44+
56− iface->call("Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
45+ updateDemoEdges();
57− }
46+ updateBackgroundFile();
60−void AccountsService::propertiesChangedSlot(const QString &interface, const QVariantMap &changed, const QStringList &invalid)
49+bool AccountsService::getDemoEdges()
62− // Merge changed and invalidated together
51+ return m_demoEdges;
63− QStringList combined;
52+}
65− combined << changed.keys();
66− combined.removeDuplicates();
68− Q_EMIT propertiesChanged(getUserForPath(message().path()), interface, combined);
54+void AccountsService::setDemoEdges(bool demoEdges)
56+ m_demoEdges = demoEdges;
57+ m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
71−void AccountsService::maybeChangedSlot()
60+QString AccountsService::getBackgroundFile()
73− Q_EMIT maybeChanged(getUserForPath(message().path()));
62+ return m_backgroundFile;
76−QString AccountsService::getUserForPath(const QString &path)
65+void AccountsService::updateDemoEdges()
78− QMap<QString, QDBusInterface *>::const_iterator i;
67+ auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
79− for (i = users.constBegin(); i != users.constEnd(); ++i) {
68+ if (m_demoEdges != demoEdges) {
80− if (i.value()->path() == path) {
69+ m_demoEdges = demoEdges;
81− return i.key();
70+ Q_EMIT demoEdgesChanged();
87−QDBusInterface *AccountsService::getUserInterface(const QString &user)
74+void AccountsService::updateBackgroundFile()
89− auto iface = users.value(user);
90− if (iface == nullptr && accounts_manager->isValid()) {
91− auto answer = accounts_manager->call("FindUserByName", user);
92− if (answer.type() == QDBusMessage::ReplyMessage) {
93− auto path = answer.arguments()[0].value<QDBusObjectPath>().path();
95− iface = new QDBusInterface("org.freedesktop.Accounts",
97− "org.freedesktop.DBus.Properties",
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",
76+ auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
108− "Changed",
77+ if (m_backgroundFile != backgroundFile) {
109− this,
78+ m_backgroundFile = backgroundFile;
110− SLOT(maybeChangedSlot()));
79+ Q_EMIT backgroundFileChanged();
112− // But custom properties do send out the right notifications, so
83+void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
113− // let's still listen there.
84+{
114− iface->connection().connect(
85+ if (m_user != user) {
115− iface->service(),
86+ return;
117− "org.freedesktop.DBus.Properties",
118− "PropertiesChanged",
120− SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
122− users.insert(user, iface);
89+ if (interface == "com.canonical.unity.AccountsService") {
90+ if (changed.contains("demo-edges")) {
96+void AccountsService::maybeChanged(const QString &user)
98+ if (m_user != user) {
125− return iface;
99+ return;
102+ // Standard properties might have changed
103+ updateBackgroundFile();