on ef230bb help sign in
unity8/tests/mocks/AccountsService/AccountsService.cpp
214 lines 5.2 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_usersModel(new UsersModel(this))
38QString AccountsService::user() const
40 return m_user;
43void AccountsService::setUser(const QString &user)
45 m_user = user;
46 Q_EMIT userChanged();
47 Q_EMIT passwordDisplayHintChanged();
48 Q_EMIT backgroundFileChanged();
51bool AccountsService::demoEdges() const
53 return m_demoEdges;
56void AccountsService::setDemoEdges(bool demoEdges)
58 m_demoEdges = demoEdges;
59 Q_EMIT demoEdgesChanged();
62QStringList AccountsService::demoEdgesCompleted() const
64 return m_demoEdgesCompleted;
67void AccountsService::markDemoEdgeCompleted(const QString &edge)
69 if (!m_demoEdgesCompleted.contains(edge)) {
70 m_demoEdgesCompleted << edge;
71 Q_EMIT demoEdgesCompletedChanged();
72 }
75void AccountsService::setDemoEdgesCompleted(const QStringList &demoEdgesCompleted)
77 m_demoEdgesCompleted = demoEdgesCompleted;
78 Q_EMIT demoEdgesCompletedChanged();
81bool AccountsService::enableFingerprintIdentification() const
83 return m_enableFingerprintIdentification;
86void AccountsService::setEnableFingerprintIdentification(bool enableFingerprintIdentification)
88 m_enableFingerprintIdentification = enableFingerprintIdentification;
89 Q_EMIT enableFingerprintIdentificationChanged();
92bool AccountsService::enableLauncherWhileLocked() const
94 return m_enableLauncherWhileLocked;
97void AccountsService::setEnableLauncherWhileLocked(bool enableLauncherWhileLocked)
99 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
100 Q_EMIT enableLauncherWhileLockedChanged();
103bool AccountsService::enableIndicatorsWhileLocked() const
105 return m_enableIndicatorsWhileLocked;
108void AccountsService::setEnableIndicatorsWhileLocked(bool enableIndicatorsWhileLocked)
110 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
111 Q_EMIT enableIndicatorsWhileLockedChanged();
114QString AccountsService::backgroundFile() const
116 if (!m_backgroundFile.isEmpty()) {
117 return m_backgroundFile;
118 }
120 // Check if our mock user has a background set in liblightdm
121 for (int i = 0; i < m_usersModel->count(); i++) {
122 if (m_usersModel->data(i, QLightDM::UsersModel::NameRole) == m_user) {
123 return m_usersModel->data(i, QLightDM::UsersModel::BackgroundPathRole).toString();
124 }
125 }
127 return QString();
130void AccountsService::setBackgroundFile(const QString &backgroundFile)
132 m_backgroundFile = backgroundFile;
133 backgroundFileChanged();
136bool AccountsService::statsWelcomeScreen() const
138 return m_statsWelcomeScreen;
141void AccountsService::setStatsWelcomeScreen(bool statsWelcomeScreen)
143 m_statsWelcomeScreen = statsWelcomeScreen;
144 statsWelcomeScreenChanged();
147AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
149 if (m_user == "has-pin")
150 return PasswordDisplayHint::Numeric;
151 else
152 return PasswordDisplayHint::Keyboard;
155uint AccountsService::failedLogins() const
157 return m_failedLogins;
160void AccountsService::setFailedLogins(uint failedLogins)
162 m_failedLogins = failedLogins;
163 failedLoginsChanged();
166uint AccountsService::failedFingerprintLogins() const
168 return m_failedFingerprintLogins;
171void AccountsService::setFailedFingerprintLogins(uint failedFingerprintLogins)
173 m_failedFingerprintLogins = failedFingerprintLogins;
174 failedFingerprintLoginsChanged();
177QString AccountsService::realName() const
179 return m_realName;
182void AccountsService::setRealName(const QString &realName)
184 m_realName = realName;
185 Q_EMIT realNameChanged();
188QString AccountsService::email() const
190 return m_email;
193void AccountsService::setEmail(const QString &email)
195 m_email = email;
196 Q_EMIT emailChanged();
199QStringList AccountsService::keymaps() const
201 if (!m_kbdMap.isEmpty()) {
202 return m_kbdMap;
203 }
205 return {QStringLiteral("us")};
208void AccountsService::setKeymaps(const QStringList &keymaps)
210 if (keymaps != m_kbdMap) {
211 m_kbdMap = keymaps;
212 Q_EMIT keymapsChanged();
213 }