on 95cd8a0 help sign in
unity8/plugins/AccountsService/AccountsService.cpp
268 lines 8.4 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 <QFile>
23#include <QStringList>
25AccountsService::AccountsService(QObject* parent)
26 : QObject(parent),
27 m_service(new AccountsServiceDBusAdaptor(this)),
28 m_user(""),
29 m_demoEdges(false),
30 m_enableLauncherWhileLocked(false),
31 m_enableIndicatorsWhileLocked(false),
32 m_statsWelcomeScreen(false),
33 m_passwordDisplayHint(Keyboard),
34 m_failedLogins(0),
35 m_hereEnabled(false),
36 m_hereLicensePath() // null means not set yet
38 connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
39 this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
40 connect(m_service, SIGNAL(maybeChanged(const QString &)),
41 this, SLOT(maybeChanged(const QString &)));
43 setUser(qgetenv("USER"));
46QString AccountsService::user() const
48 return m_user;
51void AccountsService::setUser(const QString &user)
53 if (user.isEmpty() || m_user == user)
54 return;
56 m_user = user;
57 Q_EMIT userChanged();
59 updateDemoEdges();
60 updateEnableLauncherWhileLocked();
61 updateEnableIndicatorsWhileLocked();
62 updateBackgroundFile();
63 updateStatsWelcomeScreen();
64 updatePasswordDisplayHint();
65 updateFailedLogins();
66 updateHereEnabled();
67 updateHereLicensePath();
70bool AccountsService::demoEdges() const
72 return m_demoEdges;
75void AccountsService::setDemoEdges(bool demoEdges)
77 m_demoEdges = demoEdges;
78 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
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 m_service->setUserProperty(m_user, "com.ubuntu.location.providers.here.AccountsService", "LicenseAccepted", enabled);
116QString AccountsService::hereLicensePath() const
118 return m_hereLicensePath;
121bool AccountsService::hereLicensePathValid() const
123 return !m_hereLicensePath.isNull();
126void AccountsService::updateDemoEdges()
128 auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
129 if (m_demoEdges != demoEdges) {
130 m_demoEdges = demoEdges;
131 Q_EMIT demoEdgesChanged();
132 }
135void AccountsService::updateEnableLauncherWhileLocked()
137 auto enableLauncherWhileLocked = m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "EnableLauncherWhileLocked").toBool();
138 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
139 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
140 Q_EMIT enableLauncherWhileLockedChanged();
141 }
144void AccountsService::updateEnableIndicatorsWhileLocked()
146 auto enableIndicatorsWhileLocked = m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "EnableIndicatorsWhileLocked").toBool();
147 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
148 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
149 Q_EMIT enableIndicatorsWhileLockedChanged();
150 }
153void AccountsService::updateBackgroundFile()
155 auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
156 if (m_backgroundFile != backgroundFile) {
157 m_backgroundFile = backgroundFile;
158 Q_EMIT backgroundFileChanged();
159 }
162void AccountsService::updateStatsWelcomeScreen()
164 bool statsWelcomeScreen = m_service->getUserProperty(m_user, "com.ubuntu.touch.AccountsService.SecurityPrivacy", "StatsWelcomeScreen").toBool();
165 if (m_statsWelcomeScreen != statsWelcomeScreen) {
166 m_statsWelcomeScreen = statsWelcomeScreen;
167 Q_EMIT statsWelcomeScreenChanged();
168 }
171void AccountsService::updatePasswordDisplayHint()
173 PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "PasswordDisplayHint").toInt();
174 if (m_passwordDisplayHint != passwordDisplayHint) {
175 m_passwordDisplayHint = passwordDisplayHint;
176 Q_EMIT passwordDisplayHintChanged();
177 }
180void AccountsService::updateFailedLogins()
182 uint failedLogins = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins").toUInt();
183 if (m_failedLogins != failedLogins) {
184 m_failedLogins = failedLogins;
185 Q_EMIT failedLoginsChanged();
186 }
189void AccountsService::updateHereEnabled()
191 bool hereEnabled = m_service->getUserProperty(m_user, "com.ubuntu.location.providers.here.AccountsService", "LicenseAccepted").toBool();
192 if (m_hereEnabled != hereEnabled) {
193 m_hereEnabled = hereEnabled;
194 Q_EMIT hereEnabledChanged();
195 }
198void AccountsService::updateHereLicensePath()
200 QString hereLicensePath = m_service->getUserProperty(m_user, "com.ubuntu.location.providers.here.AccountsService", "LicenseBasePath").toString();
202 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
203 hereLicensePath = "";
205 if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
206 m_hereLicensePath = hereLicensePath;
207 Q_EMIT hereLicensePathChanged();
208 }
211uint AccountsService::failedLogins() const
213 return m_failedLogins;
216void AccountsService::setFailedLogins(uint failedLogins)
218 m_failedLogins = failedLogins;
219 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins", failedLogins);
222void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
224 if (m_user != user) {
225 return;
226 }
228 if (interface == "com.canonical.unity.AccountsService") {
229 if (changed.contains("demo-edges")) {
230 updateDemoEdges();
231 }
232 } else if (interface == "com.canonical.unity.AccountsService.Private") {
233 if (changed.contains("FailedLogins")) {
234 updateFailedLogins();
235 }
236 } else if (interface == "com.ubuntu.touch.AccountsService.SecurityPrivacy") {
237 if (changed.contains("StatsWelcomeScreen")) {
238 updateStatsWelcomeScreen();
239 }
240 } else if (interface == "com.ubuntu.AccountsService.SecurityPrivacy") {
241 if (changed.contains("PasswordDisplayHint")) {
242 updatePasswordDisplayHint();
243 }
244 if (changed.contains("EnableLauncherWhileLocked")) {
245 updateEnableLauncherWhileLocked();
246 }
247 if (changed.contains("EnableIndicatorsWhileLocked")) {
248 updateEnableIndicatorsWhileLocked();
249 }
250 } else if (interface == "com.ubuntu.location.providers.here.AccountsService") {
251 if (changed.contains("LicenseAccepted")) {
252 updateHereEnabled();
253 }
254 if (changed.contains("LicenseBasePath")) {
255 updateHereLicensePath();
256 }
257 }
260void AccountsService::maybeChanged(const QString &user)
262 if (m_user != user) {
263 return;
264 }
266 // Standard properties might have changed
267 updateBackgroundFile();