@@ -24,17 +24,52 @@
24#include <QStringList>
24#include <QStringList>
25#include <QDebug>
25#include <QDebug>
27+#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
28+#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
29+#define IFACE_UBUNTU_INPUT QStringLiteral("com.ubuntu.AccountsService.Input")
30+#define IFACE_UBUNTU_SECURITY QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy")
31+#define IFACE_UBUNTU_SECURITY_OLD QStringLiteral("com.ubuntu.touch.AccountsService.SecurityPrivacy")
32+#define IFACE_UNITY QStringLiteral("com.canonical.unity.AccountsService")
33+#define IFACE_UNITY_PRIVATE QStringLiteral("com.canonical.unity.AccountsService.Private")
35+#define PROP_BACKGROUND_FILE QStringLiteral("BackgroundFile")
36+#define PROP_DEMO_EDGES QStringLiteral("demo-edges")
37+#define PROP_ENABLE_INDICATORS_WHILE_LOCKED QStringLiteral("EnableIndicatorsWhileLocked")
38+#define PROP_ENABLE_LAUNCHER_WHILE_LOCKED QStringLiteral("EnableLauncherWhileLocked")
39+#define PROP_FAILED_LOGINS QStringLiteral("FailedLogins")
40+#define PROP_LICENSE_ACCEPTED QStringLiteral("LicenseAccepted")
41+#define PROP_LICENSE_BASE_PATH QStringLiteral("LicenseBasePath")
42+#define PROP_MOUSE_CURSOR_SPEED QStringLiteral("MouseCursorSpeed")
43+#define PROP_MOUSE_DOUBLE_CLICK_SPEED QStringLiteral("MouseDoubleClickSpeed")
44+#define PROP_MOUSE_PRIMARY_BUTTON QStringLiteral("MousePrimaryButton")
45+#define PROP_MOUSE_SCROLL_SPEED QStringLiteral("MouseScrollSpeed")
46+#define PROP_PASSWORD_DISPLAY_HINT QStringLiteral("PasswordDisplayHint")
47+#define PROP_STATS_WELCOME_SCREEN QStringLiteral("StatsWelcomeScreen")
48+#define PROP_TOUCHPAD_CURSOR_SPEED QStringLiteral("TouchpadCursorSpeed")
49+#define PROP_TOUCHPAD_DISABLE_WHILE_TYPING QStringLiteral("TouchpadDisableWhileTyping")
50+#define PROP_TOUCHPAD_DISABLE_WITH_MOUSE QStringLiteral("TouchpadDisableWithMouse")
51+#define PROP_TOUCHPAD_DOUBLE_CLICK_SPEED QStringLiteral("TouchpadDoubleClickSpeed")
52+#define PROP_TOUCHPAD_PRIMARY_BUTTON QStringLiteral("TouchpadPrimaryButton")
53+#define PROP_TOUCHPAD_SCROLL_SPEED QStringLiteral("TouchpadScrollSpeed")
54+#define PROP_TOUCHPAD_TAP_TO_CLICK QStringLiteral("TouchpadTapToClick")
55+#define PROP_TOUCHPAD_TWO_FINGER_SCROLL QStringLiteral("TouchpadTwoFingerScroll")
58+QVariant primaryButtonConverter(const QVariant &value)
60+ QString stringValue = value.toString();
61+ if (stringValue == "left") {
62+ return QVariant::fromValue(0);
63+ } else if (stringValue == "right") {
64+ return QVariant::fromValue(1); // Mir is less clear on this -- any non-zero value is the same
66+ return QVariant::fromValue(0); // default to left
27AccountsService::AccountsService(QObject* parent, const QString &user)
70AccountsService::AccountsService(QObject* parent, const QString &user)
28− : QObject(parent),
71+ : QObject(parent)
29− m_service(new AccountsServiceDBusAdaptor(this)),
72+ , m_service(new AccountsServiceDBusAdaptor(this))
31− m_enableLauncherWhileLocked(false),
32− m_enableIndicatorsWhileLocked(false),
33− m_statsWelcomeScreen(false),
34− m_passwordDisplayHint(Keyboard),
36− m_hereEnabled(false),
37− m_hereLicensePath() // null means not set yet
39 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
74 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
40 QStringLiteral("/com/canonical/Unity/Input"),
75 QStringLiteral("/com/canonical/Unity/Input"),
@@ -44,6 +79,43 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
44 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
79 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
45 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
80 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
82+ registerProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE, QStringLiteral("backgroundFileChanged"));
83+ registerProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED, QStringLiteral("hereEnabledChanged"));
84+ registerProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH, QStringLiteral("hereLicensePathChanged"));
85+ registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED, QStringLiteral("enableLauncherWhileLockedChanged"));
86+ registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED, QStringLiteral("enableIndicatorsWhileLockedChanged"));
87+ registerProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT, QStringLiteral("passwordDisplayHintChanged"));
88+ registerProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN, QStringLiteral("statsWelcomeScreenChanged"));
89+ registerProperty(IFACE_UNITY, PROP_DEMO_EDGES, QStringLiteral("demoEdgesChanged"));
90+ registerProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, QStringLiteral("failedLoginsChanged"));
92+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_CURSOR_SPEED,
93+ m_unityInput, QStringLiteral("setMouseCursorSpeed"));
94+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_DOUBLE_CLICK_SPEED,
95+ m_unityInput, QStringLiteral("setMouseDoubleClickSpeed"));
96+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_PRIMARY_BUTTON,
97+ m_unityInput, QStringLiteral("setMousePrimaryButton"),
98+ primaryButtonConverter);
99+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_SCROLL_SPEED,
100+ m_unityInput, QStringLiteral("setMouseScrollSpeed"));
101+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_CURSOR_SPEED,
102+ m_unityInput, QStringLiteral("setTouchpadCursorSpeed"));
103+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_SCROLL_SPEED,
104+ m_unityInput, QStringLiteral("setTouchpadScrollSpeed"));
105+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WHILE_TYPING,
106+ m_unityInput, QStringLiteral("setTouchpadDisableWhileTyping"));
107+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WITH_MOUSE,
108+ m_unityInput, QStringLiteral("setTouchpadDisableWithMouse"));
109+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DOUBLE_CLICK_SPEED,
110+ m_unityInput, QStringLiteral("setTouchpadDoubleClickSpeed"));
111+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_PRIMARY_BUTTON,
112+ m_unityInput, QStringLiteral("setTouchpadPrimaryButton"),
113+ primaryButtonConverter);
114+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TAP_TO_CLICK,
115+ m_unityInput, QStringLiteral("setTouchpadTapToClick"));
116+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
117+ m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
47 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
119 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
@@ -57,410 +129,200 @@ void AccountsService::setUser(const QString &user)
57 if (user.isEmpty() || m_user == user)
129 if (user.isEmpty() || m_user == user)
132+ bool wasEmpty = m_user.isEmpty();
60 m_user = user;
134 m_user = user;
61 Q_EMIT userChanged();
135 Q_EMIT userChanged();
63− updateDemoEdges(false);
137+ // Do the first update synchronously, as a cheap way to block rendering
64− updateEnableLauncherWhileLocked(false);
138+ // until we have the right values on bootup.
65− updateEnableIndicatorsWhileLocked(false);
139+ refresh(!wasEmpty);
66− updateBackgroundFile(false);
67− updateMouseCursorSpeed();
68− updateTouchpadCursorSpeed();
69− updateStatsWelcomeScreen(false);
70− updatePasswordDisplayHint(false);
71− updateFailedLogins(false);
72− updateHereEnabled(false);
73− updateHereLicensePath(false);
76bool AccountsService::demoEdges() const
142bool AccountsService::demoEdges() const
78− return m_demoEdges;
144+ auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
145+ return value.toBool();
81void AccountsService::setDemoEdges(bool demoEdges)
148void AccountsService::setDemoEdges(bool demoEdges)
83− if (m_demoEdges != demoEdges) {
150+ setProperty(IFACE_UNITY, PROP_DEMO_EDGES, demoEdges);
84− m_demoEdges = demoEdges;
85− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.canonical.unity.AccountsService"), QStringLiteral("demo-edges"), demoEdges);
87− Q_EMIT demoEdgesChanged();
91bool AccountsService::enableLauncherWhileLocked() const
153bool AccountsService::enableLauncherWhileLocked() const
93− return m_enableLauncherWhileLocked;
155+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED);
156+ return value.toBool();
96bool AccountsService::enableIndicatorsWhileLocked() const
159bool AccountsService::enableIndicatorsWhileLocked() const
98− return m_enableIndicatorsWhileLocked;
161+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED);
162+ return value.toBool();
101QString AccountsService::backgroundFile() const
165QString AccountsService::backgroundFile() const
103− return m_backgroundFile;
167+ auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE);
168+ return value.toString();
106bool AccountsService::statsWelcomeScreen() const
171bool AccountsService::statsWelcomeScreen() const
108− return m_statsWelcomeScreen;
173+ auto value = getProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN);
174+ return value.toBool();
111AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
177AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
113− return m_passwordDisplayHint;
179+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT);
180+ return (PasswordDisplayHint)value.toInt();
116bool AccountsService::hereEnabled() const
183bool AccountsService::hereEnabled() const
118− return m_hereEnabled;
185+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED);
186+ return value.toBool();
121void AccountsService::setHereEnabled(bool enabled)
189void AccountsService::setHereEnabled(bool enabled)
123− if (m_hereEnabled != enabled) {
191+ setProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED, enabled);
124− m_hereEnabled = enabled;
125− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.ubuntu.location.providers.here.AccountsService"), QStringLiteral("LicenseAccepted"), enabled);
127− Q_EMIT hereEnabledChanged();
131QString AccountsService::hereLicensePath() const
194QString AccountsService::hereLicensePath() const
133− return m_hereLicensePath;
196+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
197+ QString hereLicensePath = value.toString();
198+ if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
199+ hereLicensePath = QStringLiteral("");
200+ return hereLicensePath;
136bool AccountsService::hereLicensePathValid() const
203bool AccountsService::hereLicensePathValid() const
138− return !m_hereLicensePath.isNull();
205+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
139−}
206+ return !value.toString().isNull();
141−void AccountsService::updateDemoEdges(bool async)
143− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
144− QStringLiteral("com.canonical.unity.AccountsService"),
145− QStringLiteral("demo-edges"));
146− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
148− connect(watcher, &QDBusPendingCallWatcher::finished,
149− this, [this](QDBusPendingCallWatcher* watcher) {
151− QDBusPendingReply<QDBusVariant> reply = *watcher;
152− watcher->deleteLater();
153− if (reply.isError()) {
154− qWarning() << "Failed to get 'demo-edges' property - " << reply.error().message();
158− auto demoEdges = reply.value().variant().toBool();
159− if (m_demoEdges != demoEdges) {
160− m_demoEdges = demoEdges;
161− Q_EMIT demoEdgesChanged();
165− watcher->waitForFinished();
170−void AccountsService::updateEnableLauncherWhileLocked(bool async)
209+uint AccountsService::failedLogins() const
172− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
211+ return getProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS).toUInt();
173− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
174− QStringLiteral("EnableLauncherWhileLocked"));
175− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
177− connect(watcher, &QDBusPendingCallWatcher::finished,
178− this, [this](QDBusPendingCallWatcher* watcher) {
180− QDBusPendingReply<QVariant> reply = *watcher;
181− watcher->deleteLater();
182− if (reply.isError()) {
183− qWarning() << "Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
187− const bool enableLauncherWhileLocked = reply.value().toBool();
188− if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
189− m_enableLauncherWhileLocked = enableLauncherWhileLocked;
190− Q_EMIT enableLauncherWhileLockedChanged();
194− watcher->waitForFinished();
199−void AccountsService::updateEnableIndicatorsWhileLocked(bool async)
214+void AccountsService::setFailedLogins(uint failedLogins)
201− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
216+ setProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, failedLogins);
202− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
203− QStringLiteral("EnableIndicatorsWhileLocked"));
204− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
206− connect(watcher, &QDBusPendingCallWatcher::finished,
207− this, [this](QDBusPendingCallWatcher* watcher) {
209− QDBusPendingReply<QVariant> reply = *watcher;
210− watcher->deleteLater();
211− if (reply.isError()) {
212− qWarning() << "Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
216− const bool enableIndicatorsWhileLocked = reply.value().toBool();
217− if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
218− m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
219− Q_EMIT enableIndicatorsWhileLockedChanged();
223− watcher->waitForFinished();
228−void AccountsService::updateBackgroundFile(bool async)
219+// ====================================================
229−{
220+// Everything below this line is generic helper methods
230− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
221+// ====================================================
231− QStringLiteral("org.freedesktop.Accounts.User"),
232− QStringLiteral("BackgroundFile"));
233− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
235− connect(watcher, &QDBusPendingCallWatcher::finished,
236− this, [this](QDBusPendingCallWatcher* watcher) {
238− QDBusPendingReply<QVariant> reply = *watcher;
239− watcher->deleteLater();
240− if (reply.isError()) {
241− qWarning() << "Failed to get 'BackgroundFile' property - " << reply.error().message();
245− const QString backgroundFile = reply.value().toString();
246− if (m_backgroundFile != backgroundFile) {
247− m_backgroundFile = backgroundFile;
248− Q_EMIT backgroundFileChanged();
252− watcher->waitForFinished();
257−void AccountsService::updateMouseCursorSpeed()
223+void AccountsService::emitChangedForProperty(const QString &interface, const QString &property)
259− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
225+ QString signalName = m_properties[interface][property].signal;
260− QStringLiteral("com.ubuntu.AccountsService.Input"),
226+ QMetaObject::invokeMethod(this, signalName.toUtf8().data());
261− QStringLiteral("MouseCursorSpeed"));
262− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
264− connect(watcher, &QDBusPendingCallWatcher::finished,
265− this, [this](QDBusPendingCallWatcher* watcher) {
267− QDBusPendingReply<QVariant> reply = *watcher;
268− watcher->deleteLater();
269− if (reply.isError()) {
270− qWarning() << "Failed to get 'MouseCursorSpeed' property - " << reply.error().message();
274− // Merely proxy this along to USC. We don't care about keeping a copy
275− // or exporting it internally.
276− m_unityInput->asyncCall(QStringLiteral("setMouseCursorSpeed"), reply.value());
280−void AccountsService::updateTouchpadCursorSpeed()
229+QVariant AccountsService::getProperty(const QString &interface, const QString &property) const
282− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
231+ return m_properties[interface][property].value;
283− QStringLiteral("com.ubuntu.AccountsService.Input"),
284− QStringLiteral("TouchpadCursorSpeed"));
285− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
287− connect(watcher, &QDBusPendingCallWatcher::finished,
288− this, [this](QDBusPendingCallWatcher* watcher) {
290− QDBusPendingReply<QVariant> reply = *watcher;
291− watcher->deleteLater();
292− if (reply.isError()) {
293− qWarning() << "Failed to get 'TouchpadCursorSpeed' property - " << reply.error().message();
297− // Merely proxy this along to USC. We don't care about keeping a copy
298− // or exporting it internally.
299− m_unityInput->asyncCall(QStringLiteral("setTouchpadCursorSpeed"), reply.value());
303−void AccountsService::updateStatsWelcomeScreen(bool async)
234+void AccountsService::setProperty(const QString &interface, const QString &property, const QVariant &value)
305− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
236+ if (m_properties[interface][property].value != value) {
306− QStringLiteral("com.ubuntu.touch.AccountsService.SecurityPrivacy"),
237+ m_properties[interface][property].value = value;
307− QStringLiteral("StatsWelcomeScreen"));
238+ m_service->setUserPropertyAsync(m_user, interface, property, value);
308− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
239+ emitChangedForProperty(interface, property);
310− connect(watcher, &QDBusPendingCallWatcher::finished,
311− this, [this](QDBusPendingCallWatcher* watcher) {
313− QDBusPendingReply<QVariant> reply = *watcher;
314− watcher->deleteLater();
315− if (reply.isError()) {
316− qWarning() << "Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
320− const bool statsWelcomeScreen = reply.value().toBool();
321− if (m_statsWelcomeScreen != statsWelcomeScreen) {
322− m_statsWelcomeScreen = statsWelcomeScreen;
323− Q_EMIT statsWelcomeScreenChanged();
327− watcher->waitForFinished();
332−void AccountsService::updatePasswordDisplayHint(bool async)
243+void AccountsService::updateCache(const QString &interface, const QString &property, const QVariant &value)
334− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
245+ PropertyInfo &info = m_properties[interface][property];
335− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
246+
336− QStringLiteral("PasswordDisplayHint"));
247+ if (info.proxyInterface) {
337− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
248+ QVariant finalValue;
338−
249+ if (info.proxyConverter) {
339− connect(watcher, &QDBusPendingCallWatcher::finished,
250+ finalValue = info.proxyConverter(value);
340− this, [this](QDBusPendingCallWatcher* watcher) {
251+ } else {
341−
252+ finalValue = value;
342− QDBusPendingReply<QVariant> reply = *watcher;
343− watcher->deleteLater();
344− if (reply.isError()) {
345− qWarning() << "Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
349− const PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().toInt();
350− if (m_passwordDisplayHint != passwordDisplayHint) {
351− m_passwordDisplayHint = passwordDisplayHint;
352− Q_EMIT passwordDisplayHintChanged();
354− });
254+ info.proxyInterface->asyncCall(info.proxyMethod, finalValue);
355− if (!async) {
255+ return; // don't bother saving a copy
356− watcher->waitForFinished();
361−void AccountsService::updateFailedLogins(bool async)
363− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
364− QStringLiteral("com.canonical.unity.AccountsService.Private"),
365− QStringLiteral("FailedLogins"));
366− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
368− connect(watcher, &QDBusPendingCallWatcher::finished,
369− this, [this](QDBusPendingCallWatcher* watcher) {
371− QDBusPendingReply<QVariant> reply = *watcher;
372− watcher->deleteLater();
373− if (reply.isError()) {
374− qWarning() << "Failed to get 'FailedLogins' property - " << reply.error().message();
378− const uint failedLogins = reply.value().toUInt();
258+ if (info.value != value) {
379− if (m_failedLogins != failedLogins) {
259+ info.value = value;
380− m_failedLogins = failedLogins;
260+ emitChangedForProperty(interface, property);
381− Q_EMIT failedLoginsChanged();
385− watcher->waitForFinished();
390−void AccountsService::updateHereEnabled(bool async)
264+void AccountsService::updateProperty(const QString &interface, const QString &property)
392 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
266 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
393− QStringLiteral("com.ubuntu.location.providers.here.AccountsService"),
267+ interface,
394− QStringLiteral("LicenseAccepted"));
268+ property);
395 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
269 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
397 connect(watcher, &QDBusPendingCallWatcher::finished,
271 connect(watcher, &QDBusPendingCallWatcher::finished,
398− this, [this](QDBusPendingCallWatcher* watcher) {
272+ this, [this, interface, property](QDBusPendingCallWatcher* watcher) {
400 QDBusPendingReply<QVariant> reply = *watcher;
274 QDBusPendingReply<QVariant> reply = *watcher;
401 watcher->deleteLater();
275 watcher->deleteLater();
402 if (reply.isError()) {
276 if (reply.isError()) {
403− qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
277+ qWarning() << "Failed to get '" << property << "' property:" << reply.error().message();
407− const bool hereEnabled = reply.value().toBool();
281+ updateCache(interface, property, reply.value());
408− if (m_hereEnabled != hereEnabled) {
409− m_hereEnabled = hereEnabled;
410− Q_EMIT hereEnabledChanged();
414− watcher->waitForFinished();
419−void AccountsService::updateHereLicensePath(bool async)
285+void AccountsService::updateAllProperties(const QString &interface, bool async)
421− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
287+ QDBusPendingCall pendingReply = m_service->getAllPropertiesAsync(m_user,
422− QStringLiteral("com.ubuntu.location.providers.here.AccountsService"),
288+ interface);
423− QStringLiteral("LicenseBasePath"));
424 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
289 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
426 connect(watcher, &QDBusPendingCallWatcher::finished,
291 connect(watcher, &QDBusPendingCallWatcher::finished,
427− this, [this](QDBusPendingCallWatcher* watcher) {
292+ this, [this, interface](QDBusPendingCallWatcher* watcher) {
429− QDBusPendingReply<QVariant> reply = *watcher;
294+ QDBusPendingReply< QHash<QString, QVariant> > reply = *watcher;
430 watcher->deleteLater();
295 watcher->deleteLater();
431 if (reply.isError()) {
296 if (reply.isError()) {
432− qWarning() << "Failed to get 'LicenseBasePath' property - " << reply.error().message();
297+ qWarning() << "Failed to get all properties for" << interface << ":" << reply.error().message();
436− QString hereLicensePath = reply.value().toString();
301+ auto valueHash = reply.value();
437− if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
302+ auto i = valueHash.constBegin();
438− hereLicensePath = QLatin1String("");
303+ while (i != valueHash.constEnd()) {
439−
304+ updateCache(interface, i.key(), i.value());
440− if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
305+ ++i;
441− m_hereLicensePath = hereLicensePath;
442− Q_EMIT hereLicensePathChanged();
445 if (!async) {
308 if (!async) {
446 watcher->waitForFinished();
309 watcher->waitForFinished();
451−uint AccountsService::failedLogins() const
313+void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter)
453− return m_failedLogins;
315+ registerProperty(interface, property, nullptr);
317+ m_properties[interface][property].proxyInterface = iface;
318+ m_properties[interface][property].proxyMethod = method;
319+ m_properties[interface][property].proxyConverter = converter;
456−void AccountsService::setFailedLogins(uint failedLogins)
322+void AccountsService::registerProperty(const QString &interface, const QString &property, const QString &signal)
458− if (m_failedLogins != failedLogins) {
324+ m_properties[interface][property] = PropertyInfo();
459− m_failedLogins = failedLogins;
325+ m_properties[interface][property].signal = signal;
460− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.canonical.unity.AccountsService.Private"), QStringLiteral("FailedLogins"), failedLogins);
462− Q_EMIT failedLoginsChanged();
466void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
328void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
@@ -469,42 +331,13 @@ void AccountsService::onPropertiesChanged(const QString &user, const QString &in
472− if (interface == QLatin1String("com.canonical.unity.AccountsService")) {
334+ auto propHash = m_properties.value(interface);
473− if (changed.contains(QStringLiteral("demo-edges"))) {
335+ auto i = propHash.constBegin();
474− updateDemoEdges();
336+ while (i != propHash.constEnd()) {
476− } else if (interface == QLatin1String("com.canonical.unity.AccountsService.Private")) {
477− if (changed.contains(QStringLiteral("FailedLogins"))) {
478− updateFailedLogins();
480− } else if (interface == QLatin1String("com.ubuntu.AccountsService.Input")) {
481− if (changed.contains(QStringLiteral("MouseCursorSpeed"))) {
482− updateMouseCursorSpeed();
484− if (changed.contains(QStringLiteral("TouchpadCursorSpeed"))) {
485− updateTouchpadCursorSpeed();
487− } else if (interface == QLatin1String("com.ubuntu.touch.AccountsService.SecurityPrivacy")) {
488− if (changed.contains(QStringLiteral("StatsWelcomeScreen"))) {
489− updateStatsWelcomeScreen();
491− } else if (interface == QLatin1String("com.ubuntu.AccountsService.SecurityPrivacy")) {
492− if (changed.contains(QStringLiteral("PasswordDisplayHint"))) {
493− updatePasswordDisplayHint();
495− if (changed.contains(QStringLiteral("EnableLauncherWhileLocked"))) {
337+ if (changed.contains(i.key())) {
496− updateEnableLauncherWhileLocked();
338+ updateProperty(interface, i.key());
498− if (changed.contains(QStringLiteral("EnableIndicatorsWhileLocked"))) {
499− updateEnableIndicatorsWhileLocked();
501− } else if (interface == QLatin1String("com.ubuntu.location.providers.here.AccountsService")) {
502− if (changed.contains(QStringLiteral("LicenseAccepted"))) {
503− updateHereEnabled();
505− if (changed.contains(QStringLiteral("LicenseBasePath"))) {
506− updateHereLicensePath();
@@ -514,6 +347,20 @@ void AccountsService::onMaybeChanged(const QString &user)
517− // Standard properties might have changed
350+ // Any of the standard properties might have changed!
518− updateBackgroundFile();
351+ auto propHash = m_properties.value(IFACE_ACCOUNTS_USER);
352+ auto i = propHash.constBegin();
353+ while (i != propHash.constEnd()) {
354+ updateProperty(IFACE_ACCOUNTS_USER, i.key());
359+void AccountsService::refresh(bool async)
361+ auto i = m_properties.constBegin();
362+ while (i != m_properties.constEnd()) {
363+ updateAllProperties(i.key(), async);