19 #include "AccountsService.h"
20 #include "AccountsServiceDBusAdaptor.h"
23 #include <QStringList>
26 AccountsService::AccountsService(QObject* parent,
const QString &user)
28 m_service(new AccountsServiceDBusAdaptor(this)),
30 m_enableLauncherWhileLocked(false),
31 m_enableIndicatorsWhileLocked(false),
32 m_statsWelcomeScreen(false),
33 m_passwordDisplayHint(Keyboard),
38 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged,
this, &AccountsService::onPropertiesChanged);
39 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged,
this, &AccountsService::onMaybeChanged);
41 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv(
"USER")));
44 QString AccountsService::user()
const
49 void AccountsService::setUser(
const QString &user)
51 if (user.isEmpty() || m_user == user)
57 updateDemoEdges(
false);
58 updateEnableLauncherWhileLocked(
false);
59 updateEnableIndicatorsWhileLocked(
false);
60 updateBackgroundFile(
false);
61 updateStatsWelcomeScreen(
false);
62 updatePasswordDisplayHint(
false);
63 updateFailedLogins(
false);
64 updateHereEnabled(
false);
65 updateHereLicensePath(
false);
68 bool AccountsService::demoEdges()
const
73 void AccountsService::setDemoEdges(
bool demoEdges)
75 if (m_demoEdges != demoEdges) {
76 m_demoEdges = demoEdges;
77 m_service->setUserProperty(m_user, QStringLiteral(
"com.canonical.unity.AccountsService"), QStringLiteral(
"demo-edges"), demoEdges);
79 Q_EMIT demoEdgesChanged();
83 bool AccountsService::enableLauncherWhileLocked()
const
85 return m_enableLauncherWhileLocked;
88 bool AccountsService::enableIndicatorsWhileLocked()
const
90 return m_enableIndicatorsWhileLocked;
93 QString AccountsService::backgroundFile()
const
95 return m_backgroundFile;
98 bool AccountsService::statsWelcomeScreen()
const
100 return m_statsWelcomeScreen;
103 AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint()
const
105 return m_passwordDisplayHint;
108 bool AccountsService::hereEnabled()
const
110 return m_hereEnabled;
113 void AccountsService::setHereEnabled(
bool enabled)
115 if (m_hereEnabled != enabled) {
116 m_hereEnabled = enabled;
117 m_service->setUserProperty(m_user, QStringLiteral(
"com.ubuntu.location.providers.here.AccountsService"), QStringLiteral(
"LicenseAccepted"), enabled);
119 Q_EMIT hereEnabledChanged();
123 QString AccountsService::hereLicensePath()
const
125 return m_hereLicensePath;
128 bool AccountsService::hereLicensePathValid()
const
130 return !m_hereLicensePath.isNull();
133 void AccountsService::updateDemoEdges(
bool async)
135 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
136 QStringLiteral(
"com.canonical.unity.AccountsService"),
137 QStringLiteral(
"demo-edges"));
138 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
140 connect(watcher, &QDBusPendingCallWatcher::finished,
141 this, [
this](QDBusPendingCallWatcher* watcher) {
143 QDBusPendingReply<QDBusVariant> reply = *watcher;
144 watcher->deleteLater();
145 if (reply.isError()) {
146 qWarning() <<
"Failed to get 'demo-edges' property - " << reply.error().message();
150 auto demoEdges = reply.value().variant().toBool();
151 if (m_demoEdges != demoEdges) {
152 m_demoEdges = demoEdges;
153 Q_EMIT demoEdgesChanged();
157 watcher->waitForFinished();
162 void AccountsService::updateEnableLauncherWhileLocked(
bool async)
164 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
165 QStringLiteral(
"com.ubuntu.AccountsService.SecurityPrivacy"),
166 QStringLiteral(
"EnableLauncherWhileLocked"));
167 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
169 connect(watcher, &QDBusPendingCallWatcher::finished,
170 this, [
this](QDBusPendingCallWatcher* watcher) {
172 QDBusPendingReply<QVariant> reply = *watcher;
173 watcher->deleteLater();
174 if (reply.isError()) {
175 qWarning() <<
"Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
179 const bool enableLauncherWhileLocked = reply.value().toBool();
180 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
181 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
182 Q_EMIT enableLauncherWhileLockedChanged();
186 watcher->waitForFinished();
191 void AccountsService::updateEnableIndicatorsWhileLocked(
bool async)
193 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
194 QStringLiteral(
"com.ubuntu.AccountsService.SecurityPrivacy"),
195 QStringLiteral(
"EnableIndicatorsWhileLocked"));
196 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
198 connect(watcher, &QDBusPendingCallWatcher::finished,
199 this, [
this](QDBusPendingCallWatcher* watcher) {
201 QDBusPendingReply<QVariant> reply = *watcher;
202 watcher->deleteLater();
203 if (reply.isError()) {
204 qWarning() <<
"Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
208 const bool enableIndicatorsWhileLocked = reply.value().toBool();
209 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
210 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
211 Q_EMIT enableIndicatorsWhileLockedChanged();
215 watcher->waitForFinished();
220 void AccountsService::updateBackgroundFile(
bool async)
222 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
223 QStringLiteral(
"org.freedesktop.Accounts.User"),
224 QStringLiteral(
"BackgroundFile"));
225 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
227 connect(watcher, &QDBusPendingCallWatcher::finished,
228 this, [
this](QDBusPendingCallWatcher* watcher) {
230 QDBusPendingReply<QVariant> reply = *watcher;
231 watcher->deleteLater();
232 if (reply.isError()) {
233 qWarning() <<
"Failed to get 'BackgroundFile' property - " << reply.error().message();
237 const QString backgroundFile = reply.value().toString();
238 if (m_backgroundFile != backgroundFile) {
239 m_backgroundFile = backgroundFile;
240 Q_EMIT backgroundFileChanged();
244 watcher->waitForFinished();
249 void AccountsService::updateStatsWelcomeScreen(
bool async)
251 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
252 QStringLiteral(
"com.ubuntu.touch.AccountsService.SecurityPrivacy"),
253 QStringLiteral(
"StatsWelcomeScreen"));
254 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
256 connect(watcher, &QDBusPendingCallWatcher::finished,
257 this, [
this](QDBusPendingCallWatcher* watcher) {
259 QDBusPendingReply<QVariant> reply = *watcher;
260 watcher->deleteLater();
261 if (reply.isError()) {
262 qWarning() <<
"Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
266 const bool statsWelcomeScreen = reply.value().toBool();
267 if (m_statsWelcomeScreen != statsWelcomeScreen) {
268 m_statsWelcomeScreen = statsWelcomeScreen;
269 Q_EMIT statsWelcomeScreenChanged();
273 watcher->waitForFinished();
278 void AccountsService::updatePasswordDisplayHint(
bool async)
280 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
281 QStringLiteral(
"com.ubuntu.AccountsService.SecurityPrivacy"),
282 QStringLiteral(
"PasswordDisplayHint"));
283 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
285 connect(watcher, &QDBusPendingCallWatcher::finished,
286 this, [
this](QDBusPendingCallWatcher* watcher) {
288 QDBusPendingReply<QVariant> reply = *watcher;
289 watcher->deleteLater();
290 if (reply.isError()) {
291 qWarning() <<
"Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
295 const PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().toInt();
296 if (m_passwordDisplayHint != passwordDisplayHint) {
297 m_passwordDisplayHint = passwordDisplayHint;
298 Q_EMIT passwordDisplayHintChanged();
302 watcher->waitForFinished();
307 void AccountsService::updateFailedLogins(
bool async)
309 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
310 QStringLiteral(
"com.canonical.unity.AccountsService.Private"),
311 QStringLiteral(
"FailedLogins"));
312 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
314 connect(watcher, &QDBusPendingCallWatcher::finished,
315 this, [
this](QDBusPendingCallWatcher* watcher) {
317 QDBusPendingReply<QVariant> reply = *watcher;
318 watcher->deleteLater();
319 if (reply.isError()) {
320 qWarning() <<
"Failed to get 'FailedLogins' property - " << reply.error().message();
324 const uint failedLogins = reply.value().toUInt();
325 if (m_failedLogins != failedLogins) {
326 m_failedLogins = failedLogins;
327 Q_EMIT failedLoginsChanged();
331 watcher->waitForFinished();
336 void AccountsService::updateHereEnabled(
bool async)
338 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
339 QStringLiteral(
"com.ubuntu.location.providers.here.AccountsService"),
340 QStringLiteral(
"LicenseAccepted"));
341 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
343 connect(watcher, &QDBusPendingCallWatcher::finished,
344 this, [
this](QDBusPendingCallWatcher* watcher) {
346 QDBusPendingReply<QVariant> reply = *watcher;
347 watcher->deleteLater();
348 if (reply.isError()) {
349 qWarning() <<
"Failed to get 'LicenseAccepted' property - " << reply.error().message();
353 const bool hereEnabled = reply.value().toBool();
354 if (m_hereEnabled != hereEnabled) {
355 m_hereEnabled = hereEnabled;
356 Q_EMIT hereEnabledChanged();
360 watcher->waitForFinished();
365 void AccountsService::updateHereLicensePath(
bool async)
367 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
368 QStringLiteral(
"com.ubuntu.location.providers.here.AccountsService"),
369 QStringLiteral(
"LicenseBasePath"));
370 QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(pendingReply,
this);
372 connect(watcher, &QDBusPendingCallWatcher::finished,
373 this, [
this](QDBusPendingCallWatcher* watcher) {
375 QDBusPendingReply<QVariant> reply = *watcher;
376 watcher->deleteLater();
377 if (reply.isError()) {
378 qWarning() <<
"Failed to get 'LicenseBasePath' property - " << reply.error().message();
382 QString hereLicensePath = reply.value().toString();
383 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
384 hereLicensePath = QLatin1String(
"");
386 if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
387 m_hereLicensePath = hereLicensePath;
388 Q_EMIT hereLicensePathChanged();
392 watcher->waitForFinished();
397 uint AccountsService::failedLogins()
const
399 return m_failedLogins;
402 void AccountsService::setFailedLogins(uint failedLogins)
404 if (m_failedLogins != failedLogins) {
405 m_failedLogins = failedLogins;
406 m_service->setUserProperty(m_user, QStringLiteral(
"com.canonical.unity.AccountsService.Private"), QStringLiteral(
"FailedLogins"), failedLogins);
408 Q_EMIT failedLoginsChanged();
412 void AccountsService::onPropertiesChanged(
const QString &user,
const QString &interface,
const QStringList &changed)
414 if (m_user != user) {
418 if (interface == QLatin1String(
"com.canonical.unity.AccountsService")) {
419 if (changed.contains(QStringLiteral(
"demo-edges"))) {
422 }
else if (interface == QLatin1String(
"com.canonical.unity.AccountsService.Private")) {
423 if (changed.contains(QStringLiteral(
"FailedLogins"))) {
424 updateFailedLogins();
426 }
else if (interface == QLatin1String(
"com.ubuntu.touch.AccountsService.SecurityPrivacy")) {
427 if (changed.contains(QStringLiteral(
"StatsWelcomeScreen"))) {
428 updateStatsWelcomeScreen();
430 }
else if (interface == QLatin1String(
"com.ubuntu.AccountsService.SecurityPrivacy")) {
431 if (changed.contains(QStringLiteral(
"PasswordDisplayHint"))) {
432 updatePasswordDisplayHint();
434 if (changed.contains(QStringLiteral(
"EnableLauncherWhileLocked"))) {
435 updateEnableLauncherWhileLocked();
437 if (changed.contains(QStringLiteral(
"EnableIndicatorsWhileLocked"))) {
438 updateEnableIndicatorsWhileLocked();
440 }
else if (interface == QLatin1String(
"com.ubuntu.location.providers.here.AccountsService")) {
441 if (changed.contains(QStringLiteral(
"LicenseAccepted"))) {
444 if (changed.contains(QStringLiteral(
"LicenseBasePath"))) {
445 updateHereLicensePath();
450 void AccountsService::onMaybeChanged(
const QString &user)
452 if (m_user != user) {
457 updateBackgroundFile();