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>
20/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21 * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
22 * COUNTERPART IN tests/mocks/Lightdm/liblightdm
23 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
25// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
26// To use the same method of setting role name that it does, we
27// set our compatibility to Qt4 here too.
28#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
30#include "UsersModel.h"
31#include "UsersModelPrivate.h"
33#include <QtCore/QString>
39UsersModel::UsersModel(QObject *parent) :
40 QAbstractListModel(parent),
41 d_ptr(new UsersModelPrivate(this))
43 // Extend roleNames (we want to keep the "display" role)
44 QHash<int, QByteArray> roles = roleNames();
45 roles[NameRole] = "name";
46 roles[RealNameRole] = "realName";
47 roles[LoggedInRole] = "loggedIn";
48 roles[BackgroundRole] = "background";
49 roles[BackgroundPathRole] = "backgroundPath";
50 roles[SessionRole] = "session";
51 roles[HasMessagesRole] = "hasMessages";
52 roles[ImagePathRole] = "imagePath";
53 roles[UidRole] = "uid";
56 connect(d_ptr, &UsersModelPrivate::dataChanged, this, [this](int i) {
57 QModelIndex index = createIndex(i, 0);
58 Q_EMIT dataChanged(index, index);
62int UsersModel::rowCount(const QModelIndex &parent) const
64 Q_D(const UsersModel);
66 if (parent.isValid()) {
68 } else { // parent is root
69 return d->entries.size();
73QVariant UsersModel::data(const QModelIndex &index, int role) const
75 Q_D(const UsersModel);
77 if (!index.isValid()) {
81 int row = index.row();
84 return d->entries[row].real_name;
85 case Qt::DecorationRole:
87 case UsersModel::NameRole:
88 return d->entries[row].username;
89 case UsersModel::RealNameRole:
90 return d->entries[row].real_name;
91 case UsersModel::SessionRole:
92 return d->entries[row].session;
93 case UsersModel::LoggedInRole:
94 return d->entries[row].is_active;
95 case UsersModel::BackgroundRole:
96 return QPixmap(d->entries[row].background);
97 case UsersModel::BackgroundPathRole:
98 return d->entries[row].background;
99 case UsersModel::HasMessagesRole:
100 return d->entries[row].has_messages;
101 case UsersModel::ImagePathRole:
103 case UsersModel::UidRole:
104 return d->entries[row].uid;
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