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.)
28
class MangleModel : public QSortFilterProxyModel
33
explicit MangleModel(QObject* parent=0);
35
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
38
MangleModel::MangleModel(QObject* parent)
39
: QSortFilterProxyModel(parent)
41
setSourceModel(new QLightDM::UsersModel(this));
44
QVariant MangleModel::data(const QModelIndex &index, int role) const
46
QVariant data = QSortFilterProxyModel::data(index, role);
48
// If user's real name is empty, switch to unix name
49
if (role == QLightDM::UsersModel::RealNameRole && data.toString().isEmpty()) {
50
data = QSortFilterProxyModel::data(index, QLightDM::UsersModel::NameRole);
51
} else if (role == QLightDM::UsersModel::BackgroundPathRole && data.toString().startsWith('#')) {
52
data = "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='" + data.toString() + "'/></svg>";
58
// **** Now we continue with actual UsersModel class ****
60
UsersModel::UsersModel(QObject* parent)
61
: QSortFilterProxyModelQML(parent)
63
setModel(new MangleModel(this));
64
setSortCaseSensitivity(Qt::CaseInsensitive);
65
setSortLocaleAware(true);
66
setSortRole(QLightDM::UsersModel::RealNameRole);
70
#include "UsersModel.moc"