on 034e678 help sign in
unity8/plugins/AccountsService/AccountsService.cpp
171 lines 5.2 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 * Author: Michael Terry <michael.terry@canonical.com>
17 */
19#include "AccountsService.h"
20#include "AccountsServiceDBusAdaptor.h"
22#include <QStringList>
24AccountsService::AccountsService(QObject* parent)
25 : QObject(parent),
26 m_service(new AccountsServiceDBusAdaptor(this)),
27 m_user(qgetenv("USER")),
28 m_demoEdges(false),
29 m_statsWelcomeScreen(false),
30 m_passwordDisplayHint(Keyboard),
31 m_failedLogins(0)
33 connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
34 this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
35 connect(m_service, SIGNAL(maybeChanged(const QString &)),
36 this, SLOT(maybeChanged(const QString &)));
39QString AccountsService::user() const
41 return m_user;
44void AccountsService::setUser(const QString &user)
46 m_user = user;
47 Q_EMIT userChanged();
49 updateDemoEdges();
50 updateBackgroundFile();
51 updateStatsWelcomeScreen();
52 updatePasswordDisplayHint();
53 updateFailedLogins();
56bool AccountsService::demoEdges() const
58 return m_demoEdges;
61void AccountsService::setDemoEdges(bool demoEdges)
63 m_demoEdges = demoEdges;
64 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
67QString AccountsService::backgroundFile() const
69 return m_backgroundFile;
72bool AccountsService::statsWelcomeScreen() const
74 return m_statsWelcomeScreen;
77AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
79 return m_passwordDisplayHint;
82void AccountsService::updateDemoEdges()
84 auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
85 if (m_demoEdges != demoEdges) {
86 m_demoEdges = demoEdges;
87 Q_EMIT demoEdgesChanged();
88 }
91void AccountsService::updateBackgroundFile()
93 auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
94 if (m_backgroundFile != backgroundFile) {
95 m_backgroundFile = backgroundFile;
96 Q_EMIT backgroundFileChanged();
97 }
100void AccountsService::updateStatsWelcomeScreen()
102 bool statsWelcomeScreen = m_service->getUserProperty(m_user, "com.ubuntu.touch.AccountsService.SecurityPrivacy", "StatsWelcomeScreen").toBool();
103 if (m_statsWelcomeScreen != statsWelcomeScreen) {
104 m_statsWelcomeScreen = statsWelcomeScreen;
105 Q_EMIT statsWelcomeScreenChanged();
106 }
109void AccountsService::updatePasswordDisplayHint()
111 PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "PasswordDisplayHint").toInt();
112 if (m_passwordDisplayHint != passwordDisplayHint) {
113 m_passwordDisplayHint = passwordDisplayHint;
114 Q_EMIT passwordDisplayHintChanged();
115 }
118void AccountsService::updateFailedLogins()
120 uint failedLogins = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins").toUInt();
121 if (m_failedLogins != failedLogins) {
122 m_failedLogins = failedLogins;
123 Q_EMIT failedLoginsChanged();
124 }
127uint AccountsService::failedLogins() const
129 return m_failedLogins;
132void AccountsService::setFailedLogins(uint failedLogins)
134 m_failedLogins = failedLogins;
135 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins", failedLogins);
138void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
140 if (m_user != user) {
141 return;
142 }
144 if (interface == "com.canonical.unity.AccountsService") {
145 if (changed.contains("demo-edges")) {
146 updateDemoEdges();
147 }
148 } else if (interface == "com.canonical.unity.AccountsService.Private") {
149 if (changed.contains("FailedLogins")) {
150 updateFailedLogins();
151 }
152 } else if (interface == "com.ubuntu.touch.AccountsService.SecurityPrivacy") {
153 if (changed.contains("StatsWelcomeScreen")) {
154 updateStatsWelcomeScreen();
155 }
156 } else if (interface == "com.ubuntu.AccountsService.SecurityPrivacy") {
157 if (changed.contains("PasswordDisplayHint")) {
158 updatePasswordDisplayHint();
159 }
160 }
163void AccountsService::maybeChanged(const QString &user)
165 if (m_user != user) {
166 return;
167 }
169 // Standard properties might have changed
170 updateBackgroundFile();