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(), SIGNAL(userModeChanged()),
69 this, SLOT(resetEntries()));
73UsersModel::~UsersModel()
78int UsersModel::rowCount(const QModelIndex &parent) const
80 Q_D(const UsersModel);
82 if (parent.isValid()) {
84 } else { // parent is root
85 return d->entries.size();
89QVariant UsersModel::data(const QModelIndex &index, int role) const
91 Q_D(const UsersModel);
93 if (!index.isValid()) {
97 int row = index.row();
100 return d->entries[row].real_name;
101 case Qt::DecorationRole:
103 case UsersModel::NameRole:
104 return d->entries[row].username;
105 case UsersModel::RealNameRole:
106 return d->entries[row].real_name;
107 case UsersModel::SessionRole:
108 return d->entries[row].session;
109 case UsersModel::LoggedInRole:
110 return d->entries[row].is_active;
111 case UsersModel::BackgroundRole:
112 return QPixmap(d->entries[row].background);
113 case UsersModel::BackgroundPathRole:
114 return d->entries[row].background;
115 case UsersModel::HasMessagesRole:
116 return d->entries[row].has_messages;
117 case UsersModel::ImagePathRole:
119 case UsersModel::UidRole:
120 return d->entries[row].uid;
126void UsersModel::resetEntries()
132 QString userMode = MockController::instance()->userMode();
134 if (userMode == "single") {
135 d->entries = {{"no-password", "No Password", 0, 0, false, false, "ubuntu", 0}};
136 } else if (userMode == "single-passphrase") {
137 d->entries = {{"has-password", "Has Password", 0, 0, false, false, "ubuntu", 0}};
138 } else if (userMode == "single-pin") {
139 d->entries = {{"has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0}};
140 } else if (userMode == "full") {
142 { "has-password", "Has Password", 0, 0, false, false, "ubuntu", 0 },
143 { "has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0 },
144 { "different-prompt", "Different Prompt", 0, 0, false, false, "ubuntu", 0 },
145 { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
146 { "auth-error", "Auth Error", 0, 0, false, false, "ubuntu", 0 },
147 { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
148 { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
149 { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "ubuntu", 0 },
150 { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, "ubuntu", 0 },
151 { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 },
152 { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
153 { "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 },
154 { "color-background", "Color Background", "#E95420", 0, false, false, "ubuntu", 0 },
155 // white and black are a bit redundant, but useful for manually testing if UI is still readable
156 { "white-background", "White Background", "#ffffff", 0, false, false, "ubuntu", 0 },
157 { "black-background", "Black Background", "#000000", 0, false, false, "ubuntu", 0 },
158 { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
159 { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
160 { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
161 { "empty-name", "", 0, 0, false, false, "ubuntu", 0 },
162 { "active", "Active Account", 0, 0, true, false, "ubuntu", 0 },
166 // Assign uids in a loop, just to avoid having to muck with them when
167 // adding or removing test users.
168 for (int i = 0; i < d->entries.size(); i++) {
169 d->entries[i].uid = i + 1;
172 // Assign backgrounds
173 QDir backgroundDir("/usr/share/backgrounds");
174 QStringList backgrounds = backgroundDir.entryList(QDir::Files);
175 if (!backgrounds.empty()) {
176 for (int i = 0; i < d->entries.size(); i++) {
177 if (d->entries[i].background.isNull()) {
178 d->entries[i].background = backgroundDir.filePath(backgrounds[i % backgrounds.size()]);
186QObject *UsersModel::mock()
188 return MockController::instance();
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