@@ -24,17 +24,52 @@
2424#include <QStringList>
2525#include <QDebug>
2626
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")
34+
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")
56+
57+
58+QVariant primaryButtonConverter(const QVariant &value)
59+{
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
65+ } else {
66+ return QVariant::fromValue(0); // default to left
67+ }
68+}
69+
2770AccountsService::AccountsService(QObject* parent, const QString &user)
28− : QObject(parent),
29− m_service(new AccountsServiceDBusAdaptor(this)),
30− m_demoEdges(false),
31− m_enableLauncherWhileLocked(false),
32− m_enableIndicatorsWhileLocked(false),
33− m_statsWelcomeScreen(false),
34− m_passwordDisplayHint(Keyboard),
35− m_failedLogins(0),
36− m_hereEnabled(false),
37− m_hereLicensePath() // null means not set yet
71+ : QObject(parent)
72+ , m_service(new AccountsServiceDBusAdaptor(this))
3873{
3974 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
4075 QStringLiteral("/com/canonical/Unity/Input"),
@@ -44,6 +79,43 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
4479 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
4580 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
4681
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"));
91+
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"));
118+
47119 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
48120}
49121
@@ -57,410 +129,200 @@ void AccountsService::setUser(const QString &user)
57129 if (user.isEmpty() || m_user == user)
58130 return;
59131
132+ bool wasEmpty = m_user.isEmpty();
133+
60134 m_user = user;
61135 Q_EMIT userChanged();
62136
63− updateDemoEdges(false);
64− updateEnableLauncherWhileLocked(false);
65− updateEnableIndicatorsWhileLocked(false);
66− updateBackgroundFile(false);
67− updateMouseCursorSpeed();
68− updateTouchpadCursorSpeed();
69− updateStatsWelcomeScreen(false);
70− updatePasswordDisplayHint(false);
71− updateFailedLogins(false);
72− updateHereEnabled(false);
73− updateHereLicensePath(false);
137+ // Do the first update synchronously, as a cheap way to block rendering
138+ // until we have the right values on bootup.
139+ refresh(!wasEmpty);
74140}
75141
76142bool AccountsService::demoEdges() const
77143{
78− return m_demoEdges;
144+ auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
145+ return value.toBool();
79146}
80147
81148void AccountsService::setDemoEdges(bool demoEdges)
82149{
83− if (m_demoEdges != demoEdges) {
84− m_demoEdges = demoEdges;
85− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.canonical.unity.AccountsService"), QStringLiteral("demo-edges"), demoEdges);
86−
87− Q_EMIT demoEdgesChanged();
88− }
150+ setProperty(IFACE_UNITY, PROP_DEMO_EDGES, demoEdges);
89151}
90152
91153bool AccountsService::enableLauncherWhileLocked() const
92154{
93− return m_enableLauncherWhileLocked;
155+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED);
156+ return value.toBool();
94157}
95158
96159bool AccountsService::enableIndicatorsWhileLocked() const
97160{
98− return m_enableIndicatorsWhileLocked;
161+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED);
162+ return value.toBool();
99163}
100164
101165QString AccountsService::backgroundFile() const
102166{
103− return m_backgroundFile;
167+ auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE);
168+ return value.toString();
104169}
105170
106171bool AccountsService::statsWelcomeScreen() const
107172{
108− return m_statsWelcomeScreen;
173+ auto value = getProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN);
174+ return value.toBool();
109175}
110176
111177AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
112178{
113− return m_passwordDisplayHint;
179+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT);
180+ return (PasswordDisplayHint)value.toInt();
114181}
115182
116183bool AccountsService::hereEnabled() const
117184{
118− return m_hereEnabled;
185+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED);
186+ return value.toBool();
119187}
120188
121189void AccountsService::setHereEnabled(bool enabled)
122190{
123− if (m_hereEnabled != enabled) {
124− m_hereEnabled = enabled;
125− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.ubuntu.location.providers.here.AccountsService"), QStringLiteral("LicenseAccepted"), enabled);
126−
127− Q_EMIT hereEnabledChanged();
128− }
191+ setProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED, enabled);
129192}
130193
131194QString AccountsService::hereLicensePath() const
132195{
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;
134201}
135202
136203bool AccountsService::hereLicensePathValid() const
137204{
138− return !m_hereLicensePath.isNull();
139−}
140−
141−void AccountsService::updateDemoEdges(bool async)
142−{
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);
147−
148− connect(watcher, &QDBusPendingCallWatcher::finished,
149− this, [this](QDBusPendingCallWatcher* watcher) {
150−
151− QDBusPendingReply<QDBusVariant> reply = *watcher;
152− watcher->deleteLater();
153− if (reply.isError()) {
154− qWarning() << "Failed to get 'demo-edges' property - " << reply.error().message();
155− return;
156− }
157−
158− auto demoEdges = reply.value().variant().toBool();
159− if (m_demoEdges != demoEdges) {
160− m_demoEdges = demoEdges;
161− Q_EMIT demoEdgesChanged();
162− }
163− });
164− if (!async) {
165− watcher->waitForFinished();
166− delete watcher;
167− }
205+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
206+ return !value.toString().isNull();
168207}
169208
170−void AccountsService::updateEnableLauncherWhileLocked(bool async)
209+uint AccountsService::failedLogins() const
171210{
172− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
173− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
174− QStringLiteral("EnableLauncherWhileLocked"));
175− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
176−
177− connect(watcher, &QDBusPendingCallWatcher::finished,
178− this, [this](QDBusPendingCallWatcher* watcher) {
179−
180− QDBusPendingReply<QVariant> reply = *watcher;
181− watcher->deleteLater();
182− if (reply.isError()) {
183− qWarning() << "Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
184− return;
185− }
186−
187− const bool enableLauncherWhileLocked = reply.value().toBool();
188− if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
189− m_enableLauncherWhileLocked = enableLauncherWhileLocked;
190− Q_EMIT enableLauncherWhileLockedChanged();
191− }
192− });
193− if (!async) {
194− watcher->waitForFinished();
195− delete watcher;
196− }
211+ return getProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS).toUInt();
197212}
198213
199−void AccountsService::updateEnableIndicatorsWhileLocked(bool async)
214+void AccountsService::setFailedLogins(uint failedLogins)
200215{
201− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
202− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
203− QStringLiteral("EnableIndicatorsWhileLocked"));
204− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
205−
206− connect(watcher, &QDBusPendingCallWatcher::finished,
207− this, [this](QDBusPendingCallWatcher* watcher) {
208−
209− QDBusPendingReply<QVariant> reply = *watcher;
210− watcher->deleteLater();
211− if (reply.isError()) {
212− qWarning() << "Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
213− return;
214− }
215−
216− const bool enableIndicatorsWhileLocked = reply.value().toBool();
217− if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
218− m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
219− Q_EMIT enableIndicatorsWhileLockedChanged();
220− }
221− });
222− if (!async) {
223− watcher->waitForFinished();
224− delete watcher;
225− }
216+ setProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, failedLogins);
226217}
227218
228−void AccountsService::updateBackgroundFile(bool async)
229−{
230− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
231− QStringLiteral("org.freedesktop.Accounts.User"),
232− QStringLiteral("BackgroundFile"));
233− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
234−
235− connect(watcher, &QDBusPendingCallWatcher::finished,
236− this, [this](QDBusPendingCallWatcher* watcher) {
237−
238− QDBusPendingReply<QVariant> reply = *watcher;
239− watcher->deleteLater();
240− if (reply.isError()) {
241− qWarning() << "Failed to get 'BackgroundFile' property - " << reply.error().message();
242− return;
243− }
244−
245− const QString backgroundFile = reply.value().toString();
246− if (m_backgroundFile != backgroundFile) {
247− m_backgroundFile = backgroundFile;
248− Q_EMIT backgroundFileChanged();
249− }
250− });
251− if (!async) {
252− watcher->waitForFinished();
253− delete watcher;
254− }
255−}
219+// ====================================================
220+// Everything below this line is generic helper methods
221+// ====================================================
256222
257−void AccountsService::updateMouseCursorSpeed()
223+void AccountsService::emitChangedForProperty(const QString &interface, const QString &property)
258224{
259− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
260− QStringLiteral("com.ubuntu.AccountsService.Input"),
261− QStringLiteral("MouseCursorSpeed"));
262− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
263−
264− connect(watcher, &QDBusPendingCallWatcher::finished,
265− this, [this](QDBusPendingCallWatcher* watcher) {
266−
267− QDBusPendingReply<QVariant> reply = *watcher;
268− watcher->deleteLater();
269− if (reply.isError()) {
270− qWarning() << "Failed to get 'MouseCursorSpeed' property - " << reply.error().message();
271− return;
272− }
273−
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());
277− });
225+ QString signalName = m_properties[interface][property].signal;
226+ QMetaObject::invokeMethod(this, signalName.toUtf8().data());
278227}
279228
280−void AccountsService::updateTouchpadCursorSpeed()
229+QVariant AccountsService::getProperty(const QString &interface, const QString &property) const
281230{
282− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
283− QStringLiteral("com.ubuntu.AccountsService.Input"),
284− QStringLiteral("TouchpadCursorSpeed"));
285− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
286−
287− connect(watcher, &QDBusPendingCallWatcher::finished,
288− this, [this](QDBusPendingCallWatcher* watcher) {
289−
290− QDBusPendingReply<QVariant> reply = *watcher;
291− watcher->deleteLater();
292− if (reply.isError()) {
293− qWarning() << "Failed to get 'TouchpadCursorSpeed' property - " << reply.error().message();
294− return;
295− }
296−
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());
300− });
231+ return m_properties[interface][property].value;
301232}
302233
303−void AccountsService::updateStatsWelcomeScreen(bool async)
234+void AccountsService::setProperty(const QString &interface, const QString &property, const QVariant &value)
304235{
305− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
306− QStringLiteral("com.ubuntu.touch.AccountsService.SecurityPrivacy"),
307− QStringLiteral("StatsWelcomeScreen"));
308− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
309−
310− connect(watcher, &QDBusPendingCallWatcher::finished,
311− this, [this](QDBusPendingCallWatcher* watcher) {
312−
313− QDBusPendingReply<QVariant> reply = *watcher;
314− watcher->deleteLater();
315− if (reply.isError()) {
316− qWarning() << "Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
317− return;
318− }
319−
320− const bool statsWelcomeScreen = reply.value().toBool();
321− if (m_statsWelcomeScreen != statsWelcomeScreen) {
322− m_statsWelcomeScreen = statsWelcomeScreen;
323− Q_EMIT statsWelcomeScreenChanged();
324− }
325− });
326− if (!async) {
327− watcher->waitForFinished();
328− delete watcher;
236+ if (m_properties[interface][property].value != value) {
237+ m_properties[interface][property].value = value;
238+ m_service->setUserPropertyAsync(m_user, interface, property, value);
239+ emitChangedForProperty(interface, property);
329240 }
330241}
331242
332−void AccountsService::updatePasswordDisplayHint(bool async)
243+void AccountsService::updateCache(const QString &interface, const QString &property, const QVariant &value)
333244{
334− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
335− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
336− QStringLiteral("PasswordDisplayHint"));
337− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
338−
339− connect(watcher, &QDBusPendingCallWatcher::finished,
340− this, [this](QDBusPendingCallWatcher* watcher) {
341−
342− QDBusPendingReply<QVariant> reply = *watcher;
343− watcher->deleteLater();
344− if (reply.isError()) {
345− qWarning() << "Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
346− return;
347− }
348−
349− const PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().toInt();
350− if (m_passwordDisplayHint != passwordDisplayHint) {
351− m_passwordDisplayHint = passwordDisplayHint;
352− Q_EMIT passwordDisplayHintChanged();
245+ PropertyInfo &info = m_properties[interface][property];
246+
247+ if (info.proxyInterface) {
248+ QVariant finalValue;
249+ if (info.proxyConverter) {
250+ finalValue = info.proxyConverter(value);
251+ } else {
252+ finalValue = value;
353253 }
354− });
355− if (!async) {
356− watcher->waitForFinished();
357− delete watcher;
254+ info.proxyInterface->asyncCall(info.proxyMethod, finalValue);
255+ return; // don't bother saving a copy
358256 }
359−}
360−
361−void AccountsService::updateFailedLogins(bool async)
362−{
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);
367−
368− connect(watcher, &QDBusPendingCallWatcher::finished,
369− this, [this](QDBusPendingCallWatcher* watcher) {
370−
371− QDBusPendingReply<QVariant> reply = *watcher;
372− watcher->deleteLater();
373− if (reply.isError()) {
374− qWarning() << "Failed to get 'FailedLogins' property - " << reply.error().message();
375− return;
376− }
377257
378− const uint failedLogins = reply.value().toUInt();
379− if (m_failedLogins != failedLogins) {
380− m_failedLogins = failedLogins;
381− Q_EMIT failedLoginsChanged();
382− }
383− });
384− if (!async) {
385− watcher->waitForFinished();
386− delete watcher;
258+ if (info.value != value) {
259+ info.value = value;
260+ emitChangedForProperty(interface, property);
387261 }
388262}
389263
390−void AccountsService::updateHereEnabled(bool async)
264+void AccountsService::updateProperty(const QString &interface, const QString &property)
391265{
392266 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
393− QStringLiteral("com.ubuntu.location.providers.here.AccountsService"),
394− QStringLiteral("LicenseAccepted"));
267+ interface,
268+ property);
395269 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
396270
397271 connect(watcher, &QDBusPendingCallWatcher::finished,
398− this, [this](QDBusPendingCallWatcher* watcher) {
272+ this, [this, interface, property](QDBusPendingCallWatcher* watcher) {
399273
400274 QDBusPendingReply<QVariant> reply = *watcher;
401275 watcher->deleteLater();
402276 if (reply.isError()) {
403− qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
277+ qWarning() << "Failed to get '" << property << "' property:" << reply.error().message();
404278 return;
405279 }
406280
407− const bool hereEnabled = reply.value().toBool();
408− if (m_hereEnabled != hereEnabled) {
409− m_hereEnabled = hereEnabled;
410− Q_EMIT hereEnabledChanged();
411− }
281+ updateCache(interface, property, reply.value());
412282 });
413− if (!async) {
414− watcher->waitForFinished();
415− delete watcher;
416− }
417283}
418284
419−void AccountsService::updateHereLicensePath(bool async)
285+void AccountsService::updateAllProperties(const QString &interface, bool async)
420286{
421− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
422− QStringLiteral("com.ubuntu.location.providers.here.AccountsService"),
423− QStringLiteral("LicenseBasePath"));
287+ QDBusPendingCall pendingReply = m_service->getAllPropertiesAsync(m_user,
288+ interface);
424289 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
425290
426291 connect(watcher, &QDBusPendingCallWatcher::finished,
427− this, [this](QDBusPendingCallWatcher* watcher) {
292+ this, [this, interface](QDBusPendingCallWatcher* watcher) {
428293
429− QDBusPendingReply<QVariant> reply = *watcher;
294+ QDBusPendingReply< QHash<QString, QVariant> > reply = *watcher;
430295 watcher->deleteLater();
431296 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();
433298 return;
434299 }
435300
436− QString hereLicensePath = reply.value().toString();
437− if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
438− hereLicensePath = QLatin1String("");
439−
440− if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
441− m_hereLicensePath = hereLicensePath;
442− Q_EMIT hereLicensePathChanged();
301+ auto valueHash = reply.value();
302+ auto i = valueHash.constBegin();
303+ while (i != valueHash.constEnd()) {
304+ updateCache(interface, i.key(), i.value());
305+ ++i;
443306 }
444307 });
445308 if (!async) {
446309 watcher->waitForFinished();
447− delete watcher;
448310 }
449311}
450312
451−uint AccountsService::failedLogins() const
313+void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter)
452314{
453− return m_failedLogins;
315+ registerProperty(interface, property, nullptr);
316+
317+ m_properties[interface][property].proxyInterface = iface;
318+ m_properties[interface][property].proxyMethod = method;
319+ m_properties[interface][property].proxyConverter = converter;
454320}
455321
456−void AccountsService::setFailedLogins(uint failedLogins)
322+void AccountsService::registerProperty(const QString &interface, const QString &property, const QString &signal)
457323{
458− if (m_failedLogins != failedLogins) {
459− m_failedLogins = failedLogins;
460− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.canonical.unity.AccountsService.Private"), QStringLiteral("FailedLogins"), failedLogins);
461−
462− Q_EMIT failedLoginsChanged();
463− }
324+ m_properties[interface][property] = PropertyInfo();
325+ m_properties[interface][property].signal = signal;
464326}
465327
466328void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
@@ -469,42 +331,13 @@ void AccountsService::onPropertiesChanged(const QString &user, const QString &in
469331 return;
470332 }
471333
472− if (interface == QLatin1String("com.canonical.unity.AccountsService")) {
473− if (changed.contains(QStringLiteral("demo-edges"))) {
474− updateDemoEdges();
475− }
476− } else if (interface == QLatin1String("com.canonical.unity.AccountsService.Private")) {
477− if (changed.contains(QStringLiteral("FailedLogins"))) {
478− updateFailedLogins();
479− }
480− } else if (interface == QLatin1String("com.ubuntu.AccountsService.Input")) {
481− if (changed.contains(QStringLiteral("MouseCursorSpeed"))) {
482− updateMouseCursorSpeed();
483− }
484− if (changed.contains(QStringLiteral("TouchpadCursorSpeed"))) {
485− updateTouchpadCursorSpeed();
486− }
487− } else if (interface == QLatin1String("com.ubuntu.touch.AccountsService.SecurityPrivacy")) {
488− if (changed.contains(QStringLiteral("StatsWelcomeScreen"))) {
489− updateStatsWelcomeScreen();
490− }
491− } else if (interface == QLatin1String("com.ubuntu.AccountsService.SecurityPrivacy")) {
492− if (changed.contains(QStringLiteral("PasswordDisplayHint"))) {
493− updatePasswordDisplayHint();
494− }
495− if (changed.contains(QStringLiteral("EnableLauncherWhileLocked"))) {
496− updateEnableLauncherWhileLocked();
497− }
498− if (changed.contains(QStringLiteral("EnableIndicatorsWhileLocked"))) {
499− updateEnableIndicatorsWhileLocked();
500− }
501− } else if (interface == QLatin1String("com.ubuntu.location.providers.here.AccountsService")) {
502− if (changed.contains(QStringLiteral("LicenseAccepted"))) {
503− updateHereEnabled();
504− }
505− if (changed.contains(QStringLiteral("LicenseBasePath"))) {
506− updateHereLicensePath();
334+ auto propHash = m_properties.value(interface);
335+ auto i = propHash.constBegin();
336+ while (i != propHash.constEnd()) {
337+ if (changed.contains(i.key())) {
338+ updateProperty(interface, i.key());
507339 }
340+ ++i;
508341 }
509342}
510343
@@ -514,6 +347,20 @@ void AccountsService::onMaybeChanged(const QString &user)
514347 return;
515348 }
516349
517− // Standard properties might have changed
518− updateBackgroundFile();
350+ // Any of the standard properties might have changed!
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());
355+ ++i;
356+ }
357+}
358+
359+void AccountsService::refresh(bool async)
360+{
361+ auto i = m_properties.constBegin();
362+ while (i != m_properties.constEnd()) {
363+ updateAllProperties(i.key(), async);
364+ ++i;
365+ }
519366}