2 * Copyright (C) 2013-2016 Canonical, Ltd.
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.
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.
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/>.
16 * Author: Michael Terry <michael.terry@canonical.com>
19// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
20// To use the same method of setting role name that it does, we
21// set our compatibility to Qt4 here too.
22#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
24#include "MockController.h"
25#include "MockUsersModel.h"
45class UsersModelPrivate
51UsersModel::UsersModel(QObject *parent)
52 : QAbstractListModel(parent)
53 , d_ptr(new UsersModelPrivate)
55 // Extend roleNames (we want to keep the "display" role)
56 QHash<int, QByteArray> roles = roleNames();
57 roles[NameRole] = "name";
58 roles[RealNameRole] = "realName";
59 roles[LoggedInRole] = "loggedIn";
60 roles[BackgroundRole] = "background";
61 roles[BackgroundPathRole] = "backgroundPath";
62 roles[SessionRole] = "session";
63 roles[HasMessagesRole] = "hasMessages";
64 roles[ImagePathRole] = "imagePath";
65 roles[UidRole] = "uid";
68 connect(MockController::instance(), &MockController::hasGuestAccountHintChanged,
69 this, &UsersModel::resetEntries);
70 connect(MockController::instance(), &MockController::showManualLoginHintChanged,
71 this, &UsersModel::resetEntries);
72 connect(MockController::instance(), &MockController::hideUsersHintChanged,
73 this, &UsersModel::resetEntries);
74 connect(MockController::instance(), &MockController::userModeChanged,
75 this, &UsersModel::resetEntries);
79UsersModel::~UsersModel()
84void UsersModel::setCurrentSessionName(const QString &sessionName, const QString &username)
89 for (auto &entry : d->entries) {
90 if (username == entry.username) {
91 entry.session = sessionName;
97 dataChanged(index(usersIndex, 0), index(usersIndex, 0), QVector<int>(SessionRole));
100int UsersModel::rowCount(const QModelIndex &parent) const
102 Q_D(const UsersModel);
104 if (parent.isValid()) {
106 } else { // parent is root
107 return d->entries.size();
111QVariant UsersModel::data(const QModelIndex &index, int role) const
113 Q_D(const UsersModel);
115 if (!index.isValid()) {
119 int row = index.row();
121 case Qt::DisplayRole:
122 return d->entries[row].real_name;
123 case Qt::DecorationRole:
125 case UsersModel::NameRole:
126 return d->entries[row].username;
127 case UsersModel::RealNameRole:
128 return d->entries[row].real_name;
129 case UsersModel::SessionRole:
130 return d->entries[row].session;
131 case UsersModel::LoggedInRole:
132 return d->entries[row].is_active;
133 case UsersModel::BackgroundRole:
134 return QPixmap(d->entries[row].background);
135 case UsersModel::BackgroundPathRole:
136 return d->entries[row].background;
137 case UsersModel::HasMessagesRole:
138 return d->entries[row].has_messages;
139 case UsersModel::ImagePathRole:
141 case UsersModel::UidRole:
142 return d->entries[row].uid;
148void UsersModel::resetEntries()
154 QString userMode = MockController::instance()->userMode();
156 if (userMode == "single") {
157 d->entries = {{"no-password", "No Password", "", 0, false, false, "ubuntu", 0}};
158 } else if (userMode == "single-passphrase") {
159 d->entries = {{"has-password", "Has Password", "", 0, false, false, "ubuntu", 0}};
160 } else if (userMode == "single-pin") {
161 d->entries = {{"has-pin", "Has PIN", "", 0, false, false, "ubuntu", 0}};
162 } else if (userMode == "full") {
164 * Since the real model sorts these entries alphabetically, the model indices
165 * don't line up correctly. The easiest way to fix this is to ensure that this
166 * list of entries REMAINS IN ALPHABETICAL ORDER at all times.
169 { "active", "Active Account", 0, 0, true, false, "ubuntu", 0 },
170 { "auth-error", "Auth Error", 0, 0, false, false, "ubuntu", 0 },
171 { "black-background", "Black Background", "#000000", 0, false, false, "ubuntu", 0 },
172 { "color-background", "Color Background", "#E95420", 0, false, false, "ubuntu", 0 },
173 { "different-prompt", "Different Prompt", 0, 0, false, false, "ubuntu", 0 },
174 { "empty-name", "", 0, 0, false, false, "ubuntu", 0 },
175 { "has-password", "Has Password", 0, 0, false, false, "ubuntu", 0 },
176 { "has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0 },
177 { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "ubuntu", 0 },
178 { "info-after-login", "Info After Login", 0, 0, false, false, "ubuntu", 0 },
179 { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
180 { "wacky-prompts", "Interspersed Prompts", 0, 0, false, false, "ubuntu", 0 },
181 { "invalid-session", "Invalid Session", 0, 0, false, false, "invalid", 0 },
182 { "locked", "Locked", 0, 0, false, false, "ubuntu", 0 },
183 { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, "ubuntu", 0 },
184 { "long-name", "Long name (far far too long to fit, seriously this would never fit on the screen, you will never see this part of the name)", 0, 0, false, false, "ubuntu", 0 },
185 { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
186 { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
187 { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
188 { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
189 { "no-session", "No Session", 0, 0, false, false, "", 0 },
190 { "question-prompt", "Question Prompt", 0, 0, false, false, "ubuntu", 0 },
191 { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
192 { "two-prompts", "Two Prompts", 0, 0, false, false, "ubuntu", 0 },
193 // white and black are a bit redundant, but useful for manually testing if UI is still readable
194 { "white-background", "White Background", "#ffffff", 0, false, false, "ubuntu", 0 },
195 { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 },
196 { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 }
200 // Assign uids in a loop, just to avoid having to muck with them when
201 // adding or removing test users.
202 for (int i = 0; i < d->entries.size(); i++) {
203 d->entries[i].uid = i + 1;
206 // Assign backgrounds
207 QDir backgroundDir("/usr/share/backgrounds");
208 QStringList backgrounds = backgroundDir.entryList(QDir::Files);
209 if (!backgrounds.empty()) {
210 for (int i = 0; i < d->entries.size(); i++) {
211 if (d->entries[i].background.isNull()) {
212 d->entries[i].background = backgroundDir.filePath(backgrounds[i % backgrounds.size()]);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list