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>
22QHash<int, QByteArray> SessionsModel::roleNames() const
27int SessionsModel::rowCount(const QModelIndex& parent) const
29 return m_model->rowCount(parent);
32QList<QUrl> SessionsModel::iconSearchDirectories() const
34 return m_iconSearchDirectories;
37void SessionsModel::setIconSearchDirectories(const QList<QUrl> searchDirectories)
39 // QML gives us a url with file:// prepended which breaks QFile::exists()
40 // so convert the url to a local file
41 QList<QUrl> localList = {};
42 Q_FOREACH(const QUrl& searchDirectory, searchDirectories)
44 localList.append(searchDirectory.toLocalFile());
46 m_iconSearchDirectories = localList;
47 Q_EMIT iconSearchDirectoriesChanged();
50QUrl SessionsModel::iconUrl(const QString sessionName) const
52 Q_FOREACH(const QUrl& searchDirectory, m_iconSearchDirectories)
54 // This is an established icon naming convention
55 QString customIconUrl = searchDirectory.toString(QUrl::StripTrailingSlash) +
56 "/custom_" + sessionName + "_badge.png";
57 QString iconUrl = searchDirectory.toString(QUrl::StripTrailingSlash) +
58 "/" + sessionName + "_badge.png";
60 QFile customIconFile(customIconUrl);
61 QFile iconFile(iconUrl);
62 if (customIconFile.exists()) {
63 return QUrl(customIconUrl);
64 } else if (iconFile.exists()) {
67 // Search the legacy way
68 QString path = searchDirectory.toString(QUrl::StripTrailingSlash) + "/";
69 if (sessionName == "ubuntu" || sessionName == "ubuntu-2d") {
70 path += "ubuntu_badge.png";
72 sessionName == "gnome-classic" ||
73 sessionName == "gnome-flashback-compiz" ||
74 sessionName == "gnome-flashback-metacity" ||
75 sessionName == "gnome-shell" ||
76 sessionName == "gnome-wayland" ||
77 sessionName == "gnome"
79 path += "gnome_badge.png";
80 } else if (sessionName == "plasma") {
81 path += "kde_badge.png";
82 } else if (sessionName == "xterm") {
83 path += "recovery_console_badge.png";
84 } else if (sessionName == "remote-login") {
85 path += "remote_login_help.png";
88 if (QFile(path).exists()) {
94 // FIXME make this smarter
95 return QUrl("./graphics/session_icons/unknown_badge.png");
98QVariant SessionsModel::data(const QModelIndex& index, int role) const
101 case SessionsModel::IconRole:
102 return iconUrl(m_model->data(index, Qt::DisplayRole).toString());
104 return m_model->data(index, role);
108SessionsModel::SessionsModel(QObject* parent)
109 : UnitySortFilterProxyModelQML(parent)
111 // Add a custom IconRole that isn't in either of the lightdm implementations
112 m_model = new QLightDM::SessionsModel(this);
113 m_roleNames = m_model->roleNames();
114 m_roleNames[IconRole] = "icon_url";
117 setSourceModel(m_model);
118 setSortCaseSensitivity(Qt::CaseInsensitive);
119 setSortLocaleAware(true);
120 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