on ebd7b5b help sign in
unity8/tests/mocks/liblightdm/MockController.cpp
188 lines 4.4 kB history raw
1/*
2 * Copyright (C) 2016 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 "MockController.h"
19static QLightDM::MockController *m_instance = nullptr;
21namespace QLightDM
24MockController::MockController(QObject *parent)
25 : QObject(parent)
26 , m_fullSessions(
27 {
28 {"ubuntu", "Ubuntu"},
29 {"ubuntu-2d", "Ubuntu 2D"},
30 {"gnome", "GNOME"},
31 {"gnome-classic", "GNOME Classic"},
32 {"gnome-flashback-compiz", "GNOME Flashback (Compiz)"},
33 {"gnome-flashback-metacity", "GNOME Flashback (Metacity)"},
34 {"gnome-wayland", "GNOME on Wayland"},
35 {"plasma", "Plasma"},
36 {"kde", "KDE" },
37 {"xterm", "Recovery Console"},
38 {"", "Unknown?"}
39 })
41 reset();
44MockController::~MockController()
46 m_instance = nullptr;
49MockController *MockController::instance()
51 if (!m_instance) {
52 m_instance = new MockController;
53 }
54 return m_instance;
57void MockController::reset()
59 auto userMode = qgetenv("LIBLIGHTDM_MOCK_MODE");
60 if (userMode.isEmpty()) {
61 userMode = "full";
62 }
64 setSelectUserHint("");
65 setSelectGuestHint(false);
66 setHasGuestAccountHint(false);
67 setUserMode(userMode);
68 setSessionMode("full");
69 setNumSessions(numFullSessions());
70 setShowManualLoginHint(false);
71 setHideUsersHint(false);
74QString MockController::selectUserHint() const
76 return m_selectUserHint;
79void MockController::setSelectUserHint(const QString &selectUserHint)
81 if (m_selectUserHint != selectUserHint) {
82 m_selectUserHint = selectUserHint;
83 Q_EMIT selectUserHintChanged();
84 }
87bool MockController::selectGuestHint() const
89 return m_selectGuestHint;
92void MockController::setSelectGuestHint(bool selectGuestHint)
94 if (m_selectGuestHint != selectGuestHint) {
95 m_selectGuestHint = selectGuestHint;
96 Q_EMIT selectGuestHintChanged();
97 }
100bool MockController::hasGuestAccountHint() const
102 return m_hasGuestAccountHint;
105void MockController::setHasGuestAccountHint(bool hasGuestAccountHint)
107 if (m_hasGuestAccountHint != hasGuestAccountHint) {
108 m_hasGuestAccountHint = hasGuestAccountHint;
109 Q_EMIT hasGuestAccountHintChanged();
110 }
113bool MockController::showManualLoginHint() const
115 return m_showManualLoginHint;
118void MockController::setShowManualLoginHint(bool showManualLoginHint)
120 if (m_showManualLoginHint != showManualLoginHint) {
121 m_showManualLoginHint = showManualLoginHint;
122 Q_EMIT showManualLoginHintChanged();
123 }
126bool MockController::hideUsersHint() const
128 return m_hideUsersHint;
131void MockController::setHideUsersHint(bool hideUsersHint)
133 if (m_hideUsersHint != hideUsersHint) {
134 m_hideUsersHint = hideUsersHint;
135 Q_EMIT hideUsersHintChanged();
136 }
139QString MockController::userMode() const
141 return m_userMode;
144void MockController::setUserMode(const QString &userMode)
146 if (m_userMode != userMode) {
147 m_userMode = userMode;
148 Q_EMIT userModeChanged();
149 }
152QString MockController::sessionMode() const
154 return m_sessionMode;
157void MockController::setSessionMode(const QString &sessionMode)
159 if (m_sessionMode != sessionMode) {
160 m_sessionMode = sessionMode;
161 Q_EMIT sessionModeChanged();
162 }
165const QList<MockController::SessionItem> &MockController::fullSessionItems() const
167 return m_fullSessions;
170int MockController::numFullSessions() const
172 return m_fullSessions.size();
175int MockController::numSessions() const
177 return m_numSessions;
180void MockController::setNumSessions(int numSessions)
182 if (m_numSessions != numSessions) {
183 m_numSessions = numSessions;
184 Q_EMIT numSessionsChanged();
185 }