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
// 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 "UsersModel.h"
25
#include "UsersModelPrivate.h"
26
#include <QtCore/QDir>
27
#include <QtCore/QString>
28
#include <QtGui/QIcon>
33
UsersModel::UsersModel(QObject *parent) :
34
QAbstractListModel(parent),
35
d_ptr(new UsersModelPrivate(this))
39
// Extend roleNames (we want to keep the "display" role)
40
QHash<int, QByteArray> roles = roleNames();
41
roles[NameRole] = "name";
42
roles[RealNameRole] = "realName";
43
roles[LoggedInRole] = "loggedIn";
44
roles[BackgroundRole] = "background";
45
roles[BackgroundPathRole] = "backgroundPath";
46
roles[SessionRole] = "session";
47
roles[HasMessagesRole] = "hasMessages";
48
roles[ImagePathRole] = "imagePath";
51
// Now modify our mock user backgrounds
52
QDir bgdir = QDir("/usr/share/demo-assets/shell/backgrounds/");
53
QStringList backgrounds = bgdir.entryList(QDir::Files | QDir::NoDotAndDotDot);
55
for (int i = 0, j = 0; i < d->entries.size(); i++) {
56
Entry &entry = d->entries[i];
57
if (entry.background.isNull() && !backgrounds.isEmpty()) {
58
entry.background = bgdir.filePath(backgrounds[j++]);
59
if (j >= backgrounds.length()) {
66
UsersModel::~UsersModel()
71
int UsersModel::rowCount(const QModelIndex &parent) const
73
Q_D(const UsersModel);
75
if (parent.isValid()) {
77
} else { // parent is root
78
return d->entries.size();
82
QVariant UsersModel::data(const QModelIndex &index, int role) const
84
Q_D(const UsersModel);
86
if (!index.isValid()) {
90
int row = index.row();
93
return d->entries[row].real_name;
94
case Qt::DecorationRole:
96
case UsersModel::NameRole:
97
return d->entries[row].username;
98
case UsersModel::RealNameRole:
99
return d->entries[row].real_name;
100
case UsersModel::SessionRole:
101
return d->entries[row].session;
102
case UsersModel::LoggedInRole:
103
return d->entries[row].is_active;
104
case UsersModel::BackgroundRole:
105
return QPixmap(d->entries[row].background);
106
case UsersModel::BackgroundPathRole:
107
return d->entries[row].background;
108
case UsersModel::HasMessagesRole:
109
return d->entries[row].has_messages;
110
case UsersModel::ImagePathRole: