on bionic help sign in
unity8/tests/mocks/AccountsService/AccountsService.cpp
250 lines 6.0 kB history raw
1/*
2 * Copyright (C) 2013, 2015 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 */
17#include "AccountsService.h"
18#include "UsersModel.h"
20#include <QLightDM/UsersModel>
21#include <paths.h>
23AccountsService::AccountsService(QObject* parent)
24 : QObject(parent),
25 m_enableFingerprintIdentification(true),
26 m_enableLauncherWhileLocked(true),
27 m_enableIndicatorsWhileLocked(true),
28 m_backgroundFile(),
29 m_statsWelcomeScreen(true),
30 m_failedLogins(0),
31 m_failedFingerprintLogins(0),
32 m_demoEdges(false),
33 m_demoEdgesCompleted(),
34 m_hereEnabled(false),
35 m_hereLicensePath(""),
36 m_usersModel(new UsersModel(this))
40QString AccountsService::user() const
42 return m_user;
45void AccountsService::setUser(const QString &user)
47 m_user = user;
48 Q_EMIT userChanged();
49 Q_EMIT passwordDisplayHintChanged();
50 Q_EMIT backgroundFileChanged();
53bool AccountsService::demoEdges() const
55 return m_demoEdges;
58void AccountsService::setDemoEdges(bool demoEdges)
60 m_demoEdges = demoEdges;
61 Q_EMIT demoEdgesChanged();
64QStringList AccountsService::demoEdgesCompleted() const
66 return m_demoEdgesCompleted;
69void AccountsService::markDemoEdgeCompleted(const QString &edge)
71 if (!m_demoEdgesCompleted.contains(edge)) {
72 m_demoEdgesCompleted << edge;
73 Q_EMIT demoEdgesCompletedChanged();
74 }
77void AccountsService::setDemoEdgesCompleted(const QStringList &demoEdgesCompleted)
79 m_demoEdgesCompleted = demoEdgesCompleted;
80 Q_EMIT demoEdgesCompletedChanged();
83bool AccountsService::enableFingerprintIdentification() const
85 return m_enableFingerprintIdentification;
88void AccountsService::setEnableFingerprintIdentification(bool enableFingerprintIdentification)
90 m_enableFingerprintIdentification = enableFingerprintIdentification;
91 Q_EMIT enableFingerprintIdentificationChanged();
94bool AccountsService::enableLauncherWhileLocked() const
96 return m_enableLauncherWhileLocked;
99void AccountsService::setEnableLauncherWhileLocked(bool enableLauncherWhileLocked)
101 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
102 Q_EMIT enableLauncherWhileLockedChanged();
105bool AccountsService::enableIndicatorsWhileLocked() const
107 return m_enableIndicatorsWhileLocked;
110void AccountsService::setEnableIndicatorsWhileLocked(bool enableIndicatorsWhileLocked)
112 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
113 Q_EMIT enableIndicatorsWhileLockedChanged();
116QString AccountsService::backgroundFile() const
118 if (!m_backgroundFile.isEmpty()) {
119 return m_backgroundFile;
120 }
122 // Check if our mock user has a background set in liblightdm
123 for (int i = 0; i < m_usersModel->count(); i++) {
124 if (m_usersModel->data(i, QLightDM::UsersModel::NameRole) == m_user) {
125 return m_usersModel->data(i, QLightDM::UsersModel::BackgroundPathRole).toString();
126 }
127 }
129 return QString();
132void AccountsService::setBackgroundFile(const QString &backgroundFile)
134 m_backgroundFile = backgroundFile;
135 backgroundFileChanged();
138bool AccountsService::statsWelcomeScreen() const
140 return m_statsWelcomeScreen;
143void AccountsService::setStatsWelcomeScreen(bool statsWelcomeScreen)
145 m_statsWelcomeScreen = statsWelcomeScreen;
146 statsWelcomeScreenChanged();
149AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
151 if (m_user == "has-pin")
152 return PasswordDisplayHint::Numeric;
153 else
154 return PasswordDisplayHint::Keyboard;
157uint AccountsService::failedLogins() const
159 return m_failedLogins;
162void AccountsService::setFailedLogins(uint failedLogins)
164 m_failedLogins = failedLogins;
165 failedLoginsChanged();
168uint AccountsService::failedFingerprintLogins() const
170 return m_failedFingerprintLogins;
173void AccountsService::setFailedFingerprintLogins(uint failedFingerprintLogins)
175 m_failedFingerprintLogins = failedFingerprintLogins;
176 failedFingerprintLoginsChanged();
179bool AccountsService::hereEnabled() const
181 return m_hereEnabled;
184void AccountsService::setHereEnabled(bool enabled)
186 m_hereEnabled = enabled;
187 hereEnabledChanged();
190QString AccountsService::hereLicensePath() const
192 return m_hereLicensePath;
195void AccountsService::setHereLicensePath(const QString &path)
197 // Path should always be valid (this code is all synchronous)
198 if (path == " ") {
199 m_hereLicensePath = QString::null;
200 } else if (path.isNull()) { // because qml collapses null and empty
201 m_hereLicensePath = "";
202 } else {
203 m_hereLicensePath = path;
204 }
205 hereLicensePathChanged();
208bool AccountsService::hereLicensePathValid() const
210 return !m_hereLicensePath.isNull();
213QString AccountsService::realName() const
215 return m_realName;
218void AccountsService::setRealName(const QString &realName)
220 m_realName = realName;
221 Q_EMIT realNameChanged();
224QString AccountsService::email() const
226 return m_email;
229void AccountsService::setEmail(const QString &email)
231 m_email = email;
232 Q_EMIT emailChanged();
235QStringList AccountsService::keymaps() const
237 if (!m_kbdMap.isEmpty()) {
238 return m_kbdMap;
239 }
241 return {QStringLiteral("us")};
244void AccountsService::setKeymaps(const QStringList &keymaps)
246 if (keymaps != m_kbdMap) {
247 m_kbdMap = keymaps;
248 Q_EMIT keymapsChanged();
249 }