on c488c56 help sign in
unity8/tests/mocks/AccountsService/AccountsService.cpp
266 lines 6.4 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 "MockController.h"
19#include "UsersModel.h"
21#include <QLightDM/UsersModel>
22#include <paths.h>
24AccountsService::AccountsService(QObject* parent)
25 : QObject(parent),
26 m_enableFingerprintIdentification(true),
27 m_enableLauncherWhileLocked(true),
28 m_enableIndicatorsWhileLocked(true),
29 m_backgroundFile(),
30 m_greeterMode(true),
31 m_statsWelcomeScreen(true),
32 m_failedLogins(0),
33 m_failedFingerprintLogins(0),
34 m_demoEdges(false),
35 m_demoEdgesCompleted(),
36 m_hereEnabled(false),
37 m_hereLicensePath(""),
38 m_usersModel(new UsersModel(this))
40 QLightDM::MockController::instance()->setUserMode("full");
43QString AccountsService::user() const
45 return m_user;
48void AccountsService::setUser(const QString &user)
50 m_user = user;
51 Q_EMIT userChanged();
52 Q_EMIT passwordDisplayHintChanged();
53 Q_EMIT backgroundFileChanged();
56bool AccountsService::greeterMode() const
58 return m_greeterMode;
61void AccountsService::setGreeterMode(bool greeterMode)
63 if (m_greeterMode != greeterMode) {
64 m_greeterMode = greeterMode;
65 Q_EMIT greeterModeChanged();
66 }
69bool AccountsService::demoEdges() const
71 return m_demoEdges;
74void AccountsService::setDemoEdges(bool demoEdges)
76 m_demoEdges = demoEdges;
77 Q_EMIT demoEdgesChanged();
80QStringList AccountsService::demoEdgesCompleted() const
82 return m_demoEdgesCompleted;
85void AccountsService::markDemoEdgeCompleted(const QString &edge)
87 if (!m_demoEdgesCompleted.contains(edge)) {
88 m_demoEdgesCompleted << edge;
89 Q_EMIT demoEdgesCompletedChanged();
90 }
93void AccountsService::setDemoEdgesCompleted(const QStringList &demoEdgesCompleted)
95 m_demoEdgesCompleted = demoEdgesCompleted;
96 Q_EMIT demoEdgesCompletedChanged();
99bool AccountsService::enableFingerprintIdentification() const
101 return m_enableFingerprintIdentification;
104void AccountsService::setEnableFingerprintIdentification(bool enableFingerprintIdentification)
106 m_enableFingerprintIdentification = enableFingerprintIdentification;
107 Q_EMIT enableFingerprintIdentificationChanged();
110bool AccountsService::enableLauncherWhileLocked() const
112 return m_enableLauncherWhileLocked;
115void AccountsService::setEnableLauncherWhileLocked(bool enableLauncherWhileLocked)
117 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
118 Q_EMIT enableLauncherWhileLockedChanged();
121bool AccountsService::enableIndicatorsWhileLocked() const
123 return m_enableIndicatorsWhileLocked;
126void AccountsService::setEnableIndicatorsWhileLocked(bool enableIndicatorsWhileLocked)
128 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
129 Q_EMIT enableIndicatorsWhileLockedChanged();
132QString AccountsService::backgroundFile() const
134 if (!m_backgroundFile.isEmpty()) {
135 return m_backgroundFile;
136 }
138 // Check if our mock user has a background set in liblightdm
139 for (int i = 0; i < m_usersModel->count(); i++) {
140 if (m_usersModel->data(i, QLightDM::UsersModel::NameRole) == m_user) {
141 return m_usersModel->data(i, QLightDM::UsersModel::BackgroundPathRole).toString();
142 }
143 }
145 return QString();
148void AccountsService::setBackgroundFile(const QString &backgroundFile)
150 m_backgroundFile = backgroundFile;
151 backgroundFileChanged();
154bool AccountsService::statsWelcomeScreen() const
156 return m_statsWelcomeScreen;
159void AccountsService::setStatsWelcomeScreen(bool statsWelcomeScreen)
161 m_statsWelcomeScreen = statsWelcomeScreen;
162 statsWelcomeScreenChanged();
165AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
167 if (m_user == "has-pin")
168 return PasswordDisplayHint::Numeric;
169 else
170 return PasswordDisplayHint::Keyboard;
173uint AccountsService::failedLogins() const
175 return m_failedLogins;
178void AccountsService::setFailedLogins(uint failedLogins)
180 m_failedLogins = failedLogins;
181 failedLoginsChanged();
184uint AccountsService::failedFingerprintLogins() const
186 return m_failedFingerprintLogins;
189void AccountsService::setFailedFingerprintLogins(uint failedFingerprintLogins)
191 m_failedFingerprintLogins = failedFingerprintLogins;
192 failedFingerprintLoginsChanged();
195bool AccountsService::hereEnabled() const
197 return m_hereEnabled;
200void AccountsService::setHereEnabled(bool enabled)
202 m_hereEnabled = enabled;
203 hereEnabledChanged();
206QString AccountsService::hereLicensePath() const
208 return m_hereLicensePath;
211void AccountsService::setHereLicensePath(const QString &path)
213 // Path should always be valid (this code is all synchronous)
214 if (path == " ") {
215 m_hereLicensePath = QString::null;
216 } else if (path.isNull()) { // because qml collapses null and empty
217 m_hereLicensePath = "";
218 } else {
219 m_hereLicensePath = path;
220 }
221 hereLicensePathChanged();
224bool AccountsService::hereLicensePathValid() const
226 return !m_hereLicensePath.isNull();
229QString AccountsService::realName() const
231 return m_realName;
234void AccountsService::setRealName(const QString &realName)
236 m_realName = realName;
237 Q_EMIT realNameChanged();
240QString AccountsService::email() const
242 return m_email;
245void AccountsService::setEmail(const QString &email)
247 m_email = email;
248 Q_EMIT emailChanged();
251QStringList AccountsService::keymaps() const
253 if (!m_kbdMap.isEmpty()) {
254 return m_kbdMap;
255 }
257 return {QStringLiteral("us")};
260void AccountsService::setKeymaps(const QStringList &keymaps)
262 if (keymaps != m_kbdMap) {
263 m_kbdMap = keymaps;
264 Q_EMIT keymapsChanged();
265 }