on beafaa2 help sign in
unity8/tests/mocks/liblightdm/MockController.cpp
191 lines 4.5 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_selectGuestHint(false)
27 , m_hasGuestAccountHint(false)
28 , m_fullSessions(
29 {
30 {"ubuntu", "Ubuntu"},
31 {"ubuntu-2d", "Ubuntu 2D"},
32 {"gnome", "GNOME"},
33 {"gnome-classic", "GNOME Classic"},
34 {"gnome-flashback-compiz", "GNOME Flashback (Compiz)"},
35 {"gnome-flashback-metacity", "GNOME Flashback (Metacity)"},
36 {"gnome-wayland", "GNOME on Wayland"},
37 {"plasma", "Plasma"},
38 {"kde", "KDE" },
39 {"xterm", "Recovery Console"},
40 {"", "Unknown?"}
41 })
42 , m_numSessions(0)
44 reset();
47MockController::~MockController()
49 m_instance = nullptr;
52MockController *MockController::instance()
54 if (!m_instance) {
55 m_instance = new MockController;
56 }
57 return m_instance;
60void MockController::reset()
62 auto userMode = qgetenv("LIBLIGHTDM_MOCK_MODE");
63 if (userMode.isEmpty()) {
64 userMode = "full";
65 }
67 setSelectUserHint("");
68 setSelectGuestHint(false);
69 setHasGuestAccountHint(false);
70 setUserMode(userMode);
71 setSessionMode("full");
72 setNumSessions(numFullSessions());
73 setShowManualLoginHint(false);
74 setHideUsersHint(false);
77QString MockController::selectUserHint() const
79 return m_selectUserHint;
82void MockController::setSelectUserHint(const QString &selectUserHint)
84 if (m_selectUserHint != selectUserHint) {
85 m_selectUserHint = selectUserHint;
86 Q_EMIT selectUserHintChanged();
87 }
90bool MockController::selectGuestHint() const
92 return m_selectGuestHint;
95void MockController::setSelectGuestHint(bool selectGuestHint)
97 if (m_selectGuestHint != selectGuestHint) {
98 m_selectGuestHint = selectGuestHint;
99 Q_EMIT selectGuestHintChanged();
100 }
103bool MockController::hasGuestAccountHint() const
105 return m_hasGuestAccountHint;
108void MockController::setHasGuestAccountHint(bool hasGuestAccountHint)
110 if (m_hasGuestAccountHint != hasGuestAccountHint) {
111 m_hasGuestAccountHint = hasGuestAccountHint;
112 Q_EMIT hasGuestAccountHintChanged();
113 }
116bool MockController::showManualLoginHint() const
118 return m_showManualLoginHint;
121void MockController::setShowManualLoginHint(bool showManualLoginHint)
123 if (m_showManualLoginHint != showManualLoginHint) {
124 m_showManualLoginHint = showManualLoginHint;
125 Q_EMIT showManualLoginHintChanged();
126 }
129bool MockController::hideUsersHint() const
131 return m_hideUsersHint;
134void MockController::setHideUsersHint(bool hideUsersHint)
136 if (m_hideUsersHint != hideUsersHint) {
137 m_hideUsersHint = hideUsersHint;
138 Q_EMIT hideUsersHintChanged();
139 }
142QString MockController::userMode() const
144 return m_userMode;
147void MockController::setUserMode(const QString &userMode)
149 if (m_userMode != userMode) {
150 m_userMode = userMode;
151 Q_EMIT userModeChanged();
152 }
155QString MockController::sessionMode() const
157 return m_sessionMode;
160void MockController::setSessionMode(const QString &sessionMode)
162 if (m_sessionMode != sessionMode) {
163 m_sessionMode = sessionMode;
164 Q_EMIT sessionModeChanged();
165 }
168const QList<MockController::SessionItem> &MockController::fullSessionItems() const
170 return m_fullSessions;
173int MockController::numFullSessions() const
175 return m_fullSessions.size();
178int MockController::numSessions() const
180 return m_numSessions;
183void MockController::setNumSessions(int numSessions)
185 if (m_numSessions != numSessions) {
186 m_numSessions = numSessions;
187 Q_EMIT numSessionsChanged();
188 }