2 * Copyright (C) 2015 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/>.
18#include "SessionsModel.h"
19#include <QtCore/QFile>
20#include <QtCore/QSortFilterProxyModel>
21QHash<int, QByteArray> SessionsModel::roleNames() const
26int SessionsModel::rowCount(const QModelIndex& parent) const
28 return m_model->rowCount(parent);
32QList<QUrl> SessionsModel::iconSearchDirectories() const
34 return m_iconSearchDirectories;
37QModelIndex SessionsModel::sessionIndex(QString sessionName) const
39 for (int i = 0; i < rowCount(QModelIndex()); i ++) {
40 QModelIndex index = m_model->index(i, Qt::DisplayRole);
41 QString aSession(this->data(index, Qt::DisplayRole).toString());
42 if (!QString::compare(aSession, sessionName, Qt::CaseInsensitive)) {
49QUrl SessionsModel::iconUrl(QString sessionName) const
51 Q_FOREACH(const QUrl& searchDirectory, m_iconSearchDirectories)
53 // This is an established icon naming convention
54 QString iconUrl = searchDirectory.toString(QUrl::StripTrailingSlash) +
55 "/" + sessionName.toLower() + "_badge.png";
56 QFile iconFile(iconUrl);
57 if (iconFile.exists()) {
62 // FIXME make this smarter
63 return QUrl("./graphics/session_icons/unknown_badge.png");
66QVariant SessionsModel::data(const QModelIndex& index, int role) const
69 case SessionsModel::IconRole:
70 return QVariant(iconUrl(m_model->data(index, Qt::DisplayRole).toString()));
72 return m_model->data(index, role);
76SessionsModel::SessionsModel(QObject* parent)
77 : UnitySortFilterProxyModelQML(parent)
79 // Add a custom IconRole that isn't in either of the lightdm implementations
80 m_model = new QLightDM::SessionsModel(this);
81 m_roleNames = m_model->roleNames();
82 m_roleNames[IconRole] = "icon_url";
85 setSourceModel(m_model);
86 setSortCaseSensitivity(Qt::CaseInsensitive);
87 setSortLocaleAware(true);
88 setSortRole(Qt::DisplayRole);
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