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