on f621663 help sign in
unity8/plugins/AccountsService/AccountsService.cpp
209 lines 6.6 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_enableLauncherWhileLocked(false),
30 m_enableIndicatorsWhileLocked(false),
31 m_statsWelcomeScreen(false),
32 m_passwordDisplayHint(Keyboard),
33 m_failedLogins(0)
35 connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
36 this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
37 connect(m_service, SIGNAL(maybeChanged(const QString &)),
38 this, SLOT(maybeChanged(const QString &)));
41QString AccountsService::user() const
43 return m_user;
46void AccountsService::setUser(const QString &user)
48 m_user = user;
49 Q_EMIT userChanged();
51 updateDemoEdges();
52 updateEnableLauncherWhileLocked();
53 updateEnableIndicatorsWhileLocked();
54 updateBackgroundFile();
55 updateStatsWelcomeScreen();
56 updatePasswordDisplayHint();
57 updateFailedLogins();
60bool AccountsService::demoEdges() const
62 return m_demoEdges;
65void AccountsService::setDemoEdges(bool demoEdges)
67 m_demoEdges = demoEdges;
68 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
71bool AccountsService::enableLauncherWhileLocked() const
73 return m_enableLauncherWhileLocked;
76bool AccountsService::enableIndicatorsWhileLocked() const
78 return m_enableIndicatorsWhileLocked;
81QString AccountsService::backgroundFile() const
83 return m_backgroundFile;
86bool AccountsService::statsWelcomeScreen() const
88 return m_statsWelcomeScreen;
91AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
93 return m_passwordDisplayHint;
96void AccountsService::updateDemoEdges()
98 auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
99 if (m_demoEdges != demoEdges) {
100 m_demoEdges = demoEdges;
101 Q_EMIT demoEdgesChanged();
102 }
105void AccountsService::updateEnableLauncherWhileLocked()
107 auto enableLauncherWhileLocked = m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "EnableLauncherWhileLocked").toBool();
108 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
109 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
110 Q_EMIT enableLauncherWhileLockedChanged();
111 }
114void AccountsService::updateEnableIndicatorsWhileLocked()
116 auto enableIndicatorsWhileLocked = m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "EnableIndicatorsWhileLocked").toBool();
117 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
118 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
119 Q_EMIT enableIndicatorsWhileLockedChanged();
120 }
123void AccountsService::updateBackgroundFile()
125 auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
126 if (m_backgroundFile != backgroundFile) {
127 m_backgroundFile = backgroundFile;
128 Q_EMIT backgroundFileChanged();
129 }
132void AccountsService::updateStatsWelcomeScreen()
134 bool statsWelcomeScreen = m_service->getUserProperty(m_user, "com.ubuntu.touch.AccountsService.SecurityPrivacy", "StatsWelcomeScreen").toBool();
135 if (m_statsWelcomeScreen != statsWelcomeScreen) {
136 m_statsWelcomeScreen = statsWelcomeScreen;
137 Q_EMIT statsWelcomeScreenChanged();
138 }
141void AccountsService::updatePasswordDisplayHint()
143 PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "PasswordDisplayHint").toInt();
144 if (m_passwordDisplayHint != passwordDisplayHint) {
145 m_passwordDisplayHint = passwordDisplayHint;
146 Q_EMIT passwordDisplayHintChanged();
147 }
150void AccountsService::updateFailedLogins()
152 uint failedLogins = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins").toUInt();
153 if (m_failedLogins != failedLogins) {
154 m_failedLogins = failedLogins;
155 Q_EMIT failedLoginsChanged();
156 }
159uint AccountsService::failedLogins() const
161 return m_failedLogins;
164void AccountsService::setFailedLogins(uint failedLogins)
166 m_failedLogins = failedLogins;
167 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService.Private", "FailedLogins", failedLogins);
170void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
172 if (m_user != user) {
173 return;
174 }
176 if (interface == "com.canonical.unity.AccountsService") {
177 if (changed.contains("demo-edges")) {
178 updateDemoEdges();
179 }
180 } else if (interface == "com.canonical.unity.AccountsService.Private") {
181 if (changed.contains("FailedLogins")) {
182 updateFailedLogins();
183 }
184 } else if (interface == "com.ubuntu.touch.AccountsService.SecurityPrivacy") {
185 if (changed.contains("StatsWelcomeScreen")) {
186 updateStatsWelcomeScreen();
187 }
188 } else if (interface == "com.ubuntu.AccountsService.SecurityPrivacy") {
189 if (changed.contains("PasswordDisplayHint")) {
190 updatePasswordDisplayHint();
191 }
192 if (changed.contains("EnableLauncherWhileLocked")) {
193 updateEnableLauncherWhileLocked();
194 }
195 if (changed.contains("EnableIndicatorsWhileLocked")) {
196 updateEnableIndicatorsWhileLocked();
197 }
198 }
201void AccountsService::maybeChanged(const QString &user)
203 if (m_user != user) {
204 return;
205 }
207 // Standard properties might have changed
208 updateBackgroundFile();