2 * Copyright (C) 2013 Canonical, Ltd.
5 * Michael Zanetti <michael.zanetti@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include "launchermodel.h"
21#include "launcheritem.h"
22#include "backend/launcherbackend.h"
26LauncherModel::LauncherModel(QObject *parent):
27 LauncherModelInterface(parent),
28 m_backend(new LauncherBackend(this))
30 Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
31 LauncherItem *item = new LauncherItem(entry, m_backend->displayName(entry), m_backend->icon(entry), this);
32 if (m_backend->isPinned(entry)) {
33 item->setFavorite(true);
35 item->setRecent(true);
40LauncherModel::~LauncherModel()
42 while (!m_list.empty()) {
43 m_list.takeFirst()->deleteLater();
47int LauncherModel::rowCount(const QModelIndex &parent) const
50 return m_list.count();
53QVariant LauncherModel::data(const QModelIndex &index, int role) const
55 LauncherItem *item = m_list.at(index.row());
58 return item->desktopFile();
64 return item->favorite();
70unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
72 if (index < 0 || index >= m_list.count()) {
75 return m_list.at(index);
78void LauncherModel::move(int oldIndex, int newIndex)
80 // Perform the move in our list
81 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
82 m_list.move(oldIndex, newIndex);
90void LauncherModel::pin(int index)
92 LauncherItem *item = m_list.at(index);
93 if (!item->favorite()) {
95 item->setFavorite(true);
96 item->setRecent(false);
98 m_backend->setPinned(item->desktopFile(), true);
100 QModelIndex modelIndex = this->index(index);
101 Q_EMIT dataChanged(modelIndex, modelIndex);
107QHash<int, QByteArray> LauncherModel::roleNames() const
109 QHash<int, QByteArray> roles;
110 roles.insert(RoleDesktopFile, "desktopFile");
111 roles.insert(RoleName, "name");
112 roles.insert(RoleIcon, "icon");
113 roles.insert(RoleFavorite, "favorite");
114 roles.insert(RoleRunning, "runnng");
118void LauncherModel::storeAppList()
121 Q_FOREACH(LauncherItem *item, m_list) {
122 if (item->favorite() || item->recent()) {
123 appIds << item->desktopFile();
126 m_backend->setStoredApplications(appIds);
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