on cfcde21 help sign in
unity8/tests/mocks/AccountsService/AccountsService.cpp
251 lines 6.1 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 "MockUsersModel.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 MockUsersModel(this))
38 m_usersModel->setMockMode("full");
41QString AccountsService::user() const
43 return m_user;
46void AccountsService::setUser(const QString &user)
48 m_user = user;
49 Q_EMIT userChanged();
50 Q_EMIT passwordDisplayHintChanged();
51 Q_EMIT backgroundFileChanged();
54bool AccountsService::demoEdges() const
56 return m_demoEdges;
59void AccountsService::setDemoEdges(bool demoEdges)
61 m_demoEdges = demoEdges;
62 Q_EMIT demoEdgesChanged();
65QStringList AccountsService::demoEdgesCompleted() const
67 return m_demoEdgesCompleted;
70void AccountsService::markDemoEdgeCompleted(const QString &edge)
72 if (!m_demoEdgesCompleted.contains(edge)) {
73 m_demoEdgesCompleted << edge;
74 Q_EMIT demoEdgesCompletedChanged();
75 }
78void AccountsService::setDemoEdgesCompleted(const QStringList &demoEdgesCompleted)
80 m_demoEdgesCompleted = demoEdgesCompleted;
81 Q_EMIT demoEdgesCompletedChanged();
84bool AccountsService::enableFingerprintIdentification() const
86 return m_enableFingerprintIdentification;
89void AccountsService::setEnableFingerprintIdentification(bool enableFingerprintIdentification)
91 m_enableFingerprintIdentification = enableFingerprintIdentification;
92 Q_EMIT enableFingerprintIdentificationChanged();
95bool AccountsService::enableLauncherWhileLocked() const
97 return m_enableLauncherWhileLocked;
100void AccountsService::setEnableLauncherWhileLocked(bool enableLauncherWhileLocked)
102 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
103 Q_EMIT enableLauncherWhileLockedChanged();
106bool AccountsService::enableIndicatorsWhileLocked() const
108 return m_enableIndicatorsWhileLocked;
111void AccountsService::setEnableIndicatorsWhileLocked(bool enableIndicatorsWhileLocked)
113 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
114 Q_EMIT enableIndicatorsWhileLockedChanged();
117QString AccountsService::backgroundFile() const
119 if (!m_backgroundFile.isEmpty()) {
120 return m_backgroundFile;
121 }
123 // Check if our mock user has a background set in liblightdm
124 for (int i = 0; i < m_usersModel->count(); i++) {
125 if (m_usersModel->data(i, QLightDM::UsersModel::NameRole) == m_user) {
126 return m_usersModel->data(i, QLightDM::UsersModel::BackgroundPathRole).toString();
127 }
128 }
130 return QString();
133void AccountsService::setBackgroundFile(const QString &backgroundFile)
135 m_backgroundFile = backgroundFile;
136 backgroundFileChanged();
139bool AccountsService::statsWelcomeScreen() const
141 return m_statsWelcomeScreen;
144void AccountsService::setStatsWelcomeScreen(bool statsWelcomeScreen)
146 m_statsWelcomeScreen = statsWelcomeScreen;
147 statsWelcomeScreenChanged();
150AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
152 if (m_user == "has-pin")
153 return PasswordDisplayHint::Numeric;
154 else
155 return PasswordDisplayHint::Keyboard;
158uint AccountsService::failedLogins() const
160 return m_failedLogins;
163void AccountsService::setFailedLogins(uint failedLogins)
165 m_failedLogins = failedLogins;
166 failedLoginsChanged();
169uint AccountsService::failedFingerprintLogins() const
171 return m_failedFingerprintLogins;
174void AccountsService::setFailedFingerprintLogins(uint failedFingerprintLogins)
176 m_failedFingerprintLogins = failedFingerprintLogins;
177 failedFingerprintLoginsChanged();
180bool AccountsService::hereEnabled() const
182 return m_hereEnabled;
185void AccountsService::setHereEnabled(bool enabled)
187 m_hereEnabled = enabled;
188 hereEnabledChanged();
191QString AccountsService::hereLicensePath() const
193 return m_hereLicensePath;
196void AccountsService::setHereLicensePath(const QString &path)
198 // Path should always be valid (this code is all synchronous)
199 if (path == " ") {
200 m_hereLicensePath = QString::null;
201 } else if (path.isNull()) { // because qml collapses null and empty
202 m_hereLicensePath = "";
203 } else {
204 m_hereLicensePath = path;
205 }
206 hereLicensePathChanged();
209bool AccountsService::hereLicensePathValid() const
211 return !m_hereLicensePath.isNull();
214QString AccountsService::realName() const
216 return m_realName;
219void AccountsService::setRealName(const QString &realName)
221 m_realName = realName;
222 Q_EMIT realNameChanged();
225QString AccountsService::email() const
227 return m_email;
230void AccountsService::setEmail(const QString &email)
232 m_email = email;
233 Q_EMIT emailChanged();
236QStringList AccountsService::keymaps() const
238 if (!m_kbdMap.isEmpty()) {
239 return m_kbdMap;
240 }
242 return {QStringLiteral("us")};
245void AccountsService::setKeymaps(const QStringList &keymaps)
247 if (keymaps != m_kbdMap) {
248 m_kbdMap = keymaps;
249 Q_EMIT keymapsChanged();
250 }