2 * Copyright (C) 2013 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#include "UsersModel.h"
20#include <QLightDM/UsersModel>
21#include <QtCore/QSortFilterProxyModel>
23// First, we define an internal class that wraps LightDM's UsersModel. This
24// class will modify some of the data coming from LightDM. For example, we
25// modify any empty Real Names into just normal Names.
26// (We can't modify the data directly in UsersModel below because it won't sort
27// using the modified data.)
28class MangleModel : public QSortFilterProxyModel
33 explicit MangleModel(QObject* parent=0);
35 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
38MangleModel::MangleModel(QObject* parent)
39 : QSortFilterProxyModel(parent)
41 setSourceModel(new QLightDM::UsersModel(this));
44QVariant MangleModel::data(const QModelIndex &index, int role) const
46 QVariant variantData = QSortFilterProxyModel::data(index, role);
48 // If user's real name is empty, switch to unix name
49 if (role == QLightDM::UsersModel::RealNameRole && variantData.toString().isEmpty()) {
50 variantData = QSortFilterProxyModel::data(index, QLightDM::UsersModel::NameRole);
51 } else if (role == QLightDM::UsersModel::BackgroundPathRole && variantData.toString().startsWith('#')) {
52 const QString stringData = "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='" + variantData.toString() + "'/></svg>";
53 variantData = stringData;
59// **** Now we continue with actual UsersModel class ****
61UsersModel::UsersModel(QObject* parent)
62 : UnitySortFilterProxyModelQML(parent)
64 setModel(new MangleModel(this));
65 setSortCaseSensitivity(Qt::CaseInsensitive);
66 setSortLocaleAware(true);
67 setSortRole(QLightDM::UsersModel::RealNameRole);
71#include "UsersModel.moc"
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