on xenial help sign in
Refactor AccountsService plugin to use less boilerplate
ac766b5Michael Terry
plugins/AccountsService/AccountsService.cpp+137−342
@@ -24,17 +24,29 @@
24#include <QStringList>
24#include <QStringList>
25#include <QDebug>
25#include <QDebug>
26
26
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_PASSWORD_DISPLAY_HINT QStringLiteral("PasswordDisplayHint")
44+#define PROP_STATS_WELCOME_SCREEN QStringLiteral("StatsWelcomeScreen")
45+#define PROP_TOUCHPAD_CURSOR_SPEED QStringLiteral("TouchpadCursorSpeed")
46+
27AccountsService::AccountsService(QObject* parent, const QString &user)
47AccountsService::AccountsService(QObject* parent, const QString &user)
28− : QObject(parent),
48+ : QObject(parent)
29− m_service(new AccountsServiceDBusAdaptor(this)),
49+ , 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
38{
50{
39 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
51 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
40 QStringLiteral("/com/canonical/Unity/Input"),
52 QStringLiteral("/com/canonical/Unity/Input"),
@@ -44,6 +56,21 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
44 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
56 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
45 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
57 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
46
58
59+ registerProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE, QStringLiteral("backgroundFileChanged"));
60+ registerProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED, QStringLiteral("hereEnabledChanged"));
61+ registerProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH, QStringLiteral("hereLicensePathChanged"));
62+ registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED, QStringLiteral("enableLauncherWhileLockedChanged"));
63+ registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED, QStringLiteral("enableIndicatorsWhileLockedChanged"));
64+ registerProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT, QStringLiteral("passwordDisplayHintChanged"));
65+ registerProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN, QStringLiteral("statsWelcomeScreenChanged"));
66+ registerProperty(IFACE_UNITY, PROP_DEMO_EDGES, QStringLiteral("demoEdgesChanged"));
67+ registerProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, QStringLiteral("failedLoginsChanged"));
68+
69+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_CURSOR_SPEED,
70+ m_unityInput, QStringLiteral("setMouseCursorSpeed"));
71+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_CURSOR_SPEED,
72+ m_unityInput, QStringLiteral("setTouchpadCursorSpeed"));
73+
47 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
74 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
48}
75}
49
76
@@ -57,410 +84,193 @@ void AccountsService::setUser(const QString &user)
57 if (user.isEmpty() || m_user == user)
84 if (user.isEmpty() || m_user == user)
58 return;
85 return;
59
86
87+ bool wasEmpty = m_user.isEmpty();
88+
60 m_user = user;
89 m_user = user;
61 Q_EMIT userChanged();
90 Q_EMIT userChanged();
62
91
63− updateDemoEdges(false);
92+ // Do the first update synchronously, as a cheap way to block rendering
64− updateEnableLauncherWhileLocked(false);
93+ // until we have the right values on bootup.
65− updateEnableIndicatorsWhileLocked(false);
94+ refresh(!wasEmpty);
66− updateBackgroundFile(false);
67− updateMouseCursorSpeed();
68− updateTouchpadCursorSpeed();
69− updateStatsWelcomeScreen(false);
70− updatePasswordDisplayHint(false);
71− updateFailedLogins(false);
72− updateHereEnabled(false);
73− updateHereLicensePath(false);
74}
95}
75
96
76bool AccountsService::demoEdges() const
97bool AccountsService::demoEdges() const
77{
98{
78− return m_demoEdges;
99+ auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
100+ return value.toBool();
79}
101}
80
102
81void AccountsService::setDemoEdges(bool demoEdges)
103void AccountsService::setDemoEdges(bool demoEdges)
82{
104{
83− if (m_demoEdges != demoEdges) {
105+ 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);
86−
87− Q_EMIT demoEdgesChanged();
88− }
89}
106}
90
107
91bool AccountsService::enableLauncherWhileLocked() const
108bool AccountsService::enableLauncherWhileLocked() const
92{
109{
93− return m_enableLauncherWhileLocked;
110+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED);
111+ return value.toBool();
94}
112}
95
113
96bool AccountsService::enableIndicatorsWhileLocked() const
114bool AccountsService::enableIndicatorsWhileLocked() const
97{
115{
98− return m_enableIndicatorsWhileLocked;
116+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED);
117+ return value.toBool();
99}
118}
100
119
101QString AccountsService::backgroundFile() const
120QString AccountsService::backgroundFile() const
102{
121{
103− return m_backgroundFile;
122+ auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE);
123+ return value.toString();
104}
124}
105
125
106bool AccountsService::statsWelcomeScreen() const
126bool AccountsService::statsWelcomeScreen() const
107{
127{
108− return m_statsWelcomeScreen;
128+ auto value = getProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN);
129+ return value.toBool();
109}
130}
110
131
111AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
132AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
112{
133{
113− return m_passwordDisplayHint;
134+ auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT);
135+ return (PasswordDisplayHint)value.toInt();
114}
136}
115
137
116bool AccountsService::hereEnabled() const
138bool AccountsService::hereEnabled() const
117{
139{
118− return m_hereEnabled;
140+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED);
141+ return value.toBool();
119}
142}
120
143
121void AccountsService::setHereEnabled(bool enabled)
144void AccountsService::setHereEnabled(bool enabled)
122{
145{
123− if (m_hereEnabled != enabled) {
146+ 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);
126−
127− Q_EMIT hereEnabledChanged();
128− }
129}
147}
130
148
131QString AccountsService::hereLicensePath() const
149QString AccountsService::hereLicensePath() const
132{
150{
133− return m_hereLicensePath;
151+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
152+ QString hereLicensePath = value.toString();
153+ if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
154+ hereLicensePath.clear();
155+ return hereLicensePath;
134}
156}
135
157
136bool AccountsService::hereLicensePathValid() const
158bool AccountsService::hereLicensePathValid() const
137{
159{
160+ auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
138− return !m_hereLicensePath.isNull();
161+ return !value.toString().isNull();
139}
162}
140
163
141−void AccountsService::updateDemoEdges(bool async)
164+uint AccountsService::failedLogins() const
142{
165{
143− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
166+ return getProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS).toUInt();
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− }
168}
167}
169
168
170−void AccountsService::updateEnableLauncherWhileLocked(bool async)
169+void AccountsService::setFailedLogins(uint failedLogins)
171{
170{
172− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
171+ setProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, failedLogins);
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− }
197}
172}
198
173
199−void AccountsService::updateEnableIndicatorsWhileLocked(bool async)
174+// ====================================================
200−{
175+// Everything below this line is generic helper methods
201− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
176+// ====================================================
202− QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy"),
203− QStringLiteral("EnableIndicatorsWhileLocked"));
204− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
205
177
206− connect(watcher, &QDBusPendingCallWatcher::finished,
178+void AccountsService::emitChangedForProperty(const QString &interface, const QString &property)
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− }
226−}
227−
228−void AccountsService::updateBackgroundFile(bool async)
229{
179{
230− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
180+ QString signalName = m_properties[interface][property].signal;
231− QStringLiteral("org.freedesktop.Accounts.User"),
181+ QMetaObject::invokeMethod(this, signalName.toUtf8().data());
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}
182}
256
183
257−void AccountsService::updateMouseCursorSpeed()
184+QVariant AccountsService::getProperty(const QString &interface, const QString &property) const
258{
185{
259− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
186+ return m_properties[interface][property].value;
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− });
278}
187}
279
188
280−void AccountsService::updateTouchpadCursorSpeed()
189+void AccountsService::setProperty(const QString &interface, const QString &property, const QVariant &value)
281{
190{
282− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
191+ if (m_properties[interface][property].value != value) {
283− QStringLiteral("com.ubuntu.AccountsService.Input"),
192+ m_properties[interface][property].value = value;
284− QStringLiteral("TouchpadCursorSpeed"));
193+ m_service->setUserPropertyAsync(m_user, interface, property, value);
285− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
194+ emitChangedForProperty(interface, property);
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− });
301−}
302−
303−void AccountsService::updateStatsWelcomeScreen(bool async)
304−{
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;
329 }
195 }
330}
196}
331
197
332−void AccountsService::updatePasswordDisplayHint(bool async)
198+void AccountsService::updateCache(const QString &interface, const QString &property, const QVariant &value)
333{
199{
334− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
200+ PropertyInfo &info = m_properties[interface][property];
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
201
342− QDBusPendingReply<QVariant> reply = *watcher;
202+ if (info.proxyInterface) {
343− watcher->deleteLater();
203+ info.proxyInterface->asyncCall(info.proxyMethod, value);
344− if (reply.isError()) {
204+ return; // don't bother saving a copy
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();
353− }
354− });
355− if (!async) {
356− watcher->waitForFinished();
357− delete watcher;
358 }
205 }
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− }
377
206
378− const uint failedLogins = reply.value().toUInt();
207+ if (info.value != value) {
379− if (m_failedLogins != failedLogins) {
208+ info.value = value;
380− m_failedLogins = failedLogins;
209+ emitChangedForProperty(interface, property);
381− Q_EMIT failedLoginsChanged();
382− }
383− });
384− if (!async) {
385− watcher->waitForFinished();
386− delete watcher;
387 }
210 }
388}
211}
389
212
390−void AccountsService::updateHereEnabled(bool async)
213+void AccountsService::updateProperty(const QString &interface, const QString &property)
391{
214{
392 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
215 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
393− QStringLiteral("com.ubuntu.location.providers.here.AccountsService"),
216+ interface,
394− QStringLiteral("LicenseAccepted"));
217+ property);
395 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
218 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
396
219
397 connect(watcher, &QDBusPendingCallWatcher::finished,
220 connect(watcher, &QDBusPendingCallWatcher::finished,
398− this, [this](QDBusPendingCallWatcher* watcher) {
221+ this, [this, interface, property](QDBusPendingCallWatcher* watcher) {
399
222
400 QDBusPendingReply<QVariant> reply = *watcher;
223 QDBusPendingReply<QVariant> reply = *watcher;
401 watcher->deleteLater();
224 watcher->deleteLater();
402 if (reply.isError()) {
225 if (reply.isError()) {
403− qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
226+ qWarning() << "Failed to get '" << property << "' property:" << reply.error().message();
404 return;
227 return;
405 }
228 }
406
229
407− const bool hereEnabled = reply.value().toBool();
230+ updateCache(interface, property, reply.value());
408− if (m_hereEnabled != hereEnabled) {
409− m_hereEnabled = hereEnabled;
410− Q_EMIT hereEnabledChanged();
411− }
412 });
231 });
413− if (!async) {
414− watcher->waitForFinished();
415− delete watcher;
416− }
417}
232}
418
233
419−void AccountsService::updateHereLicensePath(bool async)
234+void AccountsService::updateAllProperties(const QString &interface, bool async)
420{
235{
421− QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
236+ QDBusPendingCall pendingReply = m_service->getAllPropertiesAsync(m_user,
422− QStringLiteral("com.ubuntu.location.providers.here.AccountsService"),
237+ interface);
423− QStringLiteral("LicenseBasePath"));
424 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
238 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
425
239
426 connect(watcher, &QDBusPendingCallWatcher::finished,
240 connect(watcher, &QDBusPendingCallWatcher::finished,
427− this, [this](QDBusPendingCallWatcher* watcher) {
241+ this, [this, interface](QDBusPendingCallWatcher* watcher) {
428
242
429− QDBusPendingReply<QVariant> reply = *watcher;
243+ QDBusPendingReply< QHash<QString, QVariant> > reply = *watcher;
430 watcher->deleteLater();
244 watcher->deleteLater();
431 if (reply.isError()) {
245 if (reply.isError()) {
432− qWarning() << "Failed to get 'LicenseBasePath' property - " << reply.error().message();
246+ qWarning() << "Failed to get all properties for" << interface << ":" << reply.error().message();
433 return;
247 return;
434 }
248 }
435
249
436− QString hereLicensePath = reply.value().toString();
250+ auto valueHash = reply.value();
437− if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
251+ auto i = valueHash.constBegin();
438− hereLicensePath = QLatin1String("");
252+ while (i != valueHash.constEnd()) {
439−
253+ updateCache(interface, i.key(), i.value());
440− if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
254+ ++i;
441− m_hereLicensePath = hereLicensePath;
442− Q_EMIT hereLicensePathChanged();
443 }
255 }
444 });
256 });
445 if (!async) {
257 if (!async) {
446 watcher->waitForFinished();
258 watcher->waitForFinished();
447− delete watcher;
448 }
259 }
449}
260}
450
261
451−uint AccountsService::failedLogins() const
262+void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method)
452{
263{
453− return m_failedLogins;
264+ registerProperty(interface, property, nullptr);
265+
266+ m_properties[interface][property].proxyInterface = iface;
267+ m_properties[interface][property].proxyMethod = method;
454}
268}
455
269
456−void AccountsService::setFailedLogins(uint failedLogins)
270+void AccountsService::registerProperty(const QString &interface, const QString &property, const QString &signal)
457{
271{
458− if (m_failedLogins != failedLogins) {
272+ m_properties[interface][property] = PropertyInfo();
459− m_failedLogins = failedLogins;
273+ m_properties[interface][property].signal = signal;
460− m_service->setUserPropertyAsync(m_user, QStringLiteral("com.canonical.unity.AccountsService.Private"), QStringLiteral("FailedLogins"), failedLogins);
461−
462− Q_EMIT failedLoginsChanged();
463− }
464}
274}
465
275
466void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
276void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
@@ -469,42 +279,13 @@ void AccountsService::onPropertiesChanged(const QString &user, const QString &in
469 return;
279 return;
470 }
280 }
471
281
472− if (interface == QLatin1String("com.canonical.unity.AccountsService")) {
282+ auto propHash = m_properties.value(interface);
473− if (changed.contains(QStringLiteral("demo-edges"))) {
283+ auto i = propHash.constBegin();
474− updateDemoEdges();
284+ while (i != propHash.constEnd()) {
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"))) {
285+ if (changed.contains(i.key())) {
496− updateEnableLauncherWhileLocked();
286+ updateProperty(interface, i.key());
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();
507 }
287 }
288+ ++i;
508 }
289 }
509}
290}
510
291
@@ -514,6 +295,20 @@ void AccountsService::onMaybeChanged(const QString &user)
514 return;
295 return;
515 }
296 }
516
297
517− // Standard properties might have changed
298+ // Any of the standard properties might have changed!
518− updateBackgroundFile();
299+ auto propHash = m_properties.value(IFACE_ACCOUNTS_USER);
300+ auto i = propHash.constBegin();
301+ while (i != propHash.constEnd()) {
302+ updateProperty(IFACE_ACCOUNTS_USER, i.key());
303+ ++i;
304+ }
305+}
306+
307+void AccountsService::refresh(bool async)
308+{
309+ auto i = m_properties.constBegin();
310+ while (i != m_properties.constEnd()) {
311+ updateAllProperties(i.key(), async);
312+ ++i;
313+ }
519}
314}
plugins/AccountsService/AccountsService.h+22−20
@@ -19,8 +19,10 @@
19#ifndef UNITY_ACCOUNTSSERVICE_H
19#ifndef UNITY_ACCOUNTSSERVICE_H
20#define UNITY_ACCOUNTSSERVICE_H
20#define UNITY_ACCOUNTSSERVICE_H
21
21
22+#include <QHash>
22#include <QObject>
23#include <QObject>
23#include <QString>
24#include <QString>
25+#include <QVariant>
24
26
25class AccountsServiceDBusAdaptor;
27class AccountsServiceDBusAdaptor;
26class QDBusInterface;
28class QDBusInterface;
@@ -109,30 +111,30 @@ private Q_SLOTS:
109 void onMaybeChanged(const QString &user);
111 void onMaybeChanged(const QString &user);
110
112
111private:
113private:
112− void updateDemoEdges(bool async = true);
114+ void refresh(bool async);
113− void updateEnableLauncherWhileLocked(bool async = true);
115+ void registerProperty(const QString &interface, const QString &property, const QString &signal);
114− void updateEnableIndicatorsWhileLocked(bool async = true);
116+ void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method);
115− void updateBackgroundFile(bool async = true);
116− void updateMouseCursorSpeed();
117− void updateTouchpadCursorSpeed();
118− void updateStatsWelcomeScreen(bool async = true);
119− void updatePasswordDisplayHint(bool async = true);
120− void updateFailedLogins(bool async = true);
121− void updateHereEnabled(bool async = true);
122− void updateHereLicensePath(bool async = true);
123
117
118+ void updateAllProperties(const QString &interface, bool async);
119+ void updateProperty(const QString &interface, const QString &property);
120+ void updateCache(const QString &interface, const QString &property, const QVariant &value);
121+
122+ void setProperty(const QString &interface, const QString &property, const QVariant &value);
123+ QVariant getProperty(const QString &interface, const QString &property) const;
124+
125+ void emitChangedForProperty(const QString &interface, const QString &property);
126+
127+ struct PropertyInfo {
128+ QVariant value{};
129+ QString signal{};
130+ QDBusInterface *proxyInterface{};
131+ QString proxyMethod{};
132+ };
133+ typedef QHash< QString, QHash<QString, PropertyInfo> > PropertyHash;
134+ PropertyHash m_properties;
124 AccountsServiceDBusAdaptor *m_service;
135 AccountsServiceDBusAdaptor *m_service;
125 QDBusInterface *m_unityInput;
136 QDBusInterface *m_unityInput;
126 QString m_user;
137 QString m_user;
127− bool m_demoEdges;
128− bool m_enableLauncherWhileLocked;
129− bool m_enableIndicatorsWhileLocked;
130− QString m_backgroundFile;
131− bool m_statsWelcomeScreen;
132− PasswordDisplayHint m_passwordDisplayHint;
133− uint m_failedLogins;
134− bool m_hereEnabled;
135− QString m_hereLicensePath;
136};
138};
137
139
138#endif
140#endif
plugins/AccountsService/AccountsServiceDBusAdaptor.cpp+9
@@ -37,6 +37,15 @@ AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
37 connection, this);
37 connection, this);
38}
38}
39
39
40+QDBusPendingReply<QVariantMap> AccountsServiceDBusAdaptor::getAllPropertiesAsync(const QString &user, const QString &interface)
41+{
42+ QDBusInterface *iface = getUserInterface(user);
43+ if (iface != nullptr && iface->isValid()) {
44+ return iface->asyncCall(QStringLiteral("GetAll"), interface);
45+ }
46+ return QDBusPendingReply<QVariantMap>(QDBusMessage::createError(QDBusError::Other, QStringLiteral("Invalid Interface")));
47+}
48+
40QDBusPendingReply<QVariant> AccountsServiceDBusAdaptor::getUserPropertyAsync(const QString &user, const QString &interface, const QString &property)
49QDBusPendingReply<QVariant> AccountsServiceDBusAdaptor::getUserPropertyAsync(const QString &user, const QString &interface, const QString &property)
41{
50{
42 QDBusInterface *iface = getUserInterface(user);
51 QDBusInterface *iface = getUserInterface(user);
plugins/AccountsService/AccountsServiceDBusAdaptor.h+1
@@ -35,6 +35,7 @@ public:
35 explicit AccountsServiceDBusAdaptor(QObject *parent = 0);
35 explicit AccountsServiceDBusAdaptor(QObject *parent = 0);
36 ~AccountsServiceDBusAdaptor() = default;
36 ~AccountsServiceDBusAdaptor() = default;
37
37
38+ QDBusPendingReply<QVariantMap> getAllPropertiesAsync(const QString &user, const QString &interface);
38 Q_INVOKABLE QDBusPendingReply<QVariant> getUserPropertyAsync(const QString &user, const QString &interface, const QString &property);
39 Q_INVOKABLE QDBusPendingReply<QVariant> getUserPropertyAsync(const QString &user, const QString &interface, const QString &property);
39 Q_INVOKABLE QDBusPendingCall setUserPropertyAsync(const QString &user, const QString &interface, const QString &property, const QVariant &value);
40 Q_INVOKABLE QDBusPendingCall setUserPropertyAsync(const QString &user, const QString &interface, const QString &property, const QVariant &value);
40
41
tests/plugins/AccountsService/CMakeLists.txt+2
@@ -10,6 +10,7 @@ macro(make_dbus_class NAME INTERFACE)
10endmacro(make_dbus_class)
10endmacro(make_dbus_class)
11
11
12make_dbus_class(Accounts org.freedesktop.Accounts)
12make_dbus_class(Accounts org.freedesktop.Accounts)
13+make_dbus_class(Input com.ubuntu.AccountsService.Input)
13make_dbus_class(Properties org.freedesktop.DBus.Properties)
14make_dbus_class(Properties org.freedesktop.DBus.Properties)
14make_dbus_class(SecurityPrivacy com.ubuntu.touch.AccountsService.SecurityPrivacy)
15make_dbus_class(SecurityPrivacy com.ubuntu.touch.AccountsService.SecurityPrivacy)
15make_dbus_class(Location com.ubuntu.location.providers.here.AccountsService)
16make_dbus_class(Location com.ubuntu.location.providers.here.AccountsService)
@@ -27,6 +28,7 @@ add_executable(mock-server
27 ${CMAKE_CURRENT_BINARY_DIR}/AccountsAdaptor.cpp
28 ${CMAKE_CURRENT_BINARY_DIR}/AccountsAdaptor.cpp
28 ${CMAKE_CURRENT_BINARY_DIR}/AccountsPrivateAdaptor.cpp
29 ${CMAKE_CURRENT_BINARY_DIR}/AccountsPrivateAdaptor.cpp
29 ${CMAKE_CURRENT_BINARY_DIR}/AccountsUserAdaptor.cpp
30 ${CMAKE_CURRENT_BINARY_DIR}/AccountsUserAdaptor.cpp
31+ ${CMAKE_CURRENT_BINARY_DIR}/InputAdaptor.cpp
30 ${CMAKE_CURRENT_BINARY_DIR}/PropertiesAdaptor.cpp
32 ${CMAKE_CURRENT_BINARY_DIR}/PropertiesAdaptor.cpp
31 ${CMAKE_CURRENT_BINARY_DIR}/LocationAdaptor.cpp
33 ${CMAKE_CURRENT_BINARY_DIR}/LocationAdaptor.cpp
32 ${CMAKE_CURRENT_BINARY_DIR}/SecurityPrivacyAdaptor.cpp
34 ${CMAKE_CURRENT_BINARY_DIR}/SecurityPrivacyAdaptor.cpp
tests/plugins/AccountsService/PropertiesServer.cpp+12
@@ -42,6 +42,16 @@ QDBusVariant PropertiesServer::Get(const QString &interface, const QString &prop
42 }
42 }
43}
43}
44
44
45+QVariantMap PropertiesServer::GetAll(const QString &interface)
46+{
47+ if (m_properties.contains(interface)) {
48+ return m_properties[interface];
49+ } else {
50+ sendErrorReply(QDBusError::InvalidArgs, "Bad interface");
51+ return QVariantMap();
52+ }
53+}
54+
45void PropertiesServer::Set(const QString &interface, const QString &property, const QDBusVariant &variant)
55void PropertiesServer::Set(const QString &interface, const QString &property, const QDBusVariant &variant)
46{
56{
47 QVariant newValue = variant.variant();
57 QVariant newValue = variant.variant();
@@ -82,6 +92,8 @@ void PropertiesServer::Reset()
82 m_properties["com.canonical.unity.AccountsService"]["LauncherItems"] = QVariant::fromValue(QList<QVariantMap>());
92 m_properties["com.canonical.unity.AccountsService"]["LauncherItems"] = QVariant::fromValue(QList<QVariantMap>());
83 m_properties["com.canonical.unity.AccountsService.Private"]["FailedLogins"] = 0;
93 m_properties["com.canonical.unity.AccountsService.Private"]["FailedLogins"] = 0;
84 m_properties["com.ubuntu.touch.AccountsService.SecurityPrivacy"]["StatsWelcomeScreen"] = true;
94 m_properties["com.ubuntu.touch.AccountsService.SecurityPrivacy"]["StatsWelcomeScreen"] = true;
95+ m_properties["com.ubuntu.AccountsService.Input"]["MouseCursorSpeed"] = 0.5;
96+ m_properties["com.ubuntu.AccountsService.Input"]["TouchpadCursorSpeed"] = 0.5;
85 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableLauncherWhileLocked"] = true;
97 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableLauncherWhileLocked"] = true;
86 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableIndicatorsWhileLocked"] = true;
98 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableIndicatorsWhileLocked"] = true;
87 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["PasswordDisplayHint"] = AccountsService::Keyboard;
99 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["PasswordDisplayHint"] = AccountsService::Keyboard;
tests/plugins/AccountsService/PropertiesServer.h+1
@@ -35,6 +35,7 @@ public:
35
35
36public Q_SLOTS:
36public Q_SLOTS:
37 QDBusVariant Get(const QString &interface, const QString &property);
37 QDBusVariant Get(const QString &interface, const QString &property);
38+ QVariantMap GetAll(const QString &interface);
38 void Set(const QString &interface, const QString &property, const QDBusVariant &variant);
39 void Set(const QString &interface, const QString &property, const QDBusVariant &variant);
39
40
40 // mock only.
41 // mock only.
tests/plugins/AccountsService/client.cpp+9−9
@@ -107,7 +107,7 @@ private Q_SLOTS:
107 QCOMPARE(session.hereEnabled(), true);
107 QCOMPARE(session.hereEnabled(), true);
108 }
108 }
109
109
110− void testAsynchornousChangeForDemoEdges()
110+ void testAsynchronousChangeForDemoEdges()
111 {
111 {
112 AccountsService session(this, QTest::currentTestFunction());
112 AccountsService session(this, QTest::currentTestFunction());
113
113
@@ -119,7 +119,7 @@ private Q_SLOTS:
119 QTRY_COMPARE(session.demoEdges(), true);
119 QTRY_COMPARE(session.demoEdges(), true);
120 }
120 }
121
121
122− void testAsynchornousChangeForFailedLogins()
122+ void testAsynchronousChangeForFailedLogins()
123 {
123 {
124 AccountsService session(this, QTest::currentTestFunction());
124 AccountsService session(this, QTest::currentTestFunction());
125
125
@@ -131,7 +131,7 @@ private Q_SLOTS:
131 QTRY_COMPARE(session.failedLogins(), (uint)5);
131 QTRY_COMPARE(session.failedLogins(), (uint)5);
132 }
132 }
133
133
134− void testAsynchornousChangeForStatsWelcomeScreen()
134+ void testAsynchronousChangeForStatsWelcomeScreen()
135 {
135 {
136 AccountsService session(this, QTest::currentTestFunction());
136 AccountsService session(this, QTest::currentTestFunction());
137
137
@@ -143,7 +143,7 @@ private Q_SLOTS:
143 QTRY_COMPARE(session.statsWelcomeScreen(), false);
143 QTRY_COMPARE(session.statsWelcomeScreen(), false);
144 }
144 }
145
145
146− void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
146+ void testAsynchronousChangeForEnableLauncherWhileLocked()
147 {
147 {
148 AccountsService session(this, QTest::currentTestFunction());
148 AccountsService session(this, QTest::currentTestFunction());
149
149
@@ -155,7 +155,7 @@ private Q_SLOTS:
155 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
155 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
156 }
156 }
157
157
158− void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
158+ void testAsynchronousChangeForEnableIndicatorsWhileLocked()
159 {
159 {
160 AccountsService session(this, QTest::currentTestFunction());
160 AccountsService session(this, QTest::currentTestFunction());
161
161
@@ -167,7 +167,7 @@ private Q_SLOTS:
167 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
167 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
168 }
168 }
169
169
170− void testAsynchornousChangeForStatsPasswordDisplayHint()
170+ void testAsynchronousChangeForPasswordDisplayHint()
171 {
171 {
172 AccountsService session(this, QTest::currentTestFunction());
172 AccountsService session(this, QTest::currentTestFunction());
173
173
@@ -179,7 +179,7 @@ private Q_SLOTS:
179 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
179 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
180 }
180 }
181
181
182− void testAsynchornousChangeForStatsLicenseAccepted()
182+ void testAsynchronousChangeForLicenseAccepted()
183 {
183 {
184 AccountsService session(this, QTest::currentTestFunction());
184 AccountsService session(this, QTest::currentTestFunction());
185
185
@@ -191,7 +191,7 @@ private Q_SLOTS:
191 QTRY_COMPARE(session.hereEnabled(), true);
191 QTRY_COMPARE(session.hereEnabled(), true);
192 }
192 }
193
193
194− void testAsynchornousChangeForLicenseBasePath()
194+ void testAsynchronousChangeForLicenseBasePath()
195 {
195 {
196 AccountsService session(this, QTest::currentTestFunction());
196 AccountsService session(this, QTest::currentTestFunction());
197
197
@@ -203,7 +203,7 @@ private Q_SLOTS:
203 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
203 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
204 }
204 }
205
205
206− void testAsynchornousChangeForStatsBackgroundFile()
206+ void testAsynchronousChangeForBackgroundFile()
207 {
207 {
208 AccountsService session(this, QTest::currentTestFunction());
208 AccountsService session(this, QTest::currentTestFunction());
209
209
tests/plugins/AccountsService/interfaces.xml+5
@@ -5,6 +5,11 @@
5 <arg name="property" type="s" direction="in" />
5 <arg name="property" type="s" direction="in" />
6 <arg name="value" type="v" direction="out" />
6 <arg name="value" type="v" direction="out" />
7 </method>
7 </method>
8+ <method name="GetAll">
9+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
10+ <arg name="interface" type="s" direction="in" />
11+ <arg name="value" type="a{sv}" direction="out" />
12+ </method>
8 <method name="Set">
13 <method name="Set">
9 <arg name="interface" type="s" direction="in" />
14 <arg name="interface" type="s" direction="in" />
10 <arg name="property" type="s" direction="in" />
15 <arg name="property" type="s" direction="in" />