2 * Copyright (C) 2013, 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "AccountsService.h"
18#include "AccountsServiceDBusAdaptor.h"
24AccountsService::AccountsService(QObject* parent, const QString &user)
26 m_service(new AccountsServiceDBusAdaptor(this)),
28 m_enableLauncherWhileLocked(false),
29 m_enableIndicatorsWhileLocked(false),
30 m_statsWelcomeScreen(false),
31 m_passwordDisplayHint(Keyboard),
34 m_hereLicensePath() // null means not set yet
36 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
37 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
39 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
42QString AccountsService::user() const
47void AccountsService::setUser(const QString &user)
49 if (user.isEmpty() || m_user == user)
55 updateDemoEdges(false);
56 updateEnableLauncherWhileLocked(false);
57 updateEnableIndicatorsWhileLocked(false);
58 updateBackgroundFile(false);
59 updateStatsWelcomeScreen(false);
60 updatePasswordDisplayHint(false);
61 updateFailedLogins(false);
62 updateHereEnabled(false);
63 updateHereLicensePath(false);
66bool AccountsService::demoEdges() const
71void AccountsService::setDemoEdges(bool demoEdges)
73 if (m_demoEdges != demoEdges) {
74 m_demoEdges = demoEdges;
75 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
77 Q_EMIT demoEdgesChanged();
81bool AccountsService::enableLauncherWhileLocked() const
83 return m_enableLauncherWhileLocked;
86bool AccountsService::enableIndicatorsWhileLocked() const
88 return m_enableIndicatorsWhileLocked;
91QString AccountsService::backgroundFile() const
93 return m_backgroundFile;
96bool AccountsService::statsWelcomeScreen() const
98 return m_statsWelcomeScreen;
101AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
103 return m_passwordDisplayHint;
106bool AccountsService::hereEnabled() const
108 return m_hereEnabled;
111void AccountsService::setHereEnabled(bool enabled)
113 if (m_hereEnabled != enabled) {
114 m_hereEnabled = enabled;
115 m_service->setUserProperty(m_user, "com.ubuntu.location.providers.here.AccountsService", "LicenseAccepted", enabled);
117 Q_EMIT hereEnabledChanged();
121QString AccountsService::hereLicensePath() const
123 return m_hereLicensePath;
126bool AccountsService::hereLicensePathValid() const
128 return !m_hereLicensePath.isNull();
131QString AccountsService::realName() const
136void AccountsService::setRealName(const QString &realName)
138 if (realName != m_realName) {
139 m_realName = realName;
140 m_service->setUserProperty(m_user, "org.freedesktop.Accounts.User", "RealName", m_realName);
141 Q_EMIT realNameChanged();
145QString AccountsService::email() const
150void AccountsService::setEmail(const QString &email)
152 if (email != m_email) {
154 m_service->setUserProperty(m_user, "org.freedesktop.Accounts.User", "Email", m_email);
155 Q_EMIT emailChanged();
159void AccountsService::updateDemoEdges(bool async)
161 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
162 "com.canonical.unity.AccountsService",
164 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
166 connect(watcher, &QDBusPendingCallWatcher::finished,
167 this, [this](QDBusPendingCallWatcher* watcher) {
169 QDBusPendingReply<QDBusVariant> reply = *watcher;
170 watcher->deleteLater();
171 if (reply.isError()) {
172 qWarning() << "Failed to get 'demo-edges' property - " << reply.error().message();
176 auto demoEdges = reply.value().variant().toBool();
177 if (m_demoEdges != demoEdges) {
178 m_demoEdges = demoEdges;
179 Q_EMIT demoEdgesChanged();
183 watcher->waitForFinished();
188void AccountsService::updateEnableLauncherWhileLocked(bool async)
190 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
191 "com.ubuntu.AccountsService.SecurityPrivacy",
192 "EnableLauncherWhileLocked");
193 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
195 connect(watcher, &QDBusPendingCallWatcher::finished,
196 this, [this](QDBusPendingCallWatcher* watcher) {
198 QDBusPendingReply<QVariant> reply = *watcher;
199 watcher->deleteLater();
200 if (reply.isError()) {
201 qWarning() << "Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
205 const bool enableLauncherWhileLocked = reply.value().toBool();
206 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
207 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
208 Q_EMIT enableLauncherWhileLockedChanged();
212 watcher->waitForFinished();
217void AccountsService::updateEnableIndicatorsWhileLocked(bool async)
219 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
220 "com.ubuntu.AccountsService.SecurityPrivacy",
221 "EnableIndicatorsWhileLocked");
222 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
224 connect(watcher, &QDBusPendingCallWatcher::finished,
225 this, [this](QDBusPendingCallWatcher* watcher) {
227 QDBusPendingReply<QVariant> reply = *watcher;
228 watcher->deleteLater();
229 if (reply.isError()) {
230 qWarning() << "Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
234 const bool enableIndicatorsWhileLocked = reply.value().toBool();
235 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
236 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
237 Q_EMIT enableIndicatorsWhileLockedChanged();
241 watcher->waitForFinished();
246void AccountsService::updateBackgroundFile(bool async)
248 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
249 "org.freedesktop.Accounts.User",
251 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
253 connect(watcher, &QDBusPendingCallWatcher::finished,
254 this, [this](QDBusPendingCallWatcher* watcher) {
256 QDBusPendingReply<QVariant> reply = *watcher;
257 watcher->deleteLater();
258 if (reply.isError()) {
259 qWarning() << "Failed to get 'BackgroundFile' property - " << reply.error().message();
263 const QString backgroundFile = reply.value().toString();
264 if (m_backgroundFile != backgroundFile) {
265 m_backgroundFile = backgroundFile;
266 Q_EMIT backgroundFileChanged();
270 watcher->waitForFinished();
275void AccountsService::updateStatsWelcomeScreen(bool async)
277 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
278 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
279 "StatsWelcomeScreen");
280 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
282 connect(watcher, &QDBusPendingCallWatcher::finished,
283 this, [this](QDBusPendingCallWatcher* watcher) {
285 QDBusPendingReply<QVariant> reply = *watcher;
286 watcher->deleteLater();
287 if (reply.isError()) {
288 qWarning() << "Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
292 const bool statsWelcomeScreen = reply.value().toBool();
293 if (m_statsWelcomeScreen != statsWelcomeScreen) {
294 m_statsWelcomeScreen = statsWelcomeScreen;
295 Q_EMIT statsWelcomeScreenChanged();
299 watcher->waitForFinished();
304void AccountsService::updatePasswordDisplayHint(bool async)
306 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
307 "com.ubuntu.AccountsService.SecurityPrivacy",
308 "PasswordDisplayHint");
309 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
311 connect(watcher, &QDBusPendingCallWatcher::finished,
312 this, [this](QDBusPendingCallWatcher* watcher) {
314 QDBusPendingReply<QVariant> reply = *watcher;
315 watcher->deleteLater();
316 if (reply.isError()) {
317 qWarning() << "Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
321 const PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().toInt();
322 if (m_passwordDisplayHint != passwordDisplayHint) {
323 m_passwordDisplayHint = passwordDisplayHint;
324 Q_EMIT passwordDisplayHintChanged();
328 watcher->waitForFinished();
333void AccountsService::updateFailedLogins(bool async)
335 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
336 "com.canonical.unity.AccountsService.Private",
338 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
340 connect(watcher, &QDBusPendingCallWatcher::finished,
341 this, [this](QDBusPendingCallWatcher* watcher) {
343 QDBusPendingReply<QVariant> reply = *watcher;
344 watcher->deleteLater();
345 if (reply.isError()) {
346 qWarning() << "Failed to get 'FailedLogins' property - " << reply.error().message();
350 const uint failedLogins = reply.value().toUInt();
351 if (m_failedLogins != failedLogins) {
352 m_failedLogins = failedLogins;
353 Q_EMIT failedLoginsChanged();
357 watcher->waitForFinished();
362void AccountsService::updateHereEnabled(bool async)
364 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
365 "com.ubuntu.location.providers.here.AccountsService",
367 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
369 connect(watcher, &QDBusPendingCallWatcher::finished,
370 this, [this](QDBusPendingCallWatcher* watcher) {
372 QDBusPendingReply<QVariant> reply = *watcher;
373 watcher->deleteLater();
374 if (reply.isError()) {
375 qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
379 const bool hereEnabled = reply.value().toBool();
380 if (m_hereEnabled != hereEnabled) {
381 m_hereEnabled = hereEnabled;
382 Q_EMIT hereEnabledChanged();
386 watcher->waitForFinished();
391void AccountsService::updateHereLicensePath(bool async)
393 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
394 "com.ubuntu.location.providers.here.AccountsService",
396 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
398 connect(watcher, &QDBusPendingCallWatcher::finished,
399 this, [this](QDBusPendingCallWatcher* watcher) {
401 QDBusPendingReply<QVariant> reply = *watcher;
402 watcher->deleteLater();
403 if (reply.isError()) {
404 qWarning() << "Failed to get 'LicenseBasePath' property - " << reply.error().message();
408 QString hereLicensePath = reply.value().toString();
409 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
410 hereLicensePath = "";
412 if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
413 m_hereLicensePath = hereLicensePath;
414 Q_EMIT hereLicensePathChanged();
418 watcher->waitForFinished();
423void AccountsService::updateRealName(bool async)
425 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user, "org.freedesktop.Accounts.User", "RealName");
426 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
428 connect(watcher, &QDBusPendingCallWatcher::finished,
429 this, [this](QDBusPendingCallWatcher* watcher) {
430 QDBusPendingReply<QVariant> reply = *watcher;
431 watcher->deleteLater();
432 if (reply.isError()) {
433 qWarning() << "Failed to get 'RealName' property - " << reply.error().message();
437 const QString realName = reply.value().toString();
438 if (m_realName != realName) {
439 m_realName = realName;
440 Q_EMIT realNameChanged();
444 watcher->waitForFinished();
449void AccountsService::updateEmail(bool async)
451 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user, "org.freedesktop.Accounts.User", "Email");
452 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
454 connect(watcher, &QDBusPendingCallWatcher::finished,
455 this, [this](QDBusPendingCallWatcher* watcher) {
456 QDBusPendingReply<QVariant> reply = *watcher;
457 watcher->deleteLater();
458 if (reply.isError()) {
459 qWarning() << "Failed to get 'Email' property - " << reply.error().message();
463 const QString email = reply.value().toString();
464 if (m_email != email) {
466 Q_EMIT emailChanged();
470 watcher->waitForFinished();
475uint AccountsService::failedLogins() const
477 return m_failedLogins;
480void AccountsService::setFailedLogins(uint failedLogins)
482 if (m_failedLogins != failedLogins) {
483 m_failedLogins = failedLogins;
484 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins", failedLogins);
486 Q_EMIT failedLoginsChanged();
490void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
492 if (m_user != user) {
496 if (interface == "com.canonical.unity.AccountsService") {
497 if (changed.contains("demo-edges")) {
500 } else if (interface == "com.canonical.unity.AccountsService.Private") {
501 if (changed.contains("FailedLogins")) {
502 updateFailedLogins();
504 } else if (interface == "com.ubuntu.touch.AccountsService.SecurityPrivacy") {
505 if (changed.contains("StatsWelcomeScreen")) {
506 updateStatsWelcomeScreen();
508 } else if (interface == "com.ubuntu.AccountsService.SecurityPrivacy") {
509 if (changed.contains("PasswordDisplayHint")) {
510 updatePasswordDisplayHint();
512 if (changed.contains("EnableLauncherWhileLocked")) {
513 updateEnableLauncherWhileLocked();
515 if (changed.contains("EnableIndicatorsWhileLocked")) {
516 updateEnableIndicatorsWhileLocked();
518 } else if (interface == "com.ubuntu.location.providers.here.AccountsService") {
519 if (changed.contains("LicenseAccepted")) {
522 if (changed.contains("LicenseBasePath")) {
523 updateHereLicensePath();
528void AccountsService::onMaybeChanged(const QString &user)
530 if (m_user != user) {
534 // Standard properties might have changed
535 updateBackgroundFile();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list